annotate src/unwind-prot.cc @ 9376:d58086453171

refactor unwind_protect
author Jaroslav Hajek <highegg@gmail.com>
date Tue, 23 Jun 2009 07:55:44 +0200
parents eb63fbe60fab
children b3ab22ee8544
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2004,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
4 2005, 2006, 2007, 2008 John W. Eaton
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
5 Copyright (C) 2009 VZLU Prague
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
9 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
11 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
12 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
20 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
21 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
23 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
24
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 1
diff changeset
25 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1009
diff changeset
26 #include <config.h>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
27 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
28
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1315
diff changeset
29 #include <cstddef>
7048
845ca0affec0 [project @ 2007-10-22 16:55:41 by jwe]
jwe
parents: 7017
diff changeset
30 #include <cstring>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
31
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1343
diff changeset
32 #include "error.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
33 #include "unwind-prot.h"
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
34 #include "utils.h"
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
35
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
36 std::stack<unwind_protect::elem> unwind_protect::elt_list;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
37
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
38 std::stack<std::pair <std::string, unwind_protect::frame_id_t> > unwind_protect::tag_list;
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
39
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
40 unwind_protect::restore_mem::restore_mem (void *ptr, size_t size)
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
41 : rptr (ptr), sptr (reinterpret_cast<void *> (new char[size])), rsize (size)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
42 {
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
43 std::memcpy (sptr, rptr, size);
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7048
diff changeset
44 }
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7048
diff changeset
45
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
46 unwind_protect::restore_mem::~restore_mem (void)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
47 {
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
48 std::memcpy (rptr, sptr, rsize);
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
49 delete [] reinterpret_cast<char *> (sptr);
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
50 }
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
51
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
52 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3263
diff changeset
53 unwind_protect::begin_frame (const std::string& tag)
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
54 {
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
55 tag_list.push (std::make_pair (tag, begin_frame ()));
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
56 }
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
57
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
58 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3263
diff changeset
59 unwind_protect::run_frame (const std::string& tag)
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
60 {
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
61 while (! tag_list.empty ())
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
62 {
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
63 std::pair<std::string, frame_id_t> top = tag_list.top ();
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
64 tag_list.pop ();
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
65
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
66 run_frame (top.second);
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
67 if (top.first == tag)
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
68 break;
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
69 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
70 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
71
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
72 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3263
diff changeset
73 unwind_protect::discard_frame (const std::string& tag)
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1488
diff changeset
74 {
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
75 while (! tag_list.empty ())
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
76 {
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
77 std::pair<std::string, frame_id_t> top = tag_list.top ();
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
78 tag_list.pop ();
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
79
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
80 run_frame (top.second);
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
81 if (top.first == tag)
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
82 break;
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
83 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
84 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
85
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
86 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
87 ;;; Local Variables: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
88 ;;; mode: C++ ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
89 ;;; End: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
90 */