From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4517 invoked by alias); 12 Mar 2018 15:31:31 -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 4404 invoked by uid 89); 12 Mar 2018 15:31:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.3 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=Relocate X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Mar 2018 15:31:29 +0000 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2CFUPrA091626 for ; Mon, 12 Mar 2018 11:31:27 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gnuh02drv-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Mon, 12 Mar 2018 11:31:25 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 12 Mar 2018 15:31:19 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 12 Mar 2018 15:31:18 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2CFVHnG50200826; Mon, 12 Mar 2018 15:31:17 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 270CF52045; Mon, 12 Mar 2018 14:22:50 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id DD5A25203F; Mon, 12 Mar 2018 14:22:49 +0000 (GMT) From: Philipp Rudo To: gdb-patches@sourceware.org Cc: Omair Javaid , Yao Qi , arnez@linux.vnet.ibm.com Subject: [RFC PATCH v5 1/9] Convert substitute_path_component to C++ Date: Mon, 12 Mar 2018 15:31:00 -0000 In-Reply-To: <20180312153115.47321-1-prudo@linux.vnet.ibm.com> References: <20180312153115.47321-1-prudo@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18031215-0040-0000-0000-0000041E8844 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18031215-0041-0000-0000-00002621AFB8 Message-Id: <20180312153115.47321-2-prudo@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-12_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803120176 X-IsSubscribed: yes X-SW-Source: 2018-03/txt/msg00252.txt.bz2 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. --- gdb/auto-load.c | 19 ++++++++----------- gdb/utils.c | 47 +++++++++++------------------------------------ gdb/utils.h | 10 ++++++++-- 3 files changed, 27 insertions(+), 49 deletions(-) diff --git a/gdb/auto-load.c b/gdb/auto-load.c index 70bddbc862..a7f9635252 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -175,21 +175,18 @@ std::vector> auto_load_safe_path_vec; substitute_path_component. */ static std::vector> -auto_load_expand_dir_vars (const char *string) +auto_load_expand_dir_vars (const std::string &string) { - char *s = xstrdup (string); - substitute_path_component (&s, "$datadir", gdb_datadir); - substitute_path_component (&s, "$debugdir", debug_file_directory); + std::string s (string); + substitute_path_component (s, "$datadir", gdb_datadir); + substitute_path_component (s, "$debugdir", debug_file_directory); - if (debug_auto_load && strcmp (s, string) != 0) + if (debug_auto_load && s.compare (string) != 0) fprintf_unfiltered (gdb_stdlog, - _("auto-load: Expanded $-variables to \"%s\".\n"), s); + _("auto-load: Expanded $-variables to \"%s\".\n"), + s.c_str ()); - std::vector> dir_vec - = dirnames_to_char_ptr_vec (s); - xfree(s); - - return dir_vec; + return dirnames_to_char_ptr_vec (s.c_str ()); } /* Update auto_load_safe_path_vec from current AUTO_LOAD_SAFE_PATH. */ diff --git a/gdb/utils.c b/gdb/utils.c index b99d444a6e..d4f1398d14 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3052,49 +3052,24 @@ make_bpstat_clear_actions_cleanup (void) return make_cleanup (do_bpstat_clear_actions_cleanup, NULL); } -/* 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 + to.length ())) { - 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 = pos == 0 ? str[0] : str[pos - 1]; + char 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 8ca3eb0369..7e6a39ee82 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -298,8 +298,14 @@ extern struct cleanup *make_bpstat_clear_actions_cleanup (void); 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. STR + 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 STR). */ + +extern void substitute_path_component (std::string &str, + const std::string &from, + const std::string &to); std::string ldirname (const char *filename); -- 2.13.5