How to map size_t using ctypes?

  • Thread starter Philip Semanchuk
  • Start date
P

Philip Semanchuk

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.


Suggestions appreciated.

Thanks
Philip
 
D

Diez B. Roggisch

Philip said:
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
 
P

Philip Semanchuk

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.

D'oh! [slaps forehead]

That will teach me to RTFM. In my 2.5 doc, it's not listed in the
"Fundamental data types" section in the tutorial, but it is mentioned
in "Fundamental data types" in the ctypes reference. You'd be
surprised at the amount of Googling I did without learning this on my
own.

Thanks
Philip
 
G

Gabriel Genellina

En Mon, 06 Jul 2009 13:29:21 -0300, Philip Semanchuk
from ctypes import c_size_t

D'oh! [slaps forehead]

That will teach me to RTFM. [...] You'd be surprised at the amount of
Googling I did without learning this on my own.

Yep, seems like these terms in particular are hard to find. Searching for
+ctypes +size_t, the first "good" result comes only at page 3. Bad luck...
:(
 
P

Philip Semanchuk

En Mon, 06 Jul 2009 13:29:21 -0300, Philip Semanchuk
Philip Semanchuk wrote:

I can't figure out how to map a C variable of size_t via Python's
ctypes module.

from ctypes import c_size_t

D'oh! [slaps forehead]

That will teach me to RTFM. [...] You'd be surprised at the amount
of Googling I did without learning this on my own.

Yep, seems like these terms in particular are hard to find.
Searching for
+ctypes +size_t, the first "good" result comes only at page 3. Bad
luck...
:(

Fortunately, through my ignorance I may provide enlightenment...this
conversation is now hit #3 on page 1 =)

If I paste the URL here, will I create an infinite loop?
http://www.google.com/search?q=+ctypes++size_t
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top