8000 gh-98831: Use DECREF_INPUTS() more (#102409) · Fidget-Spinner/cpython@b99132d · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit b99132d

Browse files
gvanrossumFidget-Spinner
authored andcommitted
pythongh-98831: Use DECREF_INPUTS() more (python#102409)
1 parent 75153c1 commit b99132d

File tree

2 files changed

+38
-57
lines changed

2 files changed

+38
-57
lines changed

Python/bytecodes.c

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,7 @@ dummy_func(
457457
if (!_PyErr_Occurred(tstate)) {
458458
_PyErr_SetKeyError(sub);
459459
}
460-
Py_DECREF(dict);
461-
Py_DECREF(sub);
460+
DECREF_INPUTS();
462461
ERROR_IF(true, error);
463462
}
464463
Py_INCREF(res); // Do this before DECREF'ing dict, sub
@@ -493,7 +492,7 @@ dummy_func(
493492

494493
inst(SET_ADD, (set, unused[oparg-1], v -- set, unused[oparg-1])) {
495494
int err = PySet_Add(set, v);
496-
Py_DECREF(v);
495+
DECREF_INPUTS();
497496
ERROR_IF(err, error);
498497
PREDICT(JUMP_BACKWARD);
499498
}
@@ -972,7 +971,7 @@ dummy_func(
972971
#endif /* ENABLE_SPECIALIZATION */
973972
PyObject **top = stack_pointer + oparg - 1;
974973
int res = unpack_iterable(tstate, seq, oparg, -1, top);
975-
Py_DECREF(seq);
974+
DECREF_INPUTS();
976975
ERROR_IF(res == 0, error);
977976
}
978977

@@ -983,7 +982,7 @@ dummy_func(
983982
STAT_INC(UNPACK_SEQUENCE, hit);
984983
values[0] = Py_NewRef(PyTuple_GET_ITEM(seq, 1));
985984
values[1] = Py_NewRef(PyTuple_GET_ITEM(seq, 0));
986-
Py_DECREF(seq);
985+
DECREF_INPUTS();
987986
}
988987

989988
inst(UNPACK_SEQUENCE_TUPLE, (unused/1, seq -- values[oparg])) {
@@ -994,7 +993,7 @@ dummy_func(
994993
for (int i = oparg; --i >= 0; ) {
995994
*values++ = Py_NewRef(items[i]);
996995
}
997-
Py_DECREF(seq);
996+
DECREF_INPUTS();
998997
}
999998

1000999
inst(UNPACK_SEQUENCE_LIST, (unused/1, seq -- values[oparg])) {
@@ -1005,14 +1004,14 @@ dummy_func(
10051004
for (int i = oparg; --i >= 0; ) {
10061005
*values++ = Py_NewRef(items[i]);
10071006
}
1008-
Py_DECREF(seq);
1007+
DECREF_INPUTS();
10091008
}
10101009

10111010
inst(UNPACK_EX, (seq -- unused[oparg & 0xFF], unused, unused[oparg >> 8])) {
10121011
int totalargs = 1 + (oparg & 0xFF) + (oparg >> 8);
10131012
PyObject **top = stack_pointer + totalargs - 1;
10141013
int res = unpack_iterable(tstate, seq, oparg & 0xFF, oparg >> 8, top);
1015-
Py_DECREF(seq);
1014+
DECREF_INPUTS();
10161015
ERROR_IF(res == 0, error);
10171016
}
10181017

@@ -1040,22 +1039,21 @@ dummy_func(
10401039
#endif /* ENABLE_SPECIALIZATION */
10411040
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
10421041
int err = PyObject_SetAttr(owner, name, v);
1043-
Py_DECREF(v);
1044-
Py_DECREF(owner);
1042+
DECREF_INPUTS();
10451043
ERROR_IF(err, error);
10461044
}
10471045

10481046
inst(DELETE_ATTR, (owner --)) {
10491047
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
10501048
int err = PyObject_SetAttr(owner, name, (PyObject *)NULL);
1051-
Py_DECREF(owner);
1049+
DECREF_INPUTS();
10521050
ERROR_IF(err, error);
10531051
}
10541052

10551053
inst(STORE_GLOBAL, (v --)) {
10561054
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
10571055
int err = PyDict_SetItem(GLOBALS(), name, v);
1058-
Py_DECREF(v);
1056+
DECREF_INPUTS();
10591057
ERROR_IF(err, error);
10601058
}
10611059

@@ -1322,9 +1320,7 @@ dummy_func(
13221320

13231321
inst(BUILD_STRING, (pieces[oparg] -- str: PyUnicode_Type)) {
13241322
str = _PyUnicode_JoinArray(&_Py_STR(empty), pieces, oparg);
1325-
for (int i = 0; i < oparg; i++) {
1326-
Py_DECREF(pieces[i]);
1327-
}
1323+
DECREF_INPUTS();
13281324
ERROR_IF(str == NULL, error);
13291325
}
13301326

@@ -1387,10 +1383,7 @@ dummy_func(
13871383
if (map == NULL)
13881384
goto error;
13891385

1390-
for (int i = 0; i < oparg; i++) {
1391-
Py_DECREF(values[i*2]);
1392-
Py_DECREF(values[i*2+1]);
1393-
}
1386+
DECREF_INPUTS();
13941387
ERROR_IF(map == NULL, error);
13951388
}
13961389

@@ -1446,10 +1439,7 @@ dummy_func(
14461439
map = _PyDict_FromItems(
14471440
&PyTuple_GET_ITEM(keys, 0), 1,
14481441
values, 1, oparg);
1449-
Py_DECREF(keys);
1450-
for (int i = 0; i < oparg; i++) {
1451-
Py_DECREF(values[i]);
1452-
}
1442+
DECREF_INPUTS();
14531443
ERROR_IF(map == NULL, error);
14541444
}
14551445

@@ -1537,7 +1527,7 @@ dummy_func(
15371527
15381528
NULL | meth | arg1 | ... | argN
15391529
*/
1540-
Py_DECREF(owner);
1530+
DECREF_INPUTS();
15411531
ERROR_IF(meth == NULL, error);
15421532
res2 = NULL;
15431533
res = meth;
@@ -1546,7 +1536,7 @@ dummy_func(
15461536
else {
15471537
/* Classic, pushes one value. */
15481538
res = PyObject_GetAttr(owner, name);
1549-
Py_DECREF(owner);
1539+
DECREF_INPUTS();
15501540
ERROR_IF(res == NULL, error);
15511541
}
15521542
}
@@ -1565,7 +1555,7 @@ dummy_func(
15651555
STAT_INC(LOAD_ATTR, hit);
15661556
Py_INCREF(res);
15671557
res2 = NULL;
1568-
Py_DECREF(owner);
1558+
DECREF_INPUTS();
15691559
}
15701560

15711561
inst(LOAD_ATTR_MODULE, (unused/1, type_version/2, index/1, unused/5, owner -- res2 if (oparg & 1), res)) {
@@ -1582,7 +1572,7 @@ dummy_func(
15821572
STAT_INC(LOAD_ATTR, hit);
15831573
Py_INCREF(res);
15841574
res2 = NULL;
1585-
Py_DECREF(owner);
1575+
DECREF_INPUTS();
15861576
}
15871577

15881578
inst(LOAD_ATTR_WITH_HINT, (unused/1, type_version/2, index/1, unused/5, owner -- res2 if (oparg & 1), res)) {
@@ -1613,7 +1603,7 @@ dummy_func(
16131603
STAT_INC(LOAD_ATTR, hit);
16141604
Py_INCREF(res);
16151605
res2 = NULL;
1616-
Py_DECREF(owner);
1606+
DECREF_INPUTS();
16171607
}
16181608

16191609
inst(LOAD_ATTR_SLOT, (unused/1, type_version/2, index/1, unused/5, owner -- res2 if (oparg & 1), res)) {
@@ -1627,7 +1617,7 @@ dummy_func(
16271617
STAT_INC(LOAD_ATTR, hit);
16281618
Py_INCREF(res);
16291619
res2 = NULL;
1630-
Py_DECREF(owner);
1620+
DECREF_INPUTS();
16311621
}
16321622

16331623
inst(LOAD_ATTR_CLASS, (unused/1, type_version/2, unused/2, descr/4, cls -- res2 if (oparg & 1), res)) {
@@ -1643,7 +1633,7 @@ dummy_func(
16431633
res = descr;
16441634
assert(res != NULL);
16451635
Py_INCREF(res);
1646-
Py_DECREF(cls);
1636+
DECREF_INPUTS();
16471637
}
16481638

16491639
inst(LOAD_ATTR_PROPERTY, (unused/1, type_version/2, func_version/2, fget/4, owner -- unused if (oparg & 1), unused)) {
@@ -1780,8 +1770,7 @@ dummy_func(
17801770
STAT_INC(COMPARE_OP, deferred);
17811771
assert((oparg >> 4) <= Py_GE);
17821772
res = PyObject_RichCompare(left, right, oparg>>4);
1783-
Py_DECREF(left);
1784-
Py_DECREF(right);
1773+
DECREF_INPUTS();
17851774
ERROR_IF(res == NULL, error);
17861775
}
17871776

@@ -1807,8 +1796,7 @@ dummy_func(
18071796
#endif /* ENABLE_SPECIALIZATION */
18081797
assert((oparg >> 4) <= Py_GE);
18091798
PyObject *cond = PyObject_RichCompare(left, right, oparg>>4);
1810-
Py_DECREF(left);
1811-
Py_DECREF(right);
1799+
DECREF_INPUTS();
18121800
ERROR_IF(cond == NULL, error);
18131801
assert(next_instr[1].op.code == POP_JUMP_IF_FALSE ||
18141802
next_instr[1].op.code == POP_JUMP_IF_TRUE);
@@ -1963,7 +1951,7 @@ dummy_func(
19631951
}
19641952
else {
19651953
int err = PyObject_IsTrue(cond);
1966-
Py_DECREF(cond);
1954+
DECREF_INPUTS();
19671955
if (err == 0) {
19681956
JUMPBY(oparg);
19691957
}
@@ -2004,7 +1992,7 @@ dummy_func(
20041992
}
20051993
else {
20061994
int err = PyObject_IsTrue(cond);
2007-
Py_DECREF(cond);
1995+
DECREF_INPUTS();
20081996
if (err > 0) {
20091997
JUMPBY(oparg);
20101998
}
@@ -2038,7 +2026,7 @@ dummy_func(
20382026

20392027
inst(POP_JUMP_IF_NOT_NONE, (value -- )) {
20402028
if (!Py_IsNone(value)) {
2041-
Py_DECREF(value);
2029+
DECREF_INPUTS();
20422030
JUMPBY(oparg);
20432031
}
20442032
else {
@@ -2063,7 +2051,7 @@ dummy_func(
20632051
JUMPBY(oparg);
20642052
}
20652053
else {
2066-
Py_DECREF(value);
2054+
DECREF_INPUTS();
20672055
}
20682056
}
20692057

@@ -2270,7 +2258,7 @@ dummy_func(
22702258
if (iter == NULL) {
22712259
goto error;
22722260
}
2273-
Py_DECREF(iterable);
2261+
DECREF_INPUTS();
22742262
}
22752263
PREDICT(LOAD_CONST);
22762264
}
@@ -3168,9 +3156,7 @@ dummy_func(
31683156
assert(PyTuple_CheckExact(callargs));
31693157

31703158
result = do_call_core(tstate, func, callargs, kwargs, cframe.use_tracing);
3171-
Py_DECREF(func);
3172-
Py_DECREF(callargs);
3173-
Py_XDECREF(kwargs);
3159+
DECREF_INPUTS();
31743160

31753161
assert(PEEK(3 + (oparg & 1)) == NULL);
31763162
ERROR_IF(result == NULL, error);
@@ -3237,9 +3223,7 @@ dummy_func(
32373223

32383224
inst(BUILD_SLICE, (start, stop, step if (oparg == 3) -- slice)) {
32393225
slice = PySlice_New(start, stop, step);
3240-
Py_DECREF(start);
3241-
Py_DECREF(stop);
3242-
Py_XDECREF(step);
3226+
DECREF_INPUTS();
32433227
ERROR_IF(slice == NULL, error);
32443228
}
32453229

@@ -3285,8 +3269,7 @@ dummy_func(
32853269
} else {
32863270
/* Actually call format(). */
32873271
result = PyObject_Format(value, fmt_spec);
3288-
Py_DECREF(value);
3289-
Py_XDECREF(fmt_spec);
3272+
DECREF_INPUTS();
32903273
ERROR_IF(result == NULL, error);
32913274
}
32923275
}
@@ -3312,8 +3295,7 @@ dummy_func(
33123295
assert((unsigned)oparg < Py_ARRAY_LENGTH(binary_ops));
33133296
assert(binary_ops[oparg]);
33143297
res = binary_ops[oparg](lhs, rhs);
3315-
Py_DECREF(lhs);
3316-
Py_DECREF(rhs);
3298+
DECREF_INPUTS();
33173299
ERROR_IF(res == NULL, error);
33183300
}
33193301

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)
0