How to map size_t using ctypes?

Diez B. Roggisch deets at nospam.web.de
Mon Jul 6 18:10:36 CEST 2009


Philip Semanchuk wrote:

> Hi all,
> I can't figure out how to map a C variable of size_t via Python's
> ctypes module. Let's say I have a C function like this:
> 
> void populate_big_array(double *the_array, size_t element_count) {...}
> 
> How would I pass parameter 2? A long (or ulong) will (probably) work
> (on most platforms), but I like my code to be more robust than that.
> Furthermore, this is scientific code and it's entirely possible that
> someone will want to pass a huge array with more elements than can be
> described by a 32-bit long.

from ctypes import c_size_t

doesn't work for you? On my system, it's aliased to c_ulong, but I guess
that's depending on the platfrom of course.

Diez



More information about the Python-list mailing list