Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segfault on Graph().connected_component_containing_vertex('') #11942

Closed
kini opened this issue Oct 21, 2011 · 41 comments
Closed

segfault on Graph().connected_component_containing_vertex('') #11942

kini opened this issue Oct 21, 2011 · 41 comments

Comments

@kini
Copy link
Collaborator

kini commented Oct 21, 2011

As title.

fs@zhenghe /tmp $ sage -c "Graph().connected_component_containing_vertex('')"
/opt/sage/local/lib/libcsage.so(print_backtrace+0x31)[0x7f14e1a96df2]
/opt/sage/local/lib/libcsage.so(sigdie+0x14)[0x7f14e1a96e24]
/opt/sage/local/lib/libcsage.so(sage_signal_handler+0x20c)[0x7f14e1a96a72]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xf020)[0x7f14e31fa020]
/opt/sage/local/lib/python2.6/site-packages/sage/graphs/base/c_graph.so(+0x11aa1)[0x7f14be4d8aa1]
/opt/sage/local/lib/libpython2.6.so.1.0(+0x75876)[0x7f14e347c876]
/opt/sage/local/lib/libpython2.6.so.1.0(+0x75b92)[0x7f14e347cb92]
/opt/sage/local/lib/libpython2.6.so.1.0(+0xa0f08)[0x7f14e34a7f08]
/opt/sage/local/lib/libpython2.6.so.1.0(PyObject_Call+0x53)[0x7f14e3451cd3]
/opt/sage/local/lib/libpython2.6.so.1.0(PyEval_EvalFrameEx+0x395d)[0x7f14e34e835d]
/opt/sage/local/lib/libpython2.6.so.1.0(PyEval_EvalFrameEx+0x602d)[0x7f14e34eaa2d]
/opt/sage/local/lib/libpython2.6.so.1.0(PyEval_EvalCodeEx+0x879)[0x7f14e34eb549]
/opt/sage/local/lib/libpython2.6.so.1.0(PyEval_EvalCode+0x32)[0x7f14e34eb642]
/opt/sage/local/lib/libpython2.6.so.1.0(+0xdb07e)[0x7f14e34e207e]
/opt/sage/local/lib/libpython2.6.so.1.0(PyEval_EvalFrameEx+0x4f8d)[0x7f14e34e998d]
/opt/sage/local/lib/libpython2.6.so.1.0(PyEval_EvalCodeEx+0x879)[0x7f14e34eb549]
/opt/sage/local/lib/libpython2.6.so.1.0(PyEval_EvalCode+0x32)[0x7f14e34eb642]
/opt/sage/local/lib/libpython2.6.so.1.0(PyRun_FileExFlags+0xb0)[0x7f14e350d9b0]
/opt/sage/local/lib/libpython2.6.so.1.0(PyRun_SimpleFileExFlags+0xdf)[0x7f14e350e3ef]
/opt/sage/local/lib/libpython2.6.so.1.0(Py_Main+0xb23)[0x7f14e351b693]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xfd)[0x7f14e27fcead]
python[0x4006a1]

------------------------------------------------------------------------
Unhandled SIGSEGV: A segmentation fault occurred in Sage.
This probably occurred because a *compiled* component of Sage has a bug
in it and is not properly wrapped with sig_on(), sig_off(). You might
want to run Sage under gdb with 'sage -gdb' to debug this.
Sage will now terminate.
------------------------------------------------------------------------
/opt/sage/local/bin/sage-sage: line 772: 19065 Segmentation fault      sage-eval "$@"
fs@zhenghe /tmp $ 

Apply:

  1. attachment: trac_11942.patch
  2. attachment: trac_11942-exceptions.2.patch

Component: graph theory

Keywords: segfault cython

Author: Nathann Cohen, Keshav Kini, Jeroen Demeyer

Reviewer: Keshav Kini, David Coudert, Nathann Cohen

Merged: sage-5.0.beta0

Issue created by migration from https://trac.sagemath.org/ticket/11942

@nathanncohen

This comment has been minimized.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Oct 21, 2011

Author: Nathann Cohen

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Oct 21, 2011

comment:1

Right ! :-p

This comes from an unchecked operation at the beginning of BFS/DFS. Fixed in the following patch :-)

Nathann

@nathanncohen nathanncohen mannequin added the s: needs review label Oct 21, 2011
@kini
Copy link
Collaborator Author

kini commented Oct 22, 2011

Reviewer: Keshav Kini

@kini
Copy link
Collaborator Author

kini commented Oct 22, 2011

comment:2

Wow, that was fast! :D I have a couple of questions, though. Graph().connected_component_containing_vertex(0) already produces an exception, which includes the number 0 in the message. This is still true with your patch. Currently investigating why...

Also, your exception is a ValueError - shouldn't it be a KeyError? Shouldn't the current error for vertex 0 be a KeyError too instead of a (!?) RuntimeError? The Python docs say:

This exception is mostly a relic from a previous version of the interpreter; it is not used very much any more.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Oct 27, 2011

comment:3

Hellooooooo !

This exception is mostly a relic from a previous version of the interpreter; it is not used very much any more.

Oh ? That's a pity, I really use it a lot :-)

I immediately update the patch to return a KeyError :-)

Nathann

@kini
Copy link
Collaborator Author

kini commented Oct 27, 2011

comment:4

Oh, ValueError is still used a lot but it is RuntimeError which is not used much anymore.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Oct 27, 2011

comment:5

Oh, ValueError is still used a lot but it is RuntimeError which is not used much anymore.

Argggggg !!!

Patch reverted to the former one :-D

