-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-130115: fix thread identifiers for 32-bit musl #130391
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
+22
−9
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
51d6579
Return the main thread's short identifier on certain platforms
vfazio a9ca268
Add NEWS entry
vfazio f6ad25d
Merge branch 'main' into vfazio-thread_get_ident
vfazio b93868e
Merge remote-tracking branch 'upstream/main' into vfazio-thread_get_i…
vfazio 7a4de5f
Move pthread_t to ident conversion to a shared function
vfazio af1233b
Reword NEWS entry
vfazio 7bdfd34
Revert "Return the main thread's short identifier on certain platforms"
vfazio dc7c497
Merge remote-tracking branch 'upstream/main' into vfazio-thread_get_i…
vfazio 140a4d8
simplify conversion logic
vfazio 63812b5
Merge remote-tracking branch 'upstream/main' into vfazio-thread_get_i…
vfazio 4ae6d7e
Merge branch 'main' into vfazio-thread_get_ident
vfazio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Core_and_Builtins/2025-02-21-00-12-24.gh-issue-130115.mF-rP6.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix an issue with thread identifiers being sign-extended on some platforms. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is potentially lossy compared to the previous version if
SIZEOF_PTHREAD_T > SIZEOF_LONG
. Previously we would cast directly to aPyThread_ident_t
(anunsigned long long
), whereas we now cast through anunsigned long
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand your concern.
This was an edge case in
PyThread_start_new_thread
, my guess is that it was there for the situations wherepthread_t
was not a ulong and was, instead, a pointer or struct.It's probably fine to drop the condition in
_pthread_t_to_ident
and let the caller here truncate it since this API is specifically returning a ULONG and not aPyThread_ident_t
.Looking at the history:
2565bff
635f6fb
The cast through ulong* was for Alpha OSF which was dropped from PEP 11 a few years ago (CPython 3.3) https://bugs.python.org/issue8606. My guess is it was also defined as a pointer or struct type and this was a way to work around it by returning at least
long
bytes.I think if we find other platforms where we need to support this workaround, they can be chained to the MUSL
#ifdef
I think. The only time it would maybe be a problem is ifsizeof(uintptr_t)
<sizeof(ulong)
.If others agree, I can drop the condition so the function looks like so:
I do not suggest this as a long term solution; I do think we need to work towards making this opaque. I'm just trying to find something that is a stop-gap that can be ported back with relative ease that doesn't cause a regression.