This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/6846] New: Full featured printf hooks


The bugzilla will serve as a gathering for a patchset I'm introducing to extend
printf with a fully featured callback mechanism to support additional data-types
beyond it's current built-in types.

Caveats: This is an RFC at this point.  I'm not asking that this patch be
checked in.

Terms:
--------------------
'Format Specification Characters' - Umbrella term used to describe any character
which directs a datatype to string conversion operation.

'Conversion Specifier' - Character sequence of 1 or more bytes used to indicate
how a data type is converted.

'Length Modifier' - Character sequence of 1 or more bytes used to indicate the
length of the data type to be converted.

? Deficiencies:
-----------------------------------------------------------------------------
∘ Existing hooks only work for conversion specifiers, i.e. new length modifier
codes aren't recognized which means they aren't usable by most new data type
libraries, e.g. Vector, DFP, VSX, and AVX which introduce new length modifiers:

‣ Decimal Float:
? Length Modifiers: H,D,DD
? Conversion Specifiers: e,E,f,F,g,G,a,A

‣ Altivec/VMX:
? Length Modifiers: vl,vh,lv,hv,v, vll, llv
? Conversions Specifiers: e,E,f,F,g,G,d,i,u,o,p,x,X.c
∘ Existing hooks only support single character specification modifiers, and by
extension single-character length modifiers if we reused the existing mechanism.

? Challenges:
-----------------------------------------------------------------------------
∘ The user can't tinker with fundamental data types in existing headers so there
is no easy way to use existing flags and types to pass information between user
supplied callback functions.

‣ This necessitates the introduction of additional 'user' fields in some of the
printf internal data structures.

∘ It'd be nice to implement this without having a va_arg callback but not
overriding va_arg would have the following effects:

‣ make it so that 128-bit data types can't be printed on architectures where
long double is double because type punning wouldn't work when va_arg peeling a
128 bit data type.

‣ ABIs with relatively complicated register ordering rules can't have similar
sized data types punned to long double 128, double, or float when va_arg
peeling, e.g. _Decimal128 with even-odd register pair rules can't be punned to
IBM long double 128.

∘ The current framework uses integer representation of characters to directly
index positions in an array for storing override information.  This breaks down
under multibyte modifiers and has to be replaced with something more robust.

? What features were introduced?
-----------------------------------------------------------------------------
∘ single and multi-byte length modifiers are now supported but at a slight cost
to performance.

∘ multi-byte formats which contain previously reserved types are supported
without obstructing the functionality of the default definition, e.g. you could
override %LVf and %Lf would still work (this is a fabricated sequence not
defined by a standard).

∘ reversible format codes work, e.g. %lvf and %vlf (as defined by the Altivec PIM).

∘ A va_arg callback function is required which will peel of any datatype into a
user defined data structure.

∘ A free callback function is required which will free the user defined data
structure when printf is done printing.

? What information is needed from the user?
-----------------------------------------------------------------------------
∘ The single to multi-byte character sequence that makes up the conversion
specifier.

∘ The single to multi-byte character sequence that makes up the length modifier.

∘ arginfo function which identifies data types and sets data type flags.

∘ converter override function which actually turns the data types into strings.

∘ va_arg override function to allow the user to peel off arguments into user
provided data structures.

∘ free function to allow this data to be freed when printf is done with it.

? The code currently has some known limitations:
-----------------------------------------------------------------------------
∘ There is no branch prediction done where we should probably predict that the
hooks aren't available.

∘ Some inline functions should be macros,

∘ Some of the wide character support is a bit dodgy and needs to be tested.

∘ Some kind of hash could replace the current arginfo lookup macros which are
implemented as iterative searches.

∘ I haven't versioned the register_printf_function() after changing the API.
Perhaps a new API should be introduced instead.

∘ Multi-byte specification modifiers may not work properly.  My tests aren't
entirely robust.

∘ I haven't tested format codes which consume more than one argument.  I should
be able to test this easily enough in a test-suite.

∘ Wide-character format codes may not work properly.

∘ I think the val_ptr mechanism for telling the free function where to find the
data type after it has been peeled is a little busted.

∘ There's quite of a bit of debug code and redundant macros used for debug.

-- 
           Summary: Full featured printf hooks
           Product: glibc
           Version: 2.8
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: libc
        AssignedTo: rsa at us dot ibm dot com
        ReportedBy: rsa at us dot ibm dot com
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=6846

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]