Skip to content

Commit 97526e5

Browse files
Address review and fix tests
1 parent 98bca4a commit 97526e5

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

Python/marshal.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,7 @@ r_object(RFILE *p)
11801180
int type, code = r_byte(p);
11811181
int flag, is_interned = 0;
11821182
PyObject *retval = NULL;
1183+
bool track_tuple = false;
11831184

11841185
if (code == EOF) {
11851186
if (PyErr_ExceptionMatches(PyExc_EOFError)) {
@@ -1422,18 +1423,29 @@ r_object(RFILE *p)
14221423
if (v == NULL)
14231424
break;
14241425

1426+
// empty tuples are untracked, and we can check if n > 0,
1427+
// but using PyObject_GC_UnTrack is clearer
1428+
PyObject_GC_UnTrack(v);
1429+
track_tuple = false;
1430+
14251431
for (i = 0; i < n; i++) {
14261432
v2 = r_object(p);
14271433
if ( v2 == NULL ) {
14281434
if (!PyErr_Occurred())
14291435
PyErr_SetString(PyExc_TypeError,
14301436
"NULL object in marshal data for tuple");
14311437
Py_SETREF(v, NULL);
1438+
track_tuple = false;
14321439
break;
14331440
}
14341441
PyTuple_SET_ITEM(v, i, v2);
1442+
if (!track_tuple && PyObject_GC_IsTracked(v2)) {
1443+
track_tuple = true;
1444+
}
1445+
}
1446+
if (track_tuple) {
1447+
_PyObject_GC_TRACK(v);
14351448
}
1436-
_PyTuple_MaybeUntrack(v);
14371449
retval = v;
14381450
break;
14391451

0 commit comments

Comments
 (0)