Mercurial > octave-nkf
comparison src/ov-mex-fcn.cc @ 5864:e884ab4f29ee
[project @ 2006-06-22 00:57:27 by jwe]
author | jwe |
---|---|
date | Thu, 22 Jun 2006 00:57:28 +0000 |
parents | |
children | c9f0839c583f |
comparison
equal
deleted
inserted
replaced
5863:4c16f3104aa5 | 5864:e884ab4f29ee |
---|---|
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) | |
47 : octave_function (nm), mex_fcn_ptr (fptr), have_fmex (fmex), sh_lib (shl) | |
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 { | |
60 octave_dynamic_loader::remove (my_name, sh_lib); | |
61 } | |
62 | |
63 std::string | |
64 octave_mex_function::fcn_file_name (void) const | |
65 { | |
66 return sh_lib.file_name (); | |
67 } | |
68 | |
69 octave_time | |
70 octave_mex_function::time_parsed (void) const | |
71 { | |
72 return sh_lib.time_loaded (); | |
73 } | |
74 | |
75 octave_value_list | |
76 octave_mex_function::subsref (const std::string& type, | |
77 const std::list<octave_value_list>& idx, | |
78 int nargout) | |
79 { | |
80 octave_value_list retval; | |
81 | |
82 switch (type[0]) | |
83 { | |
84 case '(': | |
85 { | |
86 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; | |
87 | |
88 retval = do_multi_index_op (tmp_nargout, idx.front ()); | |
89 } | |
90 break; | |
91 | |
92 case '{': | |
93 case '.': | |
94 { | |
95 std::string nm = type_name (); | |
96 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); | |
97 } | |
98 break; | |
99 | |
100 default: | |
101 panic_impossible (); | |
102 } | |
103 | |
104 // FIXME -- perhaps there should be an | |
105 // octave_value_list::next_subsref member function? See also | |
106 // octave_user_function::subsref. | |
107 // | |
108 // FIXME -- Note that if a function call returns multiple | |
109 // values, and there is further indexing to perform, then we are | |
110 // ignoring all but the first value. Is this really what we want to | |
111 // do? If it is not, then what should happen for stat("file").size, | |
112 // for exmaple? | |
113 | |
114 if (idx.size () > 1) | |
115 retval = retval(0).next_subsref (nargout, type, idx); | |
116 | |
117 return retval; | |
118 } | |
119 | |
120 extern octave_value_list | |
121 C_mex (void *f, const octave_value_list& args, int nargout); | |
122 | |
123 extern octave_value_list | |
124 Fortran_mex (void *f, const octave_value_list& args, int nargout); | |
125 | |
126 octave_value_list | |
127 octave_mex_function::do_multi_index_op (int nargout, | |
128 const octave_value_list& args) | |
129 { | |
130 octave_value_list retval; | |
131 | |
132 if (error_state) | |
133 return retval; | |
134 | |
135 if (args.has_magic_colon ()) | |
136 ::error ("invalid use of colon in function argument list"); | |
137 else | |
138 { | |
139 unwind_protect::begin_frame ("mex_func_eval"); | |
140 | |
141 octave_call_stack::push (this); | |
142 | |
143 unwind_protect::add (octave_call_stack::unwind_pop, 0); | |
144 | |
145 retval = have_fmex | |
146 ? Fortran_mex (mex_fcn_ptr, args, nargout) | |
147 : C_mex (mex_fcn_ptr, args, nargout); | |
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 */ |