Loading ...
Sorry, an error occurred while loading the content.

Re: VIM crashes in one extreme situation

Expand Messages
  • Bram Moolenaar
    ... I just tried using longjmp() yesterday. That works, but the problem is that we need to get a signal for the out-of-stack situation, so that we can jump
    Message 1 of 19 , Mar 1, 2005
    • 0 Attachment
      Alejandro Lopez Valencia wrote:

      > Bram Moolenaar wrote:
      > > Mathias Michaelis wrote:
      > >>If I do a :version I get among other things
      > >>
      > >>compiled: gcc -O3 -fomit ...
      > >>linked: gcc -s -o gvim.exe ...
      > >
      > >
      > > That explains why __try isn't used. From os_win32.h:
      > >
      > > #if defined(_MSC_VER) || defined(__BORLANDC__)
      > > /* Support for __try / __except. All versions of MSVC and Borland C are
      > > * expected to have this. Any other compilers that support it? */
      > > # define HAVE_TRY_EXCEPT 1
      > >
      > > Assuming that gcc doesn't support __try, we can maybe use longjmp()?
      > > The code currently is in os_unix.c, it could be moved to a common file.
      > > Someone who wants to try this? First check if the setjmp.h include file
      > > exists.
      >
      > Yes. Mingw supports longjmp(), at least the runtime version I have
      > available (the latest, btw). I can't commit to move the longjmp code to
      > a different file soon, but I'll try (if anyone beats me to it, please do
      > and receive my eternal gratitude :-).

      I just tried using longjmp() yesterday. That works, but the problem is
      that we need to get a signal for the out-of-stack situation, so that we
      can jump somewhere. But we don't seem to have a chance to catch the
      signal. At least, I could not see it happen.

      I looked around for another solution and found some code to simulate
      __try with MingW. It is using assembly code... There is also __try1
      and __except1 in the MingW header files, but they do not do everything
      we need.

      I included it in the latest snapshot, but it's disabled. It worked
      sometimes, but at least not when the optimizer was enabled. The code is
      in src/regexp.c. Define MINGW_TRY to try out the code.

      The examples I found with this mechanism are around very simple code.
      We do recursive function calls. That might be the reason it doesn't
      work for Vim.

      If someone has good ideas how to make this work reliably, let's hear it!
      Otherwise the only solution is to compile with MSVC.

      --
      hundred-and-one symptoms of being an internet addict:
      264. You turn to the teletext page "surfing report" and are surprised that it
      is about sizes of waves and a weather forecast for seaside resorts.

      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
      /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
      \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
      \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html ///
    • George V. Reilly
      ... Unbounded recursion is a really bad idea. (I assume that s the underlying problem.) Why not explicitly manage the recursion state on a custom stack,
      Message 2 of 19 , Mar 1, 2005
      • 0 Attachment
        Bram Moolenaar wrote:

        >The examples I found with this mechanism are around very simple code.
        >We do recursive function calls. That might be the reason it doesn't
        >work for Vim.
        >
        >If someone has good ideas how to make this work reliably, let's hear it!
        >Otherwise the only solution is to compile with MSVC.
        >
        >

        Unbounded recursion is a really bad idea. (I assume that's the
        underlying problem.) Why not explicitly manage the recursion state on a
        custom stack, instead of implicitly on the system stack?

        --
        George V. Reilly george@...
        America is the only nation in history which miraculously has gone
        directly from barbarism to degeneration without the usual interval
        of civilization.
        -- George Clemenceau (1841-1929)
        -- Oscar Wilde (1854-1900)
        (Get Witty Auto-Generated Signatures from http://SmartBee.org)
      • Bram Moolenaar
        ... We would still run out of stack. Or do you mean that we would know how large the stack is and we can check that it s almost full? We actually already
        Message 3 of 19 , Mar 1, 2005
        • 0 Attachment
          George Reilly wrote:

          > Bram Moolenaar wrote:
          >
          > >The examples I found with this mechanism are around very simple code.
          > >We do recursive function calls. That might be the reason it doesn't
          > >work for Vim.
          > >
          > >If someone has good ideas how to make this work reliably, let's hear it!
          > >Otherwise the only solution is to compile with MSVC.
          >
          > Unbounded recursion is a really bad idea. (I assume that's the
          > underlying problem.) Why not explicitly manage the recursion state on a
          > custom stack, instead of implicitly on the system stack?

          We would still run out of stack. Or do you mean that we would know how
          large the stack is and we can check that it's almost full? We actually
          already have code for that: mch_stackcheck(). But it can only be used
          if we know how big the stack is, therefore it's only used when
          getrlimit() is present.

          Thus if you know a way to figure out the size of the stack, we can use
          that solution.

          An ever better solution would be to change the regexp code from using
          recursive calls to a linear approach. But that means rewriting most of
          the complex regexp code...

          --
          GALAHAD: Camelot ...
          LAUNCELOT: Camelot ...
          GAWAIN: It's only a model.
          "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

          /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
          /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
          \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
          \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html ///
        Your message has been successfully submitted and would be delivered to recipients shortly.