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
acf0ef36
Commit
acf0ef36
authored
Apr 09, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reverted 'circular cdef' patch, leaving unrelated changes intact
parent
e816f827
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
206 deletions
+43
-206
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+0
-1
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+43
-205
No files found.
Cython/Compiler/Main.py
View file @
acf0ef36
...
@@ -310,7 +310,6 @@ def compile(source, options = None, c_compile = 0, c_link = 0,
...
@@ -310,7 +310,6 @@ def compile(source, options = None, c_compile = 0, c_link = 0,
#------------------------------------------------------------------------
#------------------------------------------------------------------------
def main(command_line = 0):
def main(command_line = 0):
args = sys.argv[1:]
args = sys.argv[1:]
any_failures = 0
any_failures = 0
if command_line:
if command_line:
...
...
Cython/Compiler/ModuleNode.py
View file @
acf0ef36
...
@@ -19,35 +19,6 @@ from Errors import error
...
@@ -19,35 +19,6 @@ from Errors import error
from
PyrexTypes
import
py_object_type
from
PyrexTypes
import
py_object_type
from
Cython.Utils
import
open_new_file
,
replace_suffix
from
Cython.Utils
import
open_new_file
,
replace_suffix
def
recurse_vtab_check_inheritance
(
entry
,
b
,
dict
):
base
=
entry
while
base
is
not
None
:
if
base
.
type
.
base_type
is
None
or
base
.
type
.
base_type
.
vtabstruct_cname
is
None
:
return
False
if
base
.
type
.
base_type
.
vtabstruct_cname
==
b
.
type
.
vtabstruct_cname
:
return
True
try
:
base
=
dict
[
base
.
type
.
base_type
.
vtabstruct_cname
]
except
KeyError
:
return
True
return
False
def
recurse_vtabslot_check_inheritance
(
entry
,
b
,
dict
):
base
=
entry
while
base
is
not
None
:
if
base
.
type
.
base_type
is
None
:
return
False
if
base
.
type
.
base_type
.
objstruct_cname
==
b
.
type
.
objstruct_cname
:
return
True
try
:
base
=
dict
[
base
.
type
.
base_type
.
objstruct_cname
]
except
KeyError
:
return
True
return
False
class
ModuleNode
(
Nodes
.
Node
,
Nodes
.
BlockNode
):
class
ModuleNode
(
Nodes
.
Node
,
Nodes
.
BlockNode
):
# doc string or None
# doc string or None
# body StatListNode
# body StatListNode
...
@@ -255,13 +226,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -255,13 +226,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self
.
generate_method_table
(
env
,
code
)
self
.
generate_method_table
(
env
,
code
)
self
.
generate_filename_init_prototype
(
code
)
self
.
generate_filename_init_prototype
(
code
)
self
.
generate_module_init_func
(
modules
[:
-
1
],
env
,
code
)
self
.
generate_module_init_func
(
modules
[:
-
1
],
env
,
code
)
self
.
generate_module_init2_func
(
modules
[:
-
1
],
env
,
code
)
code
.
mark_pos
(
None
)
code
.
mark_pos
(
None
)
self
.
generate_module_cleanup_func
(
env
,
code
)
self
.
generate_module_cleanup_func
(
env
,
code
)
self
.
generate_filename_table
(
code
)
self
.
generate_filename_table
(
code
)
self
.
generate_utility_functions
(
env
,
code
)
self
.
generate_utility_functions
(
env
,
code
)
self
.
generate_declarations_for_modules
(
env
,
modules
,
code
.
h
)
for
module
in
modules
:
self
.
generate_declarations_for_module
(
module
,
code
.
h
,
definition
=
module
is
env
)
f
=
open_new_file
(
result
.
c_file
)
f
=
open_new_file
(
result
.
c_file
)
f
.
write
(
code
.
h
.
f
.
getvalue
())
f
.
write
(
code
.
h
.
f
.
getvalue
())
...
@@ -273,9 +245,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -273,9 +245,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self
.
annotate
(
code
)
self
.
annotate
(
code
)
code
.
save_annotation
(
result
.
c_file
[:
-
1
]
+
"pyx"
)
# change?
code
.
save_annotation
(
result
.
c_file
[:
-
1
]
+
"pyx"
)
# change?
def
find_referenced_modules
(
self
,
env
,
module_list
,
modules_seen
):
def
find_referenced_modules
(
self
,
env
,
module_list
,
modules_seen
):
if
env
not
in
modules_seen
:
if
env
not
in
modules_seen
:
modules_seen
[
env
]
=
1
modules_seen
[
env
]
=
1
...
@@ -363,103 +332,18 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -363,103 +332,18 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# Some C compilers don't like an empty array
# Some C compilers don't like an empty array
code
.
putln
(
"0"
)
code
.
putln
(
"0"
)
code
.
putln
(
"};"
)
code
.
putln
(
"};"
)
def
generate_vtab_dict
(
self
,
module_list
):
def
generate_declarations_for_module
(
self
,
env
,
code
,
definition
):
vtab_dict
=
{}
for
module
in
module_list
:
for
entry
in
module
.
c_class_entries
:
if
not
entry
.
in_cinclude
:
type
=
entry
.
type
scope
=
type
.
scope
if
type
.
vtabstruct_cname
:
vtab_dict
[
type
.
vtabstruct_cname
]
=
entry
return
vtab_dict
def
generate_vtab_list
(
self
,
vtab_dict
):
vtab_list
=
list
()
for
entry
in
vtab_dict
.
itervalues
():
vtab_list
.
append
(
entry
)
for
i
in
range
(
0
,
len
(
vtab_list
)):
for
j
in
range
(
0
,
len
(
vtab_list
)):
if
(
recurse_vtab_check_inheritance
(
vtab_list
[
j
],
vtab_list
[
i
],
vtab_dict
)
==
1
):
if
i
>
j
:
vtab_list
.
insert
(
j
,
vtab_list
[
i
])
if
i
>
j
:
vtab_list
.
pop
(
i
+
1
)
else
:
vtab_list
.
pop
(
i
)
#for entry in vtab_list:
#print entry.type.vtabstruct_cname
return
vtab_list
def
generate_vtabslot_dict
(
self
,
module_list
,
env
):
vtab_dict
=
{}
type_entries
=
[]
for
module
in
module_list
:
definition
=
module
is
env
if
definition
:
type_entries
.
extend
(
env
.
type_entries
)
else
:
for
entry
in
module
.
type_entries
:
if
entry
.
defined_in_pxd
:
type_entries
.
append
(
entry
)
for
entry
in
type_entries
:
type
=
entry
.
type
if
type
.
is_extension_type
:
if
not
entry
.
in_cinclude
:
type
=
entry
.
type
scope
=
type
.
scope
vtab_dict
[
type
.
objstruct_cname
]
=
entry
return
vtab_dict
def
generate_vtabslot_list
(
self
,
vtab_dict
):
vtab_list
=
list
()
for
entry
in
vtab_dict
.
itervalues
():
vtab_list
.
append
(
entry
)
for
i
in
range
(
0
,
len
(
vtab_list
)):
for
j
in
range
(
0
,
len
(
vtab_list
)):
if
(
recurse_vtabslot_check_inheritance
(
vtab_list
[
j
],
vtab_list
[
i
],
vtab_dict
)
==
1
):
if
i
>
j
:
vtab_list
.
insert
(
j
,
vtab_list
[
i
])
if
i
>
j
:
vtab_list
.
pop
(
i
+
1
)
else
:
vtab_list
.
pop
(
i
)
#for entry in vtab_list:
#print entry.type.vtabstruct_cname
return
vtab_list
def
generate_type_definitions
(
self
,
env
,
modules
,
vtab_list
,
vtabslot_list
,
code
):
for
module
in
modules
:
definition
=
module
is
env
if
definition
:
type_entries
=
module
.
type_entries
else
:
type_entries
=
[]
for
entry
in
module
.
type_entries
:
if
entry
.
defined_in_pxd
:
type_entries
.
append
(
entry
)
self
.
generate_type_header_code
(
type_entries
,
code
)
for
entry
in
vtabslot_list
:
self
.
generate_obj_struct_definition
(
entry
.
type
,
code
)
for
entry
in
vtab_list
:
self
.
generate_typeobject_predeclaration
(
entry
,
code
)
self
.
generate_exttype_vtable_struct
(
entry
,
code
)
self
.
generate_exttype_vtabptr_declaration
(
entry
,
code
)
def
generate_declarations_for_modules
(
self
,
env
,
modules
,
code
):
code
.
putln
(
""
)
code
.
putln
(
""
)
code
.
putln
(
"/* Declarations */"
)
code
.
putln
(
"/* Declarations from %s */"
%
env
.
qualified_name
)
vtab_dict
=
self
.
generate_vtab_dict
(
modules
)
self
.
generate_type_predeclarations
(
env
,
code
)
vtab_list
=
self
.
generate_vtab_list
(
vtab_dict
)
self
.
generate_type_definitions
(
env
,
code
,
definition
)
vtabslot_dict
=
self
.
generate_vtabslot_dict
(
modules
,
env
)
self
.
generate_global_declarations
(
env
,
code
,
definition
)
vtabslot_list
=
self
.
generate_vtabslot_list
(
vtabslot_dict
)
self
.
generate_cfunction_predeclarations
(
env
,
code
,
definition
)
self
.
generate_type_definitions
(
env
,
modules
,
vtab_list
,
vtabslot_list
,
code
)
for
module
in
modules
:
def
generate_type_predeclarations
(
self
,
env
,
code
):
definition
=
module
is
env
pass
self
.
generate_global_declarations
(
module
,
code
,
definition
)
self
.
generate_cfunction_predeclarations
(
module
,
code
,
definition
)
def
generate_type_header_code
(
self
,
type_entries
,
code
):
def
generate_type_header_code
(
self
,
type_entries
,
code
):
# Generate definitions of structs/unions/enums/typedefs/objstructs.
# Generate definitions of structs/unions/enums/typedefs/objstructs.
#self.generate_gcc33_hack(env, code) # Is this still needed?
#self.generate_gcc33_hack(env, code) # Is this still needed?
...
@@ -474,6 +358,23 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -474,6 +358,23 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self
.
generate_struct_union_definition
(
entry
,
code
)
self
.
generate_struct_union_definition
(
entry
,
code
)
elif
type
.
is_enum
:
elif
type
.
is_enum
:
self
.
generate_enum_definition
(
entry
,
code
)
self
.
generate_enum_definition
(
entry
,
code
)
elif
type
.
is_extension_type
:
self
.
generate_obj_struct_definition
(
type
,
code
)
def
generate_type_definitions
(
self
,
env
,
code
,
definition
):
if
definition
:
type_entries
=
env
.
type_entries
else
:
type_entries
=
[]
for
entry
in
env
.
type_entries
:
if
entry
.
defined_in_pxd
:
type_entries
.
append
(
entry
)
self
.
generate_type_header_code
(
type_entries
,
code
)
for
entry
in
env
.
c_class_entries
:
if
not
entry
.
in_cinclude
:
self
.
generate_typeobject_predeclaration
(
entry
,
code
)
self
.
generate_exttype_vtable_struct
(
entry
,
code
)
self
.
generate_exttype_vtabptr_declaration
(
entry
,
code
)
def
generate_gcc33_hack
(
self
,
env
,
code
):
def
generate_gcc33_hack
(
self
,
env
,
code
):
# Workaround for spurious warning generation in gcc 3.3
# Workaround for spurious warning generation in gcc 3.3
...
@@ -1382,13 +1283,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1382,13 +1283,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"static void %s(void); /*proto*/"
%
Naming
.
fileinit_cname
)
code
.
putln
(
"static void %s(void); /*proto*/"
%
Naming
.
fileinit_cname
)
def
generate_module_init_func
(
self
,
imported_modules
,
env
,
code
):
def
generate_module_init_func
(
self
,
imported_modules
,
env
,
code
):
code
.
putln
(
""
)
code
.
putln
(
"PyMODINIT_FUNC init2%s(void);"
%
env
.
module_name
)
code
.
putln
(
""
)
code
.
putln
(
""
)
header
=
"PyMODINIT_FUNC init%s(void)"
%
env
.
module_name
header
=
"PyMODINIT_FUNC init%s(void)"
%
env
.
module_name
code
.
putln
(
"%s; /*proto*/"
%
header
)
code
.
putln
(
"%s; /*proto*/"
%
header
)
code
.
putln
(
"%s {"
%
header
)
code
.
putln
(
"%s {"
%
header
)
# do we need any of these here, or just in init2?
code
.
put_var_declarations
(
env
.
temp_entries
)
code
.
put_var_declarations
(
env
.
temp_entries
)
code
.
putln
(
"/*--- Libary function declarations ---*/"
)
code
.
putln
(
"/*--- Libary function declarations ---*/"
)
...
@@ -1417,48 +1315,31 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1417,48 +1315,31 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"/*--- Function export code ---*/"
)
code
.
putln
(
"/*--- Function export code ---*/"
)
self
.
generate_c_function_export_code
(
env
,
code
)
self
.
generate_c_function_export_code
(
env
,
code
)
env
.
use_utility_code
(
function_export_utility_code
)
code
.
putln
(
"/*--- Function import code ---*/"
)
code
.
putln
(
'if (__Pyx_ExportFunction("init2%s", (void*)init2%s, "int (void)") < 0) %s'
%
(
env
.
module_name
,
env
.
module_name
,
code
.
error_goto
((
env
.
qualified_name
,
0
,
0
)
)
)
)
for
module
in
imported_modules
:
self
.
generate_c_function_import_code_for_module
(
module
,
env
,
code
)
code
.
putln
(
"/*--- Type init code ---*/"
)
code
.
putln
(
"/*--- Type init code ---*/"
)
self
.
generate_type_init_code
(
env
,
code
)
self
.
generate_type_init_code
(
env
,
code
)
code
.
putln
(
"/*--- Type import code ---*/"
)
code
.
putln
(
"/*--- Type import code ---*/"
)
for
module
in
imported_modules
:
for
module
in
imported_modules
:
self
.
generate_type_import_code_for_module
(
module
,
env
,
code
)
self
.
generate_type_import_code_for_module
(
module
,
env
,
code
)
code
.
putln
(
"/*--- Function import code ---*/"
)
for
module
in
imported_modules
:
self
.
generate_c_function_import_code_for_module
(
module
,
env
,
code
)
code
.
putln
(
'init2%s();'
%
env
.
module_name
)
if
Options
.
generate_cleanup_code
:
code
.
putln
(
"if (__Pyx_RegisterCleanup()) %s;"
%
code
.
error_goto
(
self
.
pos
))
code
.
putln
(
"return;"
)
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
(
'}'
)
def
generate_module_init2_func
(
self
,
imported_modules
,
env
,
code
):
code
.
init_labels
()
code
.
putln
(
""
)
header
=
"PyMODINIT_FUNC init2%s(void)"
%
env
.
module_name
code
.
putln
(
"%s; /*proto*/"
%
header
)
code
.
putln
(
"%s {"
%
header
)
code
.
putln
(
"static int __Pyx_unique = 0;"
)
code
.
putln
(
"if (__Pyx_unique==1) return;"
)
code
.
putln
(
"__Pyx_unique = 1;"
)
code
.
put_var_declarations
(
env
.
temp_entries
)
code
.
putln
(
"/*--- Execution code ---*/"
)
code
.
putln
(
"/*--- Execution code ---*/"
)
code
.
mark_pos
(
None
)
code
.
mark_pos
(
None
)
self
.
body
.
generate_execution_code
(
code
)
self
.
body
.
generate_execution_code
(
code
)
if
Options
.
generate_cleanup_code
:
if
Options
.
generate_cleanup_code
:
code
.
putln
(
"if (__Pyx_RegisterCleanup()) %s;"
%
code
.
error_goto
(
self
.
pos
))
code
.
putln
(
"if (__Pyx_RegisterCleanup()) %s;"
%
code
.
error_goto
(
self
.
pos
))
code
.
putln
(
"return;"
)
code
.
putln
(
"return;"
)
code
.
put_label
(
code
.
error_label
)
code
.
put_label
(
code
.
error_label
)
code
.
put_var_xdecrefs
(
env
.
temp_entries
)
code
.
put_var_xdecrefs
(
env
.
temp_entries
)
code
.
putln
(
'__Pyx_AddTraceback("%s");'
%
env
.
qualified_name
)
code
.
putln
(
'__Pyx_AddTraceback("%s");'
%
env
.
qualified_name
)
env
.
use_utility_code
(
Nodes
.
traceback_utility_code
)
env
.
use_utility_code
(
Nodes
.
traceback_utility_code
)
code
.
putln
(
'}'
)
code
.
putln
(
'}'
)
def
generate_module_cleanup_func
(
self
,
env
,
code
):
def
generate_module_cleanup_func
(
self
,
env
,
code
):
if
not
Options
.
generate_cleanup_code
:
if
not
Options
.
generate_cleanup_code
:
return
return
...
@@ -1642,7 +1523,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1642,7 +1523,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self
.
generate_exttype_vtable_init_code
(
entry
,
code
)
self
.
generate_exttype_vtable_init_code
(
entry
,
code
)
self
.
generate_type_ready_code
(
env
,
entry
,
code
)
self
.
generate_type_ready_code
(
env
,
entry
,
code
)
self
.
generate_typeptr_assignment_code
(
entry
,
code
)
self
.
generate_typeptr_assignment_code
(
entry
,
code
)
def
generate_base_type_import_code
(
self
,
env
,
entry
,
code
):
def
generate_base_type_import_code
(
self
,
env
,
entry
,
code
):
base_type
=
entry
.
type
.
base_type
base_type
=
entry
.
type
.
base_type
if
base_type
and
base_type
.
module_name
!=
env
.
qualified_name
:
if
base_type
and
base_type
.
module_name
!=
env
.
qualified_name
:
...
@@ -1776,49 +1657,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1776,49 +1657,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
#
#
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
call_module_function_code
=
[
"""
static PyObject *__Pyx_CallModuleFunction(char* module, char *name); /*proto*/
"""
,
"""
static PyObject *__Pyx_CallModuleFunction(char* module, char *name)
{
PyObject* py_name = 0;
PyObject* py_module_name = 0;
PyObject* py_module = 0;
PyObject* py_dict = 0;
PyObject* py_func = 0;
PyObject* py_tuple = PyTuple_New(0);
PyObject* ret = 0;
py_dict = PyImport_GetModuleDict();
if(py_dict == 0)
goto bad;
if(py_tuple == 0)
goto bad;
py_name = PyString_FromString(name);
if(py_name == 0)
goto bad;
py_module_name = PyString_FromString(module);
if(py_module_name == 0)
goto bad;
py_module = PyObject_GetItem(py_dict, py_module);
if(py_module == 0)
goto bad;
if ( (py_func = PyObject_GetAttr(py_module, py_name) ) == 0)
goto bad;
if ( (ret = PyObject_Call(py_func, py_tuple,NULL) ) == 0)
goto bad;
return ret;
bad:
Py_XDECREF(py_name);
Py_XDECREF(py_module_name);
Py_XDECREF(py_module);
Py_XDECREF(py_dict);
Py_XDECREF(py_func);
return 0;
}
"""
]
import_module_utility_code
=
[
import_module_utility_code
=
[
"""
"""
static PyObject *__Pyx_ImportModule(char *name); /*proto*/
static PyObject *__Pyx_ImportModule(char *name); /*proto*/
...
@@ -1860,7 +1698,7 @@ static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name,
...
@@ -1860,7 +1698,7 @@ static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name,
py_name = PyString_FromString(module_name);
py_name = PyString_FromString(module_name);
if (!py_name)
if (!py_name)
goto bad;
goto bad;
py_module = __Pyx_ImportModule(module_name);
py_module = __Pyx_ImportModule(module_name);
if (!py_module)
if (!py_module)
goto bad;
goto bad;
...
@@ -1892,7 +1730,7 @@ bad:
...
@@ -1892,7 +1730,7 @@ bad:
function_export_utility_code
=
[
function_export_utility_code
=
[
"""
"""
static int __Pyx_ExportFunction(char *n
, void *f, char *s
); /*proto*/
static int __Pyx_ExportFunction(char *n
ame, void *f, char *sig
); /*proto*/
"""
,
r"""
"""
,
r"""
static int __Pyx_ExportFunction(char *name, void *f, char *sig) {
static int __Pyx_ExportFunction(char *name, void *f, char *sig) {
PyObject *d = 0;
PyObject *d = 0;
...
...
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