Skip to content

Fix segfault in @interact with complex_roots - #42569

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

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.

@cxzhong

cxzhong commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

It is a bug in cypari2, so I close the PR here

@dimpase

dimpase commented Aug 13, 2026

Copy link
Copy Markdown
Member

do you have a reproducer of this in cypari2?

@cxzhong

cxzhong commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

do you have a reproducer of this in cypari2?

#42567 (comment)

@dimpase

dimpase commented Aug 13, 2026

Copy link
Copy Markdown
Member

do you have a reproducer of this in cypari2?

#42567 (comment)

I meant a reproducer which does not need Sage

@cxzhong

cxzhong commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

The origin issue example is still vaild.
sagemath/cypari2#107

@dimpase

dimpase commented Aug 13, 2026

Copy link
Copy Markdown
Member

The origin issue example is still vaild. sagemath/cypari2#107

so sagemath/cypari2#215
is the fix?

@cxzhong

cxzhong commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

The origin issue example is still vaild. sagemath/cypari2#107

so sagemath/cypari2#215
is the fix?

It fixes the origin cases

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segfault when finding polynomial roots in @interact

4 participants