Mercurial > octave
annotate libinterp/octave-value/ov-fcn-handle.cc @ 21739:c4ab2e54f100
use namespace for oct_mach_info class
* mach-info.h, mach-info.cc: Put oct_mach_info in octave namespace and
rename to mach_info. Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 19 May 2016 01:59:35 -0400 |
parents | 0504351a45e6 |
children | f4d7d0eb5b0c |
rev | line source |
---|---|
4343 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19598
diff
changeset
|
3 Copyright (C) 2003-2015 John W. Eaton |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague, a.s. |
10960 | 5 Copyright (C) 2010 Jaroslav Hajek |
4343 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
4343 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
4343 | 22 |
23 */ | |
24 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
25 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21211
diff
changeset
|
26 # include "config.h" |
4343 | 27 #endif |
28 | |
29 #include <iostream> | |
5765 | 30 #include <sstream> |
5164 | 31 #include <vector> |
4343 | 32 |
7336 | 33 #include "file-ops.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
34 #include "oct-locbuf.h" |
7336 | 35 |
4343 | 36 #include "defun.h" |
4654 | 37 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21079
diff
changeset
|
38 #include "errwarn.h" |
5663 | 39 #include "input.h" |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
40 #include "oct-hdf5.h" |
4343 | 41 #include "oct-map.h" |
42 #include "ov-base.h" | |
43 #include "ov-fcn-handle.h" | |
4980 | 44 #include "ov-usr-fcn.h" |
4343 | 45 #include "pr-output.h" |
4980 | 46 #include "pt-pr-code.h" |
47 #include "pt-misc.h" | |
48 #include "pt-stmt.h" | |
49 #include "pt-cmd.h" | |
50 #include "pt-exp.h" | |
51 #include "pt-assign.h" | |
10960 | 52 #include "pt-arg-list.h" |
4343 | 53 #include "variables.h" |
4988 | 54 #include "parse.h" |
6625 | 55 #include "unwind-prot.h" |
56 #include "defaults.h" | |
57 #include "file-stat.h" | |
58 #include "load-path.h" | |
59 #include "oct-env.h" | |
4988 | 60 |
61 #include "byte-swap.h" | |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
62 #include "ls-ascii-helper.h" |
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
63 #include "ls-hdf5.h" |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20435
diff
changeset
|
64 #include "ls-oct-text.h" |
6625 | 65 #include "ls-oct-binary.h" |
4988 | 66 #include "ls-utils.h" |
4343 | 67 |
68 | |
4612 | 69 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_handle, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
70 "function handle", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
71 "function_handle"); |
4343 | 72 |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
73 const std::string octave_fcn_handle::anonymous ("@<anonymous>"); |
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
74 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
75 octave_fcn_handle::octave_fcn_handle (const octave_value& f, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
76 const std::string& n) |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
77 : fcn (f), nm (n), has_overloads (false) |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
78 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
79 octave_user_function *uf = fcn.user_function_value (true); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
80 |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
81 if (uf && nm != anonymous) |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
82 symbol_table::cache_name (uf->scope (), nm); |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14429
diff
changeset
|
83 |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14429
diff
changeset
|
84 if (uf && uf->is_nested_function ()) |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20163
diff
changeset
|
85 error ("handles to nested functions are not yet supported"); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
86 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
87 |
4924 | 88 octave_value_list |
89 octave_fcn_handle::subsref (const std::string& type, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
90 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
91 int nargout) |
4924 | 92 { |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
93 return octave_fcn_handle::subsref (type, idx, nargout, 0); |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
94 } |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
95 |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
96 octave_value_list |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
97 octave_fcn_handle::subsref (const std::string& type, |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
98 const std::list<octave_value_list>& idx, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
99 int nargout, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
100 const std::list<octave_lvalue>* lvalue_list) |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
101 { |
4924 | 102 octave_value_list retval; |
103 | |
104 switch (type[0]) | |
105 { | |
106 case '(': | |
107 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
108 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5663 | 109 |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
110 retval = do_multi_index_op (tmp_nargout, idx.front (), |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
111 idx.size () == 1 ? lvalue_list : 0); |
4924 | 112 } |
113 break; | |
114 | |
115 case '{': | |
116 case '.': | |
117 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
118 std::string tnm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
119 error ("%s cannot be indexed with %c", tnm.c_str (), type[0]); |
4924 | 120 } |
121 break; | |
122 | |
123 default: | |
124 panic_impossible (); | |
125 } | |
126 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
127 // FIXME: perhaps there should be an |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
128 // octave_value_list::next_subsref member function? See also |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
129 // octave_builtin::subsref. |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
130 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
131 if (idx.size () > 1) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
132 retval = retval(0).next_subsref (nargout, type, idx); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
133 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
134 return retval; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
135 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
136 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
137 octave_value_list |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
138 octave_fcn_handle::do_multi_index_op (int nargout, |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
139 const octave_value_list& args) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
140 { |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
141 return do_multi_index_op (nargout, args, 0); |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
142 } |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
143 |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
144 octave_value_list |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
145 octave_fcn_handle::do_multi_index_op (int nargout, |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
146 const octave_value_list& args, |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
147 const std::list<octave_lvalue>* lvalue_list) |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
148 { |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
149 octave_value_list retval; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
150 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
151 out_of_date_check (fcn, "", false); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
152 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
153 if (has_overloads) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
154 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
155 // Possibly overloaded function. |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
156 octave_value ov_fcn; |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
157 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
158 // Compute dispatch type. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
159 builtin_type_t btyp; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
160 std::string dispatch_type = get_dispatch_type (args, btyp); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
161 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
162 // Retrieve overload. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
163 if (btyp != btyp_unknown) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
164 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
165 out_of_date_check (builtin_overloads[btyp], dispatch_type, false); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
166 ov_fcn = builtin_overloads[btyp]; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
167 } |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
168 else |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
169 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
170 str_ov_map::iterator it = overloads.find (dispatch_type); |
13193
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
171 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
172 if (it == overloads.end ()) |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
173 { |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
174 // Try parent classes too. |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
175 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
176 std::list<std::string> plist |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
177 = symbol_table::parent_classes (dispatch_type); |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
178 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
179 std::list<std::string>::const_iterator pit = plist.begin (); |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
180 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
181 while (pit != plist.end ()) |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
182 { |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
183 std::string pname = *pit; |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
184 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
185 std::string fnm = fcn_name (); |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
186 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
187 octave_value ftmp = symbol_table::find_method (fnm, pname); |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
188 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
189 if (ftmp.is_defined ()) |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
190 { |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
191 set_overload (pname, ftmp); |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
192 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
193 out_of_date_check (ftmp, pname, false); |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
194 ov_fcn = ftmp; |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
195 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
196 break; |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
197 } |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
198 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
199 pit++; |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
200 } |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
201 } |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
202 else |
9466
2ebd0717c12d
also cache class dispatch lookups in function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9463
diff
changeset
|
203 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
204 out_of_date_check (it->second, dispatch_type, false); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
205 ov_fcn = it->second; |
9466
2ebd0717c12d
also cache class dispatch lookups in function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9463
diff
changeset
|
206 } |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
207 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
208 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
209 if (ov_fcn.is_defined ()) |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
210 retval = ov_fcn.do_multi_index_op (nargout, args, lvalue_list); |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
211 else if (fcn.is_defined ()) |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
212 retval = fcn.do_multi_index_op (nargout, args, lvalue_list); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
213 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
214 error ("%s: no method for class %s", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
215 nm.c_str (), dispatch_type.c_str ()); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
216 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
217 else |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
218 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
219 // Non-overloaded function (anonymous, subfunction, private function). |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
220 if (fcn.is_defined ()) |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
221 retval = fcn.do_multi_index_op (nargout, args, lvalue_list); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
222 else |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
223 error ("%s: no longer valid function handle", nm.c_str ()); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
224 } |
4924 | 225 |
226 return retval; | |
227 } | |
228 | |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
229 dim_vector |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
230 octave_fcn_handle::dims (void) const |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
231 { |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
232 static dim_vector dv (1, 1); |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
233 return dv; |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
234 } |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
235 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
236 bool |
10322
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
237 octave_fcn_handle::is_equal_to (const octave_fcn_handle& h) const |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
238 { |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
239 bool retval = fcn.is_copy_of (h.fcn) && (has_overloads == h.has_overloads); |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
240 retval = retval && (overloads.size () == h.overloads.size ()); |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
241 |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
242 if (retval && has_overloads) |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
243 { |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
244 for (int i = 0; i < btyp_num_types && retval; i++) |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
245 retval = builtin_overloads[i].is_copy_of (h.builtin_overloads[i]); |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
246 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
247 str_ov_map::const_iterator iter = overloads.begin (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
248 str_ov_map::const_iterator hiter = h.overloads.begin (); |
10322
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
249 for (; iter != overloads.end () && retval; iter++, hiter++) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
250 retval = (iter->first == hiter->first) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
251 && (iter->second.is_copy_of (hiter->second)); |
10322
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
252 } |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
253 |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
254 return retval; |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
255 } |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
256 |
4988 | 257 bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
258 octave_fcn_handle::set_fcn (const std::string &octaveroot, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
259 const std::string& fpath) |
4988 | 260 { |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
261 if (octaveroot.length () != 0 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
262 && fpath.length () >= octaveroot.length () |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
263 && fpath.substr (0, octaveroot.length ()) == octaveroot |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
264 && OCTAVE_EXEC_PREFIX != octaveroot) |
6625 | 265 { |
266 // First check if just replacing matlabroot is enough | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
267 std::string str = OCTAVE_EXEC_PREFIX + |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
268 fpath.substr (octaveroot.length ()); |
21736
0504351a45e6
use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
269 octave::sys::file_stat fs (str); |
6625 | 270 |
271 if (fs.exists ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
272 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
273 size_t xpos = str.find_last_of (octave::sys::file_ops::dir_sep_chars ()); |
6625 | 274 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
275 std::string dir_name = str.substr (0, xpos); |
6625 | 276 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
277 octave_function *xfcn |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
278 = load_fcn_from_file (str, dir_name, "", "", nm); |
6625 | 279 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
280 if (! xfcn) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
281 error ("function handle points to non-existent function"); |
6625 | 282 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
283 octave_value tmp (xfcn); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
284 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
285 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
286 } |
6625 | 287 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
288 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
289 // Next just search for it anywhere in the system path |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
290 string_vector names(3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
291 names(0) = nm + ".oct"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
292 names(1) = nm + ".mex"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
293 names(2) = nm + ".m"; |
6625 | 294 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
295 dir_path p (load_path::system_path ()); |
6625 | 296 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
297 str = octave::sys::env::make_absolute (p.find_first_of (names)); |
6625 | 298 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
299 size_t xpos = str.find_last_of (octave::sys::file_ops::dir_sep_chars ()); |
6625 | 300 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
301 std::string dir_name = str.substr (0, xpos); |
7336 | 302 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
303 octave_function *xfcn = load_fcn_from_file (str, dir_name, "", "", nm); |
4989 | 304 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
305 if (! xfcn) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
306 error ("function handle points to non-existent function"); |
6625 | 307 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
308 octave_value tmp (xfcn); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
309 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
310 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
311 } |
6625 | 312 } |
313 else | |
314 { | |
15005
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
315 if (fpath.length () > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
316 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
317 size_t xpos = fpath.find_last_of (octave::sys::file_ops::dir_sep_chars ()); |
6625 | 318 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
319 std::string dir_name = fpath.substr (0, xpos); |
7336 | 320 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
321 octave_function *xfcn = load_fcn_from_file (fpath, dir_name, "", "", nm); |
6625 | 322 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
323 if (! xfcn) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
324 error ("function handle points to non-existent function"); |
6625 | 325 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
326 octave_value tmp (xfcn); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
327 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
328 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
329 } |
6625 | 330 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
331 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
332 fcn = symbol_table::find_function (nm); |
7336 | 333 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
334 if (! fcn.is_function ()) |
20953
758b71e964ce
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20952
diff
changeset
|
335 error ("function handle points to non-existent function"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
336 } |
6625 | 337 } |
338 | |
21124
95f8c8cdbffe
maint: Eliminate 'bool success' variable where possible.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
339 return true; |
6625 | 340 } |
341 | |
342 bool | |
6974 | 343 octave_fcn_handle::save_ascii (std::ostream& os) |
6625 | 344 { |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
345 if (nm == anonymous) |
4988 | 346 { |
6625 | 347 os << nm << "\n"; |
348 | |
4989 | 349 print_raw (os, true); |
350 os << "\n"; | |
6625 | 351 |
7336 | 352 if (fcn.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
353 return false; |
6625 | 354 |
355 octave_user_function *f = fcn.user_function_value (); | |
356 | |
7336 | 357 std::list<symbol_table::symbol_record> vars |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
358 = symbol_table::all_variables (f->scope (), 0); |
6625 | 359 |
7336 | 360 size_t varlen = vars.size (); |
6625 | 361 |
362 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
363 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
364 os << "# length: " << varlen << "\n"; |
6625 | 365 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
366 for (std::list<symbol_table::symbol_record>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
367 p = vars.begin (); p != vars.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
368 { |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20435
diff
changeset
|
369 if (! save_text_data (os, p->varval (0), p->name (), false, 0)) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17898
diff
changeset
|
370 return ! os.fail (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
371 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
372 } |
6625 | 373 } |
374 else | |
375 { | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
376 octave_function *f = function_value (); |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
377 std::string fnm = f ? f->fcn_file_name () : ""; |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
378 |
6625 | 379 os << "# octaveroot: " << OCTAVE_EXEC_PREFIX << "\n"; |
15005
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
380 if (! fnm.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
381 os << "# path: " << fnm << "\n"; |
6625 | 382 os << nm << "\n"; |
4988 | 383 } |
384 | |
385 return true; | |
386 } | |
387 | |
388 bool | |
389 octave_fcn_handle::load_ascii (std::istream& is) | |
390 { | |
6625 | 391 bool success = true; |
392 | |
393 std::streampos pos = is.tellg (); | |
394 std::string octaveroot = extract_keyword (is, "octaveroot", true); | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14544
diff
changeset
|
395 if (octaveroot.length () == 0) |
6625 | 396 { |
397 is.seekg (pos); | |
398 is.clear (); | |
399 } | |
400 pos = is.tellg (); | |
401 std::string fpath = extract_keyword (is, "path", true); | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14544
diff
changeset
|
402 if (fpath.length () == 0) |
6625 | 403 { |
404 is.seekg (pos); | |
405 is.clear (); | |
406 } | |
407 | |
4988 | 408 is >> nm; |
4989 | 409 |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
410 if (nm == anonymous) |
4988 | 411 { |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
412 skip_preceeding_newline (is); |
4988 | 413 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
414 std::string buf; |
4988 | 415 |
416 if (is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
417 { |
4988 | 418 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
419 // Get a line of text whitespace characters included, leaving |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
420 // newline in the stream. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
421 buf = read_until_newline (is, true); |
4989 | 422 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
423 } |
4988 | 424 |
6625 | 425 pos = is.tellg (); |
7336 | 426 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
427 unwind_protect_safe frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
428 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
429 // Set up temporary scope to use for evaluating the text that |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
430 // defines the anonymous function. |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
431 |
7336 | 432 symbol_table::scope_id local_scope = symbol_table::alloc_scope (); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
433 frame.add_fcn (symbol_table::erase_scope, local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
434 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
435 symbol_table::set_scope (local_scope); |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
436 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
437 octave_call_stack::push (local_scope, 0); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
438 frame.add_fcn (octave_call_stack::pop); |
4988 | 439 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
440 octave_idx_type len = 0; |
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
441 |
6625 | 442 if (extract_keyword (is, "length", len, true) && len >= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
443 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
444 if (len > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
445 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
446 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
447 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
448 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
449 bool dummy; |
6625 | 450 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
451 std::string name |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
452 = read_text_data (is, "", dummy, t2, i); |
6625 | 453 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20953
diff
changeset
|
454 if (! is) |
20956
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
455 error ("load: failed to load anonymous function handle"); |
6625 | 456 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16170
diff
changeset
|
457 symbol_table::assign (name, t2, local_scope, 0); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
458 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
459 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
460 } |
4989 | 461 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
462 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
463 is.seekg (pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
464 is.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
465 } |
6625 | 466 |
467 if (is && success) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
468 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
469 int parse_status; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
470 octave_value anon_fcn_handle = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
471 eval_string (buf, true, parse_status); |
6625 | 472 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
473 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
474 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
475 octave_fcn_handle *fh = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
476 anon_fcn_handle.fcn_handle_value (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
477 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
478 if (fh) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
479 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
480 fcn = fh->fcn; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
481 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
482 octave_user_function *uf = fcn.user_function_value (true); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
483 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
484 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
485 symbol_table::cache_name (uf->scope (), nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
486 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
487 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
488 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
489 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
490 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
491 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
492 } |
6625 | 493 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
494 success = false; |
4988 | 495 } |
496 else | |
6625 | 497 success = set_fcn (octaveroot, fpath); |
4988 | 498 |
6625 | 499 return success; |
4988 | 500 } |
501 | |
502 bool | |
6625 | 503 octave_fcn_handle::save_binary (std::ostream& os, bool& save_as_floats) |
4988 | 504 { |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
505 if (nm == anonymous) |
4988 | 506 { |
6625 | 507 std::ostringstream nmbuf; |
508 | |
7336 | 509 if (fcn.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
510 return false; |
6625 | 511 |
512 octave_user_function *f = fcn.user_function_value (); | |
513 | |
7336 | 514 std::list<symbol_table::symbol_record> vars |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
515 = symbol_table::all_variables (f->scope (), 0); |
6625 | 516 |
7336 | 517 size_t varlen = vars.size (); |
6625 | 518 |
519 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
520 nmbuf << nm << " " << varlen; |
6625 | 521 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
522 nmbuf << nm; |
6625 | 523 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14544
diff
changeset
|
524 std::string buf_str = nmbuf.str (); |
6625 | 525 int32_t tmp = buf_str.length (); |
526 os.write (reinterpret_cast<char *> (&tmp), 4); | |
527 os.write (buf_str.c_str (), buf_str.length ()); | |
528 | |
5765 | 529 std::ostringstream buf; |
4988 | 530 print_raw (buf, true); |
5765 | 531 std::string stmp = buf.str (); |
4988 | 532 tmp = stmp.length (); |
5760 | 533 os.write (reinterpret_cast<char *> (&tmp), 4); |
4988 | 534 os.write (stmp.c_str (), stmp.length ()); |
6625 | 535 |
536 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
537 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
538 for (std::list<symbol_table::symbol_record>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
539 p = vars.begin (); p != vars.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
540 { |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
541 if (! save_binary_data (os, p->varval (0), p->name (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
542 "", 0, save_as_floats)) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17898
diff
changeset
|
543 return ! os.fail (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
544 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
545 } |
6625 | 546 } |
547 else | |
548 { | |
549 std::ostringstream nmbuf; | |
550 | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
551 octave_function *f = function_value (); |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
552 std::string fnm = f ? f->fcn_file_name () : ""; |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
553 |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
554 nmbuf << nm << "\n" << OCTAVE_EXEC_PREFIX << "\n" << fnm; |
6625 | 555 |
556 std::string buf_str = nmbuf.str (); | |
557 int32_t tmp = buf_str.length (); | |
558 os.write (reinterpret_cast<char *> (&tmp), 4); | |
559 os.write (buf_str.c_str (), buf_str.length ()); | |
4988 | 560 } |
7336 | 561 |
4988 | 562 return true; |
563 } | |
564 | |
565 bool | |
566 octave_fcn_handle::load_binary (std::istream& is, bool swap, | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
567 octave::mach_info::float_format fmt) |
4988 | 568 { |
6625 | 569 bool success = true; |
7336 | 570 |
5828 | 571 int32_t tmp; |
5760 | 572 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
4988 | 573 return false; |
574 if (swap) | |
575 swap_bytes<4> (&tmp); | |
576 | |
577 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1); | |
12714
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
578 // is.get (ctmp1, tmp+1, 0); caused is.eof () to be true though |
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
579 // effectively not reading over file end |
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
580 is.read (ctmp1, tmp); |
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
581 ctmp1[tmp] = 0; |
4988 | 582 nm = std::string (ctmp1); |
583 | |
584 if (! is) | |
585 return false; | |
586 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
587 size_t anl = anonymous.length (); |
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
588 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14544
diff
changeset
|
589 if (nm.length () >= anl && nm.substr (0, anl) == anonymous) |
4988 | 590 { |
6625 | 591 octave_idx_type len = 0; |
592 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14544
diff
changeset
|
593 if (nm.length () > anl) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
594 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
595 std::istringstream nm_is (nm.substr (anl)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
596 nm_is >> len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
597 nm = nm.substr (0, anl); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
598 } |
6625 | 599 |
5760 | 600 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
601 return false; |
4988 | 602 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
603 swap_bytes<4> (&tmp); |
4988 | 604 |
605 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1); | |
12714
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
606 // is.get (ctmp2, tmp+1, 0); caused is.eof () to be true though |
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
607 // effectively not reading over file end |
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
608 is.read (ctmp2, tmp); |
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
609 ctmp2[tmp] = 0; |
4988 | 610 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
611 unwind_protect_safe frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
612 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
613 // Set up temporary scope to use for evaluating the text that |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
614 // defines the anonymous function. |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
615 |
7336 | 616 symbol_table::scope_id local_scope = symbol_table::alloc_scope (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
617 frame.add_fcn (symbol_table::erase_scope, local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
618 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
619 symbol_table::set_scope (local_scope); |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
620 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
621 octave_call_stack::push (local_scope, 0); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
622 frame.add_fcn (octave_call_stack::pop); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
623 |
6625 | 624 if (len > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
625 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
626 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
627 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
628 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
629 bool dummy; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
630 std::string doc; |
6625 | 631 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
632 std::string name = |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
633 read_binary_data (is, swap, fmt, "", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
634 dummy, t2, doc); |
6625 | 635 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20953
diff
changeset
|
636 if (! is) |
20956
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
637 error ("load: failed to load anonymous function handle"); |
6625 | 638 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16170
diff
changeset
|
639 symbol_table::assign (name, t2, local_scope); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
640 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
641 } |
6625 | 642 |
643 if (is && success) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
644 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
645 int parse_status; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
646 octave_value anon_fcn_handle = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
647 eval_string (ctmp2, true, parse_status); |
6625 | 648 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
649 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
650 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
651 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
652 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
653 if (fh) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
654 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
655 fcn = fh->fcn; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
656 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
657 octave_user_function *uf = fcn.user_function_value (true); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
658 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
659 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
660 symbol_table::cache_name (uf->scope (), nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
661 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
662 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
663 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
664 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
665 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
666 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
667 } |
4988 | 668 } |
669 else | |
670 { | |
6625 | 671 std::string octaveroot; |
672 std::string fpath; | |
673 | |
8021 | 674 if (nm.find_first_of ("\n") != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
675 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
676 size_t pos1 = nm.find_first_of ("\n"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
677 size_t pos2 = nm.find_first_of ("\n", pos1 + 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
678 octaveroot = nm.substr (pos1 + 1, pos2 - pos1 - 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
679 fpath = nm.substr (pos2 + 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
680 nm = nm.substr (0, pos1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
681 } |
6625 | 682 |
683 success = set_fcn (octaveroot, fpath); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
684 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
685 |
12714
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
686 return success; |
4988 | 687 } |
688 | |
689 bool | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
690 octave_fcn_handle::save_hdf5 (octave_hdf5_id loc_id, const char *name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
691 bool save_as_floats) |
4988 | 692 { |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
693 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
694 |
7336 | 695 bool retval = true; |
696 | |
4988 | 697 hid_t group_hid = -1; |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
698 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
699 group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
700 #else |
4988 | 701 group_hid = H5Gcreate (loc_id, name, 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
702 #endif |
7336 | 703 if (group_hid < 0) |
704 return false; | |
4988 | 705 |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18019
diff
changeset
|
706 hid_t space_hid, data_hid, type_hid; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18019
diff
changeset
|
707 space_hid = data_hid = type_hid = -1; |
4988 | 708 |
709 // attach the type of the variable | |
710 type_hid = H5Tcopy (H5T_C_S1); | |
711 H5Tset_size (type_hid, nm.length () + 1); | |
712 if (type_hid < 0) | |
713 { | |
714 H5Gclose (group_hid); | |
715 return false; | |
716 } | |
717 | |
718 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2); | |
719 hdims[0] = 0; | |
720 hdims[1] = 0; | |
5760 | 721 space_hid = H5Screate_simple (0 , hdims, 0); |
4988 | 722 if (space_hid < 0) |
723 { | |
724 H5Tclose (type_hid); | |
725 H5Gclose (group_hid); | |
726 return false; | |
727 } | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
728 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
729 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
730 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
731 #else |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
732 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
733 #endif |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
734 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
735 octave_H5P_DEFAULT, nm.c_str ()) < 0) |
4988 | 736 { |
737 H5Sclose (space_hid); | |
738 H5Tclose (type_hid); | |
739 H5Gclose (group_hid); | |
740 return false; | |
741 } | |
742 H5Dclose (data_hid); | |
743 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
744 if (nm == anonymous) |
4988 | 745 { |
5765 | 746 std::ostringstream buf; |
4988 | 747 print_raw (buf, true); |
5765 | 748 std::string stmp = buf.str (); |
4988 | 749 |
750 // attach the type of the variable | |
751 H5Tset_size (type_hid, stmp.length () + 1); | |
752 if (type_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
753 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
754 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
755 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
756 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
757 } |
4988 | 758 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
759 #if defined (HAVE_HDF5_18) |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
760 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
761 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
762 #else |
4988 | 763 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
764 octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
765 #endif |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
766 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
767 octave_H5P_DEFAULT, stmp.c_str ()) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
768 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
769 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
770 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
771 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
772 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
773 } |
4988 | 774 |
775 H5Dclose (data_hid); | |
6625 | 776 |
777 octave_user_function *f = fcn.user_function_value (); | |
778 | |
7336 | 779 std::list<symbol_table::symbol_record> vars |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
780 = symbol_table::all_variables (f->scope (), 0); |
7336 | 781 |
782 size_t varlen = vars.size (); | |
6625 | 783 |
784 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
785 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
786 hid_t as_id = H5Screate (H5S_SCALAR); |
6625 | 787 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
788 if (as_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
789 { |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
790 #if defined (HAVE_HDF5_18) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
791 hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE", |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
792 H5T_NATIVE_IDX, as_id, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
793 octave_H5P_DEFAULT, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
794 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
795 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
796 hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE", |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
797 H5T_NATIVE_IDX, as_id, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
798 #endif |
6625 | 799 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
800 if (a_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
801 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
802 retval = (H5Awrite (a_id, H5T_NATIVE_IDX, &varlen) >= 0); |
6625 | 803 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
804 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
805 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
806 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
807 retval = false; |
6625 | 808 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
809 H5Sclose (as_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
810 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
811 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
812 retval = false; |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
813 #if defined (HAVE_HDF5_18) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
814 data_hid = H5Gcreate (group_hid, "symbol table", |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
815 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
816 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
817 data_hid = H5Gcreate (group_hid, "symbol table", 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
818 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
819 if (data_hid < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
820 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
821 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
822 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
823 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
824 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
825 } |
6625 | 826 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
827 for (std::list<symbol_table::symbol_record>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
828 p = vars.begin (); p != vars.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
829 { |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
830 if (! add_hdf5_data (data_hid, p->varval (0), p->name (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
831 "", false, save_as_floats)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
832 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
833 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
834 H5Gclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
835 } |
6625 | 836 } |
837 else | |
838 { | |
839 std::string octaveroot = OCTAVE_EXEC_PREFIX; | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
840 |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
841 octave_function *f = function_value (); |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
842 std::string fpath = f ? f->fcn_file_name () : ""; |
6625 | 843 |
844 H5Sclose (space_hid); | |
845 hdims[0] = 1; | |
846 hdims[1] = octaveroot.length (); | |
847 space_hid = H5Screate_simple (0 , hdims, 0); | |
848 if (space_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
849 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
850 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
851 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
852 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
853 } |
6625 | 854 |
855 H5Tclose (type_hid); | |
856 type_hid = H5Tcopy (H5T_C_S1); | |
857 H5Tset_size (type_hid, octaveroot.length () + 1); | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
858 #if defined (HAVE_HDF5_18) |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
859 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT", |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
860 type_hid, space_hid, octave_H5P_DEFAULT, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
861 #else |
6625 | 862 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT", |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
863 type_hid, space_hid, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
864 #endif |
6625 | 865 |
866 if (a_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
867 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
868 retval = (H5Awrite (a_id, type_hid, octaveroot.c_str ()) >= 0); |
6625 | 869 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
870 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
871 } |
6625 | 872 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
873 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
874 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
875 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
876 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
877 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
878 } |
6625 | 879 |
880 H5Sclose (space_hid); | |
881 hdims[0] = 1; | |
882 hdims[1] = fpath.length (); | |
883 space_hid = H5Screate_simple (0 , hdims, 0); | |
884 if (space_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
885 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
886 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
887 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
888 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
889 } |
6625 | 890 |
891 H5Tclose (type_hid); | |
892 type_hid = H5Tcopy (H5T_C_S1); | |
893 H5Tset_size (type_hid, fpath.length () + 1); | |
894 | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
895 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
896 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
897 octave_H5P_DEFAULT, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
898 #else |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
899 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
900 #endif |
6625 | 901 |
902 if (a_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
903 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
904 retval = (H5Awrite (a_id, type_hid, fpath.c_str ()) >= 0); |
6625 | 905 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
906 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
907 } |
6625 | 908 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
909 retval = false; |
4988 | 910 } |
911 | |
912 H5Sclose (space_hid); | |
913 H5Tclose (type_hid); | |
914 H5Gclose (group_hid); | |
915 | |
916 return retval; | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
917 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
918 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
919 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
920 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
921 octave_unused_parameter (save_as_floats); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
922 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
923 warn_save ("hdf5"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
924 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
925 return false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
926 #endif |
4988 | 927 } |
928 | |
929 bool | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
930 octave_fcn_handle::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4988 | 931 { |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
932 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
933 |
7336 | 934 bool success = true; |
935 | |
4988 | 936 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id; |
937 hsize_t rank; | |
938 int slen; | |
939 | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
940 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
941 group_hid = H5Gopen (loc_id, name, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
942 #else |
4988 | 943 group_hid = H5Gopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
944 #endif |
7336 | 945 if (group_hid < 0) |
946 return false; | |
4988 | 947 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
948 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
949 data_hid = H5Dopen (group_hid, "nm", octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
950 #else |
4988 | 951 data_hid = H5Dopen (group_hid, "nm"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
952 #endif |
4988 | 953 |
954 if (data_hid < 0) | |
955 { | |
956 H5Gclose (group_hid); | |
957 return false; | |
958 } | |
959 | |
960 type_hid = H5Dget_type (data_hid); | |
961 type_class_hid = H5Tget_class (type_hid); | |
962 | |
963 if (type_class_hid != H5T_STRING) | |
964 { | |
965 H5Tclose (type_hid); | |
966 H5Dclose (data_hid); | |
967 H5Gclose (group_hid); | |
968 return false; | |
969 } | |
970 | |
971 space_hid = H5Dget_space (data_hid); | |
972 rank = H5Sget_simple_extent_ndims (space_hid); | |
973 | |
974 if (rank != 0) | |
975 { | |
976 H5Sclose (space_hid); | |
977 H5Tclose (type_hid); | |
978 H5Dclose (data_hid); | |
979 H5Gclose (group_hid); | |
980 return false; | |
981 } | |
982 | |
983 slen = H5Tget_size (type_hid); | |
984 if (slen < 0) | |
985 { | |
986 H5Sclose (space_hid); | |
987 H5Tclose (type_hid); | |
988 H5Dclose (data_hid); | |
989 H5Gclose (group_hid); | |
990 return false; | |
991 } | |
992 | |
993 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen); | |
994 | |
995 // create datatype for (null-terminated) string to read into: | |
996 st_id = H5Tcopy (H5T_C_S1); | |
997 H5Tset_size (st_id, slen); | |
998 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
999 if (H5Dread (data_hid, st_id, octave_H5S_ALL, octave_H5S_ALL, octave_H5P_DEFAULT, nm_tmp) < 0) |
4988 | 1000 { |
6695 | 1001 H5Tclose (st_id); |
4988 | 1002 H5Sclose (space_hid); |
1003 H5Tclose (type_hid); | |
6695 | 1004 H5Dclose (data_hid); |
4988 | 1005 H5Gclose (group_hid); |
1006 return false; | |
1007 } | |
1008 H5Tclose (st_id); | |
1009 H5Dclose (data_hid); | |
1010 nm = nm_tmp; | |
1011 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
1012 if (nm == anonymous) |
4988 | 1013 { |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1014 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1015 data_hid = H5Dopen (group_hid, "fcn", octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1016 #else |
4988 | 1017 data_hid = H5Dopen (group_hid, "fcn"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1018 #endif |
4988 | 1019 |
1020 if (data_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1021 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1022 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1023 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1024 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1025 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1026 } |
4988 | 1027 |
6695 | 1028 H5Tclose (type_hid); |
4988 | 1029 type_hid = H5Dget_type (data_hid); |
1030 type_class_hid = H5Tget_class (type_hid); | |
1031 | |
1032 if (type_class_hid != H5T_STRING) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1033 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1034 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1035 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1036 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1037 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1038 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1039 } |
4988 | 1040 |
6695 | 1041 H5Sclose (space_hid); |
4988 | 1042 space_hid = H5Dget_space (data_hid); |
1043 rank = H5Sget_simple_extent_ndims (space_hid); | |
1044 | |
1045 if (rank != 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1046 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1047 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1048 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1049 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1050 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1051 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1052 } |
4988 | 1053 |
1054 slen = H5Tget_size (type_hid); | |
1055 if (slen < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1056 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1057 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1058 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1059 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1060 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1061 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1062 } |
4988 | 1063 |
1064 OCTAVE_LOCAL_BUFFER (char, fcn_tmp, slen); | |
1065 | |
1066 // create datatype for (null-terminated) string to read into: | |
1067 st_id = H5Tcopy (H5T_C_S1); | |
1068 H5Tset_size (st_id, slen); | |
1069 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1070 if (H5Dread (data_hid, st_id, octave_H5S_ALL, octave_H5S_ALL, octave_H5P_DEFAULT, fcn_tmp) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1071 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1072 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1073 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1074 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1075 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1076 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1077 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1078 } |
6695 | 1079 H5Tclose (st_id); |
4988 | 1080 H5Dclose (data_hid); |
6625 | 1081 |
1082 octave_idx_type len = 0; | |
1083 | |
1084 // we have to pull some shenanigans here to make sure | |
1085 // HDF5 doesn't print out all sorts of error messages if we | |
1086 // call H5Aopen for a non-existing attribute | |
1087 | |
1088 H5E_auto_t err_func; | |
1089 void *err_func_data; | |
4988 | 1090 |
6625 | 1091 // turn off error reporting temporarily, but save the error |
1092 // reporting function: | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1093 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1094 H5Eget_auto (octave_H5E_DEFAULT, &err_func, &err_func_data); |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1095 H5Eset_auto (octave_H5E_DEFAULT, 0, 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1096 #else |
6625 | 1097 H5Eget_auto (&err_func, &err_func_data); |
1098 H5Eset_auto (0, 0); | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1099 #endif |
6625 | 1100 |
1101 hid_t attr_id = H5Aopen_name (group_hid, "SYMBOL_TABLE"); | |
4988 | 1102 |
6625 | 1103 if (attr_id >= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1104 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1105 if (H5Aread (attr_id, H5T_NATIVE_IDX, &len) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1106 success = false; |
6625 | 1107 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1108 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1109 } |
6625 | 1110 |
1111 // restore error reporting: | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1112 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1113 H5Eset_auto (octave_H5E_DEFAULT, err_func, err_func_data); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1114 #else |
6625 | 1115 H5Eset_auto (err_func, err_func_data); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1116 #endif |
6625 | 1117 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1118 unwind_protect_safe frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1119 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1120 // Set up temporary scope to use for evaluating the text that |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1121 // defines the anonymous function. |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1122 |
7336 | 1123 symbol_table::scope_id local_scope = symbol_table::alloc_scope (); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1124 frame.add_fcn (symbol_table::erase_scope, local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1125 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1126 symbol_table::set_scope (local_scope); |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1127 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1128 octave_call_stack::push (local_scope, 0); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1129 frame.add_fcn (octave_call_stack::pop); |
7336 | 1130 |
6625 | 1131 if (len > 0 && success) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1132 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1133 hsize_t num_obj = 0; |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1134 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1135 data_hid = H5Gopen (group_hid, "symbol table", octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1136 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1137 data_hid = H5Gopen (group_hid, "symbol table"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1138 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1139 H5Gget_num_objs (data_hid, &num_obj); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1140 H5Gclose (data_hid); |
6625 | 1141 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1142 if (num_obj != static_cast<hsize_t>(len)) |
20953
758b71e964ce
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20952
diff
changeset
|
1143 error ("load: failed to load anonymous function handle"); |
6625 | 1144 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1145 hdf5_callback_data dsub; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1146 int current_item = 0; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1147 for (octave_idx_type i = 0; i < len; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1148 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1149 if (H5Giterate (group_hid, "symbol table", ¤t_item, |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1150 hdf5_read_next_data, &dsub) <= 0) |
20957
9db35d2042be
maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
1151 error ("load: failed to load anonymous function handle"); |
6625 | 1152 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1153 symbol_table::assign (dsub.name, dsub.tc, local_scope); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1154 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1155 } |
6625 | 1156 |
1157 if (success) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1158 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1159 int parse_status; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1160 octave_value anon_fcn_handle = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1161 eval_string (fcn_tmp, true, parse_status); |
6625 | 1162 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1163 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1164 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1165 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1166 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1167 if (fh) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1168 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1169 fcn = fh->fcn; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1170 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1171 octave_user_function *uf = fcn.user_function_value (true); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1172 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1173 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1174 symbol_table::cache_name (uf->scope (), nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1175 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1176 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1177 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1178 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1179 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1180 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1181 } |
6625 | 1182 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1183 frame.run (); |
4988 | 1184 } |
1185 else | |
1186 { | |
6625 | 1187 std::string octaveroot; |
1188 std::string fpath; | |
1189 | |
1190 // we have to pull some shenanigans here to make sure | |
1191 // HDF5 doesn't print out all sorts of error messages if we | |
1192 // call H5Aopen for a non-existing attribute | |
1193 | |
1194 H5E_auto_t err_func; | |
1195 void *err_func_data; | |
1196 | |
1197 // turn off error reporting temporarily, but save the error | |
1198 // reporting function: | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1199 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1200 H5Eget_auto (octave_H5E_DEFAULT, &err_func, &err_func_data); |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1201 H5Eset_auto (octave_H5E_DEFAULT, 0, 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1202 #else |
6625 | 1203 H5Eget_auto (&err_func, &err_func_data); |
1204 H5Eset_auto (0, 0); | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1205 #endif |
6625 | 1206 |
1207 hid_t attr_id = H5Aopen_name (group_hid, "OCTAVEROOT"); | |
1208 if (attr_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1209 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1210 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1211 type_hid = H5Aget_type (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1212 type_class_hid = H5Tget_class (type_hid); |
6625 | 1213 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1214 if (type_class_hid != H5T_STRING) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1215 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1216 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1217 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1218 slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1219 st_id = H5Tcopy (H5T_C_S1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1220 H5Tset_size (st_id, slen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1221 OCTAVE_LOCAL_BUFFER (char, root_tmp, slen); |
6625 | 1222 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1223 if (H5Aread (attr_id, st_id, root_tmp) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1224 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1225 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1226 octaveroot = root_tmp; |
6695 | 1227 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1228 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1229 } |
6625 | 1230 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1231 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1232 } |
6625 | 1233 |
6695 | 1234 if (success) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1235 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1236 attr_id = H5Aopen_name (group_hid, "FILE"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1237 if (attr_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1238 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1239 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1240 type_hid = H5Aget_type (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1241 type_class_hid = H5Tget_class (type_hid); |
6625 | 1242 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1243 if (type_class_hid != H5T_STRING) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1244 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1245 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1246 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1247 slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1248 st_id = H5Tcopy (H5T_C_S1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1249 H5Tset_size (st_id, slen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1250 OCTAVE_LOCAL_BUFFER (char, path_tmp, slen); |
6695 | 1251 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1252 if (H5Aread (attr_id, st_id, path_tmp) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1253 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1254 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1255 fpath = path_tmp; |
6695 | 1256 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1257 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1258 } |
6695 | 1259 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1260 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1261 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1262 } |
6625 | 1263 |
1264 // restore error reporting: | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1265 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1266 H5Eset_auto (octave_H5E_DEFAULT, err_func, err_func_data); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1267 #else |
6625 | 1268 H5Eset_auto (err_func, err_func_data); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1269 #endif |
6625 | 1270 |
1271 success = (success ? set_fcn (octaveroot, fpath) : success); | |
4988 | 1272 } |
1273 | |
6695 | 1274 H5Tclose (type_hid); |
1275 H5Sclose (space_hid); | |
1276 H5Gclose (group_hid); | |
1277 | |
6625 | 1278 return success; |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1279 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1280 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
1281 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
1282 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
1283 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1284 warn_load ("hdf5"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
1285 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1286 return false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1287 #endif |
4988 | 1288 } |
6625 | 1289 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1290 /* |
6625 | 1291 %!test |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1292 %! a = 2; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1293 %! f = @(x) a + x; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1294 %! g = @(x) 2 * x; |
11541
28bae9cd7ea9
ov-fcn-handle.cc: use version instead of flops in test
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1295 %! hm = @version; |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
1296 %! hdld = @svd; |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1297 %! hbi = @log2; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1298 %! f2 = f; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1299 %! g2 = g; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1300 %! hm2 = hm; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1301 %! hdld2 = hdld; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1302 %! hbi2 = hbi; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1303 %! modes = {"-text", "-binary"}; |
21434
1da428cbf401
deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
1304 %! if (isfield (__octave_config_info__, "HAVE_HDF5") |
1da428cbf401
deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
1305 %! && __octave_config_info__ ("HAVE_HDF5")) |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1306 %! modes(end+1) = "-hdf5"; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1307 %! endif |
7901 | 1308 %! for i = 1:numel (modes) |
1309 %! mode = modes{i}; | |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
1310 %! nm = tempname (); |
6625 | 1311 %! unwind_protect |
15572
859c8bf6d134
Fix saved struct with function handle fails to load (bug #33857)
Max Brister <max@2bass.com>
parents:
15235
diff
changeset
|
1312 %! f2 (1); # bug #33857 |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1313 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2"); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1314 %! clear f2 g2 hm2 hdld2 hbi2 |
6625 | 1315 %! load (nm); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1316 %! assert (f (2), f2 (2)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1317 %! assert (g (2), g2 (2)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1318 %! assert (g (3), g2 (3)); |
6625 | 1319 %! unlink (nm); |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1320 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2"); |
6625 | 1321 %! unwind_protect_cleanup |
1322 %! unlink (nm); | |
1323 %! end_unwind_protect | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1324 %! endfor |
6625 | 1325 */ |
4988 | 1326 |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1327 /* |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1328 %!function fcn_handle_save_recurse (n, mode, nm, f2, g2, hm2, hdld2, hbi2) |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1329 %! if (n == 0) |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1330 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2"); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1331 %! else |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1332 %! fcn_handle_save_recurse (n - 1, mode, nm, f2, g2, hm2, hdld2, hbi2); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1333 %! endif |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1334 %!endfunction |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1335 %!function [f2, g2, hm2, hdld2, hbi2] = fcn_handle_load_recurse (n, nm) |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1336 %! if (n == 0) |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
1337 %! load (nm); |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1338 %! else |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1339 %! [f2, g2, hm2, hdld2, hbi2] = fcn_handle_load_recurse (n - 1, nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1340 %! endif |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1341 %!endfunction |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1342 |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1343 Test for bug #35876 |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1344 %!test |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1345 %! a = 2; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1346 %! f = @(x) a + x; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1347 %! g = @(x) 2 * x; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1348 %! hm = @version; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1349 %! hdld = @svd; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1350 %! hbi = @log2; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1351 %! f2 = f; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1352 %! g2 = g; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1353 %! hm2 = hm; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1354 %! hdld2 = hdld; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1355 %! hbi2 = hbi; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1356 %! modes = {"-text", "-binary"}; |
21434
1da428cbf401
deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
1357 %! if (isfield (__octave_config_info__, "HAVE_HDF5") |
1da428cbf401
deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
1358 %! && __octave_config_info__ ("HAVE_HDF5")) |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1359 %! modes(end+1) = "-hdf5"; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1360 %! endif |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1361 %! for i = 1:numel (modes) |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1362 %! mode = modes{i}; |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
1363 %! nm = tempname (); |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1364 %! unwind_protect |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1365 %! fcn_handle_save_recurse (2, mode, nm, f2, g2, hm2, hdld2, hbi2); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1366 %! clear f2 g2 hm2 hdld2 hbi2 |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1367 %! [f2, f2, hm2, hdld2, hbi2] = fcn_handle_load_recurse (2, nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1368 %! load (nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1369 %! assert (f (2), f2 (2)); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1370 %! assert (g (2), g2 (2)); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1371 %! assert (g (3), g2 (3)); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1372 %! unlink (nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1373 %! fcn_handle_save_recurse (2, mode, nm, f2, g2, hm2, hdld2, hbi2); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1374 %! unwind_protect_cleanup |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1375 %! unlink (nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1376 %! end_unwind_protect |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1377 %! endfor |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1378 */ |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1379 |
4343 | 1380 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18409
diff
changeset
|
1381 octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax) |
4343 | 1382 { |
1383 print_raw (os, pr_as_read_syntax); | |
1384 newline (os); | |
1385 } | |
1386 | |
1387 void | |
1388 octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const | |
1389 { | |
4980 | 1390 bool printed = false; |
1391 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
1392 if (nm == anonymous) |
4980 | 1393 { |
1394 tree_print_code tpc (os); | |
1395 | |
4989 | 1396 // FCN is const because this member function is, so we can't |
4980 | 1397 // use it to call user_function_value, so we make a copy first. |
1398 | |
1399 octave_value ftmp = fcn; | |
1400 | |
1401 octave_user_function *f = ftmp.user_function_value (); | |
1402 | |
1403 if (f) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1404 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1405 tree_parameter_list *p = f->parameter_list (); |
4980 | 1406 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1407 os << "@("; |
4980 | 1408 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1409 if (p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1410 p->accept (tpc); |
4980 | 1411 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1412 os << ") "; |
4980 | 1413 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
11220
diff
changeset
|
1414 tpc.print_fcn_handle_body (f->body ()); |
4980 | 1415 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1416 printed = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1417 } |
4980 | 1418 } |
1419 | |
1420 if (! printed) | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
1421 octave_print_internal (os, "@" + nm, pr_as_read_syntax, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1422 current_print_indent_level ()); |
4343 | 1423 } |
1424 | |
1425 octave_value | |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1426 make_fcn_handle (const std::string& nm, bool local_funcs) |
4343 | 1427 { |
1428 octave_value retval; | |
1429 | |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1430 // Bow to the god of compatibility. |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1431 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1432 // FIXME: it seems ugly to put this here, but there is no single |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1433 // function in the parser that converts from the operator name to |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1434 // the corresponding function name. At least try to do it without N |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1435 // string compares. |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1436 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1437 std::string tnm = nm; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1438 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1439 size_t len = nm.length (); |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1440 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1441 if (len == 3 && nm == ".**") |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1442 tnm = "power"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1443 else if (len == 2) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1444 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1445 if (nm[0] == '.') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1446 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1447 switch (nm[1]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1448 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1449 case '\'': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1450 tnm = "transpose"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1451 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1452 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1453 case '+': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1454 tnm = "plus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1455 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1456 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1457 case '-': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1458 tnm = "minus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1459 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1460 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1461 case '*': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1462 tnm = "times"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1463 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1464 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1465 case '/': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1466 tnm = "rdivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1467 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1468 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1469 case '^': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1470 tnm = "power"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1471 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1472 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1473 case '\\': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1474 tnm = "ldivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1475 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1476 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1477 } |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1478 else if (nm[1] == '=') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1479 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1480 switch (nm[0]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1481 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1482 case '<': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1483 tnm = "le"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1484 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1485 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1486 case '=': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1487 tnm = "eq"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1488 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1489 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1490 case '>': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1491 tnm = "ge"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1492 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1493 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1494 case '~': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1495 case '!': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1496 tnm = "ne"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1497 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1498 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1499 } |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1500 else if (nm == "**") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1501 tnm = "mpower"; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1502 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1503 else if (len == 1) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1504 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1505 switch (nm[0]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1506 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1507 case '~': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1508 case '!': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1509 tnm = "not"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1510 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1511 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1512 case '\'': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1513 tnm = "ctranspose"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1514 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1515 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1516 case '+': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1517 tnm = "plus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1518 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1519 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1520 case '-': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1521 tnm = "minus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1522 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1523 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1524 case '*': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1525 tnm = "mtimes"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1526 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1527 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1528 case '/': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1529 tnm = "mrdivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1530 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1531 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1532 case '^': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1533 tnm = "mpower"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1534 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1535 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1536 case '\\': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1537 tnm = "mldivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1538 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1539 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1540 case '<': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1541 tnm = "lt"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1542 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1543 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1544 case '>': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1545 tnm = "gt"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1546 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1547 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1548 case '&': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1549 tnm = "and"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1550 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1551 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1552 case '|': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1553 tnm = "or"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1554 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1555 } |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1556 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1557 |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1558 octave_value f = symbol_table::find_function (tnm, octave_value_list (), |
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1559 local_funcs); |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1560 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1561 octave_function *fptr = f.function_value (true); |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1562 |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1563 // Here we are just looking to see if FCN is a method or constructor |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1564 // for any class. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1565 if (local_funcs && fptr |
11461
2b8531a6a3c9
Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents:
11223
diff
changeset
|
1566 && (fptr->is_subfunction () || fptr->is_private_function () |
18441
b0aba84cf80f
Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18416
diff
changeset
|
1567 || fptr->is_class_constructor () |
b0aba84cf80f
Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18416
diff
changeset
|
1568 || fptr->is_classdef_constructor ())) |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1569 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1570 // Locally visible function. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1571 retval = octave_value (new octave_fcn_handle (f, tnm)); |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1572 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1573 else |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1574 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1575 // Globally visible (or no match yet). Query overloads. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1576 std::list<std::string> classes = load_path::overloads (tnm); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1577 bool any_match = fptr != 0 || classes.size () > 0; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1578 if (! any_match) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1579 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1580 // No match found, try updating load_path and query classes again. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1581 load_path::update (); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1582 classes = load_path::overloads (tnm); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1583 any_match = classes.size () > 0; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1584 } |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1585 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1586 if (! any_match) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1587 error ("@%s: no function and no method found", tnm.c_str ()); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1588 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1589 octave_fcn_handle *fh = new octave_fcn_handle (f, tnm); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1590 retval = fh; |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1591 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1592 for (std::list<std::string>::iterator iter = classes.begin (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1593 iter != classes.end (); iter++) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1594 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1595 std::string class_name = *iter; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1596 octave_value fmeth = symbol_table::find_method (tnm, class_name); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1597 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1598 bool is_builtin = false; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1599 for (int i = 0; i < btyp_num_types; i++) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1600 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1601 // FIXME: Too slow? Maybe binary lookup? |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1602 if (class_name == btyp_class_name[i]) |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1603 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1604 is_builtin = true; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1605 fh->set_overload (static_cast<builtin_type_t> (i), fmeth); |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1606 } |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1607 } |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1608 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1609 if (! is_builtin) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1610 fh->set_overload (class_name, fmeth); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1611 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1612 } |
4343 | 1613 |
1614 return retval; | |
1615 } | |
1616 | |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1617 /* |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1618 %!test |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1619 %! x = {".**", "power"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1620 %! ".'", "transpose"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1621 %! ".+", "plus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1622 %! ".-", "minus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1623 %! ".*", "times"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1624 %! "./", "rdivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1625 %! ".^", "power"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1626 %! ".\\", "ldivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1627 %! "<=", "le"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1628 %! "==", "eq"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1629 %! ">=", "ge"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1630 %! "~=", "ne"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1631 %! "!=", "ne"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1632 %! "**", "mpower"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1633 %! "~", "not"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1634 %! "!", "not"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1635 %! "\'", "ctranspose"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1636 %! "+", "plus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1637 %! "-", "minus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1638 %! "*", "mtimes"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1639 %! "/", "mrdivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1640 %! "^", "mpower"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1641 %! "\\", "mldivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1642 %! "<", "lt"; |
9343
70e0d3b1f26f
fix typos in previous change
John W. Eaton <jwe@octave.org>
parents:
9342
diff
changeset
|
1643 %! ">", "gt"; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1644 %! "&", "and"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1645 %! "|", "or"}; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1646 %! for i = 1:rows (x) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1647 %! assert (functions (str2func (x{i,1})).function, x{i,2}); |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1648 %! endfor |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1649 */ |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1650 |
4933 | 1651 DEFUN (functions, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1652 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20818
diff
changeset
|
1653 @deftypefn {} {@var{s} =} functions (@var{fcn_handle})\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1654 Return a structure containing information about the function handle\n\ |
4933 | 1655 @var{fcn_handle}.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1656 \n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
1657 The structure @var{s} always contains these three fields:\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1658 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1659 @table @asis\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1660 @item function\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1661 The function name. For an anonymous function (no name) this will be the\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1662 actual function definition.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1663 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1664 @item type\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1665 Type of the function.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1666 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1667 @table @asis\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1668 @item anonymous\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1669 The function is anonymous.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1670 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1671 @item private\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1672 The function is private.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1673 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1674 @item overloaded\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1675 The function overloads an existing function.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1676 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1677 @item simple\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1678 The function is a built-in or m-file function.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1679 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1680 @item subfunction\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1681 The function is a subfunction within an m-file.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1682 @end table\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1683 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1684 @item file\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1685 The m-file that will be called to perform the function. This field is empty\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1686 for anonymous and built-in functions.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1687 @end table\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1688 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1689 In addition, some function types may return more information in additional\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1690 fields.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1691 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1692 @strong{Warning:} @code{functions} is provided for debugging purposes only.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1693 It's behavior may change in the future and programs should not depend on a\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1694 particular output.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1695 \n\ |
4933 | 1696 @end deftypefn") |
4343 | 1697 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1698 if (args.length () != 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1699 print_usage (); |
4343 | 1700 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1701 octave_fcn_handle *fh = args(0).fcn_handle_value ("functions: FCN_HANDLE argument must be a function handle object"); |
4649 | 1702 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1703 octave_function *fcn = fh ? fh->function_value () : 0; |
4933 | 1704 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1705 if (! fcn) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1706 error ("functions: FCN_HANDLE is not a valid function handle object"); |
4343 | 1707 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1708 octave_scalar_map m; |
4933 | 1709 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1710 std::string fh_nm = fh->fcn_name (); |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1711 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1712 if (fh_nm == octave_fcn_handle::anonymous) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1713 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1714 std::ostringstream buf; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1715 fh->print_raw (buf); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1716 m.setfield ("function", buf.str ()); |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1717 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1718 m.setfield ("type", "anonymous"); |
4343 | 1719 } |
1720 else | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1721 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1722 m.setfield ("function", fh_nm); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1723 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1724 if (fcn->is_subfunction ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1725 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1726 m.setfield ("type", "subfunction"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1727 Cell parentage (dim_vector (1, 2)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1728 parentage.elem (0) = fh_nm; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1729 parentage.elem (1) = fcn->parent_fcn_name (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1730 m.setfield ("parentage", octave_value (parentage)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1731 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1732 else if (fcn->is_private_function ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1733 m.setfield ("type", "private"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1734 else if (fh->is_overloaded ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1735 m.setfield ("type", "overloaded"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1736 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1737 m.setfield ("type", "simple"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1738 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1739 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1740 std::string nm = fcn->fcn_file_name (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1741 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1742 if (fh_nm == octave_fcn_handle::anonymous) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1743 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1744 m.setfield ("file", nm); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1745 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1746 octave_user_function *fu = fh->user_function_value (); |
4343 | 1747 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1748 std::list<symbol_table::symbol_record> vars |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1749 = symbol_table::all_variables (fu->scope (), 0); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1750 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1751 size_t varlen = vars.size (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1752 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1753 if (varlen > 0) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1754 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1755 octave_scalar_map ws; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1756 for (std::list<symbol_table::symbol_record>::const_iterator |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1757 p = vars.begin (); p != vars.end (); p++) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1758 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1759 ws.assign (p->name (), p->varval (0)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1760 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1761 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1762 m.setfield ("workspace", ws); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1763 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1764 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1765 else if (fcn->is_user_function () || fcn->is_user_script ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1766 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1767 octave_function *fu = fh->function_value (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1768 m.setfield ("file", fu->fcn_file_name ()); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1769 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1770 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1771 m.setfield ("file", ""); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1772 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1773 return ovl (m); |
4343 | 1774 } |
1775 | |
4933 | 1776 DEFUN (func2str, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1777 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20818
diff
changeset
|
1778 @deftypefn {} {} func2str (@var{fcn_handle})\n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
1779 Return a string containing the name of the function referenced by the\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
1780 function handle @var{fcn_handle}.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1781 @seealso{str2func, functions}\n\ |
4933 | 1782 @end deftypefn") |
4343 | 1783 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1784 if (args.length () != 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1785 print_usage (); |
4930 | 1786 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1787 octave_fcn_handle *fh = args(0).fcn_handle_value ("func2str: FCN_HANDLE argument must be a function handle object"); |
6416 | 1788 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1789 if (! fh) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1790 error ("func2str: FCN_HANDLE must be a valid function handle"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1791 |
4343 | 1792 octave_value retval; |
1793 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1794 std::string fh_nm = fh->fcn_name (); |
6416 | 1795 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1796 if (fh_nm == octave_fcn_handle::anonymous) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1797 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1798 std::ostringstream buf; |
6416 | 1799 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1800 fh->print_raw (buf); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1801 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1802 retval = buf.str (); |
4343 | 1803 } |
1804 else | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1805 retval = fh_nm; |
4343 | 1806 |
1807 return retval; | |
1808 } | |
1809 | |
4933 | 1810 DEFUN (str2func, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1811 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20818
diff
changeset
|
1812 @deftypefn {} {} str2func (@var{fcn_name})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20818
diff
changeset
|
1813 @deftypefnx {} {} str2func (@var{fcn_name}, \"global\")\n\ |
4933 | 1814 Return a function handle constructed from the string @var{fcn_name}.\n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
1815 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
1816 If the optional @qcode{\"global\"} argument is passed, locally visible\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
1817 functions are ignored in the lookup.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1818 @seealso{func2str, inline}\n\ |
4933 | 1819 @end deftypefn") |
4343 | 1820 { |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1821 int nargin = args.length (); |
4343 | 1822 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1823 if (nargin < 1 || nargin > 2) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1824 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1825 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1826 std::string nm = args(0).xstring_value ("str2func: FCN_NAME must be a string"); |
20580
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
1827 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1828 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1829 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1830 if (nm[0] == '@') |
4343 | 1831 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1832 int parse_status; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1833 octave_value anon_fcn_handle = |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1834 eval_string (nm, true, parse_status); |
20508
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1835 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1836 if (parse_status == 0) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1837 retval = anon_fcn_handle; |
4343 | 1838 } |
1839 else | |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1840 retval = make_fcn_handle (nm, nargin != 2); |
4343 | 1841 |
1842 return retval; | |
1843 } | |
1844 | |
1845 /* | |
20508
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1846 %!test |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1847 %! f = str2func ("<"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1848 %! assert (class (f), "function_handle"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1849 %! assert (func2str (f), "lt"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1850 %! assert (f (1, 2), true); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1851 %! assert (f (2, 1), false); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1852 |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1853 %!test |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1854 %! f = str2func ("@(x) sin (x)"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1855 %! assert (func2str (f), "@(x) sin (x)"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1856 %! assert (f (0:3), sin (0:3)); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1857 |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1858 %!error <FCN_NAME must be a string> str2func ({"sin"}) |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1859 */ |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1860 |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
1861 /* |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
1862 %!function y = __testrecursionfunc (f, x, n) |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1863 %! if (nargin < 3) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1864 %! n = 0; |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1865 %! endif |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1866 %! if (n > 2) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1867 %! y = f (x); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1868 %! else |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1869 %! n++; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1870 %! y = __testrecursionfunc (@(x) f (2*x), x, n); |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1871 %! endif |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
1872 %!endfunction |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
1873 %! |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
1874 %!assert (__testrecursionfunc (@(x) x, 1), 8) |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1875 */ |
10960 | 1876 |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1877 DEFUN (is_function_handle, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1878 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20818
diff
changeset
|
1879 @deftypefn {} {} is_function_handle (@var{x})\n\ |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1880 Return true if @var{x} is a function handle.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1881 @seealso{isa, typeinfo, class, functions}\n\ |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1882 @end deftypefn") |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1883 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20797
diff
changeset
|
1884 if (args.length () != 1) |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1885 print_usage (); |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1886 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1887 return ovl (args(0).is_function_handle ()); |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1888 } |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1889 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1890 /* |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1891 %!shared fh |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1892 %! fh = @(x) x; |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1893 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1894 %!assert (is_function_handle (fh)) |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1895 %!assert (! is_function_handle ({fh})) |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1896 %!assert (! is_function_handle (1)) |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1897 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1898 %!error is_function_handle () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1899 %!error is_function_handle (1, 2) |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1900 */ |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1901 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1902 octave_fcn_binder::octave_fcn_binder (const octave_value& f, |
10960 | 1903 const octave_value& root, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1904 const octave_value_list& templ, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1905 const std::vector<int>& mask, |
10960 | 1906 int exp_nargin) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1907 : octave_fcn_handle (f), root_handle (root), arg_template (templ), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1908 arg_mask (mask), expected_nargin (exp_nargin) |
10960 | 1909 { |
1910 } | |
1911 | |
1912 octave_fcn_handle * | |
1913 octave_fcn_binder::maybe_binder (const octave_value& f) | |
1914 { | |
1915 octave_fcn_handle *retval = 0; | |
1916 | |
1917 octave_user_function *usr_fcn = f.user_function_value (false); | |
1918 tree_parameter_list *param_list = usr_fcn ? usr_fcn->parameter_list () : 0; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1919 |
17898
8c33abdd2f9a
maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents:
17896
diff
changeset
|
1920 tree_statement_list *cmd_list = 0; |
8c33abdd2f9a
maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents:
17896
diff
changeset
|
1921 tree_expression *body_expr = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1922 |
17896
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1923 if (usr_fcn) |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1924 { |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1925 cmd_list = usr_fcn->body (); |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1926 if (cmd_list) |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1927 { |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1928 // Verify that body is a single expression (always true in theory). |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1929 body_expr = (cmd_list->length () == 1 |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1930 ? cmd_list->front ()->expression () : 0); |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1931 } |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1932 } |
10960 | 1933 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1934 if (body_expr && body_expr->is_index_expression () |
10960 | 1935 && ! (param_list && param_list->takes_varargs ())) |
1936 { | |
1937 // It's an index expression. | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1938 tree_index_expression *idx_expr = dynamic_cast<tree_index_expression *> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1939 (body_expr); |
10960 | 1940 tree_expression *head_expr = idx_expr->expression (); |
1941 std::list<tree_argument_list *> arg_lists = idx_expr->arg_lists (); | |
1942 std::string type_tags = idx_expr->type_tags (); | |
1943 | |
1944 if (type_tags.length () == 1 && type_tags[0] == '(' | |
1945 && head_expr->is_identifier ()) | |
1946 { | |
1947 assert (arg_lists.size () == 1); | |
1948 | |
1949 // It's a single index expression: a(x,y,....) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1950 tree_identifier *head_id = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1951 dynamic_cast<tree_identifier *> (head_expr); |
10960 | 1952 tree_argument_list *arg_list = arg_lists.front (); |
1953 | |
1954 // Build a map of input params to their position. | |
1955 std::map<std::string, int> arginmap; | |
1956 int npar = 0; | |
1957 | |
1958 if (param_list) | |
1959 { | |
1960 for (tree_parameter_list::iterator it = param_list->begin (); | |
1961 it != param_list->end (); ++it, ++npar) | |
1962 { | |
1963 tree_decl_elt *elt = *it; | |
1964 tree_identifier *id = elt ? elt->ident () : 0; | |
1965 if (id && ! id->is_black_hole ()) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1966 arginmap[id->name ()] = npar; |
10960 | 1967 } |
1968 } | |
1969 | |
1970 if (arg_list && arg_list->length () > 0) | |
1971 { | |
1972 bool bad = false; | |
1973 int nargs = arg_list->length (); | |
1974 octave_value_list arg_template (nargs); | |
1975 std::vector<int> arg_mask (nargs); | |
1976 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1977 // Verify that each argument is either a named param, a constant, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1978 // or a defined identifier. |
10960 | 1979 int iarg = 0; |
1980 for (tree_argument_list::iterator it = arg_list->begin (); | |
1981 it != arg_list->end (); ++it, ++iarg) | |
1982 { | |
1983 tree_expression *elt = *it; | |
1984 if (elt && elt->is_constant ()) | |
1985 { | |
1986 arg_template(iarg) = elt->rvalue1 (); | |
1987 arg_mask[iarg] = -1; | |
1988 } | |
1989 else if (elt && elt->is_identifier ()) | |
1990 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1991 tree_identifier *elt_id = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1992 dynamic_cast<tree_identifier *> (elt); |
10960 | 1993 if (arginmap.find (elt_id->name ()) != arginmap.end ()) |
1994 { | |
1995 arg_mask[iarg] = arginmap[elt_id->name ()]; | |
1996 } | |
1997 else if (elt_id->is_defined ()) | |
1998 { | |
1999 arg_template(iarg) = elt_id->rvalue1 (); | |
2000 arg_mask[iarg] = -1; | |
2001 } | |
2002 else | |
2003 { | |
2004 bad = true; | |
2005 break; | |
2006 } | |
2007 } | |
2008 else | |
2009 { | |
2010 bad = true; | |
2011 break; | |
2012 } | |
2013 } | |
2014 | |
2015 octave_value root_val; | |
2016 | |
2017 if (! bad) | |
2018 { | |
2019 // If the head is a value, use it as root. | |
2020 if (head_id->is_defined ()) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2021 root_val = head_id->rvalue1 (); |
10960 | 2022 else |
2023 { | |
2024 // It's a name. | |
2025 std::string head_name = head_id->name (); | |
20605
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2026 |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2027 if (head_name == "eval" || head_name == "feval") |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2028 bad = true; |
10960 | 2029 else |
2030 { | |
20605
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2031 // Function handles can't handle legacy |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2032 // dispatch, so we make sure it's not |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2033 // defined. |
10960 | 2034 |
20605
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2035 if (symbol_table::get_dispatch (head_name).size () > 0) |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2036 bad = true; |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2037 else |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20531
diff
changeset
|
2038 { |
20605
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2039 // Simulate try/catch. |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2040 unwind_protect frame; |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2041 interpreter_try (frame); |
10960 | 2042 |
20605
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2043 try |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2044 { |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2045 root_val = make_fcn_handle (head_name); |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2046 } |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2047 catch (const octave_execution_exception&) |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2048 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
2049 recover_from_exception (); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
2050 |
20605
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2051 bad = true; |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2052 } |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20531
diff
changeset
|
2053 } |
10960 | 2054 } |
2055 } | |
2056 } | |
2057 | |
2058 if (! bad) | |
2059 { | |
10961 | 2060 // Stash proper name tags. |
2061 std::list<string_vector> arg_names = idx_expr->arg_names (); | |
2062 assert (arg_names.size () == 1); | |
2063 arg_template.stash_name_tags (arg_names.front ()); | |
2064 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
2065 retval = new octave_fcn_binder (f, root_val, arg_template, |
10960 | 2066 arg_mask, npar); |
2067 } | |
2068 } | |
2069 } | |
2070 } | |
2071 | |
2072 if (! retval) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2073 retval = new octave_fcn_handle (f, octave_fcn_handle::anonymous); |
10960 | 2074 |
2075 return retval; | |
2076 } | |
2077 | |
20605
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2078 /* |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2079 %!test |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2080 %! f = @(t) eval ('2*t'); |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2081 %! assert (f (21), 42); |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2082 */ |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2083 |
10960 | 2084 octave_value_list |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
2085 octave_fcn_binder::do_multi_index_op (int nargout, |
10960 | 2086 const octave_value_list& args) |
2087 { | |
2088 return do_multi_index_op (nargout, args, 0); | |
2089 } | |
2090 | |
2091 octave_value_list | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
2092 octave_fcn_binder::do_multi_index_op (int nargout, |
10960 | 2093 const octave_value_list& args, |
2094 const std::list<octave_lvalue>* lvalue_list) | |
2095 { | |
2096 octave_value_list retval; | |
2097 | |
2098 if (args.length () == expected_nargin) | |
2099 { | |
2100 for (int i = 0; i < arg_template.length (); i++) | |
2101 { | |
2102 int j = arg_mask[i]; | |
2103 if (j >= 0) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2104 arg_template(i) = args(j); // May force a copy... |
10960 | 2105 } |
2106 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2107 // Make a shallow copy of arg_template, to ensure consistency throughout |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2108 // the following call even if we happen to get back here. |
10961 | 2109 octave_value_list tmp (arg_template); |
2110 retval = root_handle.do_multi_index_op (nargout, tmp, lvalue_list); | |
10960 | 2111 } |
2112 else | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2113 retval = octave_fcn_handle::do_multi_index_op (nargout, args, lvalue_list); |
10960 | 2114 |
2115 return retval; | |
2116 } | |
13696
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2117 |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2118 /* |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
2119 %!function r = __f (g, i) |
13696
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2120 %! r = g(i); |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2121 %!endfunction |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2122 %!test |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2123 %! x = [1,2;3,4]; |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
2124 %! assert (__f (@(i) x(:,i), 1), [1;3]); |
13696
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2125 */ |