mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #15229: An OSError subclass whose __init__ doesn't call back
OSError.__init__ could produce incomplete instances, leading to crashes when calling str() on them.
This commit is contained in:
parent
4c99071c9b
commit
f87289bb58
3 changed files with 19 additions and 0 deletions
|
@ -29,6 +29,10 @@ class SubOSErrorCombinedInitFirst(SubOSErrorWithInit, SubOSErrorWithNew):
|
||||||
class SubOSErrorCombinedNewFirst(SubOSErrorWithNew, SubOSErrorWithInit):
|
class SubOSErrorCombinedNewFirst(SubOSErrorWithNew, SubOSErrorWithInit):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class SubOSErrorWithStandaloneInit(OSError):
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class HierarchyTest(unittest.TestCase):
|
class HierarchyTest(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -193,6 +197,12 @@ class ExplicitSubclassingTest(unittest.TestCase):
|
||||||
self.assertEqual(e.baz, "baz")
|
self.assertEqual(e.baz, "baz")
|
||||||
self.assertEqual(e.args, ("some message",))
|
self.assertEqual(e.args, ("some message",))
|
||||||
|
|
||||||
|
def test_init_standalone(self):
|
||||||
|
# __init__ doesn't propagate to OSError.__init__ (see issue #15229)
|
||||||
|
e = SubOSErrorWithStandaloneInit()
|
||||||
|
self.assertEqual(e.args, ())
|
||||||
|
self.assertEqual(str(e), '')
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
support.run_unittest(__name__)
|
support.run_unittest(__name__)
|
||||||
|
|
|
@ -10,6 +10,9 @@ What's New in Python 3.3.0 Beta 2?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #15229: An OSError subclass whose __init__ doesn't call back
|
||||||
|
OSError.__init__ could produce incomplete instances, leading to crashes
|
||||||
|
when calling str() on them.
|
||||||
|
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
|
@ -834,6 +834,7 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Steals the reference to args */
|
/* Steals the reference to args */
|
||||||
|
Py_CLEAR(self->args);
|
||||||
self->args = args;
|
self->args = args;
|
||||||
args = NULL;
|
args = NULL;
|
||||||
|
|
||||||
|
@ -916,6 +917,11 @@ OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
))
|
))
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
self->args = PyTuple_New(0);
|
||||||
|
if (self->args == NULL)
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
return (PyObject *) self;
|
return (PyObject *) self;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue