Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Sergio Durigan Junior <sergiodj@redhat.com>
To: Philipp Rudo <prudo@linux.vnet.ibm.com>
Cc: gdb-patches@sourceware.org,  Yao Qi <yao.qi@linaro.org>,
	 Peter Griffin <peter.griffin@linaro.org>,
	 Omair Javaid <omair.javaid@linaro.org>,
	 Andreas Arnez <arnez@linux.vnet.ibm.com>
Subject: Re: [RFC v3 1/8] Convert substitute_path_component to C++
Date: Thu, 20 Apr 2017 20:02:00 -0000	[thread overview]
Message-ID: <87vapyx2yk.fsf@redhat.com> (raw)
In-Reply-To: <20170316165739.88524-2-prudo@linux.vnet.ibm.com> (Philipp Rudo's	message of "Thu, 16 Mar 2017 17:57:32 +0100")

On Thursday, March 16 2017, Philipp Rudo wrote:

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

Thanks for the patch, Philipp.  Just a minor nit.

> 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.
> ---
>  gdb/auto-load.c | 18 +++++++++---------
>  gdb/utils.c     | 50 ++++++++++++++------------------------------------
>  gdb/utils.h     |  9 +++++++--
>  3 files changed, 30 insertions(+), 47 deletions(-)
>
> diff --git a/gdb/auto-load.c b/gdb/auto-load.c
> index 56914c8..c84fee1 100644
> --- a/gdb/auto-load.c
> +++ b/gdb/auto-load.c
> @@ -40,6 +40,7 @@
>  #include "filestuff.h"
>  #include "extension.h"
>  #include "gdb/section-scripts.h"
> +#include <string>
>  
>  /* The section to look in for auto-loaded scripts (in file formats that
>     support sections).
> @@ -175,21 +176,20 @@ static VEC (char_ptr) *auto_load_safe_path_vec;
>     this vector must be freed by free_char_ptr_vec by the caller.  */
>  
>  static VEC (char_ptr) *
> -auto_load_expand_dir_vars (const char *string)
> +auto_load_expand_dir_vars (std::string orig)
>  {
>    VEC (char_ptr) *dir_vec;
> -  char *s;
> +  std::string str = orig;
>  
> -  s = xstrdup (string);
> -  substitute_path_component (&s, "$datadir", gdb_datadir);
> -  substitute_path_component (&s, "$debugdir", debug_file_directory);
> +  substitute_path_component (str, "$datadir", gdb_datadir);
> +  substitute_path_component (str, "$debugdir", debug_file_directory);
>  
> -  if (debug_auto_load && strcmp (s, string) != 0)
> +  if (debug_auto_load && str.compare (orig) != 0)
>      fprintf_unfiltered (gdb_stdlog,
> -			_("auto-load: Expanded $-variables to \"%s\".\n"), s);
> +			_("auto-load: Expanded $-variables to \"%s\".\n"),
> +			str.c_str ());
>  
> -  dir_vec = dirnames_to_char_ptr_vec (s);
> -  xfree(s);
> +  dir_vec = dirnames_to_char_ptr_vec (str.c_str ());
>  
>    return dir_vec;
>  }
> diff --git a/gdb/utils.c b/gdb/utils.c
> index 27021a1..bef619a 100644
> --- a/gdb/utils.c
> +++ b/gdb/utils.c
> @@ -66,6 +66,8 @@
>  #include "interps.h"
>  #include "gdb_regex.h"
>  
> +#include <string>
> +
>  #if !HAVE_DECL_MALLOC
>  extern PTR malloc ();		/* ARI: PTR */
>  #endif
> @@ -3158,49 +3160,25 @@ make_cleanup_free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec)
>    return make_cleanup (do_free_char_ptr_vec, char_ptr_vec);
>  }
>  
> -/* Substitute all occurences of string FROM by string TO in *STRINGP.  *STRINGP
> -   must come from xrealloc-compatible allocator and it may be updated.  FROM
> -   needs to be delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be
> -   located at the start or end of *STRINGP.  */
> +/* See utils.h.  */
>  
>  void
> -substitute_path_component (char **stringp, const char *from, const char *to)
> +substitute_path_component (std::string &str, const std::string &from,
> +			   const std::string &to)
>  {
> -  char *string = *stringp, *s;
> -  const size_t from_len = strlen (from);
> -  const size_t to_len = strlen (to);
> -
> -  for (s = string;;)
> +  for (size_t pos = str.find (from); pos != std::string::npos;
> +       pos = str.find (from, pos + 1))
>      {
> -      s = strstr (s, from);
> -      if (s == NULL)
> -	break;
> -
> -      if ((s == string || IS_DIR_SEPARATOR (s[-1])
> -	   || s[-1] == DIRNAME_SEPARATOR)
> -          && (s[from_len] == '\0' || IS_DIR_SEPARATOR (s[from_len])
> -	      || s[from_len] == DIRNAME_SEPARATOR))
> +      char start, end;

Missing blank like between the declaration of the variables and the
assignment.

> +      start = str[pos - 1];
> +      end = str[pos + from.length ()];
> +      if ((pos == 0 || IS_DIR_SEPARATOR (start) || start == DIRNAME_SEPARATOR)
> +	  && (end == '\0' || IS_DIR_SEPARATOR (end)
> +	      || end == DIRNAME_SEPARATOR))
>  	{
> -	  char *string_new;
> -
> -	  string_new
> -	    = (char *) xrealloc (string, (strlen (string) + to_len + 1));
> -
> -	  /* Relocate the current S pointer.  */
> -	  s = s - string + string_new;
> -	  string = string_new;
> -
> -	  /* Replace from by to.  */
> -	  memmove (&s[to_len], &s[from_len], strlen (&s[from_len]) + 1);
> -	  memcpy (s, to, to_len);
> -
> -	  s += to_len;
> +	  str.replace (pos, from.length (), to);
>  	}
> -      else
> -	s++;
>      }
> -
> -  *stringp = string;
>  }
>  
>  #ifdef HAVE_WAITPID
> diff --git a/gdb/utils.h b/gdb/utils.h
> index f138702..d32114e 100644
> --- a/gdb/utils.h
> +++ b/gdb/utils.h
> @@ -132,8 +132,13 @@ extern char *gdb_abspath (const char *);
>  extern int gdb_filename_fnmatch (const char *pattern, const char *string,
>  				 int flags);
>  
> -extern void substitute_path_component (char **stringp, const char *from,
> -				       const char *to);
> +/* Substitute all occurences of string FROM by string TO in STR.  FROM
> +   needs to be delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be
> +   located at the start or end of STR).  */
> +
> +extern void substitute_path_component (std::string &str,
> +				       const std::string &from,
> +				       const std::string &to);
>  
>  char *ldirname (const char *filename);
>  
> -- 
> 2.8.4

