Problems sending list/tuple to a C extension.

Christian Seberino seberino at spawar.navy.mil
Sun Nov 23 05:28:56 CET 2003


Martin

I hope the mistake in this simple code is obvious to you:

======================================================================
#include <Python.h>
                                                                                
static PyObject* test(PyObject* self, PyObject* args) {
        int a;
                                                                                
        PyArg_ParseTuple(args, "(i)", &a);
                                                                                
        printf("a = %d\n",a);
                                                                                
        return Py_BuildValue("i", &a);
};
 
static char test_doc[] = "Does nothing.\n";
 
static PyMethodDef mapper[] = {
        {"test", (PyCFunction) test, METH_VARARGS, test_doc},
        {NULL}
};
 
void inittest(void) {
        Py_InitModule3("test", mapper, test_doc);
};


======================================================================

Here is me compiling and running...

% gcc test.c -I /usr/include/python2.2 -fpic -shared -o test.so
% python
Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import test
>>> test.test( (3) )
a = 135386744
-1073750864
>>>

Thanks again for the help.

Chris

martin at v.loewis.de (Martin v. Löwis) wrote in message news:<m3brr4um84.fsf at mira.informatik.hu-berlin.de>...
> seberino at spawar.navy.mil (Christian Seberino) writes:
> 
> > I was not able to get parens (tuples) to work for either
> > successfully.  Any ideas?
> 
> You probably did something wrong. Without seeing the code, it is hard
> to tell what that might be.
> 
> Regards,
> Martin




More information about the Python-list mailing list