[Patches] [ python-Patches-1024670 ] Error when int sent to PyLong_AsUnsignedLong

SourceForge.net noreply at sourceforge.net
Mon Sep 20 08:18:23 CEST 2004


Patches item #1024670, was opened at 2004-09-08 23:03
Message generated for change (Settings changed) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1024670&group_id=5470

Category: Core (C code)
Group: Python 2.4
>Status: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Clinton R. Nixon (crnixon)
Assigned to: Nobody/Anonymous (nobody)
Summary: Error when int sent to PyLong_AsUnsignedLong

Initial Comment:
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.

----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2004-09-20 08:18

Message:
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.

----------------------------------------------------------------------

Comment By: Clinton R. Nixon (crnixon)
Date: 2004-09-20 00:41

Message:
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.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2004-09-18 18:11

Message:
Logged In: YES 
user_id=21627

Why is it desirable to accept ints in PyLong_AsUnsignedLong?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1024670&group_id=5470


More information about the Patches mailing list