pike.git / src / dynamic_load.c

version» Context lines:

pike.git/src/dynamic_load.c:10:   # include "constants.h"   # include "pike_error.h"   # include "module.h"   # include "stralloc.h"   # include "pike_macros.h"   # include "main.h"   # include "constants.h"   # include "language.h"   # include "lex.h"    - RCSID("$Id: dynamic_load.c,v 1.59 2002/01/31 17:52:14 marcus Exp $"); + RCSID("$Id: dynamic_load.c,v 1.60 2002/03/10 03:14:46 mast Exp $");      #else /* TESTING */      #include <stdio.h>      #endif /* !TESTING */      #ifdef HAVE_ERRNO_H   #include <errno.h>   #endif /* HAVE_ERRNO_H */
pike.git/src/dynamic_load.c:305: Inside #if undefined(NO_PIKE_GUTS)
  #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:341:   };      static void cleanup_compilation(struct compilation_save *save)   {    free_program(end_program());    free_string(lex.current_file);    compilation_depth = save->compilation_depth;    lex = save->lex;   }    - /*! @decl int load_module(string module_name) + /*! @decl program load_module(string module_name)    *!    *! Load a binary module.    *!    *! This function loads a module written in C or some other language    *! into Pike. The module is initialized and any programs or constants    *! defined will immediately be available.    *!    *! When a module is loaded the function @tt{pike_module_init()@} will    *! be called to initialize it. When Pike exits @tt{pike_module_exit()@}    *! will be called. These two functions @b{must@} be available in the module.
pike.git/src/dynamic_load.c:396:    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) { +  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:420:    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;       save.lex = lex;    lex.current_line=1;    lex.current_file=make_shared_string("-");    save.compilation_depth=compilation_depth;    compilation_depth=-1;    start_new_program();   
pike.git/src/dynamic_load.c:451: Inside #if defined(PIKE_DEBUG)
   module_name,    PTRDIFF_T_TO_LONG(sp - save_sp));    }   #endif       pop_n_elems(args);    push_program(end_program());    free_string(lex.current_file);    compilation_depth = save.compilation_depth;    lex = save.lex; +  add_ref(new_module->module_prog = sp[-1].u.program);   }      #endif /* USE_DYNAMIC_MODULES */         void init_dynamic_load(void)   {   #ifdef USE_DYNAMIC_MODULES    if (dlinit()) {   
pike.git/src/dynamic_load.c:482: Inside #if defined(USE_DYNAMIC_MODULES)
  #ifdef USE_DYNAMIC_MODULES    struct module_list *tmp;    JMP_BUF recovery;    for (tmp = dynamic_module_list; tmp; tmp = tmp->next)    {    if(SETJMP(recovery))    call_handle_error();    else    (*tmp->exit)();    UNSETJMP(recovery); +  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   }         #endif /* NO_PIKE_GUTS */      #ifdef CREATE_MAIN   #include <stdio.h>