Skip to content

Commit 9ac430d

Browse files
push stackrefs into tstate
1 parent 3248658 commit 9ac430d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Include/internal/pycore_tstate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ struct _gc_thread_state {
2121
};
2222
#endif
2323

24+
/* How much scratch space to give stackref to PyObject* conversion. */
25+
#define MAX_STACKREF_SCRATCH 10
26+
2427
// Every PyThreadState is actually allocated as a _PyThreadStateImpl. The
2528
// PyThreadState fields are exposed as part of the C API, although most fields
2629
// are intended to be private. The _PyThreadStateImpl fields not exposed.
@@ -47,6 +50,7 @@ typedef struct _PyThreadStateImpl {
4750
struct _qsbr_thread_state *qsbr; // only used by free-threaded build
4851
struct llist_node mem_free_queue; // delayed free queue
4952

53+
PyObject *stackref_scratch[MAX_STACKREF_SCRATCH + 1];
5054
#ifdef Py_GIL_DISABLED
5155
// Stack references for the current thread that exist on the C stack
5256
struct _PyCStackRef *c_stack_refs;

Python/ceval_macros.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,19 @@ do { \
393393

394394
/* Stackref macros */
395395

396-
/* How much scratch space to give stackref to PyObject* conversion. */
397-
#define MAX_STACKREF_SCRATCH 10
398396

397+
#if Py_TAIL_CALL_INTERP && defined(_MSC_VER)
398+
#define STACKREFS_TO_PYOBJECTS(ARGS, ARG_COUNT, NAME) \
399+
/* +1 because vectorcall might use -1 to write self */ \
400+
_PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate; \
401+
PyObject **NAME##_temp = _tstate->stackref_scratch; \
402+
PyObject **NAME = _PyObjectArray_FromStackRefArray(ARGS, ARG_COUNT, NAME##_temp + 1);
403+
#else
399404
#define STACKREFS_TO_PYOBJECTS(ARGS, ARG_COUNT, NAME) \
400405
/* +1 because vectorcall might use -1 to write self */ \
401406
PyObject *NAME##_temp[MAX_STACKREF_SCRATCH+1]; \
402407
PyObject **NAME = _PyObjectArray_FromStackRefArray(ARGS, ARG_COUNT, NAME##_temp + 1);
408+
#endif
403409

404410
#define STACKREFS_TO_PYOBJECTS_CLEANUP(NAME) \
405411
/* +1 because we +1 previously */ \

0 commit comments

Comments
 (0)