Mercurial > octave
annotate libinterp/corefcn/mex.cc @ 27474:3fec8e9fa2aa
make recover_from_exception a member function
* interpreter.h, interpreter.cc (interpreter::recover_from_exception):
Now a member function. Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 04 Oct 2019 16:40:30 -0400 |
parents | fd32c1a9b1bd |
children | b442ec6dda5c |
rev | line source |
---|---|
7016 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
26159
diff
changeset
|
3 Copyright (C) 2006-2019 John W. Eaton |
7016 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24361
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22599
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24361
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22599
diff
changeset
|
10 (at your option) any later version. |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22599
diff
changeset
|
11 |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22599
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22599
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22599
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22599
diff
changeset
|
15 GNU General Public License for more details. |
7016 | 16 |
17 You should have received a copy of the GNU General Public License | |
18 along with Octave; see the file COPYING. If not, see | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24361
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
7016 | 20 |
21 */ | |
22 | |
22003
2d3972b802ff
use consistent style for including config.h in source files
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
2d3972b802ff
use consistent style for including config.h in source files
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
24 # include "config.h" |
2d3972b802ff
use consistent style for including config.h in source files
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
25 #endif |
5864 | 26 |
5900 | 27 #include <cstdarg> |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
28 #include <cstdlib> |
5900 | 29 #include <cstring> |
30 #include <cctype> | |
31 | |
23455
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
32 #include <limits> |
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
33 #include <map> |
5864 | 34 #include <set> |
23455
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
35 #include <string> |
5900 | 36 |
37 #include "f77-fcn.h" | |
38 #include "lo-ieee.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7901
diff
changeset
|
39 #include "oct-locbuf.h" |
23455
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
40 #include "quit.h" |
5900 | 41 |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15096
diff
changeset
|
42 #include "Cell.h" |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
43 #include "error.h" |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23499
diff
changeset
|
44 #include "interpreter-private.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22091
diff
changeset
|
45 #include "interpreter.h" |
5900 | 46 // mxArray must be declared as a class before including mexproto.h. |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15096
diff
changeset
|
47 #include "mxarray.h" |
5900 | 48 #include "mexproto.h" |
49 #include "oct-map.h" | |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20771
diff
changeset
|
50 #include "ovl.h" |
5900 | 51 #include "ov.h" |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
52 #include "ov-classdef.h" |
6068 | 53 #include "ov-mex-fcn.h" |
5900 | 54 #include "ov-usr-fcn.h" |
5864 | 55 #include "pager.h" |
56 #include "parse.h" | |
5900 | 57 #include "unwind-prot.h" |
58 #include "utils.h" | |
5864 | 59 #include "variables.h" |
6595 | 60 #include "graphics.h" |
5900 | 61 |
62 // #define DEBUG 1 | |
63 | |
5905 | 64 static void |
65 xfree (void *ptr) | |
66 { | |
67 ::free (ptr); | |
68 } | |
69 | |
6806 | 70 static mwSize |
71 max_str_len (mwSize m, const char **str) | |
5900 | 72 { |
73 int max_len = 0; | |
74 | |
6806 | 75 for (mwSize i = 0; i < m; i++) |
5900 | 76 { |
6806 | 77 mwSize tmp = strlen (str[i]); |
5900 | 78 |
79 if (tmp > max_len) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
80 max_len = tmp; |
5900 | 81 } |
82 | |
83 return max_len; | |
84 } | |
85 | |
86 static int | |
87 valid_key (const char *key) | |
88 { | |
89 int retval = 0; | |
90 | |
91 int nel = strlen (key); | |
92 | |
93 if (nel > 0) | |
94 { | |
95 if (isalpha (key[0])) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
96 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
97 for (int i = 1; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
98 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
99 if (! (isalnum (key[i]) || key[i] == '_')) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21151
diff
changeset
|
100 return retval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
101 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
102 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
103 retval = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
104 } |
5900 | 105 } |
106 | |
107 return retval; | |
108 } | |
109 | |
110 // ------------------------------------------------------------------ | |
111 | |
7357 | 112 static mwIndex |
113 calc_single_subscript_internal (mwSize ndims, const mwSize *dims, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
114 mwSize nsubs, const mwIndex *subs) |
7357 | 115 { |
116 mwIndex retval = 0; | |
117 | |
118 switch (nsubs) | |
119 { | |
120 case 0: | |
121 break; | |
122 | |
123 case 1: | |
124 retval = subs[0]; | |
125 break; | |
126 | |
127 default: | |
128 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
129 // Both nsubs and ndims should be at least 2 here. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
130 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
131 mwSize n = (nsubs <= ndims ? nsubs : ndims); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
132 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
133 retval = subs[--n]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
134 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
135 while (--n >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
136 retval = dims[n] * retval + subs[n]; |
7357 | 137 } |
138 break; | |
139 } | |
140 | |
141 return retval; | |
142 } | |
143 | |
5900 | 144 // The object that handles values pass to MEX files from Octave. Some |
145 // methods in this class may set mutate_flag to TRUE to tell the | |
146 // mxArray class to convert to the Matlab-style representation and | |
147 // then invoke the method on that object instead (for example, getting | |
148 // a pointer to real or imaginary data from a complex object requires | |
149 // a mutation but getting a pointer to real data from a real object | |
150 // does not). Changing the representation causes a copy so we try to | |
151 // avoid it unless it is really necessary. Once the conversion | |
152 // happens, we delete this representation, so the conversion can only | |
153 // happen once per call to a MEX file. | |
154 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
155 static inline void * maybe_mark_foreign (void *ptr); |
7179 | 156 |
5900 | 157 class mxArray_octave_value : public mxArray_base |
158 { | |
159 public: | |
160 | |
161 mxArray_octave_value (const octave_value& ov) | |
162 : mxArray_base (), val (ov), mutate_flag (false), | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
163 id (mxUNKNOWN_CLASS), class_name (nullptr), ndims (-1), dims (nullptr) { } |
5900 | 164 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
165 // No assignment! FIXME: should this be implemented? Note that we |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
166 // do have a copy constructor. |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
167 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
168 mxArray_octave_value& operator = (const mxArray_octave_value&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
169 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
170 mxArray_base * dup (void) const { return new mxArray_octave_value (*this); } |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
171 |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
172 mxArray * as_mxArray (void) const |
12331
f39436e14734
mex.cc (mxArray_octave_value::dup): if value can't be converted to mxArray object, create a clone of the mxArray_octave_value container
John W. Eaton <jwe@octave.org>
parents:
12123
diff
changeset
|
173 { |
17810
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
174 mxArray *retval = val.as_mxArray (); |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
175 |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
176 // RETVAL is assumed to be an mxArray_matlab object. Should we |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
177 // assert that condition here? |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
178 |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
179 if (retval) |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
180 { |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
181 // Preserve cached values of class name and dimensions in case |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
182 // they will be used after we mutate. |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
183 |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
184 // set_class_name will handle deleting class name that comes |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
185 // from as_mxArray conversion function. |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
186 |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
187 if (class_name) |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
188 { |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
189 retval->set_class_name (class_name); |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
190 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
191 class_name = nullptr; |
17810
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
192 } |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
193 |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
194 if (dims) |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
195 { |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
196 mwSize *xdims = retval->get_dimensions (); |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
197 |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
198 mxFree (xdims); |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
199 |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
200 retval->set_dimensions (dims, ndims); |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
201 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
202 dims = nullptr; |
17810
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
203 } |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
204 } |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
205 |
6da521da1c70
preserve cached mxArray_octave_value data while it's still in use (bug #40429)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
206 return retval; |
12331
f39436e14734
mex.cc (mxArray_octave_value::dup): if value can't be converted to mxArray object, create a clone of the mxArray_octave_value container
John W. Eaton <jwe@octave.org>
parents:
12123
diff
changeset
|
207 } |
5900 | 208 |
209 ~mxArray_octave_value (void) | |
210 { | |
211 mxFree (class_name); | |
212 mxFree (dims); | |
213 } | |
214 | |
215 bool is_octave_value (void) const { return true; } | |
216 | |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23553
diff
changeset
|
217 int iscell (void) const { return val.iscell (); } |
5900 | 218 |
219 int is_char (void) const { return val.is_string (); } | |
220 | |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23579
diff
changeset
|
221 int is_complex (void) const { return val.iscomplex (); } |
5900 | 222 |
223 int is_double (void) const { return val.is_double_type (); } | |
224 | |
11100
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
225 int is_function_handle (void) const { return val.is_function_handle (); } |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
226 |
5900 | 227 int is_int16 (void) const { return val.is_int16_type (); } |
228 | |
229 int is_int32 (void) const { return val.is_int32_type (); } | |
230 | |
231 int is_int64 (void) const { return val.is_int64_type (); } | |
232 | |
233 int is_int8 (void) const { return val.is_int8_type (); } | |
234 | |
23579
c20a0fa91c0c
maint: Deprecate is_bool_type and replace with islogical.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
235 int is_logical (void) const { return val.islogical (); } |
5900 | 236 |
23586
f6c5db0a02e7
maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents:
23584
diff
changeset
|
237 int is_numeric (void) const { return val.isnumeric (); } |
5900 | 238 |
239 int is_single (void) const { return val.is_single_type (); } | |
240 | |
23583
b7747a2c88b2
maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
241 int is_sparse (void) const { return val.issparse (); } |
5900 | 242 |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23583
diff
changeset
|
243 int is_struct (void) const { return val.isstruct (); } |
5900 | 244 |
245 int is_uint16 (void) const { return val.is_uint16_type (); } | |
246 | |
6069 | 247 int is_uint32 (void) const { return val.is_uint32_type (); } |
248 | |
249 int is_uint64 (void) const { return val.is_uint64_type (); } | |
250 | |
251 int is_uint8 (void) const { return val.is_uint8_type (); } | |
5900 | 252 |
253 int is_range (void) const { return val.is_range (); } | |
254 | |
23582
0cc2011d800e
maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents:
23581
diff
changeset
|
255 int isreal (void) const { return val.isreal (); } |
5900 | 256 |
257 int is_logical_scalar_true (void) const | |
258 { | |
259 return (is_logical_scalar () && val.is_true ()); | |
260 } | |
261 | |
6686 | 262 mwSize get_m (void) const { return val.rows (); } |
263 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
264 mwSize get_n (void) const |
6187 | 265 { |
6686 | 266 mwSize n = 1; |
6187 | 267 |
268 // Force dims and ndims to be cached. | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14840
diff
changeset
|
269 get_dimensions (); |
6187 | 270 |
6686 | 271 for (mwIndex i = ndims - 1; i > 0; i--) |
6187 | 272 n *= dims[i]; |
273 | |
274 return n; | |
275 } | |
5900 | 276 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
277 mwSize * get_dimensions (void) const |
5900 | 278 { |
279 if (! dims) | |
280 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
281 ndims = val.ndims (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
282 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
283 dims = static_cast<mwSize *> (mxArray::malloc (ndims |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
284 * sizeof (mwSize))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
285 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
286 dim_vector dv = val.dims (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
287 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
288 for (mwIndex i = 0; i < ndims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
289 dims[i] = dv(i); |
5900 | 290 } |
291 | |
292 return dims; | |
293 } | |
294 | |
6686 | 295 mwSize get_number_of_dimensions (void) const |
5900 | 296 { |
6332 | 297 // Force dims and ndims to be cached. |
298 get_dimensions (); | |
5900 | 299 |
300 return ndims; | |
301 } | |
302 | |
6686 | 303 void set_m (mwSize /*m*/) { request_mutation (); } |
304 | |
305 void set_n (mwSize /*n*/) { request_mutation (); } | |
306 | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
307 int set_dimensions (mwSize * /*dims_arg*/, mwSize /*ndims_arg*/) |
5900 | 308 { |
6400 | 309 request_mutation (); |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
310 |
22599
51b395d24782
maint: strip tabs and trailing whitespace from C++ sources.
John W. Eaton <jwe@octave.org>
parents:
22480
diff
changeset
|
311 return 0; |
5900 | 312 } |
313 | |
6686 | 314 mwSize get_number_of_elements (void) const { return val.numel (); } |
5900 | 315 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
316 int isempty (void) const { return val.isempty (); } |
5900 | 317 |
22462
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
318 bool is_scalar (void) const |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
319 { |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
320 // Force dims and ndims to be cached. |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
321 get_dimensions (); |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
322 |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
323 return ndims == 2 && dims[0] == 1 && dims[1] == 1; |
22599
51b395d24782
maint: strip tabs and trailing whitespace from C++ sources.
John W. Eaton <jwe@octave.org>
parents:
22480
diff
changeset
|
324 } |
22462
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
325 |
5900 | 326 mxClassID get_class_id (void) const |
327 { | |
328 id = mxUNKNOWN_CLASS; | |
329 | |
330 std::string cn = val.class_name (); | |
331 | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
332 if (cn == "double") |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
333 id = mxDOUBLE_CLASS; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
334 else if (cn == "single") |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
335 id = mxSINGLE_CLASS; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
336 else if (cn == "char") |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
337 id = mxCHAR_CLASS; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
338 else if (cn == "logical") |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
339 id = mxLOGICAL_CLASS; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
340 else if (cn == "cell") |
5900 | 341 id = mxCELL_CLASS; |
342 else if (cn == "struct") | |
343 id = mxSTRUCT_CLASS; | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
344 else if (cn == "function_handle") |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
345 id = mxFUNCTION_CLASS; |
5900 | 346 else if (cn == "int8") |
347 id = mxINT8_CLASS; | |
348 else if (cn == "uint8") | |
349 id = mxUINT8_CLASS; | |
350 else if (cn == "int16") | |
351 id = mxINT16_CLASS; | |
352 else if (cn == "uint16") | |
353 id = mxUINT16_CLASS; | |
354 else if (cn == "int32") | |
355 id = mxINT32_CLASS; | |
356 else if (cn == "uint32") | |
357 id = mxUINT32_CLASS; | |
358 else if (cn == "int64") | |
359 id = mxINT64_CLASS; | |
360 else if (cn == "uint64") | |
361 id = mxUINT64_CLASS; | |
362 | |
363 return id; | |
364 } | |
365 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
366 const char * get_class_name (void) const |
5900 | 367 { |
368 if (! class_name) | |
369 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
370 std::string s = val.class_name (); |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
371 class_name = mxArray::strsave (s.c_str ()); |
5900 | 372 } |
373 | |
374 return class_name; | |
375 } | |
376 | |
377 // Not allowed. | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
378 void set_class_name (const char * /*name_arg*/) { request_mutation (); } |
5900 | 379 |
23893
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
380 mxArray * get_property (mwIndex idx, const char *pname) const |
23884
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
381 { |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
382 mxArray *retval = nullptr; |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
383 |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
384 if (val.is_classdef_object ()) |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
385 { |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
386 octave_classdef *ov_cdef = val.classdef_object_value (); |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
387 |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
388 if (ov_cdef) |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
389 { |
23893
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
390 octave_value pval = ov_cdef->get_property (idx, pname); |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
391 |
23898
a490e729f2f2
correctly return NULL for unknown properties in mxGetProperty (bug #51725)
John W. Eaton <jwe@octave.org>
parents:
23893
diff
changeset
|
392 if (pval.is_defined()) |
23893
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
393 retval = new mxArray (pval); |
23884
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
394 } |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
395 } |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
396 |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
397 return retval; |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
398 } |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
399 |
23893
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
400 void set_property (mwIndex idx, const char *pname, const mxArray *pval) |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
401 { |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
402 if (val.is_classdef_object ()) |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
403 { |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
404 octave_classdef *ov_cdef = val.classdef_object_value (); |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
405 |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
406 if (ov_cdef) |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
407 ov_cdef->set_property (idx, pname, pval->as_octave_value ()); |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
408 } |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
409 else |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
410 err_invalid_type (); |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
411 } |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
412 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
413 mxArray * get_cell (mwIndex /*idx*/) const |
5900 | 414 { |
415 request_mutation (); | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
416 return nullptr; |
5900 | 417 } |
418 | |
419 // Not allowed. | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
420 void set_cell (mwIndex /*idx*/, mxArray * /*val*/) { request_mutation (); } |
5900 | 421 |
22480
9263b2889003
Change mxGetScalar to return the first non-zero element of sparse array.
Rik <rik@octave.org>
parents:
22471
diff
changeset
|
422 double get_scalar (void) const |
9263b2889003
Change mxGetScalar to return the first non-zero element of sparse array.
Rik <rik@octave.org>
parents:
22471
diff
changeset
|
423 { |
23583
b7747a2c88b2
maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
424 if (val.issparse ()) |
22480
9263b2889003
Change mxGetScalar to return the first non-zero element of sparse array.
Rik <rik@octave.org>
parents:
22471
diff
changeset
|
425 { |
22599
51b395d24782
maint: strip tabs and trailing whitespace from C++ sources.
John W. Eaton <jwe@octave.org>
parents:
22480
diff
changeset
|
426 // For sparse arrays, return the first non-zero value. |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
427 void *data = val.mex_get_data (); |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
428 if (data == nullptr) |
22480
9263b2889003
Change mxGetScalar to return the first non-zero element of sparse array.
Rik <rik@octave.org>
parents:
22471
diff
changeset
|
429 return 0.0; |
9263b2889003
Change mxGetScalar to return the first non-zero element of sparse array.
Rik <rik@octave.org>
parents:
22471
diff
changeset
|
430 |
23579
c20a0fa91c0c
maint: Deprecate is_bool_type and replace with islogical.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
431 if (val.islogical ()) |
22480
9263b2889003
Change mxGetScalar to return the first non-zero element of sparse array.
Rik <rik@octave.org>
parents:
22471
diff
changeset
|
432 return *static_cast<bool *> (data); |
23582
0cc2011d800e
maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents:
23581
diff
changeset
|
433 else if (val.isreal ()) |
22480
9263b2889003
Change mxGetScalar to return the first non-zero element of sparse array.
Rik <rik@octave.org>
parents:
22471
diff
changeset
|
434 return *static_cast<double *> (data); |
9263b2889003
Change mxGetScalar to return the first non-zero element of sparse array.
Rik <rik@octave.org>
parents:
22471
diff
changeset
|
435 else // Complex type, only return real part |
9263b2889003
Change mxGetScalar to return the first non-zero element of sparse array.
Rik <rik@octave.org>
parents:
22471
diff
changeset
|
436 return *static_cast<double *> (data); |
9263b2889003
Change mxGetScalar to return the first non-zero element of sparse array.
Rik <rik@octave.org>
parents:
22471
diff
changeset
|
437 } |
9263b2889003
Change mxGetScalar to return the first non-zero element of sparse array.
Rik <rik@octave.org>
parents:
22471
diff
changeset
|
438 else |
9263b2889003
Change mxGetScalar to return the first non-zero element of sparse array.
Rik <rik@octave.org>
parents:
22471
diff
changeset
|
439 return val.scalar_value (true); |
9263b2889003
Change mxGetScalar to return the first non-zero element of sparse array.
Rik <rik@octave.org>
parents:
22471
diff
changeset
|
440 } |
6332 | 441 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
442 void * get_data (void) const |
5900 | 443 { |
9358
d4b1314a7c31
mex.cc (mxArray_octave_value::get_data): avoid enumerating types that can be handled as foreign
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
444 void *retval = val.mex_get_data (); |
d4b1314a7c31
mex.cc (mxArray_octave_value::get_data): avoid enumerating types that can be handled as foreign
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
445 |
d4b1314a7c31
mex.cc (mxArray_octave_value::get_data): avoid enumerating types that can be handled as foreign
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
446 if (retval) |
d4b1314a7c31
mex.cc (mxArray_octave_value::get_data): avoid enumerating types that can be handled as foreign
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
447 maybe_mark_foreign (retval); |
5900 | 448 else |
449 request_mutation (); | |
450 | |
451 return retval; | |
452 } | |
453 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
454 void * get_imag_data (void) const |
5900 | 455 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
456 void *retval = nullptr; |
5900 | 457 |
23582
0cc2011d800e
maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents:
23581
diff
changeset
|
458 if (is_numeric () && isreal ()) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
459 retval = nullptr; |
5900 | 460 else |
461 request_mutation (); | |
462 | |
463 return retval; | |
464 } | |
465 | |
466 // Not allowed. | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
467 void set_data (void * /*pr*/) { request_mutation (); } |
5900 | 468 |
469 // Not allowed. | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
470 void set_imag_data (void * /*pi*/) { request_mutation (); } |
5900 | 471 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
472 mwIndex * get_ir (void) const |
5900 | 473 { |
7179 | 474 return static_cast<mwIndex *> (maybe_mark_foreign (val.mex_get_ir ())); |
5900 | 475 } |
476 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
477 mwIndex * get_jc (void) const |
5900 | 478 { |
7179 | 479 return static_cast<mwIndex *> (maybe_mark_foreign (val.mex_get_jc ())); |
5900 | 480 } |
481 | |
6686 | 482 mwSize get_nzmax (void) const { return val.nzmax (); } |
5900 | 483 |
484 // Not allowed. | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
485 void set_ir (mwIndex * /*ir*/) { request_mutation (); } |
5900 | 486 |
487 // Not allowed. | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
488 void set_jc (mwIndex * /*jc*/) { request_mutation (); } |
5900 | 489 |
490 // Not allowed. | |
6686 | 491 void set_nzmax (mwSize /*nzmax*/) { request_mutation (); } |
5900 | 492 |
493 // Not allowed. | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
494 int add_field (const char * /*key*/) |
5900 | 495 { |
6400 | 496 request_mutation (); |
497 return 0; | |
5900 | 498 } |
499 | |
500 // Not allowed. | |
6400 | 501 void remove_field (int /*key_num*/) { request_mutation (); } |
5900 | 502 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
503 mxArray * get_field_by_number (mwIndex /*index*/, int /*key_num*/) const |
5900 | 504 { |
505 request_mutation (); | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
506 return nullptr; |
5900 | 507 } |
508 | |
509 // Not allowed. | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
510 void set_field_by_number (mwIndex /*index*/, int /*key_num*/, |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
511 mxArray * /*val*/) |
5900 | 512 { |
6400 | 513 request_mutation (); |
5900 | 514 } |
515 | |
516 int get_number_of_fields (void) const { return val.nfields (); } | |
517 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
518 const char * get_field_name_by_number (int /*key_num*/) const |
5900 | 519 { |
520 request_mutation (); | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
521 return nullptr; |
5900 | 522 } |
523 | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
524 int get_field_number (const char * /*key*/) const |
5900 | 525 { |
526 request_mutation (); | |
527 return 0; | |
528 } | |
529 | |
6686 | 530 int get_string (char *buf, mwSize buflen) const |
5900 | 531 { |
532 int retval = 1; | |
533 | |
6686 | 534 mwSize nel = get_number_of_elements (); |
5900 | 535 |
536 if (val.is_string () && nel < buflen) | |
537 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
538 charNDArray tmp = val.char_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
539 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
540 const char *p = tmp.data (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
541 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
542 for (mwIndex i = 0; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
543 buf[i] = p[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
544 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
545 buf[nel] = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
546 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
547 retval = 0; |
5900 | 548 } |
549 | |
550 return retval; | |
551 } | |
552 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
553 char * array_to_string (void) const |
5900 | 554 { |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
555 // FIXME: this is supposed to handle multi-byte character strings. |
5900 | 556 |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
557 char *buf = nullptr; |
5900 | 558 |
559 if (val.is_string ()) | |
560 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
561 mwSize nel = get_number_of_elements (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
562 |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
563 buf = static_cast<char *> (mxArray::malloc (nel + 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
564 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
565 if (buf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
566 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
567 charNDArray tmp = val.char_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
568 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
569 const char *p = tmp.data (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
570 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
571 for (mwIndex i = 0; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
572 buf[i] = p[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
573 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
574 buf[nel] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
575 } |
5900 | 576 } |
577 | |
578 return buf; | |
579 } | |
580 | |
6686 | 581 mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const |
5900 | 582 { |
583 // Force ndims, dims to be cached. | |
584 get_dimensions (); | |
585 | |
7357 | 586 return calc_single_subscript_internal (ndims, dims, nsubs, subs); |
5900 | 587 } |
588 | |
6686 | 589 size_t get_element_size (void) const |
5900 | 590 { |
591 // Force id to be cached. | |
592 get_class_id (); | |
593 | |
594 switch (id) | |
595 { | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
596 case mxDOUBLE_CLASS: return sizeof (double); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
597 case mxSINGLE_CLASS: return sizeof (float); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
598 case mxCHAR_CLASS: return sizeof (mxChar); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
599 case mxLOGICAL_CLASS: return sizeof (mxLogical); |
5900 | 600 case mxCELL_CLASS: return sizeof (mxArray *); |
601 case mxSTRUCT_CLASS: return sizeof (mxArray *); | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
602 case mxFUNCTION_CLASS: return 0; |
5900 | 603 case mxINT8_CLASS: return 1; |
604 case mxUINT8_CLASS: return 1; | |
605 case mxINT16_CLASS: return 2; | |
606 case mxUINT16_CLASS: return 2; | |
607 case mxINT32_CLASS: return 4; | |
608 case mxUINT32_CLASS: return 4; | |
609 case mxINT64_CLASS: return 8; | |
610 case mxUINT64_CLASS: return 8; | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
611 // FIXME: user-defined objects need their own class ID. |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
612 // What should they return, size of pointer? |
5900 | 613 default: return 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
614 } |
5900 | 615 } |
616 | |
617 bool mutation_needed (void) const { return mutate_flag; } | |
618 | |
619 void request_mutation (void) const | |
620 { | |
621 if (mutate_flag) | |
622 panic_impossible (); | |
623 | |
624 mutate_flag = true; | |
625 } | |
626 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
627 mxArray * mutate (void) const { return as_mxArray (); } |
5900 | 628 |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
629 octave_value as_octave_value (void) const { return val; } |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
630 |
5900 | 631 protected: |
632 | |
633 mxArray_octave_value (const mxArray_octave_value& arg) | |
634 : mxArray_base (arg), val (arg.val), mutate_flag (arg.mutate_flag), | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
635 id (arg.id), class_name (mxArray::strsave (arg.class_name)), |
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
636 ndims (arg.ndims), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
637 dims (ndims > 0 ? static_cast<mwSize *> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
638 (mxArray::malloc (ndims * sizeof (mwSize))) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
639 : nullptr) |
5900 | 640 { |
641 if (dims) | |
642 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
643 for (mwIndex i = 0; i < ndims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
644 dims[i] = arg.dims[i]; |
5900 | 645 } |
646 } | |
647 | |
648 private: | |
649 | |
650 octave_value val; | |
651 | |
652 mutable bool mutate_flag; | |
653 | |
654 // Caching these does not cost much or lead to much duplicated | |
655 // code. For other things, we just request mutation to a | |
656 // Matlab-style mxArray object. | |
657 | |
658 mutable mxClassID id; | |
659 mutable char *class_name; | |
6686 | 660 mutable mwSize ndims; |
661 mutable mwSize *dims; | |
5900 | 662 }; |
663 | |
664 // The base class for the Matlab-style representation, used to handle | |
665 // things that are common to all Matlab-style objects. | |
666 | |
667 class mxArray_matlab : public mxArray_base | |
668 { | |
669 protected: | |
670 | |
671 mxArray_matlab (mxClassID id_arg = mxUNKNOWN_CLASS) | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
672 : mxArray_base (), class_name (nullptr), id (id_arg), ndims (0), dims (nullptr) { } |
5900 | 673 |
6686 | 674 mxArray_matlab (mxClassID id_arg, mwSize ndims_arg, const mwSize *dims_arg) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
675 : mxArray_base (), class_name (nullptr), id (id_arg), |
5900 | 676 ndims (ndims_arg < 2 ? 2 : ndims_arg), |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
677 dims (static_cast<mwSize *> (mxArray::malloc (ndims * sizeof (mwSize)))) |
5900 | 678 { |
20362
b9bd8786d310
fix incompatibility in mxCreateNumericArray (bug #45319)
John W. Eaton <jwe@octave.org>
parents:
20261
diff
changeset
|
679 if (ndims_arg == 0) |
5900 | 680 { |
20261
2691947f5409
Change mxCreateNumericArray to be Matlab compatible for ndims < 2 (bug #45319).
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
681 dims[0] = 0; |
2691947f5409
Change mxCreateNumericArray to be Matlab compatible for ndims < 2 (bug #45319).
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
682 dims[1] = 0; |
5900 | 683 } |
20362
b9bd8786d310
fix incompatibility in mxCreateNumericArray (bug #45319)
John W. Eaton <jwe@octave.org>
parents:
20261
diff
changeset
|
684 else if (ndims_arg < 2) |
b9bd8786d310
fix incompatibility in mxCreateNumericArray (bug #45319)
John W. Eaton <jwe@octave.org>
parents:
20261
diff
changeset
|
685 { |
b9bd8786d310
fix incompatibility in mxCreateNumericArray (bug #45319)
John W. Eaton <jwe@octave.org>
parents:
20261
diff
changeset
|
686 dims[0] = 1; |
b9bd8786d310
fix incompatibility in mxCreateNumericArray (bug #45319)
John W. Eaton <jwe@octave.org>
parents:
20261
diff
changeset
|
687 dims[1] = 1; |
b9bd8786d310
fix incompatibility in mxCreateNumericArray (bug #45319)
John W. Eaton <jwe@octave.org>
parents:
20261
diff
changeset
|
688 } |
5900 | 689 |
6686 | 690 for (mwIndex i = 0; i < ndims_arg; i++) |
5900 | 691 dims[i] = dims_arg[i]; |
692 | |
6686 | 693 for (mwIndex i = ndims - 1; i > 1; i--) |
5900 | 694 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
695 if (dims[i] == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
696 ndims--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
697 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
698 break; |
5900 | 699 } |
700 } | |
701 | |
702 mxArray_matlab (mxClassID id_arg, const dim_vector& dv) | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
703 : mxArray_base (), class_name (nullptr), id (id_arg), |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
704 ndims (dv.ndims ()), |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
705 dims (static_cast<mwSize *> (mxArray::malloc (ndims * sizeof (mwSize)))) |
5900 | 706 { |
6686 | 707 for (mwIndex i = 0; i < ndims; i++) |
5900 | 708 dims[i] = dv(i); |
709 | |
6686 | 710 for (mwIndex i = ndims - 1; i > 1; i--) |
5900 | 711 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
712 if (dims[i] == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
713 ndims--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
714 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
715 break; |
5900 | 716 } |
717 } | |
718 | |
6686 | 719 mxArray_matlab (mxClassID id_arg, mwSize m, mwSize n) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
720 : mxArray_base (), class_name (nullptr), id (id_arg), ndims (2), |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
721 dims (static_cast<mwSize *> (mxArray::malloc (ndims * sizeof (mwSize)))) |
5900 | 722 { |
723 dims[0] = m; | |
724 dims[1] = n; | |
725 } | |
726 | |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
727 mxArray_matlab (const mxArray_matlab& val) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
728 : mxArray_base (val), class_name (mxArray::strsave (val.class_name)), |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
729 id (val.id), ndims (val.ndims), |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
730 dims (static_cast<mwSize *> (mxArray::malloc (ndims * sizeof (mwSize)))) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
731 { |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
732 for (mwIndex i = 0; i < ndims; i++) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
733 dims[i] = val.dims[i]; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
734 } |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
735 |
5900 | 736 public: |
737 | |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
738 // No assignment! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
739 // FIXME: should this be implemented? |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
740 // Note that we *do* have a copy constructor. |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
741 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
742 mxArray_matlab& operator = (const mxArray_matlab&); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
743 |
5900 | 744 ~mxArray_matlab (void) |
745 { | |
746 mxFree (class_name); | |
747 mxFree (dims); | |
748 } | |
749 | |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23553
diff
changeset
|
750 int iscell (void) const { return id == mxCELL_CLASS; } |
5900 | 751 |
752 int is_char (void) const { return id == mxCHAR_CLASS; } | |
753 | |
754 int is_complex (void) const { return 0; } | |
755 | |
756 int is_double (void) const { return id == mxDOUBLE_CLASS; } | |
757 | |
11100
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
758 int is_function_handle (void) const { return id == mxFUNCTION_CLASS; } |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
759 |
5900 | 760 int is_int16 (void) const { return id == mxINT16_CLASS; } |
761 | |
762 int is_int32 (void) const { return id == mxINT32_CLASS; } | |
763 | |
764 int is_int64 (void) const { return id == mxINT64_CLASS; } | |
765 | |
766 int is_int8 (void) const { return id == mxINT8_CLASS; } | |
767 | |
768 int is_logical (void) const { return id == mxLOGICAL_CLASS; } | |
769 | |
770 int is_numeric (void) const | |
771 { | |
772 return (id == mxDOUBLE_CLASS || id == mxSINGLE_CLASS | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
773 || id == mxINT8_CLASS || id == mxUINT8_CLASS |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
774 || id == mxINT16_CLASS || id == mxUINT16_CLASS |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
775 || id == mxINT32_CLASS || id == mxUINT32_CLASS |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
776 || id == mxINT64_CLASS || id == mxUINT64_CLASS); |
5900 | 777 } |
778 | |
779 int is_single (void) const { return id == mxSINGLE_CLASS; } | |
780 | |
781 int is_sparse (void) const { return 0; } | |
782 | |
783 int is_struct (void) const { return id == mxSTRUCT_CLASS; } | |
784 | |
785 int is_uint16 (void) const { return id == mxUINT16_CLASS; } | |
786 | |
787 int is_uint32 (void) const { return id == mxUINT32_CLASS; } | |
788 | |
789 int is_uint64 (void) const { return id == mxUINT64_CLASS; } | |
790 | |
791 int is_uint8 (void) const { return id == mxUINT8_CLASS; } | |
792 | |
793 int is_logical_scalar_true (void) const | |
794 { | |
795 return (is_logical_scalar () | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
796 && static_cast<mxLogical *> (get_data ())[0] != 0); |
5900 | 797 } |
798 | |
6686 | 799 mwSize get_m (void) const { return dims[0]; } |
800 | |
801 mwSize get_n (void) const | |
6187 | 802 { |
6686 | 803 mwSize n = 1; |
804 | |
805 for (mwSize i = ndims - 1 ; i > 0 ; i--) | |
6187 | 806 n *= dims[i]; |
807 | |
808 return n; | |
809 } | |
5900 | 810 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
811 mwSize * get_dimensions (void) const { return dims; } |
6686 | 812 |
813 mwSize get_number_of_dimensions (void) const { return ndims; } | |
814 | |
815 void set_m (mwSize m) { dims[0] = m; } | |
816 | |
817 void set_n (mwSize n) { dims[1] = n; } | |
818 | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
819 int set_dimensions (mwSize *dims_arg, mwSize ndims_arg) |
5900 | 820 { |
821 ndims = ndims_arg; | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
822 |
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
823 mxFree (dims); |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
824 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
825 if (ndims > 0) |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
826 { |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
827 dims |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
828 = static_cast<mwSize *> (mxArray::malloc (ndims * sizeof (mwSize))); |
22599
51b395d24782
maint: strip tabs and trailing whitespace from C++ sources.
John W. Eaton <jwe@octave.org>
parents:
22480
diff
changeset
|
829 |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
830 if (dims == nullptr) |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
831 return 1; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
832 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
833 for (int i = 0; i < ndims; i++) |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
834 dims[i] = dims_arg[i]; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
835 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
836 return 0; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
837 } |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
838 else |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
839 { |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
840 dims = nullptr; |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
841 return 0; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
842 } |
5900 | 843 } |
844 | |
6686 | 845 mwSize get_number_of_elements (void) const |
5900 | 846 { |
6686 | 847 mwSize retval = dims[0]; |
848 | |
849 for (mwIndex i = 1; i < ndims; i++) | |
5900 | 850 retval *= dims[i]; |
851 | |
852 return retval; | |
853 } | |
854 | |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
855 int isempty (void) const { return get_number_of_elements () == 0; } |
5900 | 856 |
22462
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
857 bool is_scalar (void) const |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
858 { |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
859 return ndims == 2 && dims[0] == 1 && dims[1] == 1; |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
860 } |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
861 |
5900 | 862 mxClassID get_class_id (void) const { return id; } |
863 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
864 const char * get_class_name (void) const |
5900 | 865 { |
866 switch (id) | |
867 { | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
868 case mxDOUBLE_CLASS: return "double"; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
869 case mxSINGLE_CLASS: return "single"; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
870 case mxCHAR_CLASS: return "char"; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
871 case mxLOGICAL_CLASS: return "logical"; |
5900 | 872 case mxCELL_CLASS: return "cell"; |
873 case mxSTRUCT_CLASS: return "struct"; | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
874 case mxFUNCTION_CLASS: return "function_handle"; |
5900 | 875 case mxINT8_CLASS: return "int8"; |
876 case mxUINT8_CLASS: return "uint8"; | |
877 case mxINT16_CLASS: return "int16"; | |
878 case mxUINT16_CLASS: return "uint16"; | |
879 case mxINT32_CLASS: return "int32"; | |
880 case mxUINT32_CLASS: return "uint32"; | |
881 case mxINT64_CLASS: return "int64"; | |
882 case mxUINT64_CLASS: return "uint64"; | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
883 case mxUNKNOWN_CLASS: return "unknown"; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
884 // FIXME: should return the classname of user-defined objects |
5900 | 885 default: return "unknown"; |
886 } | |
887 } | |
888 | |
889 void set_class_name (const char *name_arg) | |
890 { | |
891 mxFree (class_name); | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
892 class_name = static_cast<char *> (mxArray::malloc (strlen (name_arg) + 1)); |
5900 | 893 strcpy (class_name, name_arg); |
894 } | |
895 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
896 mxArray * get_cell (mwIndex /*idx*/) const |
5900 | 897 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
898 err_invalid_type (); |
5900 | 899 } |
900 | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
901 void set_cell (mwIndex /*idx*/, mxArray * /*val*/) |
5900 | 902 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
903 err_invalid_type (); |
5900 | 904 } |
905 | |
6332 | 906 double get_scalar (void) const |
907 { | |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
908 err_invalid_type (); |
6332 | 909 } |
910 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
911 void * get_data (void) const |
5900 | 912 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
913 err_invalid_type (); |
5900 | 914 } |
915 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
916 void * get_imag_data (void) const |
5900 | 917 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
918 err_invalid_type (); |
5900 | 919 } |
920 | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
921 void set_data (void * /*pr*/) |
5900 | 922 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
923 err_invalid_type (); |
5900 | 924 } |
925 | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
926 void set_imag_data (void * /*pi*/) |
5900 | 927 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
928 err_invalid_type (); |
5900 | 929 } |
930 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
931 mwIndex * get_ir (void) const |
5900 | 932 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
933 err_invalid_type (); |
5900 | 934 } |
935 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
936 mwIndex * get_jc (void) const |
5900 | 937 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
938 err_invalid_type (); |
5900 | 939 } |
940 | |
6686 | 941 mwSize get_nzmax (void) const |
5900 | 942 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
943 err_invalid_type (); |
5900 | 944 } |
945 | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
946 void set_ir (mwIndex * /*ir*/) |
5900 | 947 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
948 err_invalid_type (); |
5900 | 949 } |
950 | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
951 void set_jc (mwIndex * /*jc*/) |
5900 | 952 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
953 err_invalid_type (); |
5900 | 954 } |
955 | |
6686 | 956 void set_nzmax (mwSize /*nzmax*/) |
5900 | 957 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
958 err_invalid_type (); |
5900 | 959 } |
960 | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
961 int add_field (const char * /*key*/) |
5900 | 962 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
963 err_invalid_type (); |
5900 | 964 } |
965 | |
966 void remove_field (int /*key_num*/) | |
967 { | |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
968 err_invalid_type (); |
5900 | 969 } |
970 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
971 mxArray * get_field_by_number (mwIndex /*index*/, int /*key_num*/) const |
5900 | 972 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
973 err_invalid_type (); |
5900 | 974 } |
975 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
976 void set_field_by_number (mwIndex /*index*/, int /*key_num*/, |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
977 mxArray * /*val*/) |
5900 | 978 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
979 err_invalid_type (); |
5900 | 980 } |
981 | |
982 int get_number_of_fields (void) const | |
983 { | |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
984 err_invalid_type (); |
5900 | 985 } |
986 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
987 const char * get_field_name_by_number (int /*key_num*/) const |
5900 | 988 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
989 err_invalid_type (); |
5900 | 990 } |
991 | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
992 int get_field_number (const char * /*key*/) const |
5900 | 993 { |
994 return -1; | |
995 } | |
996 | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
997 int get_string (char * /*buf*/, mwSize /*buflen*/) const |
5900 | 998 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
999 err_invalid_type (); |
5900 | 1000 } |
1001 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1002 char * array_to_string (void) const |
5900 | 1003 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1004 err_invalid_type (); |
5900 | 1005 } |
1006 | |
6686 | 1007 mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const |
5900 | 1008 { |
7357 | 1009 return calc_single_subscript_internal (ndims, dims, nsubs, subs); |
5900 | 1010 } |
1011 | |
6686 | 1012 size_t get_element_size (void) const |
5900 | 1013 { |
1014 switch (id) | |
1015 { | |
1016 case mxCELL_CLASS: return sizeof (mxArray *); | |
1017 case mxSTRUCT_CLASS: return sizeof (mxArray *); | |
1018 case mxLOGICAL_CLASS: return sizeof (mxLogical); | |
1019 case mxCHAR_CLASS: return sizeof (mxChar); | |
1020 case mxDOUBLE_CLASS: return sizeof (double); | |
1021 case mxSINGLE_CLASS: return sizeof (float); | |
1022 case mxINT8_CLASS: return 1; | |
1023 case mxUINT8_CLASS: return 1; | |
1024 case mxINT16_CLASS: return 2; | |
1025 case mxUINT16_CLASS: return 2; | |
1026 case mxINT32_CLASS: return 4; | |
1027 case mxUINT32_CLASS: return 4; | |
1028 case mxINT64_CLASS: return 8; | |
1029 case mxUINT64_CLASS: return 8; | |
1030 case mxFUNCTION_CLASS: return 0; | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1031 // FIXME: user-defined objects need their own class ID. |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1032 // What should they return, size of pointer? |
5900 | 1033 default: return 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1034 } |
5900 | 1035 } |
1036 | |
1037 protected: | |
1038 | |
1039 dim_vector | |
1040 dims_to_dim_vector (void) const | |
1041 { | |
6686 | 1042 mwSize nd = get_number_of_dimensions (); |
1043 | |
1044 mwSize *d = get_dimensions (); | |
5900 | 1045 |
1046 dim_vector dv; | |
1047 dv.resize (nd); | |
1048 | |
6686 | 1049 for (mwIndex i = 0; i < nd; i++) |
5900 | 1050 dv(i) = d[i]; |
1051 | |
1052 return dv; | |
1053 } | |
1054 | |
1055 private: | |
1056 | |
1057 char *class_name; | |
1058 | |
1059 mxClassID id; | |
1060 | |
6686 | 1061 mwSize ndims; |
1062 mwSize *dims; | |
5900 | 1063 |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1064 OCTAVE_NORETURN void err_invalid_type (void) const |
5900 | 1065 { |
1066 error ("invalid type for operation"); | |
1067 } | |
1068 }; | |
1069 | |
1070 // Matlab-style numeric, character, and logical data. | |
1071 | |
1072 class mxArray_number : public mxArray_matlab | |
1073 { | |
1074 public: | |
1075 | |
6686 | 1076 mxArray_number (mxClassID id_arg, mwSize ndims_arg, const mwSize *dims_arg, |
22464
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1077 mxComplexity flag = mxREAL, bool init = true) |
5900 | 1078 : mxArray_matlab (id_arg, ndims_arg, dims_arg), |
22464
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1079 pr (init ? mxArray::calloc (get_number_of_elements (), |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1080 get_element_size ()) |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1081 : mxArray::malloc (get_number_of_elements () |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1082 * get_element_size ())), |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1083 pi (flag == mxCOMPLEX |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1084 ? (init ? mxArray::calloc (get_number_of_elements (), |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1085 get_element_size ()) |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1086 : mxArray::malloc (get_number_of_elements () |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1087 * get_element_size ())) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1088 : nullptr) { } |
5900 | 1089 |
1090 mxArray_number (mxClassID id_arg, const dim_vector& dv, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1091 mxComplexity flag = mxREAL) |
5900 | 1092 : mxArray_matlab (id_arg, dv), |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1093 pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1094 pi (flag == mxCOMPLEX ? mxArray::calloc (get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1095 get_element_size ()) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1096 : nullptr) |
22464
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1097 { } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1098 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1099 mxArray_number (mxClassID id_arg, mwSize m, mwSize n, |
22464
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1100 mxComplexity flag = mxREAL, bool init = true) |
5900 | 1101 : mxArray_matlab (id_arg, m, n), |
22464
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1102 pr (init ? mxArray::calloc (get_number_of_elements (), |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1103 get_element_size ()) |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1104 : mxArray::malloc (get_number_of_elements () |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1105 * get_element_size ())), |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1106 pi (flag == mxCOMPLEX |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1107 ? (init ? mxArray::calloc (get_number_of_elements (), |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1108 get_element_size ()) |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1109 : mxArray::malloc (get_number_of_elements () |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1110 * get_element_size ())) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1111 : nullptr) |
22464
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
1112 { } |
5900 | 1113 |
1114 mxArray_number (mxClassID id_arg, double val) | |
1115 : mxArray_matlab (id_arg, 1, 1), | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1116 pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1117 pi (nullptr) |
5900 | 1118 { |
1119 double *dpr = static_cast<double *> (pr); | |
1120 dpr[0] = val; | |
1121 } | |
1122 | |
1123 mxArray_number (mxClassID id_arg, mxLogical val) | |
1124 : mxArray_matlab (id_arg, 1, 1), | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1125 pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1126 pi (nullptr) |
5900 | 1127 { |
1128 mxLogical *lpr = static_cast<mxLogical *> (pr); | |
1129 lpr[0] = val; | |
1130 } | |
1131 | |
1132 mxArray_number (const char *str) | |
10853
c3813056f94f
mxArray_number (const char *): create empty string if given NULL arg
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1133 : mxArray_matlab (mxCHAR_CLASS, |
c3813056f94f
mxArray_number (const char *): create empty string if given NULL arg
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1134 str ? (strlen (str) ? 1 : 0) : 0, |
c3813056f94f
mxArray_number (const char *): create empty string if given NULL arg
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1135 str ? strlen (str) : 0), |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
1136 pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), |
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
1137 pi (nullptr) |
5900 | 1138 { |
1139 mxChar *cpr = static_cast<mxChar *> (pr); | |
6686 | 1140 mwSize nel = get_number_of_elements (); |
1141 for (mwIndex i = 0; i < nel; i++) | |
5900 | 1142 cpr[i] = str[i]; |
1143 } | |
1144 | |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17810
diff
changeset
|
1145 // FIXME: ??? |
6806 | 1146 mxArray_number (mwSize m, const char **str) |
5900 | 1147 : mxArray_matlab (mxCHAR_CLASS, m, max_str_len (m, str)), |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1148 pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1149 pi (nullptr) |
5900 | 1150 { |
1151 mxChar *cpr = static_cast<mxChar *> (pr); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1152 |
6686 | 1153 mwSize *dv = get_dimensions (); |
1154 | |
1155 mwSize nc = dv[1]; | |
1156 | |
1157 for (mwIndex j = 0; j < m; j++) | |
5900 | 1158 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1159 const char *ptr = str[j]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1160 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1161 size_t tmp_len = strlen (ptr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1162 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1163 for (size_t i = 0; i < tmp_len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1164 cpr[m*i+j] = static_cast<mxChar> (ptr[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1165 |
25688
b2917b7858ba
maint: Use Octave convention for spacing of C++ cast statements.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
1166 for (size_t i = tmp_len; i < static_cast<size_t> (nc); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1167 cpr[m*i+j] = static_cast<mxChar> (' '); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1168 } |
5900 | 1169 } |
1170 | |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1171 protected: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1172 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1173 mxArray_number (const mxArray_number& val) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1174 : mxArray_matlab (val), |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1175 pr (mxArray::malloc (get_number_of_elements () * get_element_size ())), |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1176 pi (val.pi ? mxArray::malloc (get_number_of_elements () |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1177 * get_element_size ()) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1178 : nullptr) |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1179 { |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1180 size_t nbytes = get_number_of_elements () * get_element_size (); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1181 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1182 if (pr) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1183 memcpy (pr, val.pr, nbytes); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1184 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1185 if (pi) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1186 memcpy (pi, val.pi, nbytes); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1187 } |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1188 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1189 public: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1190 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1191 // No assignment! FIXME: should this be implemented? Note that we |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1192 // do have a copy constructor. |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1193 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1194 mxArray_number& operator = (const mxArray_number&); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1195 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1196 mxArray_base * dup (void) const { return new mxArray_number (*this); } |
5900 | 1197 |
1198 ~mxArray_number (void) | |
1199 { | |
1200 mxFree (pr); | |
1201 mxFree (pi); | |
1202 } | |
1203 | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1204 int is_complex (void) const { return pi != nullptr; } |
5907 | 1205 |
6332 | 1206 double get_scalar (void) const |
1207 { | |
1208 double retval = 0; | |
1209 | |
1210 switch (get_class_id ()) | |
1211 { | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1212 case mxDOUBLE_CLASS: |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1213 retval = *(static_cast<double *> (pr)); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1214 break; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1215 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1216 case mxSINGLE_CLASS: |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1217 retval = *(static_cast<float *> (pr)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1218 break; |
6332 | 1219 |
1220 case mxCHAR_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1221 retval = *(static_cast<mxChar *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1222 break; |
6332 | 1223 |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1224 case mxLOGICAL_CLASS: |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1225 retval = *(static_cast<bool *> (pr)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1226 break; |
6332 | 1227 |
1228 case mxINT8_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1229 retval = *(static_cast<int8_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1230 break; |
6332 | 1231 |
1232 case mxUINT8_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1233 retval = *(static_cast<uint8_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1234 break; |
6332 | 1235 |
1236 case mxINT16_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1237 retval = *(static_cast<int16_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1238 break; |
6332 | 1239 |
1240 case mxUINT16_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1241 retval = *(static_cast<uint16_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1242 break; |
6332 | 1243 |
1244 case mxINT32_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1245 retval = *(static_cast<int32_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1246 break; |
6332 | 1247 |
1248 case mxUINT32_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1249 retval = *(static_cast<uint32_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1250 break; |
6332 | 1251 |
1252 case mxINT64_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1253 retval = *(static_cast<int64_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1254 break; |
6332 | 1255 |
1256 case mxUINT64_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1257 retval = *(static_cast<uint64_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1258 break; |
6332 | 1259 |
1260 default: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1261 panic_impossible (); |
6332 | 1262 } |
1263 | |
1264 return retval; | |
1265 } | |
1266 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1267 void * get_data (void) const { return pr; } |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1268 |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1269 void * get_imag_data (void) const { return pi; } |
5907 | 1270 |
1271 void set_data (void *pr_arg) { pr = pr_arg; } | |
1272 | |
1273 void set_imag_data (void *pi_arg) { pi = pi_arg; } | |
1274 | |
6686 | 1275 int get_string (char *buf, mwSize buflen) const |
5907 | 1276 { |
13753
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1277 int retval = 0; |
5907 | 1278 |
6686 | 1279 mwSize nel = get_number_of_elements (); |
6493 | 1280 |
13753
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1281 if (! (nel < buflen)) |
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1282 { |
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1283 retval = 1; |
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1284 if (buflen > 0) |
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1285 nel = buflen-1; |
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1286 } |
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1287 |
6493 | 1288 if (nel < buflen) |
5907 | 1289 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1290 mxChar *ptr = static_cast<mxChar *> (pr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1291 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1292 for (mwIndex i = 0; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1293 buf[i] = static_cast<char> (ptr[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1294 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1295 buf[nel] = 0; |
5907 | 1296 } |
1297 | |
1298 return retval; | |
1299 } | |
1300 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1301 char * array_to_string (void) const |
5907 | 1302 { |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1303 // FIXME: this is supposed to handle multi-byte character strings. |
5907 | 1304 |
6686 | 1305 mwSize nel = get_number_of_elements (); |
5907 | 1306 |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1307 char *buf = static_cast<char *> (mxArray::malloc (nel + 1)); |
5907 | 1308 |
1309 if (buf) | |
1310 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1311 mxChar *ptr = static_cast<mxChar *> (pr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1312 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1313 for (mwIndex i = 0; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1314 buf[i] = static_cast<char> (ptr[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1315 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1316 buf[nel] = '\0'; |
5907 | 1317 } |
1318 | |
1319 return buf; | |
1320 } | |
1321 | |
5900 | 1322 octave_value as_octave_value (void) const |
1323 { | |
1324 octave_value retval; | |
1325 | |
1326 dim_vector dv = dims_to_dim_vector (); | |
1327 | |
1328 switch (get_class_id ()) | |
1329 { | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1330 case mxDOUBLE_CLASS: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1331 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1332 mwSize nel = get_number_of_elements (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1333 |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1334 double *ppr = static_cast<double *> (pr); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1335 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1336 if (pi) |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1337 { |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1338 ComplexNDArray val (dv); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1339 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1340 Complex *ptr = val.fortran_vec (); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1341 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1342 double *ppi = static_cast<double *> (pi); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1343 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1344 for (mwIndex i = 0; i < nel; i++) |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1345 ptr[i] = Complex (ppr[i], ppi[i]); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1346 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1347 retval = val; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1348 } |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1349 else |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1350 { |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1351 NDArray val (dv); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1352 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1353 double *ptr = val.fortran_vec (); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1354 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1355 for (mwIndex i = 0; i < nel; i++) |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1356 ptr[i] = ppr[i]; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1357 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1358 retval = val; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1359 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1360 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1361 break; |
5900 | 1362 |
1363 case mxSINGLE_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1364 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1365 mwSize nel = get_number_of_elements (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1366 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1367 float *ppr = static_cast<float *> (pr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1368 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1369 if (pi) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1370 { |
11132
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1371 FloatComplexNDArray val (dv); |
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1372 |
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1373 FloatComplex *ptr = val.fortran_vec (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1374 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1375 float *ppi = static_cast<float *> (pi); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1376 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1377 for (mwIndex i = 0; i < nel; i++) |
11132
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1378 ptr[i] = FloatComplex (ppr[i], ppi[i]); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1379 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1380 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1381 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1382 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1383 { |
11132
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1384 FloatNDArray val (dv); |
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1385 |
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1386 float *ptr = val.fortran_vec (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1387 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1388 for (mwIndex i = 0; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1389 ptr[i] = ppr[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1390 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1391 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1392 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1393 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1394 break; |
5900 | 1395 |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1396 case mxCHAR_CLASS: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1397 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1398 mwSize nel = get_number_of_elements (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1399 |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1400 mxChar *ppr = static_cast<mxChar *> (pr); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1401 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1402 charNDArray val (dv); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1403 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1404 char *ptr = val.fortran_vec (); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1405 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1406 for (mwIndex i = 0; i < nel; i++) |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1407 ptr[i] = static_cast<char> (ppr[i]); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1408 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1409 retval = val; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1410 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1411 break; |
5900 | 1412 |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1413 case mxLOGICAL_CLASS: |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1414 retval = int_to_ov<mxLogical, boolNDArray, bool> (dv); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1415 break; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1416 |
5900 | 1417 case mxINT8_CLASS: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1418 retval = int_to_ov<int8_t, int8NDArray, octave_int8> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1419 break; |
5900 | 1420 |
1421 case mxUINT8_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1422 retval = int_to_ov<uint8_t, uint8NDArray, octave_uint8> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1423 break; |
5900 | 1424 |
1425 case mxINT16_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1426 retval = int_to_ov<int16_t, int16NDArray, octave_int16> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1427 break; |
5900 | 1428 |
1429 case mxUINT16_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1430 retval = int_to_ov<uint16_t, uint16NDArray, octave_uint16> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1431 break; |
5900 | 1432 |
1433 case mxINT32_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1434 retval = int_to_ov<int32_t, int32NDArray, octave_int32> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1435 break; |
5900 | 1436 |
1437 case mxUINT32_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1438 retval = int_to_ov<uint32_t, uint32NDArray, octave_uint32> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1439 break; |
5900 | 1440 |
1441 case mxINT64_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1442 retval = int_to_ov<int64_t, int64NDArray, octave_int64> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1443 break; |
5900 | 1444 |
1445 case mxUINT64_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1446 retval = int_to_ov<uint64_t, uint64NDArray, octave_uint64> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1447 break; |
5900 | 1448 |
1449 default: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1450 panic_impossible (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1451 } |
5900 | 1452 |
1453 return retval; | |
1454 } | |
1455 | |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1456 protected: |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1457 |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1458 template <typename ELT_T, typename ARRAY_T, typename ARRAY_ELT_T> |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1459 octave_value |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1460 int_to_ov (const dim_vector& dv) const |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1461 { |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1462 if (pi) |
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1463 error ("complex integer types are not supported"); |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1464 |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1465 mwSize nel = get_number_of_elements (); |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1466 |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1467 ELT_T *ppr = static_cast<ELT_T *> (pr); |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1468 |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1469 ARRAY_T val (dv); |
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1470 |
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1471 ARRAY_ELT_T *ptr = val.fortran_vec (); |
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1472 |
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1473 for (mwIndex i = 0; i < nel; i++) |
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1474 ptr[i] = ppr[i]; |
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1475 |
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1476 return octave_value (val); |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1477 } |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1478 |
5900 | 1479 private: |
1480 | |
1481 void *pr; | |
1482 void *pi; | |
1483 }; | |
1484 | |
1485 // Matlab-style sparse arrays. | |
1486 | |
5903 | 1487 class mxArray_sparse : public mxArray_matlab |
5900 | 1488 { |
1489 public: | |
1490 | |
14839
e2ac6e2c588a
use mwSize for size arguments to mxArray_sparse constructor (bug #36783)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1491 mxArray_sparse (mxClassID id_arg, mwSize m, mwSize n, mwSize nzmax_arg, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1492 mxComplexity flag = mxREAL) |
27083
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1493 : mxArray_matlab (id_arg, m, n) |
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1494 { |
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1495 nzmax = (nzmax_arg > 0 ? nzmax_arg : 1); |
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1496 pr = mxArray::calloc (nzmax, get_element_size ()); |
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1497 pi = (flag == mxCOMPLEX ? mxArray::calloc (nzmax, get_element_size ()) |
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1498 : nullptr); |
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1499 ir = (static_cast<mwIndex *> (mxArray::calloc (nzmax, sizeof (mwIndex)))); |
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1500 jc = (static_cast<mwIndex *> (mxArray::calloc (n + 1, sizeof (mwIndex)))); |
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1501 } |
5900 | 1502 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1503 private: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1504 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1505 mxArray_sparse (const mxArray_sparse& val) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1506 : mxArray_matlab (val), nzmax (val.nzmax), |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1507 pr (mxArray::malloc (nzmax * get_element_size ())), |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1508 pi (val.pi ? mxArray::malloc (nzmax * get_element_size ()) : nullptr), |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1509 ir (static_cast<mwIndex *> (mxArray::malloc (nzmax * sizeof (mwIndex)))), |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1510 jc (static_cast<mwIndex *> (mxArray::malloc (nzmax * sizeof (mwIndex)))) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1511 { |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1512 size_t nbytes = nzmax * get_element_size (); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1513 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1514 if (pr) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1515 memcpy (pr, val.pr, nbytes); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1516 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1517 if (pi) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1518 memcpy (pi, val.pi, nbytes); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1519 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1520 if (ir) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1521 memcpy (ir, val.ir, nzmax * sizeof (mwIndex)); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1522 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1523 if (jc) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1524 memcpy (jc, val.jc, (val.get_n () + 1) * sizeof (mwIndex)); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1525 } |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1526 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1527 public: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1528 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1529 // No assignment! FIXME: should this be implemented? Note that we |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1530 // do have a copy constructor. |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1531 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1532 mxArray_sparse& operator = (const mxArray_sparse&); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1533 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1534 mxArray_base * dup (void) const { return new mxArray_sparse (*this); } |
5900 | 1535 |
1536 ~mxArray_sparse (void) | |
1537 { | |
5903 | 1538 mxFree (pr); |
1539 mxFree (pi); | |
5900 | 1540 mxFree (ir); |
1541 mxFree (jc); | |
1542 } | |
1543 | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1544 int is_complex (void) const { return pi != nullptr; } |
5907 | 1545 |
1546 int is_sparse (void) const { return 1; } | |
1547 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1548 void * get_data (void) const { return pr; } |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1549 |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1550 void * get_imag_data (void) const { return pi; } |
5907 | 1551 |
1552 void set_data (void *pr_arg) { pr = pr_arg; } | |
1553 | |
1554 void set_imag_data (void *pi_arg) { pi = pi_arg; } | |
1555 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1556 mwIndex * get_ir (void) const { return ir; } |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1557 |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1558 mwIndex * get_jc (void) const { return jc; } |
6686 | 1559 |
1560 mwSize get_nzmax (void) const { return nzmax; } | |
1561 | |
1562 void set_ir (mwIndex *ir_arg) { ir = ir_arg; } | |
1563 | |
1564 void set_jc (mwIndex *jc_arg) { jc = jc_arg; } | |
1565 | |
27083
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1566 void set_nzmax (mwSize nzmax_arg) |
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1567 { |
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1568 /* Require storage for at least 1 element */ |
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1569 nzmax = (nzmax_arg > 0 ? nzmax_arg : 1); |
23761e83756f
Always reserve memory for 1-element in sparse mxArray matrices (bug #56232).
Rik <rik@octave.org>
parents:
26997
diff
changeset
|
1570 } |
5907 | 1571 |
5900 | 1572 octave_value as_octave_value (void) const |
1573 { | |
5903 | 1574 octave_value retval; |
1575 | |
1576 dim_vector dv = dims_to_dim_vector (); | |
1577 | |
1578 switch (get_class_id ()) | |
1579 { | |
1580 case mxDOUBLE_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1581 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1582 if (pi) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1583 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1584 double *ppr = static_cast<double *> (pr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1585 double *ppi = static_cast<double *> (pi); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1586 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1587 SparseComplexMatrix val (get_m (), get_n (), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1588 static_cast<octave_idx_type> (nzmax)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1589 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1590 for (mwIndex i = 0; i < nzmax; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1591 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1592 val.xdata (i) = Complex (ppr[i], ppi[i]); |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1593 val.xridx (i) = ir[i]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1594 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1595 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1596 for (mwIndex i = 0; i < get_n () + 1; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1597 val.xcidx (i) = jc[i]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1598 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1599 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1600 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1601 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1602 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1603 double *ppr = static_cast<double *> (pr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1604 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1605 SparseMatrix val (get_m (), get_n (), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1606 static_cast<octave_idx_type> (nzmax)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1607 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1608 for (mwIndex i = 0; i < nzmax; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1609 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1610 val.xdata (i) = ppr[i]; |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1611 val.xridx (i) = ir[i]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1612 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1613 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1614 for (mwIndex i = 0; i < get_n () + 1; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1615 val.xcidx (i) = jc[i]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1616 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1617 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1618 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1619 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1620 break; |
5903 | 1621 |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1622 case mxLOGICAL_CLASS: |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1623 { |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1624 bool *ppr = static_cast<bool *> (pr); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1625 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1626 SparseBoolMatrix val (get_m (), get_n (), |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1627 static_cast<octave_idx_type> (nzmax)); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1628 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1629 for (mwIndex i = 0; i < nzmax; i++) |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1630 { |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1631 val.xdata (i) = ppr[i]; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1632 val.xridx (i) = ir[i]; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1633 } |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1634 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1635 for (mwIndex i = 0; i < get_n () + 1; i++) |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1636 val.xcidx (i) = jc[i]; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1637 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1638 retval = val; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1639 } |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1640 break; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1641 |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1642 case mxSINGLE_CLASS: |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1643 error ("single precision sparse data type not supported"); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1644 break; |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
1645 |
5903 | 1646 default: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1647 panic_impossible (); |
5903 | 1648 } |
1649 | |
1650 return retval; | |
5900 | 1651 } |
1652 | |
1653 private: | |
1654 | |
6686 | 1655 mwSize nzmax; |
5900 | 1656 |
5903 | 1657 void *pr; |
1658 void *pi; | |
6686 | 1659 mwIndex *ir; |
1660 mwIndex *jc; | |
5900 | 1661 }; |
1662 | |
1663 // Matlab-style struct arrays. | |
1664 | |
1665 class mxArray_struct : public mxArray_matlab | |
1666 { | |
1667 public: | |
1668 | |
6686 | 1669 mxArray_struct (mwSize ndims_arg, const mwSize *dims_arg, int num_keys_arg, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1670 const char **keys) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1671 : mxArray_matlab (mxSTRUCT_CLASS, ndims_arg, dims_arg), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1672 nfields (num_keys_arg), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1673 fields (static_cast<char **> (mxArray::calloc (nfields, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1674 sizeof (char *)))), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1675 data (static_cast<mxArray **> (mxArray::calloc (nfields * |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1676 get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1677 sizeof (mxArray *)))) |
5900 | 1678 { |
1679 init (keys); | |
1680 } | |
1681 | |
1682 mxArray_struct (const dim_vector& dv, int num_keys_arg, const char **keys) | |
1683 : mxArray_matlab (mxSTRUCT_CLASS, dv), nfields (num_keys_arg), | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1684 fields (static_cast<char **> (mxArray::calloc (nfields, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1685 sizeof (char *)))), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1686 data (static_cast<mxArray **> (mxArray::calloc (nfields * |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1687 get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1688 sizeof (mxArray *)))) |
5900 | 1689 { |
1690 init (keys); | |
1691 } | |
1692 | |
6686 | 1693 mxArray_struct (mwSize m, mwSize n, int num_keys_arg, const char **keys) |
5900 | 1694 : mxArray_matlab (mxSTRUCT_CLASS, m, n), nfields (num_keys_arg), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1695 fields (static_cast<char **> (mxArray::calloc (nfields, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1696 sizeof (char *)))), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1697 data (static_cast<mxArray **> (mxArray::calloc (nfields * |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1698 get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1699 sizeof (mxArray *)))) |
5900 | 1700 { |
1701 init (keys); | |
1702 } | |
1703 | |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1704 private: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1705 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1706 mxArray_struct (const mxArray_struct& val) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1707 : mxArray_matlab (val), nfields (val.nfields), |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1708 fields (static_cast<char **> (mxArray::malloc (nfields |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1709 * sizeof (char *)))), |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1710 data (static_cast<mxArray **> (mxArray::malloc (nfields * |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1711 get_number_of_elements () |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1712 * sizeof (mxArray *)))) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1713 { |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1714 for (int i = 0; i < nfields; i++) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1715 fields[i] = mxArray::strsave (val.fields[i]); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1716 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1717 mwSize nel = get_number_of_elements (); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1718 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1719 for (mwIndex i = 0; i < nel * nfields; i++) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1720 { |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1721 mxArray *ptr = val.data[i]; |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1722 data[i] = (ptr ? ptr->dup () : nullptr); |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1723 } |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1724 } |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1725 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1726 public: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1727 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1728 // No assignment! FIXME: should this be implemented? Note that we |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1729 // do have a copy constructor. |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1730 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1731 mxArray_struct& operator = (const mxArray_struct& val); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1732 |
5900 | 1733 void init (const char **keys) |
1734 { | |
1735 for (int i = 0; i < nfields; i++) | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1736 fields[i] = mxArray::strsave (keys[i]); |
5900 | 1737 } |
1738 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1739 mxArray_base * dup (void) const { return new mxArray_struct (*this); } |
5900 | 1740 |
1741 ~mxArray_struct (void) | |
1742 { | |
1743 for (int i = 0; i < nfields; i++) | |
1744 mxFree (fields[i]); | |
1745 | |
1746 mxFree (fields); | |
1747 | |
6686 | 1748 mwSize ntot = nfields * get_number_of_elements (); |
1749 | |
1750 for (mwIndex i = 0; i < ntot; i++) | |
5905 | 1751 delete data[i]; |
5900 | 1752 |
1753 mxFree (data); | |
1754 } | |
1755 | |
1756 int add_field (const char *key) | |
1757 { | |
1758 int retval = -1; | |
1759 | |
1760 if (valid_key (key)) | |
1761 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1762 nfields++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1763 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1764 fields = static_cast<char **> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1765 (mxRealloc (fields, nfields * sizeof (char *))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1766 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1767 if (fields) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1768 { |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1769 fields[nfields-1] = mxArray::strsave (key); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1770 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1771 mwSize nel = get_number_of_elements (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1772 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1773 mwSize ntot = nfields * nel; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1774 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1775 mxArray **new_data; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1776 new_data = static_cast<mxArray **> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1777 (mxArray::malloc (ntot * sizeof (mxArray *))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1778 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1779 if (new_data) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1780 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1781 mwIndex j = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1782 mwIndex k = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1783 mwIndex n = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1784 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1785 for (mwIndex i = 0; i < ntot; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1786 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1787 if (++n == nfields) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1788 { |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1789 new_data[j++] = nullptr; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1790 n = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1791 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1792 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1793 new_data[j++] = data[k++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1794 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1795 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1796 mxFree (data); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1797 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1798 data = new_data; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1799 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1800 retval = nfields - 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1801 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1802 } |
5900 | 1803 } |
1804 | |
1805 return retval; | |
1806 } | |
1807 | |
1808 void remove_field (int key_num) | |
1809 { | |
1810 if (key_num >= 0 && key_num < nfields) | |
1811 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1812 mwSize nel = get_number_of_elements (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1813 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1814 mwSize ntot = nfields * nel; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1815 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1816 int new_nfields = nfields - 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1817 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1818 char **new_fields = static_cast<char **> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1819 (mxArray::malloc (new_nfields * sizeof (char *))); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1820 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1821 mxArray **new_data = static_cast<mxArray **> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1822 (mxArray::malloc (new_nfields * nel |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1823 * sizeof (mxArray *))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1824 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1825 for (int i = 0; i < key_num; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1826 new_fields[i] = fields[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1827 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1828 for (int i = key_num + 1; i < nfields; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1829 new_fields[i-1] = fields[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1830 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1831 if (new_nfields > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1832 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1833 mwIndex j = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1834 mwIndex k = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1835 mwIndex n = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1836 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1837 for (mwIndex i = 0; i < ntot; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1838 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1839 if (n == key_num) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1840 k++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1841 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1842 new_data[j++] = data[k++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1843 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1844 if (++n == nfields) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1845 n = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1846 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1847 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1848 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1849 nfields = new_nfields; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1850 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1851 mxFree (fields); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1852 mxFree (data); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1853 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1854 fields = new_fields; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1855 data = new_data; |
5900 | 1856 } |
1857 } | |
1858 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1859 mxArray * get_field_by_number (mwIndex index, int key_num) const |
5900 | 1860 { |
6187 | 1861 return key_num >= 0 && key_num < nfields |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1862 ? data[nfields * index + key_num] : nullptr; |
5900 | 1863 } |
1864 | |
6686 | 1865 void set_field_by_number (mwIndex index, int key_num, mxArray *val); |
5900 | 1866 |
1867 int get_number_of_fields (void) const { return nfields; } | |
1868 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1869 const char * get_field_name_by_number (int key_num) const |
5900 | 1870 { |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1871 return key_num >= 0 && key_num < nfields ? fields[key_num] : nullptr; |
5900 | 1872 } |
1873 | |
1874 int get_field_number (const char *key) const | |
1875 { | |
1876 int retval = -1; | |
1877 | |
1878 for (int i = 0; i < nfields; i++) | |
1879 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1880 if (! strcmp (key, fields[i])) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1881 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1882 retval = i; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1883 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1884 } |
5900 | 1885 } |
1886 | |
1887 return retval; | |
1888 } | |
1889 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1890 void * get_data (void) const { return data; } |
5900 | 1891 |
1892 void set_data (void *data_arg) { data = static_cast<mxArray **> (data_arg); } | |
1893 | |
5907 | 1894 octave_value as_octave_value (void) const |
1895 { | |
1896 dim_vector dv = dims_to_dim_vector (); | |
1897 | |
1898 string_vector keys (fields, nfields); | |
1899 | |
25922
34e82a829fdd
Create scalar structs of size 1x1 with MEX interface (bug #54799).
Rik <rik@octave.org>
parents:
25751
diff
changeset
|
1900 octave_map m (dv); |
5907 | 1901 |
6686 | 1902 mwSize ntot = nfields * get_number_of_elements (); |
5907 | 1903 |
1904 for (int i = 0; i < nfields; i++) | |
1905 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1906 Cell c (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1907 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1908 octave_value *p = c.fortran_vec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1909 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1910 mwIndex k = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1911 for (mwIndex j = i; j < ntot; j += nfields) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1912 p[k++] = mxArray::as_octave_value (data[j]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1913 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1914 m.assign (keys[i], c); |
5907 | 1915 } |
1916 | |
1917 return m; | |
1918 } | |
1919 | |
5900 | 1920 private: |
1921 | |
1922 int nfields; | |
1923 | |
1924 char **fields; | |
1925 | |
1926 mxArray **data; | |
1927 }; | |
1928 | |
1929 // Matlab-style cell arrays. | |
1930 | |
1931 class mxArray_cell : public mxArray_matlab | |
1932 { | |
1933 public: | |
1934 | |
6686 | 1935 mxArray_cell (mwSize ndims_arg, const mwSize *dims_arg) |
5900 | 1936 : mxArray_matlab (mxCELL_CLASS, ndims_arg, dims_arg), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1937 data (static_cast<mxArray **> (mxArray::calloc (get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1938 sizeof (mxArray *)))) { } |
5900 | 1939 |
1940 mxArray_cell (const dim_vector& dv) | |
1941 : mxArray_matlab (mxCELL_CLASS, dv), | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1942 data (static_cast<mxArray **> (mxArray::calloc (get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1943 sizeof (mxArray *)))) { } |
5900 | 1944 |
6686 | 1945 mxArray_cell (mwSize m, mwSize n) |
5900 | 1946 : mxArray_matlab (mxCELL_CLASS, m, n), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1947 data (static_cast<mxArray **> (mxArray::calloc (get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1948 sizeof (mxArray *)))) { } |
5900 | 1949 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1950 private: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1951 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1952 mxArray_cell (const mxArray_cell& val) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1953 : mxArray_matlab (val), |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1954 data (static_cast<mxArray **> (mxArray::malloc (get_number_of_elements () |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1955 * sizeof (mxArray *)))) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1956 { |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1957 mwSize nel = get_number_of_elements (); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1958 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1959 for (mwIndex i = 0; i < nel; i++) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1960 { |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1961 mxArray *ptr = val.data[i]; |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1962 data[i] = (ptr ? ptr->dup () : nullptr); |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1963 } |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1964 } |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1965 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1966 public: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1967 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1968 // No assignment! FIXME: should this be implemented? Note that we |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1969 // do have a copy constructor. |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1970 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1971 mxArray_cell& operator = (const mxArray_cell&); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
1972 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1973 mxArray_base * dup (void) const { return new mxArray_cell (*this); } |
5900 | 1974 |
1975 ~mxArray_cell (void) | |
1976 { | |
6686 | 1977 mwSize nel = get_number_of_elements (); |
1978 | |
22449
e337b8e3592c
Fix double free causing segfault in mxSetDimensions (bug #49010).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
1979 for (mwIndex i = 0; i < nel; i++) |
5905 | 1980 delete data[i]; |
5900 | 1981 |
1982 mxFree (data); | |
1983 } | |
1984 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1985 mxArray * get_cell (mwIndex idx) const |
6187 | 1986 { |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
1987 return idx >= 0 && idx < get_number_of_elements () ? data[idx] : nullptr; |
6187 | 1988 } |
5907 | 1989 |
6686 | 1990 void set_cell (mwIndex idx, mxArray *val); |
5907 | 1991 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1992 void * get_data (void) const { return data; } |
5907 | 1993 |
1994 void set_data (void *data_arg) { data = static_cast<mxArray **> (data_arg); } | |
1995 | |
5900 | 1996 octave_value as_octave_value (void) const |
1997 { | |
1998 dim_vector dv = dims_to_dim_vector (); | |
1999 | |
2000 Cell c (dv); | |
2001 | |
6686 | 2002 mwSize nel = get_number_of_elements (); |
5900 | 2003 |
2004 octave_value *p = c.fortran_vec (); | |
2005 | |
6686 | 2006 for (mwIndex i = 0; i < nel; i++) |
5907 | 2007 p[i] = mxArray::as_octave_value (data[i]); |
5900 | 2008 |
2009 return c; | |
2010 } | |
2011 | |
2012 private: | |
2013 | |
2014 mxArray **data; | |
2015 }; | |
2016 | |
2017 // ------------------------------------------------------------------ | |
2018 | |
2019 mxArray::mxArray (const octave_value& ov) | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2020 : rep (new mxArray_octave_value (ov)), name (nullptr) { } |
5900 | 2021 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2022 mxArray::mxArray (mxClassID id, mwSize ndims, const mwSize *dims, |
22464
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2023 mxComplexity flag, bool init) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2024 : rep (new mxArray_number (id, ndims, dims, flag, init)), name (nullptr) { } |
5900 | 2025 |
2026 mxArray::mxArray (mxClassID id, const dim_vector& dv, mxComplexity flag) | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2027 : rep (new mxArray_number (id, dv, flag)), name (nullptr) { } |
5900 | 2028 |
22464
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2029 mxArray::mxArray (mxClassID id, mwSize m, mwSize n, |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2030 mxComplexity flag, bool init) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2031 : rep (new mxArray_number (id, m, n, flag, init)), name (nullptr) { } |
5900 | 2032 |
2033 mxArray::mxArray (mxClassID id, double val) | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2034 : rep (new mxArray_number (id, val)), name (nullptr) { } |
5900 | 2035 |
2036 mxArray::mxArray (mxClassID id, mxLogical val) | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2037 : rep (new mxArray_number (id, val)), name (nullptr) { } |
5900 | 2038 |
2039 mxArray::mxArray (const char *str) | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2040 : rep (new mxArray_number (str)), name (nullptr) { } |
5900 | 2041 |
6686 | 2042 mxArray::mxArray (mwSize m, const char **str) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2043 : rep (new mxArray_number (m, str)), name (nullptr) { } |
5900 | 2044 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2045 mxArray::mxArray (mxClassID id, mwSize m, mwSize n, mwSize nzmax, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2046 mxComplexity flag) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2047 : rep (new mxArray_sparse (id, m, n, nzmax, flag)), name (nullptr) { } |
5900 | 2048 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2049 mxArray::mxArray (mwSize ndims, const mwSize *dims, int num_keys, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2050 const char **keys) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2051 : rep (new mxArray_struct (ndims, dims, num_keys, keys)), name (nullptr) { } |
5900 | 2052 |
2053 mxArray::mxArray (const dim_vector& dv, int num_keys, const char **keys) | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2054 : rep (new mxArray_struct (dv, num_keys, keys)), name (nullptr) { } |
5900 | 2055 |
6686 | 2056 mxArray::mxArray (mwSize m, mwSize n, int num_keys, const char **keys) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2057 : rep (new mxArray_struct (m, n, num_keys, keys)), name (nullptr) { } |
5900 | 2058 |
6686 | 2059 mxArray::mxArray (mwSize ndims, const mwSize *dims) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2060 : rep (new mxArray_cell (ndims, dims)), name (nullptr) { } |
5900 | 2061 |
2062 mxArray::mxArray (const dim_vector& dv) | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2063 : rep (new mxArray_cell (dv)), name (nullptr) { } |
5900 | 2064 |
6686 | 2065 mxArray::mxArray (mwSize m, mwSize n) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2066 : rep (new mxArray_cell (m, n)), name (nullptr) { } |
5900 | 2067 |
2068 mxArray::~mxArray (void) | |
2069 { | |
2070 mxFree (name); | |
2071 | |
2072 delete rep; | |
2073 } | |
2074 | |
2075 void | |
2076 mxArray::set_name (const char *name_arg) | |
2077 { | |
2078 mxFree (name); | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
2079 name = mxArray::strsave (name_arg); |
5900 | 2080 } |
2081 | |
5907 | 2082 octave_value |
25451
f84755f24ccd
allow NULL mxArray* to be returned as undefined from fcn calls (bug #54096)
John W. Eaton <jwe@octave.org>
parents:
25450
diff
changeset
|
2083 mxArray::as_octave_value (const mxArray *ptr, bool null_is_empty) |
5907 | 2084 { |
25451
f84755f24ccd
allow NULL mxArray* to be returned as undefined from fcn calls (bug #54096)
John W. Eaton <jwe@octave.org>
parents:
25450
diff
changeset
|
2085 static const octave_value empty_matrix = Matrix (); |
f84755f24ccd
allow NULL mxArray* to be returned as undefined from fcn calls (bug #54096)
John W. Eaton <jwe@octave.org>
parents:
25450
diff
changeset
|
2086 |
f84755f24ccd
allow NULL mxArray* to be returned as undefined from fcn calls (bug #54096)
John W. Eaton <jwe@octave.org>
parents:
25450
diff
changeset
|
2087 return (ptr |
f84755f24ccd
allow NULL mxArray* to be returned as undefined from fcn calls (bug #54096)
John W. Eaton <jwe@octave.org>
parents:
25450
diff
changeset
|
2088 ? ptr->as_octave_value () |
f84755f24ccd
allow NULL mxArray* to be returned as undefined from fcn calls (bug #54096)
John W. Eaton <jwe@octave.org>
parents:
25450
diff
changeset
|
2089 : (null_is_empty ? empty_matrix : octave_value ())); |
5907 | 2090 } |
2091 | |
2092 octave_value | |
2093 mxArray::as_octave_value (void) const | |
2094 { | |
2095 return rep->as_octave_value (); | |
2096 } | |
2097 | |
5900 | 2098 void |
2099 mxArray::maybe_mutate (void) const | |
2100 { | |
2101 if (rep->is_octave_value ()) | |
2102 { | |
2103 // The mutate function returns a pointer to a complete new | |
2104 // mxArray object (or 0, if no mutation happened). We just want | |
2105 // to replace the existing rep with the rep from the new object. | |
2106 | |
2107 mxArray *new_val = rep->mutate (); | |
2108 | |
2109 if (new_val) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2110 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2111 delete rep; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2112 rep = new_val->rep; |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2113 new_val->rep = nullptr; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2114 delete new_val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2115 } |
5900 | 2116 } |
2117 } | |
2118 | |
2119 // ------------------------------------------------------------------ | |
2120 | |
6686 | 2121 // A class to manage calls to MEX functions. Mostly deals with memory |
5900 | 2122 // management. |
5864 | 2123 |
2124 class mex | |
2125 { | |
2126 public: | |
2127 | |
6068 | 2128 mex (octave_mex_function *f) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
2129 : curr_mex_fcn (f), memlist (), arraylist (), fname (nullptr) { } |
5864 | 2130 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
2131 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
2132 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
2133 mex (const mex&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
2134 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
2135 mex& operator = (const mex&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
2136 |
5864 | 2137 ~mex (void) |
2138 { | |
20771
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2139 // We can't use mex::free here because it modifies memlist. |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2140 while (! memlist.empty ()) |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2141 { |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
2142 auto p = memlist.begin (); |
20771
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2143 xfree (*p); |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2144 memlist.erase (p); |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2145 } |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2146 |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2147 // We can't use mex::free_value here because it modifies arraylist. |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2148 while (! arraylist.empty ()) |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2149 { |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
2150 auto p = arraylist.begin (); |
20771
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2151 delete *p; |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2152 arraylist.erase (p); |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2153 } |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2154 |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2155 if (! (memlist.empty () && arraylist.empty ())) |
5905 | 2156 error ("mex: %s: cleanup failed", function_name ()); |
5900 | 2157 |
2158 mxFree (fname); | |
5864 | 2159 } |
2160 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
2161 const char * function_name (void) const |
5900 | 2162 { |
2163 if (! fname) | |
2164 { | |
27206
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
2165 octave::tree_evaluator& tw |
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
2166 = octave::__get_evaluator__ ("mex::function_name"); |
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
2167 |
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
2168 octave_function *fcn = tw.current_function (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2169 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2170 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2171 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2172 std::string nm = fcn->name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2173 fname = mxArray::strsave (nm.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2174 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2175 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2176 fname = mxArray::strsave ("unknown"); |
5900 | 2177 } |
2178 | |
2179 return fname; | |
2180 } | |
2181 | |
6071 | 2182 // Allocate memory. |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
2183 void * malloc_unmarked (size_t n) |
5900 | 2184 { |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2185 void *ptr = std::malloc (n); |
5900 | 2186 |
2187 if (! ptr) | |
2188 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2189 // FIXME: could use "octave_new_handler();" instead |
26159
aa678451b758
Silence compiler warning about incorrect format specifier (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26113
diff
changeset
|
2190 error ("%s: failed to allocate %zd bytes of memory", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2191 function_name (), n); |
5900 | 2192 } |
2193 | |
2194 global_mark (ptr); | |
2195 | |
2196 return ptr; | |
2197 } | |
2198 | |
6071 | 2199 // Allocate memory to be freed on exit. |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
2200 void * malloc (size_t n) |
5900 | 2201 { |
2202 void *ptr = malloc_unmarked (n); | |
2203 | |
2204 mark (ptr); | |
2205 | |
2206 return ptr; | |
2207 } | |
2208 | |
6071 | 2209 // Allocate memory and initialize to 0. |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
2210 void * calloc_unmarked (size_t n, size_t t) |
5900 | 2211 { |
2212 void *ptr = malloc_unmarked (n*t); | |
2213 | |
2214 memset (ptr, 0, n*t); | |
2215 | |
2216 return ptr; | |
2217 } | |
2218 | |
6071 | 2219 // Allocate memory to be freed on exit and initialize to 0. |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
2220 void * calloc (size_t n, size_t t) |
5900 | 2221 { |
2222 void *ptr = calloc_unmarked (n, t); | |
2223 | |
2224 mark (ptr); | |
2225 | |
2226 return ptr; | |
2227 } | |
2228 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21743
diff
changeset
|
2229 // Reallocate a pointer obtained from malloc or calloc. |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21743
diff
changeset
|
2230 // If the pointer is NULL, allocate using malloc. |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21743
diff
changeset
|
2231 // We don't need an "unmarked" version of this. |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
2232 void * realloc (void *ptr, size_t n) |
5900 | 2233 { |
10225
477d05b0a739
mxRealloc: Allocate new memory on NULL argument
David Grundberg <davidg@cs.umu.se>
parents:
10127
diff
changeset
|
2234 void *v; |
477d05b0a739
mxRealloc: Allocate new memory on NULL argument
David Grundberg <davidg@cs.umu.se>
parents:
10127
diff
changeset
|
2235 |
477d05b0a739
mxRealloc: Allocate new memory on NULL argument
David Grundberg <davidg@cs.umu.se>
parents:
10127
diff
changeset
|
2236 if (ptr) |
5900 | 2237 { |
26438
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2238 auto p_local = memlist.find (ptr); |
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2239 auto p_global = global_memlist.find (ptr); |
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2240 |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2241 v = std::realloc (ptr, n); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2242 |
26438
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2243 if (v) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2244 { |
26438
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2245 if (p_local != memlist.end ()) |
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2246 { |
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2247 memlist.erase (p_local); |
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2248 memlist.insert (v); |
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2249 } |
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2250 |
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2251 if (p_global != global_memlist.end ()) |
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2252 { |
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2253 global_memlist.erase (p_global); |
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2254 global_memlist.insert (v); |
c048a6ac0f79
mex.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2255 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2256 } |
5900 | 2257 } |
10225
477d05b0a739
mxRealloc: Allocate new memory on NULL argument
David Grundberg <davidg@cs.umu.se>
parents:
10127
diff
changeset
|
2258 else |
477d05b0a739
mxRealloc: Allocate new memory on NULL argument
David Grundberg <davidg@cs.umu.se>
parents:
10127
diff
changeset
|
2259 v = malloc (n); |
5900 | 2260 |
2261 return v; | |
2262 } | |
2263 | |
2264 // Free a pointer obtained from malloc or calloc. | |
2265 void free (void *ptr) | |
2266 { | |
2267 if (ptr) | |
2268 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2269 unmark (ptr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2270 |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
2271 auto p = global_memlist.find (ptr); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2272 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2273 if (p != global_memlist.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2274 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2275 global_memlist.erase (p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2276 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2277 xfree (ptr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2278 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2279 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2280 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2281 p = foreign_memlist.find (ptr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2282 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2283 if (p != foreign_memlist.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2284 foreign_memlist.erase (p); |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
2285 #if defined (DEBUG) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2286 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2287 warning ("mxFree: skipping memory not allocated by mxMalloc, mxCalloc, or mxRealloc"); |
11276
475e90eb4ff1
mex::free: don't warn about skipping memory not allocated by mx{M,C,Re}alloc
John W. Eaton <jwe@octave.org>
parents:
11132
diff
changeset
|
2288 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2289 } |
5900 | 2290 } |
2291 } | |
2292 | |
7172 | 2293 // Mark a pointer to be freed on exit. |
2294 void mark (void *ptr) | |
2295 { | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
2296 #if defined (DEBUG) |
7172 | 2297 if (memlist.find (ptr) != memlist.end ()) |
2298 warning ("%s: double registration ignored", function_name ()); | |
2299 #endif | |
2300 | |
2301 memlist.insert (ptr); | |
2302 } | |
2303 | |
2304 // Unmark a pointer to be freed on exit, either because it was | |
2305 // made persistent, or because it was already freed. | |
2306 void unmark (void *ptr) | |
2307 { | |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
2308 auto p = memlist.find (ptr); |
7172 | 2309 |
2310 if (p != memlist.end ()) | |
2311 memlist.erase (p); | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
2312 #if defined (DEBUG) |
7172 | 2313 else |
2314 warning ("%s: value not marked", function_name ()); | |
2315 #endif | |
2316 } | |
5900 | 2317 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
2318 mxArray * mark_array (mxArray *ptr) |
6065 | 2319 { |
2320 arraylist.insert (ptr); | |
2321 return ptr; | |
2322 } | |
2323 | |
6071 | 2324 void unmark_array (mxArray *ptr) |
2325 { | |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
2326 auto p = arraylist.find (ptr); |
6071 | 2327 |
2328 if (p != arraylist.end ()) | |
2329 arraylist.erase (p); | |
2330 } | |
2331 | |
7179 | 2332 // Mark a pointer as one we allocated. |
2333 void mark_foreign (void *ptr) | |
2334 { | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
2335 #if defined (DEBUG) |
7179 | 2336 if (foreign_memlist.find (ptr) != foreign_memlist.end ()) |
2337 warning ("%s: double registration ignored", function_name ()); | |
2338 #endif | |
2339 | |
2340 foreign_memlist.insert (ptr); | |
2341 } | |
2342 | |
2343 // Unmark a pointer as one we allocated. | |
2344 void unmark_foreign (void *ptr) | |
2345 { | |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
2346 auto p = foreign_memlist.find (ptr); |
7179 | 2347 |
2348 if (p != foreign_memlist.end ()) | |
2349 foreign_memlist.erase (p); | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
2350 #if defined (DEBUG) |
7179 | 2351 else |
2352 warning ("%s: value not marked", function_name ()); | |
2353 #endif | |
2354 | |
2355 } | |
2356 | |
5900 | 2357 // Make a new array value and initialize from an octave value; it will be |
2358 // freed on exit unless marked as persistent. | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
2359 mxArray * make_value (const octave_value& ov) |
5900 | 2360 { |
6065 | 2361 return mark_array (new mxArray (ov)); |
5900 | 2362 } |
2363 | |
2364 // Free an array and its contents. | |
6065 | 2365 bool free_value (mxArray *ptr) |
5900 | 2366 { |
6065 | 2367 bool inlist = false; |
2368 | |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
2369 auto p = arraylist.find (ptr); |
5905 | 2370 |
2371 if (p != arraylist.end ()) | |
2372 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2373 inlist = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2374 arraylist.erase (p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2375 delete ptr; |
5905 | 2376 } |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
2377 #if defined (DEBUG) |
5905 | 2378 else |
2379 warning ("mex::free_value: skipping memory not allocated by mex::make_value"); | |
2380 #endif | |
6065 | 2381 |
2382 return inlist; | |
5900 | 2383 } |
2384 | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
2385 octave_mex_function * current_mex_function (void) const |
6068 | 2386 { |
2387 return curr_mex_fcn; | |
2388 } | |
2389 | |
5900 | 2390 // 1 if error should be returned to MEX file, 0 if abort. |
22452
3a8af9d517de
Initialize MEX TrapFlag variable for Matlab compatibility.
Rik <rik@octave.org>
parents:
22451
diff
changeset
|
2391 int trap_feval_error = 0; |
5864 | 2392 |
2393 private: | |
2394 | |
6068 | 2395 // Pointer to the mex function that corresponds to this mex context. |
2396 octave_mex_function *curr_mex_fcn; | |
2397 | |
5900 | 2398 // List of memory resources that need to be freed upon exit. |
2399 std::set<void *> memlist; | |
2400 | |
7179 | 2401 // List of mxArray objects that need to be freed upon exit. |
5900 | 2402 std::set<mxArray *> arraylist; |
2403 | |
7179 | 2404 // List of memory resources we know about, but that were allocated |
2405 // elsewhere. | |
2406 std::set<void *> foreign_memlist; | |
2407 | |
5900 | 2408 // The name of the currently executing function. |
2409 mutable char *fname; | |
2410 | |
2411 // List of memory resources we allocated. | |
2412 static std::set<void *> global_memlist; | |
2413 | |
2414 // Mark a pointer as one we allocated. | |
5905 | 2415 void global_mark (void *ptr) |
5900 | 2416 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
2417 #if defined (DEBUG) |
5905 | 2418 if (global_memlist.find (ptr) != global_memlist.end ()) |
2419 warning ("%s: double registration ignored", function_name ()); | |
5864 | 2420 #endif |
5900 | 2421 |
5905 | 2422 global_memlist.insert (ptr); |
5864 | 2423 } |
2424 | |
5900 | 2425 // Unmark a pointer as one we allocated. |
5905 | 2426 void global_unmark (void *ptr) |
5864 | 2427 { |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
2428 auto p = global_memlist.find (ptr); |
5905 | 2429 |
2430 if (p != global_memlist.end ()) | |
2431 global_memlist.erase (p); | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
2432 #if defined (DEBUG) |
5905 | 2433 else |
2434 warning ("%s: value not marked", function_name ()); | |
5900 | 2435 #endif |
2436 | |
5864 | 2437 } |
2438 }; | |
2439 | |
5900 | 2440 // List of memory resources we allocated. |
2441 std::set<void *> mex::global_memlist; | |
2442 | |
2443 // Current context. | |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
2444 mex *mex_context = nullptr; |
5900 | 2445 |
2446 void * | |
2447 mxArray::malloc (size_t n) | |
2448 { | |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2449 return mex_context ? mex_context->malloc_unmarked (n) : std::malloc (n); |
5900 | 2450 } |
2451 | |
2452 void * | |
2453 mxArray::calloc (size_t n, size_t t) | |
2454 { | |
6065 | 2455 return mex_context ? mex_context->calloc_unmarked (n, t) : ::calloc (n, t); |
5900 | 2456 } |
2457 | |
7179 | 2458 static inline void * |
2459 maybe_mark_foreign (void *ptr) | |
2460 { | |
2461 if (mex_context) | |
2462 mex_context->mark_foreign (ptr); | |
2463 | |
2464 return ptr; | |
2465 } | |
2466 | |
6071 | 2467 static inline mxArray * |
2468 maybe_unmark_array (mxArray *ptr) | |
2469 { | |
2470 if (mex_context) | |
2471 mex_context->unmark_array (ptr); | |
2472 | |
2473 return ptr; | |
2474 } | |
2475 | |
7172 | 2476 static inline void * |
2477 maybe_unmark (void *ptr) | |
2478 { | |
2479 if (mex_context) | |
2480 mex_context->unmark (ptr); | |
2481 | |
2482 return ptr; | |
2483 } | |
2484 | |
6071 | 2485 void |
6686 | 2486 mxArray_struct::set_field_by_number (mwIndex index, int key_num, mxArray *val) |
6071 | 2487 { |
6187 | 2488 if (key_num >= 0 && key_num < nfields) |
25450
66b72fbf2845
Backed out changeset 97e64c23fd07 (bug #54096)
John W. Eaton <jwe@octave.org>
parents:
25445
diff
changeset
|
2489 data[nfields * index + key_num] = maybe_unmark_array (val); |
6071 | 2490 } |
2491 | |
2492 void | |
6686 | 2493 mxArray_cell::set_cell (mwIndex idx, mxArray *val) |
6071 | 2494 { |
6187 | 2495 if (idx >= 0 && idx < get_number_of_elements ()) |
25450
66b72fbf2845
Backed out changeset 97e64c23fd07 (bug #54096)
John W. Eaton <jwe@octave.org>
parents:
25445
diff
changeset
|
2496 data[idx] = maybe_unmark_array (val); |
6071 | 2497 } |
2498 | |
5900 | 2499 // ------------------------------------------------------------------ |
2500 | |
2501 // C interface to mxArray objects: | |
2502 | |
2503 // Floating point predicates. | |
2504 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2505 bool |
5900 | 2506 mxIsFinite (const double v) |
2507 { | |
2508 return lo_ieee_finite (v) != 0; | |
2509 } | |
2510 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2511 bool |
5900 | 2512 mxIsInf (const double v) |
2513 { | |
2514 return lo_ieee_isinf (v) != 0; | |
2515 } | |
2516 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2517 bool |
5900 | 2518 mxIsNaN (const double v) |
2519 { | |
2520 return lo_ieee_isnan (v) != 0; | |
2521 } | |
2522 | |
2523 double | |
2524 mxGetEps (void) | |
2525 { | |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
2526 return std::numeric_limits<double>::epsilon (); |
5900 | 2527 } |
2528 | |
2529 double | |
2530 mxGetInf (void) | |
2531 { | |
2532 return lo_ieee_inf_value (); | |
2533 } | |
2534 | |
2535 double | |
2536 mxGetNaN (void) | |
2537 { | |
2538 return lo_ieee_nan_value (); | |
2539 } | |
2540 | |
2541 // Memory management. | |
2542 void * | |
2543 mxCalloc (size_t n, size_t size) | |
2544 { | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
2545 return mex_context ? mex_context->calloc (n, size) : ::calloc (n, size); |
5900 | 2546 } |
2547 | |
2548 void * | |
2549 mxMalloc (size_t n) | |
2550 { | |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2551 return mex_context ? mex_context->malloc (n) : std::malloc (n); |
5900 | 2552 } |
2553 | |
2554 void * | |
2555 mxRealloc (void *ptr, size_t size) | |
2556 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2557 return mex_context ? mex_context->realloc (ptr, size) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2558 : std::realloc (ptr, size); |
5900 | 2559 } |
2560 | |
2561 void | |
2562 mxFree (void *ptr) | |
5864 | 2563 { |
5900 | 2564 if (mex_context) |
2565 mex_context->free (ptr); | |
5864 | 2566 else |
6071 | 2567 xfree (ptr); |
5900 | 2568 } |
6065 | 2569 |
2570 static inline mxArray * | |
2571 maybe_mark_array (mxArray *ptr) | |
2572 { | |
2573 return mex_context ? mex_context->mark_array (ptr) : ptr; | |
2574 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2575 |
5900 | 2576 // Constructors. |
2577 mxArray * | |
6686 | 2578 mxCreateCellArray (mwSize ndims, const mwSize *dims) |
5900 | 2579 { |
6065 | 2580 return maybe_mark_array (new mxArray (ndims, dims)); |
5900 | 2581 } |
2582 | |
2583 mxArray * | |
6686 | 2584 mxCreateCellMatrix (mwSize m, mwSize n) |
5900 | 2585 { |
6065 | 2586 return maybe_mark_array (new mxArray (m, n)); |
5900 | 2587 } |
2588 | |
2589 mxArray * | |
6686 | 2590 mxCreateCharArray (mwSize ndims, const mwSize *dims) |
5900 | 2591 { |
6065 | 2592 return maybe_mark_array (new mxArray (mxCHAR_CLASS, ndims, dims)); |
5864 | 2593 } |
2594 | |
5900 | 2595 mxArray * |
6686 | 2596 mxCreateCharMatrixFromStrings (mwSize m, const char **str) |
5900 | 2597 { |
6065 | 2598 return maybe_mark_array (new mxArray (m, str)); |
5900 | 2599 } |
2600 | |
2601 mxArray * | |
6686 | 2602 mxCreateDoubleMatrix (mwSize m, mwSize n, mxComplexity flag) |
5900 | 2603 { |
6065 | 2604 return maybe_mark_array (new mxArray (mxDOUBLE_CLASS, m, n, flag)); |
5900 | 2605 } |
2606 | |
2607 mxArray * | |
2608 mxCreateDoubleScalar (double val) | |
2609 { | |
6065 | 2610 return maybe_mark_array (new mxArray (mxDOUBLE_CLASS, val)); |
5900 | 2611 } |
2612 | |
2613 mxArray * | |
6686 | 2614 mxCreateLogicalArray (mwSize ndims, const mwSize *dims) |
5864 | 2615 { |
6065 | 2616 return maybe_mark_array (new mxArray (mxLOGICAL_CLASS, ndims, dims)); |
5900 | 2617 } |
2618 | |
2619 mxArray * | |
6686 | 2620 mxCreateLogicalMatrix (mwSize m, mwSize n) |
5900 | 2621 { |
6065 | 2622 return maybe_mark_array (new mxArray (mxLOGICAL_CLASS, m, n)); |
5900 | 2623 } |
2624 | |
2625 mxArray * | |
7577
ba8fcc115fee
mex.cc: arg to mxCreateLogicalScalar is now mxLogical
John W. Eaton <jwe@octave.org>
parents:
7357
diff
changeset
|
2626 mxCreateLogicalScalar (mxLogical val) |
5900 | 2627 { |
6065 | 2628 return maybe_mark_array (new mxArray (mxLOGICAL_CLASS, val)); |
5900 | 2629 } |
2630 | |
2631 mxArray * | |
6686 | 2632 mxCreateNumericArray (mwSize ndims, const mwSize *dims, mxClassID class_id, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2633 mxComplexity flag) |
5900 | 2634 { |
6065 | 2635 return maybe_mark_array (new mxArray (class_id, ndims, dims, flag)); |
5864 | 2636 } |
2637 | |
5900 | 2638 mxArray * |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2639 mxCreateNumericMatrix (mwSize m, mwSize n, mxClassID class_id, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2640 mxComplexity flag) |
5900 | 2641 { |
6065 | 2642 return maybe_mark_array (new mxArray (class_id, m, n, flag)); |
5900 | 2643 } |
2644 | |
2645 mxArray * | |
22464
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2646 mxCreateUninitNumericArray (mwSize ndims, const mwSize *dims, |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2647 mxClassID class_id, mxComplexity flag) |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2648 { |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2649 return maybe_mark_array (new mxArray (class_id, ndims, dims, flag, false)); |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2650 } |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2651 |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2652 mxArray * |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2653 mxCreateUninitNumericMatrix (mwSize m, mwSize n, mxClassID class_id, |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2654 mxComplexity flag) |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2655 { |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2656 return maybe_mark_array (new mxArray (class_id, m, n, flag, false)); |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2657 } |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2658 |
1d2960b5efe6
Add new MEX fcns mxCreateUninitNumericArray, mxCreateUninitNumericMatrix.
Rik <rik@octave.org>
parents:
22462
diff
changeset
|
2659 mxArray * |
6686 | 2660 mxCreateSparse (mwSize m, mwSize n, mwSize nzmax, mxComplexity flag) |
5900 | 2661 { |
6065 | 2662 return maybe_mark_array (new mxArray (mxDOUBLE_CLASS, m, n, nzmax, flag)); |
5900 | 2663 } |
2664 | |
2665 mxArray * | |
6686 | 2666 mxCreateSparseLogicalMatrix (mwSize m, mwSize n, mwSize nzmax) |
5900 | 2667 { |
6065 | 2668 return maybe_mark_array (new mxArray (mxLOGICAL_CLASS, m, n, nzmax)); |
5900 | 2669 } |
2670 | |
2671 mxArray * | |
2672 mxCreateString (const char *str) | |
2673 { | |
6065 | 2674 return maybe_mark_array (new mxArray (str)); |
5900 | 2675 } |
2676 | |
2677 mxArray * | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2678 mxCreateStructArray (mwSize ndims, const mwSize *dims, int num_keys, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2679 const char **keys) |
5900 | 2680 { |
6065 | 2681 return maybe_mark_array (new mxArray (ndims, dims, num_keys, keys)); |
5900 | 2682 } |
5864 | 2683 |
2684 mxArray * | |
6686 | 2685 mxCreateStructMatrix (mwSize m, mwSize n, int num_keys, const char **keys) |
5900 | 2686 { |
6065 | 2687 return maybe_mark_array (new mxArray (m, n, num_keys, keys)); |
5900 | 2688 } |
2689 | |
2690 // Copy constructor. | |
2691 mxArray * | |
2692 mxDuplicateArray (const mxArray *ptr) | |
2693 { | |
11277
7d5351fc575a
mex.cc: convert mxArray_octave_value to matlab style representation when duplicating
John W. Eaton <jwe@octave.org>
parents:
11276
diff
changeset
|
2694 return maybe_mark_array (ptr->dup ()); |
5900 | 2695 } |
2696 | |
2697 // Destructor. | |
2698 void | |
2699 mxDestroyArray (mxArray *ptr) | |
2700 { | |
6065 | 2701 if (! (mex_context && mex_context->free_value (ptr))) |
2702 delete ptr; | |
5900 | 2703 } |
2704 | |
2705 // Type Predicates. | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2706 bool |
5900 | 2707 mxIsCell (const mxArray *ptr) |
2708 { | |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23553
diff
changeset
|
2709 return ptr->iscell (); |
5900 | 2710 } |
2711 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2712 bool |
5900 | 2713 mxIsChar (const mxArray *ptr) |
2714 { | |
2715 return ptr->is_char (); | |
2716 } | |
2717 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2718 bool |
5900 | 2719 mxIsClass (const mxArray *ptr, const char *name) |
2720 { | |
2721 return ptr->is_class (name); | |
2722 } | |
2723 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2724 bool |
5900 | 2725 mxIsComplex (const mxArray *ptr) |
2726 { | |
2727 return ptr->is_complex (); | |
2728 } | |
2729 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2730 bool |
5900 | 2731 mxIsDouble (const mxArray *ptr) |
2732 { | |
2733 return ptr->is_double (); | |
2734 } | |
2735 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2736 bool |
11100
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
2737 mxIsFunctionHandle (const mxArray *ptr) |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
2738 { |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
2739 return ptr->is_function_handle (); |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
2740 } |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
2741 |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2742 bool |
5900 | 2743 mxIsInt16 (const mxArray *ptr) |
2744 { | |
2745 return ptr->is_int16 (); | |
2746 } | |
2747 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2748 bool |
5900 | 2749 mxIsInt32 (const mxArray *ptr) |
2750 { | |
2751 return ptr->is_int32 (); | |
2752 } | |
2753 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2754 bool |
5900 | 2755 mxIsInt64 (const mxArray *ptr) |
2756 { | |
2757 return ptr->is_int64 (); | |
2758 } | |
2759 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2760 bool |
5900 | 2761 mxIsInt8 (const mxArray *ptr) |
2762 { | |
2763 return ptr->is_int8 (); | |
2764 } | |
2765 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2766 bool |
5900 | 2767 mxIsLogical (const mxArray *ptr) |
2768 { | |
2769 return ptr->is_logical (); | |
2770 } | |
2771 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2772 bool |
5900 | 2773 mxIsNumeric (const mxArray *ptr) |
2774 { | |
2775 return ptr->is_numeric (); | |
2776 } | |
2777 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2778 bool |
5900 | 2779 mxIsSingle (const mxArray *ptr) |
2780 { | |
2781 return ptr->is_single (); | |
2782 } | |
2783 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2784 bool |
5900 | 2785 mxIsSparse (const mxArray *ptr) |
2786 { | |
2787 return ptr->is_sparse (); | |
2788 } | |
2789 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2790 bool |
5900 | 2791 mxIsStruct (const mxArray *ptr) |
2792 { | |
2793 return ptr->is_struct (); | |
2794 } | |
2795 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2796 bool |
5900 | 2797 mxIsUint16 (const mxArray *ptr) |
2798 { | |
2799 return ptr->is_uint16 (); | |
2800 } | |
2801 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2802 bool |
5900 | 2803 mxIsUint32 (const mxArray *ptr) |
2804 { | |
2805 return ptr->is_uint32 (); | |
2806 } | |
2807 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2808 bool |
5900 | 2809 mxIsUint64 (const mxArray *ptr) |
2810 { | |
2811 return ptr->is_uint64 (); | |
2812 } | |
2813 | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2814 bool |
5900 | 2815 mxIsUint8 (const mxArray *ptr) |
2816 { | |
2817 return ptr->is_uint8 (); | |
2818 } | |
2819 | |
2820 // Odd type+size predicate. | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2821 bool |
5900 | 2822 mxIsLogicalScalar (const mxArray *ptr) |
2823 { | |
2824 return ptr->is_logical_scalar (); | |
2825 } | |
2826 | |
2827 // Odd type+size+value predicate. | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2828 bool |
5900 | 2829 mxIsLogicalScalarTrue (const mxArray *ptr) |
2830 { | |
2831 return ptr->is_logical_scalar_true (); | |
2832 } | |
2833 | |
2834 // Size predicate. | |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2835 bool |
5900 | 2836 mxIsEmpty (const mxArray *ptr) |
2837 { | |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
2838 return ptr->isempty (); |
5900 | 2839 } |
2840 | |
22462
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
2841 bool |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
2842 mxIsScalar (const mxArray *ptr) |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
2843 { |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
2844 return ptr->is_scalar (); |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
2845 } |
6cb7813e5b2f
Add new mxIsScalar function for MEX API.
Rik <rik@octave.org>
parents:
22454
diff
changeset
|
2846 |
20527
2d9ec16fa960
Print error, rather than aborting, if mex function mxIsFromGlobalWS is used (bug #46070).
Rik <rik@octave.org>
parents:
20362
diff
changeset
|
2847 // FIXME: Just plain odd thing to ask of a value. |
2d9ec16fa960
Print error, rather than aborting, if mex function mxIsFromGlobalWS is used (bug #46070).
Rik <rik@octave.org>
parents:
20362
diff
changeset
|
2848 // Still, Octave is incompatible because it does not implement this. |
22465
6149f6b34cbc
Change all mxIs* functions in MEX API to return bool rather than int.
Rik <rik@octave.org>
parents:
22464
diff
changeset
|
2849 bool |
20527
2d9ec16fa960
Print error, rather than aborting, if mex function mxIsFromGlobalWS is used (bug #46070).
Rik <rik@octave.org>
parents:
20362
diff
changeset
|
2850 mxIsFromGlobalWS (const mxArray * /*ptr*/) |
5900 | 2851 { |
20527
2d9ec16fa960
Print error, rather than aborting, if mex function mxIsFromGlobalWS is used (bug #46070).
Rik <rik@octave.org>
parents:
20362
diff
changeset
|
2852 mexErrMsgTxt ("mxIsFromGlobalWS() is unimplemented"); |
2d9ec16fa960
Print error, rather than aborting, if mex function mxIsFromGlobalWS is used (bug #46070).
Rik <rik@octave.org>
parents:
20362
diff
changeset
|
2853 |
5900 | 2854 return 0; |
2855 } | |
2856 | |
2857 // Dimension extractors. | |
6686 | 2858 size_t |
5900 | 2859 mxGetM (const mxArray *ptr) |
2860 { | |
2861 return ptr->get_m (); | |
2862 } | |
2863 | |
6686 | 2864 size_t |
5900 | 2865 mxGetN (const mxArray *ptr) |
2866 { | |
2867 return ptr->get_n (); | |
2868 } | |
2869 | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
2870 const mwSize * |
5900 | 2871 mxGetDimensions (const mxArray *ptr) |
5864 | 2872 { |
5900 | 2873 return ptr->get_dimensions (); |
2874 } | |
2875 | |
6686 | 2876 mwSize |
5900 | 2877 mxGetNumberOfDimensions (const mxArray *ptr) |
2878 { | |
2879 return ptr->get_number_of_dimensions (); | |
2880 } | |
2881 | |
6686 | 2882 size_t |
5900 | 2883 mxGetNumberOfElements (const mxArray *ptr) |
2884 { | |
2885 return ptr->get_number_of_elements (); | |
2886 } | |
2887 | |
2888 // Dimension setters. | |
2889 void | |
6686 | 2890 mxSetM (mxArray *ptr, mwSize m) |
5900 | 2891 { |
2892 ptr->set_m (m); | |
2893 } | |
2894 | |
2895 void | |
6686 | 2896 mxSetN (mxArray *ptr, mwSize n) |
5900 | 2897 { |
2898 ptr->set_n (n); | |
2899 } | |
2900 | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
2901 int |
10126
8687ce1c56da
Change signature of mxSetDimensions.
David Grundberg <davidg@cs.umu.se>
parents:
10066
diff
changeset
|
2902 mxSetDimensions (mxArray *ptr, const mwSize *dims, mwSize ndims) |
5900 | 2903 { |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
2904 return (ptr->set_dimensions (static_cast<mwSize *> |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
2905 (maybe_unmark (const_cast<mwSize *> (dims))), |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
2906 ndims)); |
5900 | 2907 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2908 |
5900 | 2909 // Data extractors. |
2910 double * | |
2911 mxGetPr (const mxArray *ptr) | |
2912 { | |
2913 return static_cast<double *> (ptr->get_data ()); | |
2914 } | |
2915 | |
2916 double * | |
2917 mxGetPi (const mxArray *ptr) | |
2918 { | |
2919 return static_cast<double *> (ptr->get_imag_data ()); | |
2920 } | |
2921 | |
2922 double | |
2923 mxGetScalar (const mxArray *ptr) | |
2924 { | |
6332 | 2925 return ptr->get_scalar (); |
5900 | 2926 } |
2927 | |
2928 mxChar * | |
2929 mxGetChars (const mxArray *ptr) | |
2930 { | |
22471
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
2931 if (mxIsChar (ptr)) |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
2932 return static_cast<mxChar *> (ptr->get_data ()); |
667d353d1ab8
Clean up MEX API prototypes to match Matlab.
Rik <rik@octave.org>
parents:
22465
diff
changeset
|
2933 else |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
2934 return nullptr; |
5900 | 2935 } |
2936 | |
2937 mxLogical * | |
2938 mxGetLogicals (const mxArray *ptr) | |
2939 { | |
2940 return static_cast<mxLogical *> (ptr->get_data ()); | |
2941 } | |
2942 | |
2943 void * | |
2944 mxGetData (const mxArray *ptr) | |
2945 { | |
2946 return ptr->get_data (); | |
2947 } | |
2948 | |
2949 void * | |
2950 mxGetImagData (const mxArray *ptr) | |
2951 { | |
2952 return ptr->get_imag_data (); | |
2953 } | |
2954 | |
2955 // Data setters. | |
2956 void | |
2957 mxSetPr (mxArray *ptr, double *pr) | |
2958 { | |
7172 | 2959 ptr->set_data (maybe_unmark (pr)); |
5900 | 2960 } |
2961 | |
2962 void | |
2963 mxSetPi (mxArray *ptr, double *pi) | |
2964 { | |
7172 | 2965 ptr->set_imag_data (maybe_unmark (pi)); |
5864 | 2966 } |
2967 | |
5900 | 2968 void |
2969 mxSetData (mxArray *ptr, void *pr) | |
2970 { | |
7172 | 2971 ptr->set_data (maybe_unmark (pr)); |
5900 | 2972 } |
2973 | |
2974 void | |
2975 mxSetImagData (mxArray *ptr, void *pi) | |
2976 { | |
7172 | 2977 ptr->set_imag_data (maybe_unmark (pi)); |
5900 | 2978 } |
2979 | |
2980 // Classes. | |
2981 mxClassID | |
2982 mxGetClassID (const mxArray *ptr) | |
2983 { | |
2984 return ptr->get_class_id (); | |
2985 } | |
2986 | |
2987 const char * | |
2988 mxGetClassName (const mxArray *ptr) | |
2989 { | |
2990 return ptr->get_class_name (); | |
2991 } | |
2992 | |
2993 void | |
2994 mxSetClassName (mxArray *ptr, const char *name) | |
2995 { | |
2996 ptr->set_class_name (name); | |
2997 } | |
2998 | |
23893
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
2999 void |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
3000 mxSetProperty (mxArray *ptr, mwIndex idx, const char *property_name, |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
3001 const mxArray *property_value) |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
3002 { |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
3003 ptr->set_property (idx, property_name, property_value); |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
3004 } |
75eff5b667b3
new mxSetProperty function for MEX API
John W. Eaton <jwe@octave.org>
parents:
23891
diff
changeset
|
3005 |
23891
142a9c7e403a
Avoid CamelCase in variables names in mxGetProperty cset (bd9e719f04cc).
Rik <rik@octave.org>
parents:
23884
diff
changeset
|
3006 mxArray * |
142a9c7e403a
Avoid CamelCase in variables names in mxGetProperty cset (bd9e719f04cc).
Rik <rik@octave.org>
parents:
23884
diff
changeset
|
3007 mxGetProperty (const mxArray *ptr, mwIndex idx, const char *property_name) |
23884
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
3008 { |
23891
142a9c7e403a
Avoid CamelCase in variables names in mxGetProperty cset (bd9e719f04cc).
Rik <rik@octave.org>
parents:
23884
diff
changeset
|
3009 return ptr->get_property (idx, property_name); |
23884
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
3010 } |
bd9e719f04cc
new mxGetProperty function for MEX API
Piotr Held <pjheld@gmail.com>
parents:
23795
diff
changeset
|
3011 |
5900 | 3012 // Cell support. |
3013 mxArray * | |
6686 | 3014 mxGetCell (const mxArray *ptr, mwIndex idx) |
5900 | 3015 { |
3016 return ptr->get_cell (idx); | |
3017 } | |
3018 | |
3019 void | |
6686 | 3020 mxSetCell (mxArray *ptr, mwIndex idx, mxArray *val) |
5900 | 3021 { |
3022 ptr->set_cell (idx, val); | |
3023 } | |
3024 | |
3025 // Sparse support. | |
6686 | 3026 mwIndex * |
5900 | 3027 mxGetIr (const mxArray *ptr) |
3028 { | |
3029 return ptr->get_ir (); | |
3030 } | |
3031 | |
6686 | 3032 mwIndex * |
5900 | 3033 mxGetJc (const mxArray *ptr) |
3034 { | |
3035 return ptr->get_jc (); | |
3036 } | |
3037 | |
6686 | 3038 mwSize |
5900 | 3039 mxGetNzmax (const mxArray *ptr) |
3040 { | |
3041 return ptr->get_nzmax (); | |
3042 } | |
3043 | |
3044 void | |
6686 | 3045 mxSetIr (mxArray *ptr, mwIndex *ir) |
5900 | 3046 { |
19739
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
3047 ptr->set_ir (static_cast<mwIndex *> (maybe_unmark (ir))); |
5900 | 3048 } |
3049 | |
3050 void | |
6686 | 3051 mxSetJc (mxArray *ptr, mwIndex *jc) |
5900 | 3052 { |
7172 | 3053 ptr->set_jc (static_cast<mwIndex *> (maybe_unmark (jc))); |
5900 | 3054 } |
3055 | |
3056 void | |
6686 | 3057 mxSetNzmax (mxArray *ptr, mwSize nzmax) |
5900 | 3058 { |
3059 ptr->set_nzmax (nzmax); | |
3060 } | |
3061 | |
3062 // Structure support. | |
3063 int | |
3064 mxAddField (mxArray *ptr, const char *key) | |
3065 { | |
3066 return ptr->add_field (key); | |
3067 } | |
3068 | |
3069 void | |
3070 mxRemoveField (mxArray *ptr, int key_num) | |
3071 { | |
3072 ptr->remove_field (key_num); | |
3073 } | |
5864 | 3074 |
3075 mxArray * | |
6686 | 3076 mxGetField (const mxArray *ptr, mwIndex index, const char *key) |
5900 | 3077 { |
3078 int key_num = mxGetFieldNumber (ptr, key); | |
3079 return mxGetFieldByNumber (ptr, index, key_num); | |
3080 } | |
3081 | |
3082 mxArray * | |
6686 | 3083 mxGetFieldByNumber (const mxArray *ptr, mwIndex index, int key_num) |
5864 | 3084 { |
5900 | 3085 return ptr->get_field_by_number (index, key_num); |
5864 | 3086 } |
3087 | |
5900 | 3088 void |
6686 | 3089 mxSetField (mxArray *ptr, mwIndex index, const char *key, mxArray *val) |
5900 | 3090 { |
3091 int key_num = mxGetFieldNumber (ptr, key); | |
3092 mxSetFieldByNumber (ptr, index, key_num, val); | |
3093 } | |
5864 | 3094 |
3095 void | |
6686 | 3096 mxSetFieldByNumber (mxArray *ptr, mwIndex index, int key_num, mxArray *val) |
5864 | 3097 { |
5900 | 3098 ptr->set_field_by_number (index, key_num, val); |
3099 } | |
3100 | |
3101 int | |
3102 mxGetNumberOfFields (const mxArray *ptr) | |
3103 { | |
3104 return ptr->get_number_of_fields (); | |
5864 | 3105 } |
3106 | |
5900 | 3107 const char * |
3108 mxGetFieldNameByNumber (const mxArray *ptr, int key_num) | |
5864 | 3109 { |
5900 | 3110 return ptr->get_field_name_by_number (key_num); |
3111 } | |
3112 | |
3113 int | |
3114 mxGetFieldNumber (const mxArray *ptr, const char *key) | |
3115 { | |
3116 return ptr->get_field_number (key); | |
5864 | 3117 } |
3118 | |
5900 | 3119 int |
6686 | 3120 mxGetString (const mxArray *ptr, char *buf, mwSize buflen) |
5900 | 3121 { |
3122 return ptr->get_string (buf, buflen); | |
3123 } | |
3124 | |
3125 char * | |
3126 mxArrayToString (const mxArray *ptr) | |
5864 | 3127 { |
5900 | 3128 return ptr->array_to_string (); |
3129 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3130 |
6686 | 3131 mwIndex |
3132 mxCalcSingleSubscript (const mxArray *ptr, mwSize nsubs, mwIndex *subs) | |
5900 | 3133 { |
3134 return ptr->calc_single_subscript (nsubs, subs); | |
5864 | 3135 } |
5900 | 3136 |
6686 | 3137 size_t |
5900 | 3138 mxGetElementSize (const mxArray *ptr) |
3139 { | |
3140 return ptr->get_element_size (); | |
3141 } | |
3142 | |
3143 // ------------------------------------------------------------------ | |
5864 | 3144 |
3145 typedef void (*cmex_fptr) (int nlhs, mxArray **plhs, int nrhs, mxArray **prhs); | |
23498
647705ffb110
use F77_INT type for integer args to Fortran MEX functions
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
3146 typedef F77_RET_T (*fmex_fptr) (F77_INT& nlhs, mxArray **plhs, |
647705ffb110
use F77_INT type for integer args to Fortran MEX functions
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
3147 F77_INT& nrhs, mxArray **prhs); |
5864 | 3148 |
3149 octave_value_list | |
23499
7d89f815d78e
modernize octave_mex_function
John W. Eaton <jwe@octave.org>
parents:
23498
diff
changeset
|
3150 call_mex (octave_mex_function& mex_fcn, const octave_value_list& args, |
7d89f815d78e
modernize octave_mex_function
John W. Eaton <jwe@octave.org>
parents:
23498
diff
changeset
|
3151 int nargout_arg) |
5864 | 3152 { |
20771
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3153 octave_quit (); |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3154 |
5900 | 3155 // Use at least 1 for nargout since even for zero specified args, |
3156 // still want to be able to return an ans. | |
5864 | 3157 |
8806 | 3158 volatile int nargout = nargout_arg; |
3159 | |
5864 | 3160 int nargin = args.length (); |
5900 | 3161 OCTAVE_LOCAL_BUFFER (mxArray *, argin, nargin); |
5864 | 3162 for (int i = 0; i < nargin; i++) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
3163 argin[i] = nullptr; |
5864 | 3164 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
3165 int nout = (nargout == 0 ? 1 : nargout); |
5900 | 3166 OCTAVE_LOCAL_BUFFER (mxArray *, argout, nout); |
5864 | 3167 for (int i = 0; i < nout; i++) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
3168 argout[i] = nullptr; |
5864 | 3169 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
3170 octave::unwind_protect_safe frame; |
5905 | 3171 |
3172 // Save old mex pointer. | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
3173 frame.protect_var (mex_context); |
5905 | 3174 |
23499
7d89f815d78e
modernize octave_mex_function
John W. Eaton <jwe@octave.org>
parents:
23498
diff
changeset
|
3175 mex context (&mex_fcn); |
5900 | 3176 |
5864 | 3177 for (int i = 0; i < nargin; i++) |
3178 argin[i] = context.make_value (args(i)); | |
3179 | |
20771
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3180 mex_context = &context; |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3181 |
23499
7d89f815d78e
modernize octave_mex_function
John W. Eaton <jwe@octave.org>
parents:
23498
diff
changeset
|
3182 void *mex_fcn_ptr = mex_fcn.mex_fcn_ptr (); |
7d89f815d78e
modernize octave_mex_function
John W. Eaton <jwe@octave.org>
parents:
23498
diff
changeset
|
3183 |
7d89f815d78e
modernize octave_mex_function
John W. Eaton <jwe@octave.org>
parents:
23498
diff
changeset
|
3184 if (mex_fcn.is_fmex ()) |
5864 | 3185 { |
23499
7d89f815d78e
modernize octave_mex_function
John W. Eaton <jwe@octave.org>
parents:
23498
diff
changeset
|
3186 fmex_fptr fcn = reinterpret_cast<fmex_fptr> (mex_fcn_ptr); |
20771
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3187 |
23498
647705ffb110
use F77_INT type for integer args to Fortran MEX functions
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
3188 F77_INT tmp_nargout = nargout; |
647705ffb110
use F77_INT type for integer args to Fortran MEX functions
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
3189 F77_INT tmp_nargin = nargin; |
20771
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3190 |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3191 fcn (tmp_nargout, argout, tmp_nargin, argin); |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3192 } |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3193 else |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3194 { |
23499
7d89f815d78e
modernize octave_mex_function
John W. Eaton <jwe@octave.org>
parents:
23498
diff
changeset
|
3195 cmex_fptr fcn = reinterpret_cast<cmex_fptr> (mex_fcn_ptr); |
20771
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3196 |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3197 fcn (nargout, argout, nargin, argin); |
5864 | 3198 } |
3199 | |
3200 // Convert returned array entries back into octave values. | |
3201 | |
3202 octave_value_list retval; | |
3203 | |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
3204 if (nargout == 0 && argout[0]) |
5864 | 3205 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
3206 // We have something for ans. |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
3207 nargout = 1; |
5864 | 3208 } |
3209 | |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
3210 retval.resize (nargout); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
3211 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
3212 for (int i = 0; i < nargout; i++) |
25451
f84755f24ccd
allow NULL mxArray* to be returned as undefined from fcn calls (bug #54096)
John W. Eaton <jwe@octave.org>
parents:
25450
diff
changeset
|
3213 retval(i) = mxArray::as_octave_value (argout[i], false); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
3214 |
5864 | 3215 return retval; |
3216 } | |
3217 | |
3218 // C interface to mex functions: | |
3219 | |
3220 const char * | |
3221 mexFunctionName (void) | |
3222 { | |
5900 | 3223 return mex_context ? mex_context->function_name () : "unknown"; |
3224 } | |
3225 | |
3226 int | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
3227 mexCallMATLAB (int nargout, mxArray *argout[], int nargin, |
15373
b5d0a47c171c
* mex.cc (mexCallMATLAB): Remove stray const added in 93dff6435fe1 (bug #37342).
John W. Eaton <jwe@octave.org>
parents:
15354
diff
changeset
|
3228 mxArray *argin[], const char *fname) |
5900 | 3229 { |
3230 octave_value_list args; | |
3231 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3232 // FIXME: do we need unwind protect to clean up args? Off hand, I |
5900 | 3233 // would say that this problem is endemic to Octave and we will |
3234 // continue to have memory leaks after Ctrl-C until proper exception | |
20771
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3235 // handling is implemented. |
5900 | 3236 |
21151
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
3237 // FIXME: Proper exception handling has been implemented (Jan. 2016). |
bfd5e48c41a1
Rename local error in mex I/F from invalid_type_error to err_invalid_type.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
3238 // Can this code be re-factored? |
5900 | 3239 args.resize (nargin); |
3240 | |
3241 for (int i = 0; i < nargin; i++) | |
5907 | 3242 args(i) = mxArray::as_octave_value (argin[i]); |
5900 | 3243 |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
3244 octave::interpreter& interp = octave::__get_interpreter__ ("mexCallMATLAB"); |
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
3245 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3246 bool execution_error = false; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3247 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3248 octave_value_list retval; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3249 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3250 try |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3251 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
3252 retval = octave::feval (fname, args, nargout); |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3253 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3254 catch (const octave::execution_exception&) |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3255 { |
20771
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3256 if (mex_context->trap_feval_error) |
22450
2fb86778f78d
Return correct status from mexCallMATLAB when mexSetTrapFlag is 1 (bug #48949).
Rik <rik@octave.org>
parents:
22449
diff
changeset
|
3257 { |
27471 | 3258 // FIXME: is there a way to indicate what error occurred? |
3259 // Should the error message be displayed here? Do we need to | |
3260 // save the exception info for lasterror? | |
3261 | |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
3262 interp.recover_from_exception (); |
22450
2fb86778f78d
Return correct status from mexCallMATLAB when mexSetTrapFlag is 1 (bug #48949).
Rik <rik@octave.org>
parents:
22449
diff
changeset
|
3263 |
2fb86778f78d
Return correct status from mexCallMATLAB when mexSetTrapFlag is 1 (bug #48949).
Rik <rik@octave.org>
parents:
22449
diff
changeset
|
3264 execution_error = true; |
2fb86778f78d
Return correct status from mexCallMATLAB when mexSetTrapFlag is 1 (bug #48949).
Rik <rik@octave.org>
parents:
22449
diff
changeset
|
3265 } |
20771
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3266 else |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3267 { |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3268 args.resize (0); |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3269 retval.resize (0); |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3270 |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3271 throw; |
ed708a7ce0a2
simplify memory management for mex files (bug #46559)
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
3272 } |
5900 | 3273 } |
3274 | |
3275 int num_to_copy = retval.length (); | |
3276 | |
3277 if (nargout < retval.length ()) | |
3278 num_to_copy = nargout; | |
3279 | |
3280 for (int i = 0; i < num_to_copy; i++) | |
3281 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3282 // FIXME: it would be nice to avoid copying the value here, |
5900 | 3283 // but there is no way to steal memory from a matrix, never mind |
3284 // that matrix memory is allocated by new[] and mxArray memory | |
3285 // is allocated by malloc(). | |
22450
2fb86778f78d
Return correct status from mexCallMATLAB when mexSetTrapFlag is 1 (bug #48949).
Rik <rik@octave.org>
parents:
22449
diff
changeset
|
3286 argout[i] = mex_context->make_value (retval(i)); |
5900 | 3287 } |
3288 | |
3289 while (num_to_copy < nargout) | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23703
diff
changeset
|
3290 argout[num_to_copy++] = nullptr; |
5900 | 3291 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3292 return execution_error ? 1 : 0; |
5900 | 3293 } |
3294 | |
22451
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3295 mxArray * |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3296 mexCallMATLABWithTrap (int nargout, mxArray *argout[], int nargin, |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3297 mxArray *argin[], const char *fname) |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3298 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
3299 mxArray *mx = nullptr; |
22451
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3300 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
3301 int old_flag = (mex_context ? mex_context->trap_feval_error : 0); |
22451
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3302 mexSetTrapFlag (1); |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3303 if (mexCallMATLAB (nargout, argout, nargin, argin, fname)) |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3304 { |
22454
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3305 const char *field_names[] = {"identifier", "message", "case", "stack"}; |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3306 mx = mxCreateStructMatrix (1, 1, 4, field_names); |
22451
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3307 mxSetFieldByNumber (mx, 0, 0, mxCreateString ("Octave:MEX")); |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3308 std::string msg = "mexCallMATLABWithTrap: function call <" |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3309 + std::string (fname) + "> failed"; |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3310 mxSetFieldByNumber (mx, 0, 1, mxCreateString (msg.c_str ())); |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3311 mxSetFieldByNumber (mx, 0, 2, mxCreateCellMatrix (0, 0)); |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
3312 mxSetFieldByNumber (mx, 0, 3, mxCreateStructMatrix (0, 1, 0, nullptr)); |
22451
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3313 } |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3314 mexSetTrapFlag (old_flag); |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3315 |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3316 return mx; |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3317 } |
ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
Rik <rik@octave.org>
parents:
22450
diff
changeset
|
3318 |
5900 | 3319 void |
3320 mexSetTrapFlag (int flag) | |
3321 { | |
3322 if (mex_context) | |
3323 mex_context->trap_feval_error = flag; | |
3324 } | |
3325 | |
3326 int | |
3327 mexEvalString (const char *s) | |
3328 { | |
3329 int retval = 0; | |
3330 | |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
3331 octave::interpreter& interp = octave::__get_interpreter__ ("mexEvalString"); |
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
3332 |
5900 | 3333 int parse_status; |
22454
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3334 bool execution_error = false; |
5900 | 3335 |
3336 octave_value_list ret; | |
3337 | |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3338 try |
5900 | 3339 { |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25922
diff
changeset
|
3340 ret = interp.eval_string (std::string (s), false, parse_status, 0); |
5900 | 3341 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
3342 catch (const octave::execution_exception&) |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3343 { |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
3344 interp.recover_from_exception (); |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3345 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3346 execution_error = true; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3347 } |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3348 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3349 if (parse_status || execution_error) |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20527
diff
changeset
|
3350 retval = 1; |
5864 | 3351 |
3352 return retval; | |
3353 } | |
3354 | |
22454
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3355 mxArray * |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3356 mexEvalStringWithTrap (const char *s) |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3357 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
3358 mxArray *mx = nullptr; |
22454
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3359 |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
3360 octave::interpreter& interp = octave::__get_interpreter__ ("mexEvalString"); |
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
3361 |
22454
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3362 int parse_status; |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3363 bool execution_error = false; |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3364 |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3365 octave_value_list ret; |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3366 |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3367 try |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3368 { |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25922
diff
changeset
|
3369 ret = interp.eval_string (std::string (s), false, parse_status, 0); |
22454
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3370 } |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3371 catch (const octave::execution_exception&) |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3372 { |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
3373 interp.recover_from_exception (); |
22454
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3374 |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3375 execution_error = true; |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3376 } |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3377 |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3378 if (parse_status || execution_error) |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3379 { |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3380 const char *field_names[] = {"identifier", "message", "case", "stack"}; |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3381 mx = mxCreateStructMatrix (1, 1, 4, field_names); |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3382 mxSetFieldByNumber (mx, 0, 0, mxCreateString ("Octave:MEX")); |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3383 std::string msg = "mexEvalStringWithTrap: eval of <" |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3384 + std::string (s) + "> failed"; |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3385 mxSetFieldByNumber (mx, 0, 1, mxCreateString (msg.c_str ())); |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3386 mxSetFieldByNumber (mx, 0, 2, mxCreateCellMatrix (0, 0)); |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
3387 mxSetFieldByNumber (mx, 0, 3, mxCreateStructMatrix (0, 1, 0, nullptr)); |
22454
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3388 } |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3389 |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3390 return mx; |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3391 } |
8445f67a8123
Add function mexEvalStringWithTrap to MEX API.
Rik <rik@octave.org>
parents:
22452
diff
changeset
|
3392 |
5864 | 3393 void |
3394 mexErrMsgTxt (const char *s) | |
3395 { | |
25751
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3396 size_t len; |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3397 |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3398 if (s && (len = strlen (s)) > 0) |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3399 { |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3400 if (s[len - 1] == '\n') |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3401 { |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3402 std::string s_tmp (s, len - 1); |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3403 error ("%s: %s\n", mexFunctionName (), s_tmp.c_str ()); |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3404 } |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3405 else |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3406 error ("%s: %s", mexFunctionName (), s); |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3407 } |
5864 | 3408 else |
16851
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3409 { |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3410 // For compatibility with Matlab, print an empty message. |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3411 // Octave's error routine requires a non-null input so use a SPACE. |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3412 error (" "); |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3413 } |
5864 | 3414 } |
3415 | |
5879 | 3416 void |
6338 | 3417 mexErrMsgIdAndTxt (const char *id, const char *fmt, ...) |
5879 | 3418 { |
6338 | 3419 if (fmt && strlen (fmt) > 0) |
3420 { | |
3421 const char *fname = mexFunctionName (); | |
3422 size_t len = strlen (fname) + 2 + strlen (fmt) + 1; | |
3423 OCTAVE_LOCAL_BUFFER (char, tmpfmt, len); | |
3424 sprintf (tmpfmt, "%s: %s", fname, fmt); | |
3425 va_list args; | |
3426 va_start (args, fmt); | |
3427 verror_with_id (id, tmpfmt, args); | |
3428 va_end (args); | |
3429 } | |
5879 | 3430 else |
16851
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3431 { |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3432 // For compatibility with Matlab, print an empty message. |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3433 // Octave's error routine requires a non-null input so use a SPACE. |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3434 error (" "); |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3435 } |
5879 | 3436 } |
3437 | |
3438 void | |
3439 mexWarnMsgTxt (const char *s) | |
3440 { | |
25751
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3441 size_t len; |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3442 |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3443 if (s && (len = strlen (s)) > 0) |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3444 { |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3445 if (s[len - 1] == '\n') |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3446 { |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3447 std::string s_tmp (s, len - 1); |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3448 warning ("%s\n", s_tmp.c_str ()); |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3449 } |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3450 else |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3451 warning ("%s", s); |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3452 } |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3453 else |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3454 { |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3455 // For compatibility with Matlab, print an empty message. |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3456 // Octave's warning routine requires a non-null input so use a SPACE. |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3457 warning (" "); |
4bd60c9c6169
Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454).
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
3458 } |
5879 | 3459 } |
3460 | |
3461 void | |
6338 | 3462 mexWarnMsgIdAndTxt (const char *id, const char *fmt, ...) |
5879 | 3463 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3464 // FIXME: is this right? What does Matlab do if fmt is NULL or |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3465 // an empty string? |
6338 | 3466 |
3467 if (fmt && strlen (fmt) > 0) | |
3468 { | |
3469 const char *fname = mexFunctionName (); | |
3470 size_t len = strlen (fname) + 2 + strlen (fmt) + 1; | |
3471 OCTAVE_LOCAL_BUFFER (char, tmpfmt, len); | |
3472 sprintf (tmpfmt, "%s: %s", fname, fmt); | |
3473 va_list args; | |
3474 va_start (args, fmt); | |
3475 vwarning_with_id (id, tmpfmt, args); | |
3476 va_end (args); | |
3477 } | |
5879 | 3478 } |
5864 | 3479 |
10127
f21fdff5c906
Change signature of mexPrintf.
David Grundberg <davidg@cs.umu.se>
parents:
10126
diff
changeset
|
3480 int |
5864 | 3481 mexPrintf (const char *fmt, ...) |
3482 { | |
10127
f21fdff5c906
Change signature of mexPrintf.
David Grundberg <davidg@cs.umu.se>
parents:
10126
diff
changeset
|
3483 int retval; |
5864 | 3484 va_list args; |
3485 va_start (args, fmt); | |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25452
diff
changeset
|
3486 retval = octave::vformat (octave_stdout, fmt, args); |
5864 | 3487 va_end (args); |
10127
f21fdff5c906
Change signature of mexPrintf.
David Grundberg <davidg@cs.umu.se>
parents:
10126
diff
changeset
|
3488 return retval; |
5864 | 3489 } |
3490 | |
3491 mxArray * | |
5879 | 3492 mexGetVariable (const char *space, const char *name) |
5864 | 3493 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
3494 mxArray *retval = nullptr; |
5864 | 3495 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7577
diff
changeset
|
3496 octave_value val; |
5864 | 3497 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26438
diff
changeset
|
3498 octave::interpreter& interp = octave::__get_interpreter__ ("mexGetVariable"); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26438
diff
changeset
|
3499 |
5864 | 3500 if (! strcmp (space, "global")) |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26438
diff
changeset
|
3501 val = interp.global_varval (name); |
5864 | 3502 else |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7577
diff
changeset
|
3503 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3504 // FIXME: should this be in variables.cc? |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
3505 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
3506 octave::unwind_protect frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
3507 |
7901 | 3508 bool caller = ! strcmp (space, "caller"); |
3509 bool base = ! strcmp (space, "base"); | |
3510 | |
3511 if (caller || base) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3512 { |
16708
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3513 // MEX files don't create a separate frame in the call stack, |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3514 // so we are already in the "caller" frame. |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3515 |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3516 if (base) |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3517 { |
27206
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
3518 octave::tree_evaluator& tw = interp.get_evaluator (); |
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
3519 |
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
3520 frame.add_method (tw, &octave::tree_evaluator::restore_frame, |
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
3521 tw.current_call_stack_frame_number ()); |
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
3522 |
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
3523 tw.goto_base_frame (); |
16708
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3524 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3525 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26438
diff
changeset
|
3526 val = interp.varval (name); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3527 } |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7577
diff
changeset
|
3528 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3529 mexErrMsgTxt ("mexGetVariable: symbol table does not exist"); |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7577
diff
changeset
|
3530 } |
7336 | 3531 |
3532 if (val.is_defined ()) | |
5864 | 3533 { |
7336 | 3534 retval = mex_context->make_value (val); |
3535 | |
3536 retval->set_name (name); | |
5864 | 3537 } |
3538 | |
3539 return retval; | |
3540 } | |
3541 | |
5879 | 3542 const mxArray * |
3543 mexGetVariablePtr (const char *space, const char *name) | |
5864 | 3544 { |
5879 | 3545 return mexGetVariable (space, name); |
5864 | 3546 } |
3547 | |
5900 | 3548 int |
15353
5f3a69a309a7
fix decl of mexPutVariable
John W. Eaton <jwe@octave.org>
parents:
15351
diff
changeset
|
3549 mexPutVariable (const char *space, const char *name, const mxArray *ptr) |
5864 | 3550 { |
5900 | 3551 if (! ptr) |
3552 return 1; | |
3553 | |
3554 if (! name) | |
3555 return 1; | |
3556 | |
3557 if (name[0] == '\0') | |
3558 name = ptr->get_name (); | |
3559 | |
3560 if (! name || name[0] == '\0') | |
3561 return 1; | |
3562 | |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26438
diff
changeset
|
3563 octave::interpreter& interp = octave::__get_interpreter__ ("mexPutVariable"); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26438
diff
changeset
|
3564 |
5900 | 3565 if (! strcmp (space, "global")) |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26438
diff
changeset
|
3566 interp.global_assign (name, mxArray::as_octave_value (ptr)); |
5900 | 3567 else |
3568 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3569 // FIXME: should this be in variables.cc? |
7336 | 3570 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
3571 octave::unwind_protect frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
3572 |
7901 | 3573 bool caller = ! strcmp (space, "caller"); |
3574 bool base = ! strcmp (space, "base"); | |
3575 | |
3576 if (caller || base) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3577 { |
16708
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3578 // MEX files don't create a separate frame in the call stack, |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3579 // so we are already in the "caller" frame. |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3580 |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3581 if (base) |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3582 { |
27206
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
3583 octave::tree_evaluator& tw = interp.get_evaluator (); |
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
3584 |
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
3585 frame.add_method (tw, &octave::tree_evaluator::restore_frame, |
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
3586 tw.current_call_stack_frame_number ()); |
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
3587 |
4e4a9d7b436e
eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents:
27083
diff
changeset
|
3588 tw.goto_base_frame (); |
16708
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3589 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3590 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26438
diff
changeset
|
3591 interp.assign (name, mxArray::as_octave_value (ptr)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3592 } |
5900 | 3593 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3594 mexErrMsgTxt ("mexPutVariable: symbol table does not exist"); |
5900 | 3595 } |
3596 | |
3597 return 0; | |
5864 | 3598 } |
3599 | |
3600 void | |
5900 | 3601 mexMakeArrayPersistent (mxArray *ptr) |
5864 | 3602 { |
7172 | 3603 maybe_unmark_array (ptr); |
5864 | 3604 } |
5879 | 3605 |
5864 | 3606 void |
5900 | 3607 mexMakeMemoryPersistent (void *ptr) |
5864 | 3608 { |
7172 | 3609 maybe_unmark (ptr); |
5864 | 3610 } |
3611 | |
5900 | 3612 int |
6068 | 3613 mexAtExit (void (*f) (void)) |
5864 | 3614 { |
6068 | 3615 if (mex_context) |
3616 { | |
3617 octave_mex_function *curr_mex_fcn = mex_context->current_mex_function (); | |
3618 | |
3619 assert (curr_mex_fcn); | |
3620 | |
3621 curr_mex_fcn->atexit (f); | |
3622 } | |
3623 | |
5900 | 3624 return 0; |
5864 | 3625 } |
3626 | |
5900 | 3627 const mxArray * |
6595 | 3628 mexGet (double handle, const char *property) |
5864 | 3629 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
3630 mxArray *m = nullptr; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
3631 |
6595 | 3632 octave_value ret = get_property_from_handle (handle, property, "mexGet"); |
3633 | |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
3634 if (ret.is_defined ()) |
6595 | 3635 m = ret.as_mxArray (); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
3636 |
6595 | 3637 return m; |
5864 | 3638 } |
3639 | |
5900 | 3640 int |
3641 mexIsGlobal (const mxArray *ptr) | |
5864 | 3642 { |
5900 | 3643 return mxIsFromGlobalWS (ptr); |
5864 | 3644 } |
3645 | |
5900 | 3646 int |
3647 mexIsLocked (void) | |
5864 | 3648 { |
5900 | 3649 int retval = 0; |
3650 | |
3651 if (mex_context) | |
3652 { | |
3653 const char *fname = mexFunctionName (); | |
3654 | |
23703
6eb5f6199a5a
move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents:
23699
diff
changeset
|
3655 octave::interpreter& interp = octave::__get_interpreter__ ("mexIsLocked"); |
6eb5f6199a5a
move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents:
23699
diff
changeset
|
3656 |
6eb5f6199a5a
move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents:
23699
diff
changeset
|
3657 retval = interp.mislocked (fname); |
5900 | 3658 } |
3659 | |
3660 return retval; | |
5864 | 3661 } |
3662 | |
5900 | 3663 std::map<std::string,int> mex_lock_count; |
3664 | |
3665 void | |
3666 mexLock (void) | |
5864 | 3667 { |
5900 | 3668 if (mex_context) |
5864 | 3669 { |
5900 | 3670 const char *fname = mexFunctionName (); |
3671 | |
3672 if (mex_lock_count.find (fname) == mex_lock_count.end ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3673 mex_lock_count[fname] = 1; |
5900 | 3674 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3675 mex_lock_count[fname]++; |
5900 | 3676 |
23703
6eb5f6199a5a
move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents:
23699
diff
changeset
|
3677 octave::interpreter& interp = octave::__get_interpreter__ ("mexLock"); |
6eb5f6199a5a
move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents:
23699
diff
changeset
|
3678 |
6eb5f6199a5a
move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents:
23699
diff
changeset
|
3679 interp.mlock (); |
5864 | 3680 } |
3681 } | |
3682 | |
5900 | 3683 int |
6595 | 3684 mexSet (double handle, const char *property, mxArray *val) |
5900 | 3685 { |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27206
diff
changeset
|
3686 bool ret |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27206
diff
changeset
|
3687 = set_property_in_handle (handle, property, mxArray::as_octave_value (val), |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27206
diff
changeset
|
3688 "mexSet"); |
6595 | 3689 return (ret ? 0 : 1); |
5900 | 3690 } |
3691 | |
3692 void | |
3693 mexUnlock (void) | |
5864 | 3694 { |
5900 | 3695 if (mex_context) |
5864 | 3696 { |
5900 | 3697 const char *fname = mexFunctionName (); |
3698 | |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
3699 auto p = mex_lock_count.find (fname); |
5905 | 3700 |
6062 | 3701 if (p != mex_lock_count.end ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3702 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3703 int count = --mex_lock_count[fname]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3704 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3705 if (count == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3706 { |
23703
6eb5f6199a5a
move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents:
23699
diff
changeset
|
3707 octave::interpreter& interp |
6eb5f6199a5a
move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents:
23699
diff
changeset
|
3708 = octave::__get_interpreter__ ("mexUnLock"); |
6eb5f6199a5a
move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents:
23699
diff
changeset
|
3709 |
6eb5f6199a5a
move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents:
23699
diff
changeset
|
3710 interp.munlock (fname); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3711 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3712 mex_lock_count.erase (p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3713 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3714 } |
5864 | 3715 } |
3716 } |