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
8829d7b1
Commit
8829d7b1
authored
Sep 17, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
streamline exception type tests
parent
7fad6270
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
59 additions
and
27 deletions
+59
-27
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+9
-4
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+2
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+2
-1
Cython/Utility/Builtins.c
Cython/Utility/Builtins.c
+2
-1
Cython/Utility/Coroutine.c
Cython/Utility/Coroutine.c
+6
-4
Cython/Utility/Exceptions.c
Cython/Utility/Exceptions.c
+19
-0
Cython/Utility/FunctionArguments.c
Cython/Utility/FunctionArguments.c
+2
-1
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+17
-15
No files found.
Cython/Compiler/ExprNodes.py
View file @
8829d7b1
...
...
@@ -2253,9 +2253,11 @@ class NameNode(AtomicExprNode):
key_error_code
=
(
'{ PyErr_Clear(); PyErr_Format(PyExc_NameError, "name
\
'
%%s
\
'
is not defined", "%s"); }'
%
self
.
entry
.
name
)
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"PyErrExceptionMatches"
,
"Exceptions.c"
))
code
.
putln
(
'if (unlikely(PyObject_DelItem(%s, %s) < 0)) {'
' if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) %s'
' if (likely(
__Pyx_
PyErr_ExceptionMatches(PyExc_KeyError))) %s'
' %s '
'}'
%
(
namespace
,
interned_cname
,
key_error_code
,
...
...
@@ -2267,9 +2269,12 @@ class NameNode(AtomicExprNode):
del_code
=
'__Pyx_PyObject_DelAttrStr(%s, %s)'
%
(
Naming
.
module_cname
,
interned_cname
)
if
ignore_nonexisting
:
code
.
putln
(
'if (unlikely(%s < 0)) { if (likely(PyErr_ExceptionMatches(PyExc_AttributeError))) PyErr_Clear(); else %s }'
%
(
del_code
,
code
.
error_goto
(
self
.
pos
)))
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"PyErrExceptionMatches"
,
"Exceptions.c"
))
code
.
putln
(
'if (unlikely(%s < 0)) {'
' if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) PyErr_Clear(); else %s '
'}'
%
(
del_code
,
code
.
error_goto
(
self
.
pos
)))
else
:
code
.
put_error_if_neg
(
self
.
pos
,
del_code
)
elif
self
.
entry
.
type
.
is_pyobject
or
self
.
entry
.
type
.
is_memoryviewslice
:
...
...
Cython/Compiler/ModuleNode.py
View file @
8829d7b1
...
...
@@ -1725,8 +1725,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"PyObject *v = PyObject_GenericGetAttr(o, n);"
)
if
getattr_entry
is
not
None
:
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"PyErrExceptionMatches"
,
"Exceptions.c"
))
code
.
putln
(
"if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) {"
)
"if (!v &&
__Pyx_
PyErr_ExceptionMatches(PyExc_AttributeError)) {"
)
code
.
putln
(
"PyErr_Clear();"
)
code
.
putln
(
...
...
Cython/Compiler/Nodes.py
View file @
8829d7b1
...
...
@@ -4122,7 +4122,8 @@ class GeneratorBodyDefNode(DefNode):
if
Future
.
generator_stop
in
env
.
global_scope
().
context
.
future_directives
:
# PEP 479: turn accidental StopIteration exceptions into a RuntimeError
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"pep479"
,
"Coroutine.c"
))
code
.
putln
(
"if (unlikely(PyErr_ExceptionMatches(PyExc_StopIteration))) "
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"PyErrExceptionMatches"
,
"Exceptions.c"
))
code
.
putln
(
"if (unlikely(__Pyx_PyErr_ExceptionMatches(PyExc_StopIteration))) "
"__Pyx_Generator_Replace_StopIteration();"
)
for
cname
,
type
in
code
.
funcstate
.
all_managed_temps
():
code
.
put_xdecref
(
cname
,
type
)
...
...
Cython/Utility/Builtins.c
View file @
8829d7b1
...
...
@@ -167,12 +167,13 @@ bad:
static
CYTHON_INLINE
PyObject
*
__Pyx_GetAttr3
(
PyObject
*
,
PyObject
*
,
PyObject
*
);
/*proto*/
//////////////////// GetAttr3 ////////////////////
//@requires: Exceptions.c::PyErrExceptionMatches
//@requires: ObjectHandling.c::GetAttr
static
CYTHON_INLINE
PyObject
*
__Pyx_GetAttr3
(
PyObject
*
o
,
PyObject
*
n
,
PyObject
*
d
)
{
PyObject
*
r
=
__Pyx_GetAttr
(
o
,
n
);
if
(
unlikely
(
!
r
))
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
if
(
!
__Pyx_
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
goto
bad
;
PyErr_Clear
();
r
=
d
;
...
...
Cython/Utility/Coroutine.c
View file @
8829d7b1
...
...
@@ -177,6 +177,7 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_AsyncIterNext(PyObject *o); /*pro
//////////////////// AsyncIter ////////////////////
//@requires: GetAwaitIter
//@requires: Exceptions.c::PyErrExceptionMatches
//@requires: ObjectHandling.c::PyObjectCallMethod0
static
CYTHON_INLINE
PyObject
*
__Pyx_Coroutine_GetAsyncIter
(
PyObject
*
obj
)
{
...
...
@@ -192,7 +193,7 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAsyncIter(PyObject *obj) {
if
(
likely
(
iter
))
return
iter
;
// FIXME: for the sake of a nicely conforming exception message, assume any AttributeError meant '__aiter__'
if
(
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
if
(
!
__Pyx_
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
return
NULL
;
}
#else
...
...
@@ -219,7 +220,7 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_AsyncIterNext(PyObject *obj) {
return
value
;
}
// FIXME: for the sake of a nicely conforming exception message, assume any AttributeError meant '__anext__'
if
(
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
if
(
__Pyx_
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
#endif
PyErr_Format
(
PyExc_TypeError
,
"'async for' requires an object with __anext__ method, got %.100s"
,
Py_TYPE
(
obj
)
->
tp_name
);
...
...
@@ -309,6 +310,7 @@ static int __pyx_Generator_init(void); /*proto*/
//@requires: Exceptions.c::PyErrFetchRestore
//@requires: Exceptions.c::SwapException
//@requires: Exceptions.c::RaiseException
//@requires: Exceptions.c::PyErrExceptionMatches
//@requires: ObjectHandling.c::PyObjectCallMethod1
//@requires: ObjectHandling.c::PyObjectGetAttrStr
//@requires: CommonTypes.c::FetchCommonType
...
...
@@ -602,7 +604,7 @@ static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) {
gen
->
is_running
=
1
;
meth
=
__Pyx_PyObject_GetAttrStr
(
yf
,
PYIDENT
(
"close"
));
if
(
unlikely
(
!
meth
))
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
{
if
(
!
__Pyx_
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
{
PyErr_WriteUnraisable
(
yf
);
}
PyErr_Clear
();
...
...
@@ -718,7 +720,7 @@ static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) {
PyObject
*
meth
=
__Pyx_PyObject_GetAttrStr
(
yf
,
PYIDENT
(
"throw"
));
if
(
unlikely
(
!
meth
))
{
Py_DECREF
(
yf
);
if
(
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
{
if
(
!
__Pyx_
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
{
gen
->
is_running
=
0
;
return
NULL
;
}
...
...
Cython/Utility/Exceptions.c
View file @
8829d7b1
...
...
@@ -5,6 +5,25 @@
// 'except' statement, curexc_* is moved over to exc_* by
// __Pyx_GetException()
/////////////// PyErrExceptionMatches.proto ///////////////
#if CYTHON_COMPILING_IN_CPYTHON
static
CYTHON_INLINE
int
__Pyx_PyErr_ExceptionMatches
(
PyObject
*
err
);
#else
#define __Pyx_PyErr_ExceptionMatches(exc_type) PyErr_ExceptionMatches(exc_type)
#endif
/////////////// PyErrExceptionMatches ///////////////
#if CYTHON_COMPILING_IN_CPYTHON
static
CYTHON_INLINE
int
__Pyx_PyErr_ExceptionMatches
(
PyObject
*
err
)
{
PyObject
*
exc_type
=
PyThreadState_GET
()
->
curexc_type
;
if
(
exc_type
==
err
)
return
1
;
if
(
unlikely
(
!
exc_type
))
return
0
;
return
PyErr_GivenExceptionMatches
(
exc_type
,
err
);
}
#endif
/////////////// PyErrFetchRestore.proto ///////////////
static
CYTHON_INLINE
void
__Pyx_ErrRestore
(
PyObject
*
type
,
PyObject
*
value
,
PyObject
*
tb
);
/*proto*/
...
...
Cython/Utility/FunctionArguments.c
View file @
8829d7b1
...
...
@@ -308,6 +308,7 @@ bad:
static
int
__Pyx_MergeKeywords
(
PyObject
*
kwdict
,
PyObject
*
source_mapping
);
/*proto*/
//////////////////// MergeKeywords ////////////////////
//@requires: Exceptions.c::PyErrExceptionMatches
//@requires: RaiseDoubleKeywords
//@requires: Optimize.c::dict_iter
...
...
@@ -320,7 +321,7 @@ static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping) {
if
(
unlikely
(
!
iter
))
{
// slow fallback: try converting to dict, then iterate
PyObject
*
args
;
if
(
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
goto
bad
;
if
(
!
__Pyx_
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
goto
bad
;
PyErr_Clear
();
args
=
PyTuple_Pack
(
1
,
source_mapping
);
if
(
likely
(
args
))
{
...
...
Cython/Utility/ObjectHandling.c
View file @
8829d7b1
...
...
@@ -268,6 +268,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
int
is_list
,
int
wraparound
,
int
boundscheck
);
/////////////// GetItemInt ///////////////
//@requires: Exceptions.c::PyErrExceptionMatches
static
CYTHON_INLINE
PyObject
*
__Pyx_GetItemInt_Generic
(
PyObject
*
o
,
PyObject
*
j
)
{
PyObject
*
r
;
...
...
@@ -324,10 +325,9 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
i
+=
l
;
}
else
{
// if length > max(Py_ssize_t), maybe the object can wrap around itself?
if
(
PyErr_ExceptionMatches
(
PyExc_OverflowError
))
PyErr_Clear
();
else
if
(
!
__Pyx_PyErr_ExceptionMatches
(
PyExc_OverflowError
))
return
NULL
;
PyErr_Clear
();
}
}
return
m
->
sq_item
(
o
,
i
);
...
...
@@ -354,6 +354,7 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje
int
is_list
,
int
wraparound
,
int
boundscheck
);
/////////////// SetItemInt ///////////////
//@requires: Exceptions.c::PyErrExceptionMatches
static
CYTHON_INLINE
int
__Pyx_SetItemInt_Generic
(
PyObject
*
o
,
PyObject
*
j
,
PyObject
*
v
)
{
int
r
;
...
...
@@ -385,10 +386,9 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje
i
+=
l
;
}
else
{
// if length > max(Py_ssize_t), maybe the object can wrap around itself?
if
(
PyErr_ExceptionMatches
(
PyExc_OverflowError
))
PyErr_Clear
();
else
if
(
!
__Pyx_PyErr_ExceptionMatches
(
PyExc_OverflowError
))
return
-
1
;
PyErr_Clear
();
}
}
return
m
->
sq_ass_item
(
o
,
i
,
v
);
...
...
@@ -420,6 +420,7 @@ static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
int
is_list
,
int
wraparound
);
/////////////// DelItemInt ///////////////
//@requires: Exceptions.c::PyErrExceptionMatches
static
CYTHON_INLINE
int
__Pyx_DelItem_Generic
(
PyObject
*
o
,
PyObject
*
j
)
{
int
r
;
...
...
@@ -445,10 +446,9 @@ static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
i
+=
l
;
}
else
{
// if length > max(Py_ssize_t), maybe the object can wrap around itself?
if
(
PyErr_ExceptionMatches
(
PyExc_OverflowError
))
PyErr_Clear
();
else
if
(
!
__Pyx_PyErr_ExceptionMatches
(
PyExc_OverflowError
))
return
-
1
;
PyErr_Clear
();
}
}
return
m
->
sq_ass_item
(
o
,
i
,
(
PyObject
*
)
NULL
);
...
...
@@ -478,6 +478,7 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice(
{{
endif
}}
/////////////// SliceObject ///////////////
//@requires: Exceptions.c::PyErrExceptionMatches
{{
if
access
==
'
Get
'
}}
static
CYTHON_INLINE
PyObject
*
__Pyx_PyObject_GetSlice
(
PyObject
*
obj
,
...
...
@@ -519,10 +520,9 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice(PyObject* obj, PyObject* value,
}
}
else
{
// if length > max(Py_ssize_t), maybe the object can wrap around itself?
if
(
PyErr_ExceptionMatches
(
PyExc_OverflowError
))
PyErr_Clear
();
else
if
(
!
__Pyx_PyErr_ExceptionMatches
(
PyExc_OverflowError
))
goto
bad
;
PyErr_Clear
();
}
}
{{
if
access
==
'
Get
'
}}
...
...
@@ -833,6 +833,7 @@ static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObj
PyObject
*
mkw
,
int
calculate_metaclass
,
int
allow_py2_metaclass
);
/*proto*/
/////////////// Py3ClassCreate ///////////////
//@requires: Exceptions.c::PyErrExceptionMatches
//@requires: PyObjectGetAttrStr
//@requires: CalculateMetaclass
...
...
@@ -851,7 +852,7 @@ static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases,
Py_DECREF
(
prep
);
Py_DECREF
(
pargs
);
}
else
{
if
(
unlikely
(
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
)))
if
(
unlikely
(
!
__Pyx_
PyErr_ExceptionMatches
(
PyExc_AttributeError
)))
return
NULL
;
PyErr_Clear
();
ns
=
PyDict_New
();
...
...
@@ -883,7 +884,7 @@ static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObj
owned_metaclass
=
PyObject_GetItem
(
dict
,
PYIDENT
(
"__metaclass__"
));
if
(
owned_metaclass
)
{
metaclass
=
owned_metaclass
;
}
else
if
(
likely
(
PyErr_ExceptionMatches
(
PyExc_KeyError
)))
{
}
else
if
(
likely
(
__Pyx_
PyErr_ExceptionMatches
(
PyExc_KeyError
)))
{
PyErr_Clear
();
}
else
{
return
NULL
;
...
...
@@ -1495,6 +1496,7 @@ static PyObject* __Pyx_PyNumber_InPlaceMatrixMultiply(PyObject* x, PyObject* y);
#endif
/////////////// MatrixMultiply ///////////////
//@requires: Exceptions.c::PyErrExceptionMatches
//@requires: PyObjectGetAttrStr
//@requires: PyObjectCallOneArg
...
...
@@ -1537,7 +1539,7 @@ bad:
return result; \
Py_DECREF(result); \
} else { \
if (!
PyErr_ExceptionMatches(PyExc_AttributeError))
\
if (!
__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))
\
return NULL; \
PyErr_Clear(); \
} \
...
...
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