Skip to content

Commit bd70ebd

Browse files
committed
Replace tuple deallocation with tuple free
1 parent dbde059 commit bd70ebd

File tree

5 files changed

+17
-28
lines changed

5 files changed

+17
-28
lines changed

Include/internal/pycore_tuple.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern PyStatus _PyTuple_InitGlobalObjects(PyInterpreterState *);
2121

2222
/* other API */
2323

24-
PyAPI_FUNC(void) _PyTuple_EmptyExactDealloc(PyObject *self);
24+
PyAPI_FUNC(void) _PyTuple_Free(PyObject *self);
2525

2626
#define _PyTuple_ITEMS(op) _Py_RVALUE(_PyTuple_CAST(op)->ob_item)
2727

Include/internal/pycore_uop_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/tupleobject.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -206,27 +206,11 @@ PyTuple_Pack(Py_ssize_t n, ...)
206206
/* Methods */
207207

208208
void
209-
_PyTuple_EmptyExactDealloc(PyObject *obj)
209+
_PyTuple_Free(PyObject *obj)
210210
{
211211
assert(PyTuple_CheckExact(obj));
212212
PyTupleObject *op = _PyTuple_CAST(obj);
213-
214-
if (Py_SIZE(op) == 0 && op == &_Py_SINGLETON(tuple_empty)) {
215-
#ifdef Py_DEBUG
216-
_Py_FatalRefcountError("deallocating the empty tuple singleton");
217-
#else
218-
return;
219-
#endif
220-
}
221-
222-
PyObject_GC_UnTrack(op);
223-
224-
#ifdef Py_DEBUG
225-
Py_ssize_t i = Py_SIZE(op);
226-
while (--i >= 0) {
227-
assert(op->ob_item[i] == NULL);
228-
}
229-
#endif
213+
assert(Py_SIZE(op) != 0);
230214

231215
// This will abort on the empty singleton (if there is one).
232216
if (!maybe_freelist_push(op)) {

Python/bytecodes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "pycore_sliceobject.h" // _PyBuildSlice_ConsumeRefs
3131
#include "pycore_stackref.h"
3232
#include "pycore_template.h" // _PyTemplate_Build()
33-
#include "pycore_tuple.h" // _PyTuple_EmptyExactDealloc(), _PyTuple_ITEMS()
33+
#include "pycore_tuple.h" // _PyTuple_Free(), _PyTuple_ITEMS()
3434
#include "pycore_typeobject.h" // _PySuper_Lookup()
3535

3636
#include "pycore_dict.h"
@@ -1672,17 +1672,17 @@ dummy_func(
16721672
}
16731673

16741674
op(_UNPACK_SEQUENCE_UNIQUE_TUPLE, (seq -- values[oparg])) {
1675-
PyObject *seq_o = PyStackRef_AsPyObjectBorrow(seq);
1675+
PyObject *seq_o = PyStackRef_AsPyObjectSteal(seq);
16761676
assert(PyTuple_CheckExact(seq_o));
16771677
assert(PyTuple_GET_SIZE(seq_o) == oparg);
16781678
DEOPT_IF(!_PyObject_IsUniquelyReferenced(seq_o));
16791679
STAT_INC(UNPACK_SEQUENCE, hit);
16801680
PyObject **items = _PyTuple_ITEMS(seq_o);
16811681
for (int i = oparg; --i >= 0; ) {
16821682
*values++ = PyStackRef_FromPyObjectSteal(items[i]);
1683-
items[i] = NULL;
16841683
}
1685-
PyStackRef_CLOSE_SPECIALIZED(seq, _PyTuple_EmptyExactDealloc);
1684+
PyObject_GC_UnTrack(seq_o);
1685+
_PyTuple_Free(seq_o);
16861686
}
16871687

16881688
macro(UNPACK_SEQUENCE_LIST) =

Python/executor_cases.c.h

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)