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
5716d1ef
Commit
5716d1ef
authored
May 28, 2011
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add utility for unbound locals exception and use it inside CCodeWriter.put_error_if_unbound
parent
c87c0ba8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
8 deletions
+29
-8
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+9
-8
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+20
-0
No files found.
Cython/Compiler/Code.py
View file @
5716d1ef
...
@@ -1420,16 +1420,17 @@ class CCodeWriter(object):
...
@@ -1420,16 +1420,17 @@ class CCodeWriter(object):
return
self
.
putln
(
"if (%s < 0) %s"
%
(
value
,
self
.
error_goto
(
pos
)))
return
self
.
putln
(
"if (%s < 0) %s"
%
(
value
,
self
.
error_goto
(
pos
)))
def
put_error_if_unbound
(
self
,
pos
,
entry
):
def
put_error_if_unbound
(
self
,
pos
,
entry
):
self
.
put
(
'if (unlikely(!%s)) { PyErr_SetString('
%
entry
.
cname
)
import
ExprNodes
if
entry
.
from_closure
:
if
entry
.
from_closure
:
self
.
put
(
'PyExc_NameError, "'
)
func
=
'__Pyx_RaiseClosureNameError'
self
.
put
(
"free variable '%s' referenced before assignment in enclosing scope"
%
self
.
globalstate
.
use_utility_code
(
entry
.
nam
e
)
ExprNodes
.
raise_closure_name_error_utility_cod
e
)
else
:
else
:
self
.
put
(
'PyExc_UnboundLocalError, "'
)
func
=
'__Pyx_RaiseUnboundLocalError'
self
.
put
(
"local variable '%s' referenced before assignment"
%
self
.
globalstate
.
use_utility_code
(
entry
.
name
)
ExprNodes
.
raise_unbound_local_error_utility_code
)
self
.
putln
(
'"); %s }'
%
self
.
error_goto
(
pos
))
self
.
put
(
'if (unlikely(!%s)) { %s("%s"); %s }'
%
(
entry
.
cname
,
func
,
entry
.
name
,
self
.
error_goto
(
pos
)))
def
set_error_info
(
self
,
pos
):
def
set_error_info
(
self
,
pos
):
self
.
funcstate
.
should_declare_error_indicator
=
True
self
.
funcstate
.
should_declare_error_indicator
=
True
...
...
Cython/Compiler/ExprNodes.py
View file @
5716d1ef
...
@@ -8280,6 +8280,26 @@ static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
...
@@ -8280,6 +8280,26 @@ static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
}
}
'''
)
'''
)
raise_unbound_local_error_utility_code
=
UtilityCode
(
proto
=
"""
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);
"""
,
impl
=
"""
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}
"""
)
raise_closure_name_error_utility_code
=
UtilityCode
(
proto
=
"""
static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname);
"""
,
impl
=
"""
static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) {
PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname);
}
"""
)
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
getitem_dict_utility_code
=
UtilityCode
(
getitem_dict_utility_code
=
UtilityCode
(
...
...
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