[issue3328] When PyObject_CallMethod fails, refcount is incorrect

Amaury Forgeot d'Arc report at bugs.python.org
Thu Jul 10 00:02:37 CEST 2008


Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:

Thanks for the short case. It makes everything simpler.
First, note that you get the same behaviour with python-only code:

import re, sys
class Issue3328:
    def f(self):
        # unbalanced parenthesis
        x = re.compile('(123')

o = Issue3328()
sys.getrefcount(o)      # prints 2
o.f()
sys.getrefcount(o)      # prints 3

And this is normal: the last exception contains the traceback (stored in
sys.last_traceback) which contains the live context frames which
reference the "self" variable which is the additional reference to our
object.
Try to provoke another error (any SyntaxError will do) and see the
refcount decrease.

Now, the three variables sys.last_traceback, sys.last_type and
sys.last_value contain the info about the last *uncaught* exception.
An exception is said to be *uncaught* when PyErr_Print() is called to
print it... That's what happens at the interactive prompt, of course,
and in your C code.

Looking at python source code, PyErr_Print() is actually a single call
to PyErr_PrintEx(1), the parameter (1) is named "set_sys_last_vars"
(aha!). You should try to call PyErr_PrintEx(0) instead, and see if this
improves something.

Then a documentation path will be very welcomed ;-)

----------
resolution:  -> works for me
status: open -> pending

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3328>
_______________________________________


More information about the Python-bugs-list mailing list