pari_close causing segfault

31 views
Skip to first unread message

Jason Grout

unread,
Sep 13, 2012, 11:37:28 AM9/13/12
to sage-...@googlegroups.com
I've rewritten the code for moving to the new IPython to make it more
flexible, and I'm running into a puzzling problem. When I call
quit_sage from an exit handler, for some reason the pari_close() call
happening inside the pari._unsafe_deallocate_pari_stack function causes
a segfault. This only happens (in my testing) when all of the following
are true:

* the exit handler is called in a particular way (triggered from the
IPython shutdown hook)

* sage is doctesting a file that creates an IPython test shell. When
running the doctests with gdb, after all of the doctests are done, the
program segfaults and gdb reports this error:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000011
0x000000010156dac8 in pari_close ()
(gdb) where
#0 0x000000010156dac8 in pari_close ()
#1 0x0000000102bf0bd7 in
__pyx_pw_4sage_4libs_4pari_3gen_12PariInstance_3_unsafe_deallocate_pari_stack
(__pyx_v_self=<value temporarily unavailable, due to optimizations>,
unused=<value temporarily unavailable, due to optimizations>) at
sage/libs/pari/gen.c:46888
Previous frame inner to this frame (gdb could not unwind past this frame)

I realize this is really vague, so I might need to put up more details
or the code. But I'm curious at this point if someone has even a clue
about what might be happening. What would cause an error like I'm seeing?

Thanks,

Jason

P.S. This is what I'm seeing when I doctest:

% sage -t interpreter.py
sage -t "devel/sage-main/sage/misc/interpreter.py"
The doctested process was killed by signal 11
[5.8 s]

----------------------------------------------------------------------
The following tests failed:


sage -t "devel/sage-main/sage/misc/interpreter.py" # Killed/crashed
Total time for all tests: 5.8 seconds

Simon King

unread,
Sep 13, 2012, 11:56:30 AM9/13/12
to sage-...@googlegroups.com
Hi Jason,

On 2012-09-13, Jason Grout <jason...@creativetrax.com> wrote:
> I've rewritten the code for moving to the new IPython to make it more
> flexible, and I'm running into a puzzling problem. When I call
> quit_sage from an exit handler, for some reason the pari_close() call
> happening inside the pari._unsafe_deallocate_pari_stack function causes
> a segfault.

I've met the same problem, and I my suggestion for a solution is at
#12215 (second patch): Simply rename _unsafe_deallocate_pari_stack into
__dealloc__, and remove the explicit call to
_unsafe_deallocate_pari_stack in sage.all.quit_sage.

I think that's the cleanest solution: As usual with Cython, if you
have C data that need to be freed when the object is deleted, then do so
in __dealloc__. When a (or actually *the unique*) pari
instance becomes garbage collected (or when quitting Sage), then
__dealloc__ is called anyway - there is absolutely no need to manually
deallocate.

The problem with #12215 is that it depends on #715 and #11521, which are
uncovering a problem in libsingular/omalloc that results in a
segmentation fault on bsd.math -- see #13447.

So, it might be a good idea to fix the pari problem independent of all
the memleak fixes in #715 and #11521, if it turns out that pari
deallocation is troublesome in other contexts as well.

Cheers,
Simon


Reply all
Reply to author
Forward
0 new messages