473,327 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

refcounting errors???

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

Nov 2 '06 #1
2 874
ha***********@gmail.com wrote:

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>

Nov 3 '06 #2
Bingo, that works.

Thanks!

Fredrik Lundh wrote:
ha***********@gmail.com wrote:

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>
Nov 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: mikey_boy | last post by:
Hello! Curious if anyone could give me a hand. I wrote this PHP script with makes a simple connection to a mysql database called firstdb and just pulls back the results and displays on the...
10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
2
by: Pierre Phaneuf | last post by:
At my workplace, we are in the process of migrating to a component system similar to COM (but not COM itself, as we have some space and portability requirements) that uses refcounting for resource...
12
by: joe martin | last post by:
In recent discussions relating to what to use for a new project which integrated the work of two, previously seperate, teams we got to the subject of our respective string implementations. One team...
0
by: doli | last post by:
Hi, I have the following piece of code which iterates through the potential errors: i =0 For Each error_item in myConn.Errors DTSPackageLog.WriteStringToLog myConn.Errors(i).Description...
4
by: johnb41 | last post by:
I have a form with a bunch of textboxes. Each text box gets validated with the ErrorProvider. I want the form to process something ONLY when all the textboxes are valid. I found a solution,...
4
by: st_ev_fe | last post by:
Hi people, I've been doing C for about 7 years now. But I'm new to C++. I've decided that C++'s operator overloading could be very handy. I'm writing something much like auto_ptr, except for...
24
by: pat | last post by:
Hi everyone, I've got an exam in c++ in two days and one of the past questions is as follows. Identify 6 syntax and 2 possible runtime errors in this code: class demo {
8
by: ImOk | last post by:
I just have a question about trapping and retrying errors especially file locking or database locks or duplicate key errors. Is there a way after you trap an error to retry the same line that...
2
by: =?Utf-8?B?UmFuZHlz?= | last post by:
This just started when I updated to sp 1 working on a APS.net, Visual Studio 2008, c# Project. When I open a project, I get tons of Errors showing in the list 300+ if I double click on them I go...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.