Passing a memory address (pointer) to an extension?
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Wed Oct 22 23:13:36 EDT 2008
More information about the Python-list mailing list
Wed Oct 22 23:13:36 EDT 2008
- Previous message (by thread): Passing a memory address (pointer) to an extension?
- Next message (by thread): Passing a memory address (pointer) to an extension?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
En Wed, 22 Oct 2008 19:10:27 -0200, Philip Semanchuk <philip at semanchuk.com> escribió: > I'm writing a Python extension in C that wraps a function which takes a > void * as a parameter. (The function is shmat() which attaches a chunk > of shared memory to the process at the address supplied by the caller.) > I would like to expose this function to Python, but I don't know how to > define the interface. > > Specifically, when calling PyArg_ParseTuple(), what letter should I use > to represent the pointer in the format string? The best idea I can come > up with is to use a long and then cast it to a void *, but assuming that > a long is big enough to store a void * is a shaky assumption. I could > use a long long (technically still risky, but practically probably OK) > but I'm not sure how widespread long longs are. Are you *really* sure you want to supply a specific address argument? Most of the time (if not always, unless you're doing really low level stuff) a NULL is perfectly adequate. Anyway, if it's going to be called from Python, the argument will be a Python integer (or long) object); you may get the value using PyInt_AsSsize_t -- Gabriel Genellina
- Previous message (by thread): Passing a memory address (pointer) to an extension?
- Next message (by thread): Passing a memory address (pointer) to an extension?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list