hello,all.

  I wrote a module in C as below, BUT msg() method cannot work
allright.

#include <stdio.h>
#include <python2.4/Python.h>

static PyObject *Roka_msg(PyObject *self,PyObject *args)
{
        printf("Roka Python lib. Version 1.0\n");
}

static PyObject *Roka_func(PyObject *self,PyObject *args)
{
        long arg;
        if(!PyArg_ParseTuple(args,"l",&arg)){
                return NULL;
        }
        return Py_BuildValue("l",arg*2);
}

//----------------------------------------------------------

static struct PyMethodDef functions[]=
{
        {"msg",Roka_msg,METH_VARARGS},
        {"func",Roka_func,METH_VARARGS},
        {NULL,NULL,0},
};


void initRoka(void)
{
        (void)Py_InitModule("Roka",functions);
}
-------------------------------------------------------------------------
python result:
>>>import Roka
>>>Roka.msg()
Roka Python lib. Version 1.0
Segmentation fault

I throw out a Segmentation fault after display my message.
Can anyone tell me why?

thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to