cb22561995-10-11Fredrik Hübinette (Hubbe) /*\
06983f1996-09-22Fredrik Hübinette (Hubbe) ||| This file a part of Pike, and is copyright by Fredrik Hubinette ||| Pike is distributed as GPL (General Public License)
cb22561995-10-11Fredrik Hübinette (Hubbe) ||| See the files COPYING and DISCLAIMER for more information. \*/
8670791999-02-28Henrik Grubbström (Grubba) /**/
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "global.h"
18099a2001-03-04Mirar (Pontus Hagland) RCSID("$Id: interpret.c,v 1.188 2001/03/04 19:27:18 mirar 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"
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
c5016f1996-04-13Fredrik Hübinette (Hubbe) #define TRACE_LEN (100 + t_flag * 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 
5267b71995-08-09Fredrik Hübinette (Hubbe) 
c915472000-12-04Martin Stjernholm PMOD_EXPORT const char *Pike_check_stack_errmsg = "Svalue stack overflow. " "(%ld of %ld entries on stack, needed %ld more entries)\n"; PMOD_EXPORT const char *Pike_check_mark_stack_errmsg = "Mark stack overflow.\n"; PMOD_EXPORT const char *Pike_check_c_stack_errmsg = "C stack overflow.\n";
342fef2000-08-23Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG static char trace_buffer[2000]; #endif
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) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  /* mark stack, used to store markers into the normal stack */
3c9f631996-09-23Fredrik Hübinette (Hubbe) int mark_stack_malloced = 0;
fa382f1996-06-21Fredrik Hübinette (Hubbe) 
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)
36feac1997-03-06Fredrik Hübinette (Hubbe)  fatal("Mark stack underflow!\n"); #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
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;
07513e1996-10-04Fredrik Hübinette (Hubbe)  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;
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) 
d77dfb1996-11-21Fredrik Hübinette (Hubbe) use_malloc:
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 *));
3c9f631996-09-23Fredrik Hübinette (Hubbe)  mark_stack_malloced=1; }
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
fa382f1996-06-21Fredrik Hübinette (Hubbe) }
4908871998-08-10Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) static int eval_instruction(unsigned char *pc);
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 }
b208c11996-08-03Fredrik Hübinette (Hubbe)  * object[index] : { object, index }
5267b71995-08-09Fredrik Hübinette (Hubbe)  * local variable : { svalue_pointer, nothing } * global variable : { svalue_pointer/short_svalue_pointer, nothing } */ 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) {
2a32691998-01-31Fredrik Hübinette (Hubbe)  case T_ARRAY_LVALUE:
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
2a32691998-01-31Fredrik Hübinette (Hubbe)  INT32 e; struct array *a; ONERROR err; a=allocate_array(lval[1].u.array->size>>1); SET_ONERROR(err, do_free_array, a); for(e=0;e<a->size;e++) lvalue_to_svalue_no_free(a->item+e, lval[1].u.array->item+(e<<1)); to->type = T_ARRAY; to->u.array=a; UNSET_ONERROR(err); break;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
2a32691998-01-31Fredrik Hübinette (Hubbe)  case T_LVALUE: assign_svalue_no_free(to, lval->u.lval); break; case T_SHORT_LVALUE:
f258372000-09-08Henrik Grubbström (Grubba)  assign_from_short_svalue_no_free(to, lval->u.short_lval, (TYPE_T)lval->subtype);
2a32691998-01-31Fredrik Hübinette (Hubbe)  break; case T_OBJECT: object_index_no_free(to, lval->u.object, lval+1); 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)) { to->u.integer=0; to->subtype=NUMBER_UNDEFINED; }else{ to->u.integer=0; to->subtype=NUMBER_NUMBER; } break; default: if(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;
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_LVALUE: assign_svalue(lval->u.lval,from); break; case T_SHORT_LVALUE:
f258372000-09-08Henrik Grubbström (Grubba)  assign_to_short_svalue(lval->u.short_lval, (TYPE_T)lval->subtype, from);
5267b71995-08-09Fredrik Hübinette (Hubbe)  break; case T_OBJECT: object_set_index(lval->u.object, lval+1, from); 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:
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(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:
6ec27f1996-12-05Per Hedbor  if(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; case T_LVALUE: if(lval->u.lval->type == t) return & ( lval->u.lval->u ); return 0; case T_SHORT_LVALUE: if(lval->subtype == t) return lval->u.short_lval; return 0; 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: if(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, ...) { if(t_flag > level) { 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, p->parent_program_id); 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, last->prog->parent_program_id, 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; INT32 e,off;
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
2a52ff2000-10-01Fredrik Hübinette (Hubbe)  if(t_flag>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)); TRACE((4,"- o->parent_identifier=%d inherit->identifier_level=%d\n", loc->o->parent_identifier, loc->inherit->identifier_level)); switch(loc->inherit->parent_offset) { default: { struct external_variable_context tmp=*loc; #ifdef PIKE_DEBUG if(!loc->inherit->inherit_level) fatal("Gahhh! inherit level zero in wrong place!\n"); #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")); loc->parent_identifier=loc->o->parent_identifier; loc->o=loc->o->parent; 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); fatal("Object zapping detected.\n"); } 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); fatal("Looks like the program %p has been zapped!\n", p); } #endif /* DEBUG_MALLOC */ #ifdef PIKE_DEBUG if(loc->parent_identifier < 0 || loc->parent_identifier > p->num_identifier_references) fatal("Identifier out of range, loc->parent_identifer=%d!\n", loc->parent_identifier); #endif loc->inherit=INHERIT_FROM_INT(p, loc->parent_identifier); #ifdef PIKE_DEBUG if(t_flag>28) 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); fatal("Looks like the program %p has been zapped!\n", p); } #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) { if(t_flag>3) { 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;
5267b71995-08-09Fredrik Hübinette (Hubbe) #define CASE(X) case (X)-F_OFFSET: #define COMPARISMENT(ID,EXPR) \ CASE(ID); \ instr=EXPR; \ pop_n_elems(2); \
7961fb1997-10-10Fredrik Hübinette (Hubbe) push_int(instr); \ break
5267b71995-08-09Fredrik Hübinette (Hubbe) 
2ba9191999-10-23Fredrik Hübinette (Hubbe) #ifdef AUTO_BIGNUM #define AUTO_BIGNUM_LOOP_TEST(X,Y) INT_TYPE_ADD_OVERFLOW(X,Y) #else #define AUTO_BIGNUM_LOOP_TEST(X,Y) 0 #endif #define LOOP(ID, INC, OP2, OP4) \
7961fb1997-10-10Fredrik Hübinette (Hubbe) CASE(ID) \ { \
f077582000-07-06Fredrik Hübinette (Hubbe)  union anything *i=get_pointer_if_this_type(Pike_sp-2, T_INT); \
2ba9191999-10-23Fredrik Hübinette (Hubbe)  if(i && !AUTO_BIGNUM_LOOP_TEST(i->integer,INC)) \
7961fb1997-10-10Fredrik Hübinette (Hubbe)  { \
2ba9191999-10-23Fredrik Hübinette (Hubbe)  i->integer += INC; \
ac61a32001-01-31Martin Stjernholm  if(i->integer OP2 Pike_sp[-3].u.integer) \
7961fb1997-10-10Fredrik Hübinette (Hubbe)  { \
ac61a32001-01-31Martin Stjernholm  DOJUMP(); \
7961fb1997-10-10Fredrik Hübinette (Hubbe)  }else{ \
ac61a32001-01-31Martin Stjernholm  SKIPJUMP(); \ } \
7961fb1997-10-10Fredrik Hübinette (Hubbe)  }else{ \
ac61a32001-01-31Martin Stjernholm  lvalue_to_svalue_no_free(Pike_sp,Pike_sp-2); Pike_sp++; \
2ba9191999-10-23Fredrik Hübinette (Hubbe)  push_int(INC); \ f_add(2); \
ac61a32001-01-31Martin Stjernholm  assign_lvalue(Pike_sp-3,Pike_sp-1); \ if(OP4 ( Pike_sp-1, Pike_sp-4 )) \
7961fb1997-10-10Fredrik Hübinette (Hubbe)  { \
ac61a32001-01-31Martin Stjernholm  DOJUMP(); \
7961fb1997-10-10Fredrik Hübinette (Hubbe)  }else{ \
ac61a32001-01-31Martin Stjernholm  SKIPJUMP(); \
7961fb1997-10-10Fredrik Hübinette (Hubbe)  } \ pop_stack(); \ } \ break; \
5267b71995-08-09Fredrik Hübinette (Hubbe) }
c5016f1996-04-13Fredrik Hübinette (Hubbe) #define CJUMP(X,Y) \ CASE(X); \
f077582000-07-06Fredrik Hübinette (Hubbe) if(Y(Pike_sp-2,Pike_sp-1)) { \
06983f1996-09-22Fredrik Hübinette (Hubbe)  DOJUMP(); \
c5016f1996-04-13Fredrik Hübinette (Hubbe) }else{ \
d4425e2000-08-24Henrik Grubbström (Grubba)  SKIPJUMP(); \
c5016f1996-04-13Fredrik Hübinette (Hubbe) } \ pop_n_elems(2); \ break
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
b9e2202000-05-03Fredrik Hübinette (Hubbe) #define BACKLOG 1024
5267b71995-08-09Fredrik Hübinette (Hubbe) struct backlog { INT32 instruction;
c7ef072000-04-21Fredrik Hübinette (Hubbe)  INT32 arg,arg2;
5267b71995-08-09Fredrik Hübinette (Hubbe)  struct program *program; unsigned char *pc;
8eaef52000-04-21Fredrik Hübinette (Hubbe) #ifdef _REENTRANT struct object *thread_id; #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;
5c8e891995-10-29Fredrik Hübinette (Hubbe) void dump_backlog(void)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
086d652000-04-26Fredrik Hübinette (Hubbe) #ifdef _REENTRANT struct object *thread=0; #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) { char *file; INT32 line;
086d652000-04-26Fredrik Hübinette (Hubbe) #ifdef _REENTRANT if(thread != backlog[e].thread_id) {
f077582000-07-06Fredrik Hübinette (Hubbe)  fprintf(stderr,"[Thread swap, Pike_interpreter.thread_id=%p]\n",backlog[e].thread_id);
086d652000-04-26Fredrik Hübinette (Hubbe)  thread = backlog[e].thread_id; } #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  file=get_line(backlog[e].pc-1,backlog[e].program, &line);
c7ef072000-04-21Fredrik Hübinette (Hubbe)  if(backlog[e].instruction < 0 || backlog[e].instruction+F_OFFSET > F_MAX_OPCODE) {
086d652000-04-26Fredrik Hübinette (Hubbe)  fprintf(stderr,"%s:%ld: ILLEGAL INSTRUCTION %d\n",
c7ef072000-04-21Fredrik Hübinette (Hubbe)  file, (long)line, backlog[e].instruction + F_OFFSET); continue; }
b9e2202000-05-03Fredrik Hübinette (Hubbe)  fprintf(stderr,"%s:%ld: %s", file, (long)line, 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));
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }while(e!=backlogp);
cb22561995-10-11Fredrik Hübinette (Hubbe) }
5267b71995-08-09Fredrik Hübinette (Hubbe)  #endif
b208c11996-08-03Fredrik Hübinette (Hubbe) static int o_catch(unsigned char *pc);
a64f6b2001-01-12Martin Stjernholm struct light_frame_info {
2810e22001-01-12Martin Stjernholm  struct pike_frame *saved_fp;
a64f6b2001-01-12Martin Stjernholm  struct svalue *expendible; struct svalue *locals; }; static void restore_light_frame_info(struct light_frame_info *info) {
2810e22001-01-12Martin Stjernholm  if (Pike_fp == info->saved_fp) { Pike_fp->expendible = info->expendible; Pike_fp->locals = info->locals; }
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) \ fatal("Return value -2 from eval_instruction is not handled here.\n"\ "Probable cause: F_ESCAPE_CATCH outside catch block.\n") #else #define EVAL_INSTR_RET_CHECK(x) #endif #ifdef PIKE_DEBUG
7d7d7e1999-01-31Fredrik Hübinette (Hubbe) #define eval_instruction eval_instruction_with_debug #include "interpreter.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7d7d7e1999-01-31Fredrik Hübinette (Hubbe) #undef eval_instruction #define eval_instruction eval_instruction_without_debug #undef PIKE_DEBUG #define print_return_value() #include "interpreter.h" #undef print_return_value #define PIKE_DEBUG #undef eval_instruction
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7d7d7e1999-01-31Fredrik Hübinette (Hubbe) static inline int eval_instruction(unsigned char *pc) { if(d_flag || t_flag>2) 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) 
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) { char *file,*s; 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;
f077582000-07-06Fredrik Hübinette (Hubbe)  file=get_line(Pike_fp->pc,Pike_fp->context.prog,&linep);
cd83521998-02-02Fredrik Hübinette (Hubbe)  while((f=STRCHR(file,'/'))) file=f+1; }else{ linep=0; file="-"; } fprintf(stderr,"- %s:%4ld: %s\n",file,(long)linep,s); free(s); }
4218011999-01-31Fredrik Hübinette (Hubbe)  #undef INIT_BLOCK #define INIT_BLOCK(X) do { X->refs=1; X->malloced_locals=0; X->scope=0; }while(0) #undef EXIT_BLOCK #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_frame(X->scope); \ if(X->malloced_locals) \ { \ free_svalues(X->locals,X->num_locals,BIT_MIXED); \ free((char *)(X->locals)); \ } \
60d9872000-03-23Fredrik Hübinette (Hubbe)  DO_IF_DMALLOC( \ X->context.prog=0; \ X->context.parent=0; \
1e4e5f2000-04-07Fredrik Hübinette (Hubbe)  X->context.name=0; \
60d9872000-03-23Fredrik Hübinette (Hubbe)  X->scope=0; \
1e4e5f2000-04-07Fredrik Hübinette (Hubbe)  X->current_object=0; \
60d9872000-03-23Fredrik Hübinette (Hubbe)  X->malloced_locals=0; \
1e4e5f2000-04-07Fredrik Hübinette (Hubbe)  X->expendible=0; \
60d9872000-03-23Fredrik Hübinette (Hubbe)  X->locals=0; \ ) \
4218011999-01-31Fredrik Hübinette (Hubbe) }while(0) BLOCK_ALLOC(pike_frame,128)
7e97c31999-01-21Fredrik Hübinette (Hubbe) #ifdef PIKE_SECURITY /* Magic trick */ static #else #define mega_apply2 mega_apply #endif
4218011999-01-31Fredrik Hübinette (Hubbe) 
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void mega_apply2(enum apply_type type, INT32 args, void *arg1, void *arg2)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) { struct object *o;
4218011999-01-31Fredrik Hübinette (Hubbe)  struct pike_frame *scope=0;
7e16612000-08-10Henrik Grubbström (Grubba)  int tailrecurse=-1; ptrdiff_t fun;
f077582000-07-06Fredrik Hübinette (Hubbe)  struct svalue *save_sp=Pike_sp-args;
7e97c31999-01-21Fredrik Hübinette (Hubbe) 
a2a8801998-03-18Per Hedbor #ifdef PROFILING #ifdef HAVE_GETHRTIME
f077582000-07-06Fredrik Hübinette (Hubbe)  long long children_base = Pike_interpreter.accounted_time; long long start_time = gethrtime() - Pike_interpreter.time_base;
6189631998-11-12Fredrik Hübinette (Hubbe)  unsigned INT32 self_time_base;
6d8c692000-08-08Henrik Grubbström (Grubba) #if 0 #ifdef PIKE_DEBUG
9750c31998-11-20Fredrik Hübinette (Hubbe)  if(start_time < 0) {
f077582000-07-06Fredrik Hübinette (Hubbe)  fatal("gethrtime() shrunk\n start_time=%ld\n gethrtime()=%ld\n Pike_interpreter.time_base=%ld\n",
9750c31998-11-20Fredrik Hübinette (Hubbe)  (long)(start_time/100000),
ed86c61998-11-20Fredrik Hübinette (Hubbe)  (long)(gethrtime()/100000),
f077582000-07-06Fredrik Hübinette (Hubbe)  (long)(Pike_interpreter.time_base/100000));
9750c31998-11-20Fredrik Hübinette (Hubbe)  }
a2a8801998-03-18Per Hedbor #endif #endif
6d8c692000-08-08Henrik Grubbström (Grubba) #endif #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
dcbfa71999-05-07Fredrik Hübinette (Hubbe) #if defined(PIKE_DEBUG) && defined(_REENTRANT) if(d_flag) {
f469831999-05-08Henrik Grubbström (Grubba)  THREAD_T self = th_self();
c91f892000-04-19Martin Stjernholm  CHECK_INTERPRETER_LOCK();
18d3d32000-04-19Martin Stjernholm 
f077582000-07-06Fredrik Hübinette (Hubbe)  if( Pike_interpreter.thread_id && !th_equal( OBJ2THREAD(Pike_interpreter.thread_id)->id, self) )
dcbfa71999-05-07Fredrik Hübinette (Hubbe)  fatal("Current thread is wrong.\n");
f077582000-07-06Fredrik Hübinette (Hubbe)  if(thread_for_id(th_self()) != Pike_interpreter.thread_id) fatal("thread_for_id() (or Pike_interpreter.thread_id) failed in mega_apply! " "%p != %p\n", thread_for_id(self), Pike_interpreter.thread_id);
f469831999-05-08Henrik Grubbström (Grubba)  }
dcbfa71999-05-07Fredrik Hübinette (Hubbe) #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  switch(type) { case APPLY_STACK: apply_stack:
bb21091998-04-10Henrik Grubbström (Grubba)  if(!args)
62222b2000-09-25Fredrik Hübinette (Hubbe)  PIKE_ERROR("`()", "Too few arguments (apply stack).\n", Pike_sp, 0);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  args--;
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp-save_sp-args > (args<<2) + 32)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  { /* The test above assures these two areas * are not overlapping */
f077582000-07-06Fredrik Hübinette (Hubbe)  assign_svalues(save_sp, Pike_sp-args-1, args+1, BIT_MIXED); pop_n_elems(Pike_sp-save_sp-args-1);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
f077582000-07-06Fredrik Hübinette (Hubbe)  arg1=(void *)(Pike_sp-args-1);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  case APPLY_SVALUE: apply_svalue: { struct svalue *s=(struct svalue *)arg1; switch(s->type) { case T_INT: if (!s->u.integer) {
f077582000-07-06Fredrik Hübinette (Hubbe)  PIKE_ERROR("0", "Attempt to call the NULL-value\n", Pike_sp, args);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  } else {
18099a2001-03-04Mirar (Pontus Hagland)  Pike_error("Attempt to call the value %"PRINTPIKEINT"d\n", s->u.integer);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  } case T_STRING: if (s->u.string->len > 20) {
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Attempt to call the string \"%20s\"...\n", s->u.string->str);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  } else {
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Attempt to call the string \"%s\"\n", s->u.string->str);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  } case T_MAPPING:
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Attempt to call a mapping\n");
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  default:
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Call to non-function value type:%s.\n",
bb21091998-04-10Henrik Grubbström (Grubba)  get_name_of_type(s->type));
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  case T_FUNCTION: if(s->subtype == FUNCTION_BUILTIN) {
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
f077582000-07-06Fredrik Hübinette (Hubbe)  struct svalue *expected_stack = Pike_sp-args;
cd83521998-02-02Fredrik Hübinette (Hubbe)  if(t_flag>1) { init_buf(); describe_svalue(s,0,0); do_trace_call(args); } #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  (*(s->u.efun->function))(args);
044c621999-04-14Fredrik Hübinette (Hubbe)  #ifdef PIKE_DEBUG
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp != expected_stack + !s->u.efun->may_return_void)
044c621999-04-14Fredrik Hübinette (Hubbe)  {
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp < expected_stack)
044c621999-04-14Fredrik Hübinette (Hubbe)  fatal("Function popped too many arguments: %s\n", s->u.efun->name->str);
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp>expected_stack+1)
044c621999-04-14Fredrik Hübinette (Hubbe)  fatal("Function left droppings on stack: %s\n", s->u.efun->name->str);
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp == expected_stack && !s->u.efun->may_return_void)
044c621999-04-14Fredrik Hübinette (Hubbe)  fatal("Non-void function returned without return value on stack: %s %d\n", s->u.efun->name->str,s->u.efun->may_return_void);
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp==expected_stack+1 && s->u.efun->may_return_void)
044c621999-04-14Fredrik Hübinette (Hubbe)  fatal("Void function returned with a value on the stack: %s %d\n", s->u.efun->name->str, s->u.efun->may_return_void); } #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  break; }else{ o=s->u.object;
f14a742000-01-22Henrik Grubbström (Grubba)  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; }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  fun=s->subtype; goto apply_low; } break; case T_ARRAY:
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
cd83521998-02-02Fredrik Hübinette (Hubbe)  if(t_flag>1) { init_buf(); describe_svalue(s,0,0); do_trace_call(args); } #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  apply_array(s->u.array,args); break; case T_PROGRAM:
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
cd83521998-02-02Fredrik Hübinette (Hubbe)  if(t_flag>1) { init_buf(); describe_svalue(s,0,0); do_trace_call(args); } #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_object(clone_object(s->u.program,args)); break; case T_OBJECT: o=s->u.object;
4218011999-01-31Fredrik Hübinette (Hubbe)  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; }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  fun=LFUN_CALL; goto call_lfun; } break; } call_lfun:
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(fun < 0 || fun >= NUM_LFUNS) fatal("Apply lfun on illegal value!\n"); #endif if(!o->prog)
f077582000-07-06Fredrik Hübinette (Hubbe)  PIKE_ERROR("destructed object", "Apply on destructed object.\n", Pike_sp, args);
a85b432000-08-10Henrik Grubbström (Grubba)  fun = FIND_LFUN(o->prog, fun);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  goto apply_low; case APPLY_LOW:
7e16612000-08-10Henrik Grubbström (Grubba)  o = (struct object *)arg1; fun = (ptrdiff_t)arg2;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  apply_low:
4218011999-01-31Fredrik Hübinette (Hubbe)  scope=0; apply_low_with_scope:
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  { struct program *p; struct reference *ref;
424d9c1999-05-02Fredrik Hübinette (Hubbe)  struct pike_frame *new_frame;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  struct identifier *function; if(fun<0) {
f077582000-07-06Fredrik Hübinette (Hubbe)  pop_n_elems(Pike_sp-save_sp);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_int(0); return; }
7e97c31999-01-21Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  check_stack(256); check_mark_stack(256);
4908871998-08-10Fredrik Hübinette (Hubbe)  check_c_stack(8192);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
424d9c1999-05-02Fredrik Hübinette (Hubbe) 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(d_flag>2) do_debug(); #endif p=o->prog; if(!p)
aa366d1998-04-16Fredrik Hübinette (Hubbe)  PIKE_ERROR("destructed object->function",
f077582000-07-06Fredrik Hübinette (Hubbe)  "Cannot call functions in destructed objects.\n", Pike_sp, args);
53f50d2000-04-17Henrik Grubbström (Grubba)  #ifdef PIKE_SECURITY CHECK_DATA_SECURITY_OR_ERROR(o, SECURITY_BIT_CALL, ("Function call permission denied.\n")); if(!CHECK_DATA_SECURITY(o, SECURITY_BIT_NOT_SETUID)) SET_CURRENT_CREDS(o->prot); #endif
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(fun>=(int)p->num_identifier_references)
56de851998-07-17Fredrik Hübinette (Hubbe)  {
7e16612000-08-10Henrik Grubbström (Grubba)  fprintf(stderr, "Function index out of range. %ld >= %d\n",
a85b432000-08-10Henrik Grubbström (Grubba)  DO_NOT_WARN((long)fun), (int)p->num_identifier_references);
56de851998-07-17Fredrik Hübinette (Hubbe)  fprintf(stderr,"########Program is:\n"); describe(p); fprintf(stderr,"########Object is:\n"); describe(o);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  fatal("Function index out of range.\n");
56de851998-07-17Fredrik Hübinette (Hubbe)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #endif ref = p->identifier_references + fun;
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(ref->inherit_offset>=p->num_inherits) fatal("Inherit offset out of range in program.\n"); #endif
4218011999-01-31Fredrik Hübinette (Hubbe)  /* init a new evaluation pike_frame */
53f50d2000-04-17Henrik Grubbström (Grubba)  new_frame=alloc_pike_frame(); debug_malloc_touch(new_frame);
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 = p->inherits[ ref->inherit_offset ];
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
4218011999-01-31Fredrik Hübinette (Hubbe)  function = new_frame->context.prog->identifiers + ref->identifier_offset;
a2a8801998-03-18Per Hedbor 
53f50d2000-04-17Henrik Grubbström (Grubba) 
f41da61999-03-17Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG if(t_flag > 9) { fprintf(stderr,"-- ref: inoff=%d idoff=%d flags=%d\n", ref->inherit_offset, ref->identifier_offset, ref->id_flags);
84f8952000-08-16Henrik Grubbström (Grubba)  fprintf(stderr,"-- context: prog->id=%d inlev=%d idlev=%d pi=%d po=%d so=%ld name=%s\n",
f41da61999-03-17Fredrik Hübinette (Hubbe)  new_frame->context.prog->id, new_frame->context.inherit_level, new_frame->context.identifier_level, new_frame->context.parent_identifier, new_frame->context.parent_offset,
84f8952000-08-16Henrik Grubbström (Grubba)  DO_NOT_WARN((long)new_frame->context.storage_offset),
f41da61999-03-17Fredrik Hübinette (Hubbe)  new_frame->context.name ? new_frame->context.name->str : "NULL"); if(t_flag>19) { describe(new_frame->context.prog); } } #endif
f077582000-07-06Fredrik Hübinette (Hubbe)  new_frame->locals = Pike_sp - args;
4218011999-01-31Fredrik Hübinette (Hubbe)  new_frame->expendible = new_frame->locals; new_frame->args = args;
a85b432000-08-10Henrik Grubbström (Grubba)  new_frame->fun = DO_NOT_WARN((unsigned INT16)fun);
4218011999-01-31Fredrik Hübinette (Hubbe)  new_frame->current_storage = o->storage+new_frame->context.storage_offset; new_frame->pc = 0; new_frame->scope=scope;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
4218011999-01-31Fredrik Hübinette (Hubbe)  add_ref(new_frame->current_object); add_ref(new_frame->context.prog); if(new_frame->context.parent) add_ref(new_frame->context.parent); if(new_frame->scope) add_ref(new_frame->scope);
53f50d2000-04-17Henrik Grubbström (Grubba) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(t_flag) {
cd83521998-02-02Fredrik Hübinette (Hubbe)  char buf[50];
f41da61999-03-17Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  init_buf();
6d8c692000-08-08Henrik Grubbström (Grubba)  sprintf(buf, "%lx->", DO_NOT_WARN((long)o));
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  my_strcat(buf); my_strcat(function->name->str);
cd83521998-02-02Fredrik Hübinette (Hubbe)  do_trace_call(args);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_fp = new_frame;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
53f50d2000-04-17Henrik Grubbström (Grubba) #ifdef PROFILING function->num_calls++; #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(function->func.offset == -1)
f077582000-07-06Fredrik Hübinette (Hubbe)  generic_error(NULL, Pike_sp, args,
aacd952000-01-07Martin Stjernholm  "Calling undefined function.\n");
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
662e451998-01-22Fredrik Hübinette (Hubbe)  tailrecurse=-1;
6189631998-11-12Fredrik Hübinette (Hubbe)  #ifdef PROFILING #ifdef HAVE_GETHRTIME self_time_base=function->total_time; #endif #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  switch(function->identifier_flags & (IDENTIFIER_FUNCTION | IDENTIFIER_CONSTANT)) { case IDENTIFIER_C_FUNCTION:
f077582000-07-06Fredrik Hübinette (Hubbe)  debug_malloc_touch(Pike_fp); Pike_fp->num_args=args;
4218011999-01-31Fredrik Hübinette (Hubbe)  new_frame->num_locals=args;
773efa1998-07-16Fredrik Hübinette (Hubbe)  check_threads_etc();
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  (*function->func.c_fun)(args); break; case IDENTIFIER_CONSTANT: {
f077582000-07-06Fredrik Hübinette (Hubbe)  struct svalue *s=&(Pike_fp->context.prog->
55198b1999-09-25Henrik Grubbström (Grubba)  constants[function->func.offset].sval);
f077582000-07-06Fredrik Hübinette (Hubbe)  debug_malloc_touch(Pike_fp);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(s->type == T_PROGRAM) {
773efa1998-07-16Fredrik Hübinette (Hubbe)  struct object *tmp; check_threads_etc(); tmp=parent_clone_object(s->u.program, o, fun, args);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_object(tmp); break; } /* Fall through */ } case 0: {
f077582000-07-06Fredrik Hübinette (Hubbe)  debug_malloc_touch(Pike_fp);
1e92671999-10-19Fredrik Hübinette (Hubbe)  debug_malloc_touch(o);
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp-save_sp-args<=0)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  { /* Create an extra svalue for tail recursion style call */
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_sp++; MEMMOVE(Pike_sp-args,Pike_sp-args-1,sizeof(struct svalue)*args); Pike_sp[-args-1].type=T_INT;
1e92671999-10-19Fredrik Hübinette (Hubbe)  }else{
f077582000-07-06Fredrik Hübinette (Hubbe)  free_svalue(Pike_sp-args-1); Pike_sp[-args-1].type=T_INT;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
f077582000-07-06Fredrik Hübinette (Hubbe)  low_object_index_no_free(Pike_sp-args-1,o,fun);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  tailrecurse=args+1; break; } case IDENTIFIER_PIKE_FUNCTION: { int num_args; int num_locals; unsigned char *pc;
0bc60d2000-06-10Martin Stjernholm  #ifdef PIKE_DEBUG if (Pike_in_gc > GC_PASS_PREPARE && Pike_in_gc < GC_PASS_KILL) fatal("Pike code called within gc.\n"); #endif
f077582000-07-06Fredrik Hübinette (Hubbe)  debug_malloc_touch(Pike_fp);
4218011999-01-31Fredrik Hübinette (Hubbe)  pc=new_frame->context.prog->program + function->func.offset;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  num_locals=EXTRACT_UCHAR(pc++); num_args=EXTRACT_UCHAR(pc++);
4218011999-01-31Fredrik Hübinette (Hubbe) 
8322b62000-05-08Fredrik Hübinette (Hubbe)  if(function->identifier_flags & IDENTIFIER_SCOPE_USED)
6fd5172000-04-25Fredrik Hübinette (Hubbe)  new_frame->expendible+=num_locals;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  /* adjust arguments on stack */ if(args < num_args) /* push zeros */ {
f077582000-07-06Fredrik Hübinette (Hubbe)  clear_svalues_undefined(Pike_sp, num_args-args); Pike_sp += num_args-args;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  args += num_args-args; } if(function->identifier_flags & IDENTIFIER_VARARGS) { f_aggregate(args - num_args); /* make array */ args = num_args+1; }else{ if(args > num_args) { /* pop excessive */ pop_n_elems(args - num_args); args=num_args; } }
f077582000-07-06Fredrik Hübinette (Hubbe)  if(num_locals > args) clear_svalues(Pike_sp, num_locals - args); Pike_sp += num_locals - args;
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(num_locals < num_args) fatal("Wrong number of arguments or locals in function def.\n"); #endif
4218011999-01-31Fredrik Hübinette (Hubbe)  new_frame->num_locals=num_locals; new_frame->num_args=num_args;
773efa1998-07-16Fredrik Hübinette (Hubbe)  check_threads_etc();
aa5b801998-06-18Fredrik Hübinette (Hubbe)  {
fc26f62000-07-06Fredrik Hübinette (Hubbe)  struct svalue **save_mark_sp=Pike_mark_sp;
aa5b801998-06-18Fredrik Hübinette (Hubbe)  tailrecurse=eval_instruction(pc);
b7c1ee2001-01-10Martin Stjernholm  EVAL_INSTR_RET_CHECK(tailrecurse);
fc26f62000-07-06Fredrik Hübinette (Hubbe)  Pike_mark_sp=save_mark_sp;
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
fc26f62000-07-06Fredrik Hübinette (Hubbe)  if(Pike_mark_sp < save_mark_sp)
aa5b801998-06-18Fredrik Hübinette (Hubbe)  fatal("Popped below save_mark_sp!\n"); #endif }
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp<Pike_interpreter.evaluator_stack)
a4a1722000-12-05Per Hedbor  fatal("Stack error (also simple).\n");
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #endif break; } }
a2a8801998-03-18Per Hedbor #ifdef PROFILING #ifdef HAVE_GETHRTIME
6189631998-11-12Fredrik Hübinette (Hubbe)  { long long time_passed, time_in_children, self_time;
f077582000-07-06Fredrik Hübinette (Hubbe)  time_in_children= Pike_interpreter.accounted_time - children_base; time_passed = gethrtime() - Pike_interpreter.time_base - start_time;
6189631998-11-12Fredrik Hübinette (Hubbe)  self_time=time_passed - time_in_children;
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_interpreter.accounted_time+=self_time;
6d8c692000-08-08Henrik Grubbström (Grubba) #if 0
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
f077582000-07-06Fredrik Hübinette (Hubbe)  if(self_time < 0 || children_base <0 || Pike_interpreter.accounted_time <0) fatal("Time is negative\n self_time=%ld\n time_passed=%ld\n time_in_children=%ld\n children_base=%ld\n Pike_interpreter.accounted_time=%ld!\n Pike_interpreter.time_base=%ld\n start_time=%ld\n",
7d17521998-11-20Fredrik Hübinette (Hubbe)  (long)(self_time/100000), (long)(time_passed/100000), (long)(time_in_children/100000), (long)(children_base/100000),
f077582000-07-06Fredrik Hübinette (Hubbe)  (long)(Pike_interpreter.accounted_time/100000), (long)(Pike_interpreter.time_base/100000),
7d17521998-11-20Fredrik Hübinette (Hubbe)  (long)(start_time/100000)
6189631998-11-12Fredrik Hübinette (Hubbe)  ); #endif
6d8c692000-08-08Henrik Grubbström (Grubba) #endif
6189631998-11-12Fredrik Hübinette (Hubbe)  function->total_time=self_time_base + (INT32)(time_passed /1000); function->self_time+=(INT32)( self_time /1000); }
a2a8801998-03-18Per Hedbor #endif #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  #if 0
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp - new_frame->locals > 1)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
f077582000-07-06Fredrik Hübinette (Hubbe)  pop_n_elems(Pike_sp - new_frame->locals -1); }else if(Pike_sp - new_frame->locals < 1){
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp - new_frame->locals<0) fatal("Frame underflow.\n");
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #endif
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_sp->u.integer = 0; Pike_sp->subtype=NUMBER_NUMBER; Pike_sp->type = T_INT; Pike_sp++;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  } #endif
7e97c31999-01-21Fredrik Hübinette (Hubbe) 
4218011999-01-31Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_fp!=new_frame)
4218011999-01-31Fredrik Hübinette (Hubbe)  fatal("Frame stack out of whack!\n"); #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
4218011999-01-31Fredrik Hübinette (Hubbe)  POP_PIKE_FRAME();
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(tailrecurse>=0) { args=tailrecurse; goto apply_stack; } } }
f077582000-07-06Fredrik Hübinette (Hubbe)  if(save_sp+1 < Pike_sp)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
f077582000-07-06Fredrik Hübinette (Hubbe)  assign_svalue(save_sp,Pike_sp-1); pop_n_elems(Pike_sp-save_sp-1);
44138c2000-08-02Fredrik Hübinette (Hubbe)  destruct_objects_to_destruct(); /* consider using a flag for immediate destruct instead... */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
f077582000-07-06Fredrik Hübinette (Hubbe)  if(save_sp+1 > Pike_sp)
cd83521998-02-02Fredrik Hübinette (Hubbe)  {
9106ac1998-02-03Fredrik Hübinette (Hubbe)  if(type != APPLY_SVALUE) push_int(0);
cd83521998-02-02Fredrik Hübinette (Hubbe)  }else{
9106ac1998-02-03Fredrik Hübinette (Hubbe)  if(t_flag>1) trace_return_value();
cd83521998-02-02Fredrik Hübinette (Hubbe)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) }
7e97c31999-01-21Fredrik Hübinette (Hubbe) #ifdef PIKE_SECURITY
bf39701999-09-06Henrik Grubbström (Grubba) static void restore_creds(struct object *creds) {
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_interpreter.current_creds) free_object(Pike_interpreter.current_creds); Pike_interpreter.current_creds = creds;
bf39701999-09-06Henrik Grubbström (Grubba) }
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void mega_apply(enum apply_type type, INT32 args, void *arg1, void *arg2)
7e97c31999-01-21Fredrik Hübinette (Hubbe) { ONERROR tmp;
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_interpreter.current_creds) add_ref(Pike_interpreter.current_creds);
7e97c31999-01-21Fredrik Hübinette (Hubbe) 
f077582000-07-06Fredrik Hübinette (Hubbe)  SET_ONERROR(tmp, restore_creds, Pike_interpreter.current_creds);
bf39701999-09-06Henrik Grubbström (Grubba)  mega_apply2(type, args, arg1, arg2);
7e97c31999-01-21Fredrik Hübinette (Hubbe)  CALL_AND_UNSET_ONERROR(tmp); } #endif
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 */ static int o_catch(unsigned char *pc) { JMP_BUF tmp;
f077582000-07-06Fredrik Hübinette (Hubbe)  struct svalue *expendible=Pike_fp->expendible; 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++;
b208c11996-08-03Fredrik Hübinette (Hubbe)  UNSETJMP(tmp);
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_fp->expendible=expendible;
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;
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)
f077582000-07-06Fredrik Hübinette (Hubbe)  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;
b7c1ee2001-01-10Martin Stjernholm  if(x>=0) mega_apply(APPLY_STACK, x, 0,0);
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); }
6697042000-11-20Martin Stjernholm PMOD_EXPORT void call_handle_error(void) { if (Pike_interpreter.svalue_stack_margin) { ONERROR tmp; int old_t_flag = t_flag; t_flag = 0; 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!"); assign_svalue_no_free(Pike_sp++, & throw_value); 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; t_flag = old_t_flag; } }
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;
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{
fc26f62000-07-06Fredrik Hübinette (Hubbe)  struct svalue **save_mark_sp=Pike_mark_sp;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  int tmp=eval_instruction(o->prog->program + offset);
b7c1ee2001-01-10Martin Stjernholm  EVAL_INSTR_RET_CHECK(tmp);
fc26f62000-07-06Fredrik Hübinette (Hubbe)  Pike_mark_sp=save_mark_sp;
b7c1ee2001-01-10Martin Stjernholm  if(tmp>=0) mega_apply(APPLY_STACK, tmp, 0,0);
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)
a4a1722000-12-05Per Hedbor  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; }
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void safe_apply_low(struct object *o,int fun,int args)
5267b71995-08-09Fredrik Hübinette (Hubbe) { JMP_BUF recovery;
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_sp-=args;
dffa011997-01-15Fredrik Hübinette (Hubbe)  free_svalue(& throw_value); throw_value.type=T_INT;
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(SETJMP(recovery)) {
dffa011997-01-15Fredrik Hübinette (Hubbe)  if(throw_value.type == T_ARRAY)
6697042000-11-20Martin Stjernholm  call_handle_error();
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_sp->u.integer = 0; Pike_sp->subtype=NUMBER_NUMBER; Pike_sp->type = T_INT; Pike_sp++;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{
6d8c692000-08-08Henrik Grubbström (Grubba)  ptrdiff_t expected_stack = Pike_sp - Pike_interpreter.evaluator_stack + 1;
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_sp+=args;
5267b71995-08-09Fredrik Hübinette (Hubbe)  apply_low(o,fun,args);
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp - Pike_interpreter.evaluator_stack > expected_stack) pop_n_elems(Pike_sp - Pike_interpreter.evaluator_stack - expected_stack); if(Pike_sp - Pike_interpreter.evaluator_stack < expected_stack)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
f077582000-07-06Fredrik Hübinette (Hubbe)  Pike_sp->u.integer = 0; Pike_sp->subtype=NUMBER_NUMBER; Pike_sp->type = T_INT; Pike_sp++;
5267b71995-08-09Fredrik Hübinette (Hubbe)  } } UNSETJMP(recovery); }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void safe_apply(struct object *o, char *fun ,INT32 args)
5683de1995-11-06Fredrik Hübinette (Hubbe) {
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
5683de1995-11-06Fredrik Hübinette (Hubbe)  if(!o->prog) fatal("Apply safe on destructed object.\n"); #endif safe_apply_low(o, find_identifier(fun, o->prog), args); }
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) fatal("Apply lfun on illegal value!\n"); #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) }
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void apply(struct object *o, 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))
fa382f1996-06-21Fredrik Hübinette (Hubbe)  fatal("Stack underflow!\n");
f6f02d1995-10-16Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
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]))
63bc491999-12-05Mirar (Pontus Hagland)  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]))
fa382f1996-06-21Fredrik Hübinette (Hubbe)  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)
5267b71995-08-09Fredrik Hübinette (Hubbe)  fatal("Mark stack underflow.\n");
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)
7b2ddd1999-04-17Henrik Grubbström (Grubba)  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]))
5267b71995-08-09Fredrik Hübinette (Hubbe)  fatal("Mark stack exceeds svalue stack\n");
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]))
5267b71995-08-09Fredrik Hübinette (Hubbe)  fatal("Local variable pointer points to Finspång.\n");
7965d72001-01-24Fredrik Hübinette (Hubbe)  if(f->args < 0 || f->args > Pike_stack_size)
4218011999-01-31Fredrik Hübinette (Hubbe)  fatal("FEL FEL FEL! HELP!! (corrupted pike_frame)\n");
0f887e1996-08-12Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
688f082001-02-27Martin Stjernholm  /*! 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. */ 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; char *file = 0; INT32 line; if (f->context.prog) { if (f->pc) file = get_line (f->pc, f->context.prog, &line); else file = get_line (f->context.prog->program, f->context.prog, &line); } if (file) fprintf (stderr, "%s:%d: ", file, line); else fputs ("unknown program: ", stderr); if (f->current_object && f->current_object->prog) { /* FIXME: Wide string identifiers. */ fputs (ID_FROM_INT (f->current_object->prog, f->fun)->name->str, stderr); 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_LVALUE: fputs ("lvalue", stderr); break; case T_INT: fprintf (stderr, "%ld", (long) arg->u.integer); break; case T_TYPE:
2db4d72001-03-03Henrik Grubbström (Grubba) #ifdef USE_PIKE_TYPE /* FIXME: */ fputs("type-value", stderr); #else /* !USE_PIKE_TYPE */
688f082001-02-27Martin Stjernholm  stupid_describe_type (arg->u.type->str, arg->u.type->len);
2db4d72001-03-03Henrik Grubbström (Grubba) #endif /* USE_PIKE_TYPE */
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) fputs (ID_FROM_INT(arg->u.object->prog,arg->subtype)->name->str, stderr); else fputc ('0', stderr); break; case T_OBJECT: { struct program *p = arg->u.object->prog; if (p && p->num_linenumbers) { file = get_line (p->program, p, &line); fprintf (stderr, "object(%s:%d)", file, line); } else fputs ("object", stderr); break; } case T_PROGRAM: { struct program *p = arg->u.program; if (p->num_linenumbers) { file = get_line (p->program, p, &line); fprintf (stderr, "program(%s:%d)", file, line); } 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: fprintf (stderr, "multiset[%ld]", (long) arg->u.multiset->ind->size); 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); } /*! 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. */ 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) { fprintf (stderr, "\nTHREAD_ID %ld (swapped %s):\n", (long) ts->id, ts->swapped ? "out" : "in"); gdb_backtrace (ts->id); } #else gdb_backtrace(); #endif }
5267b71995-08-09Fredrik Hübinette (Hubbe) #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)  } if(!mark_stack_malloced) {
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;
3c9f631996-09-23Fredrik Hübinette (Hubbe)  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) }
7965d72001-01-24Fredrik Hübinette (Hubbe)