pike.git / src / dynamic_load.c

version» Context lines:

pike.git/src/dynamic_load.c:1:   #ifndef TESTING   # include "global.h"   # include "interpret.h"   # include "constants.h"   # include "pike_error.h"   # include "module.h"   # include "stralloc.h"   # include "pike_macros.h"   # include "main.h"    - RCSID("$Id: dynamic_load.c,v 1.50 2000/12/23 07:33:49 hubbe Exp $"); + RCSID("$Id: dynamic_load.c,v 1.51 2002/07/16 11:52:07 mast Exp $");      #endif /* !TESTING */      #ifdef HAVE_ERRNO_H   #include <errno.h>   #endif /* HAVE_ERRNO_H */   #ifdef HAVE_STRING_H   #include <string.h>   #endif /* HAVE_STRING_H */   
pike.git/src/dynamic_load.c:236: Inside #if undefined(TESTING)
  #if defined(HAVE_DLOPEN) || defined(USE_DLD) || defined(USE_HPUX_DL) || defined(USE_LOADLIBRARY)   #define USE_DYNAMIC_MODULES   #endif      #ifdef USE_DYNAMIC_MODULES      struct module_list   {    struct module_list * next;    void *module; +  struct program *module_prog;    modfun init, exit;   };      struct module_list *dynamic_module_list = 0;      #ifdef NO_CAST_TO_FUN   /* Function pointers can't be casted to scalar pointers according to    * ISO-C (probably to support true Harward achitecture machines).    */   static modfun CAST_TO_FUN(void *ptr)
pike.git/src/dynamic_load.c:289:    const char *err = dlerror();    if(!err) err = "Unknown reason";    if (sp[-args].u.string->len < 1024) {    Pike_error("load_module(\"%s\") failed: %s\n",    sp[-args].u.string->str, err);    } else {    Pike_error("load_module() failed: %s\n", err);    }    }    +  { +  struct module_list *mp; +  for (mp = dynamic_module_list; mp; mp = mp->next) +  if (mp->module == module && mp->module_prog) { +  pop_n_elems(args); +  ref_push_program(mp->module_prog); +  return; +  } +  } +     init = CAST_TO_FUN(dlsym(module, "pike_module_init"));    if (!init) {    init = CAST_TO_FUN(dlsym(module, "_pike_module_init"));    }    exit = CAST_TO_FUN(dlsym(module, "pike_module_exit"));    if (!exit) {    exit = CAST_TO_FUN(dlsym(module, "_pike_module_exit"));    }       if(!init || !exit)
pike.git/src/dynamic_load.c:313:    Pike_error("Failed to initialize dynamic module \"%s\".\n", module_name);    } else {    Pike_error("Failed to initialize dynamic module.\n");    }    }       new_module=ALLOC_STRUCT(module_list);    new_module->next=dynamic_module_list;    dynamic_module_list=new_module;    new_module->module=module; +  new_module->module_prog = NULL;    new_module->init=init;    new_module->exit=exit;       start_new_program();   #ifdef PIKE_DEBUG    { struct svalue *save_sp=sp;   #endif    (*(modfun)init)();   #ifdef PIKE_DEBUG    if(sp != save_sp)    fatal("load_module(%s) left %ld droppings on stack!\n",    module_name,    PTRDIFF_T_TO_LONG(sp - save_sp));    }   #endif       pop_n_elems(args);    push_program(end_program()); -  +  add_ref(new_module->module_prog = Pike_sp[-1].u.program);   }      #endif /* USE_DYNAMIC_MODULES */         void init_dynamic_load(void)   {   #ifdef USE_DYNAMIC_MODULES    dlinit();   
pike.git/src/dynamic_load.c:353: Inside #if defined(USE_DYNAMIC_MODULES)
      ADD_EFUN("load_module",f_load_module,tFunc(tStr,tPrg),OPT_EXTERNAL_DEPEND);   #endif   }      /* Call the pike_module_exit() callbacks for the dynamic modules. */   void exit_dynamic_load(void)   {   #ifdef USE_DYNAMIC_MODULES    struct module_list *tmp; -  for (tmp = dynamic_module_list; tmp; tmp = tmp->next) +  for (tmp = dynamic_module_list; tmp; tmp = tmp->next) {    (*tmp->exit)(); -  +  free_program(tmp->module_prog); +  tmp->module_prog = NULL; +  }   #endif   }      /* Unload all the dynamically loaded modules. */   void free_dynamic_load(void)   {   #ifdef USE_DYNAMIC_MODULES    while(dynamic_module_list)    {    struct module_list *tmp=dynamic_module_list;    dynamic_module_list=tmp->next;   #ifndef DEBUG_MALLOC    dlclose(tmp->module);   #endif -  +  if (tmp->module_prog) free_program(tmp->module_prog);    free((char *)tmp);    }   #endif   }         #else /* TESTING */   #include <stdio.h>      int main()