5864
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 2006, 2007 John W. Eaton |
5864
|
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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
5864
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
5864
|
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 "oct-obj.h" |
|
33 #include "ov-mex-fcn.h" |
|
34 #include "ov.h" |
|
35 #include "toplev.h" |
|
36 #include "unwind-prot.h" |
|
37 |
|
38 DEFINE_OCTAVE_ALLOCATOR (octave_mex_function); |
|
39 |
|
40 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_mex_function, |
|
41 "mex function", "mex function"); |
|
42 |
|
43 octave_mex_function::octave_mex_function |
|
44 (void *fptr, bool fmex, const octave_shlib& shl, |
|
45 const std::string& nm) |
6068
|
46 : octave_function (nm), mex_fcn_ptr (fptr), exit_fcn_ptr (0), |
|
47 have_fmex (fmex), sh_lib (shl) |
5864
|
48 { |
|
49 mark_fcn_file_up_to_date (time_parsed ()); |
|
50 |
|
51 std::string file_name = fcn_file_name (); |
|
52 |
|
53 system_fcn_file |
|
54 = (! file_name.empty () |
|
55 && Voct_file_dir == file_name.substr (0, Voct_file_dir.length ())); |
|
56 } |
|
57 |
|
58 octave_mex_function::~octave_mex_function (void) |
|
59 { |
6068
|
60 if (exit_fcn_ptr) |
|
61 (*exit_fcn_ptr) (); |
|
62 |
5864
|
63 octave_dynamic_loader::remove (my_name, sh_lib); |
|
64 } |
|
65 |
|
66 std::string |
|
67 octave_mex_function::fcn_file_name (void) const |
|
68 { |
|
69 return sh_lib.file_name (); |
|
70 } |
|
71 |
|
72 octave_time |
|
73 octave_mex_function::time_parsed (void) const |
|
74 { |
|
75 return sh_lib.time_loaded (); |
|
76 } |
|
77 |
|
78 octave_value_list |
|
79 octave_mex_function::subsref (const std::string& type, |
|
80 const std::list<octave_value_list>& idx, |
|
81 int nargout) |
|
82 { |
|
83 octave_value_list retval; |
|
84 |
|
85 switch (type[0]) |
|
86 { |
|
87 case '(': |
|
88 { |
|
89 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
|
90 |
|
91 retval = do_multi_index_op (tmp_nargout, idx.front ()); |
|
92 } |
|
93 break; |
|
94 |
|
95 case '{': |
|
96 case '.': |
|
97 { |
|
98 std::string nm = type_name (); |
|
99 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
100 } |
|
101 break; |
|
102 |
|
103 default: |
|
104 panic_impossible (); |
|
105 } |
|
106 |
|
107 // FIXME -- perhaps there should be an |
|
108 // octave_value_list::next_subsref member function? See also |
|
109 // octave_user_function::subsref. |
|
110 // |
|
111 // FIXME -- Note that if a function call returns multiple |
|
112 // values, and there is further indexing to perform, then we are |
|
113 // ignoring all but the first value. Is this really what we want to |
|
114 // do? If it is not, then what should happen for stat("file").size, |
|
115 // for exmaple? |
|
116 |
|
117 if (idx.size () > 1) |
|
118 retval = retval(0).next_subsref (nargout, type, idx); |
|
119 |
|
120 return retval; |
|
121 } |
|
122 |
|
123 extern octave_value_list |
6068
|
124 call_mex (bool have_fmex, void *f, const octave_value_list& args, |
|
125 int nargout, octave_mex_function *curr_mex_fcn); |
5864
|
126 |
|
127 octave_value_list |
|
128 octave_mex_function::do_multi_index_op (int nargout, |
|
129 const octave_value_list& args) |
|
130 { |
|
131 octave_value_list retval; |
|
132 |
|
133 if (error_state) |
|
134 return retval; |
|
135 |
|
136 if (args.has_magic_colon ()) |
|
137 ::error ("invalid use of colon in function argument list"); |
|
138 else |
|
139 { |
|
140 unwind_protect::begin_frame ("mex_func_eval"); |
|
141 |
|
142 octave_call_stack::push (this); |
|
143 |
|
144 unwind_protect::add (octave_call_stack::unwind_pop, 0); |
|
145 |
6068
|
146 retval = call_mex (have_fmex, mex_fcn_ptr, args, nargout, this); |
5864
|
147 |
|
148 unwind_protect::run_frame ("mex_func_eval"); |
|
149 } |
|
150 |
|
151 return retval; |
|
152 } |
|
153 |
|
154 /* |
|
155 ;;; Local Variables: *** |
|
156 ;;; mode: C++ *** |
|
157 ;;; End: *** |
|
158 */ |