Hi,
I have a few problems with the C-API. I am trying to embed Python in a
simulator that I am writing (I am replacing my previous Guile-based
scripting system (mostly as pyrex is a lot nicer than swig and the fact
that PyUnit is really nice)).
Non the less, my problems come when dealing with callbacks from my
C-code to python 2.4.4.
This is the python code that is executed (through PyRun_SimpleFile):
----------
import io
import config
config.setScreenSize(800, 600)
def foo(a, b, c):
print a, b, c
io.registerButtonHandler("foo", foo) # register foo as io-callback
io.bindKeyUp("a", "foo") # bind the a-key to the
foo function
----------
Where io and config are two pyrex generated modules.
Now, when I start tapping the a-key foo is activated (and prints its
arguments), but is only done so 8 times, on the 9th time the app
crashes in the internal_print function invoked by the print-statement.
The registration of the callback is done by
Py_INCREF(f);
ah->u.button.u.s = f;
The invokation of the foo-function goes somewhere in the line of:
PyObject *up = PyBool_FromLong(1L);
if (! up) PyErr_Print();
PyObject *res = PyObject_CallFunction(action.u.button.u.s,
"(NIH)",
up, (unsigned int)key, (unsigned short)special);
if (! res) PyErr_Print();
Py_XDECREF(res);
Py_XDECREF(up);
I would suppose that I have made a mistake somewhere, but cannot really
figure out what. So I would appreciate any pointers on what I can have
done wrong.
Best regards and thanks in advance,
Mattias