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
Boxiang Sun
cython
Commits
f6c590d3
Commit
f6c590d3
authored
Aug 26, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduce code redundancy in Py2/3 cleanup code setup
parent
1bb2ba41
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
21 deletions
+13
-21
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+4
-15
Cython/Utility/ModuleSetupCode.c
Cython/Utility/ModuleSetupCode.c
+9
-6
No files found.
Cython/Compiler/ModuleNode.py
View file @
f6c590d3
...
...
@@ -1975,15 +1975,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
not
Options
.
generate_cleanup_code
:
return
code
.
putln
(
"#if PY_MAJOR_VERSION >= 3"
)
code
.
putln
(
'static void %s(CYTHON_UNUSED PyObject *self)'
%
Naming
.
cleanup_cname
)
code
.
putln
(
"#else"
)
code
.
putln
(
'static PyObject *%s(CYTHON_UNUSED PyObject *self, CYTHON_UNUSED PyObject *unused)'
%
code
.
putln
(
'static void %s(CYTHON_UNUSED PyObject *self) {'
%
Naming
.
cleanup_cname
)
code
.
putln
(
"#endif"
)
code
.
putln
(
"{"
)
if
Options
.
generate_cleanup_code
>=
2
:
code
.
putln
(
"/*--- Global cleanup code ---*/"
)
rev_entries
=
list
(
env
.
var_entries
)
...
...
@@ -2026,10 +2019,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
'Py_CLEAR(%s);'
%
Naming
.
builtins_cname
)
code
.
putln
(
'#endif'
)
code
.
putln
(
"#if PY_MAJOR_VERSION < 3"
)
code
.
putln
(
"Py_INCREF(Py_None); return Py_None;"
)
code
.
putln
(
'#endif'
)
def
generate_main_method
(
self
,
env
,
code
):
module_is_main
=
"%s%s"
%
(
Naming
.
module_is_main
,
self
.
full_module_name
.
replace
(
'.'
,
'__'
))
if
Options
.
embed
==
"main"
:
...
...
@@ -2048,13 +2037,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
doc
=
"__Pyx_DOCSTR(%s)"
%
code
.
get_string_const
(
env
.
doc
)
else
:
doc
=
"0"
code
.
putln
(
""
)
code
.
putln
(
"#if PY_MAJOR_VERSION >= 3"
)
if
Options
.
generate_cleanup_code
:
cleanup_func
=
"(freefunc)%s"
%
Naming
.
cleanup_cname
code
.
putln
(
"static void %s(PyObject *self); /*proto*/"
%
Naming
.
cleanup_cname
)
else
:
cleanup_func
=
'NULL'
code
.
putln
(
""
)
code
.
putln
(
"#if PY_MAJOR_VERSION >= 3"
)
code
.
putln
(
"static struct PyModuleDef %s = {"
%
Naming
.
pymoduledef_cname
)
code
.
putln
(
" PyModuleDef_HEAD_INIT,"
)
code
.
putln
(
' __Pyx_NAMESTR("%s"),'
%
env
.
module_name
)
...
...
Cython/Utility/ModuleSetupCode.c
View file @
f6c590d3
...
...
@@ -478,16 +478,19 @@ end:
/////////////// RegisterModuleCleanup.proto ///////////////
//@substitute: naming
static
void
$
{
cleanup_cname
}(
PyObject
*
self
);
/*proto*/
static
int
__Pyx_RegisterCleanup
(
void
);
/*proto*/
#if PY_MAJOR_VERSION < 3
static
PyObject
*
$
{
cleanup_cname
}(
PyObject
*
self
,
PyObject
*
unused
);
/*proto*/
#endif
/////////////// RegisterModuleCleanup ///////////////
//@substitute: naming
//@requires: ImportExport.c::ModuleImport
#if PY_MAJOR_VERSION < 3
static
PyObject
*
$
{
cleanup_cname
}
_atexit
(
PyObject
*
module
,
CYTHON_UNUSED
PyObject
*
unused
)
{
$
{
cleanup_cname
}(
module
);
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
int
__Pyx_RegisterCleanup
(
void
)
{
// Don't use Py_AtExit because that has a 32-call limit and is called
// after python finalization.
...
...
@@ -496,7 +499,8 @@ static int __Pyx_RegisterCleanup(void) {
// user exit code to run before us that may depend on the globals
// and cached objects that we are about to clean up.
static
PyMethodDef
cleanup_def
=
{
__Pyx_NAMESTR
(
"__cleanup"
),
(
PyCFunction
)
$
{
cleanup_cname
},
METH_NOARGS
,
0
};
static
PyMethodDef
cleanup_def
=
{
__Pyx_NAMESTR
(
"__cleanup"
),
(
PyCFunction
)
$
{
cleanup_cname
}
_atexit
,
METH_NOARGS
,
0
};
PyObject
*
cleanup_func
=
0
;
PyObject
*
atexit
=
0
;
...
...
@@ -528,8 +532,7 @@ static int __Pyx_RegisterCleanup(void) {
if
(
!
args
)
goto
bad
;
ret
=
PyList_Insert
(
reg
,
0
,
args
);
}
else
{
}
else
{
if
(
!
reg
)
PyErr_Clear
();
Py_XDECREF
(
reg
);
...
...
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