comparison liboctave/oct-shlib.cc @ 4110:b9238356dd07

[project @ 2002-10-17 16:14:44 by jwe]
author jwe
date Thu, 17 Oct 2002 16:14:45 +0000
parents b79da8779a0e
children bcdf1c264e08
comparison
equal deleted inserted replaced
4109:6e20cac828cd 4110:b9238356dd07
22 22
23 #ifdef HAVE_CONFIG_H 23 #ifdef HAVE_CONFIG_H
24 #include <config.h> 24 #include <config.h>
25 #endif 25 #endif
26 26
27 #if defined (WITH_SHL) 27 #if defined (HAVE_SHL_LOAD_API)
28 #include <cerrno> 28 #include <cerrno>
29 #include <cstring> 29 #include <cstring>
30 #endif 30 #endif
31 31
32 extern "C" 32 extern "C"
33 { 33 {
34 #if defined (WITH_DL) 34 #if defined (HAVE_DLOPEN_API)
35 #if defined (HAVE_DLFCN_H) 35 #if defined (HAVE_DLFCN_H)
36 #include <dlfcn.h> 36 #include <dlfcn.h>
37 #else 37 #else
38 extern void *dlopen (const char *, int); 38 extern void *dlopen (const char *, int);
39 extern const char *dlerror (void); 39 extern const char *dlerror (void);
41 extern int dlclose (void *); 41 extern int dlclose (void *);
42 #endif 42 #endif
43 #ifndef RTLD_LAZY 43 #ifndef RTLD_LAZY
44 #define RTLD_LAZY 1 44 #define RTLD_LAZY 1
45 #endif 45 #endif
46 #elif defined (WITH_SHL) 46 #elif defined (HAVE_SHL_LOAD_API)
47 #include <dl.h> 47 #include <dl.h>
48 #endif 48 #endif
49 } 49 }
50 50
51 #include "file-stat.h" 51 #include "file-stat.h"
191 fcn_names.resize (0); 191 fcn_names.resize (0);
192 192
193 tm_loaded = static_cast<time_t> (0); 193 tm_loaded = static_cast<time_t> (0);
194 } 194 }
195 195
196 #if defined (WITH_DL) 196 #if defined (HAVE_DLOPEN_API)
197 197
198 class 198 class
199 octave_dlopen_shlib : public octave_base_shlib 199 octave_dlopen_shlib : public octave_base_shlib
200 { 200 {
201 public: 201 public:
295 295
296 tabula_rasa (); 296 tabula_rasa ();
297 } 297 }
298 } 298 }
299 299
300 #elif defined (WITH_SHL) 300 #elif defined (HAVE_SHL_LOAD_API)
301 301
302 class 302 class
303 octave_shl_load_shlib : public octave_base_shlib 303 octave_shl_load_shlib : public octave_base_shlib
304 { 304 {
305 public: 305 public:
398 398
399 tabula_rasa (); 399 tabula_rasa ();
400 } 400 }
401 } 401 }
402 402
403 #elif defined (HAVE_LOADLIBRARY_API)
404
405 class
406 octave_w32_shlib: public octave_base_shlib
407 {
408 public:
409
410 octave_w32_shlib (void);
411
412 ~octave_w32_shlib (void);
413
414 void open (const std::string& f, bool warn_future = false);
415
416 void *search (const std::string& name, name_mangler mangler = 0);
417
418 void close (octave_shlib::close_hook cl_hook = 0);
419
420 bool is_open (void) const { return (handle != 0); }
421
422 private:
423
424 // No copying!
425
426 octave_w32_shlib (const octave_w32_shlib&);
427
428 octave_w32_shlib& operator = (const octave_w32_shlib&);
429
430 HINSTANCE handle;
431 };
432
433 octave_w32_shlib::octave_w32_shlib (void)
434 : octave_base_shlib (), handle (0)
435 {
436 }
437
438 octave_w32_shlib::~octave_w32_shlib (void)
439 {
440 close ();
441 }
442
443 void
444 octave_w32_shlib::open (const std::string& f, bool warn_future)
445 {
446 if (! is_open ())
447 {
448 file = f;
449
450 handle = LoadLibrary (file.c_str ());
451
452 if (handle != NULL)
453 stamp_time (warn_future);
454 else
455 {
456 DWORD lastError = GetLastError ();
457 char *msg;
458
459 switch (lastError)
460 {
461 case ERROR_MOD_NOT_FOUND:
462 case ERROR_DLL_NOT_FOUND:
463 msg = "could not find library or dependents";
464 break;
465
466 case ERROR_INVALID_DLL:
467 msg = "library or its dependents are damaged";
468 break;
469
470 case ERROR_DLL_INIT_FAILED:
471 msg = "library initialization routine failed";
472 break;
473
474 default:
475 msg = "library open failed";
476 }
477
478 (*current_liboctave_error_handler) ("%s: %s", msg, file.c_str ());
479 }
480 }
481 else
482 (*current_liboctave_error_handler)
483 ("shared library %s is already open", file.c_str ());
484 }
485
486 void *
487 octave_w32_shlib::search (const std::string& name,
488 octave_shlib::name_mangler mangler)
489 {
490 void *function = 0;
491
492 if (is_open ())
493 {
494 std::string sym_name = name;
495
496 if (mangler)
497 sym_name = mangler (name);
498
499 function
500 = static_cast<void *> (GetProcAddress (handle, sym_name.c_str ()));
501
502 if (function)
503 add_to_fcn_names (name);
504 }
505 else
506 (*current_liboctave_error_handler)
507 ("shared library %s is not open", file.c_str ());
508
509 return function;
510 }
511
512 void
513 octave_w32_shlib::close (octave_shlib::close_hook cl_hook)
514 {
515 if (is_open ())
516 {
517 do_close_hook (cl_hook);
518
519 FreeLibrary (handle);
520
521 handle = 0;
522
523 tabula_rasa ();
524 }
525 }
526
403 #endif 527 #endif
404 528
405 octave_shlib * 529 octave_shlib *
406 octave_shlib::make_shlib (void) 530 octave_shlib::make_shlib (void)
407 { 531 {
408 #if defined (WITH_DL) 532 #if defined (HAVE_DLOPEN_API)
409 return new octave_dlopen_shlib (); 533 return new octave_dlopen_shlib ();
410 #elif defined (WITH_SHL) 534 #elif defined (HAVE_SHL_LOAD_API)
411 return new octave_shl_load_shlib (); 535 return new octave_shl_load_shlib ();
536 #elif defined (HAVE_LOADLIBRARY_API)
537 return new octave_w32_shlib ();
412 #else 538 #else
413 return new octave_base_shlib (); 539 return new octave_base_shlib ();
414 #endif 540 #endif
415 } 541 }
416 542