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
8293ea4c
Commit
8293ea4c
authored
Oct 26, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support cleanup code for utility code
parent
ab03e674
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+13
-0
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+4
-1
Cython/Utils.py
Cython/Utils.py
+8
-0
No files found.
Cython/Compiler/Code.py
View file @
8293ea4c
...
...
@@ -184,6 +184,7 @@ class GlobalState(object):
self
.
pystring_table
=
rootwriter
.
new_writer
()
self
.
init_cached_builtins_writer
=
rootwriter
.
new_writer
()
self
.
initwriter
=
rootwriter
.
new_writer
()
self
.
cleanupwriter
=
rootwriter
.
new_writer
()
if
Options
.
cache_builtins
:
self
.
init_cached_builtins_writer
.
enter_cfunc_scope
()
...
...
@@ -193,6 +194,10 @@ class GlobalState(object):
self
.
initwriter
.
putln
(
""
)
self
.
initwriter
.
putln
(
"static int __Pyx_InitGlobals(void) {"
)
self
.
cleanupwriter
.
enter_cfunc_scope
()
self
.
cleanupwriter
.
putln
(
""
)
self
.
cleanupwriter
.
putln
(
"static void __Pyx_CleanupGlobals(void) {"
)
self
.
pystring_table
.
putln
(
""
)
self
.
pystring_table
.
putln
(
"static __Pyx_StringTabEntry %s[] = {"
%
Naming
.
stringtab_cname
)
...
...
@@ -230,6 +235,10 @@ class GlobalState(object):
w
.
putln
(
"return -1;"
)
w
.
putln
(
"}"
)
w
.
exit_cfunc_scope
()
w
=
self
.
cleanupwriter
w
.
putln
(
"}"
)
w
.
exit_cfunc_scope
()
def
insert_initcode_into
(
self
,
code
):
if
self
.
pystring_table_needed
:
...
...
@@ -238,6 +247,9 @@ class GlobalState(object):
code
.
insert
(
self
.
init_cached_builtins_writer
)
code
.
insert
(
self
.
initwriter
)
def
insert_cleanupcode_into
(
self
,
code
):
code
.
insert
(
self
.
cleanupwriter
)
def
put_pyobject_decl
(
self
,
entry
):
self
.
decls_writer
.
putln
(
"static PyObject *%s;"
%
entry
.
cname
)
...
...
@@ -351,6 +363,7 @@ class GlobalState(object):
if
utility_code
.
impl
:
self
.
utildefwriter
.
put
(
utility_code
.
impl
)
utility_code
.
write_init_code
(
self
.
initwriter
,
self
.
module_pos
)
utility_code
.
write_cleanup_code
(
self
.
cleanupwriter
,
self
.
module_pos
)
def
has_code
(
self
,
name
):
return
name
in
self
.
used_utility_code
...
...
Cython/Compiler/ModuleNode.py
View file @
8293ea4c
...
...
@@ -1542,7 +1542,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
exit_cfunc_scope
()
# done with labels
def
generate_module_init_func
(
self
,
imported_modules
,
env
,
code
):
# Insert code stream of __Pyx_InitGlobals
# Insert code stream of __Pyx_InitGlobals
()
code
.
globalstate
.
insert_initcode_into
(
code
)
code
.
enter_cfunc_scope
()
...
...
@@ -1627,6 +1627,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
return
env
.
use_utility_code
(
import_module_utility_code
)
env
.
use_utility_code
(
register_cleanup_utility_code
)
# Insert code stream of __Pyx_CleanupGlobals()
code
.
globalstate
.
insert_cleanupcode_into
(
code
)
code
.
putln
()
code
.
putln
(
'static PyObject* %s(PyObject *self, PyObject *unused) {'
%
Naming
.
cleanup_cname
)
if
Options
.
generate_cleanup_code
>=
2
:
...
...
@@ -1637,6 +1639,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
entry
.
visibility
!=
'extern'
:
if
entry
.
type
.
is_pyobject
and
entry
.
used
:
code
.
put_var_decref_clear
(
entry
)
code
.
putln
(
"__Pyx_CleanupGlobals();"
)
if
Options
.
generate_cleanup_code
>=
3
:
code
.
putln
(
"/*--- Type import cleanup code ---*/"
)
for
type
,
_
in
env
.
types_imported
.
items
():
...
...
Cython/Utils.py
View file @
8293ea4c
...
...
@@ -105,3 +105,11 @@ class UtilityCode(object):
self
.
init
(
writer
,
pos
)
else
:
writer
.
put
(
self
.
init
)
def
write_cleanup_code
(
self
,
writer
,
pos
):
if
not
self
.
cleanup
:
return
if
callable
(
self
.
cleanup
):
self
.
cleanup
(
writer
,
pos
)
else
:
writer
.
put
(
self
.
cleanup
)
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