From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A844FC433F5 for ; Mon, 14 Feb 2022 11:19:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350863AbiBNLTZ (ORCPT ); Mon, 14 Feb 2022 06:19:25 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350621AbiBNLTN (ORCPT ); Mon, 14 Feb 2022 06:19:13 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B84D3694B8 for ; Mon, 14 Feb 2022 02:52:40 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id p15so36496556ejc.7 for ; Mon, 14 Feb 2022 02:52:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=E/TT01vk+TwDTxyVO+CySmmufUASQrx6o6WcTn2zA6g=; b=LWvXIogIhqRUhxWeVG/UvEOK/9eOLM6ssOlZy/3RDNw9vDq2wBdtU6s7kREbP0cnJC gCEPNNbIxVz9Px1HgdnzYzXC8WZKL4MCivjZM5RrjKfgwDDuCtxB7G/SMndpEDk/2rfg 0Pgi/XwsUUXLkr419KVcuHZS58QmtN1jYdlsc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=E/TT01vk+TwDTxyVO+CySmmufUASQrx6o6WcTn2zA6g=; b=JIWoOuLsWsCo6NSsAtb+EFWsGU6Bj9feEWZeuB8wHOsyujWL0hc8e14/DR6QyWjGBO SI5u9DgY7RBxEnhKRVsyQzzy8K9ZRJk1im6H4ySsYyfTXtWnoTOADJuy/CXYoyZ/zQzv 7ZjZiK2Mf4AGzDHAXfHTHfA6x7v0hY3jz07Ffy4Gvumygr82bLmQNPP4UTGWgoIUbyh5 zGB7isZyLI30+JWbZ20src/qe0WAElh/zieQp3eIqFxr9X9oa0Ch1fMmbfYndPlmp0/t cl6YSEv6jAF3qaqcZZWc5JbNGw1vIUDNBwIECBg7LA+SJ0+AQUnCMpM9nmgg8KB2OdcX 2pzg== X-Gm-Message-State: AOAM530En/AFK1yTeQu5UHewpFYs2n8OdOHSgHViBwnlkbnH7KKF6GBG v3Dt6FYpUExK7nvIRPzXzqyDnA== X-Google-Smtp-Source: ABdhPJyRmRhJ+m6AufBMjvO+EAajLPaNwsbL28+VihphAK/HPcx1aafI2fcRcWVtS458a+Wge2rcZw== X-Received: by 2002:a17:907:7204:: with SMTP id dr4mr10860530ejc.708.1644835959219; Mon, 14 Feb 2022 02:52:39 -0800 (PST) Received: from [192.168.1.149] ([80.208.64.233]) by smtp.gmail.com with ESMTPSA id q12sm14773393edv.99.2022.02.14.02.52.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Feb 2022 02:52:38 -0800 (PST) Message-ID: Date: Mon, 14 Feb 2022 11:52:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v4 12/20] vsprintf: add new `%pA` format specifier Content-Language: en-US To: Andy Shevchenko , Miguel Ojeda Cc: Linus Torvalds , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Gary Guo , Alex Gaynor , Wedson Almeida Filho , Petr Mladek , Steven Rostedt , Sergey Senozhatsky References: <20220212130410.6901-1-ojeda@kernel.org> <20220212130410.6901-13-ojeda@kernel.org> From: Rasmus Villemoes In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14/02/2022 11.18, Andy Shevchenko wrote: > On Sat, Feb 12, 2022 at 02:03:38PM +0100, Miguel Ojeda wrote: > >> From: Gary Guo > > Not sure I understand this... > >> This patch adds a format specifier `%pA` to `vsprintf` which formats >> a pointer as `core::fmt::Arguments`. Doing so allows us to directly >> format to the internal buffer of `printf`, so we do not have to use >> a temporary buffer on the stack to pre-assemble the message on >> the Rust side. >> >> This specifier is intended only to be used from Rust and not for C, so >> `checkpatch.pl` is intentionally unchanged to catch any misuse. >> >> Co-developed-by: Alex Gaynor >> Signed-off-by: Alex Gaynor >> Co-developed-by: Wedson Almeida Filho >> Signed-off-by: Wedson Almeida Filho > >> Signed-off-by: Gary Guo > > ...together with this in the current SoB chain. > >> Co-developed-by: Miguel Ojeda >> Signed-off-by: Miguel Ojeda > > I'm wondering if you considered to use %pV. > I think the point is for vsnprintf() to call (back) into Rust code. That said, I don't like the !CONFIG_RUST version to return NULL, that will surely crash moments later. So I prefer something like [rust.h] // no CONFIG_RUST conditional +char *rust_fmt_argument(char* buf, char* end, void *ptr); [vsprintf.c] + case 'A': + if (IS_ENABLED(CONFIG_RUST)) + return rust_fmt_argument(buf, end, ptr); + else + return string_nocheck(buf, end, "[%pA in non-Rust code?!]", default_str_spec); Rasmus