[Pyrex] Python/C API or void * problems...

Greg Ewing greg at cosc.canterbury.ac.nz
Mon Nov 3 00:15:57 CET 2003


Scott Robinson <scott_pyrex at scott.tranzoa.net>:

> I have a function I'm interfacing similar to the following:
> 
> int process_data (void *data, int data_length)
> 
> I can't seem to properly define access to the PyString accessors:
> 
> cdef extern from "Python.h" :
>   char *  PyString_AsString   (object string)
>   int     PyString_Size       (object string)
> 
> Is this correct, or should "object" be "PyObject *"? Pyrex complains with
> the original definition.

No, that's correct. Whatever complaint you got must have been
caused by something else.

You don't really need PyString_AsString, since Pyrex will do
that itself given the right conditions. The following should
do what you want:

cdef extern from "Python.h" :
  int PyString_Size(object string)

cdef extern from "something.h":
  int process_data (void *data, int data_length)

def py_process_data(char *data):
  process_data(data, PyString_Size(data))

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+




More information about the Pyrex mailing list