]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45355: More use of sizeof(_Py_CODEUNIT) (GH-28720)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 4 Oct 2021 11:11:26 +0000 (14:11 +0300)
committerGitHub <noreply@github.com>
Mon, 4 Oct 2021 11:11:26 +0000 (14:11 +0300)
Objects/codeobject.c
Objects/frameobject.c
Python/compile.c

index ad8f13a781b94af47927a2469db7643d5b420a95..8de5c4d9c8a9d75d58e507a93f040e2f49749c07 100644 (file)
@@ -656,15 +656,13 @@ _PyCode_Addr2Offset(PyCodeObject* co, int addrq)
     if (co->co_columntable == Py_None || addrq < 0) {
         return -1;
     }
-    if (addrq % 2 == 1) {
-        --addrq;
-    }
-    if (addrq >= PyBytes_GET_SIZE(co->co_columntable)) {
+    addrq /= sizeof(_Py_CODEUNIT);
+    if (addrq*2 >= PyBytes_GET_SIZE(co->co_columntable)) {
         return -1;
     }
 
     unsigned char* bytes = (unsigned char*)PyBytes_AS_STRING(co->co_columntable);
-    return bytes[addrq] - 1;
+    return bytes[addrq*2] - 1;
 }
 
 int
@@ -673,15 +671,13 @@ _PyCode_Addr2EndOffset(PyCodeObject* co, int addrq)
     if (co->co_columntable == Py_None || addrq < 0) {
         return -1;
     }
-    if (addrq % 2 == 0) {
-        ++addrq;
-    }
-    if (addrq >= PyBytes_GET_SIZE(co->co_columntable)) {
+    addrq /= sizeof(_Py_CODEUNIT);
+    if (addrq*2+1 >= PyBytes_GET_SIZE(co->co_columntable)) {
         return -1;
     }
 
     unsigned char* bytes = (unsigned char*)PyBytes_AS_STRING(co->co_columntable);
-    return bytes[addrq] - 1;
+    return bytes[addrq*2+1] - 1;
 }
 
 void
index b743dc72eee790e7ef29f42aa62137c06a044bf4..e4c16de66211d00811115d8fa81437366648a951 100644 (file)
@@ -373,8 +373,8 @@ marklines(PyCodeObject *code, int len)
     }
 
     while (PyLineTable_NextAddressRange(&bounds)) {
-        assert(bounds.ar_start/2 < len);
-        linestarts[bounds.ar_start/2] = bounds.ar_line;
+        assert(bounds.ar_start/(int)sizeof(_Py_CODEUNIT) < len);
+        linestarts[bounds.ar_start/sizeof(_Py_CODEUNIT)] = bounds.ar_line;
     }
     return linestarts;
 }
index fdc2ce61a8e0353b896926095e828cd95286b668..694da29b771d07b65e0ded8686d781ca8d9a4dcd 100644 (file)
@@ -7081,7 +7081,7 @@ assemble_line_range(struct assembler* a, int current, PyObject** table,
                     int* prev, int* start, int* offset)
 {
     int ldelta, bdelta;
-    bdelta = (a->a_offset - *start) * 2;
+    bdelta = (a->a_offset - *start) * sizeof(_Py_CODEUNIT);
     if (bdelta == 0) {
         return 1;
     }