Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
969765b6
Commit
969765b6
authored
Feb 14, 2018
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimise the module init function for small code size regardless of the externally provided CFLAGS.
See #2102.
parent
56aa4c15
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
3 deletions
+14
-3
CHANGES.rst
CHANGES.rst
+4
-0
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+4
-3
Cython/Utility/ModuleSetupCode.c
Cython/Utility/ModuleSetupCode.c
+6
-0
No files found.
CHANGES.rst
View file @
969765b6
...
@@ -8,6 +8,10 @@ Cython Changelog
...
@@ -8,6 +8,10 @@ Cython Changelog
Features added
Features added
--------------
--------------
* When compiling with gcc, the module init function is now tuned for small
code size instead of whatever compile flags were provided externally.
(Github issue #2102)
* Cdef classes can now multiply inherit from ordinary Python classes.
* Cdef classes can now multiply inherit from ordinary Python classes.
(The primary base must still be a c class, possibly ``object``, and
(The primary base must still be a c class, possibly ``object``, and
the other bases must *not* be cdef classes.)
the other bases must *not* be cdef classes.)
...
...
Cython/Compiler/ModuleNode.py
View file @
969765b6
...
@@ -2279,10 +2279,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -2279,10 +2279,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
header2
=
"__Pyx_PyMODINIT_FUNC init%s(void)"
%
env
.
module_name
header2
=
"__Pyx_PyMODINIT_FUNC init%s(void)"
%
env
.
module_name
header3
=
"__Pyx_PyMODINIT_FUNC %s(void)"
%
self
.
mod_init_func_cname
(
'PyInit'
,
env
)
header3
=
"__Pyx_PyMODINIT_FUNC %s(void)"
%
self
.
mod_init_func_cname
(
'PyInit'
,
env
)
code
.
putln
(
"#if PY_MAJOR_VERSION < 3"
)
code
.
putln
(
"#if PY_MAJOR_VERSION < 3"
)
code
.
putln
(
"%s; /*proto*/"
%
header2
)
# Optimise for small code size as the module init function is only executed once.
code
.
putln
(
"CYTHON_SMALL_CODE %s; /*proto*/"
%
header2
)
code
.
putln
(
header2
)
code
.
putln
(
header2
)
code
.
putln
(
"#else"
)
code
.
putln
(
"#else"
)
code
.
putln
(
"%s; /*proto*/"
%
header3
)
code
.
putln
(
"
CYTHON_SMALL_CODE
%s; /*proto*/"
%
header3
)
code
.
putln
(
header3
)
code
.
putln
(
header3
)
# CPython 3.5+ supports multi-phase module initialisation (gives access to __spec__, __file__, etc.)
# CPython 3.5+ supports multi-phase module initialisation (gives access to __spec__, __file__, etc.)
...
@@ -2296,7 +2297,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -2296,7 +2297,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
(
"
CYTHON_SMALL_CODE
static 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
...
...
Cython/Utility/ModuleSetupCode.c
View file @
969765b6
...
@@ -665,6 +665,12 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
...
@@ -665,6 +665,12 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
#endif
#endif
#if defined(__GNUC__)
#define CYTHON_SMALL_CODE __attribute__((optimize("Os")))
#else
#define CYTHON_SMALL_CODE
#endif
/////////////// FastTypeChecks.proto ///////////////
/////////////// FastTypeChecks.proto ///////////////
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment