Skip to content

Commit 4ea0388

Browse files
committed
Fix negative f_lasti on Python 3.10
1 parent ed1262e commit 4ea0388

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

pythoncapi_compat.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ PyFrame_GetLasti(PyFrameObject *frame)
251251
// bpo-27129: Since Python 3.10.0a7, f_lasti is an instruction offset,
252252
// not a bytes offset anymore. Python uses 16-bit "wordcode" (2 bytes)
253253
// instructions.
254+
if (frame->f_lasti < 0) {
255+
return -1;
256+
}
254257
return frame->f_lasti * 2;
255258
#else
256259
return frame->f_lasti;

0 commit comments

Comments
 (0)