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. \*/
4b974c1999-02-20Henrik Grubbström (Grubba) /**/
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "global.h"
26dc072000-04-06Fredrik Hübinette (Hubbe) RCSID("$Id: main.c,v 1.87 2000/04/06 21:00:20 hubbe Exp $");
5740881998-01-01Fredrik Hübinette (Hubbe) #include "fdlib.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "backend.h" #include "module.h" #include "object.h"
4b974c1999-02-20Henrik Grubbström (Grubba) #include "language.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "lex.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "pike_types.h" #include "builtin_functions.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "array.h" #include "stralloc.h" #include "interpret.h" #include "error.h"
bb55f81997-03-16Fredrik Hübinette (Hubbe) #include "pike_macros.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "callback.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "signal_handler.h"
07513e1996-10-04Fredrik Hübinette (Hubbe) #include "threads.h"
9c6f7d1997-04-15Fredrik Hübinette (Hubbe) #include "dynamic_load.h" #include "gc.h"
61e9a01998-01-25Fredrik Hübinette (Hubbe) #include "multiset.h"
9c6f7d1997-04-15Fredrik Hübinette (Hubbe) #include "mapping.h"
5740881998-01-01Fredrik Hübinette (Hubbe) #include "cpp.h"
0808b21998-01-25Fredrik Hübinette (Hubbe) #include "main.h"
19aaeb1998-05-25Fredrik Hübinette (Hubbe) #include "operators.h"
7e97c31999-01-21Fredrik Hübinette (Hubbe) #include "security.h"
67f0b51999-09-26Henrik Grubbström (Grubba) #include "constants.h"
c37c7e1999-03-26Fredrik Hübinette (Hubbe) #include "version.h"
5740881998-01-01Fredrik Hübinette (Hubbe) 
cee5811999-12-05Henrik Grubbström (Grubba) #include "las.h"
ac173e1997-11-02Henrik Grubbström (Grubba) #include <errno.h>
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifdef HAVE_LOCALE_H #include <locale.h> #endif
6930181996-02-25Fredrik Hübinette (Hubbe) 
6e37dc1996-06-21Fredrik Hübinette (Hubbe) #include "time_stuff.h"
6930181996-02-25Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> #endif
9debfa1999-08-11Fredrik Hübinette (Hubbe) #ifdef TRY_USE_MMX #include <mmx.h> int try_use_mmx; #endif
f8e5fe1997-01-18Henrik Grubbström (Grubba) 
5267b71995-08-09Fredrik Hübinette (Hubbe) char *master_file;
e1195f1997-03-23Fredrik Hübinette (Hubbe) char **ARGV;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
cd83521998-02-02Fredrik Hübinette (Hubbe) int debug_options=0;
7d955e1999-12-13Henrik Grubbström (Grubba) int runtime_options=0;
5267b71995-08-09Fredrik Hübinette (Hubbe) int d_flag=0; int c_flag=0; int t_flag=0;
943f851998-04-13Henrik Grubbström (Grubba) int default_t_flag=0;
5267b71995-08-09Fredrik Hübinette (Hubbe) int a_flag=0; int l_flag=0;
06983f1996-09-22Fredrik Hübinette (Hubbe) int p_flag=0;
943f851998-04-13Henrik Grubbström (Grubba) #ifdef YYDEBUG extern int yydebug; #endif /* YYDEBUG */
3f1eeb1998-04-05Fredrik Hübinette (Hubbe) static long instructions_left;
c37c7e1999-03-26Fredrik Hübinette (Hubbe) #define MASTER_COOKIE "(#*&)@(*&$Master Cookie:" #ifndef MAXPATHLEN #define MAXPATHLEN 32768 #endif char master_location[MAXPATHLEN * 2] = MASTER_COOKIE;
3f1eeb1998-04-05Fredrik Hübinette (Hubbe) static void time_to_exit(struct callback *cb,void *tmp,void *ignored) { if(instructions_left-- < 0) { push_int(0); f_exit(1); } }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
81b84e1996-12-03Fredrik Hübinette (Hubbe) static struct callback_list post_master_callbacks;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
6e37dc1996-06-21Fredrik Hübinette (Hubbe) struct callback *add_post_master_callback(callback_func call,
8f4f881996-06-20Fredrik Hübinette (Hubbe)  void *arg,
6e37dc1996-06-21Fredrik Hübinette (Hubbe)  callback_func free_func)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
6e37dc1996-06-21Fredrik Hübinette (Hubbe)  return add_to_callback(&post_master_callbacks, call, arg, free_func);
5267b71995-08-09Fredrik Hübinette (Hubbe) }
61e9a01998-01-25Fredrik Hübinette (Hubbe) static struct callback_list exit_callbacks; struct callback *add_exit_callback(callback_func call, void *arg, callback_func free_func) { return add_to_callback(&exit_callbacks, call, arg, free_func); }
a999e71998-07-27Fredrik Hübinette (Hubbe) #ifdef __NT__ static void get_master_key(long cat) { HKEY k; char buffer[4096]; DWORD len=sizeof(buffer)-1,type=REG_SZ; long ret; if(RegOpenKeyEx(cat,
624e851999-06-02Marcus Comstedt  (LPCTSTR)"SOFTWARE\\Idonex\\Pike\\0.7",
a999e71998-07-27Fredrik Hübinette (Hubbe)  0,KEY_READ,&k)==ERROR_SUCCESS) { if(RegQueryValueEx(k, "PIKE_MASTER", 0, &type, buffer, &len)==ERROR_SUCCESS) {
21315b1999-05-07Fredrik Hübinette (Hubbe)  dmalloc_accept_leak( master_file=strdup(buffer) );
a999e71998-07-27Fredrik Hübinette (Hubbe)  } RegCloseKey(k); } } #endif /* __NT__ */
3c0c281998-01-26Fredrik Hübinette (Hubbe) int dbm_main(int argc, char **argv)
5267b71995-08-09Fredrik Hübinette (Hubbe) { JMP_BUF back;
61e9a01998-01-25Fredrik Hübinette (Hubbe)  int e, num, do_backend;
5267b71995-08-09Fredrik Hübinette (Hubbe)  char *p; struct array *a;
85f59e1998-01-08Fredrik Hübinette (Hubbe) #ifdef DECLARE_ENVIRON extern char **environ; #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9debfa1999-08-11Fredrik Hübinette (Hubbe) #ifdef TRY_USE_MMX try_use_mmx=mmx_ok(); #endif
e1195f1997-03-23Fredrik Hübinette (Hubbe)  ARGV=argv;
5740881998-01-01Fredrik Hübinette (Hubbe)  fd_init();
cee5811999-12-05Henrik Grubbström (Grubba) #ifdef SHARED_NODES node_hash.table = malloc(sizeof(node *)*16411); if (!node_hash.table) { fatal("Out of memory!\n"); } MEMSET(node_hash.table, 0, sizeof(node *)*16411); node_hash.size = 16411; #endif /* SHARED_NODES */
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifdef HAVE_SETLOCALE
2cf1a11996-09-23Fredrik Hübinette (Hubbe) #ifdef LC_NUMERIC
06983f1996-09-22Fredrik Hübinette (Hubbe)  setlocale(LC_NUMERIC, "C");
2cf1a11996-09-23Fredrik Hübinette (Hubbe) #endif #ifdef LC_CTYPE
06983f1996-09-22Fredrik Hübinette (Hubbe)  setlocale(LC_CTYPE, "");
2cf1a11996-09-23Fredrik Hübinette (Hubbe) #endif #ifdef LC_TIME
06983f1996-09-22Fredrik Hübinette (Hubbe)  setlocale(LC_TIME, "C");
2cf1a11996-09-23Fredrik Hübinette (Hubbe) #endif #ifdef LC_COLLATE
06983f1996-09-22Fredrik Hübinette (Hubbe)  setlocale(LC_COLLATE, "");
2cf1a11996-09-23Fredrik Hübinette (Hubbe) #endif #ifdef LC_MESSAGES
06983f1996-09-22Fredrik Hübinette (Hubbe)  setlocale(LC_MESSAGES, "");
2cf1a11996-09-23Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif
bf47e12000-04-06Henrik Grubbström (Grubba) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  init_backend(); master_file = 0;
c37c7e1999-03-26Fredrik Hübinette (Hubbe) 
208f351998-05-12Henrik Grubbström (Grubba) #ifdef HAVE_GETENV
a999e71998-07-27Fredrik Hübinette (Hubbe)  if(getenv("PIKE_MASTER")) master_file = getenv("PIKE_MASTER");
208f351998-05-12Henrik Grubbström (Grubba) #endif
dc7cc91998-01-14Fredrik Hübinette (Hubbe) 
c37c7e1999-03-26Fredrik Hübinette (Hubbe)  if(master_location[CONSTANT_STRLEN(MASTER_COOKIE)]) master_file=master_location + CONSTANT_STRLEN(MASTER_COOKIE); #if __NT__ if(!master_file) get_master_key(HKEY_CURRENT_USER); if(!master_file) get_master_key(HKEY_LOCAL_MACHINE); #endif if(!master_file) { sprintf(master_location,DEFAULT_MASTER, PIKE_MAJOR_VERSION, PIKE_MINOR_VERSION, PIKE_BUILD_VERSION); master_file=master_location; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  for(e=1; e<argc; e++) { if(argv[e][0]=='-') { for(p=argv[e]+1; *p;) { switch(*p) { case 'D': add_predefine(p+1); p+=strlen(p); break; case 'm': if(p[1]) { master_file=p+1; p+=strlen(p); }else{ e++; if(e >= argc) { fprintf(stderr,"Missing argument to -m\n"); exit(1); } master_file=argv[e]; p+=strlen(p); } break;
9f243b1996-08-12Fredrik Hübinette (Hubbe)  case 's': if(!p[1]) { e++; if(e >= argc) { fprintf(stderr,"Missing argument to -s\n"); exit(1); } p=argv[e];
4908871998-08-10Fredrik Hübinette (Hubbe)  }else{ p++; if(*p=='s') { if(!p[1]) { e++; if(e >= argc) { fprintf(stderr,"Missing argument to -ss\n"); exit(1); } p=argv[e]; }else{ p++; } #ifdef _REENTRANT thread_stack_size=STRTOL(p,&p,0); #endif p+=strlen(p); break; }
9f243b1996-08-12Fredrik Hübinette (Hubbe)  }
4908871998-08-10Fredrik Hübinette (Hubbe)  stack_size=STRTOL(p,&p,0);
9f243b1996-08-12Fredrik Hübinette (Hubbe)  p+=strlen(p); if(stack_size < 256) { fprintf(stderr,"Stack size must at least be 256.\n"); exit(1); } break;
3f1eeb1998-04-05Fredrik Hübinette (Hubbe)  case 'q': if(!p[1]) { e++; if(e >= argc) { fprintf(stderr,"Missing argument to -q\n"); exit(1); } p=argv[e];
4908871998-08-10Fredrik Hübinette (Hubbe)  }else{ p++;
3f1eeb1998-04-05Fredrik Hübinette (Hubbe)  }
4908871998-08-10Fredrik Hübinette (Hubbe)  instructions_left=STRTOL(p,&p,0);
3f1eeb1998-04-05Fredrik Hübinette (Hubbe)  p+=strlen(p); add_to_callback(&evaluator_callbacks, time_to_exit, 0,0); break;
5267b71995-08-09Fredrik Hübinette (Hubbe)  case 'd':
cd83521998-02-02Fredrik Hübinette (Hubbe)  more_d_flags: switch(p[1]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': d_flag+=STRTOL(p+1,&p,10); break;
943f851998-04-13Henrik Grubbström (Grubba)  case 'c': p++; #ifdef YYDEBUG yydebug++; #endif /* YYDEBUG */ break;
cd83521998-02-02Fredrik Hübinette (Hubbe)  case 's': debug_options|=DEBUG_SIGNALS; p++;
9b08a21998-03-31Fredrik Hübinette (Hubbe)  goto more_d_flags; case 't': debug_options|=NO_TAILRECURSION;
cd83521998-02-02Fredrik Hübinette (Hubbe)  p++;
9b08a21998-03-31Fredrik Hübinette (Hubbe)  goto more_d_flags;
cd83521998-02-02Fredrik Hübinette (Hubbe) 
7d955e1999-12-13Henrik Grubbström (Grubba)  default: d_flag += (p[0] == 'd');
cee5811999-12-05Henrik Grubbström (Grubba)  p++;
7d955e1999-12-13Henrik Grubbström (Grubba)  } break;
cee5811999-12-05Henrik Grubbström (Grubba) 
7d955e1999-12-13Henrik Grubbström (Grubba)  case 'r':
17e1771999-12-13Per Hedbor  more_r_flags: switch(p[1]) {
7d955e1999-12-13Henrik Grubbström (Grubba)  case 't': runtime_options |= RUNTIME_CHECK_TYPES; p++;
17e1771999-12-13Per Hedbor  goto more_r_flags;
7d955e1999-12-13Henrik Grubbström (Grubba)  case 'T': runtime_options |= RUNTIME_STRICT_TYPES; p++;
17e1771999-12-13Per Hedbor  goto more_r_flags;
7d955e1999-12-13Henrik Grubbström (Grubba) 
17e1771999-12-13Per Hedbor  default: p++;
7d955e1999-12-13Henrik Grubbström (Grubba)  break;
cd83521998-02-02Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  break; case 'a': if(p[1]>='0' && p[1]<='9') a_flag+=STRTOL(p+1,&p,10); else a_flag++,p++; break; case 't': if(p[1]>='0' && p[1]<='9') t_flag+=STRTOL(p+1,&p,10); else t_flag++,p++;
943f851998-04-13Henrik Grubbström (Grubba)  default_t_flag = t_flag;
5267b71995-08-09Fredrik Hübinette (Hubbe)  break;
06983f1996-09-22Fredrik Hübinette (Hubbe)  case 'p': if(p[1]>='0' && p[1]<='9') p_flag+=STRTOL(p+1,&p,10); else p_flag++,p++; break;
5267b71995-08-09Fredrik Hübinette (Hubbe)  case 'l': if(p[1]>='0' && p[1]<='9') l_flag+=STRTOL(p+1,&p,10); else l_flag++,p++; break; default:
4967071997-01-15Fredrik Hübinette (Hubbe)  p+=strlen(p);
5267b71995-08-09Fredrik Hübinette (Hubbe)  } } }else{ break; } }
2a50961995-08-23Fredrik Hübinette (Hubbe) #if !defined(RLIMIT_NOFILE) && defined(RLIMIT_OFILE) #define RLIMIT_NOFILE RLIMIT_OFILE
e17dbc1995-08-11David Hedbor #endif
2a50961995-08-23Fredrik Hübinette (Hubbe) 
a9388a1998-09-02Henrik Grubbström (Grubba)  stack_top = (char *)&argv; /* Adjust for anything already pushed on the stack. * We align on a 64 KB boundary. * Thus we at worst, lose 64 KB stack. * * We have to do it this way since some compilers don't like * & and | on pointers, and casting to an integer type is * too unsafe (consider 64-bit systems). */ #if STACK_DIRECTION < 0 /* Equvivalent with |= 0xffff */ stack_top += (~((unsigned long)stack_top)) & 0xffff; #else /* STACK_DIRECTION >= 0 */ /* Equvivalent with &= ~0xffff */ stack_top -= ( ((unsigned long)stack_top)) & 0xffff; #endif /* STACK_DIRECTION < 0 */
4908871998-08-10Fredrik Hübinette (Hubbe) #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_STACK) { struct rlimit lim; if(!getrlimit(RLIMIT_STACK, &lim)) { #ifdef RLIM_INFINITY if(lim.rlim_cur == RLIM_INFINITY)
752e101999-04-30Fredrik Hübinette (Hubbe)  lim.rlim_cur=1024*1024*32;
4908871998-08-10Fredrik Hübinette (Hubbe) #endif
fcf0732000-03-28Fredrik Hübinette (Hubbe)  #ifdef Pike_INITIAL_STACK_SIZE if(lim.rlim_cur > Pike_INITIAL_STACK_SIZE) lim.rlim_cur=Pike_INITIAL_STACK_SIZE; #endif
752e101999-04-30Fredrik Hübinette (Hubbe)  stack_top += STACK_DIRECTION * lim.rlim_cur; #ifdef HAVE_PTHREAD_INITIAL_THREAD_BOS { extern char * __pthread_initial_thread_bos; /* Linux glibc threads are limited to a 4 Mb stack * __pthread_initial_thread_bos is the actual limit */ if(__pthread_initial_thread_bos && (__pthread_initial_thread_bos - stack_top) *STACK_DIRECTION < 0) stack_top=__pthread_initial_thread_bos; } #endif stack_top -= STACK_DIRECTION * 8192 * sizeof(char *);
a9388a1998-09-02Henrik Grubbström (Grubba)  #ifdef STACK_DEBUG fprintf(stderr, "1: C-stack: 0x%08p - 0x%08p, direction:%d\n", &argv, stack_top, STACK_DIRECTION); #endif /* STACK_DEBUG */
4908871998-08-10Fredrik Hübinette (Hubbe)  } }
a9388a1998-09-02Henrik Grubbström (Grubba) #else /* !HAVE_GETRLIMIT || !RLIMIT_STACK */ /* 128 MB seems a bit extreme, most OS's seem to have their limit at ~8MB */
efae671998-10-21Fredrik Hübinette (Hubbe)  stack_top += STACK_DIRECTION * (1024*1024 * 8 - 8192 * sizeof(char *));
a9388a1998-09-02Henrik Grubbström (Grubba) #ifdef STACK_DEBUG fprintf(stderr, "2: C-stack: 0x%08p - 0x%08p, direction:%d\n", &argv, stack_top, STACK_DIRECTION); #endif /* STACK_DEBUG */ #endif /* HAVE_GETRLIMIT && RLIMIT_STACK */
4908871998-08-10Fredrik Hübinette (Hubbe) 
2a50961995-08-23Fredrik Hübinette (Hubbe) #if defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)
5267b71995-08-09Fredrik Hübinette (Hubbe)  { struct rlimit lim;
f90e541995-08-17Fredrik Hübinette (Hubbe)  long tmp;
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(!getrlimit(RLIMIT_NOFILE, &lim)) {
5c8e891995-10-29Fredrik Hübinette (Hubbe) #ifdef RLIM_INFINITY if(lim.rlim_max == RLIM_INFINITY) lim.rlim_max=MAX_OPEN_FILEDESCRIPTORS; #endif
f90e541995-08-17Fredrik Hübinette (Hubbe)  tmp=MINIMUM(lim.rlim_max, MAX_OPEN_FILEDESCRIPTORS);
5267b71995-08-09Fredrik Hübinette (Hubbe)  lim.rlim_cur=tmp; setrlimit(RLIMIT_NOFILE, &lim); } } #endif
4081261998-04-23Fredrik Hübinette (Hubbe) 
6e37dc1996-06-21Fredrik Hübinette (Hubbe)  GETTIMEOFDAY(&current_time);
4081261998-04-23Fredrik Hübinette (Hubbe) 
378b2d1997-02-06Fredrik Hübinette (Hubbe)  init_shared_string_table(); init_interpreter();
aee13c1998-05-25Henrik Grubbström (Grubba)  init_types();
5740881998-01-01Fredrik Hübinette (Hubbe)  init_cpp();
378b2d1997-02-06Fredrik Hübinette (Hubbe)  init_lex();
4218011999-01-31Fredrik Hübinette (Hubbe)  init_program();
a5787d1999-03-03Fredrik Hübinette (Hubbe)  init_object();
378b2d1997-02-06Fredrik Hübinette (Hubbe) 
a91ca01998-07-10Henrik Grubbström (Grubba)  low_th_init();
378b2d1997-02-06Fredrik Hübinette (Hubbe)  init_modules();
5267b71995-08-09Fredrik Hübinette (Hubbe)  master();
ddea551996-07-01Fredrik Hübinette (Hubbe)  call_callback(& post_master_callbacks, 0);
ecf1451998-03-21Fredrik Hübinette (Hubbe)  free_callback_list(& post_master_callbacks);
4967071997-01-15Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(SETJMP(back)) {
61e9a01998-01-25Fredrik Hübinette (Hubbe)  if(throw_severity == THROW_EXIT) { num=throw_value.u.integer; }else{ ONERROR tmp; SET_ONERROR(tmp,exit_on_error,"Error in handle_error in master object!");
f545211998-01-27Fredrik Hübinette (Hubbe)  push_svalue(& throw_value);
61e9a01998-01-25Fredrik Hübinette (Hubbe)  APPLY_MASTER("handle_error", 1); pop_stack(); UNSET_ONERROR(tmp); num=10; } }else{ back.severity=THROW_EXIT;
fe5eb01998-01-31Fredrik Hübinette (Hubbe)  a=allocate_array_no_init(argc,0); for(num=0;num<argc;num++) { ITEM(a)[num].u.string=make_shared_string(argv[num]); ITEM(a)[num].type=T_STRING; } push_array(a);
61e9a01998-01-25Fredrik Hübinette (Hubbe) 
fe5eb01998-01-31Fredrik Hübinette (Hubbe)  for(num=0;environ[num];num++); a=allocate_array_no_init(num,0); for(num=0;environ[num];num++) { ITEM(a)[num].u.string=make_shared_string(environ[num]); ITEM(a)[num].type=T_STRING; } push_array(a);
61e9a01998-01-25Fredrik Hübinette (Hubbe)  apply(master(),"_main",2);
5267b71995-08-09Fredrik Hübinette (Hubbe)  pop_stack();
61e9a01998-01-25Fredrik Hübinette (Hubbe)  backend(); num=0;
5267b71995-08-09Fredrik Hübinette (Hubbe)  } UNSETJMP(back);
61e9a01998-01-25Fredrik Hübinette (Hubbe)  do_exit(num);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  return num; /* avoid warning */
61e9a01998-01-25Fredrik Hübinette (Hubbe) }
3c0c281998-01-26Fredrik Hübinette (Hubbe) #undef ATTRIBUTE #define ATTRIBUTE(X) void do_exit(int num) ATTRIBUTE((noreturn))
61e9a01998-01-25Fredrik Hübinette (Hubbe) { call_callback(&exit_callbacks, (void *)0);
ecf1451998-03-21Fredrik Hübinette (Hubbe)  free_callback_list(&exit_callbacks);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
61e9a01998-01-25Fredrik Hübinette (Hubbe)  exit_modules();
2916001998-01-16Henrik Grubbström (Grubba) 
2043ba1998-02-10Fredrik Hübinette (Hubbe) #ifdef DEBUG_MALLOC {
88a1ad1998-04-01Henrik Grubbström (Grubba)  extern void cleanup_memhdrs(void);
2043ba1998-02-10Fredrik Hübinette (Hubbe)  cleanup_memhdrs(); } #endif
61e9a01998-01-25Fredrik Hübinette (Hubbe)  exit(num);
5267b71995-08-09Fredrik Hübinette (Hubbe) }
156fd51997-10-27Fredrik Hübinette (Hubbe) void low_init_main(void)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
f01a521999-08-14Fredrik Hübinette (Hubbe)  init_error();
7e97c31999-01-21Fredrik Hübinette (Hubbe)  init_pike_security();
378b2d1997-02-06Fredrik Hübinette (Hubbe)  th_init();
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  init_operators();
5267b71995-08-09Fredrik Hübinette (Hubbe)  init_builtin_efuns();
cb22561995-10-11Fredrik Hübinette (Hubbe)  init_signals();
ca74dd1996-10-08Fredrik Hübinette (Hubbe)  init_dynamic_load();
5267b71995-08-09Fredrik Hübinette (Hubbe) }
378b2d1997-02-06Fredrik Hübinette (Hubbe) void exit_main(void)
156fd51997-10-27Fredrik Hübinette (Hubbe) {
5f06241999-04-11Fredrik Hübinette (Hubbe) #ifdef DO_PIKE_CLEANUP
156fd51997-10-27Fredrik Hübinette (Hubbe)  cleanup_objects();
5f06241999-04-11Fredrik Hübinette (Hubbe) #endif
156fd51997-10-27Fredrik Hübinette (Hubbe) } void init_main(void) { } void low_exit_main(void)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
5f06241999-04-11Fredrik Hübinette (Hubbe) #ifdef DO_PIKE_CLEANUP
be478c1997-08-30Henrik Grubbström (Grubba)  void cleanup_added_efuns(void); void cleanup_pike_types(void); void cleanup_program(void);
61e9a01998-01-25Fredrik Hübinette (Hubbe)  void cleanup_compiler(void);
8fbb361998-04-06Henrik Grubbström (Grubba)  void cleanup_backend(void);
4be46f2000-03-07Fredrik Hübinette (Hubbe)  void free_all_mapping_blocks(void);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
e37a3e1999-10-09Fredrik Hübinette (Hubbe) #ifdef AUTO_BIGNUM void exit_auto_bignum(void); exit_auto_bignum(); #endif
6d1a5e1996-10-07Fredrik Hübinette (Hubbe)  th_cleanup();
a5787d1999-03-03Fredrik Hübinette (Hubbe)  exit_object();
c52c6a1997-01-14Niels Möller  exit_dynamic_load();
cb22561995-10-11Fredrik Hübinette (Hubbe)  exit_signals();
5267b71995-08-09Fredrik Hübinette (Hubbe)  exit_lex();
5740881998-01-01Fredrik Hübinette (Hubbe)  exit_cpp();
5267b71995-08-09Fredrik Hübinette (Hubbe)  cleanup_interpret(); cleanup_added_efuns();
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  exit_operators();
06983f1996-09-22Fredrik Hübinette (Hubbe)  cleanup_pike_types();
5267b71995-08-09Fredrik Hübinette (Hubbe)  cleanup_program();
61e9a01998-01-25Fredrik Hübinette (Hubbe)  cleanup_compiler();
8310c61999-03-19Fredrik Hübinette (Hubbe)  cleanup_error();
8fbb361998-04-06Henrik Grubbström (Grubba)  cleanup_backend();
06983f1996-09-22Fredrik Hübinette (Hubbe) 
cee5811999-12-05Henrik Grubbström (Grubba) #ifdef SHARED_NODES free(node_hash.table); #endif /* SHARED_NODES */
06983f1996-09-22Fredrik Hübinette (Hubbe)  do_gc();
1ab7c61999-04-08Fredrik Hübinette (Hubbe)  exit_pike_security();
f545211998-01-27Fredrik Hübinette (Hubbe)  free_svalue(& throw_value); throw_value.type=T_INT;
06983f1996-09-22Fredrik Hübinette (Hubbe) 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #if defined(PIKE_DEBUG) && defined(DEBUG_MALLOC)
61e9a01998-01-25Fredrik Hübinette (Hubbe)  if(verbose_debug_exit) { INT32 num,size,recount=0;
2043ba1998-02-10Fredrik Hübinette (Hubbe)  fprintf(stderr,"Exited normally, counting bytes.\n");
56ac102000-03-29Fredrik Hübinette (Hubbe)  #ifdef _REENTRANT if(count_pike_threads()>1) { fprintf(stderr,"Byte counting aborted, because all threads have not exited properly.\n"); verbose_debug_exit=0; return; } #endif
25479a2000-03-07Fredrik Hübinette (Hubbe)  search_all_memheaders_for_references();
61e9a01998-01-25Fredrik Hübinette (Hubbe)  count_memory_in_arrays(&num, &size);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  if(num)
61e9a01998-01-25Fredrik Hübinette (Hubbe)  { recount++; fprintf(stderr,"Arrays left: %d (%d bytes) (zapped)\n",num,size); } zap_all_arrays(); count_memory_in_mappings(&num, &size);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  if(num)
61e9a01998-01-25Fredrik Hübinette (Hubbe)  { recount++; fprintf(stderr,"Mappings left: %d (%d bytes) (zapped)\n",num,size); } zap_all_mappings(); count_memory_in_multisets(&num, &size);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  if(num)
61e9a01998-01-25Fredrik Hübinette (Hubbe)  fprintf(stderr,"Multisets left: %d (%d bytes)\n",num,size); if(recount) { fprintf(stderr,"Garbage collecting..\n"); do_gc(); count_memory_in_arrays(&num, &size); fprintf(stderr,"Arrays left: %d (%d bytes)\n",num,size); count_memory_in_mappings(&num, &size); fprintf(stderr,"Mappings left: %d (%d bytes)\n",num,size); count_memory_in_multisets(&num, &size); fprintf(stderr,"Multisets left: %d (%d bytes)\n",num,size); } count_memory_in_programs(&num, &size);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  if(num)
61e9a01998-01-25Fredrik Hübinette (Hubbe)  fprintf(stderr,"Programs left: %d (%d bytes)\n",num,size); { struct program *p; for(p=first_program;p;p=p->next)
3f1eeb1998-04-05Fredrik Hübinette (Hubbe)  describe_something(p, T_PROGRAM, 1);
61e9a01998-01-25Fredrik Hübinette (Hubbe)  } count_memory_in_objects(&num, &size);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  if(num)
61e9a01998-01-25Fredrik Hübinette (Hubbe)  fprintf(stderr,"Objects left: %d (%d bytes)\n",num,size);
26dc072000-04-06Fredrik Hübinette (Hubbe)  { struct object *o; for(o=first_object;o;o=o->next) describe_something(o, T_OBJECT, 1); }
61e9a01998-01-25Fredrik Hübinette (Hubbe)  cleanup_shared_string_table(); } #else
06983f1996-09-22Fredrik Hübinette (Hubbe)  zap_all_arrays();
cbd60b1996-12-04Fredrik Hübinette (Hubbe)  zap_all_mappings();
06983f1996-09-22Fredrik Hübinette (Hubbe)  cleanup_shared_string_table();
61e9a01998-01-25Fredrik Hübinette (Hubbe) #endif
5b7b061999-04-08Fredrik Hübinette (Hubbe) 
b660c81999-03-01Fredrik Hübinette (Hubbe)  really_clean_up_interpret();
5f06241999-04-11Fredrik Hübinette (Hubbe) 
5b7b061999-04-08Fredrik Hübinette (Hubbe)  cleanup_callbacks(); free_all_callable_blocks(); exit_destroy_called_mark_hash();
f6f3842000-03-07Fredrik Hübinette (Hubbe) 
4be46f2000-03-07Fredrik Hübinette (Hubbe)  free_all_mapping_blocks();
f6f3842000-03-07Fredrik Hübinette (Hubbe)  first_mapping=0;
5b7b061999-04-08Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) }