summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-06-14 10:08:12 (GMT)
committerGitHub <noreply@github.com>2022-06-14 10:08:12 (GMT)
commit2bf74753c14e5360e04930b478703f4e2618f4a3 (patch)
treee2555ed09c5597e6457a7dae560d862ab01bcfa8 /Python/compile.c
parent4caf5c2753f1aa28d6f4bc1aa377975fd2a62331 (diff)
downloadcpython-2bf74753c14e5360e04930b478703f4e2618f4a3.zip
cpython-2bf74753c14e5360e04930b478703f4e2618f4a3.tar.gz
cpython-2bf74753c14e5360e04930b478703f4e2618f4a3.tar.bz2
GH-93662: Make sure that column offsets are correct in multi-line method calls. (GH-93673)
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c
index b922e01..93aafa7 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -4801,6 +4801,16 @@ is_import_originated(struct compiler *c, expr_ty e)
return flags & DEF_IMPORT;
}
+static void
+update_location_to_match_attr(struct compiler *c, expr_ty meth)
+{
+ if (meth->lineno != meth->end_lineno) {
+ // Make start location match attribute
+ c->u->u_lineno = meth->end_lineno;
+ c->u->u_col_offset = meth->end_col_offset - (int)PyUnicode_GetLength(meth->v.Attribute.attr)-1;
+ }
+}
+
// Return 1 if the method call was optimized, -1 if not, and 0 on error.
static int
maybe_optimize_method_call(struct compiler *c, expr_ty e)
@@ -4842,8 +4852,8 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
}
/* Alright, we can optimize the code. */
VISIT(c, expr, meth->v.Attribute.value);
- int old_lineno = c->u->u_lineno;
- c->u->u_lineno = meth->end_lineno;
+ SET_LOC(c, meth);
+ update_location_to_match_attr(c, meth);
ADDOP_NAME(c, LOAD_METHOD, meth->v.Attribute.attr, names);
VISIT_SEQ(c, expr, e->v.Call.args);
@@ -4853,8 +4863,9 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
return 0;
};
}
+ SET_LOC(c, e);
+ update_location_to_match_attr(c, meth);
ADDOP_I(c, CALL, argsl + kwdsl);
- c->u->u_lineno = old_lineno;
return 1;
}
@@ -7673,6 +7684,7 @@ write_location_info_short_form(struct assembler* a, int length, int column, int
int column_low_bits = column & 7;
int column_group = column >> 3;
assert(column < 80);
+ assert(end_column >= column);
assert(end_column - column < 16);
write_location_first_byte(a, PY_CODE_LOCATION_INFO_SHORT0 + column_group, length);
write_location_byte(a, (column_low_bits << 4) | (end_column - column));
@@ -7744,7 +7756,7 @@ write_location_info_entry(struct assembler* a, struct instr* i, int isize)
}
}
else if (i->i_end_lineno == i->i_lineno) {
- if (line_delta == 0 && column < 80 && end_column - column < 16) {
+ if (line_delta == 0 && column < 80 && end_column - column < 16 && end_column >= column) {
write_location_info_short_form(a, isize, column, end_column);
return 1;
}