Branch: Tag:

2006-02-27

2006-02-27 12:07:10 by Martin Stjernholm <mast@lysator.liu.se>

Avoid C stack recursion in catch blocks.

Rev: src/docode.c:1.185
Rev: src/error.c:1.144
Rev: src/interpret.c:1.368
Rev: src/interpret.h:1.165
Rev: src/interpret_functions.h:1.187
Rev: src/pike_embed.c:1.7
Rev: src/pike_error.h:1.37
Rev: src/version.h:1.383

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: error.c,v 1.143 2004/12/22 18:46:15 grubba Exp $ + || $Id: error.c,v 1.144 2006/02/27 12:07:10 mast Exp $   */      #define NO_PIKE_SHORTHAND
63: Inside #if defined(PIKE_DEBUG)
  {    char foo;   #define TESTILITEST ((((char *)Pike_interpreter.recoveries)-((char *)&foo))*STACK_DIRECTION) -  if(Pike_interpreter.recoveries && TESTILITEST > 0) { +  if(Pike_interpreter.recoveries && +  Pike_interpreter.recoveries->on_stack && +  TESTILITEST > 0) {    fprintf(stderr, "Recoveries is out biking (Pike_interpreter.recoveries=%p, Pike_sp=%p, %ld)!\n",    Pike_interpreter.recoveries, &foo,    DO_NOT_WARN((long)TESTILITEST));
83:    pop_n_elems(args);   }    - PMOD_EXPORT JMP_BUF *init_recovery(JMP_BUF *r, size_t stack_pop_levels DEBUG_LINE_ARGS) + PMOD_EXPORT JMP_BUF *init_recovery(JMP_BUF *r, size_t stack_pop_levels DEBUG_INIT_REC_ARGS)   {    check_recovery_context();   #ifdef PIKE_DEBUG    r->file=location;    OED_FPRINTF((stderr, "init_recovery(%p) %s\n", r, location)); -  +  r->on_stack = on_stack;   #endif    r->frame_pointer=Pike_fp;    r->stack_pointer=Pike_sp - stack_pop_levels - Pike_interpreter.evaluator_stack;
115:    Pike_interpreter.recoveries->onerror=Pike_interpreter.recoveries->onerror->previous;    }    +  if (Pike_interpreter.catch_ctx && +  &Pike_interpreter.catch_ctx->recovery == Pike_interpreter.recoveries) { +  struct catch_context *cc = Pike_interpreter.catch_ctx; +  Pike_interpreter.catch_ctx = cc->prev; +  really_free_catch_context (cc); +  } +     Pike_interpreter.recoveries=Pike_interpreter.recoveries->previous;    }   
158:    accept_unfinished_type_fields--;   #endif    +  if (Pike_interpreter.catch_ctx && +  &Pike_interpreter.catch_ctx->recovery == Pike_interpreter.recoveries) { +  /* This is a phony recovery made in F_CATCH that hasn't been passed +  * to LOW_SETJMP. The real jmpbuf is in catching_eval_instruction. */ + #ifdef PIKE_DEBUG +  if (!Pike_interpreter.catching_eval_jmpbuf) +  Pike_fatal ("Got phony F_CATCH recovery but no catching_eval_jmpbuf.\n"); + #endif +  LOW_LONGJMP (*Pike_interpreter.catching_eval_jmpbuf, 1); +  } +  else    LOW_LONGJMP(Pike_interpreter.recoveries->recovery,1);   }