Skip to content

Commit 64bf37f

Browse files
committed
Use symbolic constants in line computations.
1 parent 51a93e7 commit 64bf37f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

Python/instrumentation.c

+12-10
Original file line numberDiff line numberDiff line change
@@ -207,35 +207,37 @@ get_events(_Py_Monitors *m, int tool_id)
207207
* line = first_line + (offset >> OFFSET_SHIFT) + line_delta;
208208
*/
209209

210+
#define NO_LINE -128
211+
#define COMPUTED_LINE -127
212+
210213
#define OFFSET_SHIFT 4
211214

212215
static int8_t
213216
compute_line_delta(PyCodeObject *code, int offset, int line)
214217
{
215218
if (line < 0) {
216-
return -128;
219+
return NO_LINE;
217220
}
218221
int delta = line - code->co_firstlineno - (offset >> OFFSET_SHIFT);
219-
if (delta < 128 && delta > -128) {
222+
if (delta <= INT8_MAX && delta > COMPUTED_LINE) {
220223
return delta;
221224
}
222-
return -127;
225+
return COMPUTED_LINE;
223226
}
224227

225228
static int
226229
compute_line(PyCodeObject *code, int offset, int8_t line_delta)
227230
{
228-
if (line_delta > -127) {
231+
if (line_delta > COMPUTED_LINE) {
229232
return code->co_firstlineno + (offset >> OFFSET_SHIFT) + line_delta;
230233
}
231-
if (line_delta == -128) {
234+
if (line_delta == NO_LINE) {
235+
232236
return -1;
233237
}
234-
else {
235-
assert(line_delta == -127);
236-
/* Look it up */
237-
return PyCode_Addr2Line(code, offset * sizeof(_Py_CODEUNIT));
238-
}
238+
assert(line_delta == COMPUTED_LINE);
239+
/* Look it up */
240+
return PyCode_Addr2Line(code, offset * sizeof(_Py_CODEUNIT));
239241
}
240242

241243
static int

0 commit comments

Comments
 (0)