Commit 2985e5d0 authored by Stefan Behnel's avatar Stefan Behnel

move 'init threads' utility code to ModuleSetupCode.c file

parent d18be9ae
...@@ -1748,10 +1748,8 @@ class CCodeWriter(object): ...@@ -1748,10 +1748,8 @@ class CCodeWriter(object):
using the Python API). Additionally, the code generated by this method using the Python API). Additionally, the code generated by this method
may be called recursively. may be called recursively.
""" """
from Cython.Compiler import Nodes self.globalstate.use_utility_code(
UtilityCode.load_cached("ForceInitThreads", "ModuleSetupCode.c"))
self.globalstate.use_utility_code(Nodes.force_init_threads_utility_code)
self.putln("#ifdef WITH_THREAD") self.putln("#ifdef WITH_THREAD")
if declare_gilstate: if declare_gilstate:
self.put("PyGILState_STATE ") self.put("PyGILState_STATE ")
...@@ -1854,8 +1852,8 @@ class CCodeWriter(object): ...@@ -1854,8 +1852,8 @@ class CCodeWriter(object):
def put_setup_refcount_context(self, name, acquire_gil=False): def put_setup_refcount_context(self, name, acquire_gil=False):
if acquire_gil: if acquire_gil:
from Cython.Compiler import Nodes self.globalstate.use_utility_code(
self.globalstate.use_utility_code(Nodes.force_init_threads_utility_code) UtilityCode.load_cached("ForceInitThreads", "ModuleSetupCode.c"))
self.putln('__Pyx_RefNannySetupContext("%s", %d);' % (name, acquire_gil and 1 or 0)) self.putln('__Pyx_RefNannySetupContext("%s", %d);' % (name, acquire_gil and 1 or 0))
def put_finish_refcount_context(self): def put_finish_refcount_context(self):
......
...@@ -6778,7 +6778,8 @@ class GILStatNode(NogilTryFinallyStatNode): ...@@ -6778,7 +6778,8 @@ class GILStatNode(NogilTryFinallyStatNode):
return super(GILStatNode, self).analyse_declarations(env) return super(GILStatNode, self).analyse_declarations(env)
def analyse_expressions(self, env): def analyse_expressions(self, env):
env.use_utility_code(force_init_threads_utility_code) env.use_utility_code(
UtilityCode.load_cached("ForceInitThreads", "ModuleSetupCode.c"))
was_nogil = env.nogil was_nogil = env.nogil
env.nogil = self.state == 'nogil' env.nogil = self.state == 'nogil'
TryFinallyStatNode.analyse_expressions(self, env) TryFinallyStatNode.analyse_expressions(self, env)
...@@ -9023,19 +9024,6 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { ...@@ -9023,19 +9024,6 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
#------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------
force_init_threads_utility_code = UtilityCode(
proto="""
#ifndef __PYX_FORCE_INIT_THREADS
#define __PYX_FORCE_INIT_THREADS 0
#endif
""")
init_threads = UtilityCode(
init="PyEval_InitThreads();\n",
)
#------------------------------------------------------------------------------------
# Note that cPython ignores PyTrace_EXCEPTION, # Note that cPython ignores PyTrace_EXCEPTION,
# but maybe some other profilers don't. # but maybe some other profilers don't.
......
...@@ -17,6 +17,7 @@ from Cython.Compiler.UtilNodes import LetNode, LetRefNode, ResultRefNode ...@@ -17,6 +17,7 @@ from Cython.Compiler.UtilNodes import LetNode, LetRefNode, ResultRefNode
from Cython.Compiler.TreeFragment import TreeFragment from Cython.Compiler.TreeFragment import TreeFragment
from Cython.Compiler.StringEncoding import EncodedString from Cython.Compiler.StringEncoding import EncodedString
from Cython.Compiler.Errors import error, warning, CompileError, InternalError from Cython.Compiler.Errors import error, warning, CompileError, InternalError
from Cython.Compiler.Code import UtilityCode
import copy import copy
...@@ -705,7 +706,8 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): ...@@ -705,7 +706,8 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
directive[-1] not in self.valid_parallel_directives): directive[-1] not in self.valid_parallel_directives):
error(pos, "No such directive: %s" % full_name) error(pos, "No such directive: %s" % full_name)
self.module_scope.use_utility_code(Nodes.init_threads) self.module_scope.use_utility_code(
UtilityCode.load_cached("InitThreads", "ModuleSetupCode.c"))
return result return result
...@@ -722,7 +724,8 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): ...@@ -722,7 +724,8 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
self.cython_module_names.add(u"cython") self.cython_module_names.add(u"cython")
self.parallel_directives[ self.parallel_directives[
u"cython.parallel"] = node.module_name u"cython.parallel"] = node.module_name
self.module_scope.use_utility_code(Nodes.init_threads) self.module_scope.use_utility_code(
UtilityCode.load_cached("InitThreads", "ModuleSetupCode.c"))
elif node.as_name: elif node.as_name:
self.directive_names[node.as_name] = node.module_name[7:] self.directive_names[node.as_name] = node.module_name[7:]
else: else:
......
...@@ -222,6 +222,16 @@ ...@@ -222,6 +222,16 @@
#define __Pyx_DOCSTR(n) (n) #define __Pyx_DOCSTR(n) (n)
#endif #endif
/////////////// ForceInitThreads.proto ///////////////
#ifndef __PYX_FORCE_INIT_THREADS
#define __PYX_FORCE_INIT_THREADS 0
#endif
/////////////// InitThreads.init ///////////////
PyEval_InitThreads();
/////////////// CodeObjectCache.proto /////////////// /////////////// CodeObjectCache.proto ///////////////
typedef struct { typedef struct {
......
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