# HG changeset patch # User Jaroslav Hajek # Date 1260442293 -3600 # Node ID 5f3c10ecb150d758ba784177aa3b909763ae24ef # Parent 633f9d837982b79d7047b3a8d2e87bdc068cdaaa implement get_current_shlib and octave_auto_shlib diff -r 633f9d837982 -r 5f3c10ecb150 src/ChangeLog --- a/src/ChangeLog Thu Dec 10 09:14:47 2009 +0100 +++ b/src/ChangeLog Thu Dec 10 11:51:33 2009 +0100 @@ -1,3 +1,11 @@ +2009-12-10 Jaroslav Hajek + + * 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 * symtab.cc (out_of_date_check): Try also autoloads. diff -r 633f9d837982 -r 5f3c10ecb150 src/defun-int.h --- a/src/defun-int.h Thu Dec 10 09:14:47 2009 +0100 +++ b/src/defun-int.h Thu Dec 10 11:51:33 2009 +0100 @@ -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) diff -r 633f9d837982 -r 5f3c10ecb150 src/defun.cc --- a/src/defun.cc Thu Dec 10 09:14:47 2009 +0100 +++ b/src/defun.cc Thu Dec 10 11:51:33 2009 +0100 @@ -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 (curr_fcn); + retval = dld->get_shlib (); + } + else if (curr_fcn->is_mex_function ()) + { + octave_mex_function *mex = dynamic_cast (curr_fcn); + retval = mex->get_shlib (); + } + } + + return retval; +} + /* ;;; Local Variables: *** ;;; mode: C++ *** diff -r 633f9d837982 -r 5f3c10ecb150 src/ov-dld-fcn.h --- a/src/ov-dld-fcn.h Thu Dec 10 09:14:47 2009 +0100 +++ b/src/ov-dld-fcn.h Thu Dec 10 11:51:33 2009 +0100 @@ -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; diff -r 633f9d837982 -r 5f3c10ecb150 src/ov-mex-fcn.h --- a/src/ov-mex-fcn.h Thu Dec 10 09:14:47 2009 +0100 +++ b/src/ov-mex-fcn.h Thu Dec 10 11:51:33 2009 +0100 @@ -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;