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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
1edfca7f
Commit
1edfca7f
authored
Jun 12, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
quick work-around for PEP 3121 implementation in Py3 beta
parent
59cbd0ad
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
4 deletions
+51
-4
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+50
-4
Cython/Compiler/Naming.py
Cython/Compiler/Naming.py
+1
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
1edfca7f
...
...
@@ -247,6 +247,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self
.
generate_filename_init_prototype
(
code
)
if
env
.
has_import_star
:
self
.
generate_import_star
(
env
,
code
)
self
.
generate_pymoduledef_struct
(
env
,
code
)
self
.
generate_module_init_func
(
modules
[:
-
1
],
env
,
code
)
code
.
mark_pos
(
None
)
self
.
generate_module_cleanup_func
(
env
,
code
)
...
...
@@ -1516,9 +1517,17 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def
generate_module_init_func
(
self
,
imported_modules
,
env
,
code
):
code
.
putln
(
""
)
header
=
"PyMODINIT_FUNC init%s(void)"
%
env
.
module_name
code
.
putln
(
"%s; /*proto*/"
%
header
)
code
.
putln
(
"%s {"
%
header
)
header2
=
"PyMODINIT_FUNC init%s(void)"
%
env
.
module_name
header3
=
"PyMODINIT_FUNC PyInit_%s(void)"
%
env
.
module_name
code
.
putln
(
"#if PY_MAJOR_VERSION < 3"
)
code
.
putln
(
"%s; /*proto*/"
%
header2
)
code
.
putln
(
header2
)
code
.
putln
(
"#else"
)
code
.
putln
(
"%s; /*proto*/"
%
header3
)
code
.
putln
(
header3
)
code
.
putln
(
"#endif"
)
code
.
putln
(
"{"
)
code
.
put_var_declarations
(
env
.
temp_entries
)
code
.
putln
(
"%s = PyTuple_New(0); %s"
%
(
Naming
.
empty_tuple
,
code
.
error_goto_if_null
(
Naming
.
empty_tuple
,
self
.
pos
)));
...
...
@@ -1563,13 +1572,21 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self
.
body
.
generate_execution_code
(
code
)
if
Options
.
generate_cleanup_code
:
# this should be replaced by the module's tp_clear in Py3
code
.
putln
(
"if (__Pyx_RegisterCleanup()) %s;"
%
code
.
error_goto
(
self
.
pos
))
code
.
putln
(
"#if PY_MAJOR_VERSION < 3"
)
code
.
putln
(
"return;"
)
code
.
putln
(
"#else"
)
code
.
putln
(
"return %s;"
%
env
.
module_cname
)
code
.
putln
(
"#endif"
)
code
.
put_label
(
code
.
error_label
)
code
.
put_var_xdecrefs
(
env
.
temp_entries
)
code
.
putln
(
'__Pyx_AddTraceback("%s");'
%
env
.
qualified_name
)
env
.
use_utility_code
(
Nodes
.
traceback_utility_code
)
code
.
putln
(
"#if PY_MAJOR_VERSION >= 3"
)
code
.
putln
(
"return NULL;"
)
code
.
putln
(
"#endif"
)
code
.
putln
(
'}'
)
def
generate_module_cleanup_func
(
self
,
env
,
code
):
...
...
@@ -1610,6 +1627,26 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def
generate_filename_init_call
(
self
,
code
):
code
.
putln
(
"%s();"
%
Naming
.
fileinit_cname
)
def
generate_pymoduledef_struct
(
self
,
env
,
code
):
if
env
.
doc
:
doc
=
env
.
doc_cname
else
:
doc
=
"0"
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
(
' "%s",'
%
env
.
module_name
)
code
.
putln
(
" %s, /* m_doc */"
%
doc
)
code
.
putln
(
" -1, /* m_size */"
)
code
.
putln
(
" %s /* m_methods */,"
%
env
.
method_table_cname
)
code
.
putln
(
" NULL, /* m_reload */"
)
code
.
putln
(
" NULL, /* m_traverse */"
)
code
.
putln
(
" NULL, /* m_clear */"
)
code
.
putln
(
" NULL /* m_free */"
)
code
.
putln
(
"};"
)
code
.
putln
(
"#endif"
)
def
generate_module_creation_code
(
self
,
env
,
code
):
# Generate code to create the module object and
# install the builtins.
...
...
@@ -1617,19 +1654,28 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
doc
=
env
.
doc_cname
else
:
doc
=
"0"
code
.
putln
(
"#if PY_MAJOR_VERSION < 3"
)
code
.
putln
(
'%s = Py_InitModule4("%s", %s, %s, 0, PYTHON_API_VERSION);'
%
(
env
.
module_cname
,
env
.
module_name
,
env
.
method_table_cname
,
doc
))
code
.
putln
(
"#else"
)
code
.
putln
(
"%s = PyModule_Create(&%s);"
%
(
env
.
module_cname
,
Naming
.
pymoduledef_cname
))
code
.
putln
(
"#endif"
)
code
.
putln
(
"if (!%s) %s;"
%
(
env
.
module_cname
,
code
.
error_goto
(
self
.
pos
)));
code
.
putln
(
"#if PY_MAJOR_VERSION < 3"
)
code
.
putln
(
"Py_INCREF(%s);"
%
env
.
module_cname
)
code
.
putln
(
"#endif"
)
code
.
putln
(
'%s = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME);'
%
Naming
.
builtins_cname
)
...
...
Cython/Compiler/Naming.py
View file @
1edfca7f
...
...
@@ -65,6 +65,7 @@ empty_tuple = pyrex_prefix + "empty_tuple"
print_function
=
pyrex_prefix
+
"print"
print_function_kwargs
=
pyrex_prefix
+
"print_kwargs"
cleanup_cname
=
pyrex_prefix
+
"module_cleanup"
pymoduledef_cname
=
pyrex_prefix
+
"moduledef"
optional_args_cname
=
pyrex_prefix
+
"optional_args"
no_opt_args
=
pyrex_prefix
+
"no_opt_args"
import_star
=
pyrex_prefix
+
"import_star"
...
...
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