Mercurial > octave-nkf
annotate libinterp/octave-value/ov-fcn-handle.cc @ 20587:f90c8372b7ba
eliminate many more simple uses of error_state
* Cell.cc, __ichol__.cc, __ilu__.cc, balance.cc, bsxfun.cc, colloc.cc,
det.cc, dlmread.cc, dynamic-ld.cc, eig.cc, fft.cc, fft2.cc, fftn.cc,
gcd.cc, getgrent.cc, getpwent.cc, givens.cc, hess.cc, input.cc,
levenshtein.cc, load-path.cc, lookup.cc, ls-mat-ascii.cc, ls-mat4.cc,
lsode.cc, lu.cc, max.cc, md5sum.cc, mex.cc, pager.cc, pinv.cc,
pr-output.cc, qz.cc, schur.cc, sparse.cc, sqrtm.cc, str2double.cc,
strfns.cc, sub2ind.cc, sysdep.cc, time.cc, toplev.cc, tril.cc,
tsearch.cc, typecast.cc, __init_gnuplot__.cc, __magick_read__.cc,
__osmesa_print__.cc, amd.cc, audiodevinfo.cc, dmperm.cc, fftw.cc,
symrcm.cc, ov-base-diag.cc, ov-base-sparse.cc, ov-base.cc,
ov-bool-sparse.cc, ov-builtin.cc, ov-complex.cc, ov-cx-diag.cc,
ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc, ov-fcn-inline.cc,
ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc,
ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-lazy-idx.cc, ov-mex-fcn.cc,
ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc,
ov-scalar.cc, ov-str-mat.cc, op-bm-b.cc, op-bm-bm.cc, op-sbm-b.cc,
op-sbm-bm.cc, op-str-m.cc, op-str-s.cc, oct-parse.in.yy, pt-cbinop.cc,
pt-colon.cc, pt-decl.cc, pt-exp.cc, pt-id.cc, pt-misc.cc,
pt-select.cc, pt-unop.cc: Eliminate simple uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 05 Oct 2015 19:29:36 -0400 |
parents | b70cc4bd8109 |
children | 729a85dafba8 |
rev | line source |
---|---|
4343 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19632
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 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
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" |
38 #include "gripes.h" | |
5663 | 39 #include "input.h" |
19897
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:
19731
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" |
20482
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20470
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 ()) |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20198
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 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
151 out_of_date_check (fcn, std::string (), 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 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
229 bool |
10322
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
230 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
|
231 { |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
232 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
|
233 retval = retval && (overloads.size () == h.overloads.size ()); |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
234 |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
235 if (retval && has_overloads) |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
236 { |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
237 for (int i = 0; i < btyp_num_types && retval; i++) |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
238 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
|
239 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
240 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
|
241 str_ov_map::const_iterator hiter = h.overloads.begin (); |
10322
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
242 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
|
243 retval = (iter->first == hiter->first) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
244 && (iter->second.is_copy_of (hiter->second)); |
10322
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
245 } |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
246 |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
247 return retval; |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
248 } |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
249 |
4988 | 250 bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
251 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
|
252 const std::string& fpath) |
4988 | 253 { |
6625 | 254 bool success = true; |
255 | |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
256 if (octaveroot.length () != 0 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
257 && fpath.length () >= octaveroot.length () |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
258 && 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
|
259 && OCTAVE_EXEC_PREFIX != octaveroot) |
6625 | 260 { |
261 // 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
|
262 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
|
263 fpath.substr (octaveroot.length ()); |
6625 | 264 file_stat fs (str); |
265 | |
266 if (fs.exists ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
267 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
268 size_t xpos = str.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 269 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
270 std::string dir_name = str.substr (0, xpos); |
6625 | 271 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
272 octave_function *xfcn |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
273 = load_fcn_from_file (str, dir_name, "", "", nm); |
6625 | 274 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
275 if (xfcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
276 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
277 octave_value tmp (xfcn); |
6625 | 278 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
279 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
280 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
281 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
282 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
283 error ("function handle points to non-existent function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
284 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
285 } |
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 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
297 str = octave_env::make_absolute (p.find_first_of (names)); |
6625 | 298 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
299 size_t xpos = str.find_last_of (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 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
305 if (xfcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
306 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
307 octave_value tmp (xfcn); |
6625 | 308 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
309 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
310 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
311 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
312 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
313 error ("function handle points to non-existent function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
314 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
315 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
316 } |
6625 | 317 } |
318 else | |
319 { | |
15005
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
320 if (fpath.length () > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
321 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
322 size_t xpos = fpath.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 323 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
324 std::string dir_name = fpath.substr (0, xpos); |
7336 | 325 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
326 octave_function *xfcn = load_fcn_from_file (fpath, dir_name, "", "", nm); |
6625 | 327 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
328 if (xfcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
329 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
330 octave_value tmp (xfcn); |
6625 | 331 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
332 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
333 } |
15005
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
334 else |
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
335 { |
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
336 error ("function handle points to non-existent function"); |
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
337 success = false; |
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
338 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
339 } |
6625 | 340 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
341 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
342 fcn = symbol_table::find_function (nm); |
7336 | 343 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
344 if (! fcn.is_function ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
345 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
346 error ("function handle points to non-existent function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
347 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
348 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
349 } |
6625 | 350 } |
351 | |
352 return success; | |
353 } | |
354 | |
355 bool | |
6974 | 356 octave_fcn_handle::save_ascii (std::ostream& os) |
6625 | 357 { |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
358 if (nm == anonymous) |
4988 | 359 { |
6625 | 360 os << nm << "\n"; |
361 | |
4989 | 362 print_raw (os, true); |
363 os << "\n"; | |
6625 | 364 |
7336 | 365 if (fcn.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
366 return false; |
6625 | 367 |
368 octave_user_function *f = fcn.user_function_value (); | |
369 | |
7336 | 370 std::list<symbol_table::symbol_record> vars |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
371 = symbol_table::all_variables (f->scope (), 0); |
6625 | 372 |
7336 | 373 size_t varlen = vars.size (); |
6625 | 374 |
375 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
376 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
377 os << "# length: " << varlen << "\n"; |
6625 | 378 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
379 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
|
380 p = vars.begin (); p != vars.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
381 { |
20482
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20470
diff
changeset
|
382 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
|
383 return ! os.fail (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
384 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
385 } |
6625 | 386 } |
387 else | |
388 { | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
389 octave_function *f = function_value (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
390 std::string fnm = f ? f->fcn_file_name () : std::string (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
391 |
6625 | 392 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
|
393 if (! fnm.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
394 os << "# path: " << fnm << "\n"; |
6625 | 395 os << nm << "\n"; |
4988 | 396 } |
397 | |
398 return true; | |
399 } | |
400 | |
401 bool | |
402 octave_fcn_handle::load_ascii (std::istream& is) | |
403 { | |
6625 | 404 bool success = true; |
405 | |
406 std::streampos pos = is.tellg (); | |
407 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
|
408 if (octaveroot.length () == 0) |
6625 | 409 { |
410 is.seekg (pos); | |
411 is.clear (); | |
412 } | |
413 pos = is.tellg (); | |
414 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
|
415 if (fpath.length () == 0) |
6625 | 416 { |
417 is.seekg (pos); | |
418 is.clear (); | |
419 } | |
420 | |
4988 | 421 is >> nm; |
4989 | 422 |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
423 if (nm == anonymous) |
4988 | 424 { |
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
|
425 skip_preceeding_newline (is); |
4988 | 426 |
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
|
427 std::string buf; |
4988 | 428 |
429 if (is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
430 { |
4988 | 431 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
432 // 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
|
433 // newline in the stream. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
434 buf = read_until_newline (is, true); |
4989 | 435 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
436 } |
4988 | 437 |
6625 | 438 pos = is.tellg (); |
7336 | 439 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
440 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
|
441 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
442 // 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
|
443 // 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
|
444 |
7336 | 445 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
|
446 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
|
447 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
448 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
|
449 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
450 octave_call_stack::push (local_scope, 0); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
451 frame.add_fcn (octave_call_stack::pop); |
4988 | 452 |
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
|
453 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
|
454 |
6625 | 455 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
|
456 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
457 if (len > 0) |
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 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
|
460 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
461 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
462 bool dummy; |
6625 | 463 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
464 std::string name |
20482
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20470
diff
changeset
|
465 = read_text_data (is, std::string (), dummy, t2, i); |
6625 | 466 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
467 if (!is) |
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 error ("load: failed to load anonymous function handle"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
470 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
471 } |
6625 | 472 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16170
diff
changeset
|
473 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
|
474 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
475 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
476 } |
4989 | 477 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
478 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
479 is.seekg (pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
480 is.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
481 } |
6625 | 482 |
483 if (is && success) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
484 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
485 int parse_status; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
486 octave_value anon_fcn_handle = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
487 eval_string (buf, true, parse_status); |
6625 | 488 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
489 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
490 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
491 octave_fcn_handle *fh = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
492 anon_fcn_handle.fcn_handle_value (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
493 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
494 if (fh) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
495 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
496 fcn = fh->fcn; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
497 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
498 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
|
499 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
500 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
501 symbol_table::cache_name (uf->scope (), nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
502 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
503 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
504 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
505 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
506 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
507 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
508 } |
6625 | 509 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
510 success = false; |
4988 | 511 } |
512 else | |
6625 | 513 success = set_fcn (octaveroot, fpath); |
4988 | 514 |
6625 | 515 return success; |
4988 | 516 } |
517 | |
518 bool | |
6625 | 519 octave_fcn_handle::save_binary (std::ostream& os, bool& save_as_floats) |
4988 | 520 { |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
521 if (nm == anonymous) |
4988 | 522 { |
6625 | 523 std::ostringstream nmbuf; |
524 | |
7336 | 525 if (fcn.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
526 return false; |
6625 | 527 |
528 octave_user_function *f = fcn.user_function_value (); | |
529 | |
7336 | 530 std::list<symbol_table::symbol_record> vars |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
531 = symbol_table::all_variables (f->scope (), 0); |
6625 | 532 |
7336 | 533 size_t varlen = vars.size (); |
6625 | 534 |
535 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
536 nmbuf << nm << " " << varlen; |
6625 | 537 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
538 nmbuf << nm; |
6625 | 539 |
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
|
540 std::string buf_str = nmbuf.str (); |
6625 | 541 int32_t tmp = buf_str.length (); |
542 os.write (reinterpret_cast<char *> (&tmp), 4); | |
543 os.write (buf_str.c_str (), buf_str.length ()); | |
544 | |
5765 | 545 std::ostringstream buf; |
4988 | 546 print_raw (buf, true); |
5765 | 547 std::string stmp = buf.str (); |
4988 | 548 tmp = stmp.length (); |
5760 | 549 os.write (reinterpret_cast<char *> (&tmp), 4); |
4988 | 550 os.write (stmp.c_str (), stmp.length ()); |
6625 | 551 |
552 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
553 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
554 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
|
555 p = vars.begin (); p != vars.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
556 { |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
557 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
|
558 "", 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
|
559 return ! os.fail (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
560 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
561 } |
6625 | 562 } |
563 else | |
564 { | |
565 std::ostringstream nmbuf; | |
566 | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
567 octave_function *f = function_value (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
568 std::string fnm = f ? f->fcn_file_name () : std::string (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
569 |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
570 nmbuf << nm << "\n" << OCTAVE_EXEC_PREFIX << "\n" << fnm; |
6625 | 571 |
572 std::string buf_str = nmbuf.str (); | |
573 int32_t tmp = buf_str.length (); | |
574 os.write (reinterpret_cast<char *> (&tmp), 4); | |
575 os.write (buf_str.c_str (), buf_str.length ()); | |
4988 | 576 } |
7336 | 577 |
4988 | 578 return true; |
579 } | |
580 | |
581 bool | |
582 octave_fcn_handle::load_binary (std::istream& is, bool swap, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
583 oct_mach_info::float_format fmt) |
4988 | 584 { |
6625 | 585 bool success = true; |
7336 | 586 |
5828 | 587 int32_t tmp; |
5760 | 588 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
4988 | 589 return false; |
590 if (swap) | |
591 swap_bytes<4> (&tmp); | |
592 | |
593 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
|
594 // 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
|
595 // 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
|
596 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
|
597 ctmp1[tmp] = 0; |
4988 | 598 nm = std::string (ctmp1); |
599 | |
600 if (! is) | |
601 return false; | |
602 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
603 size_t anl = anonymous.length (); |
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
604 |
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
|
605 if (nm.length () >= anl && nm.substr (0, anl) == anonymous) |
4988 | 606 { |
6625 | 607 octave_idx_type len = 0; |
608 | |
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
|
609 if (nm.length () > anl) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
610 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
611 std::istringstream nm_is (nm.substr (anl)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
612 nm_is >> len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
613 nm = nm.substr (0, anl); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
614 } |
6625 | 615 |
5760 | 616 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
|
617 return false; |
4988 | 618 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
619 swap_bytes<4> (&tmp); |
4988 | 620 |
621 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
|
622 // 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
|
623 // 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
|
624 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
|
625 ctmp2[tmp] = 0; |
4988 | 626 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
627 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
|
628 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
629 // 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
|
630 // 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
|
631 |
7336 | 632 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
|
633 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
|
634 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
635 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
|
636 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
637 octave_call_stack::push (local_scope, 0); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
638 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
|
639 |
6625 | 640 if (len > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
641 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
642 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
|
643 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
644 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
645 bool dummy; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
646 std::string doc; |
6625 | 647 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
648 std::string name = |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
649 read_binary_data (is, swap, fmt, std::string (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
650 dummy, t2, doc); |
6625 | 651 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
652 if (!is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
653 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
654 error ("load: failed to load anonymous function handle"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
655 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
656 } |
6625 | 657 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16170
diff
changeset
|
658 symbol_table::assign (name, t2, local_scope); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
659 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
660 } |
6625 | 661 |
662 if (is && success) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
663 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
664 int parse_status; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
665 octave_value anon_fcn_handle = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
666 eval_string (ctmp2, true, parse_status); |
6625 | 667 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
668 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
669 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
670 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
|
671 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
672 if (fh) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
673 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
674 fcn = fh->fcn; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
675 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
676 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
|
677 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
678 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
679 symbol_table::cache_name (uf->scope (), nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
680 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
681 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
682 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
683 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
684 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
685 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
686 } |
4988 | 687 } |
688 else | |
689 { | |
6625 | 690 std::string octaveroot; |
691 std::string fpath; | |
692 | |
8021 | 693 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
|
694 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
695 size_t pos1 = nm.find_first_of ("\n"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
696 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
|
697 octaveroot = nm.substr (pos1 + 1, pos2 - pos1 - 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
698 fpath = nm.substr (pos2 + 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
699 nm = nm.substr (0, pos1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
700 } |
6625 | 701 |
702 success = set_fcn (octaveroot, fpath); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
703 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
704 |
12714
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
705 return success; |
4988 | 706 } |
707 | |
708 bool | |
19897
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:
19731
diff
changeset
|
709 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
|
710 bool save_as_floats) |
4988 | 711 { |
19897
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:
19731
diff
changeset
|
712 #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:
19731
diff
changeset
|
713 |
7336 | 714 bool retval = true; |
715 | |
4988 | 716 hid_t group_hid = -1; |
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
|
717 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
718 group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
719 #else |
4988 | 720 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
|
721 #endif |
7336 | 722 if (group_hid < 0) |
723 return false; | |
4988 | 724 |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18019
diff
changeset
|
725 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
|
726 space_hid = data_hid = type_hid = -1; |
4988 | 727 |
728 // attach the type of the variable | |
729 type_hid = H5Tcopy (H5T_C_S1); | |
730 H5Tset_size (type_hid, nm.length () + 1); | |
731 if (type_hid < 0) | |
732 { | |
733 H5Gclose (group_hid); | |
734 return false; | |
735 } | |
736 | |
737 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2); | |
738 hdims[0] = 0; | |
739 hdims[1] = 0; | |
5760 | 740 space_hid = H5Screate_simple (0 , hdims, 0); |
4988 | 741 if (space_hid < 0) |
742 { | |
743 H5Tclose (type_hid); | |
744 H5Gclose (group_hid); | |
745 return false; | |
746 } | |
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
|
747 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
748 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
749 H5P_DEFAULT, H5P_DEFAULT, 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
|
750 #else |
4988 | 751 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, 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
|
752 #endif |
4988 | 753 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
754 H5P_DEFAULT, nm.c_str ()) < 0) |
4988 | 755 { |
756 H5Sclose (space_hid); | |
757 H5Tclose (type_hid); | |
758 H5Gclose (group_hid); | |
759 return false; | |
760 } | |
761 H5Dclose (data_hid); | |
762 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
763 if (nm == anonymous) |
4988 | 764 { |
5765 | 765 std::ostringstream buf; |
4988 | 766 print_raw (buf, true); |
5765 | 767 std::string stmp = buf.str (); |
4988 | 768 |
769 // attach the type of the variable | |
770 H5Tset_size (type_hid, stmp.length () + 1); | |
771 if (type_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
772 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
773 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
774 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
775 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
776 } |
4988 | 777 |
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
|
778 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
779 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
780 H5P_DEFAULT, H5P_DEFAULT, 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
|
781 #else |
4988 | 782 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
783 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
|
784 #endif |
4988 | 785 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
786 H5P_DEFAULT, stmp.c_str ()) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
787 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
788 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
789 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
790 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
791 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
792 } |
4988 | 793 |
794 H5Dclose (data_hid); | |
6625 | 795 |
796 octave_user_function *f = fcn.user_function_value (); | |
797 | |
7336 | 798 std::list<symbol_table::symbol_record> vars |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
799 = symbol_table::all_variables (f->scope (), 0); |
7336 | 800 |
801 size_t varlen = vars.size (); | |
6625 | 802 |
803 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
804 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
805 hid_t as_id = H5Screate (H5S_SCALAR); |
6625 | 806 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
807 if (as_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
808 { |
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
|
809 #if HAVE_HDF5_18 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
810 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
|
811 H5T_NATIVE_IDX, as_id, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
812 H5P_DEFAULT, 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
|
813 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
814 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
815 hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
816 H5T_NATIVE_IDX, as_id, 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
|
817 #endif |
6625 | 818 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
819 if (a_id >= 0) |
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 retval = (H5Awrite (a_id, H5T_NATIVE_IDX, &varlen) >= 0); |
6625 | 822 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
823 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
824 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
825 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
826 retval = false; |
6625 | 827 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
828 H5Sclose (as_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
829 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
830 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
831 retval = false; |
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
|
832 #if HAVE_HDF5_18 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
833 data_hid = H5Gcreate (group_hid, "symbol table", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
834 H5P_DEFAULT, H5P_DEFAULT, 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
|
835 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
836 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
|
837 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
838 if (data_hid < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
839 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
840 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
841 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
842 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
843 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
844 } |
6625 | 845 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
846 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
|
847 p = vars.begin (); p != vars.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
848 { |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
849 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
|
850 "", false, save_as_floats)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
851 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
852 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
853 H5Gclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
854 } |
6625 | 855 } |
856 else | |
857 { | |
858 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
|
859 |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
860 octave_function *f = function_value (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
861 std::string fpath = f ? f->fcn_file_name () : std::string (); |
6625 | 862 |
863 H5Sclose (space_hid); | |
864 hdims[0] = 1; | |
865 hdims[1] = octaveroot.length (); | |
866 space_hid = H5Screate_simple (0 , hdims, 0); | |
867 if (space_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
868 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
869 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
870 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
871 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
872 } |
6625 | 873 |
874 H5Tclose (type_hid); | |
875 type_hid = H5Tcopy (H5T_C_S1); | |
876 H5Tset_size (type_hid, octaveroot.length () + 1); | |
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
|
877 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
878 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
879 type_hid, space_hid, H5P_DEFAULT, 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
|
880 #else |
6625 | 881 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
882 type_hid, space_hid, 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
|
883 #endif |
6625 | 884 |
885 if (a_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
886 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
887 retval = (H5Awrite (a_id, type_hid, octaveroot.c_str ()) >= 0); |
6625 | 888 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
889 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
890 } |
6625 | 891 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
892 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
893 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
894 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
895 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
896 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
897 } |
6625 | 898 |
899 H5Sclose (space_hid); | |
900 hdims[0] = 1; | |
901 hdims[1] = fpath.length (); | |
902 space_hid = H5Screate_simple (0 , hdims, 0); | |
903 if (space_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
904 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
905 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
906 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
907 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
908 } |
6625 | 909 |
910 H5Tclose (type_hid); | |
911 type_hid = H5Tcopy (H5T_C_S1); | |
912 H5Tset_size (type_hid, fpath.length () + 1); | |
913 | |
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
|
914 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
915 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
916 H5P_DEFAULT, 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
|
917 #else |
6625 | 918 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, 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
|
919 #endif |
6625 | 920 |
921 if (a_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
922 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
923 retval = (H5Awrite (a_id, type_hid, fpath.c_str ()) >= 0); |
6625 | 924 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
925 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
926 } |
6625 | 927 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
928 retval = false; |
4988 | 929 } |
930 | |
931 H5Sclose (space_hid); | |
932 H5Tclose (type_hid); | |
933 H5Gclose (group_hid); | |
934 | |
935 return retval; | |
19897
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:
19731
diff
changeset
|
936 |
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:
19731
diff
changeset
|
937 #else |
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:
19731
diff
changeset
|
938 gripe_save ("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:
19731
diff
changeset
|
939 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:
19731
diff
changeset
|
940 #endif |
4988 | 941 } |
942 | |
943 bool | |
19897
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:
19731
diff
changeset
|
944 octave_fcn_handle::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4988 | 945 { |
19897
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:
19731
diff
changeset
|
946 #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:
19731
diff
changeset
|
947 |
7336 | 948 bool success = true; |
949 | |
4988 | 950 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id; |
951 hsize_t rank; | |
952 int slen; | |
953 | |
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
|
954 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
955 group_hid = H5Gopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
956 #else |
4988 | 957 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
|
958 #endif |
7336 | 959 if (group_hid < 0) |
960 return false; | |
4988 | 961 |
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
|
962 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
963 data_hid = H5Dopen (group_hid, "nm", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
964 #else |
4988 | 965 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
|
966 #endif |
4988 | 967 |
968 if (data_hid < 0) | |
969 { | |
970 H5Gclose (group_hid); | |
971 return false; | |
972 } | |
973 | |
974 type_hid = H5Dget_type (data_hid); | |
975 type_class_hid = H5Tget_class (type_hid); | |
976 | |
977 if (type_class_hid != H5T_STRING) | |
978 { | |
979 H5Tclose (type_hid); | |
980 H5Dclose (data_hid); | |
981 H5Gclose (group_hid); | |
982 return false; | |
983 } | |
984 | |
985 space_hid = H5Dget_space (data_hid); | |
986 rank = H5Sget_simple_extent_ndims (space_hid); | |
987 | |
988 if (rank != 0) | |
989 { | |
990 H5Sclose (space_hid); | |
991 H5Tclose (type_hid); | |
992 H5Dclose (data_hid); | |
993 H5Gclose (group_hid); | |
994 return false; | |
995 } | |
996 | |
997 slen = H5Tget_size (type_hid); | |
998 if (slen < 0) | |
999 { | |
1000 H5Sclose (space_hid); | |
1001 H5Tclose (type_hid); | |
1002 H5Dclose (data_hid); | |
1003 H5Gclose (group_hid); | |
1004 return false; | |
1005 } | |
1006 | |
1007 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen); | |
1008 | |
1009 // create datatype for (null-terminated) string to read into: | |
1010 st_id = H5Tcopy (H5T_C_S1); | |
1011 H5Tset_size (st_id, slen); | |
1012 | |
5760 | 1013 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, nm_tmp) < 0) |
4988 | 1014 { |
6695 | 1015 H5Tclose (st_id); |
4988 | 1016 H5Sclose (space_hid); |
1017 H5Tclose (type_hid); | |
6695 | 1018 H5Dclose (data_hid); |
4988 | 1019 H5Gclose (group_hid); |
1020 return false; | |
1021 } | |
1022 H5Tclose (st_id); | |
1023 H5Dclose (data_hid); | |
1024 nm = nm_tmp; | |
1025 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
1026 if (nm == anonymous) |
4988 | 1027 { |
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
|
1028 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1029 data_hid = H5Dopen (group_hid, "fcn", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1030 #else |
4988 | 1031 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
|
1032 #endif |
4988 | 1033 |
1034 if (data_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1035 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1036 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1037 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1038 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1039 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1040 } |
4988 | 1041 |
6695 | 1042 H5Tclose (type_hid); |
4988 | 1043 type_hid = H5Dget_type (data_hid); |
1044 type_class_hid = H5Tget_class (type_hid); | |
1045 | |
1046 if (type_class_hid != H5T_STRING) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1047 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1048 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1049 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1050 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1051 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1052 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1053 } |
4988 | 1054 |
6695 | 1055 H5Sclose (space_hid); |
4988 | 1056 space_hid = H5Dget_space (data_hid); |
1057 rank = H5Sget_simple_extent_ndims (space_hid); | |
1058 | |
1059 if (rank != 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1060 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1061 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1062 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1063 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1064 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1065 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1066 } |
4988 | 1067 |
1068 slen = H5Tget_size (type_hid); | |
1069 if (slen < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1070 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1071 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1072 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1073 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1074 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1075 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1076 } |
4988 | 1077 |
1078 OCTAVE_LOCAL_BUFFER (char, fcn_tmp, slen); | |
1079 | |
1080 // create datatype for (null-terminated) string to read into: | |
1081 st_id = H5Tcopy (H5T_C_S1); | |
1082 H5Tset_size (st_id, slen); | |
1083 | |
5760 | 1084 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, fcn_tmp) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1085 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1086 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1087 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1088 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1089 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1090 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1091 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1092 } |
6695 | 1093 H5Tclose (st_id); |
4988 | 1094 H5Dclose (data_hid); |
6625 | 1095 |
1096 octave_idx_type len = 0; | |
1097 | |
1098 // we have to pull some shenanigans here to make sure | |
1099 // HDF5 doesn't print out all sorts of error messages if we | |
1100 // call H5Aopen for a non-existing attribute | |
1101 | |
1102 H5E_auto_t err_func; | |
1103 void *err_func_data; | |
4988 | 1104 |
6625 | 1105 // turn off error reporting temporarily, but save the error |
1106 // reporting function: | |
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
|
1107 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1108 H5Eget_auto (H5E_DEFAULT, &err_func, &err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1109 H5Eset_auto (H5E_DEFAULT, 0, 0); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1110 #else |
6625 | 1111 H5Eget_auto (&err_func, &err_func_data); |
1112 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
|
1113 #endif |
6625 | 1114 |
1115 hid_t attr_id = H5Aopen_name (group_hid, "SYMBOL_TABLE"); | |
4988 | 1116 |
6625 | 1117 if (attr_id >= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1118 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1119 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
|
1120 success = false; |
6625 | 1121 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1122 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1123 } |
6625 | 1124 |
1125 // restore error reporting: | |
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
|
1126 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1127 H5Eset_auto (H5E_DEFAULT, err_func, err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1128 #else |
6625 | 1129 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
|
1130 #endif |
6625 | 1131 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1132 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
|
1133 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1134 // 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
|
1135 // 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
|
1136 |
7336 | 1137 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
|
1138 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
|
1139 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1140 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
|
1141 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1142 octave_call_stack::push (local_scope, 0); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1143 frame.add_fcn (octave_call_stack::pop); |
7336 | 1144 |
6625 | 1145 if (len > 0 && success) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1146 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1147 hsize_t num_obj = 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
|
1148 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1149 data_hid = H5Gopen (group_hid, "symbol table", 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
|
1150 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1151 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
|
1152 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1153 H5Gget_num_objs (data_hid, &num_obj); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1154 H5Gclose (data_hid); |
6625 | 1155 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1156 if (num_obj != static_cast<hsize_t>(len)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1157 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1158 error ("load: failed to load anonymous function handle"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1159 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1160 } |
6625 | 1161 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
1162 hdf5_callback_data dsub; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
1163 int current_item = 0; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
1164 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
|
1165 { |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
1166 if (H5Giterate (group_hid, "symbol table", ¤t_item, |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
1167 hdf5_read_next_data, &dsub) <= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1168 { |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
1169 error ("load: failed to load anonymous function handle"); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
1170 success = false; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
1171 break; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
1172 } |
6625 | 1173 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
1174 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
|
1175 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1176 } |
6625 | 1177 |
1178 if (success) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1179 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1180 int parse_status; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1181 octave_value anon_fcn_handle = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1182 eval_string (fcn_tmp, true, parse_status); |
6625 | 1183 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1184 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1185 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1186 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
|
1187 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1188 if (fh) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1189 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1190 fcn = fh->fcn; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1191 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1192 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
|
1193 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1194 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1195 symbol_table::cache_name (uf->scope (), nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1196 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1197 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1198 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1199 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1200 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1201 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1202 } |
6625 | 1203 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1204 frame.run (); |
4988 | 1205 } |
1206 else | |
1207 { | |
6625 | 1208 std::string octaveroot; |
1209 std::string fpath; | |
1210 | |
1211 // we have to pull some shenanigans here to make sure | |
1212 // HDF5 doesn't print out all sorts of error messages if we | |
1213 // call H5Aopen for a non-existing attribute | |
1214 | |
1215 H5E_auto_t err_func; | |
1216 void *err_func_data; | |
1217 | |
1218 // turn off error reporting temporarily, but save the error | |
1219 // reporting function: | |
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
|
1220 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1221 H5Eget_auto (H5E_DEFAULT, &err_func, &err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1222 H5Eset_auto (H5E_DEFAULT, 0, 0); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1223 #else |
6625 | 1224 H5Eget_auto (&err_func, &err_func_data); |
1225 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
|
1226 #endif |
6625 | 1227 |
1228 hid_t attr_id = H5Aopen_name (group_hid, "OCTAVEROOT"); | |
1229 if (attr_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1230 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1231 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1232 type_hid = H5Aget_type (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1233 type_class_hid = H5Tget_class (type_hid); |
6625 | 1234 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1235 if (type_class_hid != H5T_STRING) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1236 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1237 else |
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 slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1240 st_id = H5Tcopy (H5T_C_S1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1241 H5Tset_size (st_id, slen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1242 OCTAVE_LOCAL_BUFFER (char, root_tmp, slen); |
6625 | 1243 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1244 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
|
1245 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1246 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1247 octaveroot = root_tmp; |
6695 | 1248 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1249 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1250 } |
6625 | 1251 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1252 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1253 } |
6625 | 1254 |
6695 | 1255 if (success) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1256 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1257 attr_id = H5Aopen_name (group_hid, "FILE"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1258 if (attr_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1259 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1260 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1261 type_hid = H5Aget_type (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1262 type_class_hid = H5Tget_class (type_hid); |
6625 | 1263 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1264 if (type_class_hid != H5T_STRING) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1265 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1266 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1267 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1268 slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1269 st_id = H5Tcopy (H5T_C_S1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1270 H5Tset_size (st_id, slen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1271 OCTAVE_LOCAL_BUFFER (char, path_tmp, slen); |
6695 | 1272 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1273 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
|
1274 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1275 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1276 fpath = path_tmp; |
6695 | 1277 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1278 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1279 } |
6695 | 1280 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1281 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1282 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1283 } |
6625 | 1284 |
1285 // restore error reporting: | |
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
|
1286 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1287 H5Eset_auto (H5E_DEFAULT, err_func, err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1288 #else |
6625 | 1289 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
|
1290 #endif |
6625 | 1291 |
1292 success = (success ? set_fcn (octaveroot, fpath) : success); | |
4988 | 1293 } |
1294 | |
6695 | 1295 H5Tclose (type_hid); |
1296 H5Sclose (space_hid); | |
1297 H5Gclose (group_hid); | |
1298 | |
6625 | 1299 return success; |
19897
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:
19731
diff
changeset
|
1300 |
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:
19731
diff
changeset
|
1301 #else |
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:
19731
diff
changeset
|
1302 gripe_load ("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:
19731
diff
changeset
|
1303 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:
19731
diff
changeset
|
1304 #endif |
4988 | 1305 } |
6625 | 1306 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1307 /* |
6625 | 1308 %!test |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1309 %! a = 2; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1310 %! f = @(x) a + x; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1311 %! 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
|
1312 %! hm = @version; |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
1313 %! hdld = @svd; |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1314 %! hbi = @log2; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1315 %! f2 = f; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1316 %! g2 = g; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1317 %! hm2 = hm; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1318 %! hdld2 = hdld; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1319 %! hbi2 = hbi; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1320 %! modes = {"-text", "-binary"}; |
16170
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
15572
diff
changeset
|
1321 %! if (isfield (octave_config_info, "HAVE_HDF5") |
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
15572
diff
changeset
|
1322 %! && 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
|
1323 %! modes(end+1) = "-hdf5"; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1324 %! endif |
7901 | 1325 %! for i = 1:numel (modes) |
1326 %! mode = modes{i}; | |
19312
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
1327 %! nm = tempname (); |
6625 | 1328 %! unwind_protect |
15572
859c8bf6d134
Fix saved struct with function handle fails to load (bug #33857)
Max Brister <max@2bass.com>
parents:
15235
diff
changeset
|
1329 %! 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
|
1330 %! 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
|
1331 %! clear f2 g2 hm2 hdld2 hbi2 |
6625 | 1332 %! load (nm); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1333 %! assert (f (2), f2 (2)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1334 %! assert (g (2), g2 (2)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1335 %! assert (g (3), g2 (3)); |
6625 | 1336 %! unlink (nm); |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1337 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2"); |
6625 | 1338 %! unwind_protect_cleanup |
1339 %! unlink (nm); | |
1340 %! end_unwind_protect | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1341 %! endfor |
6625 | 1342 */ |
4988 | 1343 |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1344 /* |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1345 %!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
|
1346 %! if (n == 0) |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1347 %! 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
|
1348 %! else |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1349 %! 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
|
1350 %! endif |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1351 %!endfunction |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1352 %!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
|
1353 %! if (n == 0) |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1354 %! load (nm) |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1355 %! else |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1356 %! [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
|
1357 %! endif |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1358 %!endfunction |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1359 |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1360 Test for bug #35876 |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1361 %!test |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1362 %! a = 2; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1363 %! f = @(x) a + x; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1364 %! g = @(x) 2 * x; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1365 %! hm = @version; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1366 %! hdld = @svd; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1367 %! hbi = @log2; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1368 %! f2 = f; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1369 %! g2 = g; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1370 %! hm2 = hm; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1371 %! hdld2 = hdld; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1372 %! hbi2 = hbi; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1373 %! modes = {"-text", "-binary"}; |
16170
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
15572
diff
changeset
|
1374 %! if (isfield (octave_config_info, "HAVE_HDF5") |
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
15572
diff
changeset
|
1375 %! && 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
|
1376 %! modes(end+1) = "-hdf5"; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1377 %! endif |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1378 %! for i = 1:numel (modes) |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1379 %! mode = modes{i}; |
19312
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
1380 %! nm = tempname (); |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1381 %! unwind_protect |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1382 %! 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
|
1383 %! 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
|
1384 %! [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
|
1385 %! load (nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1386 %! assert (f (2), f2 (2)); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1387 %! assert (g (2), g2 (2)); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1388 %! assert (g (3), g2 (3)); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1389 %! unlink (nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1390 %! 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
|
1391 %! unwind_protect_cleanup |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1392 %! unlink (nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1393 %! end_unwind_protect |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1394 %! endfor |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1395 */ |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1396 |
4343 | 1397 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18409
diff
changeset
|
1398 octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax) |
4343 | 1399 { |
1400 print_raw (os, pr_as_read_syntax); | |
1401 newline (os); | |
1402 } | |
1403 | |
1404 void | |
1405 octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const | |
1406 { | |
4980 | 1407 bool printed = false; |
1408 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
1409 if (nm == anonymous) |
4980 | 1410 { |
1411 tree_print_code tpc (os); | |
1412 | |
4989 | 1413 // FCN is const because this member function is, so we can't |
4980 | 1414 // use it to call user_function_value, so we make a copy first. |
1415 | |
1416 octave_value ftmp = fcn; | |
1417 | |
1418 octave_user_function *f = ftmp.user_function_value (); | |
1419 | |
1420 if (f) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1421 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1422 tree_parameter_list *p = f->parameter_list (); |
4980 | 1423 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1424 os << "@("; |
4980 | 1425 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1426 if (p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1427 p->accept (tpc); |
4980 | 1428 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1429 os << ") "; |
4980 | 1430 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
11220
diff
changeset
|
1431 tpc.print_fcn_handle_body (f->body ()); |
4980 | 1432 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1433 printed = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1434 } |
4980 | 1435 } |
1436 | |
1437 if (! printed) | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
1438 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
|
1439 current_print_indent_level ()); |
4343 | 1440 } |
1441 | |
1442 octave_value | |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1443 make_fcn_handle (const std::string& nm, bool local_funcs) |
4343 | 1444 { |
1445 octave_value retval; | |
1446 | |
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
|
1447 // 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
|
1448 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1449 // 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
|
1450 // 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
|
1451 // 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
|
1452 // 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
|
1453 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1454 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
|
1455 |
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 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
|
1457 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1458 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
|
1459 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
|
1460 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
|
1461 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1462 if (nm[0] == '.') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1463 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1464 switch (nm[1]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1465 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1466 case '\'': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1467 tnm = "transpose"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1468 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
|
1469 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1470 case '+': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1471 tnm = "plus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1472 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
|
1473 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1474 case '-': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1475 tnm = "minus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1476 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
|
1477 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1478 case '*': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1479 tnm = "times"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1480 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
|
1481 |
10315
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 = "rdivide"; |
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 = "power"; |
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 = "ldivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1492 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1493 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1494 } |
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
|
1495 else if (nm[1] == '=') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1496 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1497 switch (nm[0]) |
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 case '<': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1500 tnm = "le"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1501 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
|
1502 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1503 case '=': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1504 tnm = "eq"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1505 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
|
1506 |
10315
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 tnm = "ge"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1509 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
|
1510 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1511 case '~': |
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 = "ne"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1514 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1515 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1516 } |
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
|
1517 else if (nm == "**") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1518 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
|
1519 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1520 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
|
1521 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1522 switch (nm[0]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1523 { |
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 case '!': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1526 tnm = "not"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1527 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
|
1528 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1529 case '\'': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1530 tnm = "ctranspose"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1531 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
|
1532 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1533 case '+': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1534 tnm = "plus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1535 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
|
1536 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1537 case '-': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1538 tnm = "minus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1539 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
|
1540 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1541 case '*': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1542 tnm = "mtimes"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1543 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
|
1544 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1545 case '/': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1546 tnm = "mrdivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1547 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
|
1548 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1549 case '^': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1550 tnm = "mpower"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1551 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
|
1552 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1553 case '\\': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1554 tnm = "mldivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1555 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
|
1556 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1557 case '<': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1558 tnm = "lt"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1559 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
|
1560 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1561 case '>': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1562 tnm = "gt"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1563 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
|
1564 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1565 case '&': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1566 tnm = "and"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1567 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
|
1568 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1569 case '|': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1570 tnm = "or"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1571 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1572 } |
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
|
1573 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1574 |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1575 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
|
1576 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
|
1577 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1578 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
|
1579 |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1580 // 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
|
1581 // for any class. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1582 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
|
1583 && (fptr->is_subfunction () || fptr->is_private_function () |
18441
b0aba84cf80f
Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18416
diff
changeset
|
1584 || fptr->is_class_constructor () |
b0aba84cf80f
Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18416
diff
changeset
|
1585 || fptr->is_classdef_constructor ())) |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1586 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1587 // Locally visible function. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1588 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
|
1589 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1590 else |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1591 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1592 // Globally visible (or no match yet). Query overloads. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1593 std::list<std::string> classes = load_path::overloads (tnm); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1594 bool any_match = fptr != 0 || classes.size () > 0; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1595 if (! any_match) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1596 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1597 // 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
|
1598 load_path::update (); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1599 classes = load_path::overloads (tnm); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1600 any_match = classes.size () > 0; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1601 } |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1602 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1603 if (any_match) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1604 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1605 octave_fcn_handle *fh = new octave_fcn_handle (f, tnm); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1606 retval = fh; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1607 |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1608 for (std::list<std::string>::iterator iter = classes.begin (); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1609 iter != classes.end (); iter++) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1610 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1611 std::string class_name = *iter; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1612 octave_value fmeth = symbol_table::find_method (tnm, class_name); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1613 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1614 bool is_builtin = false; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1615 for (int i = 0; i < btyp_num_types; i++) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1616 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1617 // FIXME: Too slow? Maybe binary lookup? |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1618 if (class_name == btyp_class_name[i]) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1619 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1620 is_builtin = true; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1621 fh->set_overload (static_cast<builtin_type_t> (i), fmeth); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1622 } |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1623 } |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1624 |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1625 if (! is_builtin) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1626 fh->set_overload (class_name, fmeth); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1627 } |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1628 } |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1629 else |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1630 error ("@%s: no function and no method found", tnm.c_str ()); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1631 } |
4343 | 1632 |
1633 return retval; | |
1634 } | |
1635 | |
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
|
1636 /* |
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 %!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
|
1638 %! 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
|
1639 %! ".'", "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
|
1640 %! ".+", "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
|
1641 %! ".-", "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
|
1642 %! ".*", "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
|
1643 %! "./", "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
|
1644 %! ".^", "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
|
1645 %! ".\\", "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
|
1646 %! "<=", "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
|
1647 %! "==", "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
|
1648 %! ">=", "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
|
1649 %! "~=", "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
|
1650 %! "!=", "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
|
1651 %! "**", "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
|
1652 %! "~", "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
|
1653 %! "!", "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
|
1654 %! "\'", "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
|
1655 %! "+", "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
|
1656 %! "-", "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
|
1657 %! "*", "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
|
1658 %! "/", "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
|
1659 %! "^", "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
|
1660 %! "\\", "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
|
1661 %! "<", "lt"; |
9343
70e0d3b1f26f
fix typos in previous change
John W. Eaton <jwe@octave.org>
parents:
9342
diff
changeset
|
1662 %! ">", "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
|
1663 %! "&", "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
|
1664 %! "|", "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
|
1665 %! 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
|
1666 %! 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
|
1667 %! 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
|
1668 */ |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1669 |
4933 | 1670 DEFUN (functions, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1671 "-*- texinfo -*-\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1672 @deftypefn {Built-in Function} {@var{s} =} functions (@var{fcn_handle})\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1673 Return a structure containing information about the function handle\n\ |
4933 | 1674 @var{fcn_handle}.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1675 \n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19897
diff
changeset
|
1676 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
|
1677 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1678 @table @asis\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1679 @item function\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1680 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
|
1681 actual function definition.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1682 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1683 @item type\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1684 Type of the function.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1685 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1686 @table @asis\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1687 @item anonymous\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1688 The function is anonymous.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1689 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1690 @item private\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1691 The function is private.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1692 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1693 @item overloaded\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1694 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
|
1695 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1696 @item simple\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1697 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
|
1698 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1699 @item subfunction\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1700 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
|
1701 @end table\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1702 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1703 @item file\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1704 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
|
1705 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
|
1706 @end table\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1707 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1708 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
|
1709 fields.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1710 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1711 @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
|
1712 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
|
1713 particular output.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1714 \n\ |
4933 | 1715 @end deftypefn") |
4343 | 1716 { |
1717 octave_value retval; | |
1718 | |
4933 | 1719 if (args.length () == 1) |
4343 | 1720 { |
4933 | 1721 octave_fcn_handle *fh = args(0).fcn_handle_value (); |
4343 | 1722 |
1723 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1724 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1725 octave_function *fcn = fh ? fh->function_value () : 0; |
4343 | 1726 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1727 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1728 { |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1729 octave_scalar_map m; |
4649 | 1730 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1731 std::string fh_nm = fh->fcn_name (); |
4933 | 1732 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1733 if (fh_nm == octave_fcn_handle::anonymous) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1734 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1735 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1736 fh->print_raw (buf); |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1737 m.setfield ("function", buf.str ()); |
6625 | 1738 |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1739 m.setfield ("type", "anonymous"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1740 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1741 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1742 { |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1743 m.setfield ("function", fh_nm); |
4343 | 1744 |
11461
2b8531a6a3c9
Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents:
11223
diff
changeset
|
1745 if (fcn->is_subfunction ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1746 { |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1747 m.setfield ("type", "subfunction"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1748 Cell parentage (dim_vector (1, 2)); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1749 parentage.elem (0) = fh_nm; |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1750 parentage.elem (1) = fcn->parent_fcn_name (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1751 m.setfield ("parentage", octave_value (parentage)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1752 } |
9509
c5330ef7aecd
fix handles to private functions, simplify out-of-date checks in symtab
Jaroslav Hajek <highegg@gmail.com>
parents:
9466
diff
changeset
|
1753 else if (fcn->is_private_function ()) |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1754 m.setfield ("type", "private"); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1755 else if (fh->is_overloaded ()) |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1756 m.setfield ("type", "overloaded"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1757 else |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1758 m.setfield ("type", "simple"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1759 } |
4933 | 1760 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1761 std::string nm = fcn->fcn_file_name (); |
4343 | 1762 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1763 if (fh_nm == octave_fcn_handle::anonymous) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1764 { |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1765 m.setfield ("file", nm); |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1766 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1767 octave_user_function *fu = fh->user_function_value (); |
6625 | 1768 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1769 std::list<symbol_table::symbol_record> vars |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1770 = symbol_table::all_variables (fu->scope (), 0); |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1771 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1772 size_t varlen = vars.size (); |
6625 | 1773 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1774 if (varlen > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1775 { |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1776 octave_scalar_map ws; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1777 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
|
1778 p = vars.begin (); p != vars.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1779 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1780 ws.assign (p->name (), p->varval (0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1781 } |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1782 |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1783 m.setfield ("workspace", ws); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1784 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1785 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1786 else if (fcn->is_user_function () || fcn->is_user_script ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1787 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1788 octave_function *fu = fh->function_value (); |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1789 m.setfield ("file", fu->fcn_file_name ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1790 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1791 else |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1792 m.setfield ("file", ""); |
4933 | 1793 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1794 retval = m; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1795 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1796 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1797 error ("functions: FCN_HANDLE is not a valid function handle object"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1798 } |
4343 | 1799 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1800 error ("functions: FCN_HANDLE argument must be a function handle object"); |
4343 | 1801 } |
1802 else | |
5823 | 1803 print_usage (); |
4343 | 1804 |
1805 return retval; | |
1806 } | |
1807 | |
4933 | 1808 DEFUN (func2str, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1809 "-*- texinfo -*-\n\ |
4933 | 1810 @deftypefn {Built-in Function} {} func2str (@var{fcn_handle})\n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19897
diff
changeset
|
1811 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:
19897
diff
changeset
|
1812 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
|
1813 @seealso{str2func, functions}\n\ |
4933 | 1814 @end deftypefn") |
4343 | 1815 { |
1816 octave_value retval; | |
1817 | |
4933 | 1818 if (args.length () == 1) |
4930 | 1819 { |
4933 | 1820 octave_fcn_handle *fh = args(0).fcn_handle_value (); |
4930 | 1821 |
4933 | 1822 if (! error_state && fh) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1823 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1824 std::string fh_nm = fh->fcn_name (); |
6416 | 1825 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1826 if (fh_nm == octave_fcn_handle::anonymous) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1827 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1828 std::ostringstream buf; |
6416 | 1829 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1830 fh->print_raw (buf); |
6416 | 1831 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1832 retval = buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1833 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1834 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1835 retval = fh_nm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1836 } |
4343 | 1837 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1838 error ("func2str: FCN_HANDLE must be a valid function handle"); |
4343 | 1839 } |
1840 else | |
5823 | 1841 print_usage (); |
4343 | 1842 |
1843 return retval; | |
1844 } | |
1845 | |
4933 | 1846 DEFUN (str2func, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1847 "-*- texinfo -*-\n\ |
10840 | 1848 @deftypefn {Built-in Function} {} str2func (@var{fcn_name})\n\ |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1849 @deftypefnx {Built-in Function} {} str2func (@var{fcn_name}, \"global\")\n\ |
4933 | 1850 Return a function handle constructed from the string @var{fcn_name}.\n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19897
diff
changeset
|
1851 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
1852 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
|
1853 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
|
1854 @seealso{func2str, inline}\n\ |
4933 | 1855 @end deftypefn") |
4343 | 1856 { |
1857 octave_value retval; | |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1858 int nargin = args.length (); |
4343 | 1859 |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1860 if (nargin == 1 || nargin == 2) |
4343 | 1861 { |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19312
diff
changeset
|
1862 if (args(0).is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19312
diff
changeset
|
1863 { |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19312
diff
changeset
|
1864 std::string nm = args(0).string_value (); |
20470
82712ed1be68
strfunc: Issue error when given anonymous function (partial fix bug #45682).
Rik <rik@octave.org>
parents:
20469
diff
changeset
|
1865 if (nm[0] == '@') |
82712ed1be68
strfunc: Issue error when given anonymous function (partial fix bug #45682).
Rik <rik@octave.org>
parents:
20469
diff
changeset
|
1866 { |
20543
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1867 int parse_status; |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1868 octave_value anon_fcn_handle = |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1869 eval_string (nm, true, parse_status); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1870 |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1871 if (parse_status == 0) |
20566
dcfbf4c1c3c8
eliminate trailing whitespace and tabs from sources
John W. Eaton <jwe@octave.org>
parents:
20543
diff
changeset
|
1872 retval = anon_fcn_handle; |
20470
82712ed1be68
strfunc: Issue error when given anonymous function (partial fix bug #45682).
Rik <rik@octave.org>
parents:
20469
diff
changeset
|
1873 } |
20543
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1874 else |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1875 retval = make_fcn_handle (nm, nargin != 2); |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19312
diff
changeset
|
1876 } |
4343 | 1877 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1878 error ("str2func: FCN_NAME must be a string"); |
4343 | 1879 } |
1880 else | |
5823 | 1881 print_usage (); |
4343 | 1882 |
1883 return retval; | |
1884 } | |
1885 | |
1886 /* | |
20543
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1887 %!test |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1888 %! f = str2func ("<"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1889 %! assert (class (f), "function_handle"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1890 %! assert (func2str (f), "lt"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1891 %! assert (f (1, 2), true); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1892 %! assert (f (2, 1), false); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1893 |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1894 %!test |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1895 %! f = str2func ("@(x) sin (x)"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1896 %! assert (func2str (f), "@(x) sin (x)"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1897 %! assert (f (0:3), sin (0:3)); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1898 |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1899 %!error <FCN_NAME must be a string> str2func ({"sin"}) |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1900 */ |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1901 |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
1902 /* |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
1903 %!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
|
1904 %! if (nargin < 3) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1905 %! n = 0; |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1906 %! endif |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1907 %! if (n > 2) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1908 %! y = f (x); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1909 %! else |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1910 %! n++; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1911 %! 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
|
1912 %! endif |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
1913 %!endfunction |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
1914 %! |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
1915 %!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
|
1916 */ |
10960 | 1917 |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1918 DEFUN (is_function_handle, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1919 "-*- texinfo -*-\n\ |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1920 @deftypefn {Built-in Function} {} is_function_handle (@var{x})\n\ |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1921 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
|
1922 @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
|
1923 @end deftypefn") |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1924 { |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1925 octave_value retval; |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1926 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1927 int nargin = args.length (); |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1928 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1929 if (nargin == 1) |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1930 retval = args(0).is_function_handle (); |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1931 else |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1932 print_usage (); |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1933 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1934 return retval; |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1935 } |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1936 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1937 /* |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1938 %!shared fh |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1939 %! fh = @(x) x; |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1940 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1941 %!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
|
1942 %!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
|
1943 %!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
|
1944 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1945 %!error is_function_handle () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1946 %!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
|
1947 */ |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1948 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1949 octave_fcn_binder::octave_fcn_binder (const octave_value& f, |
10960 | 1950 const octave_value& root, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1951 const octave_value_list& templ, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1952 const std::vector<int>& mask, |
10960 | 1953 int exp_nargin) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1954 : 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
|
1955 arg_mask (mask), expected_nargin (exp_nargin) |
10960 | 1956 { |
1957 } | |
1958 | |
1959 octave_fcn_handle * | |
1960 octave_fcn_binder::maybe_binder (const octave_value& f) | |
1961 { | |
1962 octave_fcn_handle *retval = 0; | |
1963 | |
1964 octave_user_function *usr_fcn = f.user_function_value (false); | |
1965 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
|
1966 |
17898
8c33abdd2f9a
maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents:
17896
diff
changeset
|
1967 tree_statement_list *cmd_list = 0; |
8c33abdd2f9a
maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents:
17896
diff
changeset
|
1968 tree_expression *body_expr = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1969 |
17896
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1970 if (usr_fcn) |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1971 { |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1972 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
|
1973 if (cmd_list) |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1974 { |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1975 // 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
|
1976 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
|
1977 ? 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
|
1978 } |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1979 } |
10960 | 1980 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1981 if (body_expr && body_expr->is_index_expression () |
10960 | 1982 && ! (param_list && param_list->takes_varargs ())) |
1983 { | |
1984 // It's an index expression. | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1985 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
|
1986 (body_expr); |
10960 | 1987 tree_expression *head_expr = idx_expr->expression (); |
1988 std::list<tree_argument_list *> arg_lists = idx_expr->arg_lists (); | |
1989 std::string type_tags = idx_expr->type_tags (); | |
1990 | |
1991 if (type_tags.length () == 1 && type_tags[0] == '(' | |
1992 && head_expr->is_identifier ()) | |
1993 { | |
1994 assert (arg_lists.size () == 1); | |
1995 | |
1996 // 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
|
1997 tree_identifier *head_id = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1998 dynamic_cast<tree_identifier *> (head_expr); |
10960 | 1999 tree_argument_list *arg_list = arg_lists.front (); |
2000 | |
2001 // Build a map of input params to their position. | |
2002 std::map<std::string, int> arginmap; | |
2003 int npar = 0; | |
2004 | |
2005 if (param_list) | |
2006 { | |
2007 for (tree_parameter_list::iterator it = param_list->begin (); | |
2008 it != param_list->end (); ++it, ++npar) | |
2009 { | |
2010 tree_decl_elt *elt = *it; | |
2011 tree_identifier *id = elt ? elt->ident () : 0; | |
2012 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
|
2013 arginmap[id->name ()] = npar; |
10960 | 2014 } |
2015 } | |
2016 | |
2017 if (arg_list && arg_list->length () > 0) | |
2018 { | |
2019 bool bad = false; | |
2020 int nargs = arg_list->length (); | |
2021 octave_value_list arg_template (nargs); | |
2022 std::vector<int> arg_mask (nargs); | |
2023 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2024 // 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
|
2025 // or a defined identifier. |
10960 | 2026 int iarg = 0; |
2027 for (tree_argument_list::iterator it = arg_list->begin (); | |
2028 it != arg_list->end (); ++it, ++iarg) | |
2029 { | |
2030 tree_expression *elt = *it; | |
2031 if (elt && elt->is_constant ()) | |
2032 { | |
2033 arg_template(iarg) = elt->rvalue1 (); | |
2034 arg_mask[iarg] = -1; | |
2035 } | |
2036 else if (elt && elt->is_identifier ()) | |
2037 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2038 tree_identifier *elt_id = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2039 dynamic_cast<tree_identifier *> (elt); |
10960 | 2040 if (arginmap.find (elt_id->name ()) != arginmap.end ()) |
2041 { | |
2042 arg_mask[iarg] = arginmap[elt_id->name ()]; | |
2043 } | |
2044 else if (elt_id->is_defined ()) | |
2045 { | |
2046 arg_template(iarg) = elt_id->rvalue1 (); | |
2047 arg_mask[iarg] = -1; | |
2048 } | |
2049 else | |
2050 { | |
2051 bad = true; | |
2052 break; | |
2053 } | |
2054 } | |
2055 else | |
2056 { | |
2057 bad = true; | |
2058 break; | |
2059 } | |
2060 } | |
2061 | |
2062 octave_value root_val; | |
2063 | |
2064 if (! bad) | |
2065 { | |
2066 // If the head is a value, use it as root. | |
2067 if (head_id->is_defined ()) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2068 root_val = head_id->rvalue1 (); |
10960 | 2069 else |
2070 { | |
2071 // It's a name. | |
2072 std::string head_name = head_id->name (); | |
2073 // Function handles can't handle legacy dispatch, so | |
2074 // we make sure it's not defined. | |
2075 if (symbol_table::get_dispatch (head_name).size () > 0) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2076 bad = true; |
10960 | 2077 else |
2078 { | |
2079 // Simulate try/catch. | |
2080 unwind_protect frame; | |
11029
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10961
diff
changeset
|
2081 interpreter_try (frame); |
10960 | 2082 |
20569
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20566
diff
changeset
|
2083 bool execution_error = false; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20566
diff
changeset
|
2084 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20566
diff
changeset
|
2085 try |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20566
diff
changeset
|
2086 { |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20566
diff
changeset
|
2087 root_val = make_fcn_handle (head_name); |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20566
diff
changeset
|
2088 } |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20566
diff
changeset
|
2089 catch (const octave_execution_exception&) |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20566
diff
changeset
|
2090 { |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20566
diff
changeset
|
2091 execution_error = true; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20566
diff
changeset
|
2092 } |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20566
diff
changeset
|
2093 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20566
diff
changeset
|
2094 if (execution_error) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2095 bad = true; |
10960 | 2096 } |
2097 } | |
2098 } | |
2099 | |
2100 if (! bad) | |
2101 { | |
10961 | 2102 // Stash proper name tags. |
2103 std::list<string_vector> arg_names = idx_expr->arg_names (); | |
2104 assert (arg_names.size () == 1); | |
2105 arg_template.stash_name_tags (arg_names.front ()); | |
2106 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
2107 retval = new octave_fcn_binder (f, root_val, arg_template, |
10960 | 2108 arg_mask, npar); |
2109 } | |
2110 } | |
2111 } | |
2112 } | |
2113 | |
2114 if (! retval) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2115 retval = new octave_fcn_handle (f, octave_fcn_handle::anonymous); |
10960 | 2116 |
2117 return retval; | |
2118 } | |
2119 | |
2120 octave_value_list | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
2121 octave_fcn_binder::do_multi_index_op (int nargout, |
10960 | 2122 const octave_value_list& args) |
2123 { | |
2124 return do_multi_index_op (nargout, args, 0); | |
2125 } | |
2126 | |
2127 octave_value_list | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
2128 octave_fcn_binder::do_multi_index_op (int nargout, |
10960 | 2129 const octave_value_list& args, |
2130 const std::list<octave_lvalue>* lvalue_list) | |
2131 { | |
2132 octave_value_list retval; | |
2133 | |
2134 if (args.length () == expected_nargin) | |
2135 { | |
2136 for (int i = 0; i < arg_template.length (); i++) | |
2137 { | |
2138 int j = arg_mask[i]; | |
2139 if (j >= 0) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2140 arg_template(i) = args(j); // May force a copy... |
10960 | 2141 } |
2142 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2143 // 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
|
2144 // the following call even if we happen to get back here. |
10961 | 2145 octave_value_list tmp (arg_template); |
2146 retval = root_handle.do_multi_index_op (nargout, tmp, lvalue_list); | |
10960 | 2147 } |
2148 else | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2149 retval = octave_fcn_handle::do_multi_index_op (nargout, args, lvalue_list); |
10960 | 2150 |
2151 return retval; | |
2152 } | |
13696
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2153 |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2154 /* |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
2155 %!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
|
2156 %! r = g(i); |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2157 %!endfunction |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2158 %!test |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2159 %! 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
|
2160 %! 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
|
2161 */ |