GNU Octave  3.8.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-2013 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 
41 
43  "mex function", "mex function");
44 
46  (void *fptr, bool fmex, const octave_shlib& 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 
68 std::string
70 {
71  return sh_lib.file_name ();
72 }
73 
76 {
77  return sh_lib.time_loaded ();
78 }
79 
81 octave_mex_function::subsref (const std::string& type,
82  const std::list<octave_value_list>& idx,
83  int nargout)
84 {
85  octave_value_list retval;
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 {
134  octave_value_list retval;
135 
136  if (error_state)
137  return retval;
138 
139  if (args.has_magic_colon ())
140  ::error ("invalid use of colon in function argument list");
141  else
142  {
143  unwind_protect frame;
144 
146 
148 
149  try
150  {
152  retval = call_mex (have_fmex, mex_fcn_ptr, args, nargout, this);
154  }
155  catch (octave_execution_exception)
156  {
158  }
159  }
160 
161  return retval;
162 }