SWIG question
Brian Zhou
brian_zhou at NOSPAMtechie.com
Thu Oct 4 23:31:15 EDT 2001
I figured it out myself, need to write a typemap myself.
-Brian
"Brian Zhou" <brian_zhouNOSPAM at techie.com> wrote in message
news:1002241259.529836 at cswreg.cos.agilent.com...
> 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.
>
> -Brian
>
>
More information about the Python-list
mailing list