/[ascend]/trunk/base/generic/utilities/ascDynaLoad.c
ViewVC logotype

Diff of /trunk/base/generic/utilities/ascDynaLoad.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 426 by johnpye, Fri Mar 31 08:52:57 2006 UTC revision 427 by johnpye, Tue Apr 4 04:13:34 2006 UTC
# Line 25  Line 25 
25   */   */
26    
27  /*  /*
28      Small changes made by Michael Moore (mdm@cis.ohio-state.edu)      This file *should* support unix/linux-style systems (dlfcn.h)
29      December 24th, 1993.      and Windows.
     The tcl sections ripped out by Kirk Abbott (ka0p@edrc.cmu.edu)  
     September 3rd, 1994.  
     Removed OSF, Ultrix sections from this file -- johnpye, Mon 2 Jan 2005  
   
     To date the architectures supported are:  
         sun - pure sunos, defines also handle MACH.  
         solaris,  
         hpux  
         sgi  
         Windows  
30    
31      Remember that under most systems, profiling does not work      Note that under many systems, profiling does not work
32      with dynamic libraries. !      with dynamic libraries!
33  */  */
34    
35    
36    
37    
38    #ifdef DYNAMIC_PACKAGES
39    
40    
41    
42    
43  #include <stdio.h>  #include <stdio.h>
44  #include <stdlib.h>  #include <stdlib.h>
45  #include <stdarg.h>  #include <stdarg.h>
# Line 185  void AscCheckDuplicateLoad(CONST char *p Line 183  void AscCheckDuplicateLoad(CONST char *p
183    }    }
184  }  }
185    
186  /*---------------------------------------  /*-----------------------------------------------
   PLATFORM-SPECIFIC STUFF  
 */  
   
 #ifdef __WIN32__  
 # include <windows.h>  
 /*  
187      WINDOWS      WINDOWS
188  */  */
189    #if defined(__WIN32__)
190    # include <windows.h>
191    
192  int Asc_DynamicLoad(CONST char *path, CONST char *initFun)  int Asc_DynamicLoad(CONST char *path, CONST char *initFun)
193  {  {
194  #define ASCDL_OK /* this line should appear inside each Asc_DynamicLoad */  #define ASCDL_OK /* this line should appear inside each Asc_DynamicLoad */
# Line 231  int Asc_DynamicLoad(CONST char *path, CO Line 226  int Asc_DynamicLoad(CONST char *path, CO
226    }    }
227    return (install == NULL) ? 0 : (*install)(CreateUserFunction,error_reporter);    return (install == NULL) ? 0 : (*install)(CreateUserFunction,error_reporter);
228  }  }
229    
230    # define UNLOAD FreeLibrary
231    # define DLLSYM GetProcAddress
232    # define DLL_CAST (HINSTANCE)
233    # define ASC_DLERRSTRING "unknown"
234    # define UNLOAD_SUCCESS TRUE
235    
236  #endif /* __WIN32__ */  #endif /* __WIN32__ */
237    
238    /*-----------------------------------------------
239        UNIX/LINUX
240    */
241  /*  /*
242      SOLARIS and LINUX      SOLARIS and LINUX
243  */  */
# Line 241  int Asc_DynamicLoad(CONST char *path, CO Line 246  int Asc_DynamicLoad(CONST char *path, CO
246      From a quick Google, it appears that AIX 5.1 now provides dlfcn.h,      From a quick Google, it appears that AIX 5.1 now provides dlfcn.h,
247      so I'll remove the code that was emulating it here. -- johnpye      so I'll remove the code that was emulating it here. -- johnpye
248  */  */
249  #if defined(sun) || defined(linux) || defined(__unix__) || defined(solaris) || defined(_AIX) || defined(_SGI_SOURCE)  #if defined(sun) || defined(linux) || defined(__unix__) \
250        || defined(solaris) || defined(_AIX) || defined(_SGI_SOURCE)
251  # ifndef MACH  # ifndef MACH
252  #  include <dlfcn.h>  #  include <dlfcn.h>
253  # else  # else
254  #  error "MACH unsupported"  #  error "MACH unsupported"
255  # endif  # endif
256    
 /*  
     R.I.P. OSF  
     http://en.wikipedia.org/wiki/Open_Software_Foundation  
 */  
   
 /*  
     POSIX-type systems (see above)  
 */  
