Skip to content

Commit 2cf6043

Browse files
authored
Fix assert Crash when code size is 0
I encountered a crash from the asertion line (e.g. 1240) when running a Cython generated extension module (grpc-python, which creates async def functions) under PYTHONDEBUGMODE. It appears that the co object created by Cython in this case has a zero length code bytes -- which probably made sense because there is no python bytecode. Assuming Cython is correct in reporting a non-zero sized co object in this case, I think we can short circuit the Addr* functions for zero sized co objects.
1 parent 28d91d0 commit 2cf6043

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Objects/codeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
10151015
int
10161016
PyCode_Addr2Line(PyCodeObject *co, int addrq)
10171017
{
1018-
if (addrq < 0) {
1018+
if (addrq < 0 || _PyCode_NBYTES(co)) {
10191019
return co->co_firstlineno;
10201020
}
10211021
if (co->_co_monitoring && co->_co_monitoring->lines) {
@@ -1232,7 +1232,7 @@ PyCode_Addr2Location(PyCodeObject *co, int addrq,
12321232
int *start_line, int *start_column,
12331233
int *end_line, int *end_column)
12341234
{
1235-
if (addrq < 0) {
1235+
if (addrq < 0 || _PyCode_NBYTES(co) == 0) {
12361236
*start_line = *end_line = co->co_firstlineno;
12371237
*start_column = *end_column = 0;
12381238
return 1;

0 commit comments

Comments
 (0)