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: c_void_pointer should accept a long pointer > 0x7fffffff
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: theller Nosy List: nnorwitz, theller
Priority: normal Keywords:

Created on 2006-07-06 14:46 by theller, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
c_void_p.patch theller, 2006-07-06 16:57 Patch against current SVN trunk.
Messages (5)
msg29076 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2006-07-06 14:46
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.
msg29077 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2006-07-06 16:56
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.
msg29078 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2006-07-06 17:03
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.
msg29079 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-07-10 00:32
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.
msg29080 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2006-07-10 09:12
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.
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43626
2006-07-06 14:46:33thellercreate