env.generate_library_function_declarations(code)
self.generate_filename_init_call(code)
+ code.putln("/*--- Threads initialization code ---*/")
+ code.putln("#if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS")
+ code.putln("#ifdef WITH_THREAD")
+ code.putln("PyEval_InitThreads();")
+ code.putln("#endif")
+ code.putln("#endif")
+
code.putln("/*--- Initialize various global constants etc. ---*/")
code.putln(code.error_goto_if_neg("__Pyx_InitGlobals()", self.pos))
# ----- GIL acquisition
acquire_gil = self.need_gil_acquisition(lenv)
if acquire_gil:
+ env.use_utility_code(py23_init_threads_utility_code)
code.putln("PyGILState_STATE _save = PyGILState_Ensure();")
# ----- Automatic lead-ins for certain special functions
if not lenv.nogil:
finally_clause = GILExitNode(pos, state = state))
def analyse_expressions(self, env):
+ env.use_utility_code(py23_init_threads_utility_code)
was_nogil = env.nogil
env.nogil = 1
TryFinallyStatNode.analyse_expressions(self, env)
""")
#------------------------------------------------------------------------------------
+
+py23_init_threads_utility_code = UtilityCode(
+proto="""
+#ifndef __PYX_FORCE_INIT_THREADS
+#define __PYX_FORCE_INIT_THREADS 0
+#if PY_VERSION_HEX < 0x02040000
+#undef __PYX_FORCE_INIT_THREADS
+#define __PYX_FORCE_INIT_THREADS 1
+#endif
+#endif
+""")
+
+#------------------------------------------------------------------------------------