Skip to content

Commit a2aba9e

Browse files
committed
Fix tuple.tp_new for managed subclasses
1 parent 287ac2b commit a2aba9e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

graalpython/com.oracle.graal.python.cext/src/tupleobject.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ PyObject* PyTuple_Pack(Py_ssize_t n, ...) {
6161
return result;
6262
}
6363

64+
PyObject* PyTruffle_Tuple_Alloc(PyTypeObject* cls, Py_ssize_t nitems);
65+
6466
POLYGLOT_DECLARE_TYPE(PyTupleObject);
6567
PyObject * tuple_subtype_new(PyTypeObject *type, PyObject *iterable) {
6668
PyTupleObject* newobj;
@@ -75,7 +77,10 @@ PyObject * tuple_subtype_new(PyTypeObject *type, PyObject *iterable) {
7577
assert(PyTuple_Check(tmp));
7678
n = PyTuple_GET_SIZE(tmp);
7779

78-
newobj = (PyTupleObject*) type->tp_alloc(type, n);
80+
/* GraalPy note: we cannot call type->tp_alloc here because managed subtypes don't inherit tp_alloc but get a generic one.
81+
* In CPython tuple uses the generic one to begin with, so they don't have this problem
82+
*/
83+
newobj = (PyTupleObject*) PyTruffle_Tuple_Alloc(type, n);
7984
if (newobj == NULL) {
8085
return NULL;
8186
}

0 commit comments

Comments
 (0)