Commit fbb9c678 authored by Marius Wachtler's avatar Marius Wachtler

Don't overwrite empty tp_new when type is inheriting from object

The capi uses this to deny instancing a type directly.
parent 25847f9e
......@@ -3427,6 +3427,9 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
// RELEASE_ASSERT(cls->tp_traverse == NULL, "");
// RELEASE_ASSERT(cls->tp_clear == NULL, "");
// set this flag early because some function check if it is set pretty early
cls->is_user_defined = true;
assert(cls->attrs.hcls == NULL);
new (&cls->attrs) HCAttrs(HiddenClass::makeSingleton());
#define INITIALIZE(a) new (&(a)) decltype(a)
......@@ -3510,7 +3513,6 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
cls->gc_visit = &conservativeAndBasesGCHandler;
else
cls->gc_visit = &conservativeGCHandler;
cls->is_user_defined = true;
if (!cls->instancesHaveHCAttrs() && cls->tp_base) {
......
......@@ -44,6 +44,14 @@ print slots_test.SlotsTesterNum(0) == slots_test.SlotsTesterNum(1)
for i in slots_test.SlotsTesterSeq(6):
print i
try:
# seqiter.tp_new is NULL so we should not be allowed to create an instance
slot_tester_seqiter = type(iter(slots_test.SlotsTesterSeq(6)))
print slot_tester_seqiter
slot_tester_seqiter()
except Exception as e:
print e
su = slots_test.SlotsTesterSub(5)
print su
......
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