changeset: 83296:5358ee70f831 parent: 83294:185ae0c95e5b parent: 83295:52bd2035e70a user: Mark Dickinson date: Sat Apr 13 17:46:04 2013 +0100 files: Lib/test/test_int.py Misc/NEWS Objects/abstract.c description: Issue #17715: Merge fix from 3.3. diff -r 185ae0c95e5b -r 5358ee70f831 Lib/test/test_int.py --- a/Lib/test/test_int.py Sat Apr 13 17:35:14 2013 +0100 +++ b/Lib/test/test_int.py Sat Apr 13 17:46:04 2013 +0100 @@ -354,6 +354,12 @@ return 42 self.assertEqual(int(JustTrunc()), 42) + class ExceptionalTrunc(base): + def __trunc__(self): + 1 / 0 + with self.assertRaises(ZeroDivisionError): + int(ExceptionalTrunc()) + for trunc_result_base in (object, Classic): class Integral(trunc_result_base): def __int__(self): diff -r 185ae0c95e5b -r 5358ee70f831 Misc/NEWS --- a/Misc/NEWS Sat Apr 13 17:35:14 2013 +0100 +++ b/Misc/NEWS Sat Apr 13 17:46:04 2013 +0100 @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #17715: Fix segmentation fault from raising an exception in a __trunc__ + method. + - Issue #17643: Add __callback__ attribute to weakref.ref. - Issue #16447: Fixed potential segmentation fault when setting __name__ on a diff -r 185ae0c95e5b -r 5358ee70f831 Objects/abstract.c --- a/Objects/abstract.c Sat Apr 13 17:35:14 2013 +0100 +++ b/Objects/abstract.c Sat Apr 13 17:46:04 2013 +0100 @@ -1314,6 +1314,8 @@ PyObject *truncated = PyEval_CallObject(trunc_func, NULL); PyObject *int_instance; Py_DECREF(trunc_func); + if (truncated == NULL) + return NULL; /* __trunc__ is specified to return an Integral type, but int() needs to return a int. */ int_instance = convert_integral_to_int(truncated,