From patchwork Tue Jan 1 22:45:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 30930 Received: (qmail 122907 invoked by alias); 1 Jan 2019 22:45:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 122597 invoked by uid 89); 1 Jan 2019 22:45:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=obtained, incompatible X-HELO: mail-wr1-f51.google.com Received: from mail-wr1-f51.google.com (HELO mail-wr1-f51.google.com) (209.85.221.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Jan 2019 22:45:21 +0000 Received: by mail-wr1-f51.google.com with SMTP id c14so28995312wrr.0 for ; Tue, 01 Jan 2019 14:45:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=4b4h9GDD+pEOodCdzGFx8fYBx6gRdvkOIVKDanvv29s=; b=aJai4EN9GjHzrMNUVcFkwTBm4nfycEMr+CVBNlIoOO1d2lkFhaP8WhotQ1Gve+WfEs NeXycQqfOrOo2LA8+Ij8xetepv/uA2E5gDzVHLxEM9HJfNtOSIcmcHO7S4Mz1XwLCS4Q /YMzz3nRXLCiZor9P473CvjTkACB/DoSXiv+9aFiJ3HaTBRHSrpCNTQBShYj1GkpIP4w GU/QWfAuyuqRTNmBn7nLxbKzzDdfgv2/0n1c2vDq9X0FK6AwKP1A5O4PfZBUfm0nEbb9 HEfRYRTka9LlltLgW70WF350zMli1xeNiDG9Uu9jTTt2PCslmjRSOxIzJft110BlRPk7 SBUw== Return-Path: Received: from localhost (host86-172-198-47.range86-172.btcentralplus.com. [86.172.198.47]) by smtp.gmail.com with ESMTPSA id h1sm11056523wmb.0.2019.01.01.14.45.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 Jan 2019 14:45:18 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/6] gdb: Remove a cleanup from find_overload_match Date: Tue, 1 Jan 2019 22:45:03 +0000 Message-Id: In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes This patch changes cp-support.c:cp_func_name to return a 'gdb::unique_xmalloc_ptr' instead of a 'char *'. This allows a cleanup to be removed from valops.c:find_overload_match. gdb/ChangeLog: * compile/compile-cplus-types.c (compile_cplus_instance::decl_name): Handle changes to cp_func_name. * cp-support.c (cp_func_name): Update header comment, update return type. * cp-support.h (cp_func_name): Update return type in declaration. * valops.c (find_overload_match): Move temp_func local to top level of function and change its type. Use temp_func to hold and delete temporary string obtained from cp_func_name. --- gdb/ChangeLog | 12 ++++++++++++ gdb/compile/compile-cplus-types.c | 4 ++-- gdb/cp-support.c | 9 ++++----- gdb/cp-support.h | 2 +- gdb/valops.c | 10 ++++------ 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c index 3de0d8eee8c..910a874550d 100644 --- a/gdb/compile/compile-cplus-types.c +++ b/gdb/compile/compile-cplus-types.c @@ -63,9 +63,9 @@ compile_cplus_instance::decl_name (const char *natural) if (natural == nullptr) return nullptr; - char *name = cp_func_name (natural); + gdb::unique_xmalloc_ptr name = cp_func_name (natural); if (name != nullptr) - return gdb::unique_xmalloc_ptr (name); + return name; return gdb::unique_xmalloc_ptr (xstrdup (natural)); } diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 2024f87c44d..489bcca2b8d 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -808,10 +808,9 @@ method_name_from_physname (const char *physname) /* If FULL_NAME is the demangled name of a C++ function (including an arg list, possibly including namespace/class qualifications), return a new string containing only the function name (without the - arg list/class qualifications). Otherwise, return NULL. The - caller is responsible for freeing the memory in question. */ + arg list/class qualifications). Otherwise, return NULL. */ -char * +gdb::unique_xmalloc_ptr cp_func_name (const char *full_name) { gdb::unique_xmalloc_ptr ret; @@ -820,14 +819,14 @@ cp_func_name (const char *full_name) info = cp_demangled_name_to_comp (full_name, NULL); if (!info) - return NULL; + return nullptr; ret_comp = unqualified_name_from_comp (info->tree); if (ret_comp != NULL) ret = cp_comp_to_string (ret_comp, 10); - return ret.release (); + return ret; } /* Helper for cp_remove_params. DEMANGLED_NAME is the name of a diff --git a/gdb/cp-support.h b/gdb/cp-support.h index 32fafe4a5a7..2677e1bfcaf 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -96,7 +96,7 @@ extern unsigned int cp_find_first_component (const char *name); extern unsigned int cp_entire_prefix_len (const char *name); -extern char *cp_func_name (const char *full_name); +extern gdb::unique_xmalloc_ptr cp_func_name (const char *full_name); extern gdb::unique_xmalloc_ptr cp_remove_params (const char *demanged_name); diff --git a/gdb/valops.c b/gdb/valops.c index caf31629482..1a9d6a6f958 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -2520,6 +2520,7 @@ find_overload_match (gdb::array_view args, const char *obj_type_name = NULL; const char *func_name = NULL; + gdb::unique_xmalloc_ptr temp_func; enum oload_classification match_quality; enum oload_classification method_match_quality = INCOMPATIBLE; enum oload_classification src_method_match_quality = INCOMPATIBLE; @@ -2666,20 +2667,17 @@ find_overload_match (gdb::array_view args, && TYPE_CODE (check_typedef (SYMBOL_TYPE (fsym))) == TYPE_CODE_FUNC) { - char *temp_func; - temp_func = cp_func_name (qualified_name); /* If cp_func_name did not remove anything, the name of the symbol did not include scope or argument types - it was probably a C-style function. */ - if (temp_func) + if (temp_func != nullptr) { - make_cleanup (xfree, temp_func); - if (strcmp (temp_func, qualified_name) == 0) + if (strcmp (temp_func.get (), qualified_name) == 0) func_name = NULL; else - func_name = temp_func; + func_name = temp_func.get (); } } }