mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-20 02:42:09 +03:00
src: C89-compliant _libssh2_debug() macro (#831)
Before this patch, with debug logging disabled, libssh2 code used a variadic macro to catch `_libssh2_debug()` calls, and convert them to no-ops. In certain conditions, it used an empty inline function instead. Variadic macro is a C99 feature. It means that depending on compiler, and build settings, it littered the build log with warnings about this. The new solution uses the trick of passing the variable arg list as a single argument and pass that down to the debug function with a regular macro. When disabled, another regular C89-compatible macro converts it to a no-op. This makes inlining, C99 variadic macros and maintaining the conditions for each unnecessary and also makes the codebase compile more consistently, e.g. with forced C standards and/or picky warnings. TL;DR: It makes this feature C89-compliant.
This commit is contained in:
@@ -993,23 +993,12 @@ struct _LIBSSH2_COMP_METHOD
|
||||
};
|
||||
|
||||
#ifdef LIBSSH2DEBUG
|
||||
void _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format,
|
||||
...);
|
||||
void
|
||||
_libssh2_debug_low(LIBSSH2_SESSION * session, int context, const char *format,
|
||||
...);
|
||||
#define _libssh2_debug(x) _libssh2_debug_low x
|
||||
#else
|
||||
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
|
||||
(defined(__GNUC__) && !defined(__clang__))
|
||||
/* C99 supported and also by older GCC */
|
||||
#define _libssh2_debug(x,y,...) do {} while (0)
|
||||
#else
|
||||
/* no gcc and not C99, do static and hopefully inline */
|
||||
static inline void
|
||||
_libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
|
||||
{
|
||||
(void)session;
|
||||
(void)context;
|
||||
(void)format;
|
||||
}
|
||||
#endif
|
||||
#define _libssh2_debug(x) do {} while (0)
|
||||
#endif
|
||||
|
||||
#define LIBSSH2_SOCKET_UNKNOWN 1
|
||||
|
||||
Reference in New Issue
Block a user