Commit e94bf900 authored by Stefan Behnel's avatar Stefan Behnel

separate trace declarations from initialisation to fix "declaration after code" C compiler error

parent 96aafb08
......@@ -2202,8 +2202,11 @@ class CCodeWriter(object):
self.globalstate.use_utility_code(
UtilityCode.load_cached("WriteUnraisableException", "Exceptions.c"))
def put_trace_declarations(self, codeobj=None, nogil=False):
self.putln('__Pyx_TraceDeclarations(%s, %d)' % (codeobj or 'NULL', nogil))
def put_trace_declarations(self):
self.putln('__Pyx_TraceDeclarations')
def put_trace_frame_init(self, codeobj=None):
self.putln('__Pyx_TraceFrameInit(%s)' % (codeobj or 'NULL'))
def put_trace_call(self, name, pos, nogil=False):
self.putln('__Pyx_TraceCall("%s", %s[%s], %s, %d, %s);' % (
......
......@@ -2053,7 +2053,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.put_declare_refcount_context()
if profile or linetrace:
tempdecl_code.put_trace_declarations(None)
tempdecl_code.put_trace_declarations()
code.put_trace_frame_init()
code.putln("#if CYTHON_REFNANNY")
code.putln("__Pyx_RefNanny = __Pyx_RefNannyImportAPI(\"refnanny\");")
......
......@@ -1763,10 +1763,6 @@ class FuncDefNode(StatNode, BlockNode):
tempvardecl_code = code.insertion_point()
self.generate_keyword_list(code)
if profile or linetrace:
code_object = self.code_object.calculate_result_code(code) if self.code_object else None
code.put_trace_declarations(code_object, nogil=not code.funcstate.gil_owned)
# ----- Extern library function declarations
lenv.generate_library_function_declarations(code)
......@@ -1800,6 +1796,11 @@ class FuncDefNode(StatNode, BlockNode):
elif lenv.nogil and lenv.has_with_gil_block:
code.declare_gilstate()
if profile or linetrace:
tempvardecl_code.put_trace_declarations()
code_object = self.code_object.calculate_result_code(code) if self.code_object else None
code.put_trace_frame_init(code_object)
# ----- set up refnanny
if use_refnanny:
tempvardecl_code.put_declare_refcount_context()
......
......@@ -42,10 +42,12 @@
#define CYTHON_FRAME_DEL(frame) Py_CLEAR(frame)
#endif
#define __Pyx_TraceDeclarations(codeobj, nogil) \
#define __Pyx_TraceDeclarations \
static PyCodeObject *$frame_code_cname = NULL; \
CYTHON_FRAME_MODIFIER PyFrameObject *$frame_cname = NULL; \
int __Pyx_use_tracing = 0; \
int __Pyx_use_tracing = 0;
#define __Pyx_TraceFrameInit(codeobj) \
if (codeobj) $frame_code_cname = (PyCodeObject*) codeobj;
#ifdef WITH_THREAD
......@@ -152,7 +154,8 @@
#else
#define __Pyx_TraceDeclarations(codeobj, nogil)
#define __Pyx_TraceDeclarations
#define __Pyx_TraceFrameInit(codeobj)
// mark error label as used to avoid compiler warnings
#define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error) if (1); else goto_error;
#define __Pyx_TraceException()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment