8000 revert lists · python/cpython@65be3fd · GitHub
[go: up one dir, main page]

Skip to content

Commit 65be3fd

Browse files
revert lists
1 parent 4f4107a commit 65be3fd

File tree

9 files changed

+65
-11
lines changed

9 files changed

+65
-11
lines changed

Include/internal/pycore_ceval.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ 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);
261+
260262
PyAPI_FUNC(void) _PyObjectArray_Free(PyObject **array, PyObject **scratch);
261263

262264

Include/internal/pycore_list.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ extern "C" {
99
#endif
1010

1111
#include "pycore_freelist.h" // _PyFreeListState
12-
#include "pycore_stackref.h" // _PyStackRef
1312

1413
PyAPI_FUNC(PyObject*) _PyList_Extend(PyListObject *, PyObject *);
1514
extern void _PyList_DebugMallocStats(FILE *out);
@@ -59,7 +58,7 @@ typedef struct {
5958
PyListObject *it_seq; /* Set to NULL when iterator is exhausted */
6059
} _PyListIterObject;
6160

62-
PyAPI_FUNC(PyObject *)_PyList_FromStackSteal(_PyStackRef const *src, Py_ssize_t n);
61+
PyAPI_FUNC(PyObject *)_PyList_FromArraySteal(PyObject *const *src, Py_ssize_t n);
6362

6463
#ifdef __cplusplus
6564
}

Objects/listobject.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,7 +3183,7 @@ PyList_AsTuple(PyObject *v)
31833183
}
31843184

31853185
PyObject *
3186-
_PyList_FromStackSteal(_PyStackRef const *src, Py_ssize_t n)
3186+
_PyList_FromArraySteal(PyObject *const *src, Py_ssize_t n)
31873187
{
31883188
if (n == 0) {
31893189
return PyList_New(0);
@@ -3192,16 +3192,13 @@ _PyList_FromStackSteal(_PyStackRef const *src, Py_ssize_t n)
31923192
PyListObject *list = (PyListObject *)PyList_New(n);
31933193
if (list == NULL) {
31943194
for (Py_ssize_t i = 0; i < n; i++) {
3195-
PyStackRef_CLOSE(src[i]);
3195+
Py_DECREF(src[i]);
31963196
}
31973197
return NULL;
31983198
}
31993199

32003200
PyObject **dst = list->ob_item;
3201-
for (Py_ssize_t i = 0; i < n; i++) {
3202-
PyObject *item = PyStackRef_AsPyObjectNew(src[i]);
3203-
dst[i] = item;
3204-
}
3201+
memcpy(dst, src, n * sizeof(PyObject *));
32053202

32063203
return (PyObject *)list;
32073204
}

Python/bytecodes.c

Lines changed: 7 additions & 1 deletion
1792
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,13 @@ dummy_func(
17901790
}
17911791

1792
inst(BUILD_LIST, (values[oparg] -- list)) {
1793-
PyObject *list_o = _PyList_FromStackSteal(values, oparg);
1793+
STACKREFS_TO_PYOBJECTS_NEW(values, oparg, values_o);
1794+
if (values_o == NULL) {
1795+
DECREF_INPUTS();
1796+
ERROR_IF(true, error);
1797+
}
1798+
PyObject *list_o = _PyList_FromArraySteal(values_o, oparg);
1799+
STACKREFS_TO_PYOBJECTS_CLEANUP(values_o);
17941800
ERROR_IF(list_o == NULL, error);
17951801
list = PyStackRef_FromPyObjectSteal(list_o);
17961802
}

Python/ceval.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,25 @@ _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+
696715
void
697716
_PyObjectArray_Free(PyObject **array, PyObject **scratch)
698717
{

Python/ceval_macros.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,17 @@ 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+
467478
#ifdef Py_GIL_DISABLED
468479
#define STACKREFS_TO_PYOBJECTS_CLEANUP(NAME) \
469480
_PyObjectArray_Free(NAME, NAME##_temp);

Python/executor_cases.c.h

Lines changed: 9 additions & 1 deletion
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: 9 additions & 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@ def has_error_without_pop(op: parser.InstDef) -> bool:
424424
"Py_FatalError",
425425
"PyStackRef_IsTrue",
426426
"PyStackRef_IsFalse",
427+
"STACKREFS_TO_PYOBJECTS_NEW",
428+
"STACKREFS_TO_PYOBJECTS",
429+
"STACKREFS_TO_PYOBJECTS_CLEANUP",
430+
"_PyList_FromArraySteal",
427431
)
428432

429433
ESCAPING_FUNCTIONS = (

0 commit comments

Comments
 (0)
0