summaryrefslogtreecommitdiffstats
path: root/Include/internal
diff options
context:
space:
mode:
authormpage <mpage@meta.com>2024-12-02 18:13:30 (GMT)
committerGitHub <noreply@github.com>2024-12-02 18:13:30 (GMT)
commitc4303763dac4494300e299e54c079a4a11931a55 (patch)
tree07e7f8ba1956f133c510dcc0b17ff600114dcd1a /Include/internal
parentc46acd3588864e97d0e0fe37a41aa5e94ac7af51 (diff)
downloadcpython-c4303763dac4494300e299e54c079a4a11931a55.zip
cpython-c4303763dac4494300e299e54c079a4a11931a55.tar.gz
cpython-c4303763dac4494300e299e54c079a4a11931a55.tar.bz2
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
Diffstat (limited to 'Include/internal')
-rw-r--r--Include/internal/pycore_code.h9
-rw-r--r--Include/internal/pycore_frame.h2
2 files changed, 9 insertions, 2 deletions
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index a0acf76..d607a54 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -609,12 +609,19 @@ PyAPI_DATA(const struct _PyCode8) _Py_InitCleanup;
#ifdef Py_GIL_DISABLED
+static inline _PyCodeArray *
+_PyCode_GetTLBCArray(PyCodeObject *co)
+{
+ return _Py_STATIC_CAST(_PyCodeArray *,
+ _Py_atomic_load_ptr_acquire(&co->co_tlbc));
+}
+
// Return a pointer to the thread-local bytecode for the current thread, if it
// exists.
static inline _Py_CODEUNIT *
_PyCode_GetTLBCFast(PyThreadState *tstate, PyCodeObject *co)
{
- _PyCodeArray *code = _Py_atomic_load_ptr_acquire(&co->co_tlbc);
+ _PyCodeArray *code = _PyCode_GetTLBCArray(co);
int32_t idx = ((_PyThreadStateImpl*) tstate)->tlbc_index;
if (idx < code->size && code->entries[idx] != NULL) {
return (_Py_CODEUNIT *) code->entries[idx];
diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h
index b786c5f..96ae4dd 100644
--- a/Include/internal/pycore_frame.h
+++ b/Include/internal/pycore_frame.h
@@ -94,7 +94,7 @@ _PyFrame_GetBytecode(_PyInterpreterFrame *f)
{
#ifdef Py_GIL_DISABLED
PyCodeObject *co = _PyFrame_GetCode(f);
- _PyCodeArray *tlbc = _Py_atomic_load_ptr_acquire(&co->co_tlbc);
+ _PyCodeArray *tlbc = _PyCode_GetTLBCArray(co);
assert(f->tlbc_index >= 0 && f->tlbc_index < tlbc->size);
return (_Py_CODEUNIT *)tlbc->entries[f->tlbc_index];
#else