strange thing after call PyObject_CallMethod

Exe ashen_light at messir.net
Sat Jan 3 12:31:42 EST 2009


Hello everybody!

I'm in trouble. This code shows that ob_refcnt increased by python
if "on_recv" method throws exception. This occurs only if base C-class  
subclassed
in python code.
======
my_old_refcnt = Py_REFCNT(self);
py_result = PyObject_CallMethod(self, "on_recv", "(y#)", recvbuf, result);
my_new_refcnt = Py_REFCNT(self);

log_debug("refcnt before call %d", my_old_refcnt);
log_debug("after call: %d\n", my_new_refcnt);
======


Output:
======
tcpconn.c: refcnt before call 1
tcpconn.c: after call: 2
======

If PyObject_CallMethod returns success(any non-NULL value) anything okay.
Tested on Python 3.1a0 (py3k:68145M, Jan  2 2009, 20:51:28).

Why this happenning and who makes Py_INCREF(self)?


PS garbage collector knows about this so on exit
PyGC_Collect deletes instance.

-- 
//wbr
Kandalintsev Alexandre



More information about the Python-list mailing list