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
Gwenaël Samain
cython
Commits
60eb977a
Commit
60eb977a
authored
Nov 23, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix 'raise type, instance' in Py3 by preventing it from trying to re-instantiate the instance
parent
7e59e591
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
22 deletions
+39
-22
Cython/Utility/Exceptions.c
Cython/Utility/Exceptions.c
+39
-22
No files found.
Cython/Utility/Exceptions.c
View file @
60eb977a
...
...
@@ -155,28 +155,45 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject
value
=
type
;
type
=
(
PyObject
*
)
Py_TYPE
(
value
);
}
else
if
(
PyExceptionClass_Check
(
type
))
{
// instantiate the type now (we don't know when and how it will be caught)
PyObject
*
args
;
if
(
!
value
)
args
=
PyTuple_New
(
0
);
else
if
(
PyTuple_Check
(
value
))
{
Py_INCREF
(
value
);
args
=
value
;
}
else
args
=
PyTuple_Pack
(
1
,
value
);
if
(
!
args
)
goto
bad
;
owned_instance
=
PyEval_CallObject
(
type
,
args
);
Py_DECREF
(
args
);
if
(
!
owned_instance
)
goto
bad
;
value
=
owned_instance
;
if
(
!
PyExceptionInstance_Check
(
value
))
{
PyErr_Format
(
PyExc_TypeError
,
"calling %R should have returned an instance of "
"BaseException, not %R"
,
type
,
Py_TYPE
(
value
));
goto
bad
;
// make sure value is an exception instance of type
PyObject
*
instance_class
=
NULL
;
if
(
value
&&
PyExceptionInstance_Check
(
value
))
{
instance_class
=
(
PyObject
*
)
Py_TYPE
(
value
);
if
(
instance_class
!=
type
)
{
if
(
PyObject_IsSubclass
(
instance_class
,
type
))
{
// believe the instance
type
=
instance_class
;
}
else
{
instance_class
=
NULL
;
}
}
}
if
(
!
instance_class
)
{
// instantiate the type now (we don't know when and how it will be caught)
// assuming that 'value' is an argument to the type's constructor
// not using PyErr_NormalizeException() to avoid ref-counting problems
PyObject
*
args
;
if
(
!
value
)
args
=
PyTuple_New
(
0
);
else
if
(
PyTuple_Check
(
value
))
{
Py_INCREF
(
value
);
args
=
value
;
}
else
args
=
PyTuple_Pack
(
1
,
value
);
if
(
!
args
)
goto
bad
;
owned_instance
=
PyObject_Call
(
type
,
args
,
NULL
);
Py_DECREF
(
args
);
if
(
!
owned_instance
)
goto
bad
;
value
=
owned_instance
;
if
(
!
PyExceptionInstance_Check
(
value
))
{
PyErr_Format
(
PyExc_TypeError
,
"calling %R should have returned an instance of "
"BaseException, not %R"
,
type
,
Py_TYPE
(
value
));
goto
bad
;
}
}
}
else
{
PyErr_SetString
(
PyExc_TypeError
,
...
...
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