Skip to content

[Windows] Fix Int32(bitPattern:) call failure #708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 27, 2024

Conversation

jmschonfeld
Copy link
Contributor

The Windows toolchain build for x86 was failing with:

C:\Users\swift-ci\jenkins\workspace\swift-PR-build-toolchain-windows\swift-foundation\Sources\FoundationEssentials\ProcessInfo\ProcessInfo.swift:141:34: error: cannot convert value of type 'DWORD' (aka 'UInt') to expected argument type 'UInt32'
139 |     var processIdentifier: Int32 {
140 | #if os(Windows)
141 |         return Int32(bitPattern: GetProcessId(GetCurrentProcess()))
    |                                  `- error: cannot convert value of type 'DWORD' (aka 'UInt') to expected argument type 'UInt32'
142 | #else
143 |         return Int32(getpid())

In SCL-F we just call Int32(GetProcessId(GetCurrentProcess())) instead which works so this changes the swift-foundation implementation to do the same so that it is compatible across architectures.

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test Windows platform

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is fine for now. The problem is that GetProcessId returns an unsigned value, so this can now trap right?

@jmschonfeld
Copy link
Contributor Author

I guess this is fine for now. The problem is that GetProcessId returns an unsigned value, so this can now trap right?

Ah that's true, I was trying to remember why we did this and I think that's why. Perhaps instead I should use return Int32(bitPattern: UInt32(GetProcessId(GetCurrentProcess()))) so that it traps if the value is more than 32 bits wide but still converts to a negative number instead of trapping if it's just within Int32.max ..< UInt32.max. Do you think that'd be better?

@compnerd
Copy link
Member

Yes, I think that described behaviour was what we were after and missed the need for the UInt32 initialiser.

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test Windows platform

1 similar comment
@jmschonfeld
Copy link
Contributor Author

@swift-ci please test Windows platform

@jmschonfeld
Copy link
Contributor Author

The windows toolchain build got a lot farther with this change, and the Windows test failure here is the known test_writeToSpecialFile test failure

@jmschonfeld jmschonfeld merged commit d3610e9 into swiftlang:main Jun 27, 2024
2 of 3 checks passed
@jmschonfeld jmschonfeld deleted the windows/fix-arch-failures branch June 27, 2024 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants