Commit d1b7e9af authored by Stefan Behnel's avatar Stefan Behnel

Mark several one-time functions (used during module init) with...

Mark several one-time functions (used during module init) with CYTHON_SMALL_CODE to reduce their binary code impact on the overall module size.
parent 073b3b90
...@@ -1147,19 +1147,19 @@ class GlobalState(object): ...@@ -1147,19 +1147,19 @@ class GlobalState(object):
else: else:
w = self.parts['cached_builtins'] w = self.parts['cached_builtins']
w.enter_cfunc_scope() w.enter_cfunc_scope()
w.putln("static int __Pyx_InitCachedBuiltins(void) {") w.putln("static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {")
w = self.parts['cached_constants'] w = self.parts['cached_constants']
w.enter_cfunc_scope() w.enter_cfunc_scope()
w.putln("") w.putln("")
w.putln("static int __Pyx_InitCachedConstants(void) {") w.putln("static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {")
w.put_declare_refcount_context() w.put_declare_refcount_context()
w.put_setup_refcount_context("__Pyx_InitCachedConstants") w.put_setup_refcount_context("__Pyx_InitCachedConstants")
w = self.parts['init_globals'] w = self.parts['init_globals']
w.enter_cfunc_scope() w.enter_cfunc_scope()
w.putln("") w.putln("")
w.putln("static int __Pyx_InitGlobals(void) {") w.putln("static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {")
if not Options.generate_cleanup_code: if not Options.generate_cleanup_code:
del self.parts['cleanup_globals'] del self.parts['cleanup_globals']
...@@ -1167,7 +1167,7 @@ class GlobalState(object): ...@@ -1167,7 +1167,7 @@ class GlobalState(object):
w = self.parts['cleanup_globals'] w = self.parts['cleanup_globals']
w.enter_cfunc_scope() w.enter_cfunc_scope()
w.putln("") w.putln("")
w.putln("static void __Pyx_CleanupGlobals(void) {") w.putln("static CYTHON_SMALL_CODE void __Pyx_CleanupGlobals(void) {")
code = self.parts['utility_code_proto'] code = self.parts['utility_code_proto']
code.putln("") code.putln("")
......
...@@ -375,7 +375,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -375,7 +375,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_lambda_definitions(env, code) self.generate_lambda_definitions(env, code)
# generate normal variable and function definitions # generate normal variable and function definitions
self.generate_variable_definitions(env, code) self.generate_variable_definitions(env, code)
self.body.generate_function_definitions(env, code) self.body.generate_function_definitions(env, code)
code.mark_pos(None) code.mark_pos(None)
self.generate_typeobj_definitions(env, code) self.generate_typeobj_definitions(env, code)
self.generate_method_table(env, code) self.generate_method_table(env, code)
...@@ -383,6 +385,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -383,6 +385,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_import_star(env, code) self.generate_import_star(env, code)
self.generate_pymoduledef_struct(env, code) self.generate_pymoduledef_struct(env, code)
# initialise the macro to reduce the code size of one-time functionality
code.putln(UtilityCode.load_as_string("SmallCodeConfig", "ModuleSetupCode.c")[0].strip())
# init_globals is inserted before this # init_globals is inserted before this
self.generate_module_init_func(modules[:-1], env, globalstate['init_module']) self.generate_module_init_func(modules[:-1], env, globalstate['init_module'])
self.generate_module_cleanup_func(env, globalstate['cleanup_module']) self.generate_module_cleanup_func(env, globalstate['cleanup_module'])
...@@ -2297,7 +2302,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -2297,7 +2302,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("") code.putln("")
# main module init code lives in Py_mod_exec function, not in PyInit function # main module init code lives in Py_mod_exec function, not in PyInit function
code.putln("static int %s(PyObject *%s)" % ( code.putln("static CYTHON_SMALL_CODE int %s(PyObject *%s)" % (
self.mod_init_func_cname(Naming.pymodule_exec_func_cname, env), self.mod_init_func_cname(Naming.pymodule_exec_func_cname, env),
Naming.pymodinit_module_arg)) Naming.pymodinit_module_arg))
code.putln("#endif") # PEP489 code.putln("#endif") # PEP489
...@@ -2509,7 +2514,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -2509,7 +2514,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.call_code = orig_code.insertion_point() self.call_code = orig_code.insertion_point()
code = function_code code = function_code
code.enter_cfunc_scope(scope) code.enter_cfunc_scope(scope)
prototypes.putln("static int %s(void); /*proto*/" % self.cfunc_name) prototypes.putln("static CYTHON_SMALL_CODE int %s(void); /*proto*/" % self.cfunc_name)
code.putln("static int %s(void) {" % self.cfunc_name) code.putln("static int %s(void) {" % self.cfunc_name)
code.put_declare_refcount_context() code.put_declare_refcount_context()
self.tempdecl_code = code.insertion_point() self.tempdecl_code = code.insertion_point()
......
...@@ -672,6 +672,20 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { ...@@ -672,6 +672,20 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
#endif #endif
/////////////// SmallCodeConfig.proto ///////////////
#ifndef CYTHON_SMALL_CODE
#if defined(__clang__)
#define CYTHON_SMALL_CODE
#elif defined(__GNUC__) && (!(defined(__cplusplus)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)))
// At least g++ 4.4.7 can generate crashing code with this option. (GH #2235)
#define CYTHON_SMALL_CODE __attribute__((optimize("Os")))
#else
#define CYTHON_SMALL_CODE
#endif
#endif
/////////////// PyModInitFuncType.proto /////////////// /////////////// PyModInitFuncType.proto ///////////////
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
...@@ -694,17 +708,6 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { ...@@ -694,17 +708,6 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
#endif #endif
#ifndef CYTHON_SMALL_CODE
#if defined(__clang__)
#define CYTHON_SMALL_CODE
#elif defined(__GNUC__) && (!(defined(__cplusplus)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)))
// At least g++ 4.4.7 can generate crashing code with this option. (GH #2235)
#define CYTHON_SMALL_CODE __attribute__((optimize("Os")))
#else
#define CYTHON_SMALL_CODE
#endif
#endif
/////////////// FastTypeChecks.proto /////////////// /////////////// FastTypeChecks.proto ///////////////
...@@ -862,7 +865,7 @@ PyEval_InitThreads(); ...@@ -862,7 +865,7 @@ PyEval_InitThreads();
//@substitute: naming //@substitute: naming
//#if CYTHON_PEP489_MULTI_PHASE_INIT //#if CYTHON_PEP489_MULTI_PHASE_INIT
static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) { static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) {
PyObject *value = PyObject_GetAttrString(spec, from_name); PyObject *value = PyObject_GetAttrString(spec, from_name);
int result = 0; int result = 0;
if (likely(value)) { if (likely(value)) {
...@@ -876,7 +879,7 @@ static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const ch ...@@ -876,7 +879,7 @@ static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const ch
return result; return result;
} }
static PyObject* ${pymodule_create_func_cname}(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { static CYTHON_SMALL_CODE PyObject* ${pymodule_create_func_cname}(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
PyObject *module = NULL, *moddict, *modname; PyObject *module = NULL, *moddict, *modname;
// For now, we only have exactly one module instance. // For now, we only have exactly one module instance.
......
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