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$ +    */      #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:20:   # include "stralloc.h"   # include "pike_macros.h"   # include "main.h"   # include "constants.h"   # include "lex.h"   # include "object.h"      #else /* TESTING */      #include <stdio.h> + #include <string.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) + #if !defined(HAVE_DLOPEN) || defined(USE_SEMIDYNAMIC_MODULES)    - #if defined(HAVE_DLD_LINK) && defined(HAVE_DLD_GET_FUNC) + #ifdef USE_SEMIDYNAMIC_MODULES + #undef HAVE_DLOPEN + #define USE_STATIC_MODULES + #define HAVE_SOME_DLOPEN + #define EMULATE_DLOPEN + #define USE_DYNAMIC_MODULES + #elif defined(HAVE_DLD_LINK) && defined(HAVE_DLD_GET_FUNC)   #define USE_DLD   #define HAVE_SOME_DLOPEN   #define EMULATE_DLOPEN - #else - #if defined(HAVE_SHL_LOAD) && defined(HAVE_DL_H) + #elif defined(HAVE_SHL_LOAD) && defined(HAVE_DL_H)   #define USE_HPUX_DL   #define HAVE_SOME_DLOPEN   #define EMULATE_DLOPEN - #else -  - #ifdef USE_DLL - #if defined(HAVE_LOADLIBRARY) && defined(HAVE_FREELIBRARY) && \ + #elif defined(USE_DLL) && \ +  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 -  - #ifdef HAVE_MACH_O_DYLD_H + #elif defined(HAVE_MACH_O_DYLD_H)   /* MacOS X... */   #define USE_DYLD   #define HAVE_SOME_DLOPEN   #define EMULATE_DLOPEN - #else /* !HAVE_MACH_O_DYLD_H */ - #if !defined (USE_DLL) && defined (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 -  + /* HAVE_DLOPEN */   #define HAVE_SOME_DLOPEN   #endif         #ifdef HAVE_SOME_DLOPEN      typedef void (*modfun)(void);    - #ifdef USE_LOADLIBRARY + #ifdef USE_STATIC_MODULES +  + static void *dlopen(const char *foo, int how) + { +  struct pike_string *s = low_read_file(foo); +  char *name, *end; +  void *res; +  +  if (!s) return NULL; +  if (strncmp(s->str, "PMODULE=\"", 9)) { +  free_string(s); +  return NULL; +  } +  name = s->str + 9; +  if (!(end = strchr(name, '\"'))) { +  free_string(s); +  return NULL; +  } +  +  res = find_semidynamic_module(name, end - name); +  free_string(s); +  return res; + } +  + static char *dlerror(void) + { +  return "Invalid dynamic module."; + } +  + static void *dlsym(void *module, char *function) + { +  if (!strcmp(function, "pike_module_init")) +  return get_semidynamic_init_fun(module); +  if (!strcmp(function, "pike_module_exit")) +  return get_semidynamic_exit_fun(module); +  return NULL; + } +  + static int dlinit(void) + { +  return 1; + } +  + static void dlclose(void *module) + { + } +  + #elif defined(USE_LOADLIBRARY)   #include <windows.h>      static TCHAR *convert_string(const char *str, ptrdiff_t len)   {    ptrdiff_t e; -  TCHAR *ret=(TCHAR *)xalloc((len+1) * sizeof(TCHAR)); +  TCHAR *ret=xalloc((len+1) * sizeof(TCHAR));    for(e=0;e<len;e++) ret[e]=EXTRACT_UCHAR(str+e);    ret[e]=0;    return ret;   }      static void *dlopen(const char *foo, int how)   {    TCHAR *tmp;    HINSTANCE ret;    tmp=convert_string(foo, strlen(foo));    ret=LoadLibrary(tmp); -  free((char *)tmp); +  free(tmp);    return (void *)ret;   }      static char * dlerror(void)   {    static char buffer[200];    int err = GetLastError();    switch(err) {    case ERROR_MOD_NOT_FOUND:    return "The specified module could not be found.";
pike.git/src/dynamic_load.c:195:   {    shl_t lib;       lib = shl_load(libname, how, 0L);       return (void *)lib;   }      static char *dlerror(void)   { - #ifdef HAVE_STRERROR +     return strerror(errno); - #else -  return ""; /* I hope it's better than null..*/ - #endif +    }      static void *dlsym(void *module, char *function)   {    void *func;    int result;    shl_t mod = (shl_t)module;       result = shl_findsym(&mod, function, TYPE_UNDEFINED, &func);    if (result == -1)
pike.git/src/dynamic_load.c:376: Inside #if defined(USE_DYNAMIC_MODULES) and #if defined(NO_CAST_TO_FUN)
   void *ptr;    modfun fun;    } u;    u.ptr = ptr;    return u.fun;   }   #else /* !NO_CAST_TO_FUN */   #define CAST_TO_FUN(X) ((modfun)X)   #endif /* NO_CAST_TO_FUN */    - static void cleanup_compilation(void *ignored) + static void cleanup_compilation(void *UNUSED(ignored))   {    struct program *p = end_program();    if (p) {    free_program(p);    }   }      /*! @decl program load_module(string module_name)    *!    *! Load a binary module.
pike.git/src/dynamic_load.c:451:    ((struct module_load_error_struct *) (err_obj->storage + module_load_error_offset))       const char *err = dlerror();    if (err) {    if (err[strlen (err) - 1] == '\n')    push_string (make_shared_binary_string (err, strlen (err) - 1));    else    push_text (err);    }    else -  push_constant_text ("Unknown reason"); +  push_static_text ("Unknown reason");       add_ref (LOADERR_STRUCT (err_obj)->path = Pike_sp[-args - 1].u.string);    add_ref (LOADERR_STRUCT (err_obj)->reason = Pike_sp[-1].u.string);       if (Pike_sp[-args].u.string->len < 1024) {    throw_error_object (err_obj, "load_module", Pike_sp - args - 1, args,    "load_module(\"%s\") failed: %s\n",    module_name->str, Pike_sp[-1].u.string->str);    } else {    throw_error_object (err_obj, "load_module", Pike_sp - args - 1, args,
pike.git/src/dynamic_load.c:658: Inside #if defined(USE_DYNAMIC_MODULES)
   {    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");   #endif -  free((char *)tmp); +  free(tmp);    }   #endif   }         #endif /* NO_PIKE_GUTS */      #ifdef CREATE_MAIN   #include <stdio.h>