Skip to content

Commit e108619

Browse files
Remove redundant refcount
1 parent d844d22 commit e108619

File tree

8 files changed

+56
-16
lines changed

8 files changed

+56
-16
lines changed

Include/internal/pycore_opcode_metadata.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.

Include/internal/pycore_uop_ids.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.

Include/internal/pycore_uop_metadata.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.

Lib/test/test_capi/test_opt.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,6 +2517,24 @@ def testfunc(n):
25172517
self.assertNotIn("_POP_TOP_INT", uops)
25182518
self.assertIn("_POP_TOP_NOP", uops)
25192519

2520+
def test_store_attr_slot(self):
2521+
class C:
2522+
__slots__ = ('x',)
2523+
2524+
def testfunc(n):
2525+
c = C()
2526+
for _ in range(n):
2527+
c.x = 42
2528+
y = c.x
2529+
return y
2530+
2531+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2532+
self.assertEqual(res, 42)
2533+
self.assertIsNotNone(ex)
2534+
uops = get_opnames(ex)
2535+
self.assertIn("_STORE_ATTR_SLOT", uops)
2536+
self.assertIn("_POP_TOP", uops)
2537+
25202538
def test_attr_promotion_failure(self):
25212539
# We're not testing for any specific uops here, just
25222540
# testing it doesn't crash.

Python/bytecodes.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,7 +2668,7 @@ dummy_func(
26682668
_GUARD_TYPE_VERSION +
26692669
_STORE_ATTR_WITH_HINT;
26702670

2671-
op(_STORE_ATTR_SLOT, (index/1, value, owner --)) {
2671+
op(_STORE_ATTR_SLOT, (index/1, value, owner -- o)) {
26722672
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
26732673

26742674
DEOPT_IF(!LOCK_OBJECT(owner_o));
@@ -2677,14 +2677,16 @@ dummy_func(
26772677
PyObject *old_value = *(PyObject **)addr;
26782678
FT_ATOMIC_STORE_PTR_RELEASE(*(PyObject **)addr, PyStackRef_AsPyObjectSteal(value));
26792679
UNLOCK_OBJECT(owner_o);
2680-
PyStackRef_CLOSE(owner);
2680+
INPUTS_DEAD();
2681+
o = owner;
26812682
Py_XDECREF(old_value);
26822683
}
26832684

26842685
macro(STORE_ATTR_SLOT) =
26852686
unused/1 +
26862687
_GUARD_TYPE_VERSION +
2687-
_STORE_ATTR_SLOT;
2688+
_STORE_ATTR_SLOT +
2689+
POP_TOP;
26882690

26892691
family(COMPARE_OP, INLINE_CACHE_ENTRIES_COMPARE_OP) = {
26902692
COMPARE_OP_FLOAT,

Python/executor_cases.c.h

Lines changed: 10 additions & 4 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: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)