Skip to content

Commit 0240cd7

Browse files
committed
Remove some warnings for Windows builds
1 parent 04ed260 commit 0240cd7

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

Sources/CoreFoundation/include/ForSwiftFoundationOnly.h

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define NOMINMAX
3636
#define VC_EXTRALEAN
3737
#define WIN32_LEAN_AND_MEAN
38+
#define _CRT_NONSTDC_NO_DEPRECATE
3839
#include <Windows.h>
3940
#elif !TARGET_OS_WASI
4041
#include <fts.h>

Sources/Foundation/FileManager+Win32.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ extension FileManager {
108108

109109
var wszVolumeName: [WCHAR] = Array<WCHAR>(repeating: 0, count: Int(MAX_PATH))
110110

111-
var hVolumes: HANDLE = FindFirstVolumeW(&wszVolumeName, DWORD(wszVolumeName.count))
111+
let hVolumes: HANDLE = FindFirstVolumeW(&wszVolumeName, DWORD(wszVolumeName.count))
112112
guard hVolumes != INVALID_HANDLE_VALUE else { return nil }
113113
defer { FindVolumeClose(hVolumes) }
114114

@@ -350,7 +350,7 @@ extension FileManager {
350350
guard let _lastReturned else { return firstValidItem() }
351351

352352
if _lastReturned.hasDirectoryPath && (level == 0 || !_options.contains(.skipsSubdirectoryDescendants)) {
353-
try walk(directory: _lastReturned) { entry, attributes in
353+
walk(directory: _lastReturned) { entry, attributes in
354354
if entry == "." || entry == ".." { return }
355355
if _options.contains(.skipsHiddenFiles) && attributes & FILE_ATTRIBUTE_HIDDEN == FILE_ATTRIBUTE_HIDDEN {
356356
return
@@ -386,7 +386,7 @@ extension FileManager.NSPathDirectoryEnumerator {
386386
internal func _nextObject() -> Any? {
387387
guard let url = innerEnumerator.nextObject() as? URL else { return nil }
388388

389-
let path: String? = try? baseURL.withUnsafeNTPath { pwszBasePath in
389+
let path: String? = baseURL.withUnsafeNTPath { pwszBasePath in
390390
let dwBaseAttrs = GetFileAttributesW(pwszBasePath)
391391
if dwBaseAttrs == INVALID_FILE_ATTRIBUTES { return nil }
392392

Sources/Foundation/Host.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ open class Host: NSObject {
135135
var ulResult: ULONG =
136136
GetAdaptersAddresses(ULONG(AF_UNSPEC), 0, nil, nil, &ulSize)
137137

138-
var arAdapters: UnsafeMutableRawPointer =
138+
let arAdapters: UnsafeMutableRawPointer =
139139
UnsafeMutableRawPointer.allocate(byteCount: Int(ulSize),
140140
alignment: 1)
141141
defer { arAdapters.deallocate() }
@@ -150,7 +150,7 @@ open class Host: NSObject {
150150
while pAdapter != nil {
151151
// print("Adapter: \(String(cString: pAdapter!.pointee.AdapterName))")
152152

153-
var arAddresses: UnsafeMutablePointer<IP_ADAPTER_UNICAST_ADDRESS> =
153+
let arAddresses: UnsafeMutablePointer<IP_ADAPTER_UNICAST_ADDRESS> =
154154
pAdapter!.pointee.FirstUnicastAddress
155155

156156
var pAddress: UnsafeMutablePointer<IP_ADAPTER_UNICAST_ADDRESS>? =

Sources/Foundation/Thread.swift

+32-28
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ open class Thread : NSObject {
128128
@available(*, noasync)
129129
open class func sleep(until date: Date) {
130130
#if os(Windows)
131-
var hTimer: HANDLE = CreateWaitableTimerW(nil, true, nil)
131+
let hTimer: HANDLE = CreateWaitableTimerW(nil, true, nil)
132132
if hTimer == HANDLE(bitPattern: 0) { fatalError("unable to create timer: \(GetLastError())") }
133133
defer { CloseHandle(hTimer) }
134134

@@ -166,7 +166,7 @@ open class Thread : NSObject {
166166
@available(*, noasync)
167167
open class func sleep(forTimeInterval interval: TimeInterval) {
168168
#if os(Windows)
169-
var hTimer: HANDLE = CreateWaitableTimerW(nil, true, nil)
169+
let hTimer: HANDLE = CreateWaitableTimerW(nil, true, nil)
170170
// FIXME(compnerd) how to check that hTimer is not NULL?
171171
defer { CloseHandle(hTimer) }
172172

@@ -410,37 +410,41 @@ open class Thread : NSObject {
410410
let hProcess: HANDLE = GetCurrentProcess()
411411
SymSetOptions(DWORD(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS))
412412
if !SymInitializeW(hProcess, nil, true) {
413-
return []
413+
return []
414414
}
415415
return backtraceAddresses { (addresses, count) in
416-
var symbols: [String] = []
417-
418-
let addresses: UnsafeMutableBufferPointer<PVOID?> =
419-
UnsafeMutableBufferPointer<PVOID?>(start: addresses, count: count)
420-
withUnsafeTemporaryAllocation(byteCount: MemoryLayout<SYMBOL_INFO>.size + 127,
421-
alignment: 8) { buffer in
422-
let pSymbolInfo: UnsafeMutablePointer<SYMBOL_INFO> =
416+
var symbols: [String] = []
417+
418+
let addresses: UnsafeMutableBufferPointer<PVOID?> =
419+
UnsafeMutableBufferPointer<PVOID?>(start: addresses, count: count)
420+
withUnsafeTemporaryAllocation(byteCount: MemoryLayout<SYMBOL_INFO>.size + 127,
421+
alignment: 8) { buffer in
422+
let pSymbolInfo: UnsafeMutablePointer<SYMBOL_INFO> =
423423
buffer.baseAddress!.assumingMemoryBound(to: SYMBOL_INFO.self)
424-
425-
for address in addresses {
426-
pSymbolInfo.pointee.SizeOfStruct =
424+
425+
for address in addresses {
426+
pSymbolInfo.pointee.SizeOfStruct =
427427
ULONG(MemoryLayout<SYMBOL_INFO>.size)
428-
pSymbolInfo.pointee.MaxNameLen = 128
429-
430-
var dwDisplacement: DWORD64 = 0
431-
if SymFromAddr(hProcess, DWORD64(UInt(bitPattern: address)),
432-
&dwDisplacement, &pSymbolInfo.pointee) {
433-
symbols.append(String(unsafeUninitializedCapacity: Int(pSymbolInfo.pointee.NameLen) + 1) {
434-
strncpy($0.baseAddress, &pSymbolInfo.pointee.Name, $0.count)
435-
return $0.count
436-
})
437-
} else {
438-
symbols.append("\(address)")
439-
}
428+
pSymbolInfo.pointee.MaxNameLen = 128
429+
430+
var dwDisplacement: DWORD64 = 0
431+
if SymFromAddr(hProcess, DWORD64(UInt(bitPattern: address)),
432+
&dwDisplacement, &pSymbolInfo.pointee) {
433+
symbols.append(String(unsafeUninitializedCapacity: Int(pSymbolInfo.pointee.NameLen) + 1) {
434+
strncpy_s($0.baseAddress, $0.count, &pSymbolInfo.pointee.Name, $0.count)
435+
return $0.count
436+
})
437+
} else {
438+
if let address {
439+
symbols.append("\(address)")
440+
} else {
441+
symbols.append("<unknown address>")
442+
}
443+
}
444+
}
440445
}
441-
}
442-
443-
return symbols
446+
447+
return symbols
444448
}
445449
#else
446450
return backtraceAddresses({ (addrs, count) in

0 commit comments

Comments
 (0)