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
1cb0cb2f
Commit
1cb0cb2f
authored
Feb 27, 2013
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#17296: backport fix for issue 1692335, naive exception pickling.
parent
5f794098
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
2 deletions
+28
-2
Lib/test/test_exceptions.py
Lib/test/test_exceptions.py
+15
-1
Misc/NEWS
Misc/NEWS
+3
-0
Objects/exceptions.c
Objects/exceptions.c
+10
-1
No files found.
Lib/test/test_exceptions.py
View file @
1cb0cb2f
...
...
@@ -10,6 +10,15 @@ import errno
from
test.support
import
(
TESTFN
,
captured_output
,
check_impl_detail
,
cpython_only
,
gc_collect
,
run_unittest
,
unlink
)
class
NaiveException
(
Exception
):
def
__init__
(
self
,
x
):
self
.
x
=
x
class
SlottedNaiveException
(
Exception
):
__slots__
=
(
'x'
,)
def
__init__
(
self
,
x
):
self
.
x
=
x
# XXX This is not really enough, each *operation* should be tested!
class
ExceptionTests
(
unittest
.
TestCase
):
...
...
@@ -272,6 +281,10 @@ class ExceptionTests(unittest.TestCase):
{
'args'
:
(
'
\
u3042
'
,
0
,
1
,
'ouch'
),
'object'
:
'
\
u3042
'
,
'reason'
:
'ouch'
,
'start'
:
0
,
'end'
:
1
}),
(
NaiveException
,
(
'foo'
,),
{
'args'
:
(
'foo'
,),
'x'
:
'foo'
}),
(
SlottedNaiveException
,
(
'foo'
,),
{
'args'
:
(
'foo'
,),
'x'
:
'foo'
}),
]
try
:
exceptionList
.
append
(
...
...
@@ -291,7 +304,8 @@ class ExceptionTests(unittest.TestCase):
raise
else
:
# Verify module name
self
.
assertEqual
(
type
(
e
).
__module__
,
'builtins'
)
if
not
type
(
e
).
__name__
.
endswith
(
'NaiveException'
):
self
.
assertEqual
(
type
(
e
).
__module__
,
'builtins'
)
# Verify no ref leaks in Exc_str()
s
=
str
(
e
)
for
checkArgName
in
expected
:
...
...
Misc/NEWS
View file @
1cb0cb2f
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
Core and Builtins
-----------------
- Issue #1692335: Move initial args assignment to
BaseException.__new__ to help pickling of naive subclasses.
- Issue #17275: Corrected class name in init error messages of the C version of
BufferedWriter and BufferedRandom.
...
...
Objects/exceptions.c
View file @
1cb0cb2f
...
...
@@ -29,6 +29,12 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
self
->
dict
=
NULL
;
self
->
traceback
=
self
->
cause
=
self
->
context
=
NULL
;
if
(
args
)
{
self
->
args
=
args
;
Py_INCREF
(
args
);
return
(
PyObject
*
)
self
;
}
self
->
args
=
PyTuple_New
(
0
);
if
(
!
self
->
args
)
{
Py_DECREF
(
self
);
...
...
@@ -41,12 +47,15 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static
int
BaseException_init
(
PyBaseExceptionObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
PyObject
*
tmp
;
if
(
!
_PyArg_NoKeywords
(
Py_TYPE
(
self
)
->
tp_name
,
kwds
))
return
-
1
;
Py_DECREF
(
self
->
args
)
;
tmp
=
self
->
args
;
self
->
args
=
args
;
Py_INCREF
(
self
->
args
);
Py_XDECREF
(
tmp
);
return
0
;
}
...
...
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