Skip to content

Commit b175416

Browse files
committed
Address code review
1 parent c628ffc commit b175416

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

Include/internal/pycore_tstate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ typedef struct _PyThreadStateImpl {
7878
#endif
7979

8080
#ifdef _Py_TIER2
81-
struct _PyUOpInstruction *buffer;
81+
struct _PyUOpInstruction *jit_uop_buffer;
8282
#endif
8383

8484
} _PyThreadStateImpl;

Python/optimizer.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,14 +1281,13 @@ uop_optimize(
12811281
_PyBloomFilter dependencies;
12821282
_Py_BloomFilter_Init(&dependencies);
12831283
_PyThreadStateImpl *tstate = (_PyThreadStateImpl *)_PyThreadState_GET();
1284-
if (tstate->buffer == NULL) {
1285-
tstate->buffer = (_PyUOpInstruction *)PyMem_RawMalloc(UOP_MAX_TRACE_LENGTH*sizeof(_PyUOpInstruction));
1286-
if (tstate->buffer == NULL) {
1287-
PyErr_NoMemory();
1284+
if (tstate->jit_uop_buffer == NULL) {
1285+
tstate->jit_uop_buffer = (_PyUOpInstruction *)PyMem_RawMalloc(UOP_MAX_TRACE_LENGTH*sizeof(_PyUOpInstruction));
1286+
if (tstate->jit_uop_buffer == NULL) {
12881287
return -1;
12891288
}
12901289
}
1291-
_PyUOpInstruction *buffer = tstate->buffer;
1290+
_PyUOpInstruction *buffer = tstate->jit_uop_buffer;
12921291
OPT_STAT_INC(attempts);
12931292
char *env_var = Py_GETENV("PYTHON_UOPS_OPTIMIZE");
12941293
bool is_noopt = true;

Python/pylifecycle.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -863,10 +863,6 @@ pycore_interp_init(PyThreadState *tstate)
863863
if (_tstate->c_stack_hard_limit == 0) {
864864
_Py_InitializeRecursionLimits(tstate);
865865
}
866-
#ifdef _Py_TIER2
867-
// Ensure the buffer is to be set as NULL for MSVC
868-
_tstate->buffer = NULL;
869-
#endif
870866
PyInterpreterState *interp = tstate->interp;
871867
PyStatus status;
872868
PyObject *sysmod = NULL;
@@ -1708,11 +1704,6 @@ finalize_modules(PyThreadState *tstate)
17081704
interp->jit = false;
17091705
#ifdef _Py_TIER2
17101706
_Py_Executors_InvalidateAll(interp, 0);
1711-
_PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate;
1712-
if (_tstate->buffer != NULL) {
1713-
PyMem_RawFree(_tstate->buffer);
1714-
_tstate->buffer = NULL;
1715-
}
17161707
#endif
17171708

17181709
// Stop watching __builtin__ modifications

Python/pystate.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,11 @@ new_threadstate(PyInterpreterState *interp, int whence)
15361536
}
15371537
#endif
15381538

1539+
#ifdef _Py_TIER2
1540+
// Ensure the buffer is to be set as NULL for MSVC
1541+
tstate->jit_uop_buffer = NULL;
1542+
#endif
1543+
15391544
/* We serialize concurrent creation to protect global state. */
15401545
HEAD_LOCK(interp->runtime);
15411546

@@ -1726,6 +1731,14 @@ PyThreadState_Clear(PyThreadState *tstate)
17261731
_Py_ClearTLBCIndex((_PyThreadStateImpl *)tstate);
17271732
#endif
17281733

1734+
#ifdef _Py_TIER2
1735+
_PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate;
1736+
if (_tstate->jit_uop_buffer != NULL) {
1737+
PyMem_RawFree(_tstate->jit_uop_buffer);
1738+
_tstate->jit_uop_buffer = NULL;
1739+
}
1740+
#endif
1741+
17291742
// Merge our queue of pointers to be freed into the interpreter queue.
17301743
_PyMem_AbandonDelayed(tstate);
17311744

0 commit comments

Comments
 (0)