[C-API] Weird sys.exc_info reference segfault

J

Jonas H.

Hello list,

I have a really weird reference problem with `sys.exc_info`, and, if I'm
right, function frames.

The software in question is bjoern, a WSGI web server written in C,
which you can find at http://github.com/jonashaag/bjoern.

This WSGI application:

def app(env, start_response):
start_response('200 alright', [])
try:
a
except:
import sys
sys.exc_info()
return ['hello']

import bjoern
bjoern.run(app, '0.0.0.0', 8080)

works perfect, however, if I make the 7th line an assignment:

x = sys.exc_info()

I get a segmentation fault after a few requests, the stack trace being:

#1 frame_clear ()
#2 collect ()
#3 _PyObject_GC_Malloc ()
#4 PyType_GenericAlloc ()
#5 BaseException_new ()
#6 type_call ()
#7 PyObject_Call ()
#8 PyEval_CallObjectWithKeywords ()
#9 PyErr_NormalizeException ()
#10 PyEval_EvalFrameEx ()
#11 PyEval_EvalCodeEx ()
#12 function_call ()
#14 PyObject_CallFunctionObjArgs ()
#15 wsgi_call_application (request=...) at bjoern/wsgi.c:33

Now that is weird. The only difference between the two functions is that
the second one (with the assignment) keeps a reference to the exc_info
tuple in the function frame.
The `PyThreadState_GET()->exc_{type,value,traceback}` values, however,
should be the same in both cases, because the `except:` cleanup resets
those to NULL, shouldn't it?

Do you have any tips how to debug this?

Thanks in advance,
Jonas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top