From patchwork Mon Jun 22 17:25:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 39766 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 773033851C1F; Mon, 22 Jun 2020 17:25:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 773033851C1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592846711; bh=hiGku0xSYLilTUG2B6tIB7kgOxaZGXoUq28q0ZRxU7M=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=IQ1mEo1GZo174qcWdnNl5swtO40Dw3qeGffrcn3NgIlEosu8lsVy2JwpW5z5QZvFe jkN5dV9VQNdVJ7Q+O+Ii0yGmxb88rWb5MozqsSDE78x9BVDvpcPI5Ws+v0SPwIv4vo D3egrrT4akapAEgrVjVWqYLx/+gXg2eZlYrLObWc= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by sourceware.org (Postfix) with ESMTPS id 0955A3851C04 for ; Mon, 22 Jun 2020 17:25:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0955A3851C04 Received: by mail-qt1-x84a.google.com with SMTP id o11so13756963qti.23 for ; Mon, 22 Jun 2020 10:25:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=hiGku0xSYLilTUG2B6tIB7kgOxaZGXoUq28q0ZRxU7M=; b=M5Jywy+lM54cIQuqAX4ySxV3XVSpVqxCFngpV+feT3UdUITE2jGNGcSfBOrqN784Je NqHJZ5+n48F0lzX+Amx9IM6EESWWR/rRm8jxsLNEqZrrsoEi/FRVtQHndrr/zfjg8h20 tQdXM8qkLVWy1L7G7WoRpIYAeg6ZL4zGmB4hiTZeqyyLDFXTTSjzUbNC++nsOmyeCCry Sz4ti6msXcREaSpsIJUXuP1rCY/+qc+95uPT6y1P77jGobLSVH5wRwCneZvCLASBOTbd vEhVHOCLgDrCg76ZzlWB7WIuxoSrpu0EjZHQhy0NO485+FoqTC3H9EW2OdmGcGcO77Vy dtGg== X-Gm-Message-State: AOAM5322xdBgofvjX30kuVniNu17gLp6t90Su8vPviQ3U+7C+PpSbD5U d1CNuE0HeDuNQl8jKvh6coO4vUTvnpSadg68MC4G/NZULQMY1WaQIX7lWAlPl5u26ib8ZZJ1QQE TDy0kdvktZNhEZvFTsRAnOBtSLK6I5UsxbFMRZ9FK6GqGLqKOlY5parlM4o3g25eVOBcmyF4= X-Google-Smtp-Source: ABdhPJzJmJYulGT2bk3bl6N7OjaEtOPK6G++z95Pb3jXrUAEEl+NAJgfC4lazQpMHR/c9WoiYuv1lpHwe6SMkA== X-Received: by 2002:a0c:bd12:: with SMTP id m18mr11840217qvg.178.1592846708500; Mon, 22 Jun 2020 10:25:08 -0700 (PDT) Date: Mon, 22 Jun 2020 18:25:04 +0100 In-Reply-To: <20200622160619.4154-1-gprocida@google.com> Message-Id: <20200622172504.27660-1-gprocida@google.com> Mime-Version: 1.0 References: <20200622160619.4154-1-gprocida@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [PATCH v2] abg-reader.cc: track WIP types by pointer not name To: libabigail@sourceware.org X-Spam-Status: No, score=-23.1 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Giuliano Procida via Libabigail From: Giuliano Procida Reply-To: Giuliano Procida Cc: maennich@google.com, kernel-team@android.com, gprocida@google.com Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" When reading ABI XML files, the reader needs to construct types progressively as any type may depend on other types and even on itself. Such work-in-progress types are tracked explicitly. The storage used for this is a map from (external, qualified) type name to a count of how many times the type (name) has been seen. However, function type names are invariably stored as "void ()" as they are incomplete at the point they are added to the map. When the reader later attempts to remove the marking they have their proper, different names. In short, the code doesn't do what it's supposed to. This commit changes the stored value from string to const type_base*. Equality on type_base_sptr has been defined to be a deep comparison so storing those wouldn't be quite right. It also replaces the unordered_map with a simple vector, implementing a searchable stack. This is simpler and fast, for the expected number of types, and allows a stronger invariant to be asserted due to the preservation of insertion order. Note that this commit removes some of the call paths that result in incorrect (external) type names being cached, regardless of whether they are actually used. * src/abg-reader.cc (xml_reader::m_wip_types_map): Replace with m_wip_types_stack of type vector. (xml_reader::clear_wip_classes_map): Remove. (xml_reader::clear_wip_types_stack): New function, clears m_wip_types_stack. (xml_reader::mark_type_as_wip): Push type pointer onto m_wip_types_stack. (xml_reader::unmark_type_as_wip): Add assertion that type pointer is at top of stack. Pop pointer off m_wip_types_stack. (xml_reader::is_wip_type): Test if type pointer in stack. Signed-off-by: Giuliano Procida Reviewed-by: Matthias Maennich --- src/abg-reader.cc | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/abg-reader.cc b/src/abg-reader.cc index eb74659f..480d1402 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -26,6 +26,7 @@ /// native XML format is named "abixml". #include "config.h" +#include #include #include #include @@ -119,7 +120,7 @@ private: unordered_map > m_types_map; unordered_map > m_fn_tmpl_map; unordered_map > m_class_tmpl_map; - unordered_map m_wip_types_map; + vector m_wip_types_stack; vector m_types_to_canonicalize; string_xml_node_map m_id_xml_node_map; xml_node_decl_base_sptr_map m_xml_node_decl_map; @@ -522,8 +523,8 @@ public: /// the map of the class that are currently being built, but at not /// yet fully built. void - clear_wip_classes_map() - {m_wip_types_map.clear();} + clear_wip_types_stack() + {m_wip_types_stack.clear();} /// Mark a given type as being "Work In Progress"; that is, mark it /// as being currently built. @@ -534,12 +535,7 @@ public: { if (!t) return; - string qname = get_type_name(t, /*qualified=*/true); - unordered_map::iterator it = m_wip_types_map.find(qname); - if (it == m_wip_types_map.end()) - m_wip_types_map[qname] = 1; - else - ++it->second; + m_wip_types_stack.push_back(t.get()); } /// Mark a given class as being *NOT* "Work In Progress" anymore; @@ -551,15 +547,9 @@ public: { if (!t) return; - - string qname = get_type_name(t, /*qualified=*/true); - unordered_map::iterator it = m_wip_types_map.find(qname); - if (it == m_wip_types_map.end()) - return; - if (it->second) - --it->second; - if (it->second == 0) - m_wip_types_map.erase(it); + ABG_ASSERT(!m_wip_types_stack.empty()); + ABG_ASSERT(m_wip_types_stack.back() == t.get()); + m_wip_types_stack.pop_back(); } /// Test if a type is being currently built; that is, if it's "Work @@ -571,11 +561,8 @@ public: { if (!t) return false; - - string qname = get_type_name(t, /*qualified=*/true); - unordered_map::const_iterator i = - m_wip_types_map.find(qname); - return i != m_wip_types_map.end(); + return std::find(m_wip_types_stack.begin(), m_wip_types_stack.end(), t.get()) + != m_wip_types_stack.end(); } /// Test if two types are equal, without comparing them structurally.