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.

Author rcoyner
Recipients nikratio, rcoyner, robotify, theller
Date 2010-03-01.02:58:31
SpamBayes Score 0.0007294849
Marked as misclassified No
Message-id <1267412314.09.0.0723729940766.issue6729@psf.upfronthosting.co.za>
In-reply-to
Content
You don't want to do c_size_t = c_void_p because that will prevent type checking. We want c_size_t to be integers; setting it to c_void_p will accept other values. The lines that define c_size_t are doing a sizeof check to determine how many bits the CPU supports, and c_size_t should represent unsigned integers [1].

On a 16-bit machine: c_size_t = c_uint
On a 32-bit machine: c_size_t = c_ulong
On a 64-bit machine: c_size_t = c_ulonglong

Now, ssize_t is like size_t, except that it is signed [2]. So if I am not mistaken, all we have to do is:

if sizeof(c_uint) == sizeof(c_void_p):
    c_size_t = c_uint
    c_ssize_t = c_int
elif sizeof(c_ulong) == sizeof(c_void_p):
    c_size_t = c_ulong
    c_ssize_t = c_long
elif sizeof(c_ulonglong) == sizeof(c_void_p):
    c_size_t = c_ulonglong
    c_ssize_t = c_longlong


Patch attached with documentation and unit test.


[1] - http://www.gnu.org/software/libc/manual/html_node/Important-Data-Types.html
[2] - http://www.gnu.org/software/libc/manual/html_node/I_002fO-Primitives.html
History
Date User Action Args
2010-03-01 02:58:34rcoynersetrecipients: + rcoyner, theller, nikratio, robotify
2010-03-01 02:58:34rcoynersetmessageid: <1267412314.09.0.0723729940766.issue6729@psf.upfronthosting.co.za>
2010-03-01 02:58:32rcoynerlinkissue6729 messages
2010-03-01 02:58:32rcoynercreate