Closed
Description
Bug report
This comes from a recently discovered SymPy issue: sympy/sympy#23690
The following code fails in CPython 3.10 or newer for large N apparently due to the changes in #25403 (CC @markshannon):
#!/usr/bin/env python3
template = """\
def %(name)s(A, B):
(%(A)s,) = A
(%(B)s,) = B
return (%(AB)s,)
"""
def make_function(N):
name = "monomial_mul"
A = [f"a{i}" for i in range(N)]
B = [f"b{i}" for i in range(N)]
AB = [ "%s + %s" % (a, b) for a, b in zip(A, B) ]
code = template % dict(name=name, A=", ".join(A), B=", ".join(B), AB=", ".join(AB))
ns = {}
exec(code, ns)
return ns["monomial_mul"]
if __name__ == "__main__":
from sys import argv
make_function(int(argv[1]))
In CPython 3.9 or older this can run fine albeit slow for large values of N
(I tested 100000).
With CPython 3.10 or current main (3.11b3) this will fail with SystemError for any N
greater than 3000:
$ ./python test.py 3000
$ ./python test.py 3001
Traceback (most recent call last):
File "/home/oscar/current/sympy/cpython/test.py", line 22, in <module>
make_function(int(argv[1]))
File "/home/oscar/current/sympy/cpython/test.py", line 17, in make_function
exec(code, ns)
SystemError: excessive stack use: stack is 3001 deep
I wasn't sure that this was a deliberate effect of the changes or if it should definitely be considered a bug but the comment added in #25403 indicates that it should be:
Lines 49 to 71 in c0453a4
Your environment
Tested on Ubuntu with a range of Python versions.