Mercurial > hg > octave-lyh
annotate src/unwind-prot.h @ 9394:b3ab22ee8544
further improve unwind_protect
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 25 Jun 2009 08:47:24 +0200 |
parents | 8bec23396924 |
children | 17af7cce7d1b |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2002, 2004, |
8920 | 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 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
1 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
1 | 22 |
23 */ | |
24 | |
383 | 25 #if !defined (octave_unwind_prot_h) |
26 #define octave_unwind_prot_h 1 | |
1 | 27 |
1342 | 28 #include <cstddef> |
529 | 29 |
1755 | 30 #include <string> |
4214 | 31 #include <stack> |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
32 #include <memory> |
240 | 33 |
2985 | 34 class |
6109 | 35 OCTINTERP_API |
2985 | 36 unwind_protect |
37 { | |
38 public: | |
39 | |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
40 // A generic unwind_protect element. Knows how to run itself and discard itself. |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
41 class elem |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
42 { |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
43 public: |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
44 virtual void run (void) { } |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
45 virtual ~elem (void) { } |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
46 }; |
2985 | 47 |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
48 // An element that merely runs a void (*)(void *) function. |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
49 |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
50 class fcn_elem : public elem |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
51 { |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
52 public: |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
53 fcn_elem (void (*fptr) (void *), void *ptr) |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
54 : e_fptr (fptr), e_ptr (ptr) { } |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
55 |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
56 void run (void) { e_fptr (e_ptr); } |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
57 |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
58 private: |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
59 void (*e_fptr) (void *); |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
60 void *e_ptr; |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
61 }; |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
62 |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
63 // An element that stores arbitrary variable, and restores it. |
2985 | 64 |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
65 template <class T> |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
66 class restore_var_elem : public elem |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
67 { |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
68 public: |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
69 restore_var_elem (T& ref, const T& val) |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
70 : e_ptr (&ref), e_val (val) { } |
2985 | 71 |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
72 void run (void) { *e_ptr = e_val; } |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
73 |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
74 private: |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
75 T *e_ptr, e_val; |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
76 }; |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
77 |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
78 // An element that stores a variable of type T along with a void (*) (T) |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
79 // function pointer, and calls the function with the parameter. |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
80 |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
81 template <class T> |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
82 class action_var_elem : public elem |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
83 { |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
84 public: |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
85 action_var_elem (void (*fcn) (T), T val) |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
86 : e_fcn (fcn), e_val (val) { } |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
87 |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
88 void run (void) { e_fcn (e_val); } |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
89 |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
90 private: |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
91 void (*e_fcn) (T); |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
92 T e_val; |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
93 }; |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
94 |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
95 typedef size_t frame_id_t; |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
96 |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
97 // Generic. Users may subclass elem to provide their own cleanup. |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
98 static void add (elem *el) |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
99 { |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
100 elt_list.push (el); |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
101 } |
2985 | 102 |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
103 static bool empty (void) |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
104 { return elt_list.empty (); } |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
105 |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
106 static void run (void) |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
107 { |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
108 // Use auto_ptr, so that even if the following run () call throws an |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
109 // exception, we still clean up the element. |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
110 std::auto_ptr<elem> elt (elt_list.top ()); |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
111 elt_list.pop (); |
2985 | 112 |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
113 elt->run (); |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
114 } |
2985 | 115 |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
116 static void discard (void) |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
117 { |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
118 // No need to use ato_ptr here. |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
119 elem *elt = elt_list.top (); |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
120 elt_list.pop (); |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
121 |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
122 delete elt; |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
123 } |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
124 |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
125 static frame_id_t begin_frame () |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
126 { |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
127 return elt_list.size (); |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
128 } |
2985 | 129 |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
130 static void run_frame (frame_id_t frame_id) |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
131 { |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
132 while (elt_list.size () > frame_id) |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
133 run (); |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
134 } |
2985 | 135 |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
136 static void discard_frame (frame_id_t frame_id) |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
137 { |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
138 while (elt_list.size () > frame_id) |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
139 discard (); |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
140 } |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
141 |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
142 // String tags are deprecated. Use the above trio. |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
143 |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
144 static void begin_frame (const std::string& tag) GCC_ATTR_DEPRECATED; |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
145 |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
146 static void run_frame (const std::string& tag) GCC_ATTR_DEPRECATED; |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
147 |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
148 static void discard_frame (const std::string& tag) GCC_ATTR_DEPRECATED; |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
149 |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
150 static void run_all (void) |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
151 { |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
152 run_frame (0); |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
153 while (! tag_list.empty ()) |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
154 tag_list.pop (); |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
155 } |
2985 | 156 |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
157 static void discard_all (void) |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
158 { |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
159 discard_frame (0); |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
160 while (! tag_list.empty ()) |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
161 tag_list.pop (); |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
162 } |
2985 | 163 |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
164 static void add (void (*fcn) (void *), void *ptr = 0) |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
165 { |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
166 elt_list.push (new fcn_elem (fcn, ptr)); |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
167 } |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
168 |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
169 // Protect any variable. |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
170 template <class T> |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
171 static void protect_var (T& var) |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
172 { |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
173 elt_list.push (new restore_var_elem<T> (var, var)); |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
174 } |
2985 | 175 |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
176 // Protect any variable, value given. |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
177 template <class T> |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
178 static void protect_var (T& var, const T& val) |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
179 { |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
180 elt_list.push (new restore_var_elem<T> (var, val)); |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
181 } |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
182 |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
183 // Store a function pointer together with a single argument (passed by value). |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
184 template <class T> |
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
185 static void add_action_var (void (*action) (T), T val) |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
186 { |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
187 elt_list.push (new action_var_elem<T> (action, val)); |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
188 } |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
189 |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
190 private: |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
191 |
9394
b3ab22ee8544
further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
9384
diff
changeset
|
192 static std::stack<elem *> elt_list; |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
193 |
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
194 static std::stack<std::pair <std::string, frame_id_t> > tag_list; |
2985 | 195 }; |
196 | |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
197 // Backward compatibility macros. Avoid them; use protect_var directly. |
2985 | 198 |
199 #define unwind_protect_bool(b) \ | |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
200 unwind_protect::protect_var (b) |
2985 | 201 |
202 #define unwind_protect_int(i) \ | |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
203 unwind_protect::protect_var (i) |
2985 | 204 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
205 #define unwind_protect_size_t(i) \ |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
206 unwind_protect::protect_var (i) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
207 |
2985 | 208 #define unwind_protect_str(s) \ |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
209 unwind_protect::protect_var (s) |
2985 | 210 |
211 #define unwind_protect_ptr(p) \ | |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
212 unwind_protect::protect_var (p) |
5760 | 213 |
5854 | 214 #define unwind_protect_fptr(p) \ |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
215 unwind_protect::protect_var (p) |
5854 | 216 |
5760 | 217 #define unwind_protect_const_ptr(p) \ |
9376
d58086453171
refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
218 unwind_protect::protect_var (p) |
2985 | 219 |
1 | 220 #endif |
221 | |
222 /* | |
223 ;;; Local Variables: *** | |
224 ;;; mode: C++ *** | |
225 ;;; End: *** | |
226 */ |