GNU Octave  6.2.0
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-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include "oct-shlib.h"
31 
32 #include "defaults.h"
33 #include "dynamic-ld.h"
34 #include "error.h"
35 #include "errwarn.h"
36 #include "interpreter-private.h"
37 #include "interpreter.h"
38 #include "ov-mex-fcn.h"
39 #include "ov.h"
40 #include "ovl.h"
41 #include "profiler.h"
42 #include "unwind-prot.h"
43 
44 
46  "mex function", "mex function");
47 
49  (void *fptr, bool fmex, const octave::dynamic_library& shl,
50  const std::string& nm)
51  : octave_function (nm), m_mex_fcn_ptr (fptr), m_exit_fcn_ptr (nullptr),
52  m_is_fmex (fmex), m_sh_lib (shl)
53 {
55 
56  std::string file_name = fcn_file_name ();
57 
60  = (! file_name.empty ()
61  && oct_file_dir == file_name.substr (0, oct_file_dir.length ()));
62 }
63 
65 {
66  if (m_exit_fcn_ptr)
67  (*m_exit_fcn_ptr) ();
68 
69  octave::dynamic_loader& dyn_loader
70  = octave::__get_dynamic_loader__ ("~octave_mex_function");
71 
72  dyn_loader.remove_mex (my_name, m_sh_lib);
73 }
74 
75 std::string
77 {
78  return m_sh_lib.file_name ();
79 }
80 
83 {
84  return m_sh_lib.time_loaded ();
85 }
86 
87 // FIXME: shouldn't this declaration be a header file somewhere?
88 extern octave_value_list
89 call_mex (octave_mex_function& curr_mex_fcn, const octave_value_list& args,
90  int nargout);
91 
94  const octave_value_list& args)
95 {
97 
98  if (args.has_magic_colon ())
99  error ("invalid use of colon in function argument list");
100 
101  octave::profiler& profiler = tw.get_profiler ();
102 
103  octave::profiler::enter<octave_mex_function> block (profiler, *this);
104 
105  retval = call_mex (*this, args, nargout);
106 
107  return retval;
108 }
sys::time time_loaded(void) const
Definition: oct-shlib.h:200
std::string file_name(void) const
Definition: oct-shlib.h:197
profiler & get_profiler(void)
Definition: pt-eval.h:374
std::string my_name
Definition: ov-fcn.h:276
void(* m_exit_fcn_ptr)(void)
Definition: ov-mex-fcn.h:107
octave_value_list execute(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
Definition: ov-mex-fcn.cc:93
void mark_fcn_file_up_to_date(const octave::sys::time &t)
Definition: ov-mex-fcn.h:74
~octave_mex_function(void)
Definition: ov-mex-fcn.cc:64
octave::sys::time time_parsed(void) const
Definition: ov-mex-fcn.cc:82
octave::dynamic_library m_sh_lib
Definition: ov-mex-fcn.h:111
std::string fcn_file_name(void) const
Definition: ov-mex-fcn.cc:76
octave_mex_function(void)
Definition: ov-mex-fcn.h:54
bool has_magic_colon(void) const
Definition: ovl.cc:215
void error(const char *fmt,...)
Definition: error.cc:968
std::string oct_file_dir(void)
Definition: defaults.cc:283
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
Definition: lo-specfun.cc:1128
dynamic_loader & __get_dynamic_loader__(const std::string &who)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:180
octave_value_list call_mex(octave_mex_function &curr_mex_fcn, const octave_value_list &args, int nargout)
Definition: mex.cc:3155
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811