-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
thread.get_ident() should return unsigned value #50781
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
Comments
In glibc library (on linux) pthread_t is defined as: typedef unsigned long int pthread_t; But python thread module interprets this value as signed long. Reproduce:
>>> import thread
>>> thread.get_ident()
In some cases it returns negative value.
Checked in python 2.4, 2.5, 2.6 Proposal: Other possibility is to change only returned value by get_ident Background: |
Can a C guru comment on this please. |
Well, the issue is that signedness differs depending on the platform. Under Windows, thread ids are signed (DWORD). Satisfying all cases would complicate things quite a bit. |
no, DWORD is a 32-bit unsigned integer |
Oops, my bad. |
Here is a patch, which made all thread id to be unsigned. |
You could add a test for it. |
On Linux, the following C program tells me that pthread_t is unsigned. #include <pthread.h>
#include <stdio.h>
#define TYPE_IS_SIGNED(TYPE) ((TYPE)-1 < (TYPE)0)
int main()
{
printf("signed? %i\n", TYPE_IS_SIGNED(pthread_t));
return 0;
} So it's fair to modify threading.get_ident() to return an unsigned number. But I disagree to change stable Python versions, it may break applications. Oh, I wrote write_thread_id() in Python/traceback.c and this function already casts the thread identifier to an unsigned number ;-) |
Here is updated patch. Added few tests. |
Cool. I sent a review. |
Thank you Victor for your review. Here is updated patch. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: