SWIG question

Brian Zhou brian_zhouNOSPAM at techie.com
Fri Oct 5 02:20:58 CEST 2001

I want to use SWIG to wrap a C routine that accepting a python string:

>>> c_routine("abc")

and in the c_routine(), I need to get the string pointer and length,
probably using

    char *ptr, int size;
    PyArg_Parse(str, "s#", &ptr, &size);

I tried:

    int routine(PyObject *s) {
        char *ptr, int size;
        PyArg_Parse(str, "s#", &ptr, &size);
        // ...

it compiled ok, but when called,

>>> from testmodule import *
>>> p = routine("abc")
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "queue_module.py", line 35, in routine
    val = queue_modulec.routine(arg0)
TypeError: Type error in argument 1 of routine. Expected _PyObject_p.

How should I write the correct C routine?

Thanks for any suggestions.


More information about the Python-list mailing list