error on crude test of embedding python in c++ HELP PLEASE
Thomas Heller
theller at python.net
Tue Dec 7 15:50:29 EST 2004
"Donnie Leen" <Kingdom.Lin at yeah.net> writes:
> I wrote a program to test calling c function from python code embedding in c
> as following, it cause error after running a while(about 398 circle). I
> test it in msvc6, python2.3, windows 2k, could anyone tell me why this
> happened since i just work according to the document? Thanks first.
>
> Donnie Leen
>
>
> source code:
>
>
> #include <Python.h>
>
> static PyObject* pymyfun( PyObject* self, PyObject* args )
> {
> return Py_None; // do nothing
You forgot an Py_INCREF here:
Py_INCREF(Py_None);
return Py_None; // do nothing
> }
> static PyMethodDef emb_methods[] = {
> { "fun", pymyfun, METH_VARARGS, "doc." },
> {NULL, NULL, 0, NULL}
> };
>
> void main( )
> {
> Py_Initialize( );
>
> PyObject* r = Py_InitModule( "mymodule", emb_methods );
> PyRun_SimpleString( "import mymodule" );
> while ( 1 )
> {
> // error occur after 398 loops here
> PyRun_SimpleString( "mymodule.fun( 'testest' )" );
> }
>
> Py_Finalize();
> }
More information about the Python-list
mailing list