Other than that, LGTM.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/


  reply	other threads:[~2017-04-20 20:02 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-16 16:57 [RFC v3 0/8] Support for Linux kernel debugging Philipp Rudo
2017-03-16 16:57 ` [RFC v3 1/8] Convert substitute_path_component to C++ Philipp Rudo
2017-04-20 20:02   ` Sergio Durigan Junior [this message]
2017-05-03 16:20     ` Philipp Rudo
2017-03-16 16:58 ` [RFC v3 7/8] Add privileged registers for s390x Philipp Rudo
2017-03-16 16:58 ` [RFC v3 6/8] Seperate common s390-tdep.* from s390-linux-tdep.* Philipp Rudo
2017-03-16 16:58 ` [RFC v3 4/8] Add kernel module support for linux-kernel target Philipp Rudo
2017-05-02 13:15   ` Yao Qi
2017-05-03 16:16     ` Philipp Rudo
2017-05-05 21:33       ` Yao Qi
2017-05-08  9:18         ` Philipp Rudo
2017-05-08 13:05           ` Yao Qi via gdb-patches
2017-03-16 16:58 ` [RFC v3 5/8] Add commands " Philipp Rudo
2017-03-16 16:58 ` [RFC v3 3/8] Add basic Linux kernel support Philipp Rudo
2017-04-16 22:59   ` Omair Javaid
2017-05-03 14:38     ` Philipp Rudo
2017-04-20 11:09   ` Omair Javaid
2017-04-24 15:24     ` Andreas Arnez
2017-05-03 14:13       ` Omair Javaid
2017-05-03 15:20         ` Philipp Rudo
2017-05-03 14:38     ` Philipp Rudo
2017-05-02 11:14   ` Yao Qi
2017-05-03 15:36     ` Philipp Rudo
2017-05-07 23:54       ` Omair Javaid
     [not found]         ` <20170508132204.7a733dc2@ThinkPad>
     [not found]           ` <CADrjBPqijRQFH4jthAedFzOzMLchpyvM53aXc9grOCjS2YUNCw@mail.gmail.com>
2017-05-10  9:03             ` Philipp Rudo
2017-05-10  9:36           ` Philipp Rudo
2017-05-19  8:45           ` Yao Qi
2017-05-19 15:24             ` Andreas Arnez
2017-05-19 16:28               ` John Baldwin
2017-05-19 17:05                 ` Andreas Arnez
2017-05-19 17:40                   ` John Baldwin
2017-05-22 10:18                     ` Andreas Arnez
2017-03-16 16:58 ` [RFC v3 2/8] Add libiberty/concat styled concat_path function Philipp Rudo
2017-03-16 16:58 ` [RFC v3 8/8] Add S390 support for linux-kernel target Philipp Rudo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vapyx2yk.fsf@redhat.com \
    --to=sergiodj@redhat.com \
    --cc=arnez@linux.vnet.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=omair.javaid@linaro.org \
    --cc=peter.griffin@linaro.org \
    --cc=prudo@linux.vnet.ibm.com \
    --cc=yao.qi@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox