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
1966f1c9
Commit
1966f1c9
authored
Sep 01, 2007
by
Collin Winter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix refleaks exposed by test_raise.
parent
1963ad31
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
3 deletions
+31
-3
Lib/test/test_raise.py
Lib/test/test_raise.py
+24
-0
Objects/exceptions.c
Objects/exceptions.c
+5
-1
Python/ceval.c
Python/ceval.c
+2
-2
No files found.
Lib/test/test_raise.py
View file @
1966f1c9
...
...
@@ -37,6 +37,18 @@ class TestRaise(unittest.TestCase):
else
:
self
.
fail
(
"No exception raised"
)
def
test_erroneous_exception
(
self
):
class
MyException
(
Exception
):
def
__init__
(
self
):
raise
RuntimeError
()
try
:
raise
MyException
except
RuntimeError
:
pass
else
:
self
.
fail
(
"No exception raised"
)
class
TestCause
(
unittest
.
TestCase
):
def
test_invalid_cause
(
self
):
...
...
@@ -64,6 +76,18 @@ class TestCause(unittest.TestCase):
else
:
self
.
fail
(
"No exception raised"
)
def
test_erroneous_cause
(
self
):
class
MyException
(
Exception
):
def
__init__
(
self
):
raise
RuntimeError
()
try
:
raise
IndexError
from
MyException
except
RuntimeError
:
pass
else
:
self
.
fail
(
"No exception raised"
)
class
TestTraceback
(
unittest
.
TestCase
):
def
test_sets_traceback
(
self
):
...
...
Objects/exceptions.c
View file @
1966f1c9
...
...
@@ -28,7 +28,7 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
NULL
;
/* the dict is created on the fly in PyObject_GenericSetAttr */
self
->
dict
=
NULL
;
self
->
traceback
=
NULL
;
self
->
traceback
=
self
->
cause
=
self
->
context
=
NULL
;
self
->
args
=
PyTuple_New
(
0
);
if
(
!
self
->
args
)
{
...
...
@@ -58,6 +58,8 @@ BaseException_clear(PyBaseExceptionObject *self)
Py_CLEAR
(
self
->
dict
);
Py_CLEAR
(
self
->
args
);
Py_CLEAR
(
self
->
traceback
);
Py_CLEAR
(
self
->
cause
);
Py_CLEAR
(
self
->
context
);
return
0
;
}
...
...
@@ -75,6 +77,8 @@ BaseException_traverse(PyBaseExceptionObject *self, visitproc visit, void *arg)
Py_VISIT
(
self
->
dict
);
Py_VISIT
(
self
->
args
);
Py_VISIT
(
self
->
traceback
);
Py_VISIT
(
self
->
cause
);
Py_VISIT
(
self
->
context
);
return
0
;
}
...
...
Python/ceval.c
View file @
1966f1c9
...
...
@@ -2967,7 +2967,6 @@ do_raise(PyObject *exc, PyObject *cause)
/* Not something you can raise. You get an exception
anyway, just not what you specified :-) */
Py_DECREF
(
exc
);
Py_XDECREF
(
cause
);
PyErr_SetString
(
PyExc_TypeError
,
"exceptions must derive from BaseException"
);
goto
raise_error
;
...
...
@@ -2980,12 +2979,12 @@ do_raise(PyObject *exc, PyObject *cause)
fixed_cause
=
PyObject_CallObject
(
cause
,
NULL
);
if
(
fixed_cause
==
NULL
)
goto
raise_error
;
Py_DECREF
(
cause
);
}
else
if
(
PyExceptionInstance_Check
(
cause
))
{
fixed_cause
=
cause
;
}
else
{
Py_DECREF
(
cause
);
PyErr_SetString
(
PyExc_TypeError
,
"exception causes must derive from BaseException"
);
goto
raise_error
;
...
...
@@ -3000,6 +2999,7 @@ raise_error:
Py_XDECREF
(
value
);
Py_XDECREF
(
type
);
Py_XDECREF
(
tb
);
Py_XDECREF
(
cause
);
return
WHY_EXCEPTION
;
}
...
...
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