delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/03/11/15:28:19

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
From: "John W. Eaton" <jwe AT bevo DOT che DOT wisc DOT edu>
MIME-Version: 1.0
Message-ID: <16945.65298.969435.612411@devzero.bogus.domain>
Date: Fri, 11 Mar 2005 15:26:58 -0500
To: cygwin <cygwin AT cygwin DOT com>
Subject: problem mixing C++ exceptions and setjmp/longjmp
X-CAE-MailScanner-Information: Please contact security AT engr DOT wisc DOT edu if this message contains a virus or has been corrupted in delivery.
X-CAE-MailScanner: Found to be clean (starburst)
X-IsSubscribed: yes
Note-from-DJ: This may be spam

--6iYdsVneNo
Content-Type: text/plain; charset=us-ascii
Content-Description: message body and .signature
Content-Transfer-Encoding: 7bit

I believe the following program should print

  main: calling doit
  doit: calling toit
  toit: throwing exception
  toit: caught exception, longjumping
  doit: longjump landed, throwing exception
  main: caught exception

but on the current Cygwin (updated today) using the 1.5.13-1
cygwin.dll and either gcc 3.3 or 3.4, it crashes with a segfault just
after printing the next to last line:

  doit: longjump landed, throwing exception

I tried going back to 1.5.12, but that did not fix the problem.

Can anyone reproduce this problem?

This problem affects GNU Octave, as it uses this technique to handle
interrupts in code that is a mixture of C++, C, and Fortran.  If
SIGINT arrives in a section of Octave code, the signal handler sets a
flag and then returns, letting Octave check the flag periodically.  At
some safe location, an exception is thrown that will return control
to the top level of the main interpreter loop.  If SIGINT arrives
inside some foreign code (say, readline, or some Fortran code) then
the signal handler jumps back to the location of the call to the
foreign code.  At that point, an exception is thrown to get back to
the top level.  I've not had problems with this approach until
recently when I upgraded my Cygwin installation.  Now Ctrl-C at the
prompt causes a segfault.  The program below is a distillation of the
key features of the Octave code, and shows the same problem.

Any clues?

Thanks,

jwe

-- 
www.octave.org | jwe AT octave DOT org


--6iYdsVneNo
Content-Type: text/plain
Content-Disposition: inline;
	filename="except.cc"
Content-Transfer-Encoding: 7bit

#include <setjmp.h>

#include <iostream>

jmp_buf context;

class
exception
{
  // empty;
};

static void
toit (void)
{
  try
    {
      std::cerr << "toit: throwing exception" << std::endl;
      throw exception ();
    }
  catch (exception)
    {
      std::cerr << "toit: caught exception, longjumping" << std::endl;
      longjmp (context, 1);
    }
}

static void
doit (void)
{
  if (setjmp (context) == 0)
    {
      std::cerr << "doit: calling toit" << std::endl;
      toit ();
    }
  else
    {
      std::cerr << "doit: longjump landed, throwing exception" << std::endl;
      throw exception ();
    }
}

int
main (void)
{
  try
    {
      std::cerr << "main: calling doit" << std::endl;
      doit ();
    }
  catch (exception)
    {
      std::cerr << "main: caught exception" << std::endl;
    }

  return 0;
}


--6iYdsVneNo
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
--6iYdsVneNo--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019