Commit 97d6f419 authored by Antoine Pitrou's avatar Antoine Pitrou

Use struct member (ht_type) instead of casting pointers.

parent 292d9fa0
...@@ -2395,13 +2395,14 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) ...@@ -2395,13 +2395,14 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
if (res == NULL) if (res == NULL)
return NULL; return NULL;
type = &res->ht_type;
res->ht_name = PyUnicode_FromString(s); res->ht_name = PyUnicode_FromString(s);
if (!res->ht_name) if (!res->ht_name)
goto fail; goto fail;
res->ht_qualname = res->ht_name; res->ht_qualname = res->ht_name;
Py_INCREF(res->ht_qualname); Py_INCREF(res->ht_qualname);
res->ht_type.tp_name = spec->name; type->tp_name = spec->name;
if (!res->ht_type.tp_name) if (!type->tp_name)
goto fail; goto fail;
/* Adjust for empty tuple bases */ /* Adjust for empty tuple bases */
...@@ -2436,7 +2437,6 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) ...@@ -2436,7 +2437,6 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
goto fail; goto fail;
} }
type = (PyTypeObject *)res;
/* Initialize essential fields */ /* Initialize essential fields */
type->tp_as_number = &res->as_number; type->tp_as_number = &res->as_number;
type->tp_as_sequence = &res->as_sequence; type->tp_as_sequence = &res->as_sequence;
...@@ -2448,9 +2448,9 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) ...@@ -2448,9 +2448,9 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
Py_INCREF(base); Py_INCREF(base);
type->tp_base = base; type->tp_base = base;
res->ht_type.tp_basicsize = spec->basicsize; type->tp_basicsize = spec->basicsize;
res->ht_type.tp_itemsize = spec->itemsize; type->tp_itemsize = spec->itemsize;
res->ht_type.tp_flags = spec->flags | Py_TPFLAGS_HEAPTYPE; type->tp_flags = spec->flags | Py_TPFLAGS_HEAPTYPE;
for (slot = spec->slots; slot->slot; slot++) { for (slot = spec->slots; slot->slot; slot++) {
if (slot->slot >= Py_ARRAY_LENGTH(slotoffsets)) { if (slot->slot >= Py_ARRAY_LENGTH(slotoffsets)) {
...@@ -2470,20 +2470,20 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) ...@@ -2470,20 +2470,20 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
if (tp_doc == NULL) if (tp_doc == NULL)
goto fail; goto fail;
memcpy(tp_doc, slot->pfunc, len); memcpy(tp_doc, slot->pfunc, len);
res->ht_type.tp_doc = tp_doc; type->tp_doc = tp_doc;
} }
} }
if (res->ht_type.tp_dictoffset) { if (type->tp_dictoffset) {
res->ht_cached_keys = _PyDict_NewKeysForClass(); res->ht_cached_keys = _PyDict_NewKeysForClass();
} }
if (res->ht_type.tp_dealloc == NULL) { if (type->tp_dealloc == NULL) {
/* It's a heap type, so needs the heap types' dealloc. /* It's a heap type, so needs the heap types' dealloc.
subtype_dealloc will call the base type's tp_dealloc, if subtype_dealloc will call the base type's tp_dealloc, if
necessary. */ necessary. */
res->ht_type.tp_dealloc = subtype_dealloc; type->tp_dealloc = subtype_dealloc;
} }
if (PyType_Ready(&res->ht_type) < 0) if (PyType_Ready(type) < 0)
goto fail; goto fail;
/* Set type.__module__ */ /* Set type.__module__ */
......
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