Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ private let _archiverPath: String? = {
return _archiverName.withCString(encodedAs: UTF16.self) { archiverName -> String? in
var result: UnsafeMutablePointer<CWideChar>?

let flags = ULONG(PATHCCH_ALLOW_LONG_PATHS.rawValue)
guard S_OK == PathAllocCombine(buffer.baseAddress!, archiverName, flags, &result) else {
guard S_OK == PathAllocCombine(buffer.baseAddress!, archiverName, DWORD(PATHCCH_ALLOW_LONG_PATHS.rawValue), &result) else {
return nil
}
defer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension HBITMAP__: _AttachableByAddressAsIWICBitmapSource {
// The only reasonable failure mode for `CopyImage()` is allocation failure,
// and Swift treats allocation failures as fatal. Hence, we do not check for
// `nil` on return.
CopyImage(imageAddress, UINT(IMAGE_BITMAP), 0, 0, 0).assumingMemoryBound(to: Self.self)
CopyImage(imageAddress, IMAGE_BITMAP, 0, 0, 0).assumingMemoryBound(to: Self.self)
}

public static func _deinitializeAttachableValue(at imageAddress: UnsafeMutablePointer<Self>) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Testing/ExitTests/ExitTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ extension ExitTest {
// On Windows, similarly disable Windows Error Reporting and the Windows
// Error Reporting UI. Note we expect to be the first component to call
// these functions, so we don't attempt to preserve any previously-set bits.
_ = SetErrorMode(UINT(SEM_NOGPFAULTERRORBOX))
_ = WerSetFlags(DWORD(WER_FAULT_REPORTING_NO_UI))
_ = SetErrorMode(SEM_NOGPFAULTERRORBOX)
_ = WerSetFlags(WER_FAULT_REPORTING_NO_UI)
#else
#warning("Platform-specific implementation missing: unable to disable crash reporting")
#endif
Expand Down
6 changes: 3 additions & 3 deletions Sources/Testing/ExitTests/SpawnProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func spawnExecutable(
}

// Ensure the file handle can be inherited by the child process.
guard SetHandleInformation(windowsHANDLE, DWORD(HANDLE_FLAG_INHERIT), DWORD(HANDLE_FLAG_INHERIT)) else {
guard SetHandleInformation(windowsHANDLE, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT) else {
throw Win32Error(rawValue: GetLastError())
}

Expand Down Expand Up @@ -326,13 +326,13 @@ func spawnExecutable(
// SEE: https://devblogs.microsoft.com/oldnewthing/20101109-00/?p=12323
let workingDirectoryPath = rootDirectoryPath

var flags = DWORD(CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT | EXTENDED_STARTUPINFO_PRESENT)
var flags = CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT | EXTENDED_STARTUPINFO_PRESENT

// Start the process suspended so we can attach a debugger if needed. We
// always start the child process in a suspended state even if the
// "SWT_START_CHILD_PROCESSES_SUSPENDED" environment variable isn't set so that
// the debugger has a chance to attach to the child.
flags |= DWORD(CREATE_SUSPENDED)
flags |= CREATE_SUSPENDED

return try environ.withCString(encodedAs: UTF16.self) { environ in
try workingDirectoryPath.withCString(encodedAs: UTF16.self) { workingDirectoryPath in
Expand Down
2 changes: 1 addition & 1 deletion Sources/Testing/ExitTests/WaitFor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func wait(for processHandle: consuming HANDLE) async throws -> ExitStatus {

// We only want the callback to fire once (and not be rescheduled.) Waiting
// may take an arbitrarily long time, so let the thread pool know that too.
let flags = ULONG(WT_EXECUTEONLYONCE | WT_EXECUTELONGFUNCTION)
let flags = WT_EXECUTEONLYONCE | WT_EXECUTELONGFUNCTION
guard RegisterWaitForSingleObject(&waitHandle, processHandle, callback, context, INFINITE, flags) else {
continuation.resume(throwing: Win32Error(rawValue: GetLastError()))
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extension Backtrace {
withUnsafeTemporaryAllocation(of: SYMBOL_INFO_PACKAGEW.self, capacity: 1) { symbolInfo in
let symbolInfo = symbolInfo.baseAddress!
symbolInfo.pointee.si.SizeOfStruct = ULONG(MemoryLayout<SYMBOL_INFOW>.stride)
symbolInfo.pointee.si.MaxNameLen = ULONG(MAX_SYM_NAME)
symbolInfo.pointee.si.MaxNameLen = MAX_SYM_NAME
var displacement = DWORD64(0)
if SymFromAddrW(hProcess, DWORD64(clamping: address), &displacement, symbolInfo.pointer(to: \.si)!) {
let symbolName = String.decodeCString(symbolInfo.pointer(to: \.si.Name)!, as: UTF16.self)?.result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ extension CommandLine {
#endif
while result == nil {
try withUnsafeTemporaryAllocation(of: CWideChar.self, capacity: bufferCount) { buffer in
SetLastError(DWORD(ERROR_SUCCESS))
SetLastError(ERROR_SUCCESS)
_ = GetModuleFileNameW(nil, buffer.baseAddress!, DWORD(buffer.count))
switch GetLastError() {
case DWORD(ERROR_SUCCESS):
case ERROR_SUCCESS:
result = String.decodeCString(buffer.baseAddress!, as: UTF16.self)?.result
if result == nil {
throw Win32Error(rawValue: DWORD(ERROR_ILLEGAL_CHARACTER))
throw Win32Error(rawValue: ERROR_ILLEGAL_CHARACTER)
}
case DWORD(ERROR_INSUFFICIENT_BUFFER):
case ERROR_INSUFFICIENT_BUFFER:
bufferCount += Int(MAX_PATH)
case let errorCode:
throw Win32Error(rawValue: errorCode)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Testing/Support/CError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension Win32Error: CustomStringConvertible {
// we need to temporarily mis-cast the pointer before we can pass it in.
let count = buffer.withMemoryRebound(to: CWideChar.self) { buffer in
FormatMessageW(
DWORD(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK),
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
nil,
rawValue,
DWORD(swt_MAKELANGID(WORD(LANG_NEUTRAL), WORD(SUBLANG_DEFAULT))),
Expand Down
6 changes: 3 additions & 3 deletions Sources/Testing/Support/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ package enum Environment {
name.withCString(encodedAs: UTF16.self) { name in
func getVariable(maxCount: Int) -> String? {
withUnsafeTemporaryAllocation(of: CWideChar.self, capacity: maxCount) { buffer in
SetLastError(DWORD(ERROR_SUCCESS))
SetLastError(ERROR_SUCCESS)
let count = GetEnvironmentVariableW(name, buffer.baseAddress!, DWORD(buffer.count))
if count == 0 {
switch GetLastError() {
case DWORD(ERROR_SUCCESS):
case ERROR_SUCCESS:
// Empty String
return ""
case DWORD(ERROR_ENVVAR_NOT_FOUND):
case ERROR_ENVVAR_NOT_FOUND:
// The environment variable wasn't set.
return nil
case let errorCode:
Expand Down
2 changes: 1 addition & 1 deletion Sources/_TestDiscovery/Additions/WinSDKAdditions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension HMODULE {
}
} else {
// Create a toolhelp snapshot that lists modules.
guard let snapshot = CreateToolhelp32Snapshot(DWORD(TH32CS_SNAPMODULE), 0) else {
guard let snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0) else {
return nil
}
state.snapshot = snapshot
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestingTests/ABIEntryPointTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private func withTestingLibraryImageAddress<R>(_ body: (ImageAddress?) throws ->
// We can't dynamically look up a function linked into the test executable on
// ELF-based platforms.
#elseif os(Windows)
let flags = DWORD(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS)
let flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
try addressInTestingLibrary.withMemoryRebound(to: CWideChar.self, capacity: MemoryLayout<UnsafeRawPointer>.stride / MemoryLayout<CWideChar>.stride) { addressInTestingLibrary in
try #require(GetModuleHandleExW(flags, addressInTestingLibrary, &testingLibraryAddress))
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/TestingTests/Support/CErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ struct CErrorTests {
struct Win32ErrorTests {
@Test("Win32Error.description property",
arguments: [
(DWORD(ERROR_OUTOFMEMORY), "Not enough memory resources are available to complete this operation."),
(DWORD(ERROR_INVALID_ACCESS), "The access code is invalid."),
(DWORD(ERROR_ARITHMETIC_OVERFLOW), "Arithmetic result exceeded 32 bits."),
(ERROR_OUTOFMEMORY, "Not enough memory resources are available to complete this operation."),
(ERROR_INVALID_ACCESS, "The access code is invalid."),
(ERROR_ARITHMETIC_OVERFLOW, "Arithmetic result exceeded 32 bits."),
(999_999_999, "An unknown error occurred (999999999)."),
]
)
Expand Down
6 changes: 3 additions & 3 deletions Tests/TestingTests/Support/FileHandleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ struct FileHandleTests {
CreateFileW(
path,
GENERIC_READ,
DWORD(FILE_SHARE_READ | FILE_SHARE_WRITE),
FILE_SHARE_READ | FILE_SHARE_WRITE,
nil,
DWORD(OPEN_ALWAYS),
DWORD(FILE_ATTRIBUTE_NORMAL),
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
nil
)
)
Expand Down
Loading