Re: Profiler called with wrong args by system callback

Guido.van.Rossum@cwi.nl
Wed, 25 Jan 1995 11:25:30 +0100

Jim, your clear exposition of the problem finally made me realize
what's going on.

If I'm right, it has been fixed in Python 1.2, which is in beta right
now. (Have you tried the beta release yet?) What seems to happen is
that your __setitem__ is called and raises an exception. The
interpreter catches this exception and calls err_clear(). However in
all versions before 1.2(beta), the err_clear() erroneously did not
clear the stack trace set aside by the exception.

If you want to try this in earlier versions of Python, you can add the
following to the end of err_clear() in errors.c:

/* Also clear interpreter stack trace */
tb = tb_fetch();
XDECREF(tb);

(There are other changes needed to fix the problem in its whole
generality, which is why it's better to wait for 1.2 or pick up the
beta, but this should take care of the immediate problem you are
experiencing -- somehow I have a feeling you're dependent on other
changes you've made to pre-1.2 Python which will mean that it's not
just a matter of unpacking the beta for you. :-)

BTW you mention that the problem goes away if you use

for i in sequence[:]: ...

This seems strange, unless your __getslice__ method returns a built-in
list rather than an instance of your own array class?

Cheers,

--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>