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
53a3e9a2
Commit
53a3e9a2
authored
Oct 03, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Repair compilation error for nested module level comprehensions.
Closes #1906.
parent
8514f0f8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
8 deletions
+56
-8
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+10
-4
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+14
-4
tests/run/dictcomp.pyx
tests/run/dictcomp.pyx
+32
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
53a3e9a2
...
@@ -7949,8 +7949,7 @@ class ScopedExprNode(ExprNode):
...
@@ -7949,8 +7949,7 @@ class ScopedExprNode(ExprNode):
generate_inner_evaluation_code
(
code
)
generate_inner_evaluation_code
(
code
)
# normal (non-error) exit
# normal (non-error) exit
for
entry
in
py_entries
:
self
.
_generate_vars_cleanup
(
code
,
py_entries
)
code
.
put_var_xdecref_clear
(
entry
)
# error/loop body exit points
# error/loop body exit points
exit_scope
=
code
.
new_label
(
'exit_scope'
)
exit_scope
=
code
.
new_label
(
'exit_scope'
)
...
@@ -7959,8 +7958,7 @@ class ScopedExprNode(ExprNode):
...
@@ -7959,8 +7958,7 @@ class ScopedExprNode(ExprNode):
list
(
zip
(
code
.
get_loop_labels
(),
old_loop_labels
))):
list
(
zip
(
code
.
get_loop_labels
(),
old_loop_labels
))):
if
code
.
label_used
(
label
):
if
code
.
label_used
(
label
):
code
.
put_label
(
label
)
code
.
put_label
(
label
)
for
entry
in
py_entries
:
self
.
_generate_vars_cleanup
(
code
,
py_entries
)
code
.
put_var_xdecref_clear
(
entry
)
code
.
put_goto
(
old_label
)
code
.
put_goto
(
old_label
)
code
.
put_label
(
exit_scope
)
code
.
put_label
(
exit_scope
)
code
.
putln
(
'} /* exit inner scope */'
)
code
.
putln
(
'} /* exit inner scope */'
)
...
@@ -7968,6 +7966,14 @@ class ScopedExprNode(ExprNode):
...
@@ -7968,6 +7966,14 @@ class ScopedExprNode(ExprNode):
code
.
set_loop_labels
(
old_loop_labels
)
code
.
set_loop_labels
(
old_loop_labels
)
code
.
error_label
=
old_error_label
code
.
error_label
=
old_error_label
def
_generate_vars_cleanup
(
self
,
code
,
py_entries
):
for
entry
in
py_entries
:
if
entry
.
is_cglobal
:
code
.
put_var_gotref
(
entry
)
code
.
put_decref_set
(
entry
.
cname
,
"Py_None"
)
else
:
code
.
put_var_xdecref_clear
(
entry
)
class
ComprehensionNode
(
ScopedExprNode
):
class
ComprehensionNode
(
ScopedExprNode
):
# A list/set/dict comprehension
# A list/set/dict comprehension
...
...
Cython/Compiler/Symtab.py
View file @
53a3e9a2
...
@@ -1715,7 +1715,10 @@ class LocalScope(Scope):
...
@@ -1715,7 +1715,10 @@ class LocalScope(Scope):
# Return None if not found.
# Return None if not found.
entry
=
Scope
.
lookup
(
self
,
name
)
entry
=
Scope
.
lookup
(
self
,
name
)
if
entry
is
not
None
:
if
entry
is
not
None
:
if
entry
.
scope
is
not
self
and
entry
.
scope
.
is_closure_scope
:
entry_scope
=
entry
.
scope
while
entry_scope
.
is_genexpr_scope
:
entry_scope
=
entry_scope
.
outer_scope
if
entry_scope
is
not
self
and
entry_scope
.
is_closure_scope
:
if
hasattr
(
entry
.
scope
,
"scope_class"
):
if
hasattr
(
entry
.
scope
,
"scope_class"
):
raise
InternalError
(
"lookup() after scope class created."
)
raise
InternalError
(
"lookup() after scope class created."
)
# The actual c fragment for the different scopes differs
# The actual c fragment for the different scopes differs
...
@@ -1751,8 +1754,12 @@ class GeneratorExpressionScope(Scope):
...
@@ -1751,8 +1754,12 @@ class GeneratorExpressionScope(Scope):
is_genexpr_scope
=
True
is_genexpr_scope
=
True
def
__init__
(
self
,
outer_scope
):
def
__init__
(
self
,
outer_scope
):
name
=
outer_scope
.
global_scope
().
next_id
(
Naming
.
genexpr_id_ref
)
parent_scope
=
outer_scope
Scope
.
__init__
(
self
,
name
,
outer_scope
,
outer_scope
)
# TODO: also ignore class scopes?
while
parent_scope
.
is_genexpr_scope
:
parent_scope
=
parent_scope
.
parent_scope
name
=
parent_scope
.
global_scope
().
next_id
(
Naming
.
genexpr_id_ref
)
Scope
.
__init__
(
self
,
name
,
outer_scope
,
parent_scope
)
self
.
directives
=
outer_scope
.
directives
self
.
directives
=
outer_scope
.
directives
self
.
genexp_prefix
=
"%s%d%s"
%
(
Naming
.
pyrex_prefix
,
len
(
name
),
name
)
self
.
genexp_prefix
=
"%s%d%s"
%
(
Naming
.
pyrex_prefix
,
len
(
name
),
name
)
...
@@ -1779,6 +1786,9 @@ class GeneratorExpressionScope(Scope):
...
@@ -1779,6 +1786,9 @@ class GeneratorExpressionScope(Scope):
cname
=
'%s%s'
%
(
self
.
genexp_prefix
,
self
.
parent_scope
.
mangle
(
Naming
.
var_prefix
,
name
or
self
.
next_id
()))
cname
=
'%s%s'
%
(
self
.
genexp_prefix
,
self
.
parent_scope
.
mangle
(
Naming
.
var_prefix
,
name
or
self
.
next_id
()))
entry
=
self
.
declare
(
name
,
cname
,
type
,
pos
,
visibility
)
entry
=
self
.
declare
(
name
,
cname
,
type
,
pos
,
visibility
)
entry
.
is_variable
=
True
entry
.
is_variable
=
True
if
self
.
parent_scope
.
is_module_scope
:
entry
.
is_cglobal
=
True
else
:
entry
.
is_local
=
True
entry
.
is_local
=
True
entry
.
in_subscope
=
True
entry
.
in_subscope
=
True
self
.
var_entries
.
append
(
entry
)
self
.
var_entries
.
append
(
entry
)
...
...
tests/run/dictcomp.pyx
View file @
53a3e9a2
...
@@ -57,3 +57,35 @@ def sorted(it):
...
@@ -57,3 +57,35 @@ def sorted(it):
l
=
list
(
it
)
l
=
list
(
it
)
l
.
sort
()
l
.
sort
()
return
l
return
l
# Copied from sre_compile.py in CPython 3.7. Previously failed to detect variable initialisation.
_equivalences
=
(
# LATIN SMALL LETTER I, LATIN SMALL LETTER DOTLESS I
(
0x69
,
0x131
),
# iı
# LATIN SMALL LETTER S, LATIN SMALL LETTER LONG S
(
0x73
,
0x17f
),
# sſ
# MICRO SIGN, GREEK SMALL LETTER MU
(
0xb5
,
0x3bc
),
# µμ
# COMBINING GREEK YPOGEGRAMMENI, GREEK SMALL LETTER IOTA, GREEK PROSGEGRAMMENI
(
0x345
,
0x3b9
,
0x1fbe
),
# \u0345ιι
# ...
)
_ignorecase_fixes
=
{
i
:
tuple
(
j
for
j
in
t
if
i
!=
j
)
for
t
in
_equivalences
for
i
in
t
}
def
nested_tuple
():
"""
>>> modlevel, funclevel = nested_tuple()
>>> modlevel == funclevel or (modlevel, funclevel)
True
"""
inner_ignorecase_fixes
=
{
i
:
tuple
(
j
for
j
in
t
if
i
!=
j
)
for
t
in
_equivalences
for
i
in
t
}
return
sorted
(
_ignorecase_fixes
.
items
()),
sorted
(
inner_ignorecase_fixes
.
items
())
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