cpython: 06e4b9f2e4b0 (original) (raw)
Mercurial > cpython
changeset 105621:06e4b9f2e4b0 3.5
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Wed, 14 Dec 2016 19:52:17 +0200 |
parents | c3da1ee47e6b |
children | 0ce789eae627 a89469328b78 |
files | Lib/test/test_descr.py Misc/NEWS Objects/typeobject.c |
diffstat | 3 files changed, 3 insertions(+), 31 deletions(-)[+] [-] Lib/test/test_descr.py 2 Misc/NEWS 3 Objects/typeobject.c 29 |
line wrap: on
line diff
--- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -1662,6 +1662,7 @@ order (MRO) for bases """ self.assertEqual(b.foo, 3) self.assertEqual(b.class, D)
- @unittest.expectedFailure def test_bad_new(self): self.assertRaises(TypeError, object.new) self.assertRaises(TypeError, object.new, '')
@@ -1708,6 +1709,7 @@ order (MRO) for bases """ object.init(A(3)) self.assertRaises(TypeError, object.init, A(3), 5)
- @unittest.expectedFailure def test_restored_object_new(self): class A(object): def new(cls, *args, **kwargs):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,9 +13,6 @@ Core and Builtins
- Issue #28512: Fixed setting the offset attribute of SyntaxError by PyErr_SyntaxLocationEx() and PyErr_SyntaxLocationObject(). -- Issue #5322: Fixed setting new to a PyCFunction inside Python code.
- Original patch by Andreas Stührk. -
- Issue #28648: Fixed crash in Py_DecodeLocale() in debug build on Mac OS X when decode astral characters. Patch by Xiang Zhang.
--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -6798,34 +6798,7 @@ update_one_slot(PyTypeObject *type, slot sanity checks and constructing a new argument list. Cut all that nonsense short -- this speeds up instance creation tremendously. */
PyObject *self = PyCFunction_GET_SELF(descr);[](#l3.7)
if (!self || !PyType_Check(self)) {[](#l3.8)
/* This should never happen because[](#l3.9)
tp_new_wrapper expects a type for self.[](#l3.10)
Use slot_tp_new which will call[](#l3.11)
tp_new_wrapper which will raise an[](#l3.12)
exception. */[](#l3.13)
specific = (void *)slot_tp_new;[](#l3.14)
}[](#l3.15)
else {[](#l3.16)
PyTypeObject *staticbase;[](#l3.17)
specific = ((PyTypeObject *)self)->tp_new;[](#l3.18)
/* Check that the user does not do anything[](#l3.19)
silly and unsafe like object.__new__(dict).[](#l3.20)
To do this, we check that the most derived[](#l3.21)
base that's not a heap type is this type. */[](#l3.22)
staticbase = type->tp_base;[](#l3.23)
while (staticbase &&[](#l3.24)
(staticbase->tp_flags & Py_TPFLAGS_HEAPTYPE))[](#l3.25)
staticbase = staticbase->tp_base;[](#l3.26)
if (staticbase &&[](#l3.27)
staticbase->tp_new != specific)[](#l3.28)
/* Seems to be unsafe, better use[](#l3.29)
slot_tp_new which will call[](#l3.30)
tp_new_wrapper which will raise an[](#l3.31)
exception if it is unsafe. */[](#l3.32)
specific = (void *)slot_tp_new;[](#l3.33)
}[](#l3.34)
specific = (void *)type->tp_new;[](#l3.35) /* XXX I'm not 100% sure that there isn't a hole[](#l3.36) in this reasoning that requires additional[](#l3.37) sanity checks. I'll buy the first person to[](#l3.38)