This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Error when int sent to PyLong_AsUnsignedLong
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: crnixon, loewis
Priority: normal Keywords: patch

Created on 2004-09-08 21:03 by crnixon, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
longobject.diff crnixon, 2004-09-08 21:03 Patch for Objects/longobject.c
Messages (4)
msg46869 - (view) Author: Clinton R. Nixon (crnixon) Date: 2004-09-08 21:03
When sending a Python integer as an argument to
PyLong_AsUnsignedLong, the following error occurs

SystemError: Objects/longobject.c:240: bad argument to
internal function

This error comes from the fact that
PyLong_AsUnsignedLong, unlike PyLong_AsLong, does not
check to see if the number is a long or integer, but
only a long.

This patch checks to see if the number is an integer,
and if so, calls PyInt_AsUnsignedLongMask.
msg46870 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2004-09-18 16:11
Logged In: YES 
user_id=21627

Why is it desirable to accept ints in PyLong_AsUnsignedLong?
msg46871 - (view) Author: Clinton R. Nixon (crnixon) Date: 2004-09-19 22:41
Logged In: YES 
user_id=350049

The reasons I submitted the patch:

* There's a precedent in the PyLong_AsLong code.
* The error was causing PyCDK (Python binding to the Curses
Development Kit) to segfault.
* Seeing as there's no data lost converting from int to
long, it makes sense to go ahead and convert instead of
crapping out.
msg46872 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2004-09-20 06:18
Logged In: YES 
user_id=21627

I see. The precedent of PyLong_AsLong is a good rationale.
However, your patch is incorrect: It would return a value
for negative integers, whereas it should raise an
OverflowError in this case. I have committed a different
patch as longobject.c 1.165, NEWS 1.1138, which also adds
the same extension to PyLong_AsUnsignedLongMask.
History
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40886
2004-09-08 21:03:12crnixoncreate