From: Paul K. <pki...@ja...> - 2002-11-25 21:37:03
|
On Mon, Nov 25, 2002 at 08:35:11PM +0000, Nix wrote: > On Sun, 24 Nov 2002, Paul Kienzle said: > > The reason that won't work is because you need to something to catch it. > > But the catcher is in octave/toplev.cc; it throws right through our code > and out the other side. > > (I'm sort of assuming that our destructors do all the necessary cleanup; > if not, we'll need the occasional catch-and-rethrow ourselves.) > > Of course this code only handles errors, not interrupts. For that, see > below :) > > > That requires putting trapping code around each call to superLU to set > > the jump return address and reset it when done. Plus any loops outside > > of superLU need to have periodic checks if an interrupt has been triggered. > > ... oh, damn and blast, SuperLU is C. I didn't notice and thought it was > C++. Maybe all is not lost. I forgot that we are recompiling superlu ourselves. When I tested this a couple of years ago, I found that I could do something like: main.cc: #include <iostream> extern "C" { void throw_back(void); } extern "C" { void C_stuff(void); } class myexception {}; void throw_back(void) { throw myexception(); } int main(int argc, char *argv[]) { try { C_stuff(); std::cout << "not caught" << std::endl; } catch (myexception) { std::cout << "caught" << std::endl; } return 0; } lib.c: void C_stuff(void) { void throw_back(void); throw_back(); } Makefile: all: main.o lib.o g++ main.o lib.o -o throw_back main.o: main.cc g++ -c main.cc -o main.o lib.o: lib.c gcc -c -fexceptions lib.c -o lib.o This seems to still work. I don't know what to throw though. octave_throw_interrupt_exception() ? octave_throw_bad_alloc() ? If this works, I can push out a new octave-forge very soon, but Ctrl-C will not be responsive within superLU. For Ctrl-C we need to put OCTAVE_QUIT in all the inner loops of *.{cc,h} and wrap calls to superLU with BEGIN/END_INTERRUPT_WITH_EXCEPTIONS. At least I think that's what we are supposed to do. It's not clear how we can clean up a superLU malloc which was interrupted during initialization. I believe that's why garbage collection was invented. > > OK, C that counts as foreign code, so calls into SuperLU will require > BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE / > END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE wrapped around them. That > should let the code flow when interrupted by SIGINT within SuperLU go > > SIGINT -> signal handler in octave's src/sighandlers.cc -> > octave_jump_to_enclosing_context() -> longjmp() to the > END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE -> Octave's toplev.cc. > > > The macros to do this are in quit.h, but I don't know the exact magic. > > I think I've decrypted it. > > > Let me know if you are going to persue this, because it is top of my list > > It's top of mine too. Patch in an hour or so (this box is running rather > slowly right now, alas, and it would be inurbane for me to antinice > everyone else into oblivion). > > > (right behind family and work that is, which in this season puts it > > much too far back ;-) > > :) > > -- > `I keep hearing about SF writers dying, but I never hear about SF > writers being born. So I guess eventually there'll be none left.' > -- Keith F. Lynch > |