// Put the proper slots in place
fixup_slot_dispatchers(type);
- if (type->tp_flags & Py_TPFLAGS_MANAGED_DICT) {
- PyHeapTypeObject *et = (PyHeapTypeObject*)type;
- et->ht_cached_keys = _PyDict_NewKeysForClass();
- }
-
if (type_new_set_names(type) < 0) {
goto error;
}
goto finally;
}
- if (type->tp_flags & Py_TPFLAGS_MANAGED_DICT) {
- res->ht_cached_keys = _PyDict_NewKeysForClass();
- }
-
if (type->tp_doc) {
PyObject *__doc__ = PyUnicode_FromString(_PyType_DocWithoutSignature(type->tp_name, type->tp_doc));
if (!__doc__) {
return 0;
}
+static int
+type_ready_managed_dict(PyTypeObject *type)
+{
+ if (!(type->tp_flags & Py_TPFLAGS_MANAGED_DICT)) {
+ return 0;
+ }
+ if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
+ PyErr_Format(PyExc_SystemError,
+ "type %s has the Py_TPFLAGS_MANAGED_DICT flag "
+ "but not Py_TPFLAGS_HEAPTYPE flag",
+ type->tp_name);
+ return -1;
+ }
+ PyHeapTypeObject* et = (PyHeapTypeObject*)type;
+ if (et->ht_cached_keys == NULL) {
+ et->ht_cached_keys = _PyDict_NewKeysForClass();
+ if (et->ht_cached_keys == NULL) {
+ PyErr_NoMemory();
+ return -1;
+ }
+ }
+ return 0;
+}
static int
type_ready_post_checks(PyTypeObject *type)
if (type_ready_add_subclasses(type) < 0) {
return -1;
}
+ if (type_ready_managed_dict(type) < 0) {
+ return -1;
+ }
if (type_ready_post_checks(type) < 0) {
return -1;
}