e576bb2002-10-11Martin Nilsson /* || 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.
e851e92003-06-06Martin Nilsson || $Id: interpret.c,v 1.305 2003/06/06 13:04:56 nilsson Exp $
e576bb2002-10-11Martin Nilsson */
aedfb12002-10-09Martin Nilsson 
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "global.h"
e851e92003-06-06Martin Nilsson RCSID("$Id: interpret.c,v 1.305 2003/06/06 13:04:56 nilsson Exp $");
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "interpret.h" #include "object.h" #include "program.h" #include "svalue.h" #include "array.h" #include "mapping.h"
b2d3e42000-12-01Fredrik Hübinette (Hubbe) #include "pike_error.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "language.h" #include "stralloc.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "constants.h"
bb55f81997-03-16Fredrik Hübinette (Hubbe) #include "pike_macros.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "multiset.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "backend.h" #include "operators.h" #include "opcodes.h" #include "main.h" #include "lex.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "builtin_functions.h" #include "signal_handler.h" #include "gc.h"
07513e1996-10-04Fredrik Hübinette (Hubbe) #include "threads.h"
a29e021996-10-15Fredrik Hübinette (Hubbe) #include "callback.h"
9c6f7d1997-04-15Fredrik Hübinette (Hubbe) #include "fd_control.h"
7e97c31999-01-21Fredrik Hübinette (Hubbe) #include "security.h"
4218011999-01-31Fredrik Hübinette (Hubbe) #include "block_alloc.h"
43899f1999-10-23Fredrik Noring #include "bignum.h"
e498d91999-12-13Henrik Grubbström (Grubba) #include "pike_types.h"
0e0cd72001-07-20Henrik Grubbström (Grubba) #include "pikecode.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
349fcb1996-10-09Fredrik Hübinette (Hubbe) #include <fcntl.h>
8aeeb21996-11-19Fredrik Hübinette (Hubbe) #include <errno.h>
688f082001-02-27Martin Stjernholm #include <ctype.h>
349fcb1996-10-09Fredrik Hübinette (Hubbe) 
b208c11996-08-03Fredrik Hübinette (Hubbe) #ifdef HAVE_MMAP #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif #ifdef HAVE_SYS_MMAN_H #include <sys/mman.h> #endif
06983f1996-09-22Fredrik Hübinette (Hubbe) #ifdef MAP_NORESERVE
b208c11996-08-03Fredrik Hübinette (Hubbe) #define USE_MMAP_FOR_STACK #endif #endif
189fd01997-01-28Fredrik Hübinette (Hubbe) /* * Define the default evaluator stack size, used for just about everything. */ #define EVALUATOR_STACK_SIZE 100000
97ebb32003-01-09Henrik Grubbström (Grubba) #define TRACE_LEN (100 + Pike_interpreter.trace_level * 10)
5267b71995-08-09Fredrik Hübinette (Hubbe) 
6697042000-11-20Martin Stjernholm /* Keep some margin on the stack space checks. They're lifted when * handle_error runs to give it some room. */ #define SVALUE_STACK_MARGIN 100 /* Tested in 7.1: 40 was enough, 30 wasn't. */
45c65d2000-11-20Martin Stjernholm #define C_STACK_MARGIN 8000 /* Tested in 7.1: 3000 was enough, 2600 wasn't. */
6697042000-11-20Martin Stjernholm 
88149c2001-07-08Henrik Grubbström (Grubba) #ifdef HAVE_COMPUTED_GOTO PIKE_OPCODE_T *fcode_to_opcode = NULL;
afa1c62001-07-09Henrik Grubbström (Grubba) struct op_2_f *opcode_to_fcode = NULL;
88149c2001-07-08Henrik Grubbström (Grubba) #endif /* HAVE_COMPUTED_GOTO */
5267b71995-08-09Fredrik Hübinette (Hubbe) 
c299402001-11-10Martin Stjernholm PMOD_EXPORT const char Pike_check_stack_errmsg[] =
c915472000-12-04Martin Stjernholm  "Svalue stack overflow. " "(%ld of %ld entries on stack, needed %ld more entries)\n";
c299402001-11-10Martin Stjernholm PMOD_EXPORT const char Pike_check_mark_stack_errmsg[] =
c915472000-12-04Martin Stjernholm  "Mark stack overflow.\n";
c299402001-11-10Martin Stjernholm PMOD_EXPORT const char Pike_check_c_stack_errmsg[] =
c915472000-12-04Martin Stjernholm  "C stack overflow.\n";
c299402001-11-10Martin Stjernholm #ifdef PIKE_DEBUG PMOD_EXPORT const char msg_stack_error[] = "Stack error.\n"; PMOD_EXPORT const char msg_pop_neg[] = "Popping negative number of args.... (%"PRINTPTRDIFFT"d) \n"; #endif
c915472000-12-04Martin Stjernholm 
342fef2000-08-23Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG static char trace_buffer[2000]; #endif
0f65e12002-09-14Martin Stjernholm #ifdef INTERNAL_PROFILING PMOD_EXPORT unsigned long evaluator_callback_calls = 0; #endif
342fef2000-08-23Fredrik Hübinette (Hubbe) 
f077582000-07-06Fredrik Hübinette (Hubbe) /* Pike_sp points to first unused value on stack
5267b71995-08-09Fredrik Hübinette (Hubbe)  * (much simpler than letting it point at the last used value.) */
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT struct Pike_interpreter Pike_interpreter;
7965d72001-01-24Fredrik Hübinette (Hubbe) PMOD_EXPORT int Pike_stack_size = EVALUATOR_STACK_SIZE;
f077582000-07-06Fredrik Hübinette (Hubbe) 
6f3ad02001-07-02Martin Stjernholm static void trace_return_value(void); static void do_trace_call(INT32);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
07346a2001-05-11Henrik Grubbström (Grubba) void gdb_stop_here(void) { ; }
be478c1997-08-30Henrik Grubbström (Grubba) void push_sp_mark(void)
36feac1997-03-06Fredrik Hübinette (Hubbe) {
7965d72001-01-24Fredrik Hübinette (Hubbe)  if(Pike_mark_sp == Pike_interpreter.mark_stack + Pike_stack_size)
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("No more mark stack!\n");
fc26f62000-07-06Fredrik Hübinette (Hubbe)  *Pike_mark_sp++=Pike_sp;
36feac1997-03-06Fredrik Hübinette (Hubbe) }
6d8c692000-08-08Henrik Grubbström (Grubba) ptrdiff_t pop_sp_mark(void)
36feac1997-03-06Fredrik Hübinette (Hubbe) {
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
fc26f62000-07-06Fredrik Hübinette (Hubbe)  if(Pike_mark_sp < Pike_interpreter.mark_stack)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Mark stack underflow!\n");
36feac1997-03-06Fredrik Hübinette (Hubbe) #endif
fc26f62000-07-06Fredrik Hübinette (Hubbe)  return Pike_sp - *--Pike_mark_sp;
36feac1997-03-06Fredrik Hübinette (Hubbe) }
fa382f1996-06-21Fredrik Hübinette (Hubbe) 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
05c7cd1997-07-19Fredrik Hübinette (Hubbe) static void gc_check_stack_callback(struct callback *foo, void *bar, void *gazonk) {
4218011999-01-31Fredrik Hübinette (Hubbe)  struct pike_frame *f;
6d8c692000-08-08Henrik Grubbström (Grubba)  debug_gc_xmark_svalues(Pike_interpreter.evaluator_stack, Pike_sp-Pike_interpreter.evaluator_stack-1, " on current interpreter stack");
62d3e41998-04-05Fredrik Hübinette (Hubbe) 
f077582000-07-06Fredrik Hübinette (Hubbe)  for(f=Pike_fp;f;f=f->next)
62d3e41998-04-05Fredrik Hübinette (Hubbe)  { if(f->context.parent)
f077582000-07-06Fredrik Hübinette (Hubbe)  gc_external_mark2(f->context.parent,0," in Pike_fp->context.parent on current stack"); gc_external_mark2(f->current_object,0," in Pike_fp->current_object on current stack"); gc_external_mark2(f->context.prog,0," in Pike_fp->context.prog on current stack");
62d3e41998-04-05Fredrik Hübinette (Hubbe)  }
05c7cd1997-07-19Fredrik Hübinette (Hubbe) } #endif
28498e2002-11-09Henrik Grubbström (Grubba) /* Execute Pike code starting at pc. * * 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. */
eff6212001-07-09Henrik Grubbström (Grubba) static int eval_instruction(PIKE_OPCODE_T *pc);
a078232001-07-08Henrik Grubbström (Grubba) 
fa8c692000-11-30Fredrik Hübinette (Hubbe) PMOD_EXPORT void init_interpreter(void)
fa382f1996-06-21Fredrik Hübinette (Hubbe) {
b208c11996-08-03Fredrik Hübinette (Hubbe) #ifdef USE_MMAP_FOR_STACK
349fcb1996-10-09Fredrik Hübinette (Hubbe)  static int fd = -1;
b208c11996-08-03Fredrik Hübinette (Hubbe) 
05c7cd1997-07-19Fredrik Hübinette (Hubbe) 
b208c11996-08-03Fredrik Hübinette (Hubbe) #ifndef MAP_VARIABLE #define MAP_VARIABLE 0 #endif #ifndef MAP_PRIVATE #define MAP_PRIVATE 0 #endif
3c9f631996-09-23Fredrik Hübinette (Hubbe) #ifndef MAP_FAILED #define MAP_FAILED -1 #endif
349fcb1996-10-09Fredrik Hübinette (Hubbe) #ifndef MAP_ANONYMOUS
b208c11996-08-03Fredrik Hübinette (Hubbe) #define MAP_ANONYMOUS 0
349fcb1996-10-09Fredrik Hübinette (Hubbe)  if(fd == -1) {
cf39c21996-11-18Fredrik Hübinette (Hubbe)  while(1) { fd=open("/dev/zero",O_RDONLY); if(fd >= 0) break; if(errno != EINTR)
d77dfb1996-11-21Fredrik Hübinette (Hubbe)  {
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_interpreter.evaluator_stack=0; Pike_interpreter.mark_stack=0;
d77dfb1996-11-21Fredrik Hübinette (Hubbe)  goto use_malloc; }
cf39c21996-11-18Fredrik Hübinette (Hubbe)  }
c36b851997-11-01Henrik Grubbström (Grubba)  /* Don't keep this fd on exec() */ set_close_on_exec(fd, 1);
349fcb1996-10-09Fredrik Hübinette (Hubbe)  }
b208c11996-08-03Fredrik Hübinette (Hubbe) #endif
06983f1996-09-22Fredrik Hübinette (Hubbe) #define MMALLOC(X,Y) (Y *)mmap(0,X*sizeof(Y),PROT_READ|PROT_WRITE, MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, fd, 0)
b208c11996-08-03Fredrik Hübinette (Hubbe) 
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_interpreter.evaluator_stack_malloced=0;
a8964a2003-03-24Jonas Wallden  Pike_interpreter.mark_stack_malloced=0;
7965d72001-01-24Fredrik Hübinette (Hubbe)  Pike_interpreter.evaluator_stack=MMALLOC(Pike_stack_size,struct svalue); Pike_interpreter.mark_stack=MMALLOC(Pike_stack_size, struct svalue *);
f077582000-07-06Fredrik Hübinette (Hubbe)  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;
a5cd6a2001-09-24Henrik Grubbström (Grubba)  use_malloc:
07513e1996-10-04Fredrik Hübinette (Hubbe) #else
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_interpreter.evaluator_stack=0; Pike_interpreter.mark_stack=0;
b208c11996-08-03Fredrik Hübinette (Hubbe) #endif
07513e1996-10-04Fredrik Hübinette (Hubbe) 
f077582000-07-06Fredrik Hübinette (Hubbe)  if(!Pike_interpreter.evaluator_stack)
3c9f631996-09-23Fredrik Hübinette (Hubbe)  {
7965d72001-01-24Fredrik Hübinette (Hubbe)  Pike_interpreter.evaluator_stack=(struct svalue *)xalloc(Pike_stack_size*sizeof(struct svalue));
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_interpreter.evaluator_stack_malloced=1;
3c9f631996-09-23Fredrik Hübinette (Hubbe)  }
f077582000-07-06Fredrik Hübinette (Hubbe)  if(!Pike_interpreter.mark_stack)
3c9f631996-09-23Fredrik Hübinette (Hubbe)  {
7965d72001-01-24Fredrik Hübinette (Hubbe)  Pike_interpreter.mark_stack=(struct svalue **)xalloc(Pike_stack_size*sizeof(struct svalue *));
a8964a2003-03-24Jonas Wallden  Pike_interpreter.mark_stack_malloced=1;
3c9f631996-09-23Fredrik Hübinette (Hubbe)  }
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_sp=Pike_interpreter.evaluator_stack;
fc26f62000-07-06Fredrik Hübinette (Hubbe)  Pike_mark_sp=Pike_interpreter.mark_stack;
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_fp=0;
62d3e41998-04-05Fredrik Hübinette (Hubbe) 
6697042000-11-20Martin Stjernholm  Pike_interpreter.svalue_stack_margin = SVALUE_STACK_MARGIN; Pike_interpreter.c_stack_margin = C_STACK_MARGIN;
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
62d3e41998-04-05Fredrik Hübinette (Hubbe)  { static struct callback *spcb; if(!spcb) { spcb=add_gc_callback(gc_check_stack_callback,0,0);
424d9c1999-05-02Fredrik Hübinette (Hubbe)  dmalloc_accept_leak(spcb);
62d3e41998-04-05Fredrik Hübinette (Hubbe)  } } #endif
d65e531998-11-19Fredrik Hübinette (Hubbe) #ifdef PROFILING #ifdef HAVE_GETHRTIME
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_interpreter.time_base = gethrtime(); Pike_interpreter.accounted_time =0;
d65e531998-11-19Fredrik Hübinette (Hubbe) #endif #endif
2b506e2002-10-16Marcus Comstedt #if defined(HAVE_COMPUTED_GOTO) || defined(PIKE_USE_MACHINE_CODE)
9271c02002-10-16Marcus Comstedt  { static int tables_need_init=1; if(tables_need_init) { /* Initialize the fcode_to_opcode table / jump labels. */ eval_instruction(NULL);
440a122001-07-24Henrik Grubbström (Grubba) #if defined(PIKE_USE_MACHINE_CODE) && !defined(PIKE_DEBUG)
9271c02002-10-16Marcus Comstedt  /* Simple operator opcodes... */
440a122001-07-24Henrik Grubbström (Grubba) #define SET_INSTR_ADDRESS(X, Y) (instrs[(X)-F_OFFSET].address = (void *)Y)
9271c02002-10-16Marcus Comstedt  SET_INSTR_ADDRESS(F_COMPL, o_compl); SET_INSTR_ADDRESS(F_LSH, o_lsh); SET_INSTR_ADDRESS(F_RSH, o_rsh); SET_INSTR_ADDRESS(F_SUBTRACT, o_subtract); SET_INSTR_ADDRESS(F_AND, o_and); SET_INSTR_ADDRESS(F_OR, o_or); SET_INSTR_ADDRESS(F_XOR, o_xor); SET_INSTR_ADDRESS(F_MULTIPLY, o_multiply); SET_INSTR_ADDRESS(F_DIVIDE, o_divide); SET_INSTR_ADDRESS(F_MOD, o_mod); SET_INSTR_ADDRESS(F_CAST, f_cast); SET_INSTR_ADDRESS(F_CAST_TO_INT, o_cast_to_int); SET_INSTR_ADDRESS(F_CAST_TO_STRING, o_cast_to_string); SET_INSTR_ADDRESS(F_RANGE, o_range); SET_INSTR_ADDRESS(F_SSCANF, o_sscanf);
440a122001-07-24Henrik Grubbström (Grubba) #endif /* PIKE_USE_MACHINE_CODE && !PIKE_DEBUG */
9271c02002-10-16Marcus Comstedt  tables_need_init=0; } } #endif /* HAVE_COMPUTED_GOTO || PIKE_USE_MACHINE_CODE */
fa382f1996-06-21Fredrik Hübinette (Hubbe) }
4908871998-08-10Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe) /* * lvalues are stored in two svalues in one of these formats: * array[index] : { array, index } * mapping[index] : { mapping, index }
06983f1996-09-22Fredrik Hübinette (Hubbe)  * multiset[index] : { multiset, index }
a903032003-02-16Martin Stjernholm  * 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)
5267b71995-08-09Fredrik Hübinette (Hubbe)  */ void lvalue_to_svalue_no_free(struct svalue *to,struct svalue *lval) {
7e97c31999-01-21Fredrik Hübinette (Hubbe) #ifdef PIKE_SECURITY if(lval->type <= MAX_COMPLEX) if(!CHECK_DATA_SECURITY(lval->u.array, SECURITY_BIT_INDEX))
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Index permission denied.\n");
7e97c31999-01-21Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  switch(lval->type) {
d6591a2001-03-08Fredrik Hübinette (Hubbe)  case T_ARRAY_LVALUE:
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
2a32691998-01-31Fredrik Hübinette (Hubbe)  INT32 e; struct array *a;
2523ce2003-04-28Martin Stjernholm  TYPE_FIELD types = 0;
2a32691998-01-31Fredrik Hübinette (Hubbe)  ONERROR err; a=allocate_array(lval[1].u.array->size>>1); SET_ONERROR(err, do_free_array, a);
2523ce2003-04-28Martin Stjernholm  for(e=0;e<a->size;e++) { lvalue_to_svalue_no_free(ITEM(a)+e, ITEM(lval[1].u.array)+(e<<1)); types |= 1 << ITEM(a)[e].type; } a->type_field = types;
2a32691998-01-31Fredrik Hübinette (Hubbe)  to->type = T_ARRAY; to->u.array=a; UNSET_ONERROR(err); break;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
2a32691998-01-31Fredrik Hübinette (Hubbe) 
a903032003-02-16Martin Stjernholm  case T_SVALUE_PTR:
50ea682003-03-14Henrik Grubbström (Grubba)  dmalloc_touch_svalue(lval->u.lval);
2a32691998-01-31Fredrik Hübinette (Hubbe)  assign_svalue_no_free(to, lval->u.lval); break;
a903032003-02-16Martin Stjernholm 
2a32691998-01-31Fredrik Hübinette (Hubbe)  case T_OBJECT:
a903032003-02-16Martin Stjernholm  if (lval[1].type == T_OBJ_INDEX) low_object_index_no_free (to, lval->u.object, lval[1].u.identifier); else object_index_no_free(to, lval->u.object, lval+1);
2a32691998-01-31Fredrik Hübinette (Hubbe)  break; case T_ARRAY: simple_array_index_no_free(to, lval->u.array, lval+1); break; case T_MAPPING: mapping_index_no_free(to, lval->u.mapping, lval+1); break; case T_MULTISET: to->type=T_INT; if(multiset_member(lval->u.multiset,lval+1)) {
d6591a2001-03-08Fredrik Hübinette (Hubbe)  to->u.integer=1; to->subtype=NUMBER_NUMBER;
2a32691998-01-31Fredrik Hübinette (Hubbe)  }else{ to->u.integer=0;
d6591a2001-03-08Fredrik Hübinette (Hubbe)  to->subtype=NUMBER_UNDEFINED;
2a32691998-01-31Fredrik Hübinette (Hubbe)  } break; default:
9f516a2001-12-16Martin Stjernholm  if(SAFE_IS_ZERO(lval))
c6bdce1999-03-19Fredrik Hübinette (Hubbe)  index_error(0,0,0,lval,lval+1,"Indexing the NULL value.\n");
2a32691998-01-31Fredrik Hübinette (Hubbe)  else
c6bdce1999-03-19Fredrik Hübinette (Hubbe)  index_error(0,0,0,lval,lval+1,"Indexing a basic type.\n");
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void assign_lvalue(struct svalue *lval,struct svalue *from)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
7e97c31999-01-21Fredrik Hübinette (Hubbe) #ifdef PIKE_SECURITY if(lval->type <= MAX_COMPLEX) if(!CHECK_DATA_SECURITY(lval->u.array, SECURITY_BIT_SET_INDEX))
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Assign index permission denied.\n");
7e97c31999-01-21Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  switch(lval->type) {
2a32691998-01-31Fredrik Hübinette (Hubbe)  case T_ARRAY_LVALUE: { INT32 e; if(from->type != T_ARRAY)
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Trying to assign combined lvalue from non-array.\n");
2a32691998-01-31Fredrik Hübinette (Hubbe)  if(from->u.array->size < (lval[1].u.array->size>>1))
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Not enough values for multiple assign.\n");
2a32691998-01-31Fredrik Hübinette (Hubbe) 
bd8d601999-05-13Fredrik Hübinette (Hubbe)  if(from->u.array->size > (lval[1].u.array->size>>1))
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Too many values for multiple assign.\n");
bd8d601999-05-13Fredrik Hübinette (Hubbe) 
2a32691998-01-31Fredrik Hübinette (Hubbe)  for(e=0;e<from->u.array->size;e++) assign_lvalue(lval[1].u.array->item+(e<<1),from->u.array->item+e); } break;
a903032003-02-16Martin Stjernholm  case T_SVALUE_PTR:
50ea682003-03-14Henrik Grubbström (Grubba)  dmalloc_touch_svalue(from); dmalloc_touch_svalue(lval->u.lval);
5267b71995-08-09Fredrik Hübinette (Hubbe)  assign_svalue(lval->u.lval,from); break; case T_OBJECT:
a903032003-02-16Martin Stjernholm  if (lval[1].type == T_OBJ_INDEX) object_low_set_index (lval->u.object, lval[1].u.identifier, from); else object_set_index(lval->u.object, lval+1, from);
5267b71995-08-09Fredrik Hübinette (Hubbe)  break; case T_ARRAY: simple_set_index(lval->u.array, lval+1, from); break; case T_MAPPING: mapping_insert(lval->u.mapping, lval+1, from); break;
06983f1996-09-22Fredrik Hübinette (Hubbe)  case T_MULTISET:
9f516a2001-12-16Martin Stjernholm  if(UNSAFE_IS_ZERO(from))
06983f1996-09-22Fredrik Hübinette (Hubbe)  multiset_delete(lval->u.multiset, lval+1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  else
06983f1996-09-22Fredrik Hübinette (Hubbe)  multiset_insert(lval->u.multiset, lval+1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  break; default:
9f516a2001-12-16Martin Stjernholm  if(SAFE_IS_ZERO(lval))
c6bdce1999-03-19Fredrik Hübinette (Hubbe)  index_error(0,0,0,lval,lval+1,"Indexing the NULL value.\n");
6ec27f1996-12-05Per Hedbor  else
c6bdce1999-03-19Fredrik Hübinette (Hubbe)  index_error(0,0,0,lval,lval+1,"Indexing a basic type.\n");
5267b71995-08-09Fredrik Hübinette (Hubbe)  } } union anything *get_pointer_if_this_type(struct svalue *lval, TYPE_T t) {
7e97c31999-01-21Fredrik Hübinette (Hubbe) #ifdef PIKE_SECURITY if(lval->type <= MAX_COMPLEX) if(!CHECK_DATA_SECURITY(lval->u.array, SECURITY_BIT_SET_INDEX))
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Assign index permission denied.\n");
7e97c31999-01-21Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  switch(lval->type) {
2a32691998-01-31Fredrik Hübinette (Hubbe)  case T_ARRAY_LVALUE: return 0;
a903032003-02-16Martin Stjernholm  case T_SVALUE_PTR:
50ea682003-03-14Henrik Grubbström (Grubba)  dmalloc_touch_svalue(lval->u.lval);
2a32691998-01-31Fredrik Hübinette (Hubbe)  if(lval->u.lval->type == t) return & ( lval->u.lval->u ); return 0;
a903032003-02-16Martin Stjernholm 
2a32691998-01-31Fredrik Hübinette (Hubbe)  case T_OBJECT: return object_get_item_ptr(lval->u.object,lval+1,t); case T_ARRAY: return array_get_item_ptr(lval->u.array,lval+1,t); case T_MAPPING: return mapping_get_item_ptr(lval->u.mapping,lval+1,t);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
2a32691998-01-31Fredrik Hübinette (Hubbe)  case T_MULTISET: return 0; default:
9f516a2001-12-16Martin Stjernholm  if(SAFE_IS_ZERO(lval))
c6bdce1999-03-19Fredrik Hübinette (Hubbe)  index_error(0,0,0,lval,lval+1,"Indexing the NULL value.\n"); else index_error(0,0,0,lval,lval+1,"Indexing a basic type.\n");
2a32691998-01-31Fredrik Hübinette (Hubbe)  return 0;
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
d4425e2000-08-24Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG
342fef2000-08-23Fredrik Hübinette (Hubbe) inline void pike_trace(int level,char *fmt, ...) ATTRIBUTE((format (printf, 2, 3))); inline void pike_trace(int level,char *fmt, ...) {
97ebb32003-01-09Henrik Grubbström (Grubba)  if(Pike_interpreter.trace_level > level)
342fef2000-08-23Fredrik Hübinette (Hubbe)  { va_list args; va_start(args,fmt); vsprintf(trace_buffer,fmt,args); va_end(args); write_to_stderr(trace_buffer,strlen(trace_buffer)); } } void my_describe_inherit_structure(struct program *p) { struct inherit *in,*last=0; int e,i=0; last=p->inherits-1; fprintf(stderr,"PROGRAM[%d]: inherits=%d identifers_refs=%d ppid=%d\n", p->id, p->num_inherits, p->num_identifier_references,
3af3412002-09-11Martin Stjernholm  p->parent ? p->parent->id : -1);
342fef2000-08-23Fredrik Hübinette (Hubbe)  for(e=0;e<p->num_identifier_references;e++) { in=INHERIT_FROM_INT(p,e); while(last < in) { last++;
08de582000-08-24Henrik Grubbström (Grubba)  fprintf(stderr, "[%ld]%*s parent{ offset=%d ident=%d id=%d } " "id{ level=%d } prog=%d\n", DO_NOT_WARN((long)(last - p->inherits)),
342fef2000-08-23Fredrik Hübinette (Hubbe)  last->inherit_level*2,"", last->parent_offset, last->parent_identifier,
3af3412002-09-11Martin Stjernholm  last->prog->parent ? last->prog->parent->id : -1,
342fef2000-08-23Fredrik Hübinette (Hubbe)  last->identifier_level, last->prog->id); i=0; } fprintf(stderr," %*s %d,%d: %s\n", in->inherit_level*2,"", e,i, ID_FROM_INT(p,e)->name->str); i++; } } #define TRACE(X) pike_trace X #else #define TRACE(X) #endif PMOD_EXPORT void find_external_context(struct external_variable_context *loc, int arg2) { struct program *p;
e428262001-06-10Henrik Grubbström (Grubba) 
d1cac52000-09-07Henrik Grubbström (Grubba)  TRACE((4, "-find_external_context(%d, inherit=%ld)\n", arg2,
2a52ff2000-10-01Fredrik Hübinette (Hubbe)  DO_NOT_WARN((long)(loc->o->prog ? loc->inherit - loc->o->prog->inherits : 0))));
342fef2000-08-23Fredrik Hübinette (Hubbe)  if(!loc->o)
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Current object is destructed\n");
342fef2000-08-23Fredrik Hübinette (Hubbe)  while(--arg2>=0) { #ifdef PIKE_DEBUG
97ebb32003-01-09Henrik Grubbström (Grubba)  if(Pike_interpreter.trace_level>8 && loc->o->prog)
342fef2000-08-23Fredrik Hübinette (Hubbe)  my_describe_inherit_structure(loc->o->prog); #endif TRACE((4,"- i->parent_offset=%d i->parent_identifier=%d\n", loc->inherit->parent_offset, loc->inherit->parent_identifier));
f3c7152001-04-14Fredrik Hübinette (Hubbe)  TRACE((4,"- o->parent_identifier=%d inherit->identifier_level=%d\n",
d797152001-09-13Fredrik Hübinette (Hubbe)  loc->o->prog && (loc->o->prog->flags & PROGRAM_USES_PARENT) ?
f3c7152001-04-14Fredrik Hübinette (Hubbe)  PARENT_INFO(loc->o)->parent_identifier : -1,
342fef2000-08-23Fredrik Hübinette (Hubbe)  loc->inherit->identifier_level)); switch(loc->inherit->parent_offset) { default: { struct external_variable_context tmp=*loc; #ifdef PIKE_DEBUG if(!loc->inherit->inherit_level)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Gahhh! inherit level zero in wrong place!\n");
342fef2000-08-23Fredrik Hübinette (Hubbe) #endif while(tmp.inherit->inherit_level >= loc->inherit->inherit_level) { TRACE((5,"- inherit-- (%d >= %d)\n",tmp.inherit->inherit_level, loc->inherit->inherit_level)); tmp.inherit--; } find_external_context(&tmp, loc->inherit->parent_offset); loc->o=tmp.o; loc->parent_identifier = loc->inherit->parent_identifier+ tmp.inherit->identifier_level; } break; case -17: TRACE((5,"- Following inherit->parent\n")); loc->parent_identifier=loc->inherit->parent_identifier; loc->o=loc->inherit->parent; break; case -18: TRACE((5,"- Following o->parent\n"));
d797152001-09-13Fredrik Hübinette (Hubbe)  if(((p=loc->o->prog) || (p=get_program_for_object_being_destructed(loc->o))) && (p->flags & PROGRAM_USES_PARENT))
f3c7152001-04-14Fredrik Hübinette (Hubbe)  {
d797152001-09-13Fredrik Hübinette (Hubbe)  loc->parent_identifier=LOW_PARENT_INFO(loc->o,p)->parent_identifier; loc->o=LOW_PARENT_INFO(loc->o,p)->parent;
f3c7152001-04-14Fredrik Hübinette (Hubbe)  }else{ loc->o=0; loc->parent_identifier=-1; }
342fef2000-08-23Fredrik Hübinette (Hubbe)  break; } if(!loc->o)
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Parent was lost during cloning.\n");
342fef2000-08-23Fredrik Hübinette (Hubbe)  if(!(p=loc->o->prog))
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Attempting to access variable in destructed object\n");
342fef2000-08-23Fredrik Hübinette (Hubbe)  #ifdef DEBUG_MALLOC if (loc->o->refs == 0x55555555) { fprintf(stderr, "The object %p has been zapped!\n", loc->o); describe(p);
5aad932002-08-15Marcus Comstedt  Pike_fatal("Object zapping detected.\n");
342fef2000-08-23Fredrik Hübinette (Hubbe)  } if (p->refs == 0x55555555) { fprintf(stderr, "The program %p has been zapped!\n", p); describe(p); fprintf(stderr, "Which taken from the object %p\n", loc->o); describe(loc->o);
5aad932002-08-15Marcus Comstedt  Pike_fatal("Looks like the program %p has been zapped!\n", p);
342fef2000-08-23Fredrik Hübinette (Hubbe)  } #endif /* DEBUG_MALLOC */ #ifdef PIKE_DEBUG if(loc->parent_identifier < 0 || loc->parent_identifier > p->num_identifier_references)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Identifier out of range, loc->parent_identifer=%d!\n",
342fef2000-08-23Fredrik Hübinette (Hubbe)  loc->parent_identifier); #endif loc->inherit=INHERIT_FROM_INT(p, loc->parent_identifier); #ifdef PIKE_DEBUG
97ebb32003-01-09Henrik Grubbström (Grubba)  if(Pike_interpreter.trace_level>28)
342fef2000-08-23Fredrik Hübinette (Hubbe)  my_describe_inherit_structure(p); #endif
d1cac52000-09-07Henrik Grubbström (Grubba)  TRACE((5,"- Parent identifier = %d (%s), inherit # = %ld\n",
342fef2000-08-23Fredrik Hübinette (Hubbe)  loc->parent_identifier, ID_FROM_INT(p, loc->parent_identifier)->name->str,
d1cac52000-09-07Henrik Grubbström (Grubba)  DO_NOT_WARN((long)(loc->inherit - p->inherits))));
342fef2000-08-23Fredrik Hübinette (Hubbe)  #ifdef DEBUG_MALLOC if (loc->inherit->storage_offset == 0x55555555) { fprintf(stderr, "The inherit %p has been zapped!\n", loc->inherit); debug_malloc_dump_references(loc->inherit,0,2,0); fprintf(stderr, "It was extracted from the program %p %d\n", p, loc->parent_identifier); describe(p); fprintf(stderr, "Which was in turn taken from the object %p\n", loc->o); describe(loc->o);
5aad932002-08-15Marcus Comstedt  Pike_fatal("Looks like the program %p has been zapped!\n", p);
342fef2000-08-23Fredrik Hübinette (Hubbe)  } #endif /* DEBUG_MALLOC */ } TRACE((4,"--find_external_context: parent_id=%d (%s)\n", loc->parent_identifier, ID_FROM_INT(loc->o->prog,loc->parent_identifier)->name->str )); }
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
be478c1997-08-30Henrik Grubbström (Grubba) void print_return_value(void)
5683de1995-11-06Fredrik Hübinette (Hubbe) {
97ebb32003-01-09Henrik Grubbström (Grubba)  if(Pike_interpreter.trace_level>3)
5683de1995-11-06Fredrik Hübinette (Hubbe)  { char *s; init_buf();
f077582000-07-06Fredrik Hübinette (Hubbe)  describe_svalue(Pike_sp-1,0,0);
5683de1995-11-06Fredrik Hübinette (Hubbe)  s=simple_free_buf();
6d8c692000-08-08Henrik Grubbström (Grubba)  if((size_t)strlen(s) > (size_t)TRACE_LEN)
5683de1995-11-06Fredrik Hübinette (Hubbe)  { s[TRACE_LEN]=0; s[TRACE_LEN-1]='.'; s[TRACE_LEN-2]='.';
53bb632000-02-15Henrik Grubbström (Grubba)  s[TRACE_LEN-3]='.';
5683de1995-11-06Fredrik Hübinette (Hubbe)  } fprintf(stderr,"- value: %s\n",s); free(s); } } #else
acc38d1995-11-20Fredrik Hübinette (Hubbe) #define print_return_value()
5683de1995-11-06Fredrik Hübinette (Hubbe) #endif
81b84e1996-12-03Fredrik Hübinette (Hubbe) struct callback_list evaluator_callbacks;
c5016f1996-04-13Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe) /* * reset the stack machine. */
be478c1997-08-30Henrik Grubbström (Grubba) void reset_evaluator(void)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_fp=0; pop_n_elems(Pike_sp - Pike_interpreter.evaluator_stack);
5267b71995-08-09Fredrik Hübinette (Hubbe) }
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
31984c2003-03-20Martin Stjernholm 
b9e2202000-05-03Fredrik Hübinette (Hubbe) #define BACKLOG 1024
5267b71995-08-09Fredrik Hübinette (Hubbe) struct backlog {
31984c2003-03-20Martin Stjernholm  PIKE_INSTR_T instruction;
c7ef072000-04-21Fredrik Hübinette (Hubbe)  INT32 arg,arg2;
5267b71995-08-09Fredrik Hübinette (Hubbe)  struct program *program;
eff6212001-07-09Henrik Grubbström (Grubba)  PIKE_OPCODE_T *pc;
8eaef52000-04-21Fredrik Hübinette (Hubbe) #ifdef _REENTRANT
114e2a2003-02-16Martin Stjernholm  struct thread_state *thread_state;
8eaef52000-04-21Fredrik Hübinette (Hubbe) #endif
6d8c692000-08-08Henrik Grubbström (Grubba)  ptrdiff_t stack; ptrdiff_t mark_stack;
5267b71995-08-09Fredrik Hübinette (Hubbe) }; struct backlog backlog[BACKLOG]; int backlogp=BACKLOG-1;
b1f6a62003-03-21Martin Stjernholm static inline void low_debug_instr_prologue (PIKE_INSTR_T instr)
31984c2003-03-20Martin Stjernholm { if(Pike_interpreter.trace_level > 2) { char *file, *f; struct pike_string *filep; INT32 linep;
b1f6a62003-03-21Martin Stjernholm  filep = get_line(Pike_fp->pc,Pike_fp->context.prog,&linep);
31984c2003-03-20Martin Stjernholm  if (filep && !filep->size_shift) { file = filep->str; while((f=STRCHR(file,'/'))) file=f+1; } fprintf(stderr,"- %s:%4ld:(%"PRINTPTRDIFFT"d): " "%-25s %4"PRINTPTRDIFFT"d %4"PRINTPTRDIFFT"d\n", file ? file : "-",(long)linep,
b1f6a62003-03-21Martin Stjernholm  Pike_fp->pc - Pike_fp->context.prog->program,
31984c2003-03-20Martin Stjernholm  get_opcode_name(instr), Pike_sp-Pike_interpreter.evaluator_stack, Pike_mark_sp-Pike_interpreter.mark_stack); free_string(filep); } #ifdef HAVE_COMPUTED_GOTO if (instr) ADD_RUNNED(instr); else Pike_fatal("NULL Instruction!\n"); #else /* !HAVE_COMPUTED_GOTO */ if(instr + F_OFFSET < F_MAX_OPCODE) ADD_RUNNED(instr); #endif /* HAVE_COMPUTED_GOTO */ if(d_flag) { backlogp++; if(backlogp >= BACKLOG) backlogp=0; if(backlog[backlogp].program) free_program(backlog[backlogp].program); backlog[backlogp].program=Pike_fp->context.prog; add_ref(Pike_fp->context.prog); backlog[backlogp].instruction=instr;
b1f6a62003-03-21Martin Stjernholm  backlog[backlogp].pc = Pike_fp->pc;
31984c2003-03-20Martin Stjernholm  backlog[backlogp].stack = Pike_sp - Pike_interpreter.evaluator_stack; backlog[backlogp].mark_stack = Pike_mark_sp - Pike_interpreter.mark_stack; #ifdef _REENTRANT backlog[backlogp].thread_state=Pike_interpreter.thread_state; #endif #ifdef _REENTRANT CHECK_INTERPRETER_LOCK(); if(d_flag>1) DEBUG_CHECK_THREAD(); #endif Pike_sp[0].type=99; /* an invalid type */ Pike_sp[1].type=99; Pike_sp[2].type=99; Pike_sp[3].type=99; if(Pike_sp<Pike_interpreter.evaluator_stack || Pike_mark_sp < Pike_interpreter.mark_stack || Pike_fp->locals>Pike_sp) Pike_fatal("Stack error (generic) sp=%p/%p mark_sp=%p/%p locals=%p.\n", Pike_sp, Pike_interpreter.evaluator_stack, Pike_mark_sp, Pike_interpreter.mark_stack, Pike_fp->locals); if(Pike_mark_sp > Pike_interpreter.mark_stack+Pike_stack_size) Pike_fatal("Mark Stack error (overflow).\n"); if(Pike_mark_sp < Pike_interpreter.mark_stack) Pike_fatal("Mark Stack error (underflow).\n"); if(Pike_sp > Pike_interpreter.evaluator_stack+Pike_stack_size) Pike_fatal("stack error (overflow).\n"); if(/* Pike_fp->fun>=0 && */ Pike_fp->current_object->prog && Pike_fp->locals+Pike_fp->num_locals > Pike_sp) Pike_fatal("Stack error (stupid!).\n"); if(Pike_interpreter.recoveries && (Pike_sp-Pike_interpreter.evaluator_stack < Pike_interpreter.recoveries->stack_pointer)) Pike_fatal("Stack error (underflow).\n"); if(Pike_mark_sp > Pike_interpreter.mark_stack && Pike_mark_sp[-1] > Pike_sp) Pike_fatal("Stack error (underflow?)\n"); if(d_flag > 9) do_debug(); debug_malloc_touch(Pike_fp->current_object); switch(d_flag) { default: case 3: check_object(Pike_fp->current_object); /* break; */ case 2: check_object_context(Pike_fp->current_object, Pike_fp->context.prog, Pike_fp->current_object->storage+ Pike_fp->context.storage_offset); case 1: case 0: break; } } } #define DEBUG_LOG_ARG(ARG) \ (backlog[backlogp].arg = (ARG), \ (Pike_interpreter.trace_level>3 ? \ sprintf(trace_buffer, "- Arg = %ld\n", \ (long) backlog[backlogp].arg), \ write_to_stderr(trace_buffer,strlen(trace_buffer)) : 0)) #define DEBUG_LOG_ARG2(ARG2) \ (backlog[backlogp].arg2 = (ARG2), \ (Pike_interpreter.trace_level>3 ? \ sprintf(trace_buffer, "- Arg2 = %ld\n", \ (long) backlog[backlogp].arg2), \ write_to_stderr(trace_buffer,strlen(trace_buffer)) : 0))
5c8e891995-10-29Fredrik Hübinette (Hubbe) void dump_backlog(void)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
086d652000-04-26Fredrik Hübinette (Hubbe) #ifdef _REENTRANT
114e2a2003-02-16Martin Stjernholm  struct thread_state *thread=0;
086d652000-04-26Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  int e; if(!d_flag || backlogp<0 || backlogp>=BACKLOG) return; e=backlogp; do { e++; if(e>=BACKLOG) e=0; if(backlog[e].program) {
50edc82001-07-13Henrik Grubbström (Grubba)  struct pike_string *file;
5267b71995-08-09Fredrik Hübinette (Hubbe)  INT32 line;
086d652000-04-26Fredrik Hübinette (Hubbe) #ifdef _REENTRANT
114e2a2003-02-16Martin Stjernholm  if(thread != backlog[e].thread_state)
086d652000-04-26Fredrik Hübinette (Hubbe)  {
114e2a2003-02-16Martin Stjernholm  fprintf(stderr,"[Thread swap, Pike_interpreter.thread_state=%p]\n",backlog[e].thread_state); thread = backlog[e].thread_state;
086d652000-04-26Fredrik Hübinette (Hubbe)  } #endif
31984c2003-03-20Martin Stjernholm  file = get_line(backlog[e].pc,backlog[e].program, &line);
eff6212001-07-09Henrik Grubbström (Grubba) #ifdef HAVE_COMPUTED_GOTO
31984c2003-03-20Martin Stjernholm  fprintf(stderr,"%s:%ld:(%"PRINTPTRDIFFT"d): %s",
50edc82001-07-13Henrik Grubbström (Grubba)  file->str,
eff6212001-07-09Henrik Grubbström (Grubba)  (long)line,
31984c2003-03-20Martin Stjernholm  backlog[e].pc - backlog[e].program->program,
afa1c62001-07-09Henrik Grubbström (Grubba)  get_opcode_name(backlog[e].instruction));
eff6212001-07-09Henrik Grubbström (Grubba) #else /* !HAVE_COMPUTED_GOTO */
31984c2003-03-20Martin Stjernholm  if(backlog[e].instruction+F_OFFSET > F_MAX_OPCODE)
c7ef072000-04-21Fredrik Hübinette (Hubbe)  {
31984c2003-03-20Martin Stjernholm  fprintf(stderr,"%s:%ld:(%"PRINTPTRDIFFT"d): ILLEGAL INSTRUCTION %d\n",
50edc82001-07-13Henrik Grubbström (Grubba)  file->str,
c7ef072000-04-21Fredrik Hübinette (Hubbe)  (long)line,
31984c2003-03-20Martin Stjernholm  backlog[e].pc - backlog[e].program->program,
c7ef072000-04-21Fredrik Hübinette (Hubbe)  backlog[e].instruction + F_OFFSET);
50edc82001-07-13Henrik Grubbström (Grubba)  free_string(file);
c7ef072000-04-21Fredrik Hübinette (Hubbe)  continue; }
31984c2003-03-20Martin Stjernholm  fprintf(stderr,"%s:%ld:(%"PRINTPTRDIFFT"d): %s",
50edc82001-07-13Henrik Grubbström (Grubba)  file->str,
b9e2202000-05-03Fredrik Hübinette (Hubbe)  (long)line,
31984c2003-03-20Martin Stjernholm  backlog[e].pc - backlog[e].program->program,
b9e2202000-05-03Fredrik Hübinette (Hubbe)  low_get_f_name(backlog[e].instruction + F_OFFSET, backlog[e].program));
c7ef072000-04-21Fredrik Hübinette (Hubbe)  if(instrs[backlog[e].instruction].flags & I_HASARG2) {
b9e2202000-05-03Fredrik Hübinette (Hubbe)  fprintf(stderr,"(%ld,%ld)",
c7ef072000-04-21Fredrik Hübinette (Hubbe)  (long)backlog[e].arg, (long)backlog[e].arg2); }
ac61a32001-01-31Martin Stjernholm  else if(instrs[backlog[e].instruction].flags & I_JUMP) { fprintf(stderr,"(%+ld)", (long)backlog[e].arg); }
c7ef072000-04-21Fredrik Hübinette (Hubbe)  else if(instrs[backlog[e].instruction].flags & I_HASARG) {
b9e2202000-05-03Fredrik Hübinette (Hubbe)  fprintf(stderr,"(%ld)", (long)backlog[e].arg);
c7ef072000-04-21Fredrik Hübinette (Hubbe)  }
1330e12000-08-10Henrik Grubbström (Grubba)  fprintf(stderr," %ld, %ld\n",
a85b432000-08-10Henrik Grubbström (Grubba)  DO_NOT_WARN((long)backlog[e].stack), DO_NOT_WARN((long)backlog[e].mark_stack));
eff6212001-07-09Henrik Grubbström (Grubba) #endif /* HAVE_COMPUTED_GOTO */
50edc82001-07-13Henrik Grubbström (Grubba)  free_string(file);
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }while(e!=backlogp);
cb22561995-10-11Fredrik Hübinette (Hubbe) }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
31984c2003-03-20Martin Stjernholm #else /* PIKE_DEBUG */ #define DEBUG_LOG_ARG(arg) 0 #define DEBUG_LOG_ARG2(arg2) 0 #endif /* !PIKE_DEBUG */
eff6212001-07-09Henrik Grubbström (Grubba) static int o_catch(PIKE_OPCODE_T *pc);
b208c11996-08-03Fredrik Hübinette (Hubbe) 
a64f6b2001-01-12Martin Stjernholm 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
b7c1ee2001-01-10Martin Stjernholm #define EVAL_INSTR_RET_CHECK(x) \ if (x == -2) \
5aad932002-08-15Marcus Comstedt  Pike_fatal("Return value -2 from eval_instruction is not handled here.\n"\
b7c1ee2001-01-10Martin Stjernholm  "Probable cause: F_ESCAPE_CATCH outside catch block.\n") #else #define EVAL_INSTR_RET_CHECK(x) #endif
f822262001-07-16Fredrik Hübinette (Hubbe)  #ifdef PIKE_USE_MACHINE_CODE /* Labels to jump to to cause eval_instruction to return */ /* FIXME: Replace these with assembler lables */
2b506e2002-10-16Marcus Comstedt void *do_inter_return_label = NULL;
f822262001-07-16Fredrik Hübinette (Hubbe) void *do_escape_catch_label;
9271c02002-10-16Marcus Comstedt void *dummy_label = NULL;
f822262001-07-16Fredrik Hübinette (Hubbe) 
2f401a2001-07-26Henrik Grubbström (Grubba) #ifndef DEF_PROG_COUNTER
8328ca2001-07-18Henrik Grubbström (Grubba) #define DEF_PROG_COUNTER
2f401a2001-07-26Henrik Grubbström (Grubba) #endif /* !DEF_PROG_COUNTER */
f822262001-07-16Fredrik Hübinette (Hubbe) 
9a41452001-08-01Marcus Comstedt #ifndef CALL_MACHINE_CODE #define CALL_MACHINE_CODE(pc) \ do { \ /* The test is needed to get the labels to work... */ \ if (pc) { \ /* No extra setup needed! \ */ \ return ((int (*)(void))(pc))(); \ } \
7293b72001-08-03Henrik Grubbström (Grubba)  } while(0)
9a41452001-08-01Marcus Comstedt #endif /* !CALL_MACHINE_CODE */
fd9b662003-03-22Martin Stjernholm #ifndef EXIT_MACHINE_CODE
be79d72003-03-23Martin Stjernholm #define EXIT_MACHINE_CODE()
fd9b662003-03-22Martin Stjernholm #endif
31984c2003-03-20Martin Stjernholm #ifdef PIKE_DEBUG
b1f6a62003-03-21Martin Stjernholm static void debug_instr_prologue (PIKE_INSTR_T instr)
31984c2003-03-20Martin Stjernholm {
b1f6a62003-03-21Martin Stjernholm  low_debug_instr_prologue (instr);
31984c2003-03-20Martin Stjernholm } #define DEBUG_PROLOGUE(OPCODE, EXTRA) do { \ if (d_flag || Pike_interpreter.trace_level > 2) { \
b1f6a62003-03-21Martin Stjernholm  debug_instr_prologue ((OPCODE) - F_OFFSET); \
31984c2003-03-20Martin Stjernholm  EXTRA; \ } \ } while (0) /* The following are intended to be called directly from generated * machine code. */
b1f6a62003-03-21Martin Stjernholm void simple_debug_instr_prologue_0 (PIKE_INSTR_T instr)
31984c2003-03-20Martin Stjernholm { if (d_flag || Pike_interpreter.trace_level > 2)
b1f6a62003-03-21Martin Stjernholm  low_debug_instr_prologue (instr);
31984c2003-03-20Martin Stjernholm }
b1f6a62003-03-21Martin Stjernholm void simple_debug_instr_prologue_1 (PIKE_INSTR_T instr, INT32 arg)
31984c2003-03-20Martin Stjernholm { if (d_flag || Pike_interpreter.trace_level > 2) {
b1f6a62003-03-21Martin Stjernholm  low_debug_instr_prologue (instr);
31984c2003-03-20Martin Stjernholm  DEBUG_LOG_ARG (arg); } }
b1f6a62003-03-21Martin Stjernholm void simple_debug_instr_prologue_2 (PIKE_INSTR_T instr, INT32 arg1, INT32 arg2)
31984c2003-03-20Martin Stjernholm { if (d_flag || Pike_interpreter.trace_level > 2) {
b1f6a62003-03-21Martin Stjernholm  low_debug_instr_prologue (instr);
31984c2003-03-20Martin Stjernholm  DEBUG_LOG_ARG (arg1); DEBUG_LOG_ARG2 (arg2); } } #else /* !PIKE_DEBUG */ #define DEBUG_PROLOGUE(OPCODE, EXTRA) do {} while (0) #endif /* !PIKE_DEBUG */
2bcc0d2002-05-11Martin Stjernholm #define OPCODE0(O,N,F,C) \
1524392001-07-16Fredrik Hübinette (Hubbe) void PIKE_CONCAT(opcode_,O)(void) { \
8328ca2001-07-18Henrik Grubbström (Grubba)  DEF_PROG_COUNTER; \
31984c2003-03-20Martin Stjernholm  DEBUG_PROLOGUE (O, ;); \
1524392001-07-16Fredrik Hübinette (Hubbe) C }
f822262001-07-16Fredrik Hübinette (Hubbe) 
2bcc0d2002-05-11Martin Stjernholm #define OPCODE1(O,N,F,C) \
1524392001-07-16Fredrik Hübinette (Hubbe) void PIKE_CONCAT(opcode_,O)(INT32 arg1) {\
8328ca2001-07-18Henrik Grubbström (Grubba)  DEF_PROG_COUNTER; \
31984c2003-03-20Martin Stjernholm  DEBUG_PROLOGUE (O, DEBUG_LOG_ARG (arg1)); \
1524392001-07-16Fredrik Hübinette (Hubbe) C }
f822262001-07-16Fredrik Hübinette (Hubbe) 
2bcc0d2002-05-11Martin Stjernholm #define OPCODE2(O,N,F,C) \
1524392001-07-16Fredrik Hübinette (Hubbe) void PIKE_CONCAT(opcode_,O)(INT32 arg1,INT32 arg2) { \
8328ca2001-07-18Henrik Grubbström (Grubba)  DEF_PROG_COUNTER; \
31984c2003-03-20Martin Stjernholm  DEBUG_PROLOGUE (O, DEBUG_LOG_ARG (arg1); DEBUG_LOG_ARG2 (arg2)); \
1524392001-07-16Fredrik Hübinette (Hubbe) C }
3e25ec2002-11-02Henrik Grubbström (Grubba) #ifdef OPCODE_INLINE_BRANCH #define TEST_OPCODE0(O,N,F,C) \ int PIKE_CONCAT(test_opcode_,O)(void) { \ int branch_taken = 0; \ DEF_PROG_COUNTER; \
31984c2003-03-20Martin Stjernholm  DEBUG_PROLOGUE (O, ;); \
3e25ec2002-11-02Henrik Grubbström (Grubba)  C; \ return branch_taken; \ } #define TEST_OPCODE1(O,N,F,C) \ int PIKE_CONCAT(test_opcode_,O)(INT32 arg1) {\ int branch_taken = 0; \ DEF_PROG_COUNTER; \
31984c2003-03-20Martin Stjernholm  DEBUG_PROLOGUE (O, DEBUG_LOG_ARG (arg1)); \
3e25ec2002-11-02Henrik Grubbström (Grubba)  C; \ return branch_taken; \ } #define TEST_OPCODE2(O,N,F,C) \ int PIKE_CONCAT(test_opcode_,O)(INT32 arg1, INT32 arg2) { \ int branch_taken = 0; \ DEF_PROG_COUNTER; \
31984c2003-03-20Martin Stjernholm  DEBUG_PROLOGUE (O, DEBUG_LOG_ARG (arg1); DEBUG_LOG_ARG2 (arg2)); \
3e25ec2002-11-02Henrik Grubbström (Grubba)  C; \ return branch_taken; \ }
13684b2002-11-04Marcus Comstedt #define DO_BRANCH() (branch_taken = -1) #define DONT_BRANCH() (branch_taken = 0)
3e25ec2002-11-02Henrik Grubbström (Grubba) #else /* !OPCODE_INLINE_BRANCH */ #define TEST_OPCODE0 OPCODE0 #define TEST_OPCODE1 OPCODE1 #define TEST_OPCODE2 OPCODE2 #endif /* OPCODE_INLINE_BRANCH */
1524392001-07-16Fredrik Hübinette (Hubbe) 
2bcc0d2002-05-11Martin Stjernholm #define OPCODE0_JUMP(O,N,F,C) OPCODE0(O,N,F,C) #define OPCODE1_JUMP(O,N,F,C) OPCODE1(O,N,F,C) #define OPCODE2_JUMP(O,N,F,C) OPCODE2(O,N,F,C)
1524392001-07-16Fredrik Hübinette (Hubbe) 
2bcc0d2002-05-11Martin Stjernholm #define OPCODE0_TAIL(O,N,F,C) OPCODE0(O,N,F,C) #define OPCODE1_TAIL(O,N,F,C) OPCODE1(O,N,F,C) #define OPCODE2_TAIL(O,N,F,C) OPCODE2(O,N,F,C)
1524392001-07-16Fredrik Hübinette (Hubbe) 
2bcc0d2002-05-11Martin Stjernholm #define OPCODE0_TAILJUMP(O,N,F,C) OPCODE0(O,N,F,C) #define OPCODE1_TAILJUMP(O,N,F,C) OPCODE1(O,N,F,C) #define OPCODE2_TAILJUMP(O,N,F,C) OPCODE2(O,N,F,C)
f822262001-07-16Fredrik Hübinette (Hubbe) 
2bcc0d2002-05-11Martin Stjernholm #define OPCODE0_RETURN(O,N,F,C) OPCODE0(O,N,F,C) #define OPCODE1_RETURN(O,N,F,C) OPCODE1(O,N,F,C) #define OPCODE2_RETURN(O,N,F,C) OPCODE2(O,N,F,C)
7997532001-07-27Henrik Grubbström (Grubba) 
2bcc0d2002-05-11Martin Stjernholm #define OPCODE0_RETURNJUMP(O,N,F,C) OPCODE0(O,N,F,C) #define OPCODE1_RETURNJUMP(O,N,F,C) OPCODE1(O,N,F,C) #define OPCODE2_RETURNJUMP(O,N,F,C) OPCODE2(O,N,F,C)
7997532001-07-27Henrik Grubbström (Grubba) 
3e25ec2002-11-02Henrik Grubbström (Grubba) /* BRANCH opcodes only generate code for the test, * so that the branch instruction can be inlined. */ #define OPCODE0_BRANCH(O,N,F,C) TEST_OPCODE0(O,N,F,C) #define OPCODE1_BRANCH(O,N,F,C) TEST_OPCODE1(O,N,F,C) #define OPCODE2_BRANCH(O,N,F,C) TEST_OPCODE2(O,N,F,C) #define OPCODE0_TAILBRANCH(O,N,F,C) TEST_OPCODE0(O,N,F,C) #define OPCODE1_TAILBRANCH(O,N,F,C) TEST_OPCODE1(O,N,F,C) #define OPCODE2_TAILBRANCH(O,N,F,C) TEST_OPCODE2(O,N,F,C)
105be62002-11-10Henrik Grubbström (Grubba) #define OPCODE0_ALIAS(O,N,F,C) #define OPCODE1_ALIAS(O,N,F,C) #define OPCODE2_ALIAS(O,N,F,C)
f822262001-07-16Fredrik Hübinette (Hubbe) #undef HAVE_COMPUTED_GOTO
0996a92001-07-17Henrik Grubbström (Grubba) #ifdef __GNUC__
2f401a2001-07-26Henrik Grubbström (Grubba)  /* Define the program counter if necessary. */ DEF_PROG_COUNTER;
f822262001-07-16Fredrik Hübinette (Hubbe) 
62a1bc2002-11-24Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG /* Note: The debug code is extracted, to keep the frame size constant. */ static int eval_instruction_low(PIKE_OPCODE_T *pc); #endif /* PIKE_DEBUG */
f822262001-07-16Fredrik Hübinette (Hubbe) 
62a1bc2002-11-24Henrik Grubbström (Grubba) static int eval_instruction(PIKE_OPCODE_T *pc)
0996a92001-07-17Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG
62a1bc2002-11-24Henrik Grubbström (Grubba) {
fcc65d2003-02-26Martin Stjernholm  if (Pike_interpreter.trace_level > 5 && pc) {
0996a92001-07-17Henrik Grubbström (Grubba)  int i;
e73f112002-10-30Martin Nilsson  fprintf(stderr, "Calling code at %p:\n", pc);
2f401a2001-07-26Henrik Grubbström (Grubba) #ifdef PIKE_OPCODE_ALIGN if (((INT32)pc) % PIKE_OPCODE_ALIGN) {
5aad932002-08-15Marcus Comstedt  Pike_fatal("Odd offset!\n");
c696242001-07-18Henrik Grubbström (Grubba)  }
2f401a2001-07-26Henrik Grubbström (Grubba) #endif /* PIKE_OPCODE_ALIGN */
0996a92001-07-17Henrik Grubbström (Grubba)  for (i=0; i < 16; i+=4) { fprintf(stderr, " 0x%08x 0x%08x 0x%08x 0x%08x\n", ((int *)pc)[i], ((int *)pc)[i+1], ((int *)pc)[i+2], ((int *)pc)[i+3]); } }
62a1bc2002-11-24Henrik Grubbström (Grubba)  return eval_instruction_low(pc); } static int eval_instruction_low(PIKE_OPCODE_T *pc)
0996a92001-07-17Henrik Grubbström (Grubba) #endif /* PIKE_DEBUG */
62a1bc2002-11-24Henrik Grubbström (Grubba) { if(pc == NULL) { if(do_inter_return_label != NULL) Pike_fatal("eval_instruction called with NULL (twice).\n"); do_inter_return_label = && inter_return_label; do_escape_catch_label = && inter_escape_catch_label; /* Trick optimizer */ if(!dummy_label) return 0; }
0996a92001-07-17Henrik Grubbström (Grubba) 
9a41452001-08-01Marcus Comstedt  CALL_MACHINE_CODE(pc);
f822262001-07-16Fredrik Hübinette (Hubbe)  /* This code is never reached, but will * prevent gcc from optimizing the labels below too much */ fprintf(stderr,"We have reached the end of the world!\n"); goto *dummy_label;
fd9b662003-03-22Martin Stjernholm  inter_escape_catch_label: EXIT_MACHINE_CODE(); return -2;
f822262001-07-16Fredrik Hübinette (Hubbe) 
fd9b662003-03-22Martin Stjernholm  inter_return_label: EXIT_MACHINE_CODE(); return -1;
f822262001-07-16Fredrik Hübinette (Hubbe) }
0996a92001-07-17Henrik Grubbström (Grubba) #endif /* __GNUC__ */
f822262001-07-16Fredrik Hübinette (Hubbe) 
7b2c002001-07-18Henrik Grubbström (Grubba) #ifndef SET_PROG_COUNTER
a8e2ec2001-07-17Henrik Grubbström (Grubba) #define SET_PROG_COUNTER(X) (PROG_COUNTER=(X))
7b2c002001-07-18Henrik Grubbström (Grubba) #endif /* SET_PROG_COUNTER */
a8e2ec2001-07-17Henrik Grubbström (Grubba) 
f822262001-07-16Fredrik Hübinette (Hubbe) #undef DONE #undef FETCH #undef INTER_RETURN #undef INTER_ESCAPE_CATCH #define DONE return #define FETCH
a8e2ec2001-07-17Henrik Grubbström (Grubba) #define INTER_RETURN {SET_PROG_COUNTER(do_inter_return_label);DONE;} #define INTER_ESCAPE_CATCH {SET_PROG_COUNTER(do_escape_catch_label);DONE;}
f822262001-07-16Fredrik Hübinette (Hubbe)  #include "interpret_functions_fixed.h" #else /* PIKE_USE_MACHINE_CODE */
7b2c002001-07-18Henrik Grubbström (Grubba) #ifndef SET_PROG_COUNTER #define SET_PROG_COUNTER(X) (PROG_COUNTER=(X)) #endif /* SET_PROG_COUNTER */
afa1c62001-07-09Henrik Grubbström (Grubba) #ifdef HAVE_COMPUTED_GOTO int lookup_sort_fun(const void *a, const void *b) { return (int)(((ptrdiff_t)((struct op_2_f *)a)->opcode) - ((ptrdiff_t)((struct op_2_f *)b)->opcode)); } #endif /* HAVE_COMPUTED_GOTO */
88149c2001-07-08Henrik Grubbström (Grubba) /* NOTE: Due to the implementation of computed goto, * interpreter.h may only be included once. */ #if defined(PIKE_DEBUG) && !defined(HAVE_COMPUTED_GOTO)
7d7d7e1999-01-31Fredrik Hübinette (Hubbe) #define eval_instruction eval_instruction_with_debug
d49add2001-04-25Fredrik Hübinette (Hubbe) #include "interpreter_debug.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7d7d7e1999-01-31Fredrik Hübinette (Hubbe) #undef eval_instruction #define eval_instruction eval_instruction_without_debug
f822262001-07-16Fredrik Hübinette (Hubbe) 
7d7d7e1999-01-31Fredrik Hübinette (Hubbe) #undef PIKE_DEBUG
f822262001-07-16Fredrik Hübinette (Hubbe) #undef NDEBUG #undef DO_IF_DEBUG #define DO_IF_DEBUG(X)
7d7d7e1999-01-31Fredrik Hübinette (Hubbe) #define print_return_value() #include "interpreter.h"
f822262001-07-16Fredrik Hübinette (Hubbe) 
7d7d7e1999-01-31Fredrik Hübinette (Hubbe) #define PIKE_DEBUG
f822262001-07-16Fredrik Hübinette (Hubbe) #define NDEBUG #undef DO_IF_DEBUG #define DO_IF_DEBUG(X) X #undef print_return_value
7d7d7e1999-01-31Fredrik Hübinette (Hubbe) #undef eval_instruction
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7d7d7e1999-01-31Fredrik Hübinette (Hubbe) static inline int eval_instruction(unsigned char *pc) {
97ebb32003-01-09Henrik Grubbström (Grubba)  if(d_flag || Pike_interpreter.trace_level>2)
7d7d7e1999-01-31Fredrik Hübinette (Hubbe)  return eval_instruction_with_debug(pc); else return eval_instruction_without_debug(pc); }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
7d7d7e1999-01-31Fredrik Hübinette (Hubbe) #else #include "interpreter.h"
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #endif
a599231996-09-25Fredrik Hübinette (Hubbe) 
f822262001-07-16Fredrik Hübinette (Hubbe)  #endif /* PIKE_USE_MACHINE_CODE */
cd83521998-02-02Fredrik Hübinette (Hubbe) static void trace_return_value(void) { char *s; init_buf(); my_strcat("Return: ");
f077582000-07-06Fredrik Hübinette (Hubbe)  describe_svalue(Pike_sp-1,0,0);
cd83521998-02-02Fredrik Hübinette (Hubbe)  s=simple_free_buf();
6d8c692000-08-08Henrik Grubbström (Grubba)  if((size_t)strlen(s) > (size_t)TRACE_LEN)
cd83521998-02-02Fredrik Hübinette (Hubbe)  { s[TRACE_LEN]=0; s[TRACE_LEN-1]='.'; s[TRACE_LEN-2]='.'; s[TRACE_LEN-2]='.'; } fprintf(stderr,"%-*s%s\n",4,"-",s); free(s); } static void do_trace_call(INT32 args) {
50edc82001-07-13Henrik Grubbström (Grubba)  struct pike_string *filep = NULL; char *file, *s;
cd83521998-02-02Fredrik Hübinette (Hubbe)  INT32 linep,e; my_strcat("("); for(e=0;e<args;e++) { if(e) my_strcat(",");
f077582000-07-06Fredrik Hübinette (Hubbe)  describe_svalue(Pike_sp-args+e,0,0);
cd83521998-02-02Fredrik Hübinette (Hubbe)  } my_strcat(")"); s=simple_free_buf();
6d8c692000-08-08Henrik Grubbström (Grubba)  if((size_t)strlen(s) > (size_t)TRACE_LEN)
cd83521998-02-02Fredrik Hübinette (Hubbe)  { s[TRACE_LEN]=0; s[TRACE_LEN-1]='.'; s[TRACE_LEN-2]='.'; s[TRACE_LEN-2]='.'; }
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_fp && Pike_fp->pc)
cd83521998-02-02Fredrik Hübinette (Hubbe)  { char *f;
50edc82001-07-13Henrik Grubbström (Grubba)  filep = get_line(Pike_fp->pc,Pike_fp->context.prog,&linep); file = filep->str; while((f=STRCHR(file,'/'))) file=f+1;
cd83521998-02-02Fredrik Hübinette (Hubbe)  }else{ linep=0; file="-"; } fprintf(stderr,"- %s:%4ld: %s\n",file,(long)linep,s);
50edc82001-07-13Henrik Grubbström (Grubba)  if (filep) { free_string(filep); }
cd83521998-02-02Fredrik Hübinette (Hubbe)  free(s); }
4218011999-01-31Fredrik Hübinette (Hubbe)  #undef INIT_BLOCK
92fb222001-05-13Fredrik Hübinette (Hubbe) #define INIT_BLOCK(X) do { \
50ea682003-03-14Henrik Grubbström (Grubba)  X->refs=0; \ add_ref(X); /* For DMALLOC... */ \
92fb222001-05-13Fredrik Hübinette (Hubbe)  X->flags=0; \ X->scope=0; \
bc8ea62001-05-14Henrik Grubbström (Grubba)  DO_IF_SECURITY( if(CURRENT_CREDS) { \ add_ref(X->current_creds=CURRENT_CREDS); \ } else { \ X->current_creds = 0; \ }) \
92fb222001-05-13Fredrik Hübinette (Hubbe) }while(0)
4218011999-01-31Fredrik Hübinette (Hubbe)  #undef EXIT_BLOCK
fa21262001-08-31Fredrik Hübinette (Hubbe) #define EXIT_BLOCK(X) do { \ free_object(X->current_object); \ if(X->context.prog) free_program(X->context.prog); \ if(X->context.parent) free_object(X->context.parent); \ if(X->scope) free_pike_scope(X->scope); \ DO_IF_SECURITY( if(X->current_creds) { \ free_object(X->current_creds); \ }) \ DO_IF_DEBUG( \ if(X->flags & PIKE_FRAME_MALLOCED_LOCALS) \
5aad932002-08-15Marcus Comstedt  Pike_fatal("Pike frame is not supposed to have malloced locals here!\n")); \
50ea682003-03-14Henrik Grubbström (Grubba)  \
fa21262001-08-31Fredrik Hübinette (Hubbe)  DO_IF_DMALLOC( \ X->context.prog=0; \ X->context.parent=0; \ X->context.name=0; \ X->scope=0; \ X->current_object=0; \ X->flags=0; \ X->expendible=0; \ X->locals=0; \ DO_IF_SECURITY( X->current_creds=0; ) \ ) \
4218011999-01-31Fredrik Hübinette (Hubbe) }while(0)
3aab372002-11-24Martin Stjernholm BLOCK_ALLOC_FILL_PAGES(pike_frame, 4)
fa21262001-08-31Fredrik Hübinette (Hubbe)  void really_free_pike_scope(struct pike_frame *scope) { if(scope->flags & PIKE_FRAME_MALLOCED_LOCALS) { free_mixed_svalues(scope->locals,scope->num_locals); free((char *)(scope->locals)); #ifdef PIKE_DEBUG scope->flags&=~PIKE_FRAME_MALLOCED_LOCALS; #endif } really_free_pike_frame(scope); }
4218011999-01-31Fredrik Hübinette (Hubbe) 
28498e2002-11-09Henrik Grubbström (Grubba) /* Apply a function. * * Application types: * * APPLY_STACK: Apply Pike_sp[-args] with args-1 arguments. * * APPLY_SVALUE: Apply the svalue at arg1, and adjust the stack * to leave a return value. * * APPLY_SVALUE_STRICT: Apply the svalue at arg1, and don't adjust the * stack for functions that return void. * * APPLY_LOW: Apply function #arg2 in object arg1. * * Return values: * * Returns zero if the function was invalid or has been executed. * * Returns one if a frame has been set up to start the function * with eval_instruction(Pike_fp->pc - ENTRY_PROLOGUE_SIZE). After * eval_instruction() is done the frame needs to be removed by a call * to low_return() or low_return_pop(). */
f663c92003-04-03Henrik Grubbström (Grubba) int low_mega_apply(enum apply_type type, INT32 args, void *arg1, void *arg2)
9ddbf22001-05-10Fredrik Hübinette (Hubbe) { struct object *o; struct pike_frame *scope=0; ptrdiff_t fun; struct svalue *save_sp=Pike_sp-args; #if defined(PIKE_DEBUG) && defined(_REENTRANT) if(d_flag) { THREAD_T self = th_self(); CHECK_INTERPRETER_LOCK();
0431312003-02-15Henrik Grubbström (Grubba)  if( Pike_interpreter.thread_state && !th_equal(Pike_interpreter.thread_state->id, self) )
5aad932002-08-15Marcus Comstedt  Pike_fatal("Current thread is wrong.\n");
442be32003-02-16Henrik Grubbström (Grubba)  DEBUG_CHECK_THREAD();
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  } #endif switch(type) { case APPLY_STACK: if(!args) PIKE_ERROR("`()", "Too few arguments (apply stack).\n", Pike_sp, 0); args--; arg1=(void *)(Pike_sp-args-1); case APPLY_SVALUE:
24c37f2001-05-24Fredrik Hübinette (Hubbe)  case APPLY_SVALUE_STRICT:
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  apply_svalue: { struct svalue *s=(struct svalue *)arg1; switch(s->type) { case T_INT: if (!s->u.integer) { PIKE_ERROR("0", "Attempt to call the NULL-value\n", Pike_sp, args); } else { Pike_error("Attempt to call the value %"PRINTPIKEINT"d\n", s->u.integer); } case T_STRING: if (s->u.string->len > 20) { Pike_error("Attempt to call the string \"%20s\"...\n", s->u.string->str); } else { Pike_error("Attempt to call the string \"%s\"\n", s->u.string->str); } case T_MAPPING: Pike_error("Attempt to call a mapping\n"); default: Pike_error("Call to non-function value type:%s.\n", get_name_of_type(s->type)); case T_FUNCTION: if(s->subtype == FUNCTION_BUILTIN) { #ifdef PIKE_DEBUG struct svalue *expected_stack = Pike_sp-args;
97ebb32003-01-09Henrik Grubbström (Grubba)  if(Pike_interpreter.trace_level>1)
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  { init_buf(); describe_svalue(s,0,0); do_trace_call(args); } #endif
f19fc72002-09-14Martin Stjernholm  check_threads_etc();
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  (*(s->u.efun->function))(args); #ifdef PIKE_DEBUG
d9a93b2001-07-01Fredrik Hübinette (Hubbe)  s->u.efun->runs++;
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  if(Pike_sp != expected_stack + !s->u.efun->may_return_void) { if(Pike_sp < expected_stack)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Function popped too many arguments: %s\n",
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  s->u.efun->name->str); if(Pike_sp>expected_stack+1)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Function left droppings on stack: %s\n",
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  s->u.efun->name->str); if(Pike_sp == expected_stack && !s->u.efun->may_return_void)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Non-void function returned without return value on stack: %s %d\n",
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  s->u.efun->name->str,s->u.efun->may_return_void); if(Pike_sp==expected_stack+1 && s->u.efun->may_return_void)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Void function returned with a value on the stack: %s %d\n",
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  s->u.efun->name->str, s->u.efun->may_return_void); } #endif break; }else{
70be662001-06-19Fredrik Hübinette (Hubbe)  type=APPLY_SVALUE;
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  o=s->u.object;
87338f2003-01-15Martin Stjernholm  if(o->prog == pike_trampoline_program && s->subtype == QUICK_FIND_LFUN(pike_trampoline_program, LFUN_CALL))
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  { fun=((struct pike_trampoline *)(o->storage))->func; scope=((struct pike_trampoline *)(o->storage))->frame; o=scope->current_object; goto apply_low_with_scope; } fun=s->subtype; goto apply_low; } break; case T_ARRAY: #ifdef PIKE_DEBUG
97ebb32003-01-09Henrik Grubbström (Grubba)  if(Pike_interpreter.trace_level>1)
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  { init_buf(); describe_svalue(s,0,0); do_trace_call(args); } #endif apply_array(s->u.array,args); break; case T_PROGRAM: #ifdef PIKE_DEBUG
97ebb32003-01-09Henrik Grubbström (Grubba)  if(Pike_interpreter.trace_level>1)
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  { init_buf(); describe_svalue(s,0,0); do_trace_call(args); } #endif push_object(clone_object(s->u.program,args)); break; case T_OBJECT: o=s->u.object; if(o->prog == pike_trampoline_program) { fun=((struct pike_trampoline *)(o->storage))->func; scope=((struct pike_trampoline *)(o->storage))->frame; o=scope->current_object; goto apply_low_with_scope; } fun=LFUN_CALL;
70be662001-06-19Fredrik Hübinette (Hubbe)  type=APPLY_SVALUE;
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  goto call_lfun; } break; } call_lfun: #ifdef PIKE_DEBUG if(fun < 0 || fun >= NUM_LFUNS)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Apply lfun on illegal value!\n");
9ddbf22001-05-10Fredrik Hübinette (Hubbe) #endif if(!o->prog) PIKE_ERROR("destructed object", "Apply on destructed object.\n", Pike_sp, args); fun = FIND_LFUN(o->prog, fun); goto apply_low; case APPLY_LOW: o = (struct object *)arg1;
3071982003-01-05Henrik Grubbström (Grubba)  fun = ((char *)arg2) - (char *)0;
87338f2003-01-15Martin Stjernholm  if(o->prog == pike_trampoline_program && fun == QUICK_FIND_LFUN(pike_trampoline_program, LFUN_CALL)) { fun=((struct pike_trampoline *)(o->storage))->func; scope=((struct pike_trampoline *)(o->storage))->frame; o=scope->current_object; goto apply_low_with_scope; }
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  apply_low:
4b05702001-08-30Fredrik Hübinette (Hubbe) #undef SCOPE #include "apply_low.h" break;
9ddbf22001-05-10Fredrik Hübinette (Hubbe) 
4b05702001-08-30Fredrik Hübinette (Hubbe)  apply_low_with_scope: #define SCOPE scope #include "apply_low.h" break;
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  } if(save_sp+1 > Pike_sp) {
24c37f2001-05-24Fredrik Hübinette (Hubbe)  if(type != APPLY_SVALUE_STRICT)
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  push_int(0); }else{
4b05702001-08-30Fredrik Hübinette (Hubbe)  if(save_sp+1 < Pike_sp) { assign_svalue(save_sp,Pike_sp-1); pop_n_elems(Pike_sp-save_sp-1); low_destruct_objects_to_destruct(); /* consider using a flag for immediate destruct instead... */
9655602001-08-30Fredrik Hübinette (Hubbe) 
4b05702001-08-30Fredrik Hübinette (Hubbe)  }
97ebb32003-01-09Henrik Grubbström (Grubba)  if(Pike_interpreter.trace_level>1) trace_return_value();
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  }
f663c92003-04-03Henrik Grubbström (Grubba)  return 0;
9ddbf22001-05-10Fredrik Hübinette (Hubbe) }
2ac9502001-08-14Fredrik Hübinette (Hubbe)  #define low_return_profiling()
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  #ifdef PROFILING #ifdef HAVE_GETHRTIME
2ac9502001-08-14Fredrik Hübinette (Hubbe) #undef low_return_profiling #define low_return_profiling() do { \ struct identifier *function; \ long long time_passed, time_in_children, self_time; \ time_in_children=Pike_interpreter.accounted_time-Pike_fp->children_base; \ time_passed = gethrtime()-Pike_interpreter.time_base - Pike_fp->start_time; \ self_time=time_passed - time_in_children; \ Pike_interpreter.accounted_time+=self_time; \ function = Pike_fp->context.prog->identifiers + Pike_fp->ident; \ function->total_time=Pike_fp->self_time_base + (INT32)(time_passed /1000); \ function->self_time+=(INT32)( self_time /1000); \ }while(0)
9ddbf22001-05-10Fredrik Hübinette (Hubbe) #endif #endif
2ac9502001-08-14Fredrik Hübinette (Hubbe) #define basic_low_return() \ struct svalue *save_sp=Pike_fp->save_sp; \ DO_IF_DEBUG( \ if(Pike_mark_sp < Pike_fp->save_mark_sp) \
5aad932002-08-15Marcus Comstedt  Pike_fatal("Popped below save_mark_sp!\n"); \
2ac9502001-08-14Fredrik Hübinette (Hubbe)  if(Pike_sp<Pike_interpreter.evaluator_stack) \
5aad932002-08-15Marcus Comstedt  Pike_fatal("Stack error (also simple).\n"); \
2ac9502001-08-14Fredrik Hübinette (Hubbe)  ) \ \ Pike_mark_sp=Pike_fp->save_mark_sp; \ \ POP_PIKE_FRAME() void low_return(void) { basic_low_return();
9655602001-08-30Fredrik Hübinette (Hubbe)  if(save_sp+1 > Pike_sp)
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  { push_int(0); }else{
9655602001-08-30Fredrik Hübinette (Hubbe)  if(save_sp+1 < Pike_sp) { assign_svalue(save_sp,Pike_sp-1); pop_n_elems(Pike_sp-save_sp-1); /* consider using a flag for immediate destruct instead... */ destruct_objects_to_destruct(); }
97ebb32003-01-09Henrik Grubbström (Grubba)  if(Pike_interpreter.trace_level>1) trace_return_value();
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  } }
2ac9502001-08-14Fredrik Hübinette (Hubbe) void low_return_pop(void) { basic_low_return(); if(save_sp < Pike_sp) { pop_n_elems(Pike_sp-save_sp); /* consider using a flag for immediate destruct instead... */ destruct_objects_to_destruct(); } }
9ddbf22001-05-10Fredrik Hübinette (Hubbe) void unlink_previous_frame(void) { struct pike_frame *current, *prev; struct svalue *target, **smsp; int freespace;
3958992001-06-23Fredrik Hübinette (Hubbe) 
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  current=Pike_interpreter.frame_pointer;
3958992001-06-23Fredrik Hübinette (Hubbe)  prev=current->next; #ifdef PIKE_DEBUG { JMP_BUF *rec; if((rec=Pike_interpreter.recoveries)) { while(rec->frame_pointer == current) rec=rec->previous; if(rec->frame_pointer == current->next)
5aad932002-08-15Marcus Comstedt  Pike_fatal("You can't touch this!\n");
3958992001-06-23Fredrik Hübinette (Hubbe)  } } #endif Pike_interpreter.frame_pointer=prev;
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  target=prev->save_sp; smsp=prev->save_mark_sp; current->flags=prev->flags; POP_PIKE_FRAME(); prev=current->next=Pike_interpreter.frame_pointer; Pike_interpreter.frame_pointer=current; current->save_sp=target; current->save_mark_sp=smsp; /* Move svalues down */
d1d2b52002-05-11Martin Nilsson  freespace=Pike_fp->locals - target; if(freespace > ((Pike_sp - Pike_fp->locals)<<2) + 32)
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  { assign_svalues(target,
d1d2b52002-05-11Martin Nilsson  Pike_fp->locals, Pike_sp - Pike_fp->locals,
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  BIT_MIXED);
d1d2b52002-05-11Martin Nilsson  Pike_fp->locals-=freespace; Pike_fp->expendible-=freespace;
105ade2001-05-13Fredrik Hübinette (Hubbe)  pop_n_elems(freespace);
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  } /* Move pointers down */
d1d2b52002-05-11Martin Nilsson  freespace=Pike_fp->mark_sp_base - smsp; if(freespace > ((Pike_mark_sp - Pike_fp->mark_sp_base)<<2)+32)
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  { MEMMOVE(smsp,
d1d2b52002-05-11Martin Nilsson  Pike_fp->mark_sp_base, sizeof(struct svalue **)*(Pike_mark_sp - Pike_fp->mark_sp_base)); Pike_fp->mark_sp_base-=freespace;
105ade2001-05-13Fredrik Hübinette (Hubbe)  Pike_mark_sp-=freespace;
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  } }
4218011999-01-31Fredrik Hübinette (Hubbe) 
92fb222001-05-13Fredrik Hübinette (Hubbe) void mega_apply(enum apply_type type, INT32 args, void *arg1, void *arg2)
9ddbf22001-05-10Fredrik Hübinette (Hubbe) {
032a812001-08-18Fredrik Hübinette (Hubbe)  check_c_stack(8192);
f663c92003-04-03Henrik Grubbström (Grubba)  if(low_mega_apply(type, args, arg1, arg2))
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  {
1c9ebc2001-07-24Henrik Grubbström (Grubba)  eval_instruction(Pike_fp->pc #ifdef ENTRY_PROLOGUE_SIZE - ENTRY_PROLOGUE_SIZE #endif /* ENTRY_PROLOGUE_SIZE */ );
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  low_return(); } }
4218011999-01-31Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
b208c11996-08-03Fredrik Hübinette (Hubbe) /* Put catch outside of eval_instruction, so * the setjmp won't affect the optimization of * eval_instruction
28498e2002-11-09Henrik Grubbström (Grubba)  * * Returns 0 on throw. * * Returns 1 if the code performed a RETURN. * * Returns 2 if the code performed EXIT_CATCH or ESCAPE_CATCH.
b208c11996-08-03Fredrik Hübinette (Hubbe)  */
eff6212001-07-09Henrik Grubbström (Grubba) static int o_catch(PIKE_OPCODE_T *pc)
b208c11996-08-03Fredrik Hübinette (Hubbe) { JMP_BUF tmp;
f077582000-07-06Fredrik Hübinette (Hubbe)  struct svalue *expendible=Pike_fp->expendible;
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  int flags=Pike_fp->flags;
f077582000-07-06Fredrik Hübinette (Hubbe)  debug_malloc_touch(Pike_fp);
b208c11996-08-03Fredrik Hübinette (Hubbe)  if(SETJMP(tmp)) {
f077582000-07-06Fredrik Hübinette (Hubbe)  *Pike_sp=throw_value;
b208c11996-08-03Fredrik Hübinette (Hubbe)  throw_value.type=T_INT;
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_sp++;
50ea682003-03-14Henrik Grubbström (Grubba)  dmalloc_touch_svalue(Pike_sp-1);
b208c11996-08-03Fredrik Hübinette (Hubbe)  UNSETJMP(tmp);
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_fp->expendible=expendible;
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  Pike_fp->flags=flags;
2ac9502001-08-14Fredrik Hübinette (Hubbe)  low_destruct_objects_to_destruct();
b208c11996-08-03Fredrik Hübinette (Hubbe)  return 0; }else{
fc26f62000-07-06Fredrik Hübinette (Hubbe)  struct svalue **save_mark_sp=Pike_mark_sp;
d265191998-07-28Fredrik Hübinette (Hubbe)  int x;
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_fp->expendible=Pike_fp->locals + Pike_fp->num_locals;
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  Pike_fp->flags&=~PIKE_FRAME_RETURN_INTERNAL;
d265191998-07-28Fredrik Hübinette (Hubbe)  x=eval_instruction(pc);
cfa1db2000-05-01Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
fc26f62000-07-06Fredrik Hübinette (Hubbe)  if(Pike_mark_sp < save_mark_sp)
5aad932002-08-15Marcus Comstedt  Pike_fatal("mark Pike_sp underflow in catch.\n");
cfa1db2000-05-01Fredrik Hübinette (Hubbe) #endif
fc26f62000-07-06Fredrik Hübinette (Hubbe)  Pike_mark_sp=save_mark_sp;
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_fp->expendible=expendible;
9ddbf22001-05-10Fredrik Hübinette (Hubbe)  Pike_fp->flags=flags;
105ade2001-05-13Fredrik Hübinette (Hubbe)  if(x>=0) mega_apply(APPLY_STACK, x, 0,0); /* Should never happen */
b208c11996-08-03Fredrik Hübinette (Hubbe)  UNSETJMP(tmp);
b7c1ee2001-01-10Martin Stjernholm  return x == -2 ? 2 : 1;
b208c11996-08-03Fredrik Hübinette (Hubbe)  } }
7c0df72001-02-06Henrik Grubbström (Grubba) /*! @decl mixed call_function(function fun, mixed ... args) *! *! Call a function. */
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void f_call_function(INT32 args)
3c0c281998-01-26Fredrik Hübinette (Hubbe) { mega_apply(APPLY_STACK,args,0,0); }
ea3b2d2002-12-07Henrik Grubbström (Grubba) /*! @class MasterObject */ /*! @decl void handle_error(mixed exception) *! *! Called by the Pike runtime if an exception isn't caught. *!
b5cd8a2002-12-07Henrik Grubbström (Grubba)  *! @param exception
ea3b2d2002-12-07Henrik Grubbström (Grubba)  *! Value that was @[throw()]'n. *! *! @seealso *! @[describe_backtrace()] */ /*! @endclass */
6697042000-11-20Martin Stjernholm PMOD_EXPORT void call_handle_error(void) {
eaa4da2001-10-04Fredrik Hübinette (Hubbe)  dmalloc_touch_svalue(&throw_value);
6697042000-11-20Martin Stjernholm  if (Pike_interpreter.svalue_stack_margin) { ONERROR tmp;
97ebb32003-01-09Henrik Grubbström (Grubba)  int old_t_flag = Pike_interpreter.trace_level; Pike_interpreter.trace_level = 0;
6697042000-11-20Martin Stjernholm  Pike_interpreter.svalue_stack_margin = 0; Pike_interpreter.c_stack_margin = 0; SET_ONERROR(tmp,exit_on_error,"Error in handle_error in master object!");
a2988f2001-06-08Martin Stjernholm  *(Pike_sp++) = throw_value;
50ea682003-03-14Henrik Grubbström (Grubba)  dmalloc_touch_svalue(Pike_sp-1);
a2988f2001-06-08Martin Stjernholm  throw_value.type=T_INT;
6697042000-11-20Martin Stjernholm  APPLY_MASTER("handle_error", 1); pop_stack(); UNSET_ONERROR(tmp); Pike_interpreter.svalue_stack_margin = SVALUE_STACK_MARGIN; Pike_interpreter.c_stack_margin = C_STACK_MARGIN;
97ebb32003-01-09Henrik Grubbström (Grubba)  Pike_interpreter.trace_level = old_t_flag;
6697042000-11-20Martin Stjernholm  }
a2988f2001-06-08Martin Stjernholm  else { free_svalue(&throw_value); throw_value.type=T_INT; }
6697042000-11-20Martin Stjernholm }
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT int apply_low_safe_and_stupid(struct object *o, INT32 offset)
5267b71995-08-09Fredrik Hübinette (Hubbe) { JMP_BUF tmp;
4218011999-01-31Fredrik Hübinette (Hubbe)  struct pike_frame *new_frame=alloc_pike_frame();
5267b71995-08-09Fredrik Hübinette (Hubbe)  int ret;
3601d32002-11-23Martin Stjernholm  /* FIXME: Is this up-to-date with mega_apply? */
f077582000-07-06Fredrik Hübinette (Hubbe)  new_frame->next = Pike_fp;
4218011999-01-31Fredrik Hübinette (Hubbe)  new_frame->current_object = o; new_frame->context=o->prog->inherits[0];
f077582000-07-06Fredrik Hübinette (Hubbe)  new_frame->locals = Pike_interpreter.evaluator_stack;
4218011999-01-31Fredrik Hübinette (Hubbe)  new_frame->expendible=new_frame->locals; new_frame->args = 0; new_frame->num_args=0; new_frame->num_locals=0;
e463872000-04-03Fredrik Hübinette (Hubbe)  new_frame->fun = o->prog->num_identifier_references?o->prog->num_identifier_references-1:0;
4218011999-01-31Fredrik Hübinette (Hubbe)  new_frame->pc = 0; new_frame->current_storage=o->storage; new_frame->context.parent=0;
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_fp = new_frame;
4218011999-01-31Fredrik Hübinette (Hubbe)  add_ref(new_frame->current_object); add_ref(new_frame->context.prog);
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(SETJMP(tmp)) { ret=1; }else{
105ade2001-05-13Fredrik Hübinette (Hubbe)  int tmp; new_frame->mark_sp_base=new_frame->save_mark_sp=Pike_mark_sp; tmp=eval_instruction(o->prog->program + offset);
b7c1ee2001-01-10Martin Stjernholm  EVAL_INSTR_RET_CHECK(tmp);
105ade2001-05-13Fredrik Hübinette (Hubbe)  Pike_mark_sp=new_frame->save_mark_sp;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp<Pike_interpreter.evaluator_stack)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Stack error (simple).\n");
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif ret=0; } UNSETJMP(tmp);
4218011999-01-31Fredrik Hübinette (Hubbe)  POP_PIKE_FRAME();
5267b71995-08-09Fredrik Hübinette (Hubbe)  return ret; }
c1b8f02001-07-02Martin Stjernholm PMOD_EXPORT void safe_apply_low2(struct object *o,int fun,int args, int handle_errors)
5267b71995-08-09Fredrik Hübinette (Hubbe) { JMP_BUF recovery;
dffa011997-01-15Fredrik Hübinette (Hubbe)  free_svalue(& throw_value); throw_value.type=T_INT;
3601d32002-11-23Martin Stjernholm  if(SETJMP_SP(recovery, args))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
c1b8f02001-07-02Martin Stjernholm  if(handle_errors) call_handle_error();
3601d32002-11-23Martin Stjernholm  push_int(0);
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{ apply_low(o,fun,args); } UNSETJMP(recovery); }
c1b8f02001-07-02Martin Stjernholm PMOD_EXPORT void safe_apply_low(struct object *o,int fun,int args) { safe_apply_low2(o, fun, args, 1); }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
b770752002-11-14Marcus Comstedt PMOD_EXPORT void safe_apply(struct object *o, const char *fun ,INT32 args)
5683de1995-11-06Fredrik Hübinette (Hubbe) {
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
5aad932002-08-15Marcus Comstedt  if(!o->prog) Pike_fatal("Apply safe on destructed object.\n");
5683de1995-11-06Fredrik Hübinette (Hubbe) #endif
c1b8f02001-07-02Martin Stjernholm  safe_apply_low2(o, find_identifier(fun, o->prog), args, 1);
5683de1995-11-06Fredrik Hübinette (Hubbe) }
61863e2001-12-20Martin Stjernholm /* Returns nonzero if the function was called in some handler. */ PMOD_EXPORT int low_unsafe_apply_handler(const char *fun, struct object *handler, struct object *compat, INT32 args) { int i; #if 0 fprintf(stderr, "low_unsafe_apply_handler(\"%s\", 0x%08p, 0x%08p, %d)\n", fun, handler, compat, args); #endif /* 0 */ if (handler && handler->prog && (i = find_identifier(fun, handler->prog)) != -1) { apply_low(handler, i, args); } else if (compat && compat->prog && (i = find_identifier(fun, compat->prog)) != -1) { apply_low(compat, i, args); } else {
9abc252002-09-21Martin Stjernholm  struct object *master_obj = get_master(); if (master_obj && (i = find_identifier(fun, master_obj->prog)) != -1)
61863e2001-12-20Martin Stjernholm  apply_low(master_obj, i, args); else { pop_n_elems(args); push_undefined(); return 0; } } return 1; }
9036e82001-08-16Martin Stjernholm PMOD_EXPORT void low_safe_apply_handler(const char *fun, struct object *handler, struct object *compat, INT32 args)
c3805a2001-06-08Henrik Grubbström (Grubba) { int i;
68296f2001-07-07Henrik Grubbström (Grubba) #if 0
9036e82001-08-16Martin Stjernholm  fprintf(stderr, "low_safe_apply_handler(\"%s\", 0x%08p, 0x%08p, %d)\n",
68296f2001-07-07Henrik Grubbström (Grubba)  fun, handler, compat, args); #endif /* 0 */
6991a22001-06-11Henrik Grubbström (Grubba)  if (handler && handler->prog &&
c3805a2001-06-08Henrik Grubbström (Grubba)  (i = find_identifier(fun, handler->prog)) != -1) {
9036e82001-08-16Martin Stjernholm  safe_apply_low2(handler, i, args, 1);
6991a22001-06-11Henrik Grubbström (Grubba)  } else if (compat && compat->prog &&
2174722001-06-08Henrik Grubbström (Grubba)  (i = find_identifier(fun, compat->prog)) != -1) {
9036e82001-08-16Martin Stjernholm  safe_apply_low2(compat, i, args, 1);
c3805a2001-06-08Henrik Grubbström (Grubba)  } else {
2174722001-06-08Henrik Grubbström (Grubba)  struct object *master_obj = master();
dd79492001-08-15Martin Stjernholm  if ((i = find_identifier(fun, master_obj->prog)) != -1)
9036e82001-08-16Martin Stjernholm  safe_apply_low2(master_obj, i, args, 1);
dd79492001-08-15Martin Stjernholm  else { pop_n_elems(args); push_undefined(); }
c1b8f02001-07-02Martin Stjernholm  }
9036e82001-08-16Martin Stjernholm }
6d8e742002-11-11Henrik Grubbström (Grubba) /* NOTE: Returns 1 if result on stack, 0 otherwise. */
9036e82001-08-16Martin Stjernholm PMOD_EXPORT int safe_apply_handler(const char *fun, struct object *handler, struct object *compat, INT32 args, TYPE_FIELD rettypes) { JMP_BUF recovery;
89ee9e2002-10-28Martin Nilsson  int ret;
6d8e742002-11-11Henrik Grubbström (Grubba)  STACK_LEVEL_START(args);
9036e82001-08-16Martin Stjernholm #if 0 fprintf(stderr, "safe_apply_handler(\"%s\", 0x%08p, 0x%08p, %d)\n", fun, handler, compat, args); #endif /* 0 */ free_svalue(& throw_value); throw_value.type=T_INT;
3601d32002-11-23Martin Stjernholm  if (SETJMP_SP(recovery, args)) {
9036e82001-08-16Martin Stjernholm  ret = 0;
6d8e742002-11-11Henrik Grubbström (Grubba)  } else {
61863e2001-12-20Martin Stjernholm  if (low_unsafe_apply_handler (fun, handler, compat, args) &&
9abc252002-09-21Martin Stjernholm  rettypes && !((1 << Pike_sp[-1].type) & rettypes)) { if ((rettypes & BIT_ZERO) && SAFE_IS_ZERO (Pike_sp - 1)) { pop_stack(); push_int(0); } else { push_constant_text("Invalid return value from %s: %O\n"); push_text(fun); push_svalue(Pike_sp - 3); f_sprintf(3); if (!Pike_sp[-1].u.string->size_shift) Pike_error("%s", Pike_sp[-1].u.string->str); else Pike_error("Invalid return value from %s\n", fun); }
9036e82001-08-16Martin Stjernholm  } ret = 1;
c3805a2001-06-08Henrik Grubbström (Grubba)  }
9036e82001-08-16Martin Stjernholm  UNSETJMP(recovery);
6d8e742002-11-11Henrik Grubbström (Grubba)  STACK_LEVEL_DONE(ret);
9036e82001-08-16Martin Stjernholm  return ret;
c3805a2001-06-08Henrik Grubbström (Grubba) }
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void apply_lfun(struct object *o, int fun, int args)
fa382f1996-06-21Fredrik Hübinette (Hubbe) {
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
fa382f1996-06-21Fredrik Hübinette (Hubbe)  if(fun < 0 || fun >= NUM_LFUNS)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Apply lfun on illegal value!\n");
fa382f1996-06-21Fredrik Hübinette (Hubbe) #endif if(!o->prog)
f077582000-07-06Fredrik Hübinette (Hubbe)  PIKE_ERROR("destructed object", "Apply on destructed object.\n", Pike_sp, args);
fa382f1996-06-21Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  apply_low(o, (int)FIND_LFUN(o->prog,fun), args);
fa382f1996-06-21Fredrik Hübinette (Hubbe) }
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void apply_shared(struct object *o,
06983f1996-09-22Fredrik Hübinette (Hubbe)  struct pike_string *fun,
5267b71995-08-09Fredrik Hübinette (Hubbe)  int args) {
fa382f1996-06-21Fredrik Hübinette (Hubbe)  apply_low(o, find_shared_string_identifier(fun, o->prog), args);
5267b71995-08-09Fredrik Hübinette (Hubbe) }
b770752002-11-14Marcus Comstedt PMOD_EXPORT void apply(struct object *o, const char *fun, int args)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
fa382f1996-06-21Fredrik Hübinette (Hubbe)  apply_low(o, find_identifier(fun, o->prog), args);
5267b71995-08-09Fredrik Hübinette (Hubbe) }
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void apply_svalue(struct svalue *s, INT32 args)
5267b71995-08-09Fredrik Hübinette (Hubbe) { if(s->type==T_INT) { pop_n_elems(args); push_int(0); }else{
6d8c692000-08-08Henrik Grubbström (Grubba)  ptrdiff_t expected_stack=Pike_sp-args+1 - Pike_interpreter.evaluator_stack;
fa382f1996-06-21Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  strict_apply_svalue(s,args);
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp > (expected_stack + Pike_interpreter.evaluator_stack))
f6f02d1995-10-16Fredrik Hübinette (Hubbe)  {
f077582000-07-06Fredrik Hübinette (Hubbe)  pop_n_elems(Pike_sp-(expected_stack + Pike_interpreter.evaluator_stack));
f6f02d1995-10-16Fredrik Hübinette (Hubbe)  }
f077582000-07-06Fredrik Hübinette (Hubbe)  else if(Pike_sp < (expected_stack + Pike_interpreter.evaluator_stack))
f6f02d1995-10-16Fredrik Hübinette (Hubbe)  { push_int(0); }
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp < (expected_stack + Pike_interpreter.evaluator_stack))
5aad932002-08-15Marcus Comstedt  Pike_fatal("Stack underflow!\n");
f6f02d1995-10-16Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
9335ea2003-01-17Henrik Grubbström (Grubba) /* Apply function @[fun] in parent @[depth] levels up with @[args] arguments. */ PMOD_EXPORT void apply_external(int depth, int fun, INT32 args) { struct external_variable_context loc; loc.o = Pike_fp->current_object; if (!loc.o->prog) Pike_error("Cannot access parent of destructed object.\n"); loc.parent_identifier = Pike_fp->fun; loc.inherit = INHERIT_FROM_INT(loc.o->prog, Pike_fp->fun); find_external_context(&loc, depth); apply_low(loc.o, fun + loc.inherit->identifier_level, args); }
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
be478c1997-08-30Henrik Grubbström (Grubba) void slow_check_stack(void)
5267b71995-08-09Fredrik Hübinette (Hubbe) { struct svalue *s,**m;
4218011999-01-31Fredrik Hübinette (Hubbe)  struct pike_frame *f;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
fa382f1996-06-21Fredrik Hübinette (Hubbe)  debug_check_stack();
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7965d72001-01-24Fredrik Hübinette (Hubbe)  if(Pike_sp > &(Pike_interpreter.evaluator_stack[Pike_stack_size]))
5aad932002-08-15Marcus Comstedt  Pike_fatal("Svalue stack overflow. "
6f95902000-08-17Henrik Grubbström (Grubba)  "(%ld entries on stack, stack_size is %ld entries)\n", PTRDIFF_T_TO_LONG(Pike_sp - Pike_interpreter.evaluator_stack),
7965d72001-01-24Fredrik Hübinette (Hubbe)  PTRDIFF_T_TO_LONG(Pike_stack_size));
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7965d72001-01-24Fredrik Hübinette (Hubbe)  if(Pike_mark_sp > &(Pike_interpreter.mark_stack[Pike_stack_size]))
5aad932002-08-15Marcus Comstedt  Pike_fatal("Mark stack overflow.\n");
5267b71995-08-09Fredrik Hübinette (Hubbe) 
fc26f62000-07-06Fredrik Hübinette (Hubbe)  if(Pike_mark_sp < Pike_interpreter.mark_stack)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Mark stack underflow.\n");
5267b71995-08-09Fredrik Hübinette (Hubbe) 
f077582000-07-06Fredrik Hübinette (Hubbe)  for(s=Pike_interpreter.evaluator_stack;s<Pike_sp;s++) check_svalue(s);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
f077582000-07-06Fredrik Hübinette (Hubbe)  s=Pike_interpreter.evaluator_stack;
fc26f62000-07-06Fredrik Hübinette (Hubbe)  for(m=Pike_interpreter.mark_stack;m<Pike_mark_sp;m++)
5267b71995-08-09Fredrik Hübinette (Hubbe)  { if(*m < s)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Mark stack failure.\n");
5267b71995-08-09Fredrik Hübinette (Hubbe)  s=*m; }
7965d72001-01-24Fredrik Hübinette (Hubbe)  if(s > &(Pike_interpreter.evaluator_stack[Pike_stack_size]))
5aad932002-08-15Marcus Comstedt  Pike_fatal("Mark stack exceeds svalue stack\n");
5267b71995-08-09Fredrik Hübinette (Hubbe) 
f077582000-07-06Fredrik Hübinette (Hubbe)  for(f=Pike_fp;f;f=f->next)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
0f887e1996-08-12Fredrik Hübinette (Hubbe)  if(f->locals) {
f077582000-07-06Fredrik Hübinette (Hubbe)  if(f->locals < Pike_interpreter.evaluator_stack ||
7965d72001-01-24Fredrik Hübinette (Hubbe)  f->locals > &(Pike_interpreter.evaluator_stack[Pike_stack_size]))
5aad932002-08-15Marcus Comstedt  Pike_fatal("Local variable pointer points to Finspång.\n");
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7965d72001-01-24Fredrik Hübinette (Hubbe)  if(f->args < 0 || f->args > Pike_stack_size)
5aad932002-08-15Marcus Comstedt  Pike_fatal("FEL FEL FEL! HELP!! (corrupted pike_frame)\n");
0f887e1996-08-12Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
24e1492003-04-27Martin Stjernholm #endif
688f082001-02-27Martin Stjernholm 
9bdebf2001-10-22Martin Stjernholm static const char *safe_idname_from_int(struct program *prog, int func) { /* ID_FROM_INT with a thick layer of checks. */ struct reference *ref; struct inherit *inher; struct identifier *id; if (!prog) return "<null program *>"; if (func < 0 || func >= prog->num_identifier_references) return "<offset outside prog->identifier_references>"; if (!prog->identifier_references) return "<null prog->identifier_references>"; ref = prog->identifier_references + func; if (ref->inherit_offset >= prog->num_inherits) return "<offset outside prog->inherits>"; if (!prog->inherits) return "<null prog->inherits>"; inher = prog->inherits + ref->inherit_offset; prog = inher->prog; if (!prog) return "<null inherited prog>"; if (ref->identifier_offset >= prog->num_identifiers) return "<offset outside inherited prog->identifiers>"; if (!prog->identifiers) return "<null inherited prog->identifiers>"; id = prog->identifiers + ref->identifier_offset; if (!id->name) return "<null identifier->name>"; if (!id->name->str) return "<null identifier->name->str>"; /* FIXME: Wide string identifiers. */ return id->name->str; }
5f152f2001-03-17Henrik Grubbström (Grubba) /*: Prints the Pike backtrace for the interpreter context in the given *: thread to stderr, without messing in the internals (doesn't even *: use dynamic_buffer). *: *: This function is intended only for convenient use inside a *: debugger session; it can't be used from inside the code.
688f082001-02-27Martin Stjernholm  */ void gdb_backtrace ( #ifdef PIKE_THREADS THREAD_T thread_id #endif ) { struct pike_frame *f, *of; #ifdef PIKE_THREADS extern struct thread_state *gdb_thread_state_for_id(THREAD_T); struct thread_state *ts = gdb_thread_state_for_id(thread_id); if (!ts) { fputs ("Not a Pike thread.\n", stderr); return; } if (ts->swapped) f = ts->state.frame_pointer; else f = Pike_fp; #else f = Pike_fp; #endif for (of = 0; f; f = (of = f)->next) if (f->refs) { int args, i;
50edc82001-07-13Henrik Grubbström (Grubba)  struct pike_string *file = NULL;
688f082001-02-27Martin Stjernholm  INT32 line; if (f->context.prog) { if (f->pc) file = get_line (f->pc, f->context.prog, &line); else
4f985f2001-06-30Martin Stjernholm  file = get_program_line (f->context.prog, &line);
688f082001-02-27Martin Stjernholm  }
50edc82001-07-13Henrik Grubbström (Grubba)  if (file) { fprintf (stderr, "%s:%d: ", file->str, line); free_string(file); } else
688f082001-02-27Martin Stjernholm  fputs ("unknown program: ", stderr); if (f->current_object && f->current_object->prog) { /* FIXME: Wide string identifiers. */
9bdebf2001-10-22Martin Stjernholm  fputs (safe_idname_from_int(f->current_object->prog, f->fun), stderr);
688f082001-02-27Martin Stjernholm  fputc ('(', stderr); } else fputs ("unknown function(", stderr); if(!f->locals) { args=0; }else{ args=f->num_args; args = DO_NOT_WARN((INT32) MINIMUM(f->num_args, Pike_sp - f->locals)); if(of) args = DO_NOT_WARN((INT32)MINIMUM(f->num_args,of->locals - f->locals)); args=MAXIMUM(args,0); } for (i = 0; i < args; i++) { struct svalue *arg = f->locals + i; switch (arg->type) { case T_INT: fprintf (stderr, "%ld", (long) arg->u.integer); break; case T_TYPE:
2db4d72001-03-03Henrik Grubbström (Grubba)  /* FIXME: */ fputs("type-value", stderr);
688f082001-02-27Martin Stjernholm  break; case T_STRING: { int i,j=0; fputc ('"', stderr); for(i=0; i < arg->u.string->len && i < 100; i++) { switch(j=index_shared_string(arg->u.string,i)) { case '\n': fputc ('\\', stderr); fputc ('n', stderr); break; case '\t': fputc ('\\', stderr); fputc ('t', stderr); break; case '\b': fputc ('\\', stderr); fputc ('b', stderr); break; case '\r': fputc ('\\', stderr); fputc ('r', stderr); break; case '"': case '\\': fputc ('\\', stderr); fputc (j, stderr); break; default: if(j>=0 && j<256 && isprint(j)) { fputc (j, stderr); break; } fputc ('\\', stderr); fprintf (stderr, "%o", j); switch(index_shared_string(arg->u.string,i+1)) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': fputc ('"', stderr); fputc ('"', stderr); } break; } } fputc ('"', stderr); if (i < arg->u.string->len) fprintf (stderr, "+[%ld]", (long) (arg->u.string->len - i)); break; } case T_FUNCTION: /* FIXME: Wide string identifiers. */ if(arg->subtype == FUNCTION_BUILTIN) fputs (arg->u.efun->name->str, stderr); else if(arg->u.object->prog)
9bdebf2001-10-22Martin Stjernholm  fputs (safe_idname_from_int(arg->u.object->prog,arg->subtype), stderr);
688f082001-02-27Martin Stjernholm  else fputc ('0', stderr); break; case T_OBJECT: { struct program *p = arg->u.object->prog; if (p && p->num_linenumbers) {
4f985f2001-06-30Martin Stjernholm  file = get_program_line (p, &line);
50edc82001-07-13Henrik Grubbström (Grubba)  fprintf (stderr, "object(%s:%d)", file->str, line); free_string(file);
688f082001-02-27Martin Stjernholm  } else fputs ("object", stderr); break; } case T_PROGRAM: { struct program *p = arg->u.program; if (p->num_linenumbers) {
4f985f2001-06-30Martin Stjernholm  file = get_program_line (p, &line);
50edc82001-07-13Henrik Grubbström (Grubba)  fprintf (stderr, "program(%s:%d)", file->str, line); free_string(file);
688f082001-02-27Martin Stjernholm  } else fputs ("program", stderr); break; } case T_FLOAT: fprintf (stderr, "%f",(double) arg->u.float_number); break; case T_ARRAY: fprintf (stderr, "array[%ld]", (long) arg->u.array->size); break; case T_MULTISET:
5b15bb2001-12-10Martin Stjernholm  fprintf (stderr, "multiset[%ld]", (long) multiset_sizeof (arg->u.multiset));
688f082001-02-27Martin Stjernholm  break; case T_MAPPING: fprintf (stderr, "mapping[%ld]", (long) m_sizeof (arg->u.mapping)); break; default: fprintf (stderr, "<Unknown %d>", arg->type); } if (i < args - 1) fputs (", ", stderr); } fputs (")\n", stderr); } else fputs ("frame with no references\n", stderr); }
5f152f2001-03-17Henrik Grubbström (Grubba) /*: Prints the Pike backtraces for the interpreter contexts in all *: Pike threads to stderr, using @[gdb_backtrace]. *: *: This function is intended only for convenient use inside a *: debugger session; it can't be used from inside the program.
688f082001-02-27Martin Stjernholm  */ void gdb_backtraces() { #ifdef PIKE_THREADS extern INT32 gdb_next_thread_state(INT32, struct thread_state **); INT32 i = 0; struct thread_state *ts = 0; while ((i = gdb_next_thread_state (i, &ts)), ts) {
e851e92003-06-06Martin Nilsson  fprintf (stderr, "\nTHREAD_ID %p (swapped %s):\n", (void *)ts->id, ts->swapped ? "out" : "in");
688f082001-02-27Martin Stjernholm  gdb_backtrace (ts->id); } #else gdb_backtrace(); #endif }
66a1572001-01-12Martin Stjernholm PMOD_EXPORT void custom_check_stack(ptrdiff_t amount, const char *fmt, ...)
c915472000-12-04Martin Stjernholm { if (low_stack_check(amount)) { va_list args; va_start(args, fmt); va_error(fmt, args); } }
fa8c692000-11-30Fredrik Hübinette (Hubbe) PMOD_EXPORT void cleanup_interpret(void)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
5267b71995-08-09Fredrik Hübinette (Hubbe)  int e; #endif
f077582000-07-06Fredrik Hübinette (Hubbe)  while(Pike_fp)
424d9c1999-05-02Fredrik Hübinette (Hubbe)  POP_PIKE_FRAME();
5267b71995-08-09Fredrik Hübinette (Hubbe) 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
5267b71995-08-09Fredrik Hübinette (Hubbe)  for(e=0;e<BACKLOG;e++) { if(backlog[e].program) { free_program(backlog[e].program); backlog[e].program=0; } } #endif reset_evaluator();
b208c11996-08-03Fredrik Hübinette (Hubbe)  #ifdef USE_MMAP_FOR_STACK
f077582000-07-06Fredrik Hübinette (Hubbe)  if(!Pike_interpreter.evaluator_stack_malloced)
3c9f631996-09-23Fredrik Hübinette (Hubbe)  {
7965d72001-01-24Fredrik Hübinette (Hubbe)  munmap((char *)Pike_interpreter.evaluator_stack, Pike_stack_size*sizeof(struct svalue));
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_interpreter.evaluator_stack=0;
3c9f631996-09-23Fredrik Hübinette (Hubbe)  }
a8964a2003-03-24Jonas Wallden  if(!Pike_interpreter.mark_stack_malloced)
3c9f631996-09-23Fredrik Hübinette (Hubbe)  {
7965d72001-01-24Fredrik Hübinette (Hubbe)  munmap((char *)Pike_interpreter.mark_stack, Pike_stack_size*sizeof(struct svalue *));
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_interpreter.mark_stack=0;
3c9f631996-09-23Fredrik Hübinette (Hubbe)  }
b208c11996-08-03Fredrik Hübinette (Hubbe) #endif
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_interpreter.evaluator_stack) free((char *)Pike_interpreter.evaluator_stack); if(Pike_interpreter.mark_stack) free((char *)Pike_interpreter.mark_stack);
3c9f631996-09-23Fredrik Hübinette (Hubbe) 
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_interpreter.mark_stack=0; Pike_interpreter.evaluator_stack=0;
a8964a2003-03-24Jonas Wallden  Pike_interpreter.mark_stack_malloced=0;
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_interpreter.evaluator_stack_malloced=0;
5267b71995-08-09Fredrik Hübinette (Hubbe) }
b660c81999-03-01Fredrik Hübinette (Hubbe)  void really_clean_up_interpret(void) {
5b7b061999-04-08Fredrik Hübinette (Hubbe) #ifdef DO_PIKE_CLEANUP
424d9c1999-05-02Fredrik Hübinette (Hubbe) #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
b660c81999-03-01Fredrik Hübinette (Hubbe)  free_all_pike_frame_blocks();
5b7b061999-04-08Fredrik Hübinette (Hubbe) #endif
b660c81999-03-01Fredrik Hübinette (Hubbe) }