]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-127411: Fix invalid conversion of load of TLBC array when compiled in C++ (#127466)
authormpage <mpage@meta.com>
Mon, 2 Dec 2024 18:13:30 +0000 (10:13 -0800)
committerGitHub <noreply@github.com>
Mon, 2 Dec 2024 18:13:30 +0000 (10:13 -0800)
Cast the result of the load to the correct type

Include/internal/pycore_code.h
Include/internal/pycore_frame.h

index a0acf76db6f04d15e33779a861bbb412ad704f03..d607a54aa4a2f5b376d293db618e63071729d0ad 100644 (file)
@@ -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];
index b786c5f49e9831fce38f3c9c80c2c9cd554549f7..96ae4dd22ecb43a51a6274182892326dddd56ae1 100644 (file)
@@ -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