Please make byteswapping utilities behave consistently through static inlines
Submitted by Diego Elio Pettenò
Link to original bug (#557517)
Description
Right now the behaviour of the byteswapping utilities in glib is not consistent between them and with other similar interfaces in other libraries.
In particular, there is no consistency on whether the arguments to byteswapping macros are evaluated once or twice (which does matter for side-effects; while the documentation does point this out, it is buried under some general information that most programmers wouldn't feel the need to read, and "experimental knowledge" may prove fatal (on x86 with optimisation turned on evaluation happen once; if a developer wrote a software without noticing the one-line warning, and got it to work for him, might ship something that breaks on, say, AMD64 where the 16-bit macros evaluate the argument twice).
Comparable interfaces from C libraries (bswap_*) and FFmpeg/libavutil only evaluate the parameter once.
Since the inline assembly versions of the macros already use GNU extensions (extension), an alternative could be to use static inline functions to provide the same interface, and yet evaluate the arguments just once.
Empirical tests between glibc's and FFmpeg's bswap macros show that at least on GCC 4.3 whether the code is emitted through a macro or a static inline, the resulting assembly code is 100% identical. On the other hand, it makes debugging easier since the code is no more just "glued" on where the macro is expanded, and an user might opt in to disable inlining altogether to step through those functions, if needed.
I'll attach a proof-of-concept patch changing one macro into static inline, I'll be happy to convert the rest of the code to this form if it's to be accepted.
Version: 2.18.x