Skip to content

Commit c430376

Browse files
authored
gh-127411: Fix invalid conversion of load of TLBC array when compiled in C++ (#127466)
Cast the result of the load to the correct type
1 parent c46acd3 commit c430376

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Include/internal/pycore_code.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,19 @@ PyAPI_DATA(const struct _PyCode8) _Py_InitCleanup;
609609

610610
#ifdef Py_GIL_DISABLED
611611

612+
static inline _PyCodeArray *
613+
_PyCode_GetTLBCArray(PyCodeObject *co)
614+
{
615+
return _Py_STATIC_CAST(_PyCodeArray *,
616+
_Py_atomic_load_ptr_acquire(&co->co_tlbc));
617+
}
618+
612619
// Return a pointer to the thread-local bytecode for the current thread, if it
613620
// exists.
614621
static inline _Py_CODEUNIT *
615622
_PyCode_GetTLBCFast(PyThreadState *tstate, PyCodeObject *co)
616623
{
617-
_PyCodeArray *code = _Py_atomic_load_ptr_acquire(&co->co_tlbc);
624+
_PyCodeArray *code = _PyCode_GetTLBCArray(co);
618625
int32_t idx = ((_PyThreadStateImpl*) tstate)->tlbc_index;
619626
if (idx < code->size && code->entries[idx] != NULL) {
620627
return (_Py_CODEUNIT *) code->entries[idx];

Include/internal/pycore_frame.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ _PyFrame_GetBytecode(_PyInterpreterFrame *f)
9494
{
9595
#ifdef Py_GIL_DISABLED
9696
PyCodeObject *co = _PyFrame_GetCode(f);
97-
_PyCodeArray *tlbc = _Py_atomic_load_ptr_acquire(&co->co_tlbc);
97+
_PyCodeArray *tlbc = _PyCode_GetTLBCArray(co);
9898
assert(f->tlbc_index >= 0 && f->tlbc_index < tlbc->size);
9999
return (_Py_CODEUNIT *)tlbc->entries[f->tlbc_index];
100100
#else

0 commit comments

Comments
 (0)