Mercurial > hg > octave-lyh
comparison liboctave/oct-shlib.cc @ 4162:bcdf1c264e08
[project @ 2002-11-10 00:34:37 by jwe]
author | jwe |
---|---|
date | Sun, 10 Nov 2002 00:34:37 +0000 |
parents | b9238356dd07 |
children | e4b7578e5fc7 |
comparison
equal
deleted
inserted
replaced
4161:8eb844b6349b | 4162:bcdf1c264e08 |
---|---|
25 #endif | 25 #endif |
26 | 26 |
27 #if defined (HAVE_SHL_LOAD_API) | 27 #if defined (HAVE_SHL_LOAD_API) |
28 #include <cerrno> | 28 #include <cerrno> |
29 #include <cstring> | 29 #include <cstring> |
30 #endif | |
31 | |
32 #if defined (HAVE_DYLD_API) | |
33 #include <Mach-O/dyld.h> | |
30 #endif | 34 #endif |
31 | 35 |
32 extern "C" | 36 extern "C" |
33 { | 37 { |
34 #if defined (HAVE_DLOPEN_API) | 38 #if defined (HAVE_DLOPEN_API) |
522 | 526 |
523 tabula_rasa (); | 527 tabula_rasa (); |
524 } | 528 } |
525 } | 529 } |
526 | 530 |
531 #elif defined (HAVE_DYLD_API) | |
532 | |
533 class | |
534 octave_dyld_shlib : public octave_base_shlib | |
535 { | |
536 public: | |
537 | |
538 octave_dyld_shlib (void); | |
539 | |
540 ~octave_dyld_shlib (void); | |
541 | |
542 void open (const std::string& f, bool warn_future = false); | |
543 | |
544 void *search (const std::string& name, name_mangler mangler = 0); | |
545 | |
546 void close (octave_shlib::close_hook cl_hook = 0); | |
547 | |
548 bool is_open (void) const {return (isOpen); } | |
549 | |
550 private: | |
551 | |
552 // No copying! | |
553 | |
554 octave_dyld_shlib (const octave_dyld_shlib&); | |
555 | |
556 octave_dyld_shlib& operator = (const octave_dyld_shlib&); | |
557 | |
558 bool isOpen; | |
559 NSObjectFileImage img; | |
560 NSModule handle; | |
561 }; | |
562 | |
563 octave_dyld_shlib::octave_dyld_shlib (void) | |
564 : octave_base_shlib (), isOpen (false), handle (0) | |
565 { | |
566 } | |
567 | |
568 octave_dyld_shlib::~octave_dyld_shlib (void) | |
569 { | |
570 close (); | |
571 } | |
572 | |
573 void | |
574 octave_dyld_shlib::open (const std::string& f, bool warn_future) | |
575 { | |
576 int returnCode; | |
577 | |
578 if (! is_open ()) | |
579 { | |
580 file = f; | |
581 | |
582 returnCode = NSCreateObjectFileImageFromFile (file.c_str (), &img); | |
583 | |
584 if (NSObjectFileImageSuccess == returnCode) | |
585 { | |
586 handle = NSLinkModule (img, file.c_str (), | |
587 (NSLINKMODULE_OPTION_RETURN_ON_ERROR | |
588 | NSLINKMODULE_OPTION_PRIVATE)); | |
589 if (handle) | |
590 { | |
591 stamp_time (warn_future); | |
592 isOpen = true; | |
593 } | |
594 else | |
595 { | |
596 (*current_liboctave_error_handler) | |
597 ("couldn't link module %s", file.c_str ()); | |
598 } | |
599 } | |
600 else | |
601 { | |
602 (*current_liboctave_error_handler) | |
603 ("got NSObjectFileImageReturnCode %d", returnCode); | |
604 | |
605 // XXX FIXME XXX -- should use NSLinkEditError () to get | |
606 // more info on what went wrong. | |
607 } | |
608 } | |
609 else | |
610 { | |
611 (*current_liboctave_error_handler) | |
612 ("bundle %s is already open", file.c_str ()); | |
613 } | |
614 } | |
615 | |
616 void * | |
617 octave_dyld_shlib::search (const std::string& name, | |
618 octave_shlib::name_mangler mangler) | |
619 { | |
620 void *function = 0; | |
621 | |
622 if (is_open ()) | |
623 { | |
624 std::string sym_name = name; | |
625 | |
626 if (mangler) | |
627 sym_name = mangler (name); | |
628 | |
629 NSSymbol symbol = NSLookupSymbolInModule (handle, sym_name.c_str ()); | |
630 | |
631 if (symbol) | |
632 { | |
633 function = NSAddressOfSymbol (symbol); | |
634 add_to_fcn_names (name); | |
635 } | |
636 } | |
637 else | |
638 (*current_liboctave_error_handler) | |
639 ("bundle %s is not open", file.c_str ()); | |
640 | |
641 return function; | |
642 } | |
643 | |
644 void | |
645 octave_dyld_shlib::close (octave_shlib::close_hook cl_hook) | |
646 { | |
647 if (is_open ()) | |
648 { | |
649 do_close_hook (cl_hook); | |
650 | |
651 NSUnLinkModule (handle, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES); | |
652 | |
653 handle = 0; | |
654 | |
655 if (NSDestroyObjectFileImage (img)) | |
656 isOpen = false; | |
657 | |
658 tabula_rasa (); | |
659 } | |
660 } | |
661 | |
527 #endif | 662 #endif |
528 | 663 |
529 octave_shlib * | 664 octave_shlib * |
530 octave_shlib::make_shlib (void) | 665 octave_shlib::make_shlib (void) |
531 { | 666 { |
533 return new octave_dlopen_shlib (); | 668 return new octave_dlopen_shlib (); |
534 #elif defined (HAVE_SHL_LOAD_API) | 669 #elif defined (HAVE_SHL_LOAD_API) |
535 return new octave_shl_load_shlib (); | 670 return new octave_shl_load_shlib (); |
536 #elif defined (HAVE_LOADLIBRARY_API) | 671 #elif defined (HAVE_LOADLIBRARY_API) |
537 return new octave_w32_shlib (); | 672 return new octave_w32_shlib (); |
673 #elif defined (HAVE_DYLD_API) | |
674 return new octave_dyld_shlib (); | |
538 #else | 675 #else |
539 return new octave_base_shlib (); | 676 return new octave_base_shlib (); |
540 #endif | 677 #endif |
541 } | 678 } |
542 | 679 |