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):
for key, value in base.values.items():
if key not in kwds:
kwds[key] = value
sources = [file]
if template is not None:
sources += template.sources[1:]
module_list.append(exn_type(
name=module_name,
sources=[file],
sources=sources,
**kwds))
m = module_list[-1]
seen.add(name)
......
......@@ -655,17 +655,27 @@ class GlobalState(object):
if self.should_declare(entry.cname, entry):
self.put_pyobject_decl(entry)
w = self.parts['cached_builtins']
conditional_name = False
if entry.name == 'xrange':
# replaced by range() in Py3
conditional_name = True
w.putln('#if PY_MAJOR_VERSION >= 3')
self.put_cached_builtin_init(
entry.pos, StringEncoding.EncodedString('range'),
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')
self.put_cached_builtin_init(
entry.pos, StringEncoding.EncodedString(entry.name),
entry.cname)
if entry.name == 'xrange':
if conditional_name:
w.putln('#endif')
def put_cached_builtin_init(self, pos, name, cname):
......
......@@ -2011,7 +2011,7 @@ def looking_at_expr(s):
is_type = True
elif s.sy == '*' or s.sy == '**':
s.next()
is_type = s.sy == ')'
is_type = s.sy in (')', ']')
s.put_back(*saved)
elif s.sy == '(':
s.next()
......
......@@ -902,8 +902,8 @@ class ModuleScope(Scope):
return self.outer_scope.lookup(name, language_level = self.context.language_level)
def declare_builtin(self, name, pos):
if not hasattr(builtins, name) and name != 'xrange':
# 'xrange' is special cased in Code.py
if not hasattr(builtins, name) and name not in ('xrange', 'BaseException'):
# 'xrange' and 'BaseException' are special cased in Code.py
if self.has_import_star:
entry = self.declare_var(name, py_object_type, pos)
return entry
......@@ -1361,7 +1361,7 @@ class GeneratorExpressionScope(Scope):
self.genexp_prefix = "%s%d%s" % (Naming.pyrex_prefix, len(name), 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,
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):
# report the error for the original directory
libdir = sysconfig.get_config_var('LIBDIR')
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.abspath(os.path.join('..', '..', cython))
self.assert_(os.system(
......
......@@ -56,3 +56,14 @@ def test_for_in_range(arg):
for c in range(arg):
l.append(c)
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