Nathann

@kini
Copy link
Collaborator Author

kini commented Oct 27, 2011

comment:6

Attachment: trac_11942.patch.gz

... but... even though ValueError is used a lot, the correct one to use here is KeyError... D:

Anyway don't worry about it, I'll do that in another patch later :) Sorry, didn't get much time to look at this earlier this week.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Oct 27, 2011

comment:7

Replying to @kini:

... but... even though ValueError is used a lot, the correct one to use here is KeyError... D:

Arggggggggggg !!!

Anyway don't worry about it, I'll do that in another patch later :) Sorry, didn't get much time to look at this earlier this week.

Good !! THaaaaanks ! :-)

Nathann

@jdemeyer
Copy link

jdemeyer commented Nov 3, 2011

Milestone sage-4.7.3 deleted

@jdemeyer jdemeyer removed this from the sage-4.8 milestone Nov 3, 2011
@dcoudert
Copy link
Contributor

Changed reviewer from Keshav Kini to Keshav Kini, David Coudert

@dcoudert
Copy link
Contributor

comment:9

I don't understand why you have both stopped the discussion without concluding on the status of this patch.

I have no problem when installing the patch and building the documentation.
The function tests correctly that the parameter is or is not a vertex of the graph.

For me the patch is correct, so I give a positive review.

Best,
David.

@dcoudert dcoudert added this to the sage-4.8 milestone Dec 10, 2011
@kini
Copy link
Collaborator Author

kini commented Dec 10, 2011

comment:10

Please read the comments. The ValueError needs to be changed to KeyError, and also I wanted to understand the following before giving it a positive review, as possibly the fix could be improved (multiple code paths for a single purpose is bad design):

Graph().connected_component_containing_vertex(0) already produces an exception, which includes the number 0 in the message. This is still true with your patch.

Sorry for neglecting this ticket for so long.

@kini
Copy link
Collaborator Author

kini commented Jan 4, 2012

Changed keywords from none to segfault cython

@kini
Copy link
Collaborator Author

kini commented Jan 4, 2012

comment:11

Well, I'm still not sure about the multiple code paths. But here is a patch to use better exceptions throughout the file in question, though that's sort of tangential to the original purpose of the ticket. This ticket has been sitting around too long for me to delay it any further just because of my ignorance of the Cython graphs code, especially since it fixes a segfault, so I will give a positive review to Nathann's part. Maybe someone can review my exceptions patch? It passes make ptestlong on my machine fwiw.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jan 5, 2012

Changed reviewer from Keshav Kini, David Coudert to Keshav Kini, David Coudert, Nathann Cohen

@kini
Copy link
Collaborator Author

kini commented Jan 5, 2012

comment:20

Hurrah! Thanks for the review (and the original patch)!

BTW, I botched that 2001 quote above... it should be "I'm sorry, Dave, I'm afraid I can't do that", of course :P

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jan 5, 2012

comment:21

BTW, I botched that 2001 quote above... it should be "I'm sorry, Dave, I'm afraid I can't do that", of course :P

No harm done, we both watched the french version of it :-D

@jdemeyer jdemeyer modified the milestones: sage-4.8, sage-5.0 Jan 5, 2012
@jdemeyer
Copy link

jdemeyer commented Jan 5, 2012

Use LookupError instead of ValueError or KeyError

@jdemeyer
Copy link

jdemeyer commented Jan 5, 2012

Changed author from Nathann Cohen, Keshav Kini to Nathann Cohen, Keshav Kini, Jeroen Demeyer

@jdemeyer
Copy link

jdemeyer commented Jan 5, 2012

comment:23

Attachment: trac_11942-exceptions.2.patch.gz

Since KeyError is specifically about dicts, I think the more general LookupError is better. Needs review.

@jdemeyer

This comment has been minimized.

@kini
Copy link
Collaborator Author

kini commented Jan 5, 2012

comment:25

Oh, I was under the impression that those base classes shouldn't be instantiated, but that seems to be unfounded after reading the docs. Looks good to me! Lines 855-856 of $SAGE_ROOT/devel/sage/sage/graphs/base/graph_backends.py contains another exception which seems like it should be a LookupError but I'm not sure I understand why the current exception is imported from !NetworkX. Maybe there is a good reason for it?

@kini kini modified the milestones: sage-5.0, sage-4.8 Jan 5, 2012
@kini
Copy link
Collaborator Author

kini commented Jan 5, 2012

comment:26

Whoops, didn't mean to change the milestone.

@kini kini modified the milestones: sage-4.8, sage-5.0 Jan 5, 2012
@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jan 5, 2012

comment:27

Well, these lines are contained in the NetworkX backend, so it may mean that they define their own Exceptions in the NetworkX project. I do not think this class is still used in Sage anyway.

Nathann

@kini
Copy link
Collaborator Author

kini commented Jan 5, 2012

comment:28

But didn't Sage developers write that NetworkX backend wrapper? Well, never mind, if it's not used in Sage anymore.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jan 5, 2012

comment:29

Well yes, and that's most probably this class. But if you run some code made for NetworkX on a Sage graph with our own exception it may break the NetworkX code. I guess this was the point of importing exceptions. Thank you for the patch Jeroen !

Nathann

@kini
Copy link
Collaborator Author

kini commented Jan 5, 2012

comment:30

Replying to @nathanncohen:

if you run some code made for NetworkX on a Sage graph

Aha, now I get it. And yes, thanks Jeroen :)

@jdemeyer
Copy link

Merged: sage-5.0.beta0

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

No branches or pull requests

4 participants