All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Robert Elliott <elliott@hpe.com>,
	Matt Fleming <matt@codeblueprint.co.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org,
	Brian Norris <computersforpeace@gmail.com>,
	Hariprasad S <hariprasad@chelsio.com>
Subject: Re: [PATCH v2 06/11] lib/vsprintf: introduce %pl to print in human-readable form
Date: Mon, 18 Jan 2016 21:57:44 +0100	[thread overview]
Message-ID: <87mvs2ehbr.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <1452810221-116505-7-git-send-email-andriy.shevchenko@linux.intel.com> (Andy Shevchenko's message of "Fri, 15 Jan 2016 00:23:36 +0200")

On Thu, Jan 14 2016, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Introduce a new extension for printing given unsigned long long value in
> human-readable form with automatically choosen IEC binary prefix. The value is
> passed by reference.
>

I don't like this, and don't find it particularly useful. There's also
the problem Joe mentions with types; inevitably, someone wants to pass a
size_t or an unsigned int or whatnot, and allowing that gets ugly, as is
forcing the caller to copy the value to a temp u64.

If you really want this, I think it would be much better to introduce a
helper which takes a user-supplied (typically small stack) buffer,
formats into that, and maybe for convenience returns that buffer (so it
can be passed directly to a %s). That's a lot more flexible, and avoids
the annoying type issue since the user's value just gets passed directly
(and thus auto-promoted to u64) to the helper.

The %pX space is also rapidly diminishing, so we should think twice
before introducing yet another rarely used extension.

In any case, I had to read the implementation to figure out that the
prefix chosen is the largest for which the printed value is exactly what
was passed in. Please make that more explicit. [It also means that the
printed string isn't necessarily human readable at all, as your test
value 1097364144125 shows].

Rasmus

  parent reply	other threads:[~2016-01-18 20:57 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-14 22:23 [PATCH v2 00/11] lib/vsprintf: refactor and introduce %pl specifier Andy Shevchenko
2016-01-14 22:23 ` [PATCH v2 01/11] lib/vsprintf: introduce put_one_char() for 3 line idiom Andy Shevchenko
2016-01-18 20:35   ` Rasmus Villemoes
2016-01-14 22:23 ` [PATCH v2 02/11] lib/vsprintf: make default_dec_spec global Andy Shevchenko
2016-01-18 20:38   ` Rasmus Villemoes
2016-01-14 22:23 ` [PATCH v2 03/11] lib/vsprintf: make default_str_spec global Andy Shevchenko
2016-01-14 22:23 ` [PATCH v2 04/11] lib/string_helpers: export string_units_{2,10} for others Andy Shevchenko
2016-01-14 22:23 ` [PATCH v2 05/11] lib/string_helpers: fix indentation in few places Andy Shevchenko
2016-01-14 22:23 ` [PATCH v2 06/11] lib/vsprintf: introduce %pl to print in human-readable form Andy Shevchenko
2016-01-15  3:04   ` Joe Perches
2016-01-18 20:57   ` Rasmus Villemoes [this message]
2016-01-21 21:13   ` H. Peter Anvin
2016-01-14 22:23 ` [PATCH v2 07/11] x86/efi: print size and base in binary units in efi_print_memmap Andy Shevchenko
2016-01-14 22:23 ` [PATCH v2 08/11] lib/vsprintf: allow range of prefix for %pl[From[To]] Andy Shevchenko
2016-01-18 21:40   ` Rasmus Villemoes
2016-01-14 22:23 ` [PATCH v2 09/11] lib/vsprintf: use precision field with %pl[From[To]] Andy Shevchenko
2016-01-18 22:21   ` Rasmus Villemoes
2016-01-14 22:23 ` [PATCH v2 10/11] cxgb4: print value in human-readable form via %.0plKM Andy Shevchenko
2016-01-14 22:23 ` [PATCH v2 11/11] pcmciamtd: " Andy Shevchenko
2016-01-21 12:51 ` [PATCH v2 00/11] lib/vsprintf: refactor and introduce %pl specifier Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mvs2ehbr.fsf@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=computersforpeace@gmail.com \
    --cc=elliott@hpe.com \
    --cc=hariprasad@chelsio.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@codeblueprint.co.uk \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.