30 #if defined (HAVE_SHL_LOAD_API)
35 #if defined (HAVE_DYLD_API)
36 #include <mach-o/dyld.h>
41 #if defined (HAVE_DLOPEN_API)
42 #if defined (HAVE_DLFCN_H)
45 extern void *dlopen (
const char *,
int);
46 extern const char *dlerror (
void);
47 extern void *dlsym (
void *,
const char *);
48 extern int dlclose (
void *);
50 #elif defined (HAVE_SHL_LOAD_API)
52 #elif defined (HAVE_LOADLIBRARY_API)
53 #define WIN32_LEAN_AND_MEAN
64 : count (1), file (f), tm_loaded (), fcn_names ()
69 (*current_liboctave_warning_with_id_handler)
70 (
"Octave:warn-future-time-stamp",
71 "timestamp on file %s is in the future",
file.c_str ());
78 return (fs && fs.
is_newer (tm_loaded));
88 tm_loaded = fs.
mtime ();
90 (*current_liboctave_warning_handler)
91 (
"library %s not reloaded due to existing references", file.c_str ());
99 std::map<std::string, shlib_rep *>::iterator p = instances.find (f);
100 if (p != instances.end ())
108 retval = new_instance (f);
118 if (p == fcn_names.end ())
131 if (p != fcn_names.end () && --(p->second) == 0)
133 fcn_names.erase (fcn_name);
153 #if defined (HAVE_DLOPEN_API)
160 octave_dlopen_shlib (
const std::string&
f);
162 ~octave_dlopen_shlib (
void);
164 void *
search (
const std::string& name,
171 bool is_open (
void)
const {
return (library != 0); }
177 octave_dlopen_shlib (
const octave_dlopen_shlib&);
179 octave_dlopen_shlib&
operator = (
const octave_dlopen_shlib&);
184 octave_dlopen_shlib::octave_dlopen_shlib (
const std::string&
f)
193 #if defined (RTLD_NOW)
197 library = dlopen (
file.c_str (), flags);
201 const char *msg = dlerror ();
204 (*current_liboctave_error_handler) (
"%s: failed to load: %s",
212 octave_dlopen_shlib::~octave_dlopen_shlib (
void)
226 std::string sym_name = name;
229 sym_name = mangler (name);
231 function = dlsym (library, sym_name.c_str ());
235 (
"shared library %s is not open", file.c_str ());
240 #elif defined (HAVE_SHL_LOAD_API)
247 octave_shl_load_shlib (
const std::string& f);
249 ~octave_shl_load_shlib (
void);
251 void *
search (
const std::string& name,
254 bool is_open (
void)
const {
return (library != 0); }
260 octave_shl_load_shlib (
const octave_shl_load_shlib&);
262 octave_shl_load_shlib&
operator = (
const octave_shl_load_shlib&);
267 octave_shl_load_shlib::octave_shl_load_shlib (
const std::string& f)
272 library = shl_load (
file.c_str (), BIND_IMMEDIATE, 0L);
277 (*current_liboctave_error_handler) (
"%s", gnulib::strerror (errno));
281 octave_shl_load_shlib::~octave_shl_load_shlib (
void)
284 shl_unload (library);
295 std::string sym_name = name;
298 sym_name = mangler (name);
300 int status = shl_findsym (&library, sym_name.c_str (),
301 TYPE_UNDEFINED, &
function);
305 (
"shared library %s is not open",
file.c_str ());
310 #elif defined (HAVE_LOADLIBRARY_API)
317 octave_w32_shlib (
const std::string& f);
319 ~octave_w32_shlib (
void);
321 void *
search (
const std::string& name,
324 bool is_open (
void)
const {
return (handle != 0); }
330 octave_w32_shlib (
const octave_w32_shlib&);
332 octave_w32_shlib&
operator = (
const octave_w32_shlib&);
337 octave_w32_shlib::octave_w32_shlib (
const std::string& f)
340 handle = LoadLibrary (
file.c_str ());
344 DWORD lastError = GetLastError ();
349 case ERROR_MOD_NOT_FOUND:
350 case ERROR_DLL_NOT_FOUND:
351 msg =
"could not find library or dependents";
354 case ERROR_INVALID_DLL:
355 msg =
"library or its dependents are damaged";
358 case ERROR_DLL_INIT_FAILED:
359 msg =
"library initialization routine failed";
363 msg =
"library open failed";
366 (*current_liboctave_error_handler) (
"%s: %s", msg,
file.c_str ());
370 octave_w32_shlib::~octave_w32_shlib (
void)
373 FreeLibrary (handle);
378 void * octave_w32_search (HINSTANCE handle,
const char * name);
389 std::string sym_name = name;
392 sym_name = mangler (name);
394 function = octave_w32_library_search (handle, sym_name.c_str ());
398 (
"shared library %s is not open", file.c_str ());
403 #elif defined (HAVE_DYLD_API)
410 octave_dyld_shlib (
void);
412 ~octave_dyld_shlib (
void);
414 void open (
const std::string& f);
416 void *
search (
const std::string& name,
421 bool is_open (
void)
const {
return (handle != 0); }
427 octave_dyld_shlib (
const octave_dyld_shlib&);
429 octave_dyld_shlib&
operator = (
const octave_dyld_shlib&);
431 NSObjectFileImage img;
435 octave_dyld_shlib::octave_dyld_shlib (
const std::string& f)
438 int returnCode = NSCreateObjectFileImageFromFile (
file.c_str (), &img);
440 if (NSObjectFileImageSuccess == returnCode)
442 handle = NSLinkModule (img,
file.c_str (),
443 (NSLINKMODULE_OPTION_RETURN_ON_ERROR
444 | NSLINKMODULE_OPTION_PRIVATE));
447 NSLinkEditErrors ler;
450 const char *errstr = 0;
452 NSLinkEditError (&ler, &lerno, &file2, &errstr);
455 errstr =
"unspecified error";
457 (*current_liboctave_error_handler)
458 (
"%s: %s",
file.c_str (), errstr);
463 (*current_liboctave_error_handler)
464 (
"got NSObjectFileImageReturnCode %d", returnCode);
471 octave_dyld_shlib::~octave_dyld_shlib (
void)
474 NSUnLinkModule (handle, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES);
476 NSDestroyObjectFileImage (img);
487 std::string sym_name = name;
490 sym_name = mangler (name);
492 NSSymbol symbol = NSLookupSymbolInModule (handle, sym_name.c_str ());
496 function = NSAddressOfSymbol (symbol);
501 (
"bundle %s is not open", file.c_str ());
511 #if defined (HAVE_DLOPEN_API)
512 return new octave_dlopen_shlib (f);
513 #elif defined (HAVE_SHL_LOAD_API)
514 return new octave_shl_load_shlib (f);
515 #elif defined (HAVE_LOADLIBRARY_API)
516 return new octave_w32_shlib (f);
517 #elif defined (HAVE_DYLD_API)
518 return new octave_dyld_shlib (f);
520 (*current_liboctave_error_handler)
521 (
"no API for dynamic loading is available");