Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-96046: Initialize ht_cached_keys in PyType_Ready() #96047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 22, 2022
Prev Previous commit
Next Next commit
Fix format, use memory error.
  • Loading branch information
tiran committed Aug 18, 2022
commit cfbd154fc47f741ecc6089cbad3770cce6e7ba86
12 changes: 5 additions & 7 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3505,21 +3505,21 @@ type_check_basicsize_includes_size_and_offsets(PyTypeObject* type)
}
if (type->tp_weaklistoffset + (Py_ssize_t)sizeof(PyObject*) > max) {
PyErr_Format(PyExc_TypeError,
"weaklist offset %d is out of bounds for type '%s' (tp_basicsize = %d)",
"weaklist offset %zd is out of bounds for type '%s' (tp_basicsize = %zd)",
type->tp_weaklistoffset,
type->tp_name, type->tp_basicsize);
return -1;
}
if (type->tp_dictoffset + (Py_ssize_t)sizeof(PyObject*) > max) {
PyErr_Format(PyExc_TypeError,
"dict offset %d is out of bounds for type '%s' (tp_basicsize = %d)",
"dict offset %zd is out of bounds for type '%s' (tp_basicsize = %zd)",
type->tp_dictoffset,
type->tp_name, type->tp_basicsize);
return -1;
}
if (type->tp_vectorcall_offset + (Py_ssize_t)sizeof(vectorcallfunc*) > max) {
PyErr_Format(PyExc_TypeError,
"vectorcall offset %d is out of bounds for type '%s' (tp_basicsize = %d)",
"vectorcall offset %zd is out of bounds for type '%s' (tp_basicsize = %zd)",
type->tp_vectorcall_offset,
type->tp_name, type->tp_basicsize);
return -1;
Expand Down Expand Up @@ -6768,17 +6768,15 @@ type_ready_managed_dict(PyTypeObject *type)
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.",
"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_Format(PyExc_SystemError,
"failed to initialize ht_cached_keys of type %s.",
type->tp_name);
PyErr_NoMemory();
return -1;
}
}
Expand Down