From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 106054 invoked by alias); 3 May 2017 16:20:48 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 106036 invoked by uid 89); 3 May 2017 16:20:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=sick X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 03 May 2017 16:20:45 +0000 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v43GF2em130900 for ; Wed, 3 May 2017 12:20:46 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0b-001b2d01.pphosted.com with ESMTP id 2a790smf3q-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 03 May 2017 12:20:45 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 3 May 2017 17:20:44 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 3 May 2017 17:20:42 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v43GKfSK20840798; Wed, 3 May 2017 16:20:41 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A11C5AE055; Wed, 3 May 2017 17:19:09 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6B66AAE045; Wed, 3 May 2017 17:19:09 +0100 (BST) Received: from ThinkPad (unknown [9.152.212.148]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 3 May 2017 17:19:09 +0100 (BST) Date: Wed, 03 May 2017 16:20:00 -0000 From: Philipp Rudo To: Sergio Durigan Junior Cc: gdb-patches@sourceware.org, Yao Qi , Peter Griffin , Omair Javaid , Andreas Arnez Subject: Re: [RFC v3 1/8] Convert substitute_path_component to C++ In-Reply-To: <87vapyx2yk.fsf@redhat.com> References: <20170316165739.88524-1-prudo@linux.vnet.ibm.com> <20170316165739.88524-2-prudo@linux.vnet.ibm.com> <87vapyx2yk.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 17050316-0008-0000-0000-0000043A9F77 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050316-0009-0000-0000-00001D841800 Message-Id: <20170503182040.6a9fcdf3@ThinkPad> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-05-03_13:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705030297 X-IsSubscribed: yes X-SW-Source: 2017-05/txt/msg00067.txt.bz2 Hi Sergio, sorry for the late answer but I was sick the last two weeks. Thanks for the hint. I fixed it locally. Thanks Philipp On Thu, 20 Apr 2017 16:02:11 -0400 Sergio Durigan Junior wrote: > 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 > > > > /* 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 > > + > > #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, >