Skip to content

Commit 41dd028

Browse files
committed
address feedback
1 parent 05618aa commit 41dd028

7 files changed

Lines changed: 30 additions & 8 deletions

File tree

Include/internal/pycore_stackref.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ _PyStackRef_DUP(_PyStackRef ref, const char *filename, int linenumber)
263263
}
264264
#define PyStackRef_DUP(REF) _PyStackRef_DUP(REF, __FILE__, __LINE__)
265265

266+
static inline _PyStackRef
267+
_PyStackRef_DupImmortal(_PyStackRef ref, const char *filename, int linenumber)
268+
{
269+
assert(!PyStackRef_IsError(ref));
270+
assert(!PyStackRef_IsTaggedInt(ref));
271+
assert(!PyStackRef_RefcountOnObject(ref));
272+
PyObject *obj = _Py_stackref_get_object(ref);
273+
assert(_Py_IsImmortal(obj));
274+
return _Py_stackref_create(obj, Py_TAG_REFCNT, filename, linenumber);
275+
}
276+
#define PyStackRef_DupImmortal(REF) _PyStackRef_DupImmortal((REF), __FILE__, __LINE__)
277+
266278
static inline void
267279
_PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct, const char *filename, int linenumber)
268280
{
@@ -633,6 +645,15 @@ PyStackRef_DUP(_PyStackRef ref)
633645
}
634646
#endif
635647

648+
static inline _PyStackRef
649+
PyStackRef_DupImmortal(_PyStackRef ref)
650+
{
651+
assert(!PyStackRef_IsNull(ref));
652+
assert(!PyStackRef_RefcountOnObject(ref));
653+
assert(_Py_IsImmortal(BITS_TO_PTR_MASKED(ref)));
654+
return ref;
655+
}
656+
636657
static inline bool
637658
PyStackRef_IsHeapSafe(_PyStackRef ref)
638659
{

Modules/_testinternalcapi/test_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1972,7 +1972,7 @@ dummy_func(
19721972
inst(LOAD_COMMON_CONSTANT, ( -- value)) {
19731973
// Keep in sync with _common_constants in opcode.py
19741974
assert(oparg < NUM_COMMON_CONSTANTS);
1975-
value = PyStackRef_DUP(tstate->interp->common_consts[oparg]);
1975+
value = PyStackRef_DupImmortal(tstate->interp->common_consts[oparg]);
19761976
}
19771977

19781978
inst(LOAD_BUILD_CLASS, ( -- bc)) {

Python/executor_cases.c.h

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

Python/flowgraph.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,8 +1331,8 @@ get_const_value(int opcode, int oparg, PyObject *co_consts)
13311331
}
13321332
if (opcode == LOAD_COMMON_CONSTANT) {
13331333
assert(oparg < NUM_COMMON_CONSTANTS);
1334-
return Py_NewRef(PyStackRef_AsPyObjectBorrow(
1335-
_PyInterpreterState_GET()->common_consts[oparg]));
1334+
return PyStackRef_AsPyObjectBorrow(
1335+
_PyInterpreterState_GET()->common_consts[oparg]);
13361336
}
13371337

13381338
if (constant == NULL) {

Python/generated_cases.c.h

Lines changed: 1 addition & 1 deletion
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ def has_error_without_pop(op: parser.CodeDef) -> bool:
599599
"PyStackRef_CLEAR",
600600
"PyStackRef_CLOSE_SPECIALIZED",
601601
"PyStackRef_DUP",
602+
"PyStackRef_DupImmortal",
602603
"PyStackRef_False",
603604
"PyStackRef_FromPyObjectBorrow",
604605
"PyStackRef_FromPyObjectNew",

0 commit comments

Comments
 (0)