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):
else:
w = self.parts['cached_builtins']
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.enter_cfunc_scope()
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_setup_refcount_context("__Pyx_InitCachedConstants")
w = self.parts['init_globals']
w.enter_cfunc_scope()
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:
del self.parts['cleanup_globals']
......@@ -1167,7 +1167,7 @@ class GlobalState(object):
w = self.parts['cleanup_globals']
w.enter_cfunc_scope()
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.putln("")
......
......@@ -375,7 +375,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_lambda_definitions(env, code)
# generate normal variable and function definitions
self.generate_variable_definitions(env, code)
self.body.generate_function_definitions(env, code)
code.mark_pos(None)
self.generate_typeobj_definitions(env, code)
self.generate_method_table(env, code)
......@@ -383,6 +385,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_import_star(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
self.generate_module_init_func(modules[:-1], env, globalstate['init_module'])
self.generate_module_cleanup_func(env, globalstate['cleanup_module'])
......@@ -2297,7 +2302,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("")
# 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),
Naming.pymodinit_module_arg))
code.putln("#endif") # PEP489
......@@ -2509,7 +2514,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.call_code = orig_code.insertion_point()
code = function_code
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.put_declare_refcount_context()
self.tempdecl_code = code.insertion_point()
......
......@@ -672,6 +672,20 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
#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 ///////////////
#if PY_MAJOR_VERSION < 3
......@@ -694,17 +708,6 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
#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 ///////////////
......@@ -862,7 +865,7 @@ PyEval_InitThreads();
//@substitute: naming
//#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);
int result = 0;
if (likely(value)) {
......@@ -876,7 +879,7 @@ static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const ch
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;
// 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