5864
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 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 2, or (at your option) any |
|
10 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, write to the Free |
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "oct-shlib.h" |
|
29 |
|
30 #include <defaults.h> |
|
31 #include "dynamic-ld.h" |
|
32 #include "error.h" |
|
33 #include "oct-obj.h" |
|
34 #include "ov-mex-fcn.h" |
|
35 #include "ov.h" |
|
36 #include "toplev.h" |
|
37 #include "unwind-prot.h" |
|
38 |
|
39 DEFINE_OCTAVE_ALLOCATOR (octave_mex_function); |
|
40 |
|
41 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_mex_function, |
|
42 "mex function", "mex function"); |
|
43 |
|
44 octave_mex_function::octave_mex_function |
|
45 (void *fptr, bool fmex, const octave_shlib& shl, |
|
46 const std::string& nm) |
6068
|
47 : octave_function (nm), mex_fcn_ptr (fptr), exit_fcn_ptr (0), |
|
48 have_fmex (fmex), sh_lib (shl) |
5864
|
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 |
|
59 octave_mex_function::~octave_mex_function (void) |
|
60 { |
6068
|
61 if (exit_fcn_ptr) |
|
62 (*exit_fcn_ptr) (); |
|
63 |
5864
|
64 octave_dynamic_loader::remove (my_name, sh_lib); |
|
65 } |
|
66 |
|
67 std::string |
|
68 octave_mex_function::fcn_file_name (void) const |
|
69 { |
|
70 return sh_lib.file_name (); |
|
71 } |
|
72 |
|
73 octave_time |
|
74 octave_mex_function::time_parsed (void) const |
|
75 { |
|
76 return sh_lib.time_loaded (); |
|
77 } |
|
78 |
|
79 octave_value_list |
|
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 extern octave_value_list |
6068
|
125 call_mex (bool have_fmex, void *f, const octave_value_list& args, |
|
126 int nargout, octave_mex_function *curr_mex_fcn); |
5864
|
127 |
|
128 octave_value_list |
|
129 octave_mex_function::do_multi_index_op (int nargout, |
|
130 const octave_value_list& args) |
|
131 { |
|
132 octave_value_list retval; |
|
133 |
|
134 if (error_state) |
|
135 return retval; |
|
136 |
|
137 if (args.has_magic_colon ()) |
|
138 ::error ("invalid use of colon in function argument list"); |
|
139 else |
|
140 { |
|
141 unwind_protect::begin_frame ("mex_func_eval"); |
|
142 |
|
143 octave_call_stack::push (this); |
|
144 |
|
145 unwind_protect::add (octave_call_stack::unwind_pop, 0); |
|
146 |
6068
|
147 retval = call_mex (have_fmex, mex_fcn_ptr, args, nargout, this); |
5864
|
148 |
|
149 unwind_protect::run_frame ("mex_func_eval"); |
|
150 } |
|
151 |
|
152 return retval; |
|
153 } |
|
154 |
|
155 /* |
|
156 ;;; Local Variables: *** |
|
157 ;;; mode: C++ *** |
|
158 ;;; End: *** |
|
159 */ |