Mercurial > octave
annotate src/toplev.cc @ 8377:25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 29 Oct 2008 16:52:10 +0100 |
parents | fa78cb8d8a5c |
children | 83b8c739d626 |
rev | line source |
---|---|
1683 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
4 2004, 2005, 2006, 2007 John W. Eaton | |
1683 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1683 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1683 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <cassert> | |
4489 | 29 #include <cerrno> |
1683 | 30 #include <cstdlib> |
31 #include <cstring> | |
4221 | 32 #include <new> |
1683 | 33 |
3503 | 34 #include <fstream> |
35 #include <iostream> | |
5765 | 36 #include <sstream> |
1728 | 37 #include <string> |
38 | |
1683 | 39 #ifdef HAVE_UNISTD_H |
2442 | 40 #ifdef HAVE_SYS_TYPES_H |
1683 | 41 #include <sys/types.h> |
2442 | 42 #endif |
1683 | 43 #include <unistd.h> |
44 #endif | |
45 | |
2926 | 46 #include "cmd-edit.h" |
47 #include "file-ops.h" | |
1683 | 48 #include "lo-error.h" |
2370 | 49 #include "lo-mappers.h" |
3020 | 50 #include "oct-env.h" |
4153 | 51 #include "quit.h" |
1755 | 52 #include "str-vec.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8347
diff
changeset
|
53 #include "oct-locbuf.h" |
1683 | 54 |
2492 | 55 #include <defaults.h> |
1683 | 56 #include "defun.h" |
57 #include "error.h" | |
58 #include "file-io.h" | |
59 #include "input.h" | |
60 #include "lex.h" | |
2492 | 61 #include <oct-conf.h> |
1742 | 62 #include "oct-hist.h" |
2162 | 63 #include "oct-map.h" |
2862 | 64 #include "oct-obj.h" |
1683 | 65 #include "pager.h" |
66 #include "parse.h" | |
67 #include "pathsearch.h" | |
68 #include "procstream.h" | |
2370 | 69 #include "ov.h" |
2985 | 70 #include "pt-jump.h" |
2982 | 71 #include "pt-stmt.h" |
1683 | 72 #include "sighandlers.h" |
73 #include "sysdep.h" | |
2693 | 74 #include "syswait.h" |
1750 | 75 #include "toplev.h" |
1683 | 76 #include "unwind-prot.h" |
77 #include "utils.h" | |
78 #include "variables.h" | |
2492 | 79 #include <version.h> |
1683 | 80 |
3020 | 81 // TRUE means we are exiting via the builtin exit or quit functions. |
82 static bool quitting_gracefully = false; | |
1683 | 83 |
4217 | 84 // TRUE means we are ready to interpret commands, but not everything |
85 // is ready for interactive use. | |
86 bool octave_interpreter_ready = false; | |
87 | |
4172 | 88 // TRUE means we've processed all the init code and we are good to go. |
89 bool octave_initialized = false; | |
90 | |
1683 | 91 // Current command to execute. |
92 tree_statement_list *global_command = 0; | |
93 | |
5743 | 94 octave_call_stack *octave_call_stack::instance = 0; |
95 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
96 int |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
97 octave_call_stack::do_current_line (void) const |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
98 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
99 tree_statement *stmt = do_top_statement (); |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
100 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
101 return stmt ? stmt->line () : -1; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
102 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
103 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
104 int |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
105 octave_call_stack::do_current_column (void) const |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
106 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
107 tree_statement *stmt = do_top_statement (); |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
108 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
109 return stmt ? stmt->column () : -1; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
110 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
111 |
7877 | 112 int |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
113 octave_call_stack::do_caller_user_code_line (void) const |
7877 | 114 { |
115 int retval = -1; | |
116 | |
7890 | 117 const_iterator p = cs.end (); |
118 | |
119 while (p != cs.begin ()) | |
7877 | 120 { |
7890 | 121 const call_stack_elt& elt = *(--p); |
7877 | 122 |
123 octave_function *f = elt.fcn; | |
124 | |
125 if (f && f->is_user_code ()) | |
126 { | |
127 tree_statement *stmt = elt.stmt; | |
128 | |
129 if (stmt) | |
130 { | |
131 retval = stmt->line (); | |
132 break; | |
133 } | |
134 } | |
135 } | |
136 | |
137 return retval; | |
138 } | |
139 | |
140 int | |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
141 octave_call_stack::do_caller_user_code_column (void) const |
7877 | 142 { |
143 int retval = -1; | |
144 | |
7890 | 145 const_iterator p = cs.end (); |
146 | |
147 while (p != cs.begin ()) | |
7877 | 148 { |
7890 | 149 const call_stack_elt& elt = *(--p); |
7877 | 150 |
151 octave_function *f = elt.fcn; | |
152 | |
153 if (f && f->is_user_code ()) | |
154 { | |
155 tree_statement *stmt = elt.stmt; | |
156 | |
157 if (stmt) | |
158 { | |
159 retval = stmt->column (); | |
160 break; | |
161 } | |
162 } | |
163 } | |
164 | |
165 return retval; | |
166 } | |
167 | |
7901 | 168 size_t |
169 octave_call_stack::do_num_user_code_frames (octave_idx_type& curr_user_frame) const | |
170 { | |
171 size_t retval = 0; | |
172 | |
173 curr_user_frame = 0; | |
174 | |
175 // Look for the caller of dbstack. | |
176 size_t frame = cs[curr_frame].prev; | |
177 | |
178 bool found = false; | |
179 | |
180 size_t k = cs.size (); | |
181 | |
182 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++) | |
183 { | |
184 octave_function *f = (*p).fcn; | |
185 | |
186 if (--k == frame) | |
187 found = true; | |
188 | |
189 if (f && f->is_user_code ()) | |
190 { | |
191 if (! found) | |
192 curr_user_frame++; | |
193 | |
194 retval++; | |
195 } | |
196 } | |
197 | |
198 // We counted how many user frames were not the one, in reverse. | |
199 // Now set curr_user_frame to be the index in the other direction. | |
200 curr_user_frame = retval - curr_user_frame - 1; | |
201 | |
202 return retval; | |
203 } | |
204 | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
205 octave_user_code * |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
206 octave_call_stack::do_caller_user_code (size_t nskip) const |
5744 | 207 { |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
208 octave_user_code *retval = 0; |
5744 | 209 |
7890 | 210 const_iterator p = cs.end (); |
211 | |
212 while (p != cs.begin ()) | |
5744 | 213 { |
7890 | 214 const call_stack_elt& elt = *(--p); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
215 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
216 octave_function *f = elt.fcn; |
5744 | 217 |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
218 if (f && f->is_user_code ()) |
5744 | 219 { |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
220 if (nskip > 0) |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
221 nskip--; |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
222 else |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
223 { |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
224 retval = dynamic_cast<octave_user_code *> (f); |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
225 break; |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
226 } |
5744 | 227 } |
228 } | |
229 | |
230 return retval; | |
231 } | |
232 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
233 Octave_map |
7901 | 234 octave_call_stack::do_backtrace (size_t nskip, |
235 octave_idx_type& curr_user_frame) const | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
236 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
237 Octave_map retval; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
238 |
7901 | 239 size_t user_code_frames = do_num_user_code_frames (curr_user_frame); |
240 | |
241 size_t nframes = nskip <= user_code_frames ? user_code_frames - nskip : 0; | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
242 |
7901 | 243 // Our list is reversed. |
244 curr_user_frame = nframes - curr_user_frame - 1; | |
245 | |
246 Cell keys (6, 1); | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
247 |
7901 | 248 keys(0) = "file"; |
249 keys(1) = "name"; | |
250 keys(2) = "line"; | |
251 keys(3) = "column"; | |
252 keys(4) = "scope"; | |
253 keys(5) = "context"; | |
7890 | 254 |
7901 | 255 Cell file (nframes, 1); |
256 Cell name (nframes, 1); | |
257 Cell line (nframes, 1); | |
258 Cell column (nframes, 1); | |
259 Cell scope (nframes, 1); | |
260 Cell context (nframes, 1); | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
261 |
7901 | 262 if (nframes > 0) |
263 { | |
264 int k = 0; | |
265 | |
266 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++) | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
267 { |
7901 | 268 const call_stack_elt& elt = *p; |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
269 |
7736 | 270 octave_function *f = elt.fcn; |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
271 |
7901 | 272 if (f && f->is_user_code ()) |
7736 | 273 { |
7901 | 274 if (nskip > 0) |
275 nskip--; | |
7736 | 276 else |
277 { | |
7901 | 278 scope(k) = elt.scope; |
279 context(k) = elt.context; | |
280 | |
281 file(k) = f->fcn_file_name (); | |
282 std::string parent_fcn_name = f->parent_fcn_name (); | |
283 if (parent_fcn_name == std::string ()) | |
284 name(k) = f->name (); | |
285 else | |
286 name(k) = f->parent_fcn_name () + Vfilemarker + f->name (); | |
287 | |
288 tree_statement *stmt = elt.stmt; | |
289 | |
290 if (stmt) | |
291 { | |
292 line(k) = stmt->line (); | |
293 column(k) = stmt->column (); | |
294 } | |
295 else | |
296 { | |
297 line(k) = -1; | |
298 column(k) = -1; | |
299 } | |
300 | |
301 k++; | |
7736 | 302 } |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
303 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
304 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
305 |
7736 | 306 retval.assign ("file", file); |
307 retval.assign ("name", name); | |
308 retval.assign ("line", line); | |
309 retval.assign ("column", column); | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
310 retval.assign ("scope", scope); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
311 retval.assign ("context", context); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
312 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
313 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
314 return retval; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
315 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
316 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
317 bool |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
318 octave_call_stack::do_goto_frame (size_t n, bool verbose) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
319 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
320 bool retval = false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
321 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
322 if (n < cs.size ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
323 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
324 retval = true; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
325 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
326 curr_frame = n; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
327 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
328 const call_stack_elt& elt = cs[n]; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
329 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
330 symbol_table::set_scope_and_context (elt.scope, elt.context); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
331 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
332 if (verbose) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
333 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
334 octave_function *f = elt.fcn; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
335 std::string nm = f ? f->name () : std::string ("<unknown>"); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
336 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
337 tree_statement *s = elt.stmt; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
338 int l = -1; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
339 int c = -1; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
340 if (s) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
341 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
342 l = s->line (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
343 c = s->column (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
344 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
345 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
346 octave_stdout << "stopped in " << nm |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
347 << " at line " << l << " column " << c |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
348 << " (" << elt.scope << "[" << elt.context << "])" |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
349 << std::endl; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
350 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
351 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
352 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
353 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
354 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
355 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
356 bool |
7901 | 357 octave_call_stack::do_goto_frame_relative (int nskip, bool verbose) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
358 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
359 bool retval = false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
360 |
7901 | 361 if (nskip == 0) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
362 retval = true; |
7890 | 363 else |
364 { | |
7901 | 365 int incr = nskip < 0 ? -1 : 1; |
366 | |
367 // Start looking with the caller of dbup/dbdown. | |
368 size_t frame = cs[curr_frame].prev; | |
369 | |
370 while (true) | |
371 { | |
372 if ((incr < 0 && frame == 0) || (incr > 0 && frame == cs.size () - 1)) | |
373 break; | |
374 | |
375 frame += incr; | |
376 | |
377 const call_stack_elt& elt = cs[frame]; | |
378 | |
379 octave_function *f = elt.fcn; | |
380 | |
381 if (f && f->is_user_code ()) | |
382 { | |
383 if (nskip > 0) | |
384 nskip--; | |
385 else if (nskip < 0) | |
386 nskip++; | |
387 | |
388 if (nskip == 0) | |
389 { | |
390 curr_frame = frame; | |
391 cs[cs.size () - 1].prev = curr_frame; | |
7890 | 392 |
7901 | 393 if (verbose) |
394 { | |
395 tree_statement *s = elt.stmt; | |
396 int l = -1; | |
397 int c = -1; | |
398 if (s) | |
399 { | |
400 l = s->line (); | |
401 c = s->column (); | |
402 } | |
403 | |
404 std::ostringstream buf; | |
405 buf << f->name () << ": " << " line " << l | |
406 << ", column " << c << std::endl; | |
407 | |
408 octave_stdout << buf.str (); | |
409 } | |
410 | |
411 retval = true; | |
412 break; | |
413 } | |
414 } | |
415 } | |
416 | |
417 // There is no need to set scope and context here. That will | |
418 // happen when the dbup/dbdown frame is popped and we jump to | |
419 // the new "prev" frame set above. | |
7890 | 420 } |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
421 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
422 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
423 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
424 |
5744 | 425 void |
7901 | 426 octave_call_stack::do_goto_caller_frame (void) |
427 { | |
428 size_t frame = curr_frame; | |
429 | |
430 bool skipped = false; | |
431 | |
432 while (frame != 0) | |
433 { | |
434 frame = cs[frame].prev; | |
435 | |
436 const call_stack_elt& elt = cs[frame]; | |
437 | |
438 octave_function *f = elt.fcn; | |
439 | |
440 if (f && f->is_user_code ()) | |
441 { | |
442 if (! skipped) | |
443 // We found the current user code frame, so skip it. | |
444 skipped = true; | |
445 else | |
446 { | |
447 // We found the caller user code frame. | |
448 call_stack_elt tmp (elt); | |
449 tmp.prev = curr_frame; | |
450 | |
451 curr_frame = cs.size (); | |
452 | |
453 cs.push_back (tmp); | |
454 | |
455 symbol_table::set_scope_and_context (tmp.scope, tmp.context); | |
456 | |
457 break; | |
458 } | |
459 } | |
460 } | |
461 } | |
462 | |
463 void | |
464 octave_call_stack::do_goto_base_frame (void) | |
465 { | |
466 call_stack_elt tmp (cs[0]); | |
467 tmp.prev = curr_frame; | |
468 | |
469 curr_frame = cs.size (); | |
470 | |
471 cs.push_back (tmp); | |
472 | |
473 symbol_table::set_scope_and_context (tmp.scope, tmp.context); | |
474 } | |
475 | |
476 void | |
8013
b3e667f1ab4c
call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
477 octave_call_stack::do_backtrace_error_message (void) const |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
478 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
479 if (error_state > 0) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
480 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
481 error_state = -1; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
482 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
483 error ("called from:"); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
484 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
485 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
486 if (! cs.empty ()) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
487 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
488 const call_stack_elt& elt = cs.back (); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
489 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
490 octave_function *fcn = elt.fcn; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
491 tree_statement *stmt = elt.stmt; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
492 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
493 std::string fcn_name = "?unknown?"; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
494 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
495 if (fcn) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
496 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
497 fcn_name = fcn->fcn_file_name (); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
498 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
499 if (fcn_name.empty ()) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
500 fcn_name = fcn->name (); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
501 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
502 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
503 int line = stmt ? stmt->line () : -1; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
504 int column = stmt ? stmt->column () : -1; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
505 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
506 error (" %s at line %d, column %d", |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
507 fcn_name.c_str (), line, column); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
508 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
509 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
510 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
511 void |
4180 | 512 recover_from_exception (void) |
513 { | |
514 can_interrupt = true; | |
4182 | 515 octave_interrupt_immediately = 0; |
4180 | 516 octave_interrupt_state = 0; |
5142 | 517 octave_signal_caught = 0; |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7409
diff
changeset
|
518 octave_exception_state = octave_no_exception; |
4180 | 519 octave_restore_signal_mask (); |
520 octave_catch_interrupts (); | |
521 } | |
522 | |
1907 | 523 int |
5189 | 524 main_loop (void) |
1907 | 525 { |
2016 | 526 octave_save_signal_mask (); |
527 | |
3020 | 528 can_interrupt = true; |
1907 | 529 |
5142 | 530 octave_signal_hook = octave_signal_handler; |
4429 | 531 octave_interrupt_hook = unwind_protect::run_all; |
532 octave_bad_alloc_hook = unwind_protect::run_all; | |
533 | |
2554 | 534 octave_catch_interrupts (); |
1907 | 535 |
4172 | 536 octave_initialized = true; |
537 | |
1907 | 538 // The big loop. |
539 | |
4153 | 540 int retval = 0; |
1907 | 541 do |
542 { | |
4180 | 543 try |
1907 | 544 { |
7336 | 545 symbol_table::reset_scope (); |
2620 | 546 |
4318 | 547 reset_error_handler (); |
548 | |
4153 | 549 reset_parser (); |
2620 | 550 |
4753 | 551 // This is the same as yyparse in parse.y. |
552 retval = octave_parse (); | |
2620 | 553 |
4153 | 554 if (retval == 0) |
555 { | |
7913
f46e73bcb85b
toplev.cc (main_loop): undo previous change; input.cc (get_debug_input): don't delete global_command here
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
556 if (global_command) |
3804 | 557 { |
7913
f46e73bcb85b
toplev.cc (main_loop): undo previous change; input.cc (get_debug_input): don't delete global_command here
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
558 global_command->eval (); |
3883 | 559 |
7913
f46e73bcb85b
toplev.cc (main_loop): undo previous change; input.cc (get_debug_input): don't delete global_command here
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
560 delete global_command; |
3883 | 561 |
7913
f46e73bcb85b
toplev.cc (main_loop): undo previous change; input.cc (get_debug_input): don't delete global_command here
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
562 global_command = 0; |
3883 | 563 |
4171 | 564 OCTAVE_QUIT; |
565 | |
3883 | 566 if (! (interactive || forced_interactive)) |
567 { | |
4207 | 568 bool quit = (tree_return_command::returning |
569 || tree_break_command::breaking); | |
4153 | 570 |
4207 | 571 if (tree_return_command::returning) |
572 tree_return_command::returning = 0; | |
4153 | 573 |
4207 | 574 if (tree_break_command::breaking) |
575 tree_break_command::breaking--; | |
4153 | 576 |
577 if (quit) | |
578 break; | |
579 } | |
580 | |
581 if (error_state) | |
582 { | |
583 if (! (interactive || forced_interactive)) | |
584 { | |
585 // We should exit with a non-zero status. | |
586 retval = 1; | |
587 break; | |
588 } | |
589 } | |
590 else | |
591 { | |
592 if (octave_completion_matches_called) | |
593 octave_completion_matches_called = false; | |
594 else | |
595 command_editor::increment_current_command_number (); | |
3883 | 596 } |
597 } | |
4153 | 598 else if (parser_end_of_input) |
599 break; | |
2620 | 600 } |
4153 | 601 } |
4182 | 602 catch (octave_interrupt_exception) |
4153 | 603 { |
4180 | 604 recover_from_exception (); |
5629 | 605 octave_stdout << "\n"; |
4180 | 606 } |
4181 | 607 catch (std::bad_alloc) |
4180 | 608 { |
609 recover_from_exception (); | |
610 std::cerr | |
6680 | 611 << "error: memory exhausted or requested size too large for range of Octave's index type -- trying to return to prompt" |
612 << std::endl; | |
1907 | 613 } |
614 } | |
615 while (retval == 0); | |
616 | |
617 return retval; | |
618 } | |
619 | |
1683 | 620 // Fix up things before exiting. |
621 | |
622 void | |
3162 | 623 clean_up_and_exit (int retval) |
624 { | |
3216 | 625 do_octave_atexit (); |
1683 | 626 |
5451 | 627 sysdep_cleanup (); |
628 | |
3162 | 629 exit (retval == EOF ? 0 : retval); |
1683 | 630 } |
631 | |
3180 | 632 DEFUN (quit, args, nargout, |
3332 | 633 "-*- texinfo -*-\n\ |
634 @deftypefn {Built-in Function} {} exit (@var{status})\n\ | |
635 @deftypefnx {Built-in Function} {} quit (@var{status})\n\ | |
636 Exit the current Octave session. If the optional integer value\n\ | |
637 @var{status} is supplied, pass that value to the operating system as the\n\ | |
6615 | 638 Octave's exit status. The default value is zero.\n\ |
3333 | 639 @end deftypefn") |
1683 | 640 { |
2086 | 641 octave_value_list retval; |
2068 | 642 |
3180 | 643 if (nargout == 0) |
2068 | 644 { |
3180 | 645 int exit_status = 0; |
646 | |
647 quitting_gracefully = true; | |
1683 | 648 |
3180 | 649 if (args.length () > 0) |
650 { | |
3202 | 651 int tmp = args(0).nint_value (); |
1683 | 652 |
3202 | 653 if (! error_state) |
654 exit_status = tmp; | |
3180 | 655 } |
656 | |
657 clean_up_and_exit (exit_status); | |
2068 | 658 } |
3180 | 659 else |
660 error ("quit: invalid number of output arguments"); | |
2068 | 661 |
1683 | 662 return retval; |
663 } | |
664 | |
665 DEFALIAS (exit, quit); | |
666 | |
1957 | 667 DEFUN (warranty, , , |
3446 | 668 "-*- texinfo -*-\n\ |
669 @deftypefn {Built-in Function} {} warranty ()\n\ | |
670 Describe the conditions for copying and distributing Octave.\n\ | |
671 @end deftypefn") | |
1683 | 672 { |
2086 | 673 octave_value_list retval; |
1683 | 674 |
3922 | 675 octave_stdout << "\n" \ |
676 OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\ | |
677 \n\ | |
1683 | 678 This program is free software; you can redistribute it and/or modify\n\ |
679 it under the terms of the GNU General Public License as published by\n\ | |
7016 | 680 the Free Software Foundation; either version 3 of the License, or\n\ |
1683 | 681 (at your option) any later version.\n\ |
682 \n\ | |
683 This program is distributed in the hope that it will be useful,\n\ | |
684 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ | |
685 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ | |
686 GNU General Public License for more details.\n\ | |
687 \n\ | |
688 You should have received a copy of the GNU General Public License\n\ | |
7016 | 689 along with this program. If not, see <http://www.gnu.org/licenses/>.\n\ |
1683 | 690 \n"; |
691 | |
692 return retval; | |
693 } | |
694 | |
695 // Execute a shell command. | |
696 | |
1965 | 697 static void |
698 cleanup_iprocstream (void *p) | |
699 { | |
3060 | 700 iprocstream *cmd = static_cast<iprocstream *> (p); |
701 | |
702 octave_child_list::remove (cmd->pid ()); | |
703 | |
704 delete cmd; | |
1965 | 705 } |
706 | |
6316 | 707 static int |
708 wait_for_input (int fid) | |
709 { | |
710 int retval = -1; | |
711 | |
712 #if defined (HAVE_SELECT) | |
713 if (fid >= 0) | |
714 { | |
715 fd_set set; | |
716 | |
717 FD_ZERO (&set); | |
718 FD_SET (fid, &set); | |
719 | |
720 retval = select (FD_SETSIZE, &set, 0, 0, 0); | |
721 } | |
722 #else | |
723 retval = 1; | |
724 #endif | |
725 | |
726 return retval; | |
727 } | |
728 | |
2086 | 729 static octave_value_list |
3523 | 730 run_command_and_return_output (const std::string& cmd_str) |
2083 | 731 { |
2086 | 732 octave_value_list retval; |
2083 | 733 |
734 iprocstream *cmd = new iprocstream (cmd_str.c_str ()); | |
735 | |
3060 | 736 if (cmd) |
2083 | 737 { |
3060 | 738 unwind_protect::add (cleanup_iprocstream, cmd); |
739 | |
740 if (*cmd) | |
741 { | |
6316 | 742 int fid = cmd->file_number (); |
2095 | 743 |
6316 | 744 std::ostringstream output_buf; |
4494 | 745 |
3060 | 746 char ch; |
3147 | 747 |
4489 | 748 for (;;) |
3147 | 749 { |
4489 | 750 if (cmd->get (ch)) |
751 output_buf.put (ch); | |
752 else | |
753 { | |
754 if (! cmd->eof () && errno == EAGAIN) | |
755 { | |
756 cmd->clear (); | |
3147 | 757 |
6316 | 758 if (wait_for_input (fid) != 1) |
759 break; | |
4489 | 760 } |
761 else | |
762 break; | |
763 } | |
3147 | 764 } |
765 | |
3252 | 766 int cmd_status = cmd->close (); |
2083 | 767 |
3060 | 768 if (WIFEXITED (cmd_status)) |
769 cmd_status = WEXITSTATUS (cmd_status); | |
770 else | |
771 cmd_status = 127; | |
2083 | 772 |
5659 | 773 retval(0) = (double) cmd_status; |
5765 | 774 retval(1) = output_buf.str (); |
3060 | 775 } |
776 | |
777 unwind_protect::run (); | |
2083 | 778 } |
779 else | |
780 error ("unable to start subprocess for `%s'", cmd_str.c_str ()); | |
781 | |
782 return retval; | |
783 } | |
784 | |
5285 | 785 enum system_exec_type { et_sync, et_async }; |
786 | |
1957 | 787 DEFUN (system, args, nargout, |
3301 | 788 "-*- texinfo -*-\n\ |
789 @deftypefn {Built-in Function} {} system (@var{string}, @var{return_output}, @var{type})\n\ | |
790 Execute a shell command specified by @var{string}. The second\n\ | |
791 argument is optional. If @var{type} is @code{\"async\"}, the process\n\ | |
792 is started in the background and the process id of the child process\n\ | |
793 is returned immediately. Otherwise, the process is started, and\n\ | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8013
diff
changeset
|
794 Octave waits until it exits. If the @var{type} argument is omitted, a\n\ |
3301 | 795 value of @code{\"sync\"} is assumed.\n\ |
2083 | 796 \n\ |
3301 | 797 If two input arguments are given (the actual value of\n\ |
798 @var{return_output} is irrelevant) and the subprocess is started\n\ | |
799 synchronously, or if @var{system} is called with one input argument and\n\ | |
800 one or more output arguments, the output from the command is returned.\n\ | |
5097 | 801 Otherwise, if the subprocess is executed synchronously, its output is\n\ |
2321 | 802 sent to the standard output. To send the output of a command executed\n\ |
3301 | 803 with @var{system} through the pager, use a command like\n\ |
2321 | 804 \n\ |
3301 | 805 @example\n\ |
806 disp (system (cmd, 1));\n\ | |
807 @end example\n\ | |
2321 | 808 \n\ |
3301 | 809 @noindent\n\ |
2321 | 810 or\n\ |
811 \n\ | |
3301 | 812 @example\n\ |
813 printf (\"%s\n\", system (cmd, 1));\n\ | |
814 @end example\n\ | |
815 \n\ | |
5659 | 816 The @code{system} function can return two values. The first is the\n\ |
817 exit status of the command and the second is any output from the\n\ | |
818 command that was written to the standard output stream. For example,\n\ | |
3301 | 819 \n\ |
820 @example\n\ | |
5717 | 821 [status, output] = system (\"echo foo; exit 2\");\n\ |
3301 | 822 @end example\n\ |
823 \n\ | |
824 @noindent\n\ | |
825 will set the variable @code{output} to the string @samp{foo}, and the\n\ | |
826 variable @code{status} to the integer @samp{2}.\n\ | |
827 @end deftypefn") | |
1683 | 828 { |
2086 | 829 octave_value_list retval; |
1683 | 830 |
3834 | 831 unwind_protect::begin_frame ("Fsystem"); |
832 | |
1683 | 833 int nargin = args.length (); |
834 | |
2083 | 835 if (nargin > 0 && nargin < 4) |
1683 | 836 { |
5672 | 837 bool return_output = (nargout > 1 || nargin > 1); |
2083 | 838 |
3523 | 839 std::string cmd_str = args(0).string_value (); |
2083 | 840 |
5285 | 841 system_exec_type type = et_sync; |
2083 | 842 |
843 if (! error_state) | |
844 { | |
845 if (nargin > 2) | |
846 { | |
3523 | 847 std::string type_str = args(2).string_value (); |
1683 | 848 |
2083 | 849 if (! error_state) |
850 { | |
851 if (type_str == "sync") | |
5285 | 852 type = et_sync; |
2083 | 853 else if (type_str == "async") |
5285 | 854 type = et_async; |
2083 | 855 else |
856 error ("system: third arg must be \"sync\" or \"async\""); | |
857 } | |
858 else | |
859 error ("system: third argument must be a string"); | |
860 } | |
861 } | |
862 else | |
3523 | 863 error ("system: expecting std::string as first argument"); |
1683 | 864 |
2083 | 865 if (! error_state) |
866 { | |
7104 | 867 #if defined (__WIN32__) && ! defined (__CYGWIN__) |
868 // Work around weird double-quote handling on Windows systems. | |
869 if (type == et_sync) | |
870 cmd_str = "\"" + cmd_str + "\""; | |
871 #endif | |
872 | |
5285 | 873 if (type == et_async) |
2083 | 874 { |
6222 | 875 // FIXME -- maybe this should go in sysdep.cc? |
4086 | 876 #ifdef HAVE_FORK |
2083 | 877 pid_t pid = fork (); |
878 | |
879 if (pid < 0) | |
880 error ("system: fork failed -- can't create child process"); | |
881 else if (pid == 0) | |
882 { | |
5775 | 883 // FIXME -- should probably replace this |
3273 | 884 // call with something portable. |
885 | |
5510 | 886 execl ("/bin/sh", "sh", "-c", cmd_str.c_str (), |
887 static_cast<void *> (0)); | |
3273 | 888 |
889 panic_impossible (); | |
2083 | 890 } |
891 else | |
4254 | 892 retval(0) = pid; |
6222 | 893 #elif defined (__WIN32__) |
894 STARTUPINFO si; | |
895 PROCESS_INFORMATION pi; | |
896 ZeroMemory (&si, sizeof (si)); | |
897 ZeroMemory (&pi, sizeof (pi)); | |
898 OCTAVE_LOCAL_BUFFER (char, xcmd_str, cmd_str.length()+1); | |
6676 | 899 strcpy (xcmd_str, cmd_str.c_str ()); |
6222 | 900 |
901 if (! CreateProcess (0, xcmd_str, 0, 0, FALSE, 0, 0, 0, &si, &pi)) | |
902 error ("system: CreateProcess failed -- can't create child process"); | |
903 else | |
904 { | |
905 retval(0) = pi.dwProcessId; | |
906 CloseHandle (pi.hProcess); | |
907 CloseHandle (pi.hThread); | |
908 } | |
4086 | 909 #else |
910 error ("asynchronous system calls are not supported"); | |
911 #endif | |
2083 | 912 } |
2321 | 913 else if (return_output) |
914 retval = run_command_and_return_output (cmd_str); | |
2083 | 915 else |
2321 | 916 { |
917 int status = system (cmd_str.c_str ()); | |
918 | |
919 // The value in status is as returned by waitpid. If | |
920 // the process exited normally, extract the actual exit | |
921 // status of the command. Otherwise, return 127 as a | |
922 // failure code. | |
923 | |
2693 | 924 if (WIFEXITED (status)) |
925 status = WEXITSTATUS (status); | |
2321 | 926 |
4233 | 927 retval(0) = status; |
2321 | 928 } |
2083 | 929 } |
1683 | 930 } |
931 else | |
5823 | 932 print_usage (); |
1683 | 933 |
3834 | 934 unwind_protect::run_frame ("Fsystem"); |
935 | |
1683 | 936 return retval; |
937 } | |
938 | |
939 DEFALIAS (shell_cmd, system); | |
940 | |
5775 | 941 // FIXME -- this should really be static, but that causes |
2614 | 942 // problems on some systems. |
6680 | 943 std::list<std::string> octave_atexit_functions; |
2077 | 944 |
945 void | |
946 do_octave_atexit (void) | |
947 { | |
3216 | 948 static bool deja_vu = false; |
949 | |
2077 | 950 while (! octave_atexit_functions.empty ()) |
951 { | |
6680 | 952 std::string fcn = octave_atexit_functions.front (); |
4214 | 953 |
6680 | 954 octave_atexit_functions.pop_front (); |
2077 | 955 |
5237 | 956 reset_error_handler (); |
957 | |
4233 | 958 feval (fcn, octave_value_list (), 0); |
3215 | 959 |
960 flush_octave_stdout (); | |
2077 | 961 } |
3216 | 962 |
963 if (! deja_vu) | |
964 { | |
965 deja_vu = true; | |
966 | |
6068 | 967 // Do this explicitly so that destructors for mex file objects |
968 // are called, so that functions registered with mexAtExit are | |
969 // called. | |
6072 | 970 clear_mex_functions (); |
6068 | 971 |
3216 | 972 command_editor::restore_terminal_state (); |
973 | |
5775 | 974 // FIXME -- is this needed? Can it cause any trouble? |
3216 | 975 raw_mode (0); |
976 | |
5305 | 977 octave_history_write_timestamp (); |
978 | |
3216 | 979 command_history::clean_up_and_save (); |
980 | |
981 close_files (); | |
982 | |
983 cleanup_tmp_files (); | |
984 | |
985 flush_octave_stdout (); | |
986 | |
5305 | 987 if (! quitting_gracefully && (interactive || forced_interactive)) |
5629 | 988 { |
989 octave_stdout << "\n"; | |
990 | |
991 // Yes, we want this to be separate from the call to | |
992 // flush_octave_stdout above. | |
993 | |
994 flush_octave_stdout (); | |
995 } | |
3216 | 996 } |
2077 | 997 } |
998 | |
7409 | 999 void |
1000 octave_add_atexit_function (const std::string& fname) | |
1001 { | |
1002 octave_atexit_functions.push_front (fname); | |
1003 } | |
1004 | |
1005 bool | |
1006 octave_remove_atexit_function (const std::string& fname) | |
1007 { | |
1008 bool found = false; | |
1009 | |
1010 for (std::list<std::string>::iterator p = octave_atexit_functions.begin (); | |
1011 p != octave_atexit_functions.end (); p++) | |
1012 { | |
1013 if (*p == fname) | |
1014 { | |
1015 octave_atexit_functions.erase (p); | |
1016 found = true; | |
1017 break; | |
1018 } | |
1019 } | |
1020 | |
1021 return found; | |
1022 } | |
1023 | |
1024 | |
6680 | 1025 DEFUN (atexit, args, nargout, |
3332 | 1026 "-*- texinfo -*-\n\ |
1027 @deftypefn {Built-in Function} {} atexit (@var{fcn})\n\ | |
1028 Register a function to be called when Octave exits. For example,\n\ | |
2077 | 1029 \n\ |
3332 | 1030 @example\n\ |
1031 @group\n\ | |
6620 | 1032 function bye_bye ()\n\ |
1033 disp (\"Bye bye\");\n\ | |
3332 | 1034 endfunction\n\ |
6620 | 1035 atexit (\"bye_bye\");\n\ |
3332 | 1036 @end group\n\ |
1037 @end example\n\ | |
1038 \n\ | |
1039 @noindent\n\ | |
6620 | 1040 will print the message \"Bye bye\" when Octave exits.\n\ |
6680 | 1041 \n\ |
1042 @deftypefnx {Built-in Function} {} atexit (@var{fcn}, @var{flag})\n\ | |
1043 Register or unregister a function to be called when Octave exits,\n\ | |
1044 depending on @var{flag}. If @var{flag} is true, the function is\n\ | |
1045 registered, if @var{flag} is false, it is unregistered. For example,\n\ | |
1046 after registering the function @code{bye_bye} as above,\n\ | |
1047 \n\ | |
1048 @example\n\ | |
1049 atexit (\"bye_bye\", false);\n\ | |
1050 @end example\n\ | |
1051 \n\ | |
1052 @noindent\n\ | |
1053 will remove the function from the list and Octave will not call\n\ | |
1054 the function @code{bye_by} when it exits.\n\ | |
1055 \n\ | |
7001 | 1056 Note that @code{atexit} only removes the first occurrence of a function\n\ |
6680 | 1057 from the list, so if a function was placed in the list multiple\n\ |
1058 times with @code{atexit}, it must also be removed from the list\n\ | |
1059 multiple times.\n\ | |
3333 | 1060 @end deftypefn") |
2077 | 1061 { |
2086 | 1062 octave_value_list retval; |
2077 | 1063 |
1064 int nargin = args.length (); | |
1065 | |
6680 | 1066 if (nargin == 1 || nargin == 2) |
2077 | 1067 { |
3523 | 1068 std::string arg = args(0).string_value (); |
2077 | 1069 |
1070 if (! error_state) | |
6680 | 1071 { |
1072 bool add_mode = true; | |
1073 | |
1074 if (nargin == 2) | |
1075 { | |
1076 add_mode = args(1).bool_value (); | |
1077 | |
1078 if (error_state) | |
1079 error ("atexit: second argument must be a logical value"); | |
1080 } | |
1081 | |
1082 if (! error_state) | |
1083 { | |
1084 if (add_mode) | |
7409 | 1085 octave_add_atexit_function (arg); |
6680 | 1086 else |
1087 { | |
7409 | 1088 bool found = octave_remove_atexit_function (arg); |
6680 | 1089 |
1090 if (nargout > 0) | |
1091 retval(0) = found; | |
1092 } | |
1093 } | |
1094 } | |
2077 | 1095 else |
6680 | 1096 error ("atexit: argument must be a string"); |
2077 | 1097 } |
1098 else | |
5823 | 1099 print_usage (); |
2077 | 1100 |
1101 return retval; | |
1102 } | |
1103 | |
2689 | 1104 DEFUN (octave_config_info, args, , |
3301 | 1105 "-*- texinfo -*-\n\ |
1106 @deftypefn {Built-in Function} {} octave_config_info (@var{option})\n\ | |
1107 Return a structure containing configuration and installation\n\ | |
1108 information for Octave.\n\ | |
2689 | 1109 \n\ |
3301 | 1110 if @var{option} is a string, return the configuration information for the\n\ |
2689 | 1111 specified option.\n\ |
1112 \n\ | |
3301 | 1113 @end deftypefn") |
2162 | 1114 { |
2689 | 1115 octave_value retval; |
1116 | |
4128 | 1117 #if defined (ENABLE_DYNAMIC_LINKING) |
2689 | 1118 bool octave_supports_dynamic_linking = true; |
1119 #else | |
1120 bool octave_supports_dynamic_linking = false; | |
1121 #endif | |
1122 | |
4357 | 1123 static bool initialized = false; |
1124 static Octave_map m; | |
2162 | 1125 |
6274 | 1126 struct conf_info_struct |
1127 { | |
1128 bool subst_home; | |
1129 const char *key; | |
1130 const char *val; | |
1131 }; | |
1132 | |
1133 static const conf_info_struct conf_info[] = | |
4357 | 1134 { |
6274 | 1135 { false, "ALL_CFLAGS", OCTAVE_CONF_ALL_CFLAGS }, |
1136 { false, "ALL_CXXFLAGS", OCTAVE_CONF_ALL_CXXFLAGS }, | |
1137 { false, "ALL_FFLAGS", OCTAVE_CONF_ALL_FFLAGS }, | |
1138 { false, "ALL_LDFLAGS", OCTAVE_CONF_ALL_LDFLAGS }, | |
1139 { false, "AR", OCTAVE_CONF_AR }, | |
1140 { false, "ARFLAGS", OCTAVE_CONF_ARFLAGS }, | |
1141 { false, "BLAS_LIBS", OCTAVE_CONF_BLAS_LIBS }, | |
1142 { false, "CC", OCTAVE_CONF_CC }, | |
1143 { false, "CC_VERSION", OCTAVE_CONF_CC_VERSION }, | |
1144 { false, "CFLAGS", OCTAVE_CONF_CFLAGS }, | |
1145 { false, "CPICFLAG", OCTAVE_CONF_CPICFLAG }, | |
1146 { false, "CPPFLAGS", OCTAVE_CONF_CPPFLAGS }, | |
1147 { false, "CURL_LIBS", OCTAVE_CONF_CURL_LIBS }, | |
1148 { false, "CXX", OCTAVE_CONF_CXX }, | |
1149 { false, "CXXCPP", OCTAVE_CONF_CXXCPP }, | |
1150 { false, "CXXFLAGS", OCTAVE_CONF_CXXFLAGS }, | |
1151 { false, "CXXPICFLAG", OCTAVE_CONF_CXXPICFLAG }, | |
1152 { false, "CXX_VERSION", OCTAVE_CONF_CXX_VERSION }, | |
1153 { false, "DEFAULT_PAGER", OCTAVE_DEFAULT_PAGER }, | |
1154 { false, "DEFS", OCTAVE_CONF_DEFS }, | |
1155 { false, "DL_LD", OCTAVE_CONF_DL_LD }, | |
1156 { false, "DL_LDFLAGS", OCTAVE_CONF_DL_LDFLAGS }, | |
1157 { false, "ENABLE_DYNAMIC_LINKING", OCTAVE_CONF_ENABLE_DYNAMIC_LINKING }, | |
1158 { false, "EXEEXT", OCTAVE_CONF_EXEEXT }, | |
1159 { false, "F2C", OCTAVE_CONF_F2C }, | |
1160 { false, "F2CFLAGS", OCTAVE_CONF_F2CFLAGS }, | |
1161 { false, "F77", OCTAVE_CONF_F77 }, | |
1162 { false, "F77_FLOAT_STORE_FLAG", OCTAVE_CONF_F77_FLOAT_STORE_FLAG }, | |
1163 { false, "FC", OCTAVE_CONF_FC }, | |
1164 { false, "FFLAGS", OCTAVE_CONF_FFLAGS }, | |
1165 { false, "FFTW_LIBS", OCTAVE_CONF_FFTW_LIBS }, | |
1166 { false, "FLIBS", OCTAVE_CONF_FLIBS }, | |
1167 { false, "FPICFLAG", OCTAVE_CONF_FPICFLAG }, | |
1168 { false, "GLPK_LIBS", OCTAVE_CONF_GLPK_LIBS }, | |
7361 | 1169 { false, "GNUPLOT", OCTAVE_CONF_GNUPLOT }, |
6274 | 1170 { false, "INCFLAGS", OCTAVE_CONF_INCFLAGS }, |
1171 { false, "LDFLAGS", OCTAVE_CONF_LDFLAGS }, | |
1172 { false, "LD_CXX", OCTAVE_CONF_LD_CXX }, | |
1173 { false, "LD_STATIC_FLAG", OCTAVE_CONF_LD_STATIC_FLAG }, | |
1174 { false, "LEX", OCTAVE_CONF_LEX }, | |
1175 { false, "LEXLIB", OCTAVE_CONF_LEXLIB }, | |
1176 { false, "LFLAGS", OCTAVE_CONF_LFLAGS }, | |
1177 { false, "LIBCRUFT", OCTAVE_CONF_LIBCRUFT }, | |
1178 { false, "LIBEXT", OCTAVE_CONF_LIBEXT }, | |
1179 { false, "LIBFLAGS", OCTAVE_CONF_LIBFLAGS }, | |
1180 { false, "LIBOCTAVE", OCTAVE_CONF_LIBOCTAVE }, | |
1181 { false, "LIBOCTINTERP", OCTAVE_CONF_LIBOCTINTERP }, | |
1182 { false, "LIBREADLINE", OCTAVE_CONF_LIBREADLINE }, | |
1183 { false, "LIBS", OCTAVE_CONF_LIBS }, | |
1184 { false, "LN_S", OCTAVE_CONF_LN_S }, | |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7923
diff
changeset
|
1185 { false, "MAGICK_INCFLAGS", OCTAVE_CONF_MAGICK_INCFLAGS }, |
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7923
diff
changeset
|
1186 { false, "MAGICK_LIBS", OCTAVE_CONF_MAGICK_LIBS }, |
6274 | 1187 { false, "MKOCTFILE_DL_LDFLAGS", OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS }, |
1188 { false, "RANLIB", OCTAVE_CONF_RANLIB }, | |
1189 { false, "RDYNAMIC_FLAG", OCTAVE_CONF_RDYNAMIC_FLAG }, | |
1190 { false, "RLD_FLAG", OCTAVE_CONF_RLD_FLAG }, | |
1191 { false, "SED", OCTAVE_CONF_SED }, | |
1192 { false, "SHARED_LIBS", OCTAVE_CONF_SHARED_LIBS }, | |
1193 { false, "SHLEXT", OCTAVE_CONF_SHLEXT }, | |
1194 { false, "SHLEXT_VER", OCTAVE_CONF_SHLEXT_VER }, | |
1195 { false, "SH_LD", OCTAVE_CONF_SH_LD }, | |
1196 { false, "SH_LDFLAGS", OCTAVE_CONF_SH_LDFLAGS }, | |
1197 { false, "SONAME_FLAGS", OCTAVE_CONF_SONAME_FLAGS }, | |
1198 { false, "STATIC_LIBS", OCTAVE_CONF_STATIC_LIBS }, | |
1199 { false, "UGLY_DEFS", OCTAVE_CONF_UGLY_DEFS }, | |
1200 { false, "USE_64_BIT_IDX_T", OCTAVE_CONF_USE_64_BIT_IDX_T }, | |
1201 { false, "XTRA_CFLAGS", OCTAVE_CONF_XTRA_CFLAGS }, | |
1202 { false, "XTRA_CXXFLAGS", OCTAVE_CONF_XTRA_CXXFLAGS }, | |
1203 { false, "YACC", OCTAVE_CONF_YACC }, | |
1204 { false, "YFLAGS", OCTAVE_CONF_YFLAGS }, | |
1205 { false, "api_version", OCTAVE_API_VERSION }, | |
1206 { true, "archlibdir", OCTAVE_ARCHLIBDIR }, | |
1207 { true, "bindir", OCTAVE_BINDIR }, | |
1208 { false, "canonical_host_type", OCTAVE_CANONICAL_HOST_TYPE }, | |
1209 { false, "config_opts", OCTAVE_CONF_config_opts }, | |
1210 { true, "datadir", OCTAVE_DATADIR }, | |
1211 { true, "datarootdir", OCTAVE_DATAROOTDIR }, | |
6276 | 1212 { true, "exec_prefix", OCTAVE_EXEC_PREFIX }, |
6274 | 1213 { true, "fcnfiledir", OCTAVE_FCNFILEDIR }, |
1214 { true, "imagedir", OCTAVE_IMAGEDIR }, | |
1215 { true, "includedir", OCTAVE_INCLUDEDIR }, | |
1216 { true, "infodir", OCTAVE_INFODIR }, | |
6276 | 1217 { true, "infofile", OCTAVE_INFOFILE }, |
6274 | 1218 { true, "libdir", OCTAVE_LIBDIR }, |
1219 { true, "libexecdir", OCTAVE_LIBEXECDIR }, | |
6311 | 1220 { true, "localapiarchlibdir", OCTAVE_LOCALAPIARCHLIBDIR }, |
6274 | 1221 { true, "localapifcnfiledir", OCTAVE_LOCALAPIFCNFILEDIR }, |
1222 { true, "localapioctfiledir", OCTAVE_LOCALAPIOCTFILEDIR }, | |
1223 { true, "localarchlibdir", OCTAVE_LOCALARCHLIBDIR }, | |
1224 { true, "localfcnfiledir", OCTAVE_LOCALFCNFILEDIR }, | |
1225 { true, "localoctfiledir", OCTAVE_LOCALOCTFILEDIR }, | |
1226 { true, "localstartupfiledir", OCTAVE_LOCALSTARTUPFILEDIR }, | |
1227 { true, "localverarchlibdir", OCTAVE_LOCALVERARCHLIBDIR }, | |
1228 { true, "localverfcnfiledir", OCTAVE_LOCALVERFCNFILEDIR }, | |
1229 { true, "localveroctfiledir", OCTAVE_LOCALVEROCTFILEDIR }, | |
1230 { true, "man1dir", OCTAVE_MAN1DIR }, | |
1231 { false, "man1ext", OCTAVE_MAN1EXT }, | |
1232 { true, "mandir", OCTAVE_MANDIR }, | |
1233 { true, "octfiledir", OCTAVE_OCTFILEDIR }, | |
1234 { true, "octincludedir", OCTAVE_OCTINCLUDEDIR }, | |
1235 { true, "octlibdir", OCTAVE_OCTLIBDIR }, | |
6276 | 1236 { true, "prefix", OCTAVE_PREFIX }, |
6274 | 1237 { true, "startupfiledir", OCTAVE_STARTUPFILEDIR }, |
1238 { false, "version", OCTAVE_VERSION }, | |
1239 { false, 0, 0 } | |
4357 | 1240 }; |
1241 | |
1242 if (! initialized) | |
1243 { | |
4675 | 1244 m.assign ("dld", octave_value (octave_supports_dynamic_linking)); |
4357 | 1245 |
4697 | 1246 oct_mach_info::float_format ff = oct_mach_info::native_float_format (); |
1247 m.assign ("float_format", | |
1248 octave_value (oct_mach_info::float_format_as_string (ff))); | |
1249 | |
1250 m.assign ("words_big_endian", | |
1251 octave_value (oct_mach_info::words_big_endian ())); | |
1252 | |
1253 m.assign ("words_little_endian", | |
1254 octave_value (oct_mach_info::words_little_endian ())); | |
1255 | |
4357 | 1256 int i = 0; |
4440 | 1257 |
1258 while (true) | |
4357 | 1259 { |
6274 | 1260 const conf_info_struct& elt = conf_info[i++]; |
1261 | |
1262 const char *key = elt.key; | |
4357 | 1263 |
1264 if (key) | |
6274 | 1265 { |
1266 if (elt.subst_home) | |
1267 m.assign (key, octave_value (subst_octave_home (elt.val))); | |
1268 else | |
1269 m.assign (key, octave_value (elt.val)); | |
1270 } | |
4357 | 1271 else |
1272 break; | |
1273 } | |
1274 | |
4691 | 1275 bool unix_system = true; |
7013 | 1276 bool mac_system = false; |
4691 | 1277 bool windows_system = false; |
1278 | |
1279 #if defined (WIN32) | |
1280 windows_system = true; | |
1281 #if !defined (__CYGWIN__) | |
1282 unix_system = false; | |
1283 #endif | |
1284 #endif | |
1285 | |
7010 | 1286 #if defined (__APPLE__) && defined (__MACH__) |
1287 mac_system = true; | |
1288 #endif | |
1289 | |
4691 | 1290 m.assign ("unix", octave_value (unix_system)); |
7010 | 1291 m.assign ("mac", octave_value (mac_system)); |
4691 | 1292 m.assign ("windows", octave_value (windows_system)); |
1293 | |
4357 | 1294 initialized = true; |
1295 } | |
2162 | 1296 |
2689 | 1297 int nargin = args.length (); |
1298 | |
1299 if (nargin == 1) | |
1300 { | |
3523 | 1301 std::string arg = args(0).string_value (); |
2689 | 1302 |
1303 if (! error_state) | |
4675 | 1304 { |
1305 Cell c = m.contents (arg.c_str ()); | |
5199 | 1306 |
1307 if (c.is_empty ()) | |
1308 error ("octave_config_info: no info for `%s'", arg.c_str ()); | |
1309 else | |
1310 retval = c(0); | |
4675 | 1311 } |
2689 | 1312 } |
1313 else if (nargin == 0) | |
4233 | 1314 retval = m; |
2689 | 1315 else |
5823 | 1316 print_usage (); |
2689 | 1317 |
1318 return retval; | |
2162 | 1319 } |
1320 | |
1683 | 1321 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE) |
2806 | 1322 |
1683 | 1323 int debug_new_delete = 0; |
1324 | |
1325 typedef void (*vfp)(void); | |
1326 extern vfp __new_handler; | |
1327 | |
1328 void * | |
1329 __builtin_new (size_t sz) | |
1330 { | |
1331 void *p; | |
1332 | |
1333 /* malloc (0) is unpredictable; avoid it. */ | |
1334 if (sz == 0) | |
1335 sz = 1; | |
2800 | 1336 p = malloc (sz); |
1683 | 1337 while (p == 0) |
1338 { | |
1339 (*__new_handler) (); | |
2800 | 1340 p = malloc (sz); |
1683 | 1341 } |
1342 | |
1343 if (debug_new_delete) | |
5629 | 1344 std::cerr << "__builtin_new: " << p << std::endl; |
1683 | 1345 |
1346 return p; | |
1347 } | |
1348 | |
1349 void | |
1350 __builtin_delete (void *ptr) | |
1351 { | |
1352 if (debug_new_delete) | |
5629 | 1353 std::cerr << "__builtin_delete: " << ptr << std::endl; |
1683 | 1354 |
1355 if (ptr) | |
1356 free (ptr); | |
1357 } | |
2806 | 1358 |
1683 | 1359 #endif |
1360 | |
1361 /* | |
1362 ;;; Local Variables: *** | |
1363 ;;; mode: C++ *** | |
1364 ;;; End: *** | |
1365 */ |