-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
_Py_ThreadId() fails when compiled using GCC on Windows #124609
Comments
I'd be happy to review a PR to support GCC on Windows |
Thanks @colesbury, I'll put a PR together tomorrow. Should be a very minor change I think |
Just looking at the proposed code now, I think you'll need to check both If GCC on Windows provides the same intrinsics but doesn't define the compatible |
Hi @zooba, I just did a quick check and gcc on windows doesn't define _MSC_VER (at least not using winlibs' gcc 14.1.0). Happy to use MS_WINDOWS. _WIN32 is used elsewhere in the code already but if new code is using that in preference then let's go with that. The problem with the code right now ( Line 174 in a4d1fdf
With the change to MS_WINDOWS, if __readgsqword is not available then the code will fail to compile, which seems preferable to it compiling the wrong code and causing an error at runtime. Perhaps a specific check for a minimum _MSC_VER could be added (if defined) to give an explicit compile error? Do you know the min value for _MSC_VER that is required? Looks like it's been there since at least VS 2015, but the docs online don't go back further than that (https://learn.microsoft.com/en-us/cpp/intrinsics/readgsbyte-readgsdword-readgsqword-readgsword?view=msvc-140). Thanks! ps. I see the #include <intrin.h> isn't needed as it's already added elsewhere |
Right, so you need a check for when the target OS is Windows ( Maybe GCC on Windows has the same intrinsics, but I'm not aware of anything that requires or enforces that. If it is somehow enforced, then sure, but if not then we should detect GCC on Windows explicitly, even if it uses the same code. Trying to detect too many things with too few conditions is why this bug came up in the first place. Now that we know, let's use the right conditions for all the cases. I don't know those off the top of my head, so when you figure them out, submit a PR and we ought to be able to tell if it looks reasonable or not. |
…honGH-124663) (cherry picked from commit 0881e2d) Co-authored-by: Tony Roberts <tony@pyxll.com>
Bug report
Bug description:
It should be possible to build a C extension module using GCC on Windows, but when defining Py_GIL_DISABLED any call to _Py_ThreadId fails.
The if/defs in _Py_ThreadId look for _MSC_VER to be defined to determine whether it's a Windows build or not, but that specifies the VS version and not whether the build is for Windows or not.
Instead it would be better to use _WIN32 (see https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170)
Something along these lines...
CPython versions tested on:
3.13
Operating systems tested on:
Windows
Linked PRs
The text was updated successfully, but these errors were encountered: