GNU Octave  4.2.1
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-2017 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 #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 "ovl.h"
35 #include "ov-mex-fcn.h"
36 #include "ov.h"
37 #include "profiler.h"
38 #include "interpreter.h"
39 #include "unwind-prot.h"
40 
41 
43  "mex function", "mex function");
44 
46  (void *fptr, bool fmex, const octave::dynamic_library& shl,
47  const std::string& nm)
48  : octave_function (nm), mex_fcn_ptr (fptr), exit_fcn_ptr (0),
49  have_fmex (fmex), sh_lib (shl)
50 {
51  mark_fcn_file_up_to_date (time_parsed ());
52 
53  std::string file_name = fcn_file_name ();
54 
55  system_fcn_file
56  = (! file_name.empty ()
57  && Voct_file_dir == file_name.substr (0, Voct_file_dir.length ()));
58 }
59 
61 {
62  if (exit_fcn_ptr)
63  (*exit_fcn_ptr) ();
64 
66 }
67 
70 {
71  return sh_lib.file_name ();
72 }
73 
76 {
77  return sh_lib.time_loaded ();
78 }
79 
82  const std::list<octave_value_list>& idx,
83  int nargout)
84 {
86 
87  switch (type[0])
88  {
89  case '(':
90  {
91  int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout;
92 
93  retval = do_multi_index_op (tmp_nargout, idx.front ());
94  }
95  break;
96 
97  case '{':
98  case '.':
99  {
100  std::string nm = type_name ();
101  error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
102  }
103  break;
104 
105  default:
106  panic_impossible ();
107  }
108 
109  // FIXME: perhaps there should be an
110  // octave_value_list::next_subsref member function? See also
111  // octave_user_function::subsref.
112  //
113  // FIXME: Note that if a function call returns multiple
114  // values, and there is further indexing to perform, then we are
115  // ignoring all but the first value. Is this really what we want to
116  // do? If it is not, then what should happen for stat("file").size,
117  // for exmaple?
118 
119  if (idx.size () > 1)
120  retval = retval(0).next_subsref (nargout, type, idx);
121 
122  return retval;
123 }
124 
125 // FIXME: shouldn't this declaration be a header file somewhere?
126 extern octave_value_list
127 call_mex (bool have_fmex, void *f, const octave_value_list& args,
128  int nargout, octave_mex_function *curr_mex_fcn);
129 
132  const octave_value_list& args)
133 {
135 
136  if (args.has_magic_colon ())
137  error ("invalid use of colon in function argument list");
138 
140 
142 
144 
146 
147  retval = call_mex (have_fmex, mex_fcn_ptr, args, nargout, this);
148 
150 
151  return retval;
152 }
std::string my_name
Definition: ov-fcn.h:210
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
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
void error(const char *fmt,...)
Definition: error.cc:570
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:169
std::string fcn_file_name(void) const
Definition: ov-mex-fcn.cc:69
#define END_PROFILER_BLOCK
Definition: profiler.h:215
octave::sys::time time_parsed(void) const
Definition: ov-mex-fcn.cc:75
JNIEnv void * args
Definition: ov-java.cc:67
static std::string fcn_file_name(const octave_value &fcn)
Definition: symtab.cc:1168
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
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:935
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:3069
octave_value_list do_multi_index_op(int nargout, const octave_value_list &args)
Definition: ov-mex-fcn.cc:131
bool has_magic_colon(void) const
Definition: ovl.cc:202
octave_value retval
Definition: data.cc:6294
#define panic_impossible()
Definition: error.h:40
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: call-stack.h:214
idx type
Definition: ov.cc:3129
octave::unwind_protect frame
Definition: graphics.cc:11584
octave::dynamic_library sh_lib
Definition: ov-mex-fcn.h:100
std::string type_name(void) const
Definition: ov-mex-fcn.h:117
std::string Voct_file_dir
Definition: defaults.cc:78
static bool remove_mex(const std::string &fcn_name, octave::dynamic_library &shl)
Definition: dynamic-ld.cc:423
octave::sys::time time_loaded(void) const
Definition: oct-shlib.h:188
octave_mex_function(void)
Definition: ov-mex-fcn.h:46
std::string file_name(void) const
Definition: oct-shlib.h:185
static void pop(void)
Definition: call-stack.h:313
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
Definition: lo-specfun.cc:1724
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:854
~octave_mex_function(void)
Definition: ov-mex-fcn.cc:60
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, size_t skip=1)
Definition: ov.cc:1462
#define BEGIN_PROFILER_BLOCK(classname)
Definition: profiler.h:211