Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
303de6a2
Commit
303de6a2
authored
Apr 20, 2006
by
Thomas Wouters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix (and add test for) missing check for BaseException subclasses in the C
API.
parent
4f564bd6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
Lib/test/test_exceptions.py
Lib/test/test_exceptions.py
+19
-1
Python/errors.c
Python/errors.c
+9
-0
No files found.
Lib/test/test_exceptions.py
View file @
303de6a2
...
...
@@ -171,10 +171,15 @@ except Exception, e: pass
# test that setting an exception at the C level works even if the
# exception object can't be constructed.
class
BadException
:
class
BadException
(
Exception
)
:
def
__init__
(
self
):
raise
RuntimeError
,
"can't instantiate BadException"
# Exceptions must inherit from BaseException, raising invalid exception
# should instead raise SystemError
class
InvalidException
:
pass
def
test_capi1
():
import
_testcapi
try
:
...
...
@@ -201,8 +206,21 @@ def test_capi2():
else
:
print
"Expected exception"
def
test_capi3
():
import
_testcapi
try
:
_testcapi
.
raise_exception
(
InvalidException
,
1
)
except
SystemError
:
pass
except
InvalidException
:
raise
AssertionError
(
"Managed to raise InvalidException"
);
else
:
print
"Expected SystemError exception"
if
not
sys
.
platform
.
startswith
(
'java'
):
test_capi1
()
test_capi2
()
test_capi3
()
unlink
(
TESTFN
)
Python/errors.c
View file @
303de6a2
...
...
@@ -47,6 +47,15 @@ PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)
void
PyErr_SetObject
(
PyObject
*
exception
,
PyObject
*
value
)
{
if
(
exception
!=
NULL
&&
!
PyExceptionClass_Check
(
exception
))
{
PyObject
*
excstr
=
PyObject_Repr
(
exception
);
PyErr_Format
(
PyExc_SystemError
,
"exception %s not a BaseException subclass"
,
PyString_AS_STRING
(
excstr
));
Py_DECREF
(
excstr
);
return
;
}
Py_XINCREF
(
exception
);
Py_XINCREF
(
value
);
PyErr_Restore
(
exception
,
value
,
(
PyObject
*
)
NULL
);
...
...
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