Commit d1781ddc authored by Vitja Makarov's avatar Vitja Makarov

Merge remote branch 'upstream/master'

parents 231b6b64 63bcd561
...@@ -434,9 +434,12 @@ def create_extension_list(patterns, exclude=[], ctx=None, aliases=None): ...@@ -434,9 +434,12 @@ def create_extension_list(patterns, exclude=[], ctx=None, aliases=None):
for key, value in base.values.items(): for key, value in base.values.items():
if key not in kwds: if key not in kwds:
kwds[key] = value kwds[key] = value
sources = [file]
if template is not None:
sources += template.sources[1:]
module_list.append(exn_type( module_list.append(exn_type(
name=module_name, name=module_name,
sources=[file], sources=sources,
**kwds)) **kwds))
m = module_list[-1] m = module_list[-1]
seen.add(name) seen.add(name)
......
...@@ -655,17 +655,27 @@ class GlobalState(object): ...@@ -655,17 +655,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):
......
...@@ -2011,7 +2011,7 @@ def looking_at_expr(s): ...@@ -2011,7 +2011,7 @@ def looking_at_expr(s):
is_type = True is_type = True
elif s.sy == '*' or s.sy == '**': elif s.sy == '*' or s.sy == '**':
s.next() s.next()
is_type = s.sy == ')' is_type = s.sy in (')', ']')
s.put_back(*saved) s.put_back(*saved)
elif s.sy == '(': elif s.sy == '(':
s.next() s.next()
......
...@@ -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
...@@ -1361,7 +1361,7 @@ class GeneratorExpressionScope(Scope): ...@@ -1361,7 +1361,7 @@ class GeneratorExpressionScope(Scope):
self.genexp_prefix = "%s%d%s" % (Naming.pyrex_prefix, len(name), name) self.genexp_prefix = "%s%d%s" % (Naming.pyrex_prefix, len(name), name)
def mangle(self, prefix, name): def mangle(self, prefix, name):
return '%s%s' % (self.genexp_prefix, self.parent_scope.mangle(self, prefix, name)) return '%s%s' % (self.genexp_prefix, self.parent_scope.mangle(prefix, name))
def declare_var(self, name, type, pos, def declare_var(self, name, type, pos,
cname = None, visibility = 'private', is_cdef = True): cname = None, visibility = 'private', is_cdef = True):
......
cdef extern from "setjmp.h" nogil:
ctypedef struct jmp_buf:
pass
int setjmp(jmp_buf STATE)
void longjmp(jmp_buf STATE, int VALUE)
...@@ -894,7 +894,7 @@ class EmbedTest(unittest.TestCase): ...@@ -894,7 +894,7 @@ class EmbedTest(unittest.TestCase):
# report the error for the original directory # report the error for the original directory
libdir = sysconfig.get_config_var('LIBDIR') libdir = sysconfig.get_config_var('LIBDIR')
cython = 'cython.py' cython = 'cython.py'
if sys.version_info[0] >=3: if sys.version_info[0] >=3 and CY3_DIR:
cython = os.path.join(CY3_DIR, cython) cython = os.path.join(CY3_DIR, cython)
cython = os.path.abspath(os.path.join('..', '..', cython)) cython = os.path.abspath(os.path.join('..', '..', cython))
self.assert_(os.system( self.assert_(os.system(
......
...@@ -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
from libc.setjmp cimport *
cdef void check_nonzero(jmp_buf ctx, int x) nogil:
if x == 0:
longjmp(ctx, 1)
def nonzero(int x):
"""
>>> nonzero(-1)
True
>>> nonzero(0)
False
>>> nonzero(1)
True
>>> nonzero(2)
True
"""
cdef jmp_buf ctx
if setjmp(ctx) == 0:
check_nonzero(ctx, x)
return True
else:
return False
from libc.string cimport strcpy
cdef char error_msg[256]
cdef jmp_buf error_ctx
cdef void error(char msg[]) nogil:
strcpy(error_msg,msg)
longjmp(error_ctx, 1)
cdef void c_call(int x) nogil:
if x<=0:
error(b"expected a positive value")
def execute_c_call(int x):
"""
>>> execute_c_call(+2)
>>> execute_c_call(+1)
>>> execute_c_call(+0)
Traceback (most recent call last):
...
RuntimeError: expected a positive value
>>> execute_c_call(-1)
Traceback (most recent call last):
...
RuntimeError: expected a positive value
"""
if not setjmp(error_ctx):
c_call(x)
else:
raise RuntimeError(error_msg.decode())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment