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(PyObj ect *self,PyObject *args)
{
printf("Roka Python lib. Version 1.0\n");
}
static PyObject *Roka_func(PyOb ject *self,PyObject *args)
{
long arg;
if(!PyArg_Parse Tuple(args,"l", &arg)){
return NULL;
}
return Py_BuildValue(" l",arg*2);
}
//----------------------------------------------------------
static struct PyMethodDef functions[]=
{
{"msg",Roka_msg ,METH_VARARGS},
{"func",Roka_fu nc,METH_VARARGS },
{NULL,NULL,0},
};
void initRoka(void)
{
(void)Py_InitMo dule("Roka",fun ctions);
}
-------------------------------------------------------------------------
python result:
Roka Python lib. Version 1.0
Segmentation fault
I throw out a Segmentation fault after display my message.
Can anyone tell me why?
thanks.
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(PyObj ect *self,PyObject *args)
{
printf("Roka Python lib. Version 1.0\n");
}
static PyObject *Roka_func(PyOb ject *self,PyObject *args)
{
long arg;
if(!PyArg_Parse Tuple(args,"l", &arg)){
return NULL;
}
return Py_BuildValue(" l",arg*2);
}
//----------------------------------------------------------
static struct PyMethodDef functions[]=
{
{"msg",Roka_msg ,METH_VARARGS},
{"func",Roka_fu nc,METH_VARARGS },
{NULL,NULL,0},
};
void initRoka(void)
{
(void)Py_InitMo dule("Roka",fun ctions);
}
-------------------------------------------------------------------------
python result:
>>>import Roka
>>>Roka.msg()
>>>Roka.msg()
Segmentation fault
I throw out a Segmentation fault after display my message.
Can anyone tell me why?
thanks.
Comment