257  int Asc_DynamicLoad(CONST char *path, CONST char *initFun)  int Asc_DynamicLoad(CONST char *path, CONST char *initFun)
258  {  {
259  #define ASCDL_OK /* this line should appear inside each Asc_DynamicLoad */  #define ASCDL_OK /* this line should appear inside each Asc_DynamicLoad */
# Line 293  int Asc_DynamicLoad(CONST char *path, CO Line 291  int Asc_DynamicLoad(CONST char *path, CO
291    return (install == NULL) ? 0 : (*install)(CreateUserFunction,error_reporter);    return (install == NULL) ? 0 : (*install)(CreateUserFunction,error_reporter);
292  }  }
293    
294    # define UNLOAD dlclose
295    # define DLLSYM dlsym
296    # define DLL_CAST (void *)
297    # define ASC_DLERRSTRING dlerror()
298    # define UNLOAD_SUCCESS 0
299    
300  #endif /* posix: linux, unix, solaris,sgi */  #endif /* posix: linux, unix, solaris,sgi */
301    
302    /*-----------------------------------------------
303        HPUX
304    */
305  #ifdef __hpux  #ifdef __hpux
306  /*  /*
307   * Modified to work with HP/UX 9.X Operating System.      Kirk Abbott last fiddled with the following, which was
308   * Michael Moore (mdm@cis.ohio-state.edu)      originally put in place my Michael Moore for an
309   * December 24th, 1993.      HP/UX 9.X Operating Sys back in 1993. Arrr. No idea if
310   * Further modified by Kirk Abbott (ka0p@edrc.cmu.edu)      it still works.
311   * to fit in with the ASCEND system.  */
  */  
312    
313  # include <dl.h>  # include <dl.h>
314  # include <errno.h>  # include <errno.h>
315    
 /*  
     HPUX  
 */  
316  int Asc_DynamicLoad(CONST char *path, CONST char *initFun)  int Asc_DynamicLoad(CONST char *path, CONST char *initFun)
317  {  {
318  # define ASCDL_OK /* this line should appear inside each Asc_DynamicLoad */  # define ASCDL_OK /* this line should appear inside each Asc_DynamicLoad */
# Line 354  int Asc_DynamicLoad(CONST char *path, CO Line 357  int Asc_DynamicLoad(CONST char *path, CO
357    return (install == NULL) ? 0 : (*install)(CreateUserFunction,error_reporter);    return (install == NULL) ? 0 : (*install)(CreateUserFunction,error_reporter);
358  }  }
359    
 #endif /* __hpux */  
   
 /*  
     R.I.P. Ultrix  
     http://en.wikipedia.org/wiki/Ultrix  
 */  
   
 #ifndef ASCDL_OK  
 # error "Unable to build ascDynaload.o. Turn off strict ansi cc options."  
 #endif /* adlok */  
 #ifdef __hpux  
360  # define UNLOAD shl_unload  # define UNLOAD shl_unload
361  # define DLL_CAST (shl_t)  # define DLL_CAST (shl_t)
362  # define ASC_DLERRSTRING "NULL definition"  # define ASC_DLERRSTRING "NULL definition"
363  # define UNLOAD_SUCCESS 0  # define UNLOAD_SUCCESS 0
364    
365  #endif /* __hpux */  #endif /* __hpux */
 #ifdef __WIN32__  
 # define UNLOAD FreeLibrary  
 # define DLLSYM GetProcAddress  
 # define DLL_CAST (HINSTANCE)  
 # define ASC_DLERRSTRING "unknown"  
 # define UNLOAD_SUCCESS TRUE  
 #endif /* __WIN32__ */  
 #ifndef UNLOAD  
 # define UNLOAD dlclose  
 # define DLLSYM dlsym  
 # define DLL_CAST (void *)  
 # define ASC_DLERRSTRING dlerror()  
 # define UNLOAD_SUCCESS 0  
 #endif /* UNLOAD */  
366    
367  /*--------------------------------------  /*-----------------------------------------------
368    MORE MOSTLY-GENERIC STUFF      Did we get something from the above?
369    */
370    
371    #if !defined(ASCDL_OK)
372    # error "Unable to define an Asc_DynamicLoad function. Check your compiler options and installed system libraries."
373    #endif
374    
375    /**-----------------------------------------------
376        DYNAMIC UNLOADING
377  */  */
378    
379  int Asc_DynamicUnLoad(CONST char *path)  int Asc_DynamicUnLoad(CONST char *path)
# Line 413  int Asc_DynamicUnLoad(CONST char *path) Line 400  int Asc_DynamicUnLoad(CONST char *path)
400    return (retval == UNLOAD_SUCCESS) ? 0 : retval;    return (retval == UNLOAD_SUCCESS) ? 0 : retval;
401  }  }
402    
403    /**-----------------------------------------------
404        DYNAMIC VARIABLE LINKING
405    */
406  void *Asc_DynamicVariable(CONST char *libname, CONST char *symbol)  void *Asc_DynamicVariable(CONST char *libname, CONST char *symbol)
407  {  {
408    void *dlreturn;    void *dlreturn;
# Line 467  void *Asc_DynamicVariable(CONST char *li Line 456  void *Asc_DynamicVariable(CONST char *li
456    return symreturn;    return symreturn;
457  }  }
458    
459    /**-----------------------------------------------
460        DYNAMIC FUNCTION LINKING
461    */
462  DynamicF Asc_DynamicFunction(CONST char *libname, CONST char *symbol)  DynamicF Asc_DynamicFunction(CONST char *libname, CONST char *symbol)
463  {  {
464    void *dlreturn;    void *dlreturn;
# Line 519  DynamicF Asc_DynamicFunction(CONST char Line 510  DynamicF Asc_DynamicFunction(CONST char
510    }    }
511    return symreturn;    return symreturn;
512  }  }
513    
514    
515    
516    #endif
517    
518    

Legend:
Removed from v.426  
changed lines
  Added in v.427

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22