GNU Octave 7.1.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-2022 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 "file-ops.h"
31#include "oct-shlib.h"
32
33#include "defaults.h"
34#include "dynamic-ld.h"
35#include "error.h"
36#include "errwarn.h"
37#include "interpreter-private.h"
38#include "interpreter.h"
39#include "ov-mex-fcn.h"
40#include "ov.h"
41#include "ovl.h"
42#include "profiler.h"
43#include "unwind-prot.h"
44
45
47 "mex function", "mex function");
48
50 (void *fptr, bool interleaved, bool fmex, const octave::dynamic_library& shl,
51 const std::string& nm)
52 : octave_function (nm), m_mex_fcn_ptr (fptr), m_exit_fcn_ptr (nullptr),
53 m_sh_lib (shl), m_interleaved (interleaved), m_is_fmex (fmex),
54 m_is_system_fcn_file (false)
55{
57
58 std::string file_name = fcn_file_name ();
59
60 static const std::string canonical_oct_file_dir
62 static const std::string oct_file_dir
63 = canonical_oct_file_dir.empty () ? octave::config::oct_file_dir ()
64 : canonical_oct_file_dir;
65
67 = (! file_name.empty ()
68 && oct_file_dir == file_name.substr (0, oct_file_dir.length ()));
69}
70
72{
74 (*m_exit_fcn_ptr) ();
75
76 octave::dynamic_loader& dyn_loader
77 = octave::__get_dynamic_loader__ ("~octave_mex_function");
78
79 dyn_loader.remove_mex (m_name, m_sh_lib);
80}
81
82std::string
84{
85 return m_sh_lib.file_name ();
86}
87
90{
91 return m_sh_lib.time_loaded ();
92}
93
94// FIXME: shouldn't this declaration be a header file somewhere?
96call_mex (octave_mex_function& curr_mex_fcn, const octave_value_list& args,
97 int nargout);
98
100octave_mex_function::execute (octave::tree_evaluator& tw, int nargout,
101 const octave_value_list& args)
102{
103 octave_value_list retval;
104
105 if (args.has_magic_colon ())
106 error ("invalid use of colon in function argument list");
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}
sys::time time_loaded(void) const
Definition: oct-shlib.h:202
std::string file_name(void) const
Definition: oct-shlib.h:199
std::string m_name
Definition: ov-fcn.h:266
void(* m_exit_fcn_ptr)(void)
Definition: ov-mex-fcn.h:111
octave_value_list execute(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
Definition: ov-mex-fcn.cc:100
void mark_fcn_file_up_to_date(const octave::sys::time &t)
Definition: ov-mex-fcn.h:76
~octave_mex_function(void)
Definition: ov-mex-fcn.cc:71
octave::sys::time time_parsed(void) const
Definition: ov-mex-fcn.cc:89
octave::dynamic_library m_sh_lib
Definition: ov-mex-fcn.h:113
std::string fcn_file_name(void) const
Definition: ov-mex-fcn.cc:83
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:980
std::string oct_file_dir(void)
Definition: defaults.cc:283
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
Definition: lo-specfun.cc:1128
std::string canonicalize_file_name(const std::string &name)
Definition: file-ops.cc:688
dynamic_loader & __get_dynamic_loader__(const std::string &who)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:222
octave_value_list call_mex(octave_mex_function &curr_mex_fcn, const octave_value_list &args, int nargout)
Definition: mex.cc:4778