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

Skip to content

Commit 8044c7e

Browse files
Address rest of review
1 parent 8dc4fc6 commit 8044c7e

File tree

8 files changed

+25
-43
lines changed

8 files changed

+25
-43
lines changed

Include/internal/pycore_ceval.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ PyAPI_FUNC(PyObject *)_PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, Py
257257
PyAPI_FUNC(int) _PyEval_UnpackIterableStackRef(PyThreadState *tstate, _PyStackRef v, int argcnt, int argcntafter, _PyStackRef *sp);
258258
PyAPI_FUNC(void) _PyEval_FrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame *frame);
259259
PyAPI_FUNC(PyObject **) _PyObjectArray_FromStackRefArray(_PyStackRef *input, int nargs, PyObject **scratch);
260-
PyAPI_FUNC(PyObject **) _PyNewObjectArray_FromStackRefArray(_PyStackRef *input, int nargs, PyObject **scratch);
261260

262261
PyAPI_FUNC(void) _PyObjectArray_Free(PyObject **array, PyObject **scratch);
263262

Include/internal/pycore_stackref.h

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

108+
#ifdef Py_GIL_DISABLED
109+
// Gets a PyObject * from a _PyStackRef, stealing the reference
110+
static inline PyObject *
111+
PyStackRef_AsPyObjectSteal(_PyStackRef tagged)
112+
{
113+
PyObject *cleared = ((PyObject *)((tagged).bits & (~Py_TAG_BITS)));
114+
return cleared;
115+
}
116+
#else
117+
// Need to define as macro because WASI has very sensitive stack sizes.
118+
# define PyStackRef_AsPyObjectSteal(tagged) ((PyObject *)(tagged).bits)
119+
#endif
120+
108121
static inline PyTypeObject *
109122
PyStackRef_TYPE(_PyStackRef stackref)
110123
{

Python/bytecodes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@ dummy_func(
17841784
}
17851785

17861786
inst(BUILD_TUPLE, (values[oparg] -- tup)) {
1787-
STACKREFS_TO_PYOBJECTS_NEW(values, oparg, values_o);
1787+
STACKREFS_TO_PYOBJECTS(values, oparg, values_o);
17881788
if (values_o == NULL) {
17891789
DECREF_INPUTS();
17901790
ERROR_IF(true, error);
@@ -1796,7 +1796,7 @@ dummy_func(
17961796
}
17971797

17981798
inst(BUILD_LIST, (values[oparg] -- list)) {
1799-
STACKREFS_TO_PYOBJECTS_NEW(values, oparg, values_o);
1799+
STACKREFS_TO_PYOBJECTS(values, oparg, values_o);
18001800
if (values_o == NULL) {
18011801
DECREF_INPUTS();
18021802
ERROR_IF(true, error);
@@ -4025,7 +4025,7 @@ dummy_func(
40254025
assert(self_o != NULL);
40264026
DEOPT_IF(!PyList_Check(self_o));
40274027
STAT_INC(CALL, hit);
4028-
if (_PyList_AppendTakeRef((PyListObject *)self_o, PyStackRef_AsPyObjectNew(arg)) < 0) {
4028+
if (_PyList_AppendTakeRef((PyListObject *)self_o, PyStackRef_AsPyObjectSteal(arg)) < 0) {
40294029
goto pop_1_error; // Since arg is DECREF'ed already
40304030
}
40314031
PyStackRef_CLOSE(self);
@@ -4643,7 +4643,7 @@ dummy_func(
46434643

46444644
op (_GUARD_IS_NONE_POP, (val -- )) {
46454645
SYNC_SP();
4646-
if (!PyStackRef_IsNone(value)) {
4646+
if (!PyStackRef_IsNone(val)) {
46474647
PyStackRef_CLOSE(val);
46484648
EXIT_IF(1);
46494649
}

Python/ceval.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -693,25 +693,6 @@ _PyObjectArray_FromStackRefArray(_PyStackRef *input, int nargs, PyObject **scrat
693693
return result;
694694
}
695695

696-
PyObject **
697-
_PyNewObjectArray_FromStackRefArray(_PyStackRef *input, int nargs, PyObject **scratch)
698-
{
699-
PyObject **result;
700-
if (nargs > MAX_STACKREF_SCRATCH) {
701-
result = PyMem_Malloc(nargs * sizeof(PyObject *));
702-
if (result == NULL) {
703-
return NULL;
704-
}
705-
}
706-
else {
707-
result = scratch;
708-
}
709-
for (int i = 0; i < nargs; i++) {
710-
result[i] = PyStackRef_AsPyObjectNew(input[i]);
711-
}
712-
return result;
713-
}
714-
715696
void
716697
_PyObjectArray_Free(PyObject **array, PyObject **scratch)
717698
{
@@ -1514,7 +1495,7 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func,
15141495
}
15151496
else {
15161497
assert(args != NULL);
1517-
STACKREFS_TO_PYOBJECTS_NEW((_PyStackRef *)args, argcount, args_o);
1498+
STACKREFS_TO_PYOBJECTS((_PyStackRef *)args, argcount, args_o);
15181499
if (args_o == NULL) {
15191500
goto fail_pre_positional;
15201501
}

Python/ceval_macros.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -464,17 +464,6 @@ do { \
464464
assert(NAME != NULL);
465465
#endif
466466

467-
#ifdef Py_GIL_DISABLED
468-
#define STACKREFS_TO_PYOBJECTS_NEW(ARGS, ARG_COUNT, NAME) \
469-
PyObject *NAME##_temp[MAX_STACKREF_SCRATCH]; \
470-
PyObject **NAME = _PyObjectArray_FromStackRefArray(ARGS, ARG_COUNT, NAME##_temp);
471-
#else
472-
#define STACKREFS_TO_PYOBJECTS_NEW(ARGS, ARG_COUNT, NAME) \
473-
PyObject **NAME = (PyObject **)ARGS; \
474-
/* This hopefully hints to the compiler to DCE the NULL check for error */ \
475-
assert(NAME != NULL);
476-
#endif
477-
478467
#ifdef Py_GIL_DISABLED
479468
#define STACKREFS_TO_PYOBJECTS_CLEANUP(NAME) \
480469
_PyObjectArray_Free(NAME, NAME##_temp);

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/generated_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.

Tools/cases_generator/analyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ def has_error_without_pop(op: parser.InstDef) -> bool:
356356
"PyStackRef_FromPyObjectSteal",
357357
"PyStackRef_AsPyObjectBorrow",
358358
"PyStackRef_AsPyObjectNew",
359+
"PyStackRef_AsPyObjectSteal",
359360
"PyStackRef_CLOSE",
360361
"PyStackRef_DUP",
361362
"PyStackRef_CLEAR",
@@ -429,7 +430,6 @@ def has_error_without_pop(op: parser.InstDef) -> bool:
429430
"Py_FatalError",
430431
"PyStackRef_IsTrue",
431432
"PyStackRef_IsFalse",
432-
"STACKREFS_TO_PYOBJECTS_NEW",
433433
"STACKREFS_TO_PYOBJECTS",
434434
"STACKREFS_TO_PYOBJECTS_CLEANUP",
435435
"_PyList_FromArraySteal",

0 commit comments

Comments
 (0)
0