Commit 7212306
authored
CPython's pthread-based thread identifier relies on pthread_t being able
to be represented as an unsigned integer type.
This is true in most Linux libc implementations where it's defined as an
unsigned long, however musl typedefs it as a struct *.
If the pointer has the high bit set and is cast to PyThread_ident_t, the
resultant value can be sign-extended [0]. This can cause issues when
comparing against threading._MainThread's identifier. The main thread's
identifier value is retrieved via _get_main_thread_ident which is backed
by an unsigned long which truncates sign extended bits.
>>> hex(threading.main_thread().ident)
'0xb6f33f3c'
>>> hex(threading.current_thread().ident)
'0xffffffffb6f33f3c'
Work around this by conditionally compiling in some code for non-glibc
based Linux platforms that are at risk of sign-extension to return a
PyLong based on the main thread's unsigned long thread identifier if the
current thread is the main thread.
[0]: https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Arrays-and-pointers-implementation.html
---------
Signed-off-by: Vincent Fazio <[email protected]>
1 parent 345baa7 commit 7212306
File tree
2 files changed
+22
-9
lines changed- Misc/NEWS.d/next/Core_and_Builtins
- Python
2 files changed
+22
-9
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
309 | 327 | | |
310 | 328 | | |
311 | 329 | | |
312 | 330 | | |
313 | 331 | | |
314 | 332 | | |
315 | 333 | | |
316 | | - | |
| 334 | + | |
317 | 335 | | |
318 | | - | |
319 | 336 | | |
320 | 337 | | |
321 | 338 | | |
| |||
328 | 345 | | |
329 | 346 | | |
330 | 347 | | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
| 348 | + | |
336 | 349 | | |
337 | 350 | | |
338 | 351 | | |
| |||
357 | 370 | | |
358 | 371 | | |
359 | 372 | | |
360 | | - | |
361 | | - | |
| 373 | + | |
362 | 374 | | |
363 | 375 | | |
364 | 376 | | |
| |||
0 commit comments