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
51b23c9d
Commit
51b23c9d
authored
Jul 31, 2008
by
Amaury Forgeot d'Arc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correct one of the "MemoryError oddities":
the traceback would grow each time a MemoryError is raised.
parent
a308b1d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
Lib/test/test_exceptions.py
Lib/test/test_exceptions.py
+18
-0
Python/errors.c
Python/errors.c
+10
-0
No files found.
Lib/test/test_exceptions.py
View file @
51b23c9d
...
...
@@ -596,6 +596,24 @@ class ExceptionTests(unittest.TestCase):
"Exception ValueError: ValueError() "
"in <class 'KeyError'> ignored
\
n
"
)
def
test_MemoryError
(
self
):
# PyErr_NoMemory always raises the same exception instance.
# Check that the traceback is not doubled.
import
traceback
def
raiseMemError
():
try
:
"a"
*
(
sys
.
maxsize
//
2
)
except
MemoryError
as
e
:
tb
=
e
.
__traceback__
else
:
self
.
fail
(
"Should have raises a MemoryError"
)
return
traceback
.
format_tb
(
tb
)
tb1
=
raiseMemError
()
tb2
=
raiseMemError
()
self
.
assertEqual
(
tb1
,
tb2
)
def
test_main
():
run_unittest
(
ExceptionTests
)
...
...
Python/errors.c
View file @
51b23c9d
...
...
@@ -321,7 +321,17 @@ PyErr_NoMemory(void)
/* raise the pre-allocated instance if it still exists */
if
(
PyExc_MemoryErrorInst
)
{
/* Clear the previous traceback, otherwise it will be appended
* to the current one.
*
* The following statement is not likely to raise any error;
* if it does, we simply discard it.
*/
PyException_SetTraceback
(
PyExc_MemoryErrorInst
,
Py_None
);
PyErr_SetObject
(
PyExc_MemoryError
,
PyExc_MemoryErrorInst
);
}
else
/* this will probably fail since there's no memory and hee,
hee, we have to instantiate this class
...
...
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