8000 Address rest of review · python/cpython@8dc4fc6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8dc4fc6

Browse files
Address rest of review
1 parent 6c76fe3 commit 8dc4fc6

File tree

4 files changed

+44
-61
lines changed

4 files changed

+44
-61
lines changed

Include/internal/pycore_stackref.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ PyStackRef_AsPyObjectBorrow(_PyStackRef tagged)
105105
# define PyStackRef_AsPyObjectBorrow(tagged) ((PyObject *)(tagged).bits)
106106
#endif
107107

108+
static inline PyTypeObject *
109+
PyStackRef_TYPE(_PyStackRef stackref)
110+
{
111+
return Py_TYPE(PyStackRef_AsPyObjectBorrow(stackref));
112+
}
113+
108114
// Converts a PyObject * to a PyStackRef, stealing the reference
109115
static inline _PyStackRef
110116
_PyStackRef_FromPyObjectSteal(PyObject *obj)

Python/bytecodes.c

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,13 +2790,13 @@ dummy_func(
27902790
}
27912791

27922792
inst(MATCH_MAPPING, (subject -- subject, res)) {
2793-
int match = Py_TYPE(PyStackRef_AsPyObjectBorrow(subject))->tp_flags & Py_TPFLAGS_MAPPING;
2794-
res = PyStackRef_FromPyObjectSteal(match ? Py_True : Py_False);
2793+
int match = PyStackRef_TYPE(subject)->tp_flags & Py_TPFLAGS_MAPPING;
2794+
res = match ? PyStackRef_True() : PyStackRef_False();
27952795
}
27962796

27972797
inst(MATCH_SEQUENCE, (subject -- subject, res)) {
2798-
int match = Py_TYPE(PyStackRef_AsPyObjectBorrow(subject))->tp_flags & Py_TPFLAGS_SEQUENCE;
2799-
res = PyStackRef_FromPyObjectSteal(match ? Py_True : Py_False);
2798+
int match = PyStackRef_TYPE(subject)->tp_flags & Py_TPFLAGS_SEQUENCE;
2799+
res = match ? PyStackRef_True() : PyStackRef_False();
28002800
}
28012801

28022802
inst(MATCH_KEYS, (subject, keys -- subject, keys, values_or_none)) {
@@ -3894,7 +3894,6 @@ dummy_func(
38943894
DECREF_INPUTS();
38953895
ERROR_IF(true, error);
38963896
}
3897-
ERROR_IF(args_o == NULL, error);
38983897
PyObject *res_o = ((PyCFunctionFast)(void(*)(void))cfunc)(
38993898
PyCFunction_GET_SELF(callable_o),
39003899
args_o,
@@ -4008,15 +4007,11 @@ dummy_func(
40084007
if (retval < 0) {
40094008
ERROR_NO_POP();
40104009
}
4011-
PyObject *res_o = PyBool_FromLong(retval);
4012-
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
4013-
if (res_o == NULL) {
4014-
GOTO_ERROR(error);
4015-
}
4010+
res = retval ? PyStackRef_True() : PyStackRef_False();
4011+
assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL));
40164012
PyStackRef_CLOSE(inst_stackref);
40174013
PyStackRef_CLOSE(cls_stackref);
40184014
PyStackRef_CLOSE(callable);
4019-
res = PyStackRef_FromPyObjectSteal(res_o);
40204015
}
40214016

40224017
// This is secretly a super-instruction
@@ -4559,9 +4554,9 @@ dummy_func(
45594554
}
45604555

45614556
inst(INSTRUMENTED_POP_JUMP_IF_TRUE, (unused/1 -- )) {
4562-
PyObject *cond = PyStackRef_AsPyObjectBorrow(POP());
4563-
assert(PyBool_Check(cond));
4564-
int flag = Py_IsTrue(cond);
4557+
_PyStackRef cond = POP();
4558+
assert(PyBool_Check(PyStackRef_AsPyObjectBorrow(cond)));
4559+
int flag = PyStackRef_IsTrue(cond);
45654560
int offset = flag * oparg;
45664561
#if ENABLE_SPECIALIZATION
45674562
this_instr[1].cache = (this_instr[1].cache << 1) | flag;
@@ -4570,9 +4565,9 @@ dummy_func(
45704565
}
45714566

45724567
inst(INSTRUMENTED_POP_JUMP_IF_FALSE, (unused/1 -- )) {
4573-
PyObject *cond = PyStackRef_AsPyObjectBorrow(POP());
4574-
assert(PyBool_Check(cond));
4575-
int flag = Py_IsFalse(cond);
4568+
_PyStackRef cond = POP();
4569+
assert(PyBool_Check(PyStackRef_AsPyObjectBorrow(cond)));
4570+
int flag = PyStackRef_IsFalse(cond);
45764571
int offset = flag * oparg;
45774572
#if ENABLE_SPECIALIZATION
45784573
this_instr[1].cache = (this_instr[1].cache << 1) | flag;
@@ -4635,23 +4630,18 @@ dummy_func(
46354630
///////// Tier-2 only opcodes /////////
46364631

46374632
op (_GUARD_IS_TRUE_POP, (flag -- )) {
4638-
PyObject *flag_o = PyStackRef_AsPyObjectBorrow(flag);
4639-
46404633
SYNC_SP();
4641-
EXIT_IF(!Py_IsTrue(flag_o));
4642-
assert(Py_IsTrue(flag_o));
4634+
EXIT_IF(!PyStackRef_IsTrue(flag));
4635+
assert(PyStackRef_IsTrue(flag));
46434636
}
46444637

46454638
op (_GUARD_IS_FALSE_POP, (flag -- )) {
4646-
PyObject *flag_o = PyStackRef_AsPyObjectBorrow(flag);
4647-
46484639
SYNC_SP();
4649-
EXIT_IF(!Py_IsFalse(flag_o));
4650-
assert(Py_IsFalse(flag_o));
4640+
EXIT_IF(!PyStackRef_IsFalse(flag));
4641+
assert(PyStackRef_IsFalse(flag));
46514642
}
46524643

46534644
op (_GUARD_IS_NONE_POP, (val -- )) {
4654-
46554645
SYNC_SP();
46564646
if (!PyStackRef_IsNone(value)) {
46574647
PyStackRef_CLOSE(val);
@@ -4660,7 +4650,6 @@ dummy_func(
46604650
}
46614651

46624652
op (_GUARD_IS_NOT_NONE_POP, (val -- )) {
4663-
46644653
SYNC_SP();
46654654
EXIT_IF(PyStackRef_IsNone(val));
46664655
PyStackRef_CLOSE(val);

Python/executor_cases.c.h

Lines changed: 10 additions & 17 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: 12 additions & 17 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