From: Neal Norwitz Date: Sun, 8 Jun 2003 13:19:58 +0000 (+0000) Subject: Fix SF #749831, copy raises SystemError when getstate raises exception X-Git-Tag: v2.3c1~519 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e2fdc610043a29a4e95287ff53b1a2c43e401b11;p=python Fix SF #749831, copy raises SystemError when getstate raises exception --- diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index 0e39e8356d..c734a9a9d4 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -515,6 +515,12 @@ class TestCopy(unittest.TestCase): self.assert_(x is not y) self.assert_(x[0] is not y[0]) + def test_getstate_exc(self): + class EvilState(object): + def __getstate__(self): + raise ValueError, "ain't got no stickin' state" + self.assertRaises(ValueError, copy.copy, EvilState()) + def test_main(): test_support.run_unittest(TestCopy) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 93f34ed1f9..3e1569763f 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2536,6 +2536,8 @@ reduce_2(PyObject *obj) if (getstate != NULL) { state = PyObject_CallObject(getstate, NULL); Py_DECREF(getstate); + if (state == NULL) + goto end; } else { state = PyObject_GetAttrString(obj, "__dict__");