Skip to content

Commit

Permalink
wio: Turn w_print() and w_printerr() into inlines
Browse files Browse the repository at this point in the history
Make w_print() and w_printerr() be "static inline" functions,
instead of variadic macros, for better type safety and compiler
error reporting. W_FUNCTION_ATTR_WARN_UNUSED_RESULT is not used
with those functions, as it is quite common to ignore I/O errors
when printing messages to stdout/stderr anyway.
  • Loading branch information
aperezdc committed Jan 11, 2015
1 parent 461f9b1 commit a466aea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
4 changes: 2 additions & 2 deletions doc/wio.rst
Expand Up @@ -249,15 +249,15 @@ Functions
See :ref:`formatted-output` for more information.
.. c:function:: void w_print (format, ...)
.. c:function:: w_io_result_t w_print (format, ...)
Writes data in the given `format` to the standard output stream
``w_stdout``. The amount of consumed arguments depends on the
`format` string.
See :ref:`formatted-output` for more information.
.. c:function:: void w_printerr (format, ...)
.. c:function:: w_io_result_t w_printerr (format, ...)
Writes data in the given `format` to the standard error stream
``w_stderr``. The amount of consumed arguments depends on the
Expand Down
30 changes: 26 additions & 4 deletions wheel.h
Expand Up @@ -1521,10 +1521,32 @@ W_EXPORT w_io_result_t w_io_format_ulong_oct (w_io_t *io, unsigned long value)
W_FUNCTION_ATTR_WARN_UNUSED_RESULT
W_FUNCTION_ATTR_NOT_NULL ((1));

#define w_print(...) \
W_IO_NORESULT (w_io_format (w_stdout, __VA_ARGS__))
#define w_printerr(...) \
W_IO_NORESULT (w_io_format (w_stderr, __VA_ARGS__))
static inline w_io_result_t w_print (const char *format, ...)
W_FUNCTION_ATTR_NOT_NULL ((1));

static inline w_io_result_t
w_print (const char *format, ...)
{
va_list args;
va_start (args, format);
w_io_result_t r = w_io_formatv (w_stdout, format, args);
va_end (args);
return r;
}

static inline w_io_result_t w_printerr (const char *format, ...)
W_FUNCTION_ATTR_NOT_NULL ((1));

static inline w_io_result_t
w_printerr (const char *format, ...)
{
va_list args;
va_start (args, format);
w_io_result_t r = w_io_formatv (w_stderr, format, args);
va_end (args);
return r;
}


/*!
* Reads formatted input from an I/O object.
Expand Down
4 changes: 2 additions & 2 deletions wio.c
Expand Up @@ -545,7 +545,7 @@ w_io_formatv (w_io_t *io, const char *fmt, va_list args)
}


/*~f void w_print (format, ...)
/*~f w_io_result_t w_print (format, ...)
*
* Writes data in the given `format` to the standard output stream
* ``w_stdout``. The amount of consumed arguments depends on the
Expand All @@ -554,7 +554,7 @@ w_io_formatv (w_io_t *io, const char *fmt, va_list args)
* See :ref:`formatted-output` for more information.
*/

/*~f void w_printerr (format, ...)
/*~f w_io_result_t w_printerr (format, ...)
*
* Writes data in the given `format` to the standard error stream
* ``w_stderr``. The amount of consumed arguments depends on the
Expand Down

0 comments on commit a466aea

Please sign in to comment.