From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 61CEA388266F for ; Sat, 1 Jun 2024 10:29:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 61CEA388266F 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 61CEA388266F 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=1717237773; cv=none; b=j+oDNu64GpWdkZmKP03g1s3/QZ6axRCrQQkJ/FYH45nFW98//QUZC+MovSFc8FBVNhZmuTLVsdtTjnQw9YBmsOXpoS0l7xfJIjeCSC8fWiWz9Bfvg4bHH9oHba65wM95D5HkLN69iomvxUsV/6gJYPNgsxDhy8KgK8c6L8//970= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717237773; c=relaxed/simple; bh=h6dISkVuNfLwt1Ds1aH3ynG+Z9Ke1XZAIJkl5Ip1z9w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gWSInpC8FNHr/bA65QIQaB6wRtve58hCnFQV1YgSZMMscZXGtqU8ahzt/MxWGVWFTzIohII/k+4BRI1tZpoeih4qI7294Z7sQ6+r73xtOei5LooUWkgvbbk6f6NtgnZRGk4iB8OZzxEuq5CTY62EI/ApjnL/0QyNf1PAUvFSTfY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717237772; 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=c1TNghJBUltI8mp6qRpTPMhwIV9mn7yG1EgPm6Z3dr5L74dzXb9CNBcoG7DviZzwQVxIXv 8fW1pOxPpaki3ATaqreket+ybXXhTQmJmNpyXSnSPwrb6ME8syFTZD9H9XQ+AH/olKRQn/ j/zCoHacEC2Y3ym1dmdR0JBzbyF0/wk= 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 Content-Type: text/plain Content-Transfer-Encoding: 8bit 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 -- 2.45.1