Branch: Tag:

1996-08-12

1996-08-12 16:34:43 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

added stack_size variable

Rev: src/interpret.c:1.13
Rev: src/interpret.h:1.5

38:   #ifdef MMAP_NORESERV   #define USE_MMAP_FOR_STACK    - /* Fixme: just multiplying by 32 is not what we want /Hubbe */ - #define EVALUATOR_STACK_SIZE EVALUATOR_STACK_SIZE*32 +    #endif   #endif   
51:    */   struct svalue *sp; /* Current position */   struct svalue *evaluator_stack; /* Start of stack */ + int stack_size = EVALUATOR_STACK_SIZE;      /* mark stack, used to store markers into the normal stack */   struct svalue **mark_sp; /* Current position */
81:      #define MMALLOC(X,Y) (Y *)mmap(0,X*sizeof(Y),PROT_READ|PROT_WRITE, MAP_NORESERV | MAP_PRIVATE | MAP_ANONYMOUS, fd, 0)    -  evaluator_stack=MMALLOC(EVALUATOR_STACK_SIZE,struct svalue); -  mark_stack=MMALLOC(EVALUATOR_STACK_SIZE, struct svalue *); +  evaluator_stack=MMALLOC(stack_size,struct svalue); +  mark_stack=MMALLOC(stack_size, struct svalue *);       if(fd != -1) close(fd);       if(!evaluator_stack || !mark_sp) fatal("Failed to mmap() stack space.\n");   #else -  evaluator_stack=(struct svalue *)malloc(EVALUATOR_STACK_SIZE*sizeof(struct svalue)); -  mark_stack=(struct svalue **)malloc(EVALUATOR_STACK_SIZE*sizeof(struct svalue *)); +  evaluator_stack=(struct svalue *)malloc(stack_size*sizeof(struct svalue)); +  mark_stack=(struct svalue **)malloc(stack_size*sizeof(struct svalue *));   #endif    sp=evaluator_stack;    mark_sp=mark_stack;
101:      void check_stack(INT32 size)   { -  if(sp - evaluator_stack + size >= EVALUATOR_STACK_SIZE) +  if(sp - evaluator_stack + size >= stack_size)    error("Stack overflow.\n");   }      void check_mark_stack(INT32 size)   { -  if(mark_sp - mark_stack + size >= EVALUATOR_STACK_SIZE) +  if(mark_sp - mark_stack + size >= stack_size)    error("Stack overflow.\n");   }   
423: Inside #if defined(DEBUG)
   if(sp<evaluator_stack || mark_sp < mark_stack || fp->locals>sp)    fatal("Stack error (generic).\n");    -  if(sp > evaluator_stack+EVALUATOR_STACK_SIZE) +  if(sp > evaluator_stack+stack_size)    fatal("Stack error (overflow).\n");       if(fp->fun>=0 && fp->current_object->prog &&
455: Inside #if defined(DEBUG)
   set_nonblocking(2,0);       file=get_line(pc-1,fp->context.prog,&linep); -  while((f=strchr(file,'/'))) file=f+1; +  while((f=STRCHR(file,'/'))) file=f+1;    fprintf(stderr,"- %s:%4ld:(%lx): %-25s %4ld %4ld\n",    file,(long)linep,    (long)(pc-fp->context.prog->program-1),
1131: Inside #if defined(DEBUG)
   if(fp && fp->pc)    {    file=get_line(fp->pc,fp->context.prog,&linep); -  while((f=strchr(file,'/'))) file=f+1; +  while((f=STRCHR(file,'/'))) file=f+1;    }else{    linep=0;    file="-";
1171:       if(function->flags & IDENTIFIER_C_FUNCTION)    { - #if 0 -  function->func.c_fun(args); - #else -  (*function->func.c_fun)(args); + #ifdef DEBUG +  if(d_flag) check_signals();   #endif -  +  (*function->func.c_fun)(args);    }else{    int num_args;    int num_locals;
1352: Inside #if defined(DEBUG)
   if(fp && fp->pc)    {    file=get_line(fp->pc,fp->context.prog,&linep); -  while((f=strchr(file,'/'))) file=f+1; +  while((f=STRCHR(file,'/'))) file=f+1;    }else{    linep=0;    file="-";
1463: Inside #if defined(DEBUG)
      debug_check_stack();    -  if(sp > &(evaluator_stack[EVALUATOR_STACK_SIZE])) +  if(sp > &(evaluator_stack[stack_size]))    fatal("Stack overflow\n");    -  if(mark_sp > &(mark_stack[EVALUATOR_STACK_SIZE])) +  if(mark_sp > &(mark_stack[stack_size]))    fatal("Mark stack overflow.\n");       if(mark_sp < mark_stack)
1483: Inside #if defined(DEBUG)
   s=*m;    }    -  if(s > &(evaluator_stack[EVALUATOR_STACK_SIZE])) +  if(s > &(evaluator_stack[stack_size]))    fatal("Mark stack exceeds svalue stack\n");       for(f=fp;f;f=f->parent_frame)    { -  +  if(f->locals) +  {    if(f->locals < evaluator_stack || -  f->locals > &(evaluator_stack[EVALUATOR_STACK_SIZE])) +  f->locals > &(evaluator_stack[stack_size]))    fatal("Local variable pointer points to Finspång.\n");    -  if(f->args < 0 || f->args > EVALUATOR_STACK_SIZE) +  if(f->args < 0 || f->args > stack_size)    fatal("FEL FEL FEL! HELP!! (corrupted frame)\n");    }    } -  + }   #endif      void cleanup_interpret()
1525:    reset_evaluator();      #ifdef USE_MMAP_FOR_STACK -  munmap((char *)evaluator_stack, EVALUATOR_STACK_SIZE*sizeof(struct svalue)); -  munmap((char *)mark_stack, EVALUATOR_STACK_SIZE*sizeof(struct svalue *)); +  munmap((char *)evaluator_stack, stack_size*sizeof(struct svalue)); +  munmap((char *)mark_stack, stack_size*sizeof(struct svalue *));   #else    free((char *)evaluator_stack);    free((char *)mark_stack);   #endif      }