From patchwork Thu Aug 1 14:56:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1967729 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=QjlE88+M; 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 4WZXLl4DL4z1yZv for ; Fri, 2 Aug 2024 01:04:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE2C23864812 for ; Thu, 1 Aug 2024 15:04:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 80016385DDFF for ; Thu, 1 Aug 2024 14:58:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80016385DDFF Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 80016385DDFF Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::532 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524337; cv=none; b=DJFjGUJEDzogNQ+pEWRuggML3NOC13+M1/CJzbkWf+PDeEVFHe2EYL84YmGOyZ0fWSwDwFnWiKT9I6RgKSUpZ327ZQb0piuErLx6gc2z439W0kxxa0TPwgA3g87InxzzJ2coKHTKBvdoI6mPSrBV68bNUzAikMKdE0FKdWcd/D0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524337; c=relaxed/simple; bh=9Z3lPg2hrjBtJOJsjAWwhpGtDL+apqtS2Sv7jMIBQ7I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kl+fx1iFLzF+fPhqKM+ZF8LXwt42t8pWSG66WYkPrc5J75c3DMxedLrqriI3tcoEo9etnoN9ue331Z4kMTVFhAg08zoZum/UZ3CLeZHwmMP+H7X7YZ/Ekh+mtLyoJFnY65q3AgqKy+imOnDQUOcxsBaBQlilUBueXCpQeL2pNbM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5a10835480bso10291554a12.2 for ; Thu, 01 Aug 2024 07:58:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1722524324; x=1723129124; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CW1tfYgi5MWywluRDzGU17zt/ZaO8COXriRnLbBsoF0=; b=QjlE88+M2waavupgiYSe4iFFidPXu50+Utejxe7mnB7Y6dYvSLy7jxRe9VfxzOxAMu IWcz6s5haRZX5HpP1Paixs6NqqBwI5DBSufm+htFcky4HcUMLpgohVNtooBP5cBOnxoG 8qhSC5ZDchUrJ7fXbNJqphy2WK8fqtJTgAo0kUfVFNJnLuOwg640yY0M1nWahU1i6+7Q Vb8pK6q8Pn1u5z914LawRbJIqJot+HP4uWOtw8dyG/O4qokDFoFjXeciq/ne1YNo1Bpt A6hv9PLWQs7Wo9VHNOtkmVOVBzbUICqyhJWDlK9VT6I1zh5mk/1ET0F1Veaw097nQ5Qd dalQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524324; x=1723129124; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CW1tfYgi5MWywluRDzGU17zt/ZaO8COXriRnLbBsoF0=; b=wxYMSAJLzoY9cxqoZVUqkU8FdwPGSgBxk0uSKJ0QAcWhnuzXmhYhxP1PsH9sQChVnm rviYLo1J09IcQxYGRgUH96K8MbW69UrCtmfPu2BPrHWV9UVC1jFgJWfDmLZQLo5sLcl7 PkqdB99/lcSe5MbGjrXpAoDvCEiMUxyMo4KQyNENED2W81+/rK0V5PU5+TwnF7GZU6tm WUCf6rwRf/jAnsrEQAPCdfGdZk/p8tTxiUezyV/x3wVdtI2FT/BaRimlXcW336VnLwbW JM6DGW3Z9b6dTFRRtbfprqOdXSnaRNJZTqzmfpH7yhpVAQSd+nTM90q0tsPzj+5M//aJ VF2A== X-Gm-Message-State: AOJu0Yz5LztrJrHdwEtfXkn49kFsDVp3CaUwmY0UqDOvNxZztSMN1WKW RYdEKauIVhENTDaFtyqwC2tyuZ7XEcDWccdp32KiS6w7eOfBP3aKtlxc0bUxFIenL9V/Ftt89RM vStgX X-Google-Smtp-Source: AGHT+IFHjSGamV7lGyIZgO/JqqzgTGeE7teAvpiC0ucBMAVmVp7qvNjhlVGq5xPsIS5/y1ggXYCFcg== X-Received: by 2002:aa7:df12:0:b0:5a0:e62c:61c8 with SMTP id 4fb4d7f45d1cf-5b7f5128fc3mr413630a12.29.1722524323904; Thu, 01 Aug 2024 07:58:43 -0700 (PDT) Received: from platypus.lan ([2a04:cec2:9:dc84:3622:6733:ff49:ee91]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac63590592sm10252456a12.25.2024.08.01.07.58.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:58:43 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [PATCH 017/125] gccrs: rust-fmt: Store parsed string in Pieces struct Date: Thu, 1 Aug 2024 16:56:13 +0200 Message-ID: <20240801145809.366388-19-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240801145809.366388-2-arthur.cohen@embecosm.com> References: <20240801145809.366388-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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 gcc/rust/ChangeLog: * ast/rust-fmt.cc (Pieces::collect): Fix signature to take ownership of the given string. * ast/rust-fmt.h (struct Pieces): Store parsed string in the struct. libgrust/ChangeLog: * libformat_parser/src/lib.rs: Add debug prompt. --- gcc/rust/ast/rust-fmt.cc | 4 ++-- gcc/rust/ast/rust-fmt.h | 7 +++++-- libgrust/libformat_parser/src/lib.rs | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/gcc/rust/ast/rust-fmt.cc b/gcc/rust/ast/rust-fmt.cc index f6ee8a20913..511e94740c5 100644 --- a/gcc/rust/ast/rust-fmt.cc +++ b/gcc/rust/ast/rust-fmt.cc @@ -23,7 +23,7 @@ namespace Rust { namespace Fmt { Pieces -Pieces::collect (const std::string &to_parse) +Pieces::collect (std::string &&to_parse) { auto piece_slice = collect_pieces (to_parse.c_str ()); @@ -34,7 +34,7 @@ Pieces::collect (const std::string &to_parse) // auto pieces = std::vector (piece_slice.base_ptr, // piece_slice.base_ptr + piece_slice.len); - return Pieces (piece_slice); + return Pieces (piece_slice, std::move (to_parse)); } Pieces::~Pieces () { destroy_pieces (slice); } diff --git a/gcc/rust/ast/rust-fmt.h b/gcc/rust/ast/rust-fmt.h index 50aeff6433e..0bf9695bb6d 100644 --- a/gcc/rust/ast/rust-fmt.h +++ b/gcc/rust/ast/rust-fmt.h @@ -251,13 +251,16 @@ void destroy_pieces (PieceSlice); struct Pieces { - static Pieces collect (const std::string &to_parse); + static Pieces collect (std::string &&to_parse); ~Pieces (); private: - Pieces (PieceSlice slice) : slice (slice) {} + Pieces (PieceSlice slice, std::string &&to_parse) + : slice (slice), to_parse (std::move (to_parse)) + {} PieceSlice slice; + std::string to_parse; }; } // namespace Fmt diff --git a/libgrust/libformat_parser/src/lib.rs b/libgrust/libformat_parser/src/lib.rs index 9b2bffed05d..eb3e1060e5d 100644 --- a/libgrust/libformat_parser/src/lib.rs +++ b/libgrust/libformat_parser/src/lib.rs @@ -340,6 +340,7 @@ pub struct PieceSlice { pub extern "C" fn collect_pieces(input: *const libc::c_char) -> PieceSlice { // FIXME: Add comment let str = unsafe { CStr::from_ptr(input) }; + dbg!(str); // FIXME: No unwrap let pieces: Vec> = rust::collect_pieces(str.to_str().unwrap())