GNU Binutils with patches for OS216
修訂 | be0d7abb5e3b0be4cb928845e70a9134f1b19700 (tree) |
---|---|
時間 | 2017-09-12 07:15:08 |
作者 | Tom Tromey <tom@trom...> |
Commiter | Tom Tromey |
Replace interp_set_temp with scoped_restore_interp
This removes interp_set_temp and an associated cleanup, in favor of a
new RAII class, scoped_restore_interp.
ChangeLog
2017-09-11 Tom Tromey <tom@tromey.com>
* cli/cli-script.c (restore_interp): Remove.
(read_command_lines): Use scoped_restore_interp.
* interps.c (scoped_restore_interp::set_temp): Rename from
interp_set_temp.
* interps.h (class scoped_restore_interp): New.
(interp_set_temp): Remove.
@@ -1,5 +1,14 @@ | ||
1 | 1 | 2017-09-11 Tom Tromey <tom@tromey.com> |
2 | 2 | |
3 | + * cli/cli-script.c (restore_interp): Remove. | |
4 | + (read_command_lines): Use scoped_restore_interp. | |
5 | + * interps.c (scoped_restore_interp::set_temp): Rename from | |
6 | + interp_set_temp. | |
7 | + * interps.h (class scoped_restore_interp): New. | |
8 | + (interp_set_temp): Remove. | |
9 | + | |
10 | +2017-09-11 Tom Tromey <tom@tromey.com> | |
11 | + | |
3 | 12 | * mi/mi-cmd-catch.c (mi_cmd_catch_assert) |
4 | 13 | (mi_cmd_catch_exception, mi_catch_load_unload): Update. |
5 | 14 | * mi/mi-cmd-break.c (setup_breakpoint_reporting): Return a |
@@ -1158,12 +1158,6 @@ recurse_read_control_structure (char * (*read_next_line_func) (void), | ||
1158 | 1158 | return ret; |
1159 | 1159 | } |
1160 | 1160 | |
1161 | -static void | |
1162 | -restore_interp (void *arg) | |
1163 | -{ | |
1164 | - interp_set_temp (interp_name ((struct interp *)arg)); | |
1165 | -} | |
1166 | - | |
1167 | 1161 | /* Read lines from the input stream and accumulate them in a chain of |
1168 | 1162 | struct command_line's, which is then returned. For input from a |
1169 | 1163 | terminal, the special command "end" is used to mark the end of the |
@@ -1203,12 +1197,10 @@ read_command_lines (char *prompt_arg, int from_tty, int parse_commands, | ||
1203 | 1197 | validator, closure); |
1204 | 1198 | else |
1205 | 1199 | { |
1206 | - struct interp *old_interp = interp_set_temp (INTERP_CONSOLE); | |
1207 | - struct cleanup *old_chain = make_cleanup (restore_interp, old_interp); | |
1200 | + scoped_restore_interp interp_restorer (INTERP_CONSOLE); | |
1208 | 1201 | |
1209 | 1202 | head = read_command_lines_1 (read_next_line, parse_commands, |
1210 | 1203 | validator, closure); |
1211 | - do_cleanups (old_chain); | |
1212 | 1204 | } |
1213 | 1205 | |
1214 | 1206 | if (from_tty && input_interactive_p (current_ui) |
@@ -288,7 +288,7 @@ current_interp_set_logging (ui_file_up logfile, | ||
288 | 288 | |
289 | 289 | /* Temporarily overrides the current interpreter. */ |
290 | 290 | struct interp * |
291 | -interp_set_temp (const char *name) | |
291 | +scoped_restore_interp::set_interp (const char *name) | |
292 | 292 | { |
293 | 293 | struct ui_interp_info *ui_interp = get_current_interp_info (); |
294 | 294 | struct interp *interp = interp_lookup (current_ui, name); |
@@ -104,6 +104,32 @@ extern struct ui_out *interp_ui_out (struct interp *interp); | ||
104 | 104 | extern const char *interp_name (struct interp *interp); |
105 | 105 | extern struct interp *interp_set_temp (const char *name); |
106 | 106 | |
107 | +/* Temporarily set the current interpreter, and reset it on | |
108 | + destruction. */ | |
109 | +class scoped_restore_interp | |
110 | +{ | |
111 | +public: | |
112 | + | |
113 | + scoped_restore_interp (const char *name) | |
114 | + : m_interp (set_interp (name)) | |
115 | + { | |
116 | + } | |
117 | + | |
118 | + ~scoped_restore_interp () | |
119 | + { | |
120 | + set_interp (interp_name (m_interp)); | |
121 | + } | |
122 | + | |
123 | + scoped_restore_interp (const scoped_restore_interp &) = delete; | |
124 | + scoped_restore_interp &operator= (const scoped_restore_interp &) = delete; | |
125 | + | |
126 | +private: | |
127 | + | |
128 | + struct interp *set_interp (const char *name); | |
129 | + | |
130 | + struct interp *m_interp; | |
131 | +}; | |
132 | + | |
107 | 133 | extern int current_interp_named_p (const char *name); |
108 | 134 | |
109 | 135 | /* Call this function to give the current interpreter an opportunity |