From patchwork Sat Jun 1 10:25:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1942412 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=CUKRS3MT; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vrx7r6lf3z20Pb for ; Sat, 1 Jun 2024 20:30:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3EE4A382EF14 for ; Sat, 1 Jun 2024 10:29:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id BEAE23882668 for ; Sat, 1 Jun 2024 10:29:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BEAE23882668 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BEAE23882668 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717237772; cv=none; b=j6Cq871dja0GISdndk/sz1cEpCjmf3NX2mjA6wxeBglBZrlX1+3bwszVQzHJ/MwLnnhe+zRsMdIfYLWsiEWcARN4Do4A8ScN6YVRhqjVrp/Zix0KWD4KkQVjIpk+FcKX6ZDwJPGacYaktOUDDNaZ+95BFCR12XItlpcmjM5WxvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717237772; c=relaxed/simple; bh=h6dISkVuNfLwt1Ds1aH3ynG+Z9Ke1XZAIJkl5Ip1z9w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=yBYsRC+iv3fOFGQ1AI9Em8fWzAFIlJZiOjOg6IxVH/a327cMJksdh+1V7ZJFGoBFKBJRuMH0Po/kBVcBmamtm+yvKUp1ELXoI++m9ICOEp6WtXaqKaEbE5C6J8gxG8WmzwDcrQJhGQjI5McDHHVOesJMDoUZx/xjDmtpGkERghA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717237770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KBKqSGL+zCE3pJFuzbJCtzd1JcW4mwjpwzbT/txhZOo=; b=CUKRS3MTar5QexPiFQiVBJ/vybeHZb+PuZfl3+lhrsXNUjIdBwJlchrsAySdS3w1kh24xs 0AqyeMxmqB6VNR9zMRvj6QvQRgPkUKrfxTkkMdPpEEoPmz4aoxbD91wTfu9oLwB1+43zxQ R5iVMmsxY2AYHfeQWTTGLKYvC+rJc38= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-352-mUmUjO64P8W-2E5WEYm-ZQ-1; Sat, 01 Jun 2024 06:29:29 -0400 X-MC-Unique: mUmUjO64P8W-2E5WEYm-ZQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BAD64101A525; Sat, 1 Jun 2024 10:29:28 +0000 (UTC) Received: from localhost (unknown [10.42.28.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8791351BF; Sat, 1 Jun 2024 10:29:28 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] libstdc++: Reuse temporary buffer utils in Date: Sat, 1 Jun 2024 11:25:28 +0100 Message-ID: <20240601102927.878453-2-jwakely@redhat.com> In-Reply-To: <20240601102927.878453-1-jwakely@redhat.com> References: <20240601102927.878453-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org The non-throwing allocation logic in std::stacktrace duplicates the logic in , so we can just reuse those utilities. libstdc++-v3/ChangeLog: * include/std/stacktrace (basic_stacktrace::_Impl::_M_allocate): Use __detail::__get_temporary_buffer. (basic_stacktrace::_Impl::_M_deallocate): Use __detail::__return_temporary_buffer. --- libstdc++-v3/include/std/stacktrace | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace index 962dbed7a41..e0a543920bc 100644 --- a/libstdc++-v3/include/std/stacktrace +++ b/libstdc++-v3/include/std/stacktrace @@ -45,6 +45,7 @@ #include #include #include +#include // __get_temporary_buffer #include namespace std _GLIBCXX_VISIBILITY(default) @@ -545,21 +546,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return std::min(__size_max, __alloc_max); } -#if __has_builtin(__builtin_operator_new) >= 201802L -# define _GLIBCXX_OPERATOR_NEW __builtin_operator_new -# define _GLIBCXX_OPERATOR_DELETE __builtin_operator_delete -#else -# define _GLIBCXX_OPERATOR_NEW ::operator new -# define _GLIBCXX_OPERATOR_DELETE ::operator delete -#endif - -#if __cpp_sized_deallocation -# define _GLIBCXX_SIZED_DELETE(T, p, n) \ - _GLIBCXX_OPERATOR_DELETE((p), (n) * sizeof(T)) -#else -# define _GLIBCXX_SIZED_DELETE(T, p, n) _GLIBCXX_OPERATOR_DELETE(p) -#endif - // Precondition: _M_frames == nullptr && __n != 0 pointer _M_allocate(allocator_type& __alloc, size_type __n) noexcept @@ -570,11 +556,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { // For std::allocator we use nothrow-new directly so we // don't need to handle bad_alloc exceptions. - size_t __nb = __n * sizeof(value_type); - void* const __p = _GLIBCXX_OPERATOR_NEW (__nb, nothrow_t{}); + auto __p = __detail::__get_temporary_buffer(__n); if (__p == nullptr) [[unlikely]] return nullptr; - _M_frames = static_cast(__p); + _M_frames = __p; } else { @@ -599,9 +584,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (_M_capacity) { if constexpr (is_same_v>) - _GLIBCXX_SIZED_DELETE(value_type, - static_cast(_M_frames), - _M_capacity); + __detail::__return_temporary_buffer(_M_frames, _M_capacity); else __alloc.deallocate(_M_frames, _M_capacity); _M_frames = nullptr; @@ -609,10 +592,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } } -#undef _GLIBCXX_SIZED_DELETE -#undef _GLIBCXX_OPERATOR_DELETE -#undef _GLIBCXX_OPERATOR_NEW - // Precondition: __n <= _M_size void _M_resize(size_type __n, allocator_type& __alloc) noexcept