-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
negative PyLong -> C unsigned integral, TypeError or OverflowError? #49425
Comments
At Objects/longobject.c, in almost all cases int
_PyLong_AsByteArray(PyLongObject* v,
unsigned char* bytes, size_t n,
int little_endian, int is_signed)
{
<...>
if (!is_signed) {
PyErr_SetString(PyExc_TypeError,
"can't convert negative long to
unsigned");
return -1;
}
<...>
} |
This also affects 3.1. Note that the current behaviour (or rather, its effects in http://docs.python.org/dev/c-api/long.html it says for PyLong_AsUnsignedLongLong: "Return a C unsigned long long from a Python long integer. If pylong ...which suggests that the choice of TypeError was intentional. It If this change is made, then test_struct needs fixing: the change |
Looks like this was changed in a checkin by Tim Peters in r21099; before Tim, any comments? Lisandro, do you have any interest in contributing a patch for this? The |
I can contribute a patch. However, I would like to wait until Tim |
You may be in for a long wait! I hesitate to make the heretical |
Mark, here you have a patch. I've only 'make test' on a 32bit Linux box Just two comments:
|
Thanks for the patch! I agree that the 'versionchanged' reference should be added in the docs. Here's a modified version of your patch that adds a test for Lisandro, does this updated patch work for you? |
It worked for me. BTW, 'make test' did not noticed the change in Modules/testcapi_long.h, |
Committed, r69498 (trunk) and r69499 (py3k). |
...and your patch for setup.py applied in r69500, r69501, r69502, r69503. Thank you! |
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: