mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-17 22:58:26 +00:00
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch cleans up a few base headers, i.e., it removes unused includes from root/component.h, specifically base/heap.h and ram_session/ram_session.h. Hence, components that relied on the implicit inclusion of those headers have to manually include those headers now. While adjusting the log messages, I repeatedly stumbled over the problem that printing char * arguments is ambiguous. It is unclear whether to print the argument as pointer or null-terminated string. To overcome this problem, the patch introduces a new type 'Cstring' that allows the caller to express that the argument should be handled as null-terminated string. As a nice side effect, with this type in place, the optional len argument of the 'String' class could be removed. Instead of supplying a pair of (char const *, size_t), the constructor accepts a 'Cstring'. This, in turn, clears the way let the 'String' constructor use the new output mechanism to assemble a string from multiple arguments (and thereby getting rid of snprintf within Genode in the near future). To enforce the explicit resolution of the char * ambiguity, the 'char *' overload of the 'print' function is marked as deleted. Issue #1987
This commit is contained in:
committed by
Christian Helmuth
parent
a5d3aa8373
commit
17c79a9e23
@ -61,6 +61,15 @@ namespace Genode {
|
||||
*/
|
||||
void print(Output &output, char const *);
|
||||
|
||||
/**
|
||||
* Disallow printing non-const character buffers
|
||||
*
|
||||
* For 'char *' types, it is unclear whether the argument should be printed
|
||||
* as a pointer or a string. The call must resolve this ambiguity by either
|
||||
* casting the argument to 'void *' or wrapping it in a 'Cstring' object.
|
||||
*/
|
||||
void print(Output &, char *) = delete;
|
||||
|
||||
/**
|
||||
* Print pointer value
|
||||
*/
|
||||
@ -137,36 +146,39 @@ namespace Genode {
|
||||
* wrapped into an 'Hex' object, thereby selecting the corresponding
|
||||
* overloaded 'print' function below.
|
||||
*/
|
||||
struct Hex
|
||||
class Hex
|
||||
{
|
||||
enum Prefix { PREFIX, OMIT_PREFIX };
|
||||
enum Pad { PAD, NO_PAD };
|
||||
public:
|
||||
|
||||
unsigned long const value;
|
||||
size_t const digits;
|
||||
Prefix const prefix;
|
||||
Pad const pad;
|
||||
enum Prefix { PREFIX, OMIT_PREFIX };
|
||||
enum Pad { PAD, NO_PAD };
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param prefix by default, the value is prepended with the prefix
|
||||
* '0x'. The prefix can be suppressed by specifying
|
||||
* 'OMIT_PREFIX' as argument.
|
||||
* \param pad by default, leading zeros are stripped from the
|
||||
* output. If set to 'PAD', the leading zeros will be
|
||||
* printed.
|
||||
*/
|
||||
template <typename T>
|
||||
explicit Hex(T value, Prefix prefix = PREFIX, Pad pad = NO_PAD)
|
||||
: value(value), digits(2*sizeof(T)), prefix(prefix), pad(pad) { }
|
||||
private:
|
||||
|
||||
unsigned long long const _value;
|
||||
size_t const _digits;
|
||||
Prefix const _prefix;
|
||||
Pad const _pad;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param prefix by default, the value is prepended with the prefix
|
||||
* '0x'. The prefix can be suppressed by specifying
|
||||
* 'OMIT_PREFIX' as argument.
|
||||
* \param pad by default, leading zeros are stripped from the
|
||||
* output. If set to 'PAD', the leading zeros will be
|
||||
* printed.
|
||||
*/
|
||||
template <typename T>
|
||||
explicit Hex(T value, Prefix prefix = PREFIX, Pad pad = NO_PAD)
|
||||
: _value(value), _digits(2*sizeof(T)), _prefix(prefix), _pad(pad) { }
|
||||
|
||||
void print(Output &output) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Print hexadecimal number
|
||||
*/
|
||||
void print(Output &output, Hex const &);
|
||||
|
||||
/**
|
||||
* Print range as hexadecimal format
|
||||
*
|
||||
|
Reference in New Issue
Block a user