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
Kirill Smelkov
cython
Commits
133f811a
Commit
133f811a
authored
Jun 12, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
04c8a7d2
4401a4b8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
13 deletions
+67
-13
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+57
-8
Cython/Compiler/Naming.py
Cython/Compiler/Naming.py
+1
-0
tests/run/classbody_exec.pyx
tests/run/classbody_exec.pyx
+7
-3
tests/run/r_uintindex.pyx
tests/run/r_uintindex.pyx
+2
-2
No files found.
Cython/Compiler/ModuleNode.py
View file @
133f811a
...
...
@@ -248,6 +248,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
)
...
...
@@ -821,10 +822,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
#if need_self_cast:
# self.generate_self_cast(scope, code)
if
type
.
vtabslot_cname
:
code
.
putln
(
"*(struct %s **)&p->%s = %s;"
%
(
type
.
vtabstruct_cname
,
if
base_type
:
struct_type_cast
=
"(struct %s*)"
%
base_type
.
vtabstruct_cname
else
:
struct_type_cast
=
""
code
.
putln
(
"p->%s = %s%s;"
%
(
type
.
vtabslot_cname
,
type
.
vtabptr_cname
))
struct_type_cast
,
type
.
vtabptr_cname
))
for
entry
in
py_attrs
:
if
entry
.
name
==
"__weakref__"
:
code
.
putln
(
"p->%s = 0;"
%
entry
.
cname
)
...
...
@@ -1517,9 +1521,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
)));
...
...
@@ -1564,13 +1576,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,7 +1630,27 @@ 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.
...
...
@@ -1618,19 +1658,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
)
...
...
@@ -1865,7 +1914,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
for
meth_entry
in
type
.
scope
.
cfunc_entries
:
if
meth_entry
.
func_cname
:
code
.
putln
(
"
*(void(**)(void))&%s.%s = (void(*)(void)
)%s;"
%
(
"
%s.%s = (void*
)%s;"
%
(
type
.
vtable_cname
,
meth_entry
.
cname
,
meth_entry
.
func_cname
))
...
...
Cython/Compiler/Naming.py
View file @
133f811a
...
...
@@ -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"
...
...
tests/run/classbody_exec.pyx
View file @
133f811a
__doc__
=
u"""
>>> print
D
{'answer': (42, 42)}
>>> print
(D)
{
u
'answer': (42, 42)}
"""
import
sys
if
sys
.
version_info
[
0
]
>=
3
:
__doc__
=
__doc__
.
replace
(
u"u'"
,
u"'"
)
D
=
{}
def
foo
(
x
):
...
...
@@ -10,4 +14,4 @@ def foo(x):
cdef
class
Spam
:
answer
=
42
D
[
'answer'
]
=
foo
(
answer
)
D
[
u
'answer'
]
=
foo
(
answer
)
tests/run/r_uintindex.pyx
View file @
133f811a
__doc__
=
u"""
>>> print
idx_uint( ["buckle", "my", "shoe"], 2
)
>>> print
(idx_uint( ["buckle", "my", "shoe"], 2)
)
shoe
>>> print
idx_ulong(["buckle", "my", "shoe"], 2
)
>>> print
(idx_ulong(["buckle", "my", "shoe"], 2)
)
shoe
"""
...
...
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