changeset 4162:bcdf1c264e08

[project @ 2002-11-10 00:34:37 by jwe]
author jwe
date Sun, 10 Nov 2002 00:34:37 +0000
parents 8eb844b6349b
children 811ec5317aeb
files ChangeLog aclocal.m4 configure.in liboctave/ChangeLog liboctave/oct-shlib.cc
diffstat 5 files changed, 156 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Nov 09 04:02:23 2002 +0000
+++ b/ChangeLog	Sun Nov 10 00:34:37 2002 +0000
@@ -1,3 +1,10 @@
+2002-11-09  Per Persson <persquare@mac.com>
+
+	* configure.in: Use $(TOPDIR)/src/octave, not $(bindir)/octave for
+	-bundle-loader argument.	
+
+	* aclocal.m4 (OCTAVE_CXX_PREPENDS_UNDERSCORE): Force result for OS X.
+
 2002-11-07  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* configure.in: Set FPICFLAG, Also set CXXPICFLAG, CPICFLAG,
--- a/aclocal.m4	Sat Nov 09 04:02:23 2002 +0000
+++ b/aclocal.m4	Sun Nov 10 00:34:37 2002 +0000
@@ -619,6 +619,11 @@
       *-*-cygwin* | *-*-mingw*)
         octave_cv_cxx_prepends_underscore=no
       ;;
+### XXX FIXME XXX -- Ignore test result on OS X.  Yes it prepends
+### underscore, but also messes with the name so test fails (incorrectly).
+      *-*-darwin6*)
+        octave_cv_cxx_prepends_underscore=yes
+      ;;
     esac
   ])
   AC_MSG_RESULT($octave_cv_cxx_prepends_underscore)
--- a/configure.in	Sat Nov 09 04:02:23 2002 +0000
+++ b/configure.in	Sun Nov 10 00:34:37 2002 +0000
@@ -22,7 +22,7 @@
 ### 02111-1307, USA. 
 
 AC_INIT
-AC_REVISION($Revision: 1.386 $)
+AC_REVISION($Revision: 1.387 $)
 AC_PREREQ(2.52)
 AC_CONFIG_SRCDIR([src/octave.cc])
 AC_CONFIG_HEADER(config.h)
@@ -651,7 +651,7 @@
     RLD_FLAG='-Xlinker -rpath -Xlinker $(octlibdir)'
   ;;
   *-*-darwin*)
-    SH_LDFLAGS='-bundle -bundle_loader $(bindir)/octave'
+    SH_LDFLAGS='-bundle -bundle_loader $(TOPDIR)/src/octave'
     CXXPICFLAG=
     CPICFLAG=
     FPICFLAG=
--- a/liboctave/ChangeLog	Sat Nov 09 04:02:23 2002 +0000
+++ b/liboctave/ChangeLog	Sun Nov 10 00:34:37 2002 +0000
@@ -1,3 +1,8 @@
+2002-11-09  Per Persson <persquare@mac.com>
+
+	* oct-shlib.cc (octave_dyld_shlib): New class.
+	(make_shlib): Instantiate octave_dyld_shlib.
+
 2002-11-06  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* CMatrix.cc, dMatrix.cc: Sprinkle with OCTAVE_QUIT.
--- a/liboctave/oct-shlib.cc	Sat Nov 09 04:02:23 2002 +0000
+++ b/liboctave/oct-shlib.cc	Sun Nov 10 00:34:37 2002 +0000
@@ -29,6 +29,10 @@
 #include <cstring>
 #endif
 
+#if defined (HAVE_DYLD_API)
+#include <Mach-O/dyld.h>
+#endif
+
 extern "C"
 {
 #if defined (HAVE_DLOPEN_API)
@@ -524,6 +528,137 @@
     }
 }
 
+#elif defined (HAVE_DYLD_API)
+
+class
+octave_dyld_shlib : public octave_base_shlib
+{
+public:
+
+  octave_dyld_shlib (void);
+
+  ~octave_dyld_shlib (void);
+
+  void open (const std::string& f, bool warn_future = false);
+
+  void *search (const std::string& name, name_mangler mangler = 0);
+
+  void close (octave_shlib::close_hook cl_hook = 0);
+
+  bool is_open (void) const {return (isOpen); }
+
+private:
+
+  // No copying!
+
+  octave_dyld_shlib (const octave_dyld_shlib&);
+
+  octave_dyld_shlib& operator = (const octave_dyld_shlib&);
+
+  bool isOpen;
+  NSObjectFileImage img;
+  NSModule handle;
+};
+
+octave_dyld_shlib::octave_dyld_shlib (void)
+  : octave_base_shlib (), isOpen (false), handle (0)
+{
+}
+
+octave_dyld_shlib::~octave_dyld_shlib (void)
+{
+  close ();
+}
+
+void
+octave_dyld_shlib::open (const std::string& f, bool warn_future)
+{
+  int returnCode;
+
+  if (! is_open ())
+    {
+      file = f;
+
+      returnCode = NSCreateObjectFileImageFromFile (file.c_str (), &img);
+
+      if (NSObjectFileImageSuccess == returnCode)
+	{
+	  handle = NSLinkModule (img, file.c_str (),
+				 (NSLINKMODULE_OPTION_RETURN_ON_ERROR
+				  | NSLINKMODULE_OPTION_PRIVATE));
+	  if (handle)
+	    {
+	      stamp_time (warn_future);
+	      isOpen = true;
+	    }
+	  else
+	    {
+	      (*current_liboctave_error_handler)
+		("couldn't link module %s", file.c_str ());	
+	    }
+	}
+      else
+	{
+	  (*current_liboctave_error_handler)
+	    ("got NSObjectFileImageReturnCode %d", returnCode);
+
+	  // XXX FIXME XXX -- should use NSLinkEditError () to get
+	  // more info on what went wrong.
+	}
+    }
+  else
+    {
+      (*current_liboctave_error_handler)
+	("bundle %s is already open", file.c_str ());
+    }
+}
+
+void *
+octave_dyld_shlib::search (const std::string& name,
+			   octave_shlib::name_mangler mangler)
+{
+  void *function = 0;
+
+  if (is_open ())
+    {
+      std::string sym_name = name;
+
+      if (mangler)
+	sym_name = mangler (name);
+
+      NSSymbol symbol = NSLookupSymbolInModule (handle, sym_name.c_str ());
+
+      if (symbol)
+	{
+	  function = NSAddressOfSymbol (symbol);
+	  add_to_fcn_names (name);
+	}
+    }
+  else
+    (*current_liboctave_error_handler)
+      ("bundle %s is not open", file.c_str ());
+
+  return function;
+}
+
+void
+octave_dyld_shlib::close (octave_shlib::close_hook cl_hook)
+{
+  if (is_open ())
+    {
+      do_close_hook (cl_hook);
+
+      NSUnLinkModule (handle, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES);
+
+      handle = 0;
+
+      if (NSDestroyObjectFileImage (img))
+	isOpen = false;
+
+      tabula_rasa ();
+    }
+}
+
 #endif
 
 octave_shlib *
@@ -535,6 +670,8 @@
   return new octave_shl_load_shlib ();
 #elif defined (HAVE_LOADLIBRARY_API)
   return new octave_w32_shlib ();
+#elif defined (HAVE_DYLD_API)
+  return new octave_dyld_shlib ();
 #else
   return new octave_base_shlib ();
 #endif