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
da870f24
Commit
da870f24
authored
May 14, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed 'intern_names' Option - always intern identifier-like strings
parent
51f5387d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
143 deletions
+55
-143
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+34
-96
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+8
-17
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+11
-26
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+0
-1
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+2
-3
No files found.
Cython/Compiler/ExprNodes.py
View file @
da870f24
...
...
@@ -865,10 +865,7 @@ class NameNode(AtomicExprNode):
self
.
is_temp
=
0
else
:
self
.
is_temp
=
1
if
Options
.
intern_names
:
env
.
use_utility_code
(
get_name_interned_utility_code
)
else
:
env
.
use_utility_code
(
get_name_utility_code
)
env
.
use_utility_code
(
get_name_interned_utility_code
)
def
analyse_entry
(
self
,
env
):
#print "NameNode.analyse_entry:", self.name ###
...
...
@@ -878,8 +875,7 @@ class NameNode(AtomicExprNode):
self
.
type
=
type
if
entry
.
is_pyglobal
or
entry
.
is_builtin
:
assert
type
.
is_pyobject
,
"Python global or builtin not a Python object"
if
Options
.
intern_names
:
self
.
interned_cname
=
self
.
entry
.
interned_cname
=
env
.
intern
(
self
.
entry
.
name
)
self
.
interned_cname
=
self
.
entry
.
interned_cname
=
env
.
intern
(
self
.
entry
.
name
)
def
check_identifier_kind
(
self
):
#print "NameNode.check_identifier_kind:", self.entry.name ###
...
...
@@ -947,20 +943,12 @@ class NameNode(AtomicExprNode):
namespace
=
Naming
.
builtins_cname
else
:
# entry.is_pyglobal
namespace
=
entry
.
namespace_cname
if
Options
.
intern_names
:
code
.
putln
(
'%s = __Pyx_GetName(%s, %s); %s'
%
(
self
.
result_code
,
namespace
,
self
.
interned_cname
,
code
.
error_goto_if_null
(
self
.
result_code
,
self
.
pos
)))
else
:
code
.
putln
(
'%s = __Pyx_GetName(%s, "%s"); %s'
%
(
self
.
result_code
,
namespace
,
self
.
entry
.
name
,
code
.
error_goto_if_null
(
self
.
result_code
,
self
.
pos
)))
code
.
putln
(
'%s = __Pyx_GetName(%s, %s); %s'
%
(
self
.
result_code
,
namespace
,
self
.
interned_cname
,
code
.
error_goto_if_null
(
self
.
result_code
,
self
.
pos
)))
elif
entry
.
is_local
and
False
:
# control flow not good enough yet
assigned
=
entry
.
scope
.
control_flow
.
get_state
((
entry
.
name
,
'initalized'
),
self
.
pos
)
...
...
@@ -983,32 +971,17 @@ class NameNode(AtomicExprNode):
if
entry
.
is_member
:
# if we entry is a member we have to cheat: SetAttr does not work
# on types, so we create a descriptor which is then added to tp_dict
if
Options
.
intern_names
:
code
.
put_error_if_neg
(
self
.
pos
,
'PyDict_SetItem(%s->tp_dict, %s, %s)'
%
(
namespace
,
self
.
interned_cname
,
rhs
.
py_result
()))
else
:
code
.
put_error_if_neg
(
self
.
pos
,
'PyDict_SetItemString(%s->tp_dict, %s, %s)'
%
(
namespace
,
entry
.
name
,
rhs
.
py_result
()))
code
.
put_error_if_neg
(
self
.
pos
,
'PyDict_SetItem(%s->tp_dict, %s, %s)'
%
(
namespace
,
self
.
interned_cname
,
rhs
.
py_result
()))
else
:
if
Options
.
intern_names
:
code
.
put_error_if_neg
(
self
.
pos
,
'PyObject_SetAttr(%s, %s, %s)'
%
(
namespace
,
self
.
interned_cname
,
rhs
.
py_result
()))
else
:
code
.
put_error_if_neg
(
self
.
pos
,
'PyObject_SetAttrString(%s, "%s", %s)'
%
(
namespace
,
entry
.
name
,
rhs
.
py_result
()))
code
.
put_error_if_neg
(
self
.
pos
,
'PyObject_SetAttr(%s, %s, %s)'
%
(
namespace
,
self
.
interned_cname
,
rhs
.
py_result
()))
if
debug_disposal_code
:
print
(
"NameNode.generate_assignment_code:"
)
print
(
"...generating disposal code for %s"
%
rhs
)
...
...
@@ -2016,8 +1989,7 @@ class AttributeNode(ExprNode):
if
obj_type
.
is_pyobject
:
self
.
type
=
py_object_type
self
.
is_py_attr
=
1
if
Options
.
intern_names
:
self
.
interned_attr_cname
=
env
.
intern
(
self
.
attribute
)
self
.
interned_attr_cname
=
env
.
intern
(
self
.
attribute
)
else
:
if
not
obj_type
.
is_error
:
error
(
self
.
pos
,
...
...
@@ -2061,36 +2033,21 @@ class AttributeNode(ExprNode):
def
generate_result_code
(
self
,
code
):
if
self
.
is_py_attr
:
if
Options
.
intern_names
:
code
.
putln
(
'%s = PyObject_GetAttr(%s, %s); %s'
%
(
self
.
result_code
,
self
.
obj
.
py_result
(),
self
.
interned_attr_cname
,
code
.
error_goto_if_null
(
self
.
result_code
,
self
.
pos
)))
else
:
code
.
putln
(
'%s = PyObject_GetAttrString(%s, "%s"); %s'
%
(
self
.
result_code
,
self
.
obj
.
py_result
(),
self
.
attribute
,
code
.
error_goto_if_null
(
self
.
result_code
,
self
.
pos
)))
code
.
putln
(
'%s = PyObject_GetAttr(%s, %s); %s'
%
(
self
.
result_code
,
self
.
obj
.
py_result
(),
self
.
interned_attr_cname
,
code
.
error_goto_if_null
(
self
.
result_code
,
self
.
pos
)))
def
generate_assignment_code
(
self
,
rhs
,
code
):
self
.
obj
.
generate_evaluation_code
(
code
)
if
self
.
is_py_attr
:
if
Options
.
intern_names
:
code
.
put_error_if_neg
(
self
.
pos
,
'PyObject_SetAttr(%s, %s, %s)'
%
(
self
.
obj
.
py_result
(),
self
.
interned_attr_cname
,
rhs
.
py_result
()))
else
:
code
.
put_error_if_neg
(
self
.
pos
,
'PyObject_SetAttrString(%s, "%s", %s)'
%
(
self
.
obj
.
py_result
(),
self
.
attribute
,
rhs
.
py_result
()))
code
.
put_error_if_neg
(
self
.
pos
,
'PyObject_SetAttr(%s, %s, %s)'
%
(
self
.
obj
.
py_result
(),
self
.
interned_attr_cname
,
rhs
.
py_result
()))
rhs
.
generate_disposal_code
(
code
)
else
:
select_code
=
self
.
result_code
...
...
@@ -2108,16 +2065,10 @@ class AttributeNode(ExprNode):
def
generate_deletion_code
(
self
,
code
):
self
.
obj
.
generate_evaluation_code
(
code
)
if
self
.
is_py_attr
:
if
Options
.
intern_names
:
code
.
put_error_if_neg
(
self
.
pos
,
'PyObject_DelAttr(%s, %s)'
%
(
self
.
obj
.
py_result
(),
self
.
interned_attr_cname
))
else
:
code
.
put_error_if_neg
(
self
.
pos
,
'PyObject_DelAttrString(%s, "%s")'
%
(
self
.
obj
.
py_result
(),
self
.
attribute
))
code
.
put_error_if_neg
(
self
.
pos
,
'PyObject_DelAttr(%s, %s)'
%
(
self
.
obj
.
py_result
(),
self
.
interned_attr_cname
))
else
:
error
(
self
.
pos
,
"Cannot delete C attribute of extension type"
)
self
.
obj
.
generate_disposal_code
(
code
)
...
...
@@ -3904,19 +3855,6 @@ class CloneNode(CoercionNode):
#
#------------------------------------------------------------------------------------
get_name_utility_code
=
[
"""
static PyObject *__Pyx_GetName(PyObject *dict, char *name); /*proto*/
"""
,
"""
static PyObject *__Pyx_GetName(PyObject *dict, char *name) {
PyObject *result;
result = PyObject_GetAttrString(dict, name);
if (!result)
PyErr_SetString(PyExc_NameError, name);
return result;
}
"""
]
get_name_interned_utility_code
=
[
"""
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
...
...
Cython/Compiler/ModuleNode.py
View file @
da870f24
...
...
@@ -1560,23 +1560,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# Lookup and cache builtin objects.
if
Options
.
cache_builtins
:
for
entry
in
env
.
cached_builtins
:
if
Options
.
intern_names
:
#assert entry.interned_cname is not None
code
.
putln
(
'%s = __Pyx_GetName(%s, %s); if (!%s) %s'
%
(
entry
.
cname
,
Naming
.
builtins_cname
,
entry
.
interned_cname
,
entry
.
cname
,
code
.
error_goto
(
entry
.
pos
)))
else
:
code
.
putln
(
'%s = __Pyx_GetName(%s, "%s"); if (!%s) %s'
%
(
entry
.
cname
,
Naming
.
builtins_cname
,
entry
.
name
,
entry
.
cname
,
code
.
error_goto
(
entry
.
pos
)))
#assert entry.interned_cname is not None
code
.
putln
(
'%s = __Pyx_GetName(%s, %s); if (!%s) %s'
%
(
entry
.
cname
,
Naming
.
builtins_cname
,
entry
.
interned_cname
,
entry
.
cname
,
code
.
error_goto
(
entry
.
pos
)))
def
generate_global_init_code
(
self
,
env
,
code
):
# Generate code to initialise global PyObject *
...
...
Cython/Compiler/Nodes.py
View file @
da870f24
...
...
@@ -1084,8 +1084,7 @@ class CFuncDefNode(FuncDefNode):
self
.
entry
.
as_variable
=
self
.
py_func
.
entry
# Reset scope entry the above cfunction
env
.
entries
[
name
]
=
self
.
entry
if
Options
.
intern_names
:
self
.
py_func
.
interned_attr_cname
=
env
.
intern
(
self
.
py_func
.
entry
.
name
)
self
.
py_func
.
interned_attr_cname
=
env
.
intern
(
self
.
py_func
.
entry
.
name
)
if
not
env
.
is_module_scope
or
Options
.
lookup_module_cpdef
:
self
.
override
=
OverrideCheckNode
(
self
.
pos
,
py_func
=
self
.
py_func
)
self
.
body
=
StatListNode
(
self
.
pos
,
stats
=
[
self
.
override
,
self
.
body
])
...
...
@@ -1925,10 +1924,7 @@ class OverrideCheckNode(StatNode):
code
.
putln
(
"else if (unlikely(Py_TYPE(%s)->tp_dictoffset != 0)) {"
%
self_arg
)
err
=
code
.
error_goto_if_null
(
self_arg
,
self
.
pos
)
# need to get attribute manually--scope would return cdef method
if
Options
.
intern_names
:
code
.
putln
(
"%s = PyObject_GetAttr(%s, %s); %s"
%
(
self
.
func_node
.
result_code
,
self_arg
,
self
.
py_func
.
interned_attr_cname
,
err
))
else
:
code
.
putln
(
'%s = PyObject_GetAttrString(%s, "%s"); %s'
%
(
self
.
func_node
.
result_code
,
self_arg
,
self
.
py_func
.
entry
.
name
,
err
))
code
.
putln
(
"%s = PyObject_GetAttr(%s, %s); %s"
%
(
self
.
func_node
.
result_code
,
self_arg
,
self
.
py_func
.
interned_attr_cname
,
err
))
# It appears that this type is not anywhere exposed in the Python/C API
is_builtin_function_or_method
=
'(strcmp(Py_TYPE(%s)->tp_name, "builtin_function_or_method") == 0)'
%
self
.
func_node
.
result_code
is_overridden
=
'(PyCFunction_GET_FUNCTION(%s) != (void *)&%s)'
%
(
self
.
func_node
.
result_code
,
self
.
py_func
.
entry
.
func_cname
)
...
...
@@ -3683,8 +3679,7 @@ class FromImportStatNode(StatNode):
self
.
item
.
allocate_temp
(
env
)
self
.
interned_items
=
[]
for
name
,
target
in
self
.
items
:
if
Options
.
intern_names
:
self
.
interned_items
.
append
((
env
.
intern
(
name
),
target
))
self
.
interned_items
.
append
((
env
.
intern
(
name
),
target
))
target
.
analyse_target_expression
(
env
,
None
)
#target.release_target_temp(env) # was release_temp ?!?
self
.
module
.
release_temp
(
env
)
...
...
@@ -3692,24 +3687,14 @@ class FromImportStatNode(StatNode):
def
generate_execution_code
(
self
,
code
):
self
.
module
.
generate_evaluation_code
(
code
)
if
Options
.
intern_names
:
for
cname
,
target
in
self
.
interned_items
:
code
.
putln
(
'%s = PyObject_GetAttr(%s, %s); %s'
%
(
self
.
item
.
result_code
,
self
.
module
.
py_result
(),
cname
,
code
.
error_goto_if_null
(
self
.
item
.
result_code
,
self
.
pos
)))
target
.
generate_assignment_code
(
self
.
item
,
code
)
else
:
for
name
,
target
in
self
.
items
:
code
.
putln
(
'%s = PyObject_GetAttrString(%s, "%s"); %s'
%
(
self
.
item
.
result_code
,
self
.
module
.
py_result
(),
name
,
code
.
error_goto_if_null
(
self
.
item
.
result_code
,
self
.
pos
)))
target
.
generate_assignment_code
(
self
.
item
,
code
)
for
cname
,
target
in
self
.
interned_items
:
code
.
putln
(
'%s = PyObject_GetAttr(%s, %s); %s'
%
(
self
.
item
.
result_code
,
self
.
module
.
py_result
(),
cname
,
code
.
error_goto_if_null
(
self
.
item
.
result_code
,
self
.
pos
)))
target
.
generate_assignment_code
(
self
.
item
,
code
)
self
.
module
.
generate_disposal_code
(
code
)
#------------------------------------------------------------------------------------
...
...
Cython/Compiler/Options.py
View file @
da870f24
...
...
@@ -2,7 +2,6 @@
# Pyrex - Compilation-wide options
#
intern_names
=
1
# Intern global variable and attribute names
cache_builtins
=
1
# Perform lookups on builtin names only once
embed_pos_in_docstring
=
0
...
...
Cython/Compiler/Symtab.py
View file @
da870f24
...
...
@@ -1238,10 +1238,9 @@ class CClassScope(ClassScope):
# I keep it in for now. is_member should be enough
# later on
entry
.
namespace_cname
=
"(PyObject *)%s"
%
self
.
parent_type
.
typeptr_cname
if
Options
.
intern_names
:
entry
.
interned_cname
=
self
.
intern
(
name
)
entry
.
interned_cname
=
self
.
intern
(
name
)
return
entry
def
declare_pyfunction
(
self
,
name
,
pos
):
# Add an entry for a method.
...
...
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