Passing a memory address (pointer) to an extension?

Philip Semanchuk philip at semanchuk.com
Thu Oct 23 10:15:32 EDT 2008


On Oct 23, 2008, at 2:13 AM, Thomas Heller wrote:

> Philip Semanchuk schrieb:
>> 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.
>
> I suggest "O!" and a converter function calling PyLong_AsVoidPtr().


Thomas, this sounds perfect, thank you.


bye
Philip




More information about the Python-list mailing list