Swig and pointers
Miki Tebeka
mtebeka at qualcomm.com
Thu Oct 6 06:21:47 EDT 2005
Hello Java,
> ...
> extern int doIt(char *a, MY_DIGIT **digit);
> %include cpointer.i
> %pointer_functions(MY_DIGIT, md_prt);
Don't you mean md_ptr?
> %typemap(in) (char *a, MY_DIGIT **argv) {
> /* Check if is a list */
> if (PyList_Check($input)) {
> int i;
> $1 = PyList_Size($input);
> $2 = (MY_DIGIT **) malloc(($1+1)*sizeof(long *));
> for (i = 0; i < $1; i++) {
> PyObject *o = PyList_GetItem($input,i);
> if (PyString_Check(o))
> $2[i] = PyString_AsString(PyList_GetItem($input,i));
> else {
> PyErr_SetString(PyExc_TypeError,"list must contain strings");
> free($2);
> return NULL;
> }
> }
> $2[i] = 0;
> } else {
> PyErr_SetString(PyExc_TypeError,"not a list");
> return NULL;
> }
> }
>
> %typemap(freearg) (char *a, MY_DIGIT **argv) {
> free((MY_DIGIT *) $2);
> }
>
>
> ..from Python I am trying
>
> >> ptr = []
> >> doIt("blah", ptr)
>
> I thought this was the correct approach as described here:
> http://www.swig.org/Doc1.3/SWIGDocumentation.html#Python_nn59
>
> However, python comes back and says "TypeError: argument number 2: a
> 'MY_DIGIT **' is expected, 'list([])' is received"
>
> ..any ideas?
Didn't check it but from http://www.swig.org/Doc1.3/Library.html it looks
like you need to do:
ptr = new_md_prt()
HTH.
--
------------------------------------------------------------------------
Miki Tebeka <mtebeka at qualcomm.com>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 193 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20051006/f112a003/attachment.sig>
More information about the Python-list
mailing list