summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBatuhan Taskaya <batuhan@python.org>2021-07-04 18:02:16 (GMT)
committerGitHub <noreply@github.com>2021-07-04 18:02:16 (GMT)
commit44f91fc802a2b71312e9abd9e8e9dcbf02e8216d (patch)
treea4ae2ed6dc8cb896efb695abb3a1c299f10e53e5 /Objects
parentd33943a6c368c2184e238019c63ac7a267da5594 (diff)
downloadcpython-44f91fc802a2b71312e9abd9e8e9dcbf02e8216d.zip
cpython-44f91fc802a2b71312e9abd9e8e9dcbf02e8216d.tar.gz
cpython-44f91fc802a2b71312e9abd9e8e9dcbf02e8216d.tar.bz2
bpo-43950: use 0-indexed column offsets for bytecode positions (GH-27011)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/codeobject.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 6789588..aa36175 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -610,9 +610,6 @@ PyCode_Addr2Location(PyCodeObject *co, int addrq,
int *end_line, int *end_column)
{
*start_line = PyCode_Addr2Line(co, addrq);
- if (*start_line == -1) {
- *start_line = 0;
- }
*start_column = _PyCode_Addr2Offset(co, addrq);
*end_line = _PyCode_Addr2EndLine(co, addrq);
*end_column = _PyCode_Addr2EndOffset(co, addrq);
@@ -626,7 +623,7 @@ _PyCode_Addr2EndLine(PyCodeObject* co, int addrq)
return co->co_firstlineno;
}
else if (co->co_endlinetable == Py_None) {
- return 0;
+ return -1;
}
assert(addrq >= 0 && addrq < PyBytes_GET_SIZE(co->co_code));
@@ -639,34 +636,34 @@ int
_PyCode_Addr2Offset(PyCodeObject* co, int addrq)
{
if (co->co_columntable == Py_None || addrq < 0) {
- return 0;
+ return -1;
}
if (addrq % 2 == 1) {
--addrq;
}
if (addrq >= PyBytes_GET_SIZE(co->co_columntable)) {
- return 0;
+ return -1;
}
unsigned char* bytes = (unsigned char*)PyBytes_AS_STRING(co->co_columntable);
- return bytes[addrq];
+ return bytes[addrq] - 1;
}
int
_PyCode_Addr2EndOffset(PyCodeObject* co, int addrq)
{
if (co->co_columntable == Py_None || addrq < 0) {
- return 0;
+ return -1;
}
if (addrq % 2 == 0) {
++addrq;
}
if (addrq >= PyBytes_GET_SIZE(co->co_columntable)) {
- return 0;
+ return -1;
}
unsigned char* bytes = (unsigned char*)PyBytes_AS_STRING(co->co_columntable);
- return bytes[addrq];
+ return bytes[addrq] - 1;
}
void
@@ -980,7 +977,7 @@ positionsiter_dealloc(positionsiterator* pi)
static PyObject*
_source_offset_converter(int* value) {
- if (*value <= 0) {
+ if (*value == -1) {
Py_RETURN_NONE;
}
return PyLong_FromLong(*value);