coerce(ComplexNumber, 1+I) segfaults

17 views
Skip to first unread message

Dan Drake

unread,
Nov 14, 2011, 9:04:36 PM11/14/11
to sage-...@googlegroups.com
This is not fun:

sage: from sage.rings.complex_number import ComplexNumber as CN
sage: parent(1+I)
Symbolic Ring
sage: coerce(CN, 1+I)
BOOM

(with 4.8.alpha1 and 4.7.2 in 64-bit Linux)

It looks like mpfr is extremely unhappy about something.

Also, if I just use the regular ComplexNumber in the global namespace
with the same command, I get "TypeError: unable to coerce to a
ComplexNumber: <type 'str'>". I understand that coercion may not be able
to handle SymbolicRing stuff to complex, but that's a strange message,
especially since ComplexNumber claims that it wants strings to convert.
But for now let's just deal with the segfault.

Dan

--
--- Dan Drake
----- http://mathsci.kaist.ac.kr/~drake
-------

signature.asc

Jason Grout

unread,
Nov 14, 2011, 9:11:36 PM11/14/11
to sage-...@googlegroups.com

It looks like something bad happens also on 4.7. At least, when I try
on demo.sagenb.org (running 4.7 currently), after I do the coerce
statement above, it appears that the worksheet is abruptly reset and CN
is no longer defined.

Jason

Dan Drake

unread,
Nov 15, 2011, 12:14:09 AM11/15/11
to sage-...@googlegroups.com
On Mon, 14 Nov 2011 at 08:11PM -0600, Jason Grout wrote:
> It looks like something bad happens also on 4.7. At least, when I
> try on demo.sagenb.org (running 4.7 currently), after I do the
> coerce statement above, it appears that the worksheet is abruptly
> reset and CN is no longer defined.

I also get a segfault in: 4.6, 4.5.1, 4.4, and 4.3. That's as far back
as I have copies of Sage.

signature.asc

Dima Pasechnik

unread,
Nov 15, 2011, 1:09:05 AM11/15/11
to sage-...@googlegroups.com


On Tuesday, 15 November 2011 13:14:09 UTC+8, Dan Drake wrote:
On Mon, 14 Nov 2011 at 08:11PM -0600, Jason Grout wrote:
> It looks like something bad happens also on 4.7.  At least, when I
> try on demo.sagenb.org (running 4.7 currently), after I do the
> coerce statement above, it appears that the worksheet is abruptly
> reset and CN is no longer defined.

I also get a segfault in: 4.6, 4.5.1, 4.4, and 4.3. That's as far back
as I have copies of Sage.


I cannot reproduce segfaults on 4.7.* on MacOSX.
I get 
TypeError: unable to coerce to a ComplexNumber: <type 'str'>

Dmitrii

Justin C. Walker

unread,
Nov 15, 2011, 1:38:09 AM11/15/11
to sage-...@googlegroups.com

I get segfaults for both cases ('CN' and 'ComplexNumber') all the way back to 2.11 (I've tried most of the 4.x releases, some of the 3.x's and only one of the 2's). I don't see the "TypeError" failure in any case.

Justin

--
Justin C. Walker, Curmudgeon at Large
Institute for the Absorption of Federal Funds
--
Democracy is two wolves and a lamb
voting on what to have for lunch.
Liberty is a well-armed lamb contesting
the vote.

David Roe

unread,
Nov 15, 2011, 3:25:06 AM11/15/11
to sage-...@googlegroups.com
This is now #12038, which has a patch which eliminates the segfault.

The problem was that you shouldn't be using coerce like that: the
first argument should be a parent, not the element class. That
element class requires two inputs: both the parent and the data to
make a new element out of. In this case, the __init__ method was only
getting one input (1+I) and thus raising a TypeError. There's now no
reference to your new ComplexNumber, so it's deallocated, but the
mpfrs are only initialized in the __init__ method, which was never
called. So when you try to clear them in __dealloc__, you get a
segfault.
David

> --
> To post to this group, send an email to sage-...@googlegroups.com
> To unsubscribe from this group, send an email to sage-devel+...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/sage-devel
> URL: http://www.sagemath.org
>

Reply all
Reply to author
Forward
0 new messages