From patchwork Sun Jan 7 12:56:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 83479 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 55EC83858C5E for ; Sun, 7 Jan 2024 12:57:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 1F3333858403; Sun, 7 Jan 2024 12:56:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F3333858403 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1F3333858403 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704632214; cv=none; b=EjZ1tqp08ua7D24rtTvNjgYkmkV1Y8NrIA7VWWVWW/14IaflpxKi5HSjU/wPYTraH6Zut2WqH9ry0CPLz2W/otKzGGC2CGPJaO1Wg+9dexwmD5Tm7G7WSIVSEGwfXMGoGUtYiW7i4GOjZJvHtjLsMYHRg81k/i7uUI79OlefJ7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704632214; c=relaxed/simple; bh=1koQUxvhypIehfxn74iZ3G1xlTFv4jAaJ+mrsd/BeDc=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=m1PCTCCV6n92wQlxqVOIT5PAFZMrptimMgmtGFPlRYoTNOVkpvjU6G5FJTyPZUkLM5MIGePpumi7OUB3/gNnp0U/LDgqDVV8SY6HgvzrZTGBc/J8VAT0oxxcyKK4lJLl+L9cDis/tve4+seXGfKRlzZuqsO8Gs0ImjXD2sfFt6g= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-336f2c88361so1117285f8f.3; Sun, 07 Jan 2024 04:56:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704632210; x=1705237010; darn=gcc.gnu.org; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=vg6WR+K6Ty+sDX/sulZvjqAB0DXk3t0UU0fzmZpCUMY=; b=jX0vkOVGC8NOmVWIN2LpoiSR90yPKGHzi3sVgF5m5HmV9d2siLxnzzsl6vdn00mhgB +iYtkoesZZCcUaUBfCKyXAuQ7ijsAQ6Rd5vbTXBioyHydYDiE4J2WYMIBklSxaGtafTP /Ci0U4FY5XgoQE8ZmMUCFJAgaEyzbTIhUcw6W0W0ldFdLFPLCXf3XXeRiEm8kogS6TPS 88ri3RSFmmLDtAv/NGM8sFNwvVs5Wt8BkYHSZ/QFnXi8bRbqC5FPcVXlyPEe9er3k4GB 4DTSFs0xQDoofuhQrjbXSOohybX5G/A2lYucv/OuPnVsvGo/c2Nxjmtpk8e3INXy/TYR /YYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704632210; x=1705237010; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vg6WR+K6Ty+sDX/sulZvjqAB0DXk3t0UU0fzmZpCUMY=; b=LMx46NUBWNzmEKL7/qGLCPCEGlb2fg6anb1LmZrPwHSBvpLDIow8RS1bQpv+mTdqOM U+KfuRliftgkLFOi8SYeQ0LqvpJso1hQbs8LP7kyYlme6J1CGKQGwXDvO9MsmSyyQv/0 88h1Jd35quOP0tlblHdtyvrsQI7nrOElBKKDvwSt1cxYhzVmOjAoa+JxSemxQWVv3bgy c2v+Nw4YyNLxukkU4xnH4hS1w7LGvMCR1qiFoJkj5swDqTrWLYq2VsjIFjqyHipNqFCG ImUpw31QmbJ9unY+Tu+2yfwA+JskWdyW9/i/pQ0Hg+4I97Pn4DC0N2MI9IbUCuOVYyN3 /1qw== X-Gm-Message-State: AOJu0Yw5HtxyQ1oqyv0Z8fRDGs/XbIPZO/C8zNYeFGKSNSMks3Qa+yBQ WhssQljwqf0J1QRhjtDUG8pRdGfiLoM= X-Google-Smtp-Source: AGHT+IET7Q3eEgTSggVZQyEfqPQ4JvbLL9qj0B9H5uwtPIDpndQ39CehYR91LoEZ2z/17t1H2L3Udg== X-Received: by 2002:a5d:6750:0:b0:337:4e98:b725 with SMTP id l16-20020a5d6750000000b003374e98b725mr887030wrw.65.1704632209634; Sun, 07 Jan 2024 04:56:49 -0800 (PST) Received: from ?IPV6:2a01:e0a:1dc:b1c0:5496:b8b8:98b:40d4? ([2a01:e0a:1dc:b1c0:5496:b8b8:98b:40d4]) by smtp.gmail.com with ESMTPSA id h13-20020a5d6e0d000000b0033677a4e0d6sm5284602wrz.13.2024.01.07.04.56.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 07 Jan 2024 04:56:48 -0800 (PST) Message-ID: <9a2de7f9-7ac3-4d4a-a4cd-6a379c4217bc@gmail.com> Date: Sun, 7 Jan 2024 13:56:48 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: libstdc++ , gcc-patches From: =?utf-8?q?Fran=C3=A7ois_Dumont?= Subject: [PATCH] Add __cow_string C string constructor X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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+patchwork=sourceware.org@gcc.gnu.org Hi While working on the patch to use the cxx11 abi in gnu version namespace mode I got a small problem with this missing constructor. I'm not sure that the main patch will be integrated in gcc 14 so I think it is better if I propose this patch independently.     libstdc++: Add __cow_string constructor from C string     The __cow_string is instantiated from a C string in cow-stdexcept.cc. At the moment     the constructor from std::string is being used with the drawback of an intermediate     potential allocation/deallocation and copy. With the C string constructor we bypass     all those operations.     libstdc++-v3/ChangeLog:             * include/std/stdexcept (__cow_string(const char*)): New definition.             * src/c++11/cow-stdexcept.cc (__cow_string(const char*)): New definition and             declaration. Tested under Linux x64, ok to commit ? François diff --git a/libstdc++-v3/include/std/stdexcept b/libstdc++-v3/include/std/stdexcept index 66c8572d0cd..2e3c9f3bf71 100644 --- a/libstdc++-v3/include/std/stdexcept +++ b/libstdc++-v3/include/std/stdexcept @@ -54,6 +54,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __cow_string(); __cow_string(const std::string&); + __cow_string(const char*); __cow_string(const char*, size_t); __cow_string(const __cow_string&) _GLIBCXX_NOTHROW; __cow_string& operator=(const __cow_string&) _GLIBCXX_NOTHROW; diff --git a/libstdc++-v3/src/c++11/cow-stdexcept.cc b/libstdc++-v3/src/c++11/cow-stdexcept.cc index 8d1cc4605d4..12b189b43b5 100644 --- a/libstdc++-v3/src/c++11/cow-stdexcept.cc +++ b/libstdc++-v3/src/c++11/cow-stdexcept.cc @@ -127,6 +127,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __cow_string(); __cow_string(const std::string& s); + __cow_string(const char*); __cow_string(const char*, size_t n); __cow_string(const __cow_string&) noexcept; __cow_string& operator=(const __cow_string&) noexcept; @@ -139,6 +140,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __cow_string::__cow_string(const std::string& s) : _M_str(s) { } + __cow_string::__cow_string(const char* s) : _M_str(s) { } + __cow_string::__cow_string(const char* s, size_t n) : _M_str(s, n) { } __cow_string::__cow_string(const __cow_string& s) noexcept