GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-mex-fcn.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "oct-shlib.h"
28 
29 #include <defaults.h>
30 #include "dynamic-ld.h"
31 #include "error.h"
32 #include "gripes.h"
33 #include "oct-obj.h"
34 #include "ov-mex-fcn.h"
35 #include "ov.h"
36 #include "profiler.h"
37 #include "toplev.h"
38 #include "unwind-prot.h"
39 
40 
42  "mex function", "mex function");
43 
45  (void *fptr, bool fmex, const octave_shlib& shl,
46  const std::string& nm)
47  : octave_function (nm), mex_fcn_ptr (fptr), exit_fcn_ptr (0),
48  have_fmex (fmex), sh_lib (shl)
49 {
50  mark_fcn_file_up_to_date (time_parsed ());
51 
52  std::string file_name = fcn_file_name ();
53 
54  system_fcn_file
55  = (! file_name.empty ()
56  && Voct_file_dir == file_name.substr (0, Voct_file_dir.length ()));
57 }
58 
60 {
61  if (exit_fcn_ptr)
62  (*exit_fcn_ptr) ();
63 
65 }
66 
67 std::string
69 {
70  return sh_lib.file_name ();
71 }
72 
75 {
76  return sh_lib.time_loaded ();
77 }
78 
80 octave_mex_function::subsref (const std::string& type,
81  const std::list<octave_value_list>& idx,
82  int nargout)
83 {
84  octave_value_list retval;
85 
86  switch (type[0])
87  {
88  case '(':
89  {
90  int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout;
91 
92  retval = do_multi_index_op (tmp_nargout, idx.front ());
93  }
94  break;
95 
96  case '{':
97  case '.':
98  {
99  std::string nm = type_name ();
100  error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
101  }
102  break;
103 
104  default:
105  panic_impossible ();
106  }
107 
108  // FIXME: perhaps there should be an
109  // octave_value_list::next_subsref member function? See also
110  // octave_user_function::subsref.
111  //
112  // FIXME: Note that if a function call returns multiple
113  // values, and there is further indexing to perform, then we are
114  // ignoring all but the first value. Is this really what we want to
115  // do? If it is not, then what should happen for stat("file").size,
116  // for exmaple?
117 
118  if (idx.size () > 1)
119  retval = retval(0).next_subsref (nargout, type, idx);
120 
121  return retval;
122 }
123 
124 // FIXME: shouldn't this declaration be a header file somewhere?
125 extern octave_value_list
126 call_mex (bool have_fmex, void *f, const octave_value_list& args,
127  int nargout, octave_mex_function *curr_mex_fcn);
128 
131  const octave_value_list& args)
132 {
133  octave_value_list retval;
134 
135  if (error_state)
136  return retval;
137 
138  if (args.has_magic_colon ())
139  ::error ("invalid use of colon in function argument list");
140  else
141  {
142  unwind_protect frame;
143 
145 
147 
148  try
149  {
151 
152  retval = call_mex (have_fmex, mex_fcn_ptr, args, nargout, this);
153 
155  }
156  catch (octave_execution_exception)
157  {
159  }
160  }
161 
162  return retval;
163 }
octave_time time_loaded(void) const
Definition: oct-shlib.h:184
std::string my_name
Definition: ov-fcn.h:208
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-mex-fcn.h:55
void(* exit_fcn_ptr)(void)
Definition: ov-mex-fcn.h:96
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
Definition: lo-specfun.cc:1732
void error(const char *fmt,...)
Definition: error.cc:476
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:164
void gripe_library_execution_error(void)
Definition: gripes.cc:208
std::string fcn_file_name(void) const
Definition: ov-mex-fcn.cc:68
#define END_PROFILER_BLOCK
Definition: profiler.h:213
static std::string fcn_file_name(const octave_value &fcn)
Definition: symtab.cc:1163
F77_RET_T const double const double * f
void add_fcn(void(*fcn)(void))
octave_value_list call_mex(bool have_fmex, void *f, const octave_value_list &args, int nargout, octave_mex_function *curr_mex_fcn)
Definition: mex.cc:3002
octave_value_list do_multi_index_op(int nargout, const octave_value_list &args)
Definition: ov-mex-fcn.cc:130
int error_state
Definition: error.cc:101
bool has_magic_colon(void) const
Definition: oct-obj.cc:208
octave_time time_parsed(void) const
Definition: ov-mex-fcn.cc:74
#define panic_impossible()
Definition: error.h:33
static void push(octave_function *f, symbol_table::scope_id scope=symbol_table::current_scope(), symbol_table::context_id context=symbol_table::current_context())
Definition: toplev.h:233
octave_shlib sh_lib
Definition: ov-mex-fcn.h:100
std::string Voct_file_dir
Definition: defaults.cc:81
octave_mex_function(void)
Definition: ov-mex-fcn.h:46
static void pop(void)
Definition: toplev.h:332
OCTAVE_EMPTY_CPP_ARG std::string type_name(void) const
Definition: ov-mex-fcn.h:118
~octave_mex_function(void)
Definition: ov-mex-fcn.cc:59
#define BEGIN_PROFILER_BLOCK(classname)
Definition: profiler.h:209
std::string file_name(void) const
Definition: oct-shlib.h:181
static bool remove_mex(const std::string &fcn_name, octave_shlib &shl)
Definition: dynamic-ld.cc:443