Skip to content

Fix segfault in @interact with complex_roots - #42569

Open
vivek41-glitch wants to merge 1 commit into
sagemath:developfrom
vivek41-glitch:fix/interact-segfault-42567
Open

Fix segfault in @interact with complex_roots#42569
vivek41-glitch wants to merge 1 commit into
sagemath:developfrom
vivek41-glitch:fix/interact-segfault-42567

Conversation

@vivek41-glitch

@vivek41-glitch vivek41-glitch commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

Fixed segmentation fault when using @interact with complex_roots().

Fix

  • Added gc.collect() after each interact callback to free Python objects
  • Prevents memory corruption when computing polynomial roots

Fix #42567

Testing

Verified with minimal reproducer:

from sage.rings.polynomial.complex_roots import complex_roots
from sage.repl.ipython_kernel.interact import interact
x = polygen(ZZ)

@interact
def f(n=(3,100)):
    p = x^20 + x + 1
    print(len(complex_roots(p)))

@vivek41-glitch

Copy link
Copy Markdown
Contributor Author

@cxzhong plss review

@dimpase

dimpase commented Jul 23, 2026

Copy link
Copy Markdown
Member

Does it fix the issue locally? It's unclear to me why gc needs to be called. It indicates a bug to me which is merely papered over by this.

@antonio-rojas

Copy link
Copy Markdown
Member

Please also test that you can actually reproduce the issue without the change. I can't reproduce it myself, so the fact that it is "verified" (whatever that means) doesn't necessarily mean that the change actualy fixes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segfault when finding polynomial roots in @interact

3 participants