diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2021-10-04 11:11:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-04 11:11:26 (GMT) |
commit | 252b7bcb236dc261f3af1275bc90f9a303d9648f (patch) | |
tree | e259c0287bf2b02f7998d5ec9ae00a1c80d79af1 | |
parent | 9be930f9b169fb3d92693670ae069df902709b83 (diff) | |
download | cpython-252b7bcb236dc261f3af1275bc90f9a303d9648f.zip cpython-252b7bcb236dc261f3af1275bc90f9a303d9648f.tar.gz cpython-252b7bcb236dc261f3af1275bc90f9a303d9648f.tar.bz2 |
bpo-45355: More use of sizeof(_Py_CODEUNIT) (GH-28720)
-rw-r--r-- | Objects/codeobject.c | 16 | ||||
-rw-r--r-- | Objects/frameobject.c | 4 | ||||
-rw-r--r-- | Python/compile.c | 2 |
3 files changed, 9 insertions, 13 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c index ad8f13a..8de5c4d 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -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 diff --git a/Objects/frameobject.c b/Objects/frameobject.c index b743dc7..e4c16de 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -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; } diff --git a/Python/compile.c b/Python/compile.c index fdc2ce6..694da29 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -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; } |