Commit 49010ee3 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Revert changeset 1f31bf3f76f5 (issue5322) except tests.

parent 43478814
...@@ -1662,6 +1662,7 @@ order (MRO) for bases """ ...@@ -1662,6 +1662,7 @@ order (MRO) for bases """
self.assertEqual(b.foo, 3) self.assertEqual(b.foo, 3)
self.assertEqual(b.__class__, D) self.assertEqual(b.__class__, D)
@unittest.expectedFailure
def test_bad_new(self): def test_bad_new(self):
self.assertRaises(TypeError, object.__new__) self.assertRaises(TypeError, object.__new__)
self.assertRaises(TypeError, object.__new__, '') self.assertRaises(TypeError, object.__new__, '')
...@@ -1708,6 +1709,7 @@ order (MRO) for bases """ ...@@ -1708,6 +1709,7 @@ order (MRO) for bases """
object.__init__(A(3)) object.__init__(A(3))
self.assertRaises(TypeError, object.__init__, A(3), 5) self.assertRaises(TypeError, object.__init__, A(3), 5)
@unittest.expectedFailure
def test_restored_object_new(self): def test_restored_object_new(self):
class A(object): class A(object):
def __new__(cls, *args, **kwargs): def __new__(cls, *args, **kwargs):
......
...@@ -13,9 +13,6 @@ Core and Builtins ...@@ -13,9 +13,6 @@ Core and Builtins
- Issue #28512: Fixed setting the offset attribute of SyntaxError by - Issue #28512: Fixed setting the offset attribute of SyntaxError by
PyErr_SyntaxLocationEx() and PyErr_SyntaxLocationObject(). 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 - Issue #28648: Fixed crash in Py_DecodeLocale() in debug build on Mac OS X
when decode astral characters. Patch by Xiang Zhang. when decode astral characters. Patch by Xiang Zhang.
......
...@@ -6798,34 +6798,7 @@ update_one_slot(PyTypeObject *type, slotdef *p) ...@@ -6798,34 +6798,7 @@ update_one_slot(PyTypeObject *type, slotdef *p)
sanity checks and constructing a new argument sanity checks and constructing a new argument
list. Cut all that nonsense short -- this speeds list. Cut all that nonsense short -- this speeds
up instance creation tremendously. */ up instance creation tremendously. */
PyObject *self = PyCFunction_GET_SELF(descr); specific = (void *)type->tp_new;
if (!self || !PyType_Check(self)) {
/* This should never happen because
tp_new_wrapper expects a type for self.
Use slot_tp_new which will call
tp_new_wrapper which will raise an
exception. */
specific = (void *)slot_tp_new;
}
else {
PyTypeObject *staticbase;
specific = ((PyTypeObject *)self)->tp_new;
/* Check that the user does not do anything
silly and unsafe like object.__new__(dict).
To do this, we check that the most derived
base that's not a heap type is this type. */
staticbase = type->tp_base;
while (staticbase &&
(staticbase->tp_flags & Py_TPFLAGS_HEAPTYPE))
staticbase = staticbase->tp_base;
if (staticbase &&
staticbase->tp_new != specific)
/* Seems to be unsafe, better use
slot_tp_new which will call
tp_new_wrapper which will raise an
exception if it is unsafe. */
specific = (void *)slot_tp_new;
}
/* XXX I'm not 100% sure that there isn't a hole /* XXX I'm not 100% sure that there isn't a hole
in this reasoning that requires additional in this reasoning that requires additional
sanity checks. I'll buy the first person to sanity checks. I'll buy the first person to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment