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
7cf517e2
Commit
7cf517e2
authored
Jun 26, 2018
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '0.28.x'
parents
084a25f5
7f41244d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
0 deletions
+62
-0
CHANGES.rst
CHANGES.rst
+3
-0
Cython/Utility/ModuleSetupCode.c
Cython/Utility/ModuleSetupCode.c
+25
-0
tests/run/tryexcept.pyx
tests/run/tryexcept.pyx
+34
-0
No files found.
CHANGES.rst
View file @
7cf517e2
...
@@ -70,6 +70,9 @@ Bugs fixed
...
@@ -70,6 +70,9 @@ Bugs fixed
generated an invalid C function call to the (non-existent) base type implementation.
generated an invalid C function call to the (non-existent) base type implementation.
(Github issue #2309)
(Github issue #2309)
* Exception catching based on a non-literal (runtime) tuple could fail to match the
exception. (Github issue #2425)
0.28.3 (2018-05-27)
0.28.3 (2018-05-27)
===================
===================
...
...
Cython/Utility/ModuleSetupCode.c
View file @
7cf517e2
...
@@ -796,15 +796,40 @@ static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err,
...
@@ -796,15 +796,40 @@ static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err,
// so far, we only call PyErr_GivenExceptionMatches() with an exception type (not instance) as first argument
// so far, we only call PyErr_GivenExceptionMatches() with an exception type (not instance) as first argument
// => optimise for that case
// => optimise for that case
static
int
__Pyx_PyErr_GivenExceptionMatchesTuple
(
PyObject
*
exc_type
,
PyObject
*
tuple
)
{
Py_ssize_t
i
,
n
;
assert
(
PyExceptionClass_Check
(
exc_type
));
n
=
PyTuple_GET_SIZE
(
tuple
);
#if PY_MAJOR_VERSION >= 3
// the tighter subtype checking in Py3 allows faster out-of-order comparison
for
(
i
=
0
;
i
<
n
;
i
++
)
{
if
(
exc_type
==
PyTuple_GET_ITEM
(
tuple
,
i
))
return
1
;
}
#endif
for
(
i
=
0
;
i
<
n
;
i
++
)
{
PyObject
*
t
=
PyTuple_GET_ITEM
(
tuple
,
i
);
#if PY_MAJOR_VERSION < 3
if
(
likely
(
exc_type
==
t
))
return
1
;
#endif
if
(
__Pyx_inner_PyErr_GivenExceptionMatches2
(
exc_type
,
NULL
,
t
))
return
1
;
}
return
0
;
}
static
CYTHON_INLINE
int
__Pyx_PyErr_GivenExceptionMatches
(
PyObject
*
err
,
PyObject
*
exc_type
)
{
static
CYTHON_INLINE
int
__Pyx_PyErr_GivenExceptionMatches
(
PyObject
*
err
,
PyObject
*
exc_type
)
{
if
(
likely
(
err
==
exc_type
))
return
1
;
if
(
likely
(
err
==
exc_type
))
return
1
;
if
(
likely
(
PyExceptionClass_Check
(
err
)))
{
if
(
likely
(
PyExceptionClass_Check
(
err
)))
{
if
(
unlikely
(
PyTuple_Check
(
exc_type
)))
{
return
__Pyx_PyErr_GivenExceptionMatchesTuple
(
err
,
exc_type
);
}
return
__Pyx_inner_PyErr_GivenExceptionMatches2
(
err
,
NULL
,
exc_type
);
return
__Pyx_inner_PyErr_GivenExceptionMatches2
(
err
,
NULL
,
exc_type
);
}
}
return
PyErr_GivenExceptionMatches
(
err
,
exc_type
);
return
PyErr_GivenExceptionMatches
(
err
,
exc_type
);
}
}
static
CYTHON_INLINE
int
__Pyx_PyErr_GivenExceptionMatches2
(
PyObject
*
err
,
PyObject
*
exc_type1
,
PyObject
*
exc_type2
)
{
static
CYTHON_INLINE
int
__Pyx_PyErr_GivenExceptionMatches2
(
PyObject
*
err
,
PyObject
*
exc_type1
,
PyObject
*
exc_type2
)
{
assert
(
PyExceptionClass_Check
(
exc_type1
));
assert
(
PyExceptionClass_Check
(
exc_type2
));
if
(
likely
(
err
==
exc_type1
||
err
==
exc_type2
))
return
1
;
if
(
likely
(
err
==
exc_type1
||
err
==
exc_type2
))
return
1
;
if
(
likely
(
PyExceptionClass_Check
(
err
)))
{
if
(
likely
(
PyExceptionClass_Check
(
err
)))
{
return
__Pyx_inner_PyErr_GivenExceptionMatches2
(
err
,
exc_type1
,
exc_type2
);
return
__Pyx_inner_PyErr_GivenExceptionMatches2
(
err
,
exc_type1
,
exc_type2
);
...
...
tests/run/tryexcept.pyx
View file @
7cf517e2
...
@@ -58,6 +58,36 @@ def single_except_expression(a, x):
...
@@ -58,6 +58,36 @@ def single_except_expression(a, x):
i
=
3
i
=
3
return
i
return
i
exceptions
=
(
ValueError
,
TypeError
)
def
single_except_global_tuple
(
x
):
"""
>>> single_except_global_tuple(None)
2
>>> single_except_global_tuple(ValueError('test'))
3
>>> single_except_global_tuple(TypeError('test'))
3
>>> class TypeErrorSubtype(TypeError): pass
>>> single_except_global_tuple(TypeErrorSubtype('test'))
3
>>> single_except_global_tuple(AttributeError('test'))
Traceback (most recent call last):
AttributeError: test
"""
cdef
int
i
try
:
i
=
1
if
x
:
raise
x
i
=
2
except
exceptions
:
i
=
3
return
i
def
double_except_no_raise
(
a
,
b
):
def
double_except_no_raise
(
a
,
b
):
"""
"""
>>> double_except_no_raise(TypeError, ValueError)
>>> double_except_no_raise(TypeError, ValueError)
...
@@ -179,6 +209,10 @@ def normal_and_bare_except_raise(x, a):
...
@@ -179,6 +209,10 @@ def normal_and_bare_except_raise(x, a):
2
2
>>> normal_and_bare_except_raise(ValueError('test'), TypeError)
>>> normal_and_bare_except_raise(ValueError('test'), TypeError)
3
3
>>> normal_and_bare_except_raise(TypeError('test'), (TypeError, ValueError))
2
>>> normal_and_bare_except_raise(ValueError('test'), (TypeError, ValueError))
2
>>> normal_and_bare_except_raise(None, TypeError)
>>> normal_and_bare_except_raise(None, TypeError)
1
1
"""
"""
...
...
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