GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-mex-fcn.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "oct-shlib.h"
28 
29 #include "call-stack.h"
30 #include "defaults.h"
31 #include "dynamic-ld.h"
32 #include "error.h"
33 #include "errwarn.h"
34 #include "interpreter-private.h"
35 #include "interpreter.h"
36 #include "ov-mex-fcn.h"
37 #include "ov.h"
38 #include "ovl.h"
39 #include "profiler.h"
40 #include "unwind-prot.h"
41 
42 
44  "mex function", "mex function");
45 
47  (void *fptr, bool fmex, const octave::dynamic_library& shl,
48  const std::string& nm)
49  : octave_function (nm), m_mex_fcn_ptr (fptr), m_exit_fcn_ptr (nullptr),
50  m_is_fmex (fmex), m_sh_lib (shl)
51 {
52  mark_fcn_file_up_to_date (time_parsed ());
53 
54  std::string file_name = fcn_file_name ();
55 
57  m_is_system_fcn_file
58  = (! file_name.empty ()
59  && oct_file_dir == file_name.substr (0, oct_file_dir.length ()));
60 }
61 
63 {
64  if (m_exit_fcn_ptr)
65  (*m_exit_fcn_ptr) ();
66 
67  octave::dynamic_loader& dyn_loader
68  = octave::__get_dynamic_loader__ ("~octave_mex_function");
69 
70  dyn_loader.remove_mex (my_name, m_sh_lib);
71 }
72 
75 {
76  return m_sh_lib.file_name ();
77 }
78 
81 {
82  return m_sh_lib.time_loaded ();
83 }
84 
85 // FIXME: shouldn't this declaration be a header file somewhere?
86 extern octave_value_list
87 call_mex (octave_mex_function& curr_mex_fcn, const octave_value_list& args,
88  int nargout);
89 
92  const octave_value_list& args)
93 {
95 
96  if (args.has_magic_colon ())
97  error ("invalid use of colon in function argument list");
98 
100 
102  = octave::__get_call_stack__ ("octave_mex_function::call");
103 
104  cs.push (this);
105 
107 
108  octave::profiler& profiler = tw.get_profiler ();
109 
110  octave::profiler::enter<octave_mex_function> block (profiler, *this);
111 
112  retval = call_mex (*this, args, nargout);
113 
114  return retval;
115 }
octave::sys::time time_parsed(void) const
Definition: ov-mex-fcn.cc:80
std::string file_name(void) const
Definition: oct-shlib.h:193
std::string my_name
Definition: ov-fcn.h:233
bool has_magic_colon(void) const
Definition: ovl.cc:200
void(* m_exit_fcn_ptr)(void)
Definition: ov-mex-fcn.h:104
void error(const char *fmt,...)
Definition: error.cc:578
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:180
void push(octave_function *fcn)
Definition: call-stack.cc:357
sys::time time_loaded(void) const
Definition: oct-shlib.h:196
octave::call_stack & cs
Definition: ov-class.cc:1752
octave_value_list call_mex(octave_mex_function &curr_mex_fcn, const octave_value_list &args, int nargout)
Definition: mex.cc:3141
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:997
octave_value_list call(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
Definition: ov-mex-fcn.cc:91
octave_value retval
Definition: data.cc:6246
dynamic_loader & __get_dynamic_loader__(const std::string &who)
std::string oct_file_dir(void)
Definition: defaults.cc:289
octave::unwind_protect frame
Definition: graphics.cc:12190
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
Definition: lo-specfun.cc:1129
call_stack & __get_call_stack__(const std::string &who)
octave_mex_function(void)
Definition: ov-mex-fcn.h:51
std::string fcn_file_name(void) const
Definition: ov-mex-fcn.cc:74
void add_method(T *obj, void(T::*method)(void))
octave::dynamic_library m_sh_lib
Definition: ov-mex-fcn.h:108
profiler & get_profiler(void)
Definition: pt-eval.h:373
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
~octave_mex_function(void)
Definition: ov-mex-fcn.cc:62