• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

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

Revisiónc48c4ca2318c992e196c48eb96060a7405c4a814 (tree)
Tiempo2017-02-08 00:25:53
AutorPhilipp 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.

Cambiar Resumen

Diferencia incremental

--- 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
@@ -3156,49 +3158,25 @@ make_cleanup_free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec)
31563158 return make_cleanup (do_free_char_ptr_vec, char_ptr_vec);
31573159 }
31583160
3159-/* Substitute all occurences of string FROM by string TO in *STRINGP. *STRINGP
3160- must come from xrealloc-compatible allocator and it may be updated. FROM
3161- needs to be delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be
3162- located at the start or end of *STRINGP. */
3161+/* See utils.h. */
31633162
31643163 void
3165-substitute_path_component (char **stringp, const char *from, const char *to)
3164+substitute_path_component (std::string &str, const std::string &from,
3165+ const std::string &to)
31663166 {
3167- char *string = *stringp, *s;
3168- const size_t from_len = strlen (from);
3169- const size_t to_len = strlen (to);
3170-
3171- for (s = string;;)
3167+ for (size_t pos = str.find (from); pos != std::string::npos;
3168+ pos = str.find (from, pos + 1))
31723169 {
3173- s = strstr (s, from);
3174- if (s == NULL)
3175- break;
3176-
3177- if ((s == string || IS_DIR_SEPARATOR (s[-1])
3178- || s[-1] == DIRNAME_SEPARATOR)
3179- && (s[from_len] == '\0' || IS_DIR_SEPARATOR (s[from_len])
3180- || s[from_len] == DIRNAME_SEPARATOR))
3170+ char start, end;
3171+ start = str[pos - 1];
3172+ end = str[pos + from.length ()];
3173+ if ((pos == 0 || IS_DIR_SEPARATOR (start) || start == DIRNAME_SEPARATOR)
3174+ && (end == '\0' || IS_DIR_SEPARATOR (end)
3175+ || end == DIRNAME_SEPARATOR))
31813176 {
3182- char *string_new;
3183-
3184- string_new
3185- = (char *) xrealloc (string, (strlen (string) + to_len + 1));
3186-
3187- /* Relocate the current S pointer. */
3188- s = s - string + string_new;
3189- string = string_new;
3190-
3191- /* Replace from by to. */
3192- memmove (&s[to_len], &s[from_len], strlen (&s[from_len]) + 1);
3193- memcpy (s, to, to_len);
3194-
3195- s += to_len;
3177+ str.replace (pos, from.length (), to);
31963178 }
3197- else
3198- s++;
31993179 }
3200-
3201- *stringp = string;
32023180 }
32033181
32043182 #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