I have an issue with running following code compiled by cython.
import decimal
async def fo():
a = decimal.Decimal(1)
b = decimal.Decimal(0)
return min(a - b, 0)
This file was compiled with cython cython smth.py -3
Then compiled it with gcc -shared -pthread -fPIC -I/usr/include/python3.8/ smth.c
gcc version is 9.2.0
When you import the module and run coroutine fo, like this:
import asyncio
from smth import fo
async def foo():
a = await fo()
print(a)
asyncio.get_event_loop().run_until_complete(foo())
Python segfaults.
This issue is caused by return min(a - b, 0) and is also valid for return max(a - b, 0)
If I split the code like
x = min(a - b, 0)
return x
Then the problem is not present
Having the same issue on ubuntu 16.04
I see a duplicated DECREF() being generated for the temporary variable that holds the return value. That explains the crash.
__pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
Thanks for the detailed report.
Most helpful comment
Thanks for the detailed report.