You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pyexpat.c calls trace function incorrectly for exceptions #50608
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2014-10-06.13:08:08.240>created_at=<Date2009-06-28.22:43:21.910>labels= ['expert-XML', 'type-bug']
title='pyexpat.c calls trace function incorrectly for exceptions'updated_at=<Date2014-10-06.13:08:08.238>user='https://github.com/nedbat'
Pyexpat.c calls the tracing function explicitly (not sure why). When it
intercepts an exception, it calls the function with PyTrace_EXCEPTION,
but then leaves the scope without calling PyTrace_RETURN. This is
incorrect. There should always be a PyTrace_RETURN for every PyTrace_CALL.
I've attached domshow.py to demonstrate the problem.
Running it produces many lines of output, including:
line expatbuilder.py 222
line expatbuilder.py 223
call pyexpat.c 905
call expatbuilder.py 892
line expatbuilder.py 894
line expatbuilder.py 900
exception expatbuilder.py 900
return expatbuilder.py 900
exception pyexpat.c 905
exception expatbuilder.py 223
line expatbuilder.py 225
line expatbuilder.py 226
The exception at line 905 in pyexpat.c should be followed with a return
from line 905 in pyexpat.c, but is not. After that exception, the
nesting is off by one because the Calls and Returns don't match.
I have no idea why pyexpat.c invokes the trace function in the first place. Unless someone can explain why it does that when no other C extension does, my inclination would be to make it stop calling the trace function at all, not to fix how it calls it.
Activity
nedbat commentedon Jun 28, 2009
Pyexpat.c calls the tracing function explicitly (not sure why). When it
intercepts an exception, it calls the function with PyTrace_EXCEPTION,
but then leaves the scope without calling PyTrace_RETURN. This is
incorrect. There should always be a PyTrace_RETURN for every PyTrace_CALL.
I've attached domshow.py to demonstrate the problem.
Running it produces many lines of output, including:
The exception at line 905 in pyexpat.c should be followed with a return
from line 905 in pyexpat.c, but is not. After that exception, the
nesting is off by one because the Calls and Returns don't match.
ezio-melotti commentedon Nov 9, 2012
Can you provide a patch?
nedbat commentedon Nov 9, 2012
I have no idea why pyexpat.c invokes the trace function in the first place. Unless someone can explain why it does that when no other C extension does, my inclination would be to make it stop calling the trace function at all, not to fix how it calls it.
ezio-melotti commentedon Feb 23, 2013
The relevant changesets are 1c26eb768293 and e43126c470a7. See also bpo-534864.
nedbat commentedon Apr 20, 2013
Attached a patch which simply removes the code that invokes the trace function.
birkenfeld commentedon Oct 6, 2014
A more complete patch that also fixes up pyexpat's frame trickery is tracked in bpo-22462.