return NULL;
}
+/* This allocator is needed for subclasses don't want to use __new__.
+ * See https://github.com/python/cpython/issues/91020#issuecomment-1096793239
+ *
+ * This allocator will be removed when ob_shash is removed.
+ */
+static PyObject *
+bytes_alloc(PyTypeObject *self, Py_ssize_t nitems)
+{
+ PyBytesObject *obj = (PyBytesObject*)PyType_GenericAlloc(self, nitems);
+ if (obj == NULL) {
+ return NULL;
+ }
+_Py_COMP_DIAG_PUSH
+_Py_COMP_DIAG_IGNORE_DEPR_DECLS
+ obj->ob_shash = -1;
+_Py_COMP_DIAG_POP
+ return (PyObject*)obj;
+}
+
static PyObject *
bytes_subtype_new(PyTypeObject *type, PyObject *tmp)
{
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
- 0, /* tp_alloc */
+ bytes_alloc, /* tp_alloc */
bytes_new, /* tp_new */
PyObject_Del, /* tp_free */
};