Seg fault in python extension module

Luke Miller dodgyville at gmail.com
Sat Jun 3 01:51:02 CEST 2006


Hello,

I am working on my first python module based on a c program. The
module builds and installs OK using dist-utils, and imports fine into
python. However, when I try and use the one wrapper
("modgl.glVertex4f(1, 2, 3, 1)") in the module, it seg faults.

Can anyone spot why this isn't working, or recommend a way to debug
these things.

Thanks,
Luke

#include <Python.h>

static PyObject *_wrap_glVertex4f(PyObject *self, PyObject *args) {
    PyObject *resultobj = NULL;
    float arg1 ;
    float arg2 ;
    float arg3 ;
    float arg4 ;
    PyObject * obj0 = 0 ;
    PyObject * obj1 = 0 ;
    PyObject * obj2 = 0 ;
    PyObject * obj3 = 0 ;

    if(!PyArg_ParseTuple(args,(char
*)"OOOO:glVertex4f",&obj0,&obj1,&obj2,&obj3)) goto fail;
    {
        arg1 = (float)(PyFloat_AsDouble(obj0));
    }
    {
        arg2 = (float)(PyFloat_AsDouble(obj1));
    }
    {
        arg3 = (float)(PyFloat_AsDouble(obj2));
    }
    {
        arg4 = (float)(PyFloat_AsDouble(obj3));
    }
    glVertex4f(arg1,arg2,arg3,arg4);

    Py_INCREF(Py_None); resultobj = Py_None;
    return resultobj;
    fail:
    return NULL;
};


static PyMethodDef modglMethods[] = {
	 { (char *)"glVertex4f", _wrap_glVertex4f, METH_VARARGS, NULL},
	 { NULL, NULL, 0, NULL }
};


PyMODINIT_FUNC modgl(void)
{
    (void) Py_InitModule("modgl", modglMethods);
};


int
main(int argc, char *argv[])
{
    /* Pass argv[0] to the Python interpreter */
    Py_SetProgramName(argv[0]);

    /* Initialize the Python interpreter.  Required. */
    Py_Initialize();

    /* Add a static module */
    initmodgl();
	return 0;
};



More information about the Python-list mailing list