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

Skip to content

Commit 4b8c0f6

Browse files
committed
More stuff discovered while writing the simplest of testcases:
tupledealloc(): only feed the free list when the type is really a tuple, not a subtype. Otherwise, use PyObject_GC_Del(). _PyTuple_Resize(): disallow using this for tuple subtypes.
1 parent 46add98 commit 4b8c0f6

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Objects/tupleobject.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ tupledealloc(register PyTupleObject *op)
146146
while (--i >= 0)
147147
Py_XDECREF(op->ob_item[i]);
148148
#if MAXSAVESIZE > 0
149-
if (len < MAXSAVESIZE && num_free_tuples[len] < MAXSAVEDTUPLES) {
149+
if (len < MAXSAVESIZE &&
150+
num_free_tuples[len] < MAXSAVEDTUPLES &&
151+
op->ob_type == &PyTuple_Type)
152+
{
150153
op->ob_item[0] = (PyObject *) free_tuples[len];
151154
num_free_tuples[len]++;
152155
free_tuples[len] = op;
@@ -594,7 +597,7 @@ _PyTuple_Resize(PyObject **pv, int newsize)
594597
int sizediff;
595598

596599
v = (PyTupleObject *) *pv;
597-
if (v == NULL || !PyTuple_Check(v) ||
600+
if (v == NULL || v->ob_type != &PyTuple_Type ||
598601
(v->ob_size != 0 && v->ob_refcnt != 1)) {
599602
*pv = 0;
600603
Py_XDECREF(v);

0 commit comments

Comments
 (0)