Skip to content

Commit 1f5cfcd

Browse files
committed
Use PyStackRef_Borrow as the new API
1 parent b0ea38f commit 1f5cfcd

File tree

7 files changed

+34
-80
lines changed

7 files changed

+34
-80
lines changed

Include/internal/pycore_stackref.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ PyStackRef_MakeHeapSafe(_PyStackRef ref)
178178
return ref;
179179
}
180180

181+
static inline _PyStackRef
182+
PyStackRef_Borrow(_PyStackRef ref)
183+
{
184+
return PyStackRef_DUP(ref)
185+
}
186+
181187
#define PyStackRef_CLEAR(REF) \
182188
do { \
183189
_PyStackRef *_tmp_op_ptr = &(REF); \
@@ -347,7 +353,7 @@ PyStackRef_DUP(_PyStackRef stackref)
347353
}
348354

349355
static inline _PyStackRef
350-
PyStackRef_AsDeferred(_PyStackRef stackref)
356+
PyStackRef_Borrow(_PyStackRef stackref)
351357
{
352358
return (_PyStackRef){ .bits = stackref.bits | Py_TAG_DEFERRED };
353359
}
@@ -432,6 +438,8 @@ static inline void PyStackRef_CheckValid(_PyStackRef ref) {
432438

433439
#endif
434440

441+
#define PyStackRef_Borrow(ref) PyStackRef_DUP(ref)
442+
435443
#ifdef _WIN32
436444
#define PyStackRef_RefcountOnObject(REF) (((REF).bits & Py_TAG_BITS) == 0)
437445
#define PyStackRef_AsPyObjectBorrow BITS_TO_PTR_MASKED

Lib/test/test_dis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ def load_test(x, y=0):
877877
%3d LOAD_FAST_LOAD_FAST 1 (x, y)
878878
STORE_FAST_STORE_FAST 50 (b, a)
879879
880-
%3d LOAD_FAST_LOAD_FAST 35 (a, b)
880+
%3d LOAD_FAST_BORROW_LOAD_FAST_BORROW 35 (a, b)
881881
BUILD_TUPLE 2
882882
RETURN_VALUE
883883
""" % (load_test.__code__.co_firstlineno,
@@ -901,7 +901,7 @@ def loop_test():
901901
STORE_FAST 0 (i)
902902
903903
%3d LOAD_GLOBAL_MODULE 1 (load_test + NULL)
904-
LOAD_FAST 0 (i)
904+
LOAD_FAST_BORROW 0 (i)
905905
CALL_PY_GENERAL 1
906906
POP_TOP
907907
JUMP_BACKWARD_{: <6} 16 (to L1)

Programs/test_frozenmain.h

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

Python/bytecodes.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,7 @@ dummy_func(
272272

273273
replicate(8) pure inst (LOAD_FAST_BORROW, (-- value)) {
274274
assert(!PyStackRef_IsNull(GETLOCAL(oparg)));
275-
#ifdef Py_GIL_DISABLED
276-
value = PyStackRef_AsDeferred(GETLOCAL(oparg));
277-
#else
278-
value = PyStackRef_DUP(GETLOCAL(oparg));
279-
#endif
275+
value = PyStackRef_Borrow(GETLOCAL(oparg));
280276
}
281277

282278
inst(LOAD_FAST_AND_CLEAR, (-- value)) {
@@ -294,13 +290,8 @@ dummy_func(
294290
inst(LOAD_FAST_BORROW_LOAD_FAST_BORROW, ( -- value1, value2)) {
295291
uint32_t oparg1 = oparg >> 4;
296292
uint32_t oparg2 = oparg & 15;
297-
#ifdef Py_GIL_DISABLED
298-
value1 = PyStackRef_AsDeferred(GETLOCAL(oparg1));
299-
value2 = PyStackRef_AsDeferred(GETLOCAL(oparg2));
300-
#else
301-
value1 = PyStackRef_DUP(GETLOCAL(oparg1));
302-
value2 = PyStackRef_DUP(GETLOCAL(oparg2));
303-
#endif
293+
value1 = PyStackRef_Borrow(GETLOCAL(oparg1));
294+
value2 = PyStackRef_Borrow(GETLOCAL(oparg2));
304295
}
305296

306297
family(LOAD_CONST, 0) = {

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

Tools/cases_generator/analyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,11 @@ def has_error_without_pop(op: parser.CodeDef) -> bool:
584584
"PyLong_FromLong",
585585
"PyLong_FromSsize_t",
586586
"PySlice_New",
587-
"PyStackRef_AsDeferred",
588587
"PyStackRef_AsPyObjectBorrow",
589588
"PyStackRef_AsPyObjectNew",
590589
"PyStackRef_FromPyObjectNewMortal",
591590
"PyStackRef_AsPyObjectSteal",
591+
"PyStackRef_Borrow",
592592
"PyStackRef_CLEAR",
593593
"PyStackRef_CLOSE_SPECIALIZED",
594594
"PyStackRef_DUP",

0 commit comments

Comments
 (0)