changeset 9960:5f3c10ecb150

implement get_current_shlib and octave_auto_shlib
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 10 Dec 2009 11:51:33 +0100
parents 633f9d837982
children dbbec33d14f8
files src/ChangeLog src/defun-int.h src/defun.cc src/ov-dld-fcn.h src/ov-mex-fcn.h
diffstat 5 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2009-12-10  Jaroslav Hajek  <highegg@gmail.com>
+
+	* ov-dld-fcn.h (octave_dld_function::get_shlib): New method.
+	* ov-mex-fcn.h (octave_mex_function::get_shlib): New method.
+	* defun.cc (get_current_shlib): New function.
+	* defun-int.h: Declare it.
+	(octave_auto_shlib): New class.
+
 2009-12-10  Jaroslav Hajek  <highegg@gmail.com>
 
 	* symtab.cc (out_of_date_check): Try also autoloads.
--- a/src/defun-int.h
+++ b/src/defun-int.h
@@ -55,6 +55,22 @@
 extern OCTINTERP_API void
 alias_builtin (const std::string& alias, const std::string& name);
 
+// Gets the shlib of the currently executing DLD function, if any.
+extern OCTINTERP_API octave_shlib
+get_current_shlib (void);
+
+// This is a convenience class that calls the above function automatically at
+// construction time. When deriving new classes, you can either use it as a field
+// or as a parent (with multiple inheritance).
+
+class octave_auto_shlib : public octave_shlib
+{
+  octave_auto_shlib (void)
+    : octave_shlib (get_current_shlib ()) { }
+  octave_auto_shlib (const octave_shlib& shl)
+    : octave_shlib (shl) { }
+};
+
 #define DECLARE_FUNX(name, args_name, nargout_name) \
   OCTAVE_EXPORT octave_value_list \
   name (const octave_value_list& args_name, int nargout_name)
--- a/src/defun.cc
+++ b/src/defun.cc
@@ -123,6 +123,29 @@
   symbol_table::alias_built_in_function (alias, name);
 }
 
+octave_shlib
+get_current_shlib (void)
+{
+  octave_shlib retval;
+  
+  octave_function *curr_fcn = octave_call_stack::current ();
+  if (curr_fcn)
+    {
+      if (curr_fcn->is_dld_function ())
+        {
+          octave_dld_function *dld = dynamic_cast<octave_dld_function *> (curr_fcn);
+          retval = dld->get_shlib ();
+        }
+      else if (curr_fcn->is_mex_function ())
+        {
+          octave_mex_function *mex = dynamic_cast<octave_mex_function *> (curr_fcn);
+          retval = mex->get_shlib ();
+        }
+    }
+
+  return retval;
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/src/ov-dld-fcn.h
+++ b/src/ov-dld-fcn.h
@@ -72,6 +72,9 @@
       const std::string& nm = std::string (),
       const std::string& ds = std::string ());
 
+  octave_shlib get_shlib (void) const
+    { return sh_lib; }
+
 private:
 
   octave_shlib sh_lib;
--- a/src/ov-mex-fcn.h
+++ b/src/ov-mex-fcn.h
@@ -84,6 +84,9 @@
 
   void atexit (void (*fcn) (void)) { exit_fcn_ptr = fcn; }
 
+  octave_shlib get_shlib (void) const
+    { return sh_lib; }
+
 private:
 
   void *mex_fcn_ptr;