pike.git / src / dynamic_load.c

version» Context lines:

pike.git/src/dynamic_load.c:2:   # 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"   # include "constants.h"    - RCSID("$Id: dynamic_load.c,v 1.53 2001/08/02 22:24:54 hubbe Exp $"); + RCSID("$Id: dynamic_load.c,v 1.54 2001/09/10 15:51:23 grubba Exp $");    -  + #else /* TESTING */ +  + #include <stdio.h> +    #endif /* !TESTING */      #ifdef HAVE_ERRNO_H   #include <errno.h>   #endif /* HAVE_ERRNO_H */   #ifdef HAVE_STRING_H   #include <string.h>   #endif /* HAVE_STRING_H */      #if !defined(HAVE_DLOPEN)
pike.git/src/dynamic_load.c:35: Inside #if 0
     #if 0   #if defined(HAVE_LOADLIBRARY) && defined(HAVE_FREELIBRARY) && \    defined(HAVE_GETPROCADDRESS) && defined(HAVE_WINBASE_H)   #define USE_LOADLIBRARY   #define HAVE_SOME_DLOPEN   #define EMULATE_DLOPEN   #endif   #endif /* 0 */    + #ifdef HAVE_MACH_O_DYLD_H + /* MacOS X... */ + #define USE_DYLD + #define HAVE_SOME_DLOPEN + #define EMULATE_DLOPEN + #else /* !HAVE_MACH_O_DYLD_H */   #ifdef USE_MY_WIN32_DLOPEN   #include "pike_dlfcn.h"   #define HAVE_SOME_DLOPEN   #define HAVE_DLOPEN   #endif -  + #endif /* HAVE_MACH_O_DYLD_H */      #endif   #endif   #else   #define HAVE_SOME_DLOPEN   #endif         #ifdef HAVE_SOME_DLOPEN   
pike.git/src/dynamic_load.c:101: Inside #if defined(HAVE_SOME_DLOPEN)
  {    return (void *)GetProcAddress((HMODULE)module,    function);   }      static void dlclose(void *module)   {    FreeLibrary((HMODULE)module);   }    - #define dlinit() + #define dlinit() 1      #endif /* USE_LOADLIBRARY */         #ifdef USE_DLD   #include <dld.h>   static void *dlopen(const char *module_name, int how)   {    dld_create_reference("pike_module_init");    if(dld_link(module_name))
pike.git/src/dynamic_load.c:136:    return dld_get_func(function);   }      static void *dlclose(void *module)   {    if(!module) return;    dld_unlink_by_file((char *)module);    free(module);   }    - static void dlinit(void) + static int dlinit(void)   {    extern char ** ARGV;    if(dld_init(dld_find_executable(ARGV[0])))    {    fprintf(stderr,"Failed to init dld\n"); -  exit(1); +  return 0;    } -  +  /* OK */ +  return 1;   }      #endif /* USE_DLD */         #ifdef USE_HPUX_DL      #include <dl.h>      #if defined(BIND_VERBOSE)
pike.git/src/dynamic_load.c:196:    if (result == -1)    return NULL;    return func;   }      static void dlclose(void *module)   {    shl_unload((shl_t)module);   }    - #define dlinit() + #define dlinit() 1      #endif /* USE_HPUX_DL */    -  + #ifdef USE_DYLD    -  + #include <mach-o/dyld.h> +  + #define RTLD_NOW NSLINKMODULE_OPTION_BINDNOW +  + #define dlinit() _dyld_present() +  + static void *dlopen(const char *module_name, int how) + { +  NSObjectFileImageReturnCode code = 0; +  NSObjectFileImage image = NULL; +  +  if ((code = NSCreateObjectFileImageFromFile(module_name, &image)) != +  NSObjectFileImageSuccess) { +  fprintf(stderr, "NSCreateObjectFileImageFromFile(\"%s\") failed with %d\n", +  module_name, code); +  return NULL; +  } +  /* FIXME: image should be freed somewhere! */ +  return NSLinkModule(image, module_name, +  how | NSLINKMODULE_OPTION_RETURN_ON_ERROR); + } +  + static char *dlerror(void) + { +  NSLinkEditErrors class = 0; +  int error_number = 0; +  char *file_name = NULL; +  char *error_string = NULL; +  NSLinkEditError(&class, &error_number, &file_name, &error_string); +  return error_string; + } +  + static void *dlsym(void *module, char *function) + { +  return NSLookupSymbolInModule(module, function); + } +  + static void *dlclose(void *module) + { +  NSUnLinkModule(module, NSUNLINKMODULE_OPTION_NONE); +  return NULL; + } +  + #endif /* USE_DYLD */ +  +    #ifndef EMULATE_DLOPEN      #ifdef HAVE_DLFCN_H   #include <dlfcn.h>   #endif    - #define dlinit() + #define dlinit() 1   #endif /* !EMULATE_DLOPEN */         #endif /* HAVE_SOME_DLOPEN */      #ifndef RTLD_NOW   #define RTLD_NOW 0   #endif      #ifndef RTLD_LAZY
pike.git/src/dynamic_load.c:363:    pop_n_elems(args);    push_program(end_program());   }      #endif /* USE_DYNAMIC_MODULES */         void init_dynamic_load(void)   {   #ifdef USE_DYNAMIC_MODULES -  dlinit(); +  if (dlinit()) {    -  +     /* function(string:program) */    -  ADD_EFUN("load_module",f_load_module,tFunc(tStr,tPrg(tObj)),OPT_EXTERNAL_DEPEND); +  ADD_EFUN("load_module", f_load_module, +  tFunc(tStr,tPrg(tObj)), 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)    (*tmp->exit)();