lkml.org 
[lkml]   [2022]   [Jun]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH v4 05/34] vsprintf: %pf(%p)
Date
...
> > +Calling a pretty printer function
> > +---------------------------------
> > +
> > +::
> > +
> > + %pf(%p) pretty printer function taking one argument
> > + %pf(%p,%p) pretty printer function taking two arguments
> > +
> > +For calling generic pretty printers. A pretty printer is a function that takes
> > +as its first argument a pointer to a printbuf, and then zero or more additional
> > +pointer arguments. For example:
> > +
> > + void foo_to_text(struct printbuf *out, struct foo *foo)
> > + {
> > + pr_buf(out, "bar=%u baz=%u", foo->bar, foo->baz);
> > + }
> > +
> > + printf("%pf(%p)", foo_to_text, foo);
> > +
> > +Note that a pretty-printer may not sleep, if called from printk(). If called
> > +from pr_buf() or sprintf() there are no such restrictions.

I've lost the original email :-)

If you are going to implement this foo_to_text() needs to
be passed the field width, precision and flags.

Is there a real use for multiple arguments %pf(%p,%p) that can't
be implemented by requiring the caller use a relay structure?
That (sort of) solves the problem of people expecting to be
able to pass integers though.

An alternative would be using an array of a union type
to pass through the values extracted from the original va_list.

Or pass the first as a pointer (to get the possibility of compile
time format checking and any others as a union[].

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
\
 
 \ /
  Last update: 2022-06-21 13:12    [W:0.088 / U:2.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site