Skip to content

Commit c7d3f09

Browse files
committed
Replace DECREF_INPUTS with PyStackRef_CLOSE where possible
1 parent 1e51c54 commit c7d3f09

File tree

5 files changed

+55
-72
lines changed

5 files changed

+55
-72
lines changed

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_uop_metadata.h

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

Python/bytecodes.c

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ dummy_func(
361361
}
362362

363363
pure inst(POP_TOP, (value --)) {
364-
DECREF_INPUTS();
364+
PyStackRef_CLOSE(value);
365365
}
366366

367367
pure inst(PUSH_NULL, (-- res)) {
@@ -388,7 +388,7 @@ dummy_func(
388388
ERROR_NO_POP();
389389
}
390390
}
391-
DECREF_INPUTS();
391+
PyStackRef_CLOSE(value);
392392
}
393393

394394
tier1 inst(INSTRUMENTED_POP_ITER, (iter -- )) {
@@ -400,7 +400,7 @@ dummy_func(
400400
(void)receiver;
401401
val = value;
402402
DEAD(value);
403-
DECREF_INPUTS();
403+
PyStackRef_CLOSE(receiver);
404404
}
405405

406406
tier1 inst(INSTRUMENTED_END_SEND, (receiver, value -- val)) {
@@ -418,7 +418,7 @@ dummy_func(
418418

419419
inst(UNARY_NEGATIVE, (value -- res)) {
420420
PyObject *res_o = PyNumber_Negative(PyStackRef_AsPyObjectBorrow(value));
421-
DECREF_INPUTS();
421+
PyStackRef_CLOSE(value);
422422
ERROR_IF(res_o == NULL, error);
423423
res = PyStackRef_FromPyObjectSteal(res_o);
424424
}
@@ -453,7 +453,7 @@ dummy_func(
453453

454454
op(_TO_BOOL, (value -- res)) {
455455
int err = PyObject_IsTrue(PyStackRef_AsPyObjectBorrow(value));
456-
DECREF_INPUTS();
456+
PyStackRef_CLOSE(value);
457457
ERROR_IF(err < 0, error);
458458
res = err ? PyStackRef_True : PyStackRef_False;
459459
}
@@ -475,7 +475,7 @@ dummy_func(
475475
res = PyStackRef_False;
476476
}
477477
else {
478-
DECREF_INPUTS();
478+
PyStackRef_CLOSE(value);
479479
res = PyStackRef_True;
480480
}
481481
}
@@ -507,13 +507,13 @@ dummy_func(
507507
}
508508
else {
509509
assert(Py_SIZE(value_o));
510-
DECREF_INPUTS();
510+
PyStackRef_CLOSE(value);
511511
res = PyStackRef_True;
512512
}
513513
}
514514

515515
op(_REPLACE_WITH_TRUE, (value -- res)) {
516-
DECREF_INPUTS();
516+
PyStackRef_CLOSE(value);
517517
res = PyStackRef_True;
518518
}
519519

@@ -524,7 +524,7 @@ dummy_func(
524524

525525
inst(UNARY_INVERT, (value -- res)) {
526526
PyObject *res_o = PyNumber_Invert(PyStackRef_AsPyObjectBorrow(value));
527-
DECREF_INPUTS();
527+
PyStackRef_CLOSE(value);
528528
ERROR_IF(res_o == NULL, error);
529529
res = PyStackRef_FromPyObjectSteal(res_o);
530530
}
@@ -994,7 +994,7 @@ dummy_func(
994994
inst(SET_ADD, (set, unused[oparg-1], v -- set, unused[oparg-1])) {
995995
int err = PySet_Add(PyStackRef_AsPyObjectBorrow(set),
996996
PyStackRef_AsPyObjectBorrow(v));
997-
DECREF_INPUTS();
997+
PyStackRef_CLOSE(v);
998998
ERROR_IF(err, error);
999999
}
10001000

@@ -1075,7 +1075,7 @@ dummy_func(
10751075
inst(CALL_INTRINSIC_1, (value -- res)) {
10761076
assert(oparg <= MAX_INTRINSIC_1);
10771077
PyObject *res_o = _PyIntrinsics_UnaryFunctions[oparg].func(tstate, PyStackRef_AsPyObjectBorrow(value));
1078-
DECREF_INPUTS();
1078+
PyStackRef_CLOSE(value);
10791079
ERROR_IF(res_o == NULL, error);
10801080
res = PyStackRef_FromPyObjectSteal(res_o);
10811081
}
@@ -1162,12 +1162,12 @@ dummy_func(
11621162
"'async for' requires an object with "
11631163
"__aiter__ method, got %.100s",
11641164
type->tp_name);
1165-
DECREF_INPUTS();
1165+
PyStackRef_CLOSE(obj);
11661166
ERROR_IF(true, error);
11671167
}
11681168

11691169
iter_o = (*getter)(obj_o);
1170-
DECREF_INPUTS();
1170+
PyStackRef_CLOSE(obj);
11711171
ERROR_IF(iter_o == NULL, error);
11721172

11731173
if (Py_TYPE(iter_o)->tp_as_async == NULL ||
@@ -1193,7 +1193,7 @@ dummy_func(
11931193

11941194
inst(GET_AWAITABLE, (iterable -- iter)) {
11951195
PyObject *iter_o = _PyEval_GetAwaitable(PyStackRef_AsPyObjectBorrow(iterable), oparg);
1196-
DECREF_INPUTS();
1196+
PyStackRef_CLOSE(iterable);
11971197
ERROR_IF(iter_o == NULL, error);
11981198
iter = PyStackRef_FromPyObjectSteal(iter_o);
11991199
}
@@ -1255,7 +1255,7 @@ dummy_func(
12551255
JUMPBY(oparg);
12561256
}
12571257
else {
1258-
DECREF_INPUTS();
1258+
PyStackRef_CLOSE(v);
12591259
ERROR_IF(true, error);
12601260
}
12611261
}
@@ -1437,7 +1437,7 @@ dummy_func(
14371437
if (ns == NULL) {
14381438
_PyErr_Format(tstate, PyExc_SystemError,
14391439
"no locals found when storing %R", name);
1440-
DECREF_INPUTS();
1440+
PyStackRef_CLOSE(v);
14411441
ERROR_IF(true, error);
14421442
}
14431443
if (PyDict_CheckExact(ns)) {
@@ -1446,7 +1446,7 @@ dummy_func(
14461446
else {
14471447
err = PyObject_SetItem(ns, name, PyStackRef_AsPyObjectBorrow(v));
14481448
}
1449-
DECREF_INPUTS();
1449+
PyStackRef_CLOSE(v);
14501450
ERROR_IF(err, error);
14511451
}
14521452

@@ -1577,14 +1577,14 @@ dummy_func(
15771577
inst(DELETE_ATTR, (owner --)) {
15781578
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
15791579
int err = PyObject_DelAttr(PyStackRef_AsPyObjectBorrow(owner), name);
1580-
DECREF_INPUTS();
1580+
PyStackRef_CLOSE(owner);
15811581
ERROR_IF(err, error);
15821582
}
15831583

15841584
inst(STORE_GLOBAL, (v --)) {
15851585
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
15861586
int err = PyDict_SetItem(GLOBALS(), name, PyStackRef_AsPyObjectBorrow(v));
1587-
DECREF_INPUTS();
1587+
PyStackRef_CLOSE(v);
15881588
ERROR_IF(err, error);
15891589
}
15901590

@@ -1616,7 +1616,7 @@ dummy_func(
16161616
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
16171617
PyObject *v_o;
16181618
int err = PyMapping_GetOptionalItem(PyStackRef_AsPyObjectBorrow(mod_or_class_dict), name, &v_o);
1619-
DECREF_INPUTS();
1619+
PyStackRef_CLOSE(mod_or_class_dict);
16201620
ERROR_IF(err < 0, error);
16211621
if (v_o == NULL) {
16221622
if (PyDict_CheckExact(GLOBALS())
@@ -1912,17 +1912,17 @@ dummy_func(
19121912
"Value after * must be an iterable, not %.200s",
19131913
Py_TYPE(iterable)->tp_name);
19141914
}
1915-
DECREF_INPUTS();
1915+
PyStackRef_CLOSE(iterable_st);
19161916
ERROR_IF(true, error);
19171917
}
19181918
assert(Py_IsNone(none_val));
1919-
DECREF_INPUTS();
1919+
PyStackRef_CLOSE(iterable_st);
19201920
}
19211921

19221922
inst(SET_UPDATE, (set, unused[oparg-1], iterable -- set, unused[oparg-1])) {
19231923
int err = _PySet_Update(PyStackRef_AsPyObjectBorrow(set),
19241924
PyStackRef_AsPyObjectBorrow(iterable));
1925-
DECREF_INPUTS();
1925+
PyStackRef_CLOSE(iterable);
19261926
ERROR_IF(err < 0, error);
19271927
}
19281928

@@ -1997,10 +1997,10 @@ dummy_func(
19971997
"'%.200s' object is not a mapping",
19981998
Py_TYPE(update_o)->tp_name);
19991999
}
2000-
DECREF_INPUTS();
2000+
PyStackRef_CLOSE(update);
20012001
ERROR_IF(true, error);
20022002
}
2003-
DECREF_INPUTS();
2003+
PyStackRef_CLOSE(update);
20042004
}
20052005

20062006
inst(DICT_MERGE, (callable, unused, unused, dict, unused[oparg - 1], update -- callable, unused, unused, dict, unused[oparg - 1])) {
@@ -2011,10 +2011,10 @@ dummy_func(
20112011
int err = _PyDict_MergeEx(dict_o, update_o, 2);
20122012
if (err < 0) {
20132013
_PyEval_FormatKwargsError(tstate, callable_o, update_o);
2014-
DECREF_INPUTS();
2014+
PyStackRef_CLOSE(update);
20152015
ERROR_IF(true, error);
20162016
}
2017-
DECREF_INPUTS();
2017+
PyStackRef_CLOSE(update);
20182018
}
20192019

20202020
inst(MAP_ADD, (dict_st, unused[oparg - 1], key, value -- dict_st, unused[oparg - 1])) {
@@ -2199,15 +2199,15 @@ dummy_func(
21992199
CALL that it's not a method call.
22002200
meth | NULL | arg1 | ... | argN
22012201
*/
2202-
DECREF_INPUTS();
2202+
PyStackRef_CLOSE(owner);
22032203
ERROR_IF(attr_o == NULL, error);
22042204
self_or_null[0] = PyStackRef_NULL;
22052205
}
22062206
}
22072207
else {
22082208
/* Classic, pushes one value. */
22092209
attr_o = PyObject_GetAttr(PyStackRef_AsPyObjectBorrow(owner), name);
2210-
DECREF_INPUTS();
2210+
PyStackRef_CLOSE(owner);
22112211
ERROR_IF(attr_o == NULL, error);
22122212
}
22132213
attr = PyStackRef_FromPyObjectSteal(attr_o);
@@ -2762,12 +2762,11 @@ dummy_func(
27622762
assert(PyExceptionInstance_Check(left_o));
27632763
int err = _PyEval_CheckExceptTypeValid(tstate, right_o);
27642764
if (err < 0) {
2765-
DECREF_INPUTS();
2766-
ERROR_IF(true, error);
2765+
ERROR_NO_POP();
27672766
}
27682767

27692768
int res = PyErr_GivenExceptionMatches(left_o, right_o);
2770-
DECREF_INPUTS();
2769+
PyStackRef_CLOSE(right);
27712770
b = res ? PyStackRef_True : PyStackRef_False;
27722771
}
27732772

@@ -2994,7 +2993,7 @@ dummy_func(
29942993
inst(GET_ITER, (iterable -- iter)) {
29952994
/* before: [obj]; after [getiter(obj)] */
29962995
PyObject *iter_o = PyObject_GetIter(PyStackRef_AsPyObjectBorrow(iterable));
2997-
DECREF_INPUTS();
2996+
PyStackRef_CLOSE(iterable);
29982997
ERROR_IF(iter_o == NULL, error);
29992998
iter = PyStackRef_FromPyObjectSteal(iter_o);
30002999
}
@@ -3436,7 +3435,7 @@ dummy_func(
34363435
assert((oparg & 1) == 0);
34373436
STAT_INC(LOAD_ATTR, hit);
34383437
assert(descr != NULL);
3439-
DECREF_INPUTS();
3438+
PyStackRef_CLOSE(owner);
34403439
attr = PyStackRef_FromPyObjectNew(descr);
34413440
}
34423441

@@ -3452,7 +3451,7 @@ dummy_func(
34523451
assert(Py_TYPE(PyStackRef_AsPyObjectBorrow(owner))->tp_dictoffset == 0);
34533452
STAT_INC(LOAD_ATTR, hit);
34543453
assert(descr != NULL);
3455-
DECREF_INPUTS();
3454+
PyStackRef_CLOSE(owner);
34563455
attr = PyStackRef_FromPyObjectNew(descr);
34573456
}
34583457

0 commit comments

Comments
 (0)