refcounting errors???

H

hannibal.holm

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
 
F

Fredrik Lundh

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)",

what happens if you use "(OIH)" instead ?

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top