summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bytesobject.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index d0124c0..510a836 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -2861,6 +2861,25 @@ PyBytes_FromObject(PyObject *x)
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)
{
@@ -2937,7 +2956,7 @@ PyTypeObject PyBytes_Type = {
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 */
};