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
63bcd561
Commit
63bcd561
authored
Mar 18, 2011
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provide BaseException in Python 2.3/2.4
parent
58109c4f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
3 deletions
+24
-3
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+11
-1
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+2
-2
tests/run/builtinnames.pyx
tests/run/builtinnames.pyx
+11
-0
No files found.
Cython/Compiler/Code.py
View file @
63bcd561
...
@@ -650,17 +650,27 @@ class GlobalState(object):
...
@@ -650,17 +650,27 @@ class GlobalState(object):
if self.should_declare(entry.cname, entry):
if self.should_declare(entry.cname, entry):
self.put_pyobject_decl(entry)
self.put_pyobject_decl(entry)
w = self.parts['cached_builtins']
w = self.parts['cached_builtins']
conditional_name = False
if entry.name == 'xrange':
if entry.name == 'xrange':
# replaced by range() in Py3
# replaced by range() in Py3
conditional_name = True
w.putln('#if PY_MAJOR_VERSION >= 3')
w.putln('#if PY_MAJOR_VERSION >= 3')
self.put_cached_builtin_init(
self.put_cached_builtin_init(
entry.pos, StringEncoding.EncodedString('range'),
entry.pos, StringEncoding.EncodedString('range'),
entry.cname)
entry.cname)
elif entry.name == 'BaseException':
# replace BaseException by Exception in Py<2.5
conditional_name = True
w.putln('#if PY_VERSION_HEX < 0x02050000')
self.put_cached_builtin_init(
entry.pos, StringEncoding.EncodedString('Exception'),
entry.cname)
if conditional_name:
w.putln('#else')
w.putln('#else')
self.put_cached_builtin_init(
self.put_cached_builtin_init(
entry.pos, StringEncoding.EncodedString(entry.name),
entry.pos, StringEncoding.EncodedString(entry.name),
entry.cname)
entry.cname)
if
entry.name == 'xrange'
:
if
conditional_name
:
w.putln('#endif')
w.putln('#endif')
def put_cached_builtin_init(self, pos, name, cname):
def put_cached_builtin_init(self, pos, name, cname):
...
...
Cython/Compiler/Symtab.py
View file @
63bcd561
...
@@ -902,8 +902,8 @@ class ModuleScope(Scope):
...
@@ -902,8 +902,8 @@ class ModuleScope(Scope):
return self.outer_scope.lookup(name, language_level = self.context.language_level)
return self.outer_scope.lookup(name, language_level = self.context.language_level)
def declare_builtin(self, name, pos):
def declare_builtin(self, name, pos):
if not hasattr(builtins, name) and name
!= 'xrange'
:
if not hasattr(builtins, name) and name
not in ('xrange', 'BaseException')
:
# 'xrange'
is
special cased in Code.py
# 'xrange'
and 'BaseException' are
special cased in Code.py
if self.has_import_star:
if self.has_import_star:
entry = self.declare_var(name, py_object_type, pos)
entry = self.declare_var(name, py_object_type, pos)
return entry
return entry
...
...
tests/run/builtinnames.pyx
View file @
63bcd561
...
@@ -56,3 +56,14 @@ def test_for_in_range(arg):
...
@@ -56,3 +56,14 @@ def test_for_in_range(arg):
for
c
in
range
(
arg
):
for
c
in
range
(
arg
):
l
.
append
(
c
)
l
.
append
(
c
)
return
l
return
l
def
raise_and_catch_BaseException
():
"""
>>> raise_and_catch_BaseException()
1
"""
try
:
raise
BaseException
except
BaseException
:
return
1
return
2
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