Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2954359lqp; Mon, 25 Mar 2024 14:24:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXOL0s8mTzISE7mNc8zpPeekfjwSg5/tygXChORChuPzlhWJeSkMOvx81MaZMc228cqvcnOnrr9YNyah2x/yId7bsPD2i0Y41UdphUzFQ== X-Google-Smtp-Source: AGHT+IErvL3zbYjxk0GIcyUBw2LBYPtEg5BapDVcwXK9TJg5VbuGgwr2vDDLwC5TdJEGc1h7EXvU X-Received: by 2002:a05:6a20:3b06:b0:1a3:4e17:ff8f with SMTP id c6-20020a056a203b0600b001a34e17ff8fmr8033855pzh.57.1711401851997; Mon, 25 Mar 2024 14:24:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711401851; cv=pass; d=google.com; s=arc-20160816; b=dq8JvuUE3FHKgzG8EoKDJfL8mSFLxMtsVc66bcV76DC5/OGkNK/f+7UN9U/JrLrfE2 WGGc+x96za5z7szx7WKRWijkzsGdW2SnJCqjKAvnP0UXw17KNKWdwZ0eU5/7l1bWBKu+ 9NAG8lnjJlcxMTtvoY9x4lntmLikgzBCNdiREaUPx50UoRzxB2Uzs/b1ShUl96m6lKJH bQ/aF9hS7CbMdpIIZA5tFhO6uZShtfvfKoBRVTRLeJEIutTFRWMPAGMpyFW5xdnrq2w6 p9xpTLAy4hfK91pz45WXt7bOeqYQPatAgiem92nJhHhZ/DSN87RVzOtyHndO6yhyD8Az JGkw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature; bh=4DEZYFsrrJ3tXkcdN4NmU+Au67F0Ql9JXSFSSgEu1ho=; fh=i9JZ7ZNvMBANO3stZFUc4TjPApegFbCgD3XeePa6Jks=; b=USx5tYEejGtOT8TUBHNjCLmCZO5LMzP28S3JBuNVWydIiIX3AIyWQBnROsTqEaD9Or BPL4x7NE29i9Bm+jnD927zK6y9mzwBd2P0HbfmM4ypO06BIS2UkohKAbBNG2Lh3PSnpk 6laV/8tauCGFB2BbIv7pdhCEhnuXcaSz3eGGjARNIrawF7e5/YguKJ7qGLq9okJmzUZB aUJqi3MEXoyuQjjLbQHMXdfT60XygAJ950zvtrml/8afxmEQXA8bj9iuE3MJBuBlPa2X KFCO8SYgFw1YUPvyZe1EywrDVnDWZzLgKmbl9zBAayeTB8ucKlkj/jIXz93TTzSx9Os8 To7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bOYJ9sBi; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-117966-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117966-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id i10-20020a17090adc0a00b002a04a27086esi6200850pjv.166.2024.03.25.14.24.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 14:24:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117966-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bOYJ9sBi; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-117966-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117966-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2F501C0012C for ; Mon, 25 Mar 2024 20:46:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 56DF371748; Mon, 25 Mar 2024 20:44:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bOYJ9sBi" Received: from mail-ua1-f46.google.com (mail-ua1-f46.google.com [209.85.222.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDBBC5D725; Mon, 25 Mar 2024 20:44:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399498; cv=none; b=ddX9yq3l/XwVcz0VuLr6APj32dbUtCO5lHKTQkxPu5Si02izTi1HfWtBsWEK16IrqbeTeKLIoYbbkqDlJNJYAKxKTD8lUkEG4jBV2d/4ksefTrPVWQcfhPBMtd7tJWFFwZdk/s7/vPnY5z8VQWNMmqbmBKoDd/ySbS63tq4X/po= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399498; c=relaxed/simple; bh=SZAzcMIK7i3P4s4qLrG+0au4O9rvfOdsoCETN86sg8I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hds7TfgzBX3V3ypy87JTT+i1tpniau0/FH2jvLdIg7Uh9ztJWkF0wGEU0rrSyl3JAwaCw3FgbECUrdj20LQs0l9kwUO6cnTEzk62pG8rKAZhTwsyvZ5b/GAJxZWrpRdUaMFHnnPUuZc6gNR+MT4iAybeXkCs5M/iAnDvWJTQWFs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bOYJ9sBi; arc=none smtp.client-ip=209.85.222.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ua1-f46.google.com with SMTP id a1e0cc1a2514c-7db44846727so1030366241.0; Mon, 25 Mar 2024 13:44:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399496; x=1712004296; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=4DEZYFsrrJ3tXkcdN4NmU+Au67F0Ql9JXSFSSgEu1ho=; b=bOYJ9sBiCVMBgeppLoLHCOXf3wVSmonTPF5apo0FCFjze0HdJNFIO3pJVsEAZMOl7v tXFi32d3pHjj4ydp6I5PbodxWFz/yIz1IIr9yEXFw33dxln7ATsRx1s3B4EQKmBxDGjS cOgsYqvt+GO8RW8gPjEaz0du3YDe6oIJvdwAOpUhOOou10BWeuExxrxxXrvbl+2RTrG6 819mpzFsiM5A/ZugHjsQxm1outZs9XcW1Y7fzYegxhbY2+fU1YP1kzsKayvDCwLAgn1l tqSkPN4zu605dKJ3jB68zuXMxYTHGnyjYbV47ySpGlv1E5p/1QLx/gUa3LTLEvtLHk+g +/0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399496; x=1712004296; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4DEZYFsrrJ3tXkcdN4NmU+Au67F0Ql9JXSFSSgEu1ho=; b=WXK6T9YN4utyK0wLcMAzXniqwhIzPrYc0phJ51ldtNhPFnTh1I1c9s8Y+XPwGWmy98 V3mbIfGPrAz/DOkOK3U4yvqcTHHNJ9Moi6Opb8OcNVpjoaFZ4X4X9f9DCZjZqYlGXMYg nI60HICNdBI7/B06h6m1Byr1QW6SW1G8CxeOHb7t3YuLdzUT20VBEPAQwOSDMvOfQghv PVd/ThzwKugVWwbQ0+cDxGayD1HbFvqHDzG6FNL2ErprqlUGtPRT7cdhzHa970n/EN2/ YKQ03ZDgFTw2nlwvlPM+cQWWn41KpiZrvrDkvySRmiOUHlV90MhxCQDfLZeWQyF8T8E7 CaIw== X-Forwarded-Encrypted: i=1; AJvYcCVGzT3YRzu2/hq1DyEBuT4AVtisyWz+m1q+PG1+rcHa79x4g7ZI82Y6YlCBu8c5eidGDxBmiZH5IaxHb9TjIAJBdElmFPDY5GBZMmtR X-Gm-Message-State: AOJu0YyDmCc0cr2whVluImlu0H5hRNIo6oEKrZ9IPuONxi7tVM7z/mJK fg0nvWjav0PKNKY+r2SgrreBul1G6sgmhlKPtail6IY0YYqanKTm X-Received: by 2002:a05:6102:3561:b0:476:e1f5:43b8 with SMTP id bh1-20020a056102356100b00476e1f543b8mr4071235vsb.25.1711399495737; Mon, 25 Mar 2024 13:44:55 -0700 (PDT) Received: from fauth1-smtp.messagingengine.com (fauth1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id v26-20020a05620a091a00b007887583762csm2423631qkv.94.2024.03.25.13.44.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:44:55 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfauth.nyi.internal (Postfix) with ESMTP id ABB561200066; Mon, 25 Mar 2024 16:44:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 25 Mar 2024 16:44:54 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudduuddgkedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeduveeijeehvdekjeeffeethefhgeevvdeuvdekueeileeuleehleeuledt hfdthfenucffohhmrghinheprhhushhtqdhlrghnghdrohhrghdpshhprghrvggptggrph grtghithihpghmuhhtrdgrshenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhith ihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgr ihhlrdgtohhmsehfihigmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 25 Mar 2024 16:44:54 -0400 (EDT) Date: Mon, 25 Mar 2024 13:44:23 -0700 From: Boqun Feng To: Wedson Almeida Filho Cc: rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , linux-kernel@vger.kernel.org, Wedson Almeida Filho Subject: Re: [PATCH 07/10] rust: alloc: update `VecExt` to take allocation flags Message-ID: References: <20240325195418.166013-1-wedsonaf@gmail.com> <20240325195418.166013-8-wedsonaf@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240325195418.166013-8-wedsonaf@gmail.com> On Mon, Mar 25, 2024 at 04:54:15PM -0300, Wedson Almeida Filho wrote: [...] > + fn push(&mut self, v: T, flags: Flags) -> Result<(), AllocError> { > + >::reserve(self, 1, flags)?; > + let (ptr, len, cap) = destructure(self); > + // SAFETY: ptr is valid for `cap` elements. And `cap` is greater (by at least 1) than > + // `len` because of the call to `reserve` above. So the pointer after offsetting by `len` > + // elements is valid for write. > + unsafe { ptr.wrapping_add(len).write(v) }; > + > + // SAFETY: The only difference from the values returned by `destructure` is that `length` > + // is incremented by 1, which is fine because we have just initialised the element at > + // offset `length`. > + unsafe { rebuild(self, ptr, len + 1, cap) }; probably use spare_capacity_mut() here to avoid `destructure` and `rebuild`? https://doc.rust-lang.org/std/vec/struct.Vec.html#method.spare_capacity_mut // .. after reserve succeed. // there must be room for adding one more. self.spare_capacity_mut()[0].write(v); // or unsafe { self.spare_capacity_mut().as_mut_ptr().cast().write(v); } unsafe { self.set_len(self.len() + 1); } Thoughts? Regards, Boqun > Ok(()) > } > [...]