Passing a memory address (pointer) to an extension?

Philip Semanchuk philip at semanchuk.com
Wed Oct 22 23:10:27 CEST 2008


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.

Any advice appreciated.

Thanks
Philip



More information about the Python-list mailing list