• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修訂ad0b0e50cd51e645a860249b9e636e997d5c26d3 (tree)
時間2017-03-17 01:01:47
作者Philipp Rudo <prudo@linu...>
CommiterAndreas Arnez

Log Message

Convert substitute_path_component to C++

Simplify the code of utils.c:substiute_path_component by converting it to C++.

gdb/ChangeLog:

* utils.c (substitute_path_component): Convert to C++.
* utils.h (substitute_path_componetn): Adjust declatation.
* auto-load.c (auto_load_expand_dir_vars): Adjust.

Change Summary

差異

--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -40,6 +40,7 @@
4040 #include "filestuff.h"
4141 #include "extension.h"
4242 #include "gdb/section-scripts.h"
43+#include <string>
4344
4445 /* The section to look in for auto-loaded scripts (in file formats that
4546 support sections).
@@ -175,21 +176,20 @@ static VEC (char_ptr) *auto_load_safe_path_vec;
175176 this vector must be freed by free_char_ptr_vec by the caller. */
176177
177178 static VEC (char_ptr) *
178-auto_load_expand_dir_vars (const char *string)
179+auto_load_expand_dir_vars (std::string orig)
179180 {
180181 VEC (char_ptr) *dir_vec;
181- char *s;
182+ std::string str = orig;
182183
183- s = xstrdup (string);
184- substitute_path_component (&s, "$datadir", gdb_datadir);
185- substitute_path_component (&s, "$debugdir", debug_file_directory);
184+ substitute_path_component (str, "$datadir", gdb_datadir);
185+ substitute_path_component (str, "$debugdir", debug_file_directory);
186186
187- if (debug_auto_load && strcmp (s, string) != 0)
187+ if (debug_auto_load && str.compare (orig) != 0)
188188 fprintf_unfiltered (gdb_stdlog,
189- _("auto-load: Expanded $-variables to \"%s\".\n"), s);
189+ _("auto-load: Expanded $-variables to \"%s\".\n"),
190+ str.c_str ());
190191
191- dir_vec = dirnames_to_char_ptr_vec (s);
192- xfree(s);
192+ dir_vec = dirnames_to_char_ptr_vec (str.c_str ());
193193
194194 return dir_vec;
195195 }
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -66,6 +66,8 @@
6666 #include "interps.h"
6767 #include "gdb_regex.h"
6868
69+#include <string>
70+
6971 #if !HAVE_DECL_MALLOC
7072 extern PTR malloc (); /* ARI: PTR */
7173 #endif
@@ -3158,49 +3160,25 @@ make_cleanup_free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec)
31583160 return make_cleanup (do_free_char_ptr_vec, char_ptr_vec);
31593161 }
31603162
3161-/* Substitute all occurences of string FROM by string TO in *STRINGP. *STRINGP
3162- must come from xrealloc-compatible allocator and it may be updated. FROM
3163- needs to be delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be
3164- located at the start or end of *STRINGP. */
3163+/* See utils.h. */
31653164
31663165 void
3167-substitute_path_component (char **stringp, const char *from, const char *to)
3166+substitute_path_component (std::string &str, const std::string &from,
3167+ const std::string &to)
31683168 {
3169- char *string = *stringp, *s;
3170- const size_t from_len = strlen (from);
3171- const size_t to_len = strlen (to);
3172-
3173- for (s = string;;)
3169+ for (size_t pos = str.find (from); pos != std::string::npos;
3170+ pos = str.find (from, pos + 1))
31743171 {
3175- s = strstr (s, from);
3176- if (s == NULL)
3177- break;
3178-
3179- if ((s == string || IS_DIR_SEPARATOR (s[-1])
3180- || s[-1] == DIRNAME_SEPARATOR)
3181- && (s[from_len] == '\0' || IS_DIR_SEPARATOR (s[from_len])
3182- || s[from_len] == DIRNAME_SEPARATOR))
3172+ char start, end;
3173+ start = str[pos - 1];
3174+ end = str[pos + from.length ()];
3175+ if ((pos == 0 || IS_DIR_SEPARATOR (start) || start == DIRNAME_SEPARATOR)
3176+ && (end == '\0' || IS_DIR_SEPARATOR (end)
3177+ || end == DIRNAME_SEPARATOR))
31833178 {
3184- char *string_new;
3185-
3186- string_new
3187- = (char *) xrealloc (string, (strlen (string) + to_len + 1));
3188-
3189- /* Relocate the current S pointer. */
3190- s = s - string + string_new;
3191- string = string_new;
3192-
3193- /* Replace from by to. */
3194- memmove (&s[to_len], &s[from_len], strlen (&s[from_len]) + 1);
3195- memcpy (s, to, to_len);
3196-
3197- s += to_len;
3179+ str.replace (pos, from.length (), to);
31983180 }
3199- else
3200- s++;
32013181 }
3202-
3203- *stringp = string;
32043182 }
32053183
32063184 #ifdef HAVE_WAITPID
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -132,8 +132,13 @@ extern char *gdb_abspath (const char *);
132132 extern int gdb_filename_fnmatch (const char *pattern, const char *string,
133133 int flags);
134134
135-extern void substitute_path_component (char **stringp, const char *from,
136- const char *to);
135+/* Substitute all occurences of string FROM by string TO in STR. FROM
136+ needs to be delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be
137+ located at the start or end of STR). */
138+
139+extern void substitute_path_component (std::string &str,
140+ const std::string &from,
141+ const std::string &to);
137142
138143 char *ldirname (const char *filename);
139144