[ python-Bugs-1518190 ] c_void_pointer should accept a long pointer > 0x7fffffff

SourceForge.net noreply at sourceforge.net
Mon Jul 10 11:12:22 CEST 2006


Bugs item #1518190, was opened at 2006-07-06 16:46
Message generated for change (Comment added) made by theller
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1518190&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
>Status: Closed
Resolution: Accepted
Priority: 5
Submitted By: Thomas Heller (theller)
Assigned to: Thomas Heller (theller)
Summary: c_void_pointer should accept a long pointer > 0x7fffffff

Initial Comment:
Mike Fletcher reported this problem:

http://tinyurl.com/esneq

Currently, the c_void_p constructor calls
PyLong_AsVoidPtr(value), in Modules/_ctypes/cfield.c,
near line 1491.

This call should be changed to use either
PyLong_AsUnsignedLongMask() or
PyLong_AsUnsignedLongLongMask() depending on
sizeof(void *), and cast the result to (void *).

This change would also make the c_void_p behaviour more
consistent with the other c_int, c_long and so on
constructors since all of them mask the value to the
number of bits they can accept.

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

>Comment By: Thomas Heller (theller)
Date: 2006-07-10 11:12

Message:
Logged In: YES 
user_id=11105

Committed as r50513.

Neal, I'm not sure I got the #elif instead of #if issue as
you were requesting it, if not, feel free to fix that yourself.

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

Comment By: Neal Norwitz (nnorwitz)
Date: 2006-07-10 02:32

Message:
Logged In: YES 
user_id=33168

This patch is fine.  Please try to apply before the freeze
for b2.

Also, please use #elif instead of nested #if.  It makes the
code a little shorter and easier to read.

This looks like a bug fix which is fine, though I'm not sure
of all the consequences of the change.  Be sure to add a
note to Misc/NEWS.


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

Comment By: Thomas Heller (theller)
Date: 2006-07-06 19:03

Message:
Logged In: YES 
user_id=11105

Assigning to Neal for review (please).  The #if block is not
really needed imo, but I used it for clarity - it is copied
verbatim from Objects/longobject.c, which would throw
compile errors if the conditions are not fulfilled.

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

Comment By: Thomas Heller (theller)
Date: 2006-07-06 18:56

Message:
Logged In: YES 
user_id=11105

Attached a patch, with tests, that fixes this bug.
PyInt_AsUnsignedLongMask() and
PyInt_AsUnsignedLongLongMask() is what we need to use.

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

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


More information about the Python-bugs-list mailing list