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
05f97bff
Commit
05f97bff
authored
May 30, 2006
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a test case for exception pickling. args is never NULL.
parent
ddba473e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
11 deletions
+21
-11
Lib/test/test_exceptions.py
Lib/test/test_exceptions.py
+13
-0
Objects/exceptions.c
Objects/exceptions.c
+8
-11
No files found.
Lib/test/test_exceptions.py
View file @
05f97bff
...
...
@@ -270,6 +270,8 @@ try:
'winerror'
:
1
}))
except
NameError
:
pass
import
pickle
,
random
for
args
in
exceptionList
:
expected
=
args
[
-
1
]
try
:
...
...
@@ -283,3 +285,14 @@ for args in exceptionList:
(
repr
(
e
),
checkArgName
,
repr
(
expected
[
checkArgName
]),
repr
(
getattr
(
e
,
checkArgName
))
))
# test for pickling support
new
=
pickle
.
loads
(
pickle
.
dumps
(
e
,
random
.
randint
(
0
,
2
)))
for
checkArgName
in
expected
.
keys
():
if
repr
(
getattr
(
e
,
checkArgName
))
!=
repr
(
expected
[
checkArgName
]):
raise
TestFailed
(
'Checking unpickled exception arguments, '
'exception '
'"%s", attribute "%s" expected %s got %s.'
%
(
repr
(
e
),
checkArgName
,
repr
(
expected
[
checkArgName
]),
repr
(
getattr
(
e
,
checkArgName
))
))
Objects/exceptions.c
View file @
05f97bff
...
...
@@ -143,15 +143,8 @@ BaseException_reduce(PyBaseExceptionObject *self)
{
if
(
self
->
args
&&
self
->
dict
)
return
PyTuple_Pack
(
3
,
self
->
ob_type
,
self
->
args
,
self
->
dict
);
else
if
(
self
->
args
)
else
return
PyTuple_Pack
(
2
,
self
->
ob_type
,
self
->
args
);
else
{
PyObject
*
res
,
*
tup
=
PyTuple_New
(
0
);
if
(
!
tup
)
return
NULL
;
res
=
PyTuple_Pack
(
2
,
self
->
ob_type
,
tup
);
Py_DECREF
(
tup
);
return
res
;
}
}
...
...
@@ -667,6 +660,7 @@ EnvironmentError_reduce(PyEnvironmentErrorObject *self)
{
PyObject
*
args
=
self
->
args
;
PyObject
*
res
=
NULL
,
*
tmp
;
/* self->args is only the first two real arguments if there was a
* file name given to EnvironmentError. */
if
(
PyTuple_GET_SIZE
(
args
)
==
2
&&
self
->
filename
)
{
...
...
@@ -683,10 +677,13 @@ EnvironmentError_reduce(PyEnvironmentErrorObject *self)
Py_INCREF
(
self
->
filename
);
PyTuple_SET_ITEM
(
args
,
2
,
self
->
filename
);
}
else
{
}
else
Py_INCREF
(
args
);
}
res
=
PyTuple_Pack
(
3
,
self
->
ob_type
,
args
,
self
->
dict
);
if
(
self
->
dict
)
res
=
PyTuple_Pack
(
3
,
self
->
ob_type
,
args
,
self
->
dict
);
else
res
=
PyTuple_Pack
(
2
,
self
->
ob_type
,
args
);
Py_DECREF
(
args
);
return
res
;
}
...
...
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