Skip to content

Commit 0aadfe1

Browse files
Review addressed 2
1 parent 7348111 commit 0aadfe1

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

Lib/test/test_builtin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,7 @@ def test_map_strict(self):
13851385
self.assertRaises(ValueError, tuple,
13861386
map(pack, (1, 2), (1, 2), 'abc', strict=True))
13871387

1388+
# gh-140517: Testing refleaks with mortal objects.
13881389
t1 = (None, object())
13891390
t2 = (object(), object())
13901391
t3 = (object(),)

Python/bltinmodule.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,14 +1501,14 @@ map_next(PyObject *self)
15011501
}
15021502

15031503
Py_ssize_t nargs = 0;
1504-
for (i=0; i < niters; i++) {
1504+
for (i = 0; i < niters; i++) {
15051505
PyObject *it = PyTuple_GET_ITEM(lz->iters, i);
15061506
PyObject *val = Py_TYPE(it)->tp_iternext(it);
15071507
if (val == NULL) {
15081508
if (lz->strict) {
15091509
goto check;
15101510
}
1511-
goto exit;
1511+
goto exit_no_result;
15121512
}
15131513
stack[i] = val;
15141514
nargs++;
@@ -1521,46 +1521,46 @@ map_next(PyObject *self)
15211521
if (PyErr_Occurred()) {
15221522
if (!PyErr_ExceptionMatches(PyExc_StopIteration)) {
15231523
// next() on argument i raised an exception (not StopIteration)
1524-
assert(result == NULL);
1525-
goto exit;
1524+
goto exit_no_result;
15261525
}
15271526
PyErr_Clear();
15281527
}
15291528
if (i) {
15301529
// ValueError: map() argument 2 is shorter than argument 1
15311530
// ValueError: map() argument 3 is shorter than arguments 1-2
15321531
const char* plural = i == 1 ? " " : "s 1-";
1533-
result = PyErr_Format(PyExc_ValueError,
1534-
"map() argument %d is shorter than argument%s%d",
1535-
i + 1, plural, i);
1536-
goto exit;
1532+
PyErr_Format(PyExc_ValueError,
1533+
"map() argument %d is shorter than argument%s%d",
1534+
i + 1, plural, i);
1535+
goto exit_no_result;
15371536
}
15381537
for (i = 1; i < niters; i++) {
15391538
PyObject *it = PyTuple_GET_ITEM(lz->iters, i);
15401539
PyObject *val = (*Py_TYPE(it)->tp_iternext)(it);
15411540
if (val) {
15421541
Py_DECREF(val);
15431542
const char* plural = i == 1 ? " " : "s 1-";
1544-
result = PyErr_Format(PyExc_ValueError,
1545-
"map() argument %d is longer than argument%s%d",
1546-
i + 1, plural, i);
1547-
goto exit;
1543+
PyErr_Format(PyExc_ValueError,
1544+
"map() argument %d is longer than argument%s%d",
1545+
i + 1, plural, i);
1546+
goto exit_no_result;
15481547
}
15491548
if (PyErr_Occurred()) {
15501549
if (!PyErr_ExceptionMatches(PyExc_StopIteration)) {
15511550
// next() on argument i raised an exception (not StopIteration)
1552-
assert(result == NULL);
1553-
goto exit;
1551+
goto exit_no_result;
15541552
}
15551553
PyErr_Clear();
15561554
}
15571555
// Argument i is exhausted. So far so good...
15581556
}
15591557
// All arguments are exhausted. Success!
1558+
1559+
exit_no_result:
15601560
assert(result == NULL);
15611561

15621562
exit:
1563-
for (i=0; i < nargs; i++) {
1563+
for (i = 0; i < nargs; i++) {
15641564
Py_DECREF(stack[i]);
15651565
}
15661566
if (stack != small_stack) {

0 commit comments

Comments
 (0)