Mercurial > octave
changeset 23499:7d89f815d78e
modernize octave_mex_function
* ov-mex-fcn.h, ov-mex-fcn.cc: Use m_ prefix for member variables.
(octave_mex_function::mex_fcn_ptr, octave_mex_function::is_fmex):
New functions.
* mex.cc (call_mex): Eliminate redundant have_fmex, and raw MEX
function pointer arguments.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 16 May 2017 18:32:46 -0400 |
parents | 647705ffb110 |
children | 34963c076879 |
files | libinterp/corefcn/mex.cc libinterp/octave-value/ov-mex-fcn.cc libinterp/octave-value/ov-mex-fcn.h |
diffstat | 3 files changed, 41 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/mex.cc Tue May 16 17:23:09 2017 -0400 +++ b/libinterp/corefcn/mex.cc Tue May 16 18:32:46 2017 -0400 @@ -3084,8 +3084,8 @@ F77_INT& nrhs, mxArray **prhs); octave_value_list -call_mex (bool have_fmex, void *f, const octave_value_list& args, - int nargout_arg, octave_mex_function *curr_mex_fcn) +call_mex (octave_mex_function& mex_fcn, const octave_value_list& args, + int nargout_arg) { octave_quit (); @@ -3109,16 +3109,18 @@ // Save old mex pointer. frame.protect_var (mex_context); - mex context (curr_mex_fcn); + mex context (&mex_fcn); for (int i = 0; i < nargin; i++) argin[i] = context.make_value (args(i)); mex_context = &context; - if (have_fmex) + void *mex_fcn_ptr = mex_fcn.mex_fcn_ptr (); + + if (mex_fcn.is_fmex ()) { - fmex_fptr fcn = reinterpret_cast<fmex_fptr> (f); + fmex_fptr fcn = reinterpret_cast<fmex_fptr> (mex_fcn_ptr); F77_INT tmp_nargout = nargout; F77_INT tmp_nargin = nargin; @@ -3127,7 +3129,7 @@ } else { - cmex_fptr fcn = reinterpret_cast<cmex_fptr> (f); + cmex_fptr fcn = reinterpret_cast<cmex_fptr> (mex_fcn_ptr); fcn (nargout, argout, nargin, argin); }
--- a/libinterp/octave-value/ov-mex-fcn.cc Tue May 16 17:23:09 2017 -0400 +++ b/libinterp/octave-value/ov-mex-fcn.cc Tue May 16 18:32:46 2017 -0400 @@ -45,36 +45,36 @@ octave_mex_function::octave_mex_function (void *fptr, bool fmex, const octave::dynamic_library& shl, const std::string& nm) - : octave_function (nm), mex_fcn_ptr (fptr), exit_fcn_ptr (0), - have_fmex (fmex), sh_lib (shl) + : octave_function (nm), m_mex_fcn_ptr (fptr), m_exit_fcn_ptr (0), + m_is_fmex (fmex), m_sh_lib (shl) { mark_fcn_file_up_to_date (time_parsed ()); std::string file_name = fcn_file_name (); - system_fcn_file + m_is_system_fcn_file = (! file_name.empty () && Voct_file_dir == file_name.substr (0, Voct_file_dir.length ())); } octave_mex_function::~octave_mex_function (void) { - if (exit_fcn_ptr) - (*exit_fcn_ptr) (); + if (m_exit_fcn_ptr) + (*m_exit_fcn_ptr) (); - octave::dynamic_loader::remove_mex (my_name, sh_lib); + octave::dynamic_loader::remove_mex (my_name, m_sh_lib); } std::string octave_mex_function::fcn_file_name (void) const { - return sh_lib.file_name (); + return m_sh_lib.file_name (); } octave::sys::time octave_mex_function::time_parsed (void) const { - return sh_lib.time_loaded (); + return m_sh_lib.time_loaded (); } octave_value_list @@ -124,8 +124,8 @@ // FIXME: shouldn't this declaration be a header file somewhere? extern octave_value_list -call_mex (bool have_fmex, void *f, const octave_value_list& args, - int nargout, octave_mex_function *curr_mex_fcn); +call_mex (octave_mex_function& curr_mex_fcn, const octave_value_list& args, + int nargout); octave_value_list octave_mex_function::do_multi_index_op (int nargout, @@ -144,7 +144,7 @@ profile_data_accumulator::enter<octave_mex_function> block (profiler, *this); - retval = call_mex (have_fmex, mex_fcn_ptr, args, nargout, this); + retval = call_mex (*this, args, nargout); return retval; }
--- a/libinterp/octave-value/ov-mex-fcn.h Tue May 16 17:23:09 2017 -0400 +++ b/libinterp/octave-value/ov-mex-fcn.h Tue May 16 18:32:46 2017 -0400 @@ -44,10 +44,11 @@ public: octave_mex_function (void) - : mex_fcn_ptr (), exit_fcn_ptr (), have_fmex (), sh_lib (), - t_checked (), system_fcn_file () { } + : m_mex_fcn_ptr (), m_exit_fcn_ptr (), m_is_fmex (), m_sh_lib (), + m_time_checked (), m_is_system_fcn_file () { } - octave_mex_function (void *fptr, bool fmex, const octave::dynamic_library& shl, + octave_mex_function (void *fptr, bool fmex, + const octave::dynamic_library& shl, const std::string& nm = ""); // No copying! @@ -73,15 +74,18 @@ const octave_function * function_value (bool = false) const { return this; } - void mark_fcn_file_up_to_date (const octave::sys::time& t) { t_checked = t; } + void mark_fcn_file_up_to_date (const octave::sys::time& t) + { + m_time_checked = t; + } std::string fcn_file_name (void) const; octave::sys::time time_parsed (void) const; - octave::sys::time time_checked (void) const { return t_checked; } + octave::sys::time time_checked (void) const { return m_time_checked; } - bool is_system_fcn_file (void) const { return system_fcn_file; } + bool is_system_fcn_file (void) const { return m_is_system_fcn_file; } bool is_builtin_function (void) const { return false; } @@ -90,29 +94,32 @@ octave_value_list do_multi_index_op (int nargout, const octave_value_list& args); - void atexit (void (*fcn) (void)) { exit_fcn_ptr = fcn; } + void atexit (void (*fcn) (void)) { m_exit_fcn_ptr = fcn; } + + octave::dynamic_library get_shlib (void) const { return m_sh_lib; } - octave::dynamic_library get_shlib (void) const - { return sh_lib; } + void *mex_fcn_ptr (void) const { return m_mex_fcn_ptr; } + + bool is_fmex (void) const { return m_is_fmex; } private: - void *mex_fcn_ptr; + void *m_mex_fcn_ptr; - void (*exit_fcn_ptr) (void); + void (*m_exit_fcn_ptr) (void); - bool have_fmex; + bool m_is_fmex; - octave::dynamic_library sh_lib; + octave::dynamic_library m_sh_lib; // The time the file was last checked to see if it needs to be // parsed again. - mutable octave::sys::time t_checked; + mutable octave::sys::time m_time_checked; // True if this function came from a file that is considered to be a // system function. This affects whether we check the time stamp // on the file to see if it has changed. - bool system_fcn_file; + bool m_is_system_fcn_file; DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA };