pike.git / src / dynamic_load.c

version» Context lines:

pike.git/src/dynamic_load.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: dynamic_load.c,v 1.74 2003/12/10 14:42:20 grubba Exp $ + || $Id: dynamic_load.c,v 1.75 2004/03/21 16:42:01 grubba Exp $   */      #ifdef TESTING   #define NO_PIKE_INCLUDES   #define CREATE_MAIN   #define NO_PIKE_GUTS   #endif      #ifndef NO_PIKE_INCLUDES   # include "global.h"
pike.git/src/dynamic_load.c:17:   # 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.74 2003/12/10 14:42:20 grubba Exp $"); + RCSID("$Id: dynamic_load.c,v 1.75 2004/03/21 16:42:01 grubba 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:315: Inside #if undefined(NO_PIKE_GUTS)
   defined(USE_LOADLIBRARY) || defined(USE_DYLD)   #define USE_DYNAMIC_MODULES   #endif      #ifdef USE_DYNAMIC_MODULES      struct module_list   {    struct module_list * next;    void *module; +  struct pike_string *name;    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).    */
pike.git/src/dynamic_load.c:380:    *! @expr{"name.so"@} to load modules from the current directory.    */   void f_load_module(INT32 args)   {    extern int compilation_depth;    extern int global_callable_flags;       void *module;    modfun init, exit;    struct module_list *new_module; -  const char *module_name; +  struct pike_string *module_name;       ONERROR err;       struct compilation_save save;    -  if(Pike_sp[-args].type != T_STRING) +  module_name = Pike_sp[-args].u.string; +  +  if((Pike_sp[-args].type != T_STRING) || +  (module_name->size_shift) || +  (strlen(module_name->str) != module_name->len)) {    Pike_error("Bad argument 1 to load_module()\n"); -  +  }    -  module_name = Pike_sp[-args].u.string->str; +  { +  struct module_list *mp; +  for (mp = dynamic_module_list; mp; mp = mp->next) +  if (mp->name == module_name && mp->module_prog) { +  pop_n_elems(args); +  ref_push_program(mp->module_prog); +  return; +  } +  }       /* Removing RTLD_GLOBAL breaks some PiGTK themes - Hubbe */    /* Using RTLD_LAZY is faster, but makes it impossible to    * detect linking problems at runtime..    */ -  module=dlopen(module_name, +  module=dlopen(module_name->str,    RTLD_NOW /*|RTLD_GLOBAL*/ );       if(!module)    {    const char *err = dlerror();    if(!err) err = "Unknown reason";    if (Pike_sp[-args].u.string->len < 1024) {    Pike_error("load_module(\"%s\") failed: %s\n", -  Pike_sp[-args].u.string->str, err); +  module_name->str, err);    } else {    Pike_error("load_module() failed: %s\n", err);    }    }    -  + #ifdef PIKE_DEBUG    {    struct module_list *mp;    for (mp = dynamic_module_list; mp; mp = mp->next)    if (mp->module == module && mp->module_prog) { -  +  fprintf(stderr, "load_module(): Module loaded twice:\n" +  "Old name: %s\n" +  "New name: %s\n", +  mp->name->str, module_name->str);    pop_n_elems(args);    ref_push_program(mp->module_prog);    return;    }    } -  + #endif /* PIKE_DEBUG */       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)    {    dlclose(module);    -  if (strlen(module_name) < 1024) { -  Pike_error("Failed to initialize dynamic module \"%s\".\n", module_name); +  if (strlen(module_name->str) < 1024) { +  Pike_error("Failed to initialize dynamic module \"%s\".\n", +  module_name->str);    } else {    Pike_error("Failed to initialize dynamic module.\n");    }    }   #if defined(__NT__) && defined(_M_IA64)    else    {    fprintf(stderr, "pike_module_init: 0x%p\n"    " func: 0x%p\n"    " gp: 0x%p\n",
pike.git/src/dynamic_load.c:457: Inside #if defined(__NT__) && defined(_M_IA64)
   " func: 0x%p\n"    " gp: 0x%p\n",    exit, ((void **)exit)[0], ((void **)exit)[1]);    }   #endif /* __NT__ && _M_IA64 */       new_module=ALLOC_STRUCT(module_list);    new_module->next=dynamic_module_list;    dynamic_module_list=new_module;    new_module->module=module; +  copy_shared_string(new_module->name, Pike_sp[-args].u.string);    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:485:    fprintf(stderr, "Calling pike_module_init()...\n");   #endif /* __NT__ && _M_IA64 */    (*(modfun)init)();   #if defined(__NT__) && defined(_M_IA64)    fprintf(stderr, "pike_module_init() done.\n");   #endif /* __NT__ && _M_IA64 */    UNSET_ONERROR(err);   #ifdef PIKE_DEBUG    if(Pike_sp != save_sp)    Pike_fatal("load_module(%s) left %ld droppings on stack!\n", -  module_name, +  module_name->str,    PTRDIFF_T_TO_LONG(Pike_sp - save_sp));    }   #endif       pop_n_elems(args);    {    struct program *p = end_program();    free_string(lex.current_file);    compilation_depth = save.compilation_depth;    lex = save.lex;    if (p) {    push_program(p);    add_ref(new_module->module_prog = Pike_sp[-1].u.program);    } else {    /* Initialization failed. */    new_module->exit();    dlclose(module);    dynamic_module_list = new_module->next;    free(new_module); -  if (strlen(module_name) < 1024) { -  Pike_error("Failed to initialize dynamic module \"%s\".\n", module_name); +  if (strlen(module_name->str) < 1024) { +  Pike_error("Failed to initialize dynamic module \"%s\".\n", +  module_name->str);    } else {    Pike_error("Failed to initialize dynamic module.\n");    }    }    }   }      #endif /* USE_DYNAMIC_MODULES */      
pike.git/src/dynamic_load.c:562: Inside #if defined(USE_DYNAMIC_MODULES)
  #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   #ifdef PIKE_DEBUG    if (tmp->module_prog) -  Pike_fatal ("There's still a program for a dynamic module.\n"); +  Pike_fatal ("There's still a program for dynamic module \"%s\".\n", +  tmp->name->str);   #endif -  +  free_string(tmp->name); +  tmp->name = NULL;    free((char *)tmp);    }   #endif   }         #endif /* NO_PIKE_GUTS */      #ifdef CREATE_MAIN   #include <stdio.h>