pike.git / src / interpret.c

version» Context lines:

pike.git/src/interpret.c:1:   /*   || 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: interpret.c,v 1.361 2004/12/30 13:44:20 grubba Exp $ + || $Id: interpret.c,v 1.362 2005/01/25 18:01:24 grubba Exp $   */      #include "global.h"   #include "interpret.h"   #include "object.h"   #include "program.h"   #include "svalue.h"   #include "array.h"   #include "mapping.h"   #include "pike_error.h"
pike.git/src/interpret.c:176:    * Called once with NULL to initialize tables.    *    * Returns 0 if pc is NULL.    *    * Returns -1 if the code terminated due to a RETURN.    *    * Returns -2 if the code terminated due to EXIT_CATCH or ESCAPE_CATCH.    */   static int eval_instruction(PIKE_OPCODE_T *pc);    - PMOD_EXPORT void init_interpreter(void) + PMOD_EXPORT int low_init_interpreter(struct Pike_interpreter *interpreter)   {   #ifdef USE_MMAP_FOR_STACK    static int fd = -1;    -  +    #ifndef MAP_VARIABLE   #define MAP_VARIABLE 0   #endif      #ifndef MAP_PRIVATE   #define MAP_PRIVATE 0   #endif      #ifndef MAP_FAILED   #define MAP_FAILED -1
pike.git/src/interpret.c:204:   #ifndef MAP_ANONYMOUS   #define MAP_ANONYMOUS 0    if(fd == -1)    {    while(1)    {    fd=open("/dev/zero",O_RDONLY);    if(fd >= 0) break;    if(errno != EINTR)    { -  Pike_interpreter.evaluator_stack=0; -  Pike_interpreter.mark_stack=0; +  interpreter->evaluator_stack=0; +  interpreter->mark_stack=0;    goto use_malloc;   #define NEED_USE_MALLOC_LABEL    }    }    /* Don't keep this fd on exec() */    set_close_on_exec(fd, 1);    }   #endif    - #define MMALLOC(X,Y) (Y *)mmap(0,X*sizeof(Y),PROT_READ|PROT_WRITE, MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, fd, 0) + #define MMALLOC(X,Y) \ +  (Y *)mmap(0, (X)*sizeof(Y), PROT_READ|PROT_WRITE, \ +  MAP_NORESERVE|MAP_PRIVATE|MAP_ANONYMOUS, fd, 0)    -  Pike_interpreter.evaluator_stack_malloced=0; -  Pike_interpreter.mark_stack_malloced=0; -  Pike_interpreter.evaluator_stack=MMALLOC(Pike_stack_size,struct svalue); -  Pike_interpreter.mark_stack=MMALLOC(Pike_stack_size, struct svalue *); -  if((char *)MAP_FAILED == (char *)Pike_interpreter.evaluator_stack) Pike_interpreter.evaluator_stack=0; -  if((char *)MAP_FAILED == (char *)Pike_interpreter.mark_stack) Pike_interpreter.mark_stack=0; +  interpreter->evaluator_stack_malloced = 0; +  interpreter->mark_stack_malloced = 0; +  interpreter->evaluator_stack = MMALLOC(Pike_stack_size,struct svalue); +  interpreter->mark_stack = MMALLOC(Pike_stack_size, struct svalue *); +  if((char *)MAP_FAILED == (char *)interpreter->evaluator_stack) { +  interpreter->evaluator_stack = 0; +  interpreter->evaluator_stack_malloced = 1; +  } +  if((char *)MAP_FAILED == (char *)interpreter->mark_stack) { +  interpreter->mark_stack = 0; +  interpreter->mark_stack_malloced = 1; +  }      #ifdef NEED_USE_MALLOC_LABEL   use_malloc:   #endif /* NEED_USE_MALLOC_LABEL */      #else /* !USE_MMAP_FOR_STACK */ -  Pike_interpreter.evaluator_stack=0; -  Pike_interpreter.mark_stack=0; +  interpreter->evaluator_stack = 0; +  interpreter->evaluator_stack_malloced = 1; +  interpreter->mark_stack = 0; +  interpreter->mark_stack_malloced = 1;   #endif /* USE_MMAP_FOR_STACK */    -  if(!Pike_interpreter.evaluator_stack) +  if(!interpreter->evaluator_stack)    { -  Pike_interpreter.evaluator_stack=(struct svalue *)xalloc(Pike_stack_size*sizeof(struct svalue)); -  Pike_interpreter.evaluator_stack_malloced=1; +  if (!(interpreter->evaluator_stack = +  (struct svalue *)malloc(Pike_stack_size*sizeof(struct svalue)))) +  return 1; /* Out of memory (evaluator stack). */    }    -  if(!Pike_interpreter.mark_stack) +  if(!interpreter->mark_stack)    { -  Pike_interpreter.mark_stack=(struct svalue **)xalloc(Pike_stack_size*sizeof(struct svalue *)); -  Pike_interpreter.mark_stack_malloced=1; +  if (!(interpreter->mark_stack = +  (struct svalue **)malloc(Pike_stack_size*sizeof(struct svalue *)))) +  return 2; /* Out of memory (mark stack). */    }    -  Pike_sp=Pike_interpreter.evaluator_stack; -  Pike_mark_sp=Pike_interpreter.mark_stack; -  Pike_fp=0; +  interpreter->stack_pointer = interpreter->evaluator_stack; +  interpreter->mark_stack_pointer = interpreter->mark_stack; +  interpreter->frame_pointer = 0;    -  Pike_interpreter.svalue_stack_margin = SVALUE_STACK_MARGIN; -  Pike_interpreter.c_stack_margin = C_STACK_MARGIN; +  interpreter->svalue_stack_margin = SVALUE_STACK_MARGIN; +  interpreter->c_stack_margin = C_STACK_MARGIN;    -  + #ifdef PROFILING +  interpreter->unlocked_time = 0; +  interpreter->accounted_time = 0; + #endif +  +  return 0; /* OK. */ + } +  + PMOD_EXPORT void init_interpreter(void) + { +  if (low_init_interpreter(&Pike_interpreter)) { +  Pike_fatal("Out of memory initializing the interpreter stack.\n"); +  } +    #ifdef PIKE_DEBUG    {    static struct callback *spcb;    if(!spcb)    {    spcb=add_gc_callback(gc_check_stack_callback,0,0);    dmalloc_accept_leak(spcb);    }    }   #endif - #ifdef PROFILING -  Pike_interpreter.unlocked_time = 0; -  Pike_interpreter.accounted_time = 0; - #endif +    #if defined(HAVE_COMPUTED_GOTO) || defined(PIKE_USE_MACHINE_CODE)    {    static int tables_need_init=1;    if(tables_need_init) {    /* Initialize the fcode_to_opcode table / jump labels. */    eval_instruction(NULL);   #if defined(PIKE_USE_MACHINE_CODE) && !defined(PIKE_DEBUG)    /* Simple operator opcodes... */   #define SET_INSTR_ADDRESS(X, Y) (instrs[(X)-F_OFFSET].address = (void *)Y)    SET_INSTR_ADDRESS(F_COMPL, o_compl);
pike.git/src/interpret.c:297: Inside #if defined(HAVE_COMPUTED_GOTO) || defined(PIKE_USE_MACHINE_CODE)
   SET_INSTR_ADDRESS(F_CAST_TO_STRING, o_cast_to_string);    SET_INSTR_ADDRESS(F_RANGE, o_range2);    SET_INSTR_ADDRESS(F_SSCANF, o_sscanf);   #endif /* PIKE_USE_MACHINE_CODE && !PIKE_DEBUG */    tables_need_init=0;    }    }   #endif /* HAVE_COMPUTED_GOTO || PIKE_USE_MACHINE_CODE */   }    -  +    /*    * lvalues are stored in two svalues in one of these formats:    * array[index] : { array, index }    * mapping[index] : { mapping, index }    * multiset[index] : { multiset, index }    * object[index] : { object, index } (external object indexing)    * local variable : { svalue pointer (T_SVALUE_PTR), nothing (T_VOID) }    * global variable : { object, identifier index (T_OBJ_INDEX) } (internal object indexing)    */   
pike.git/src/interpret.c:2828: Inside #if defined(USE_MMAP_FOR_STACK)
   munmap((char *)Pike_interpreter.evaluator_stack, Pike_stack_size*sizeof(struct svalue));    Pike_interpreter.evaluator_stack=0;    }    if(!Pike_interpreter.mark_stack_malloced)    {    munmap((char *)Pike_interpreter.mark_stack, Pike_stack_size*sizeof(struct svalue *));    Pike_interpreter.mark_stack=0;    }   #endif    -  if(Pike_interpreter.evaluator_stack) free((char *)Pike_interpreter.evaluator_stack); -  if(Pike_interpreter.mark_stack) free((char *)Pike_interpreter.mark_stack); +  if(Pike_interpreter.evaluator_stack) +  free((char *)Pike_interpreter.evaluator_stack); +  if(Pike_interpreter.mark_stack) +  free((char *)Pike_interpreter.mark_stack);       Pike_interpreter.mark_stack=0;    Pike_interpreter.evaluator_stack=0;    Pike_interpreter.mark_stack_malloced=0;    Pike_interpreter.evaluator_stack_malloced=0;   }      void really_clean_up_interpret(void)   {   #ifdef DO_PIKE_CLEANUP   #if 0    struct pike_frame_block *p;    int e;    for(p=pike_frame_blocks;p;p=p->next)    for(e=0;e<128;e++)    debug_malloc_dump_references( p->x + e);   #endif    free_all_pike_frame_blocks();   #endif   }