1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-11-02 10:53:16 +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:
Viktor Szakats
2023-03-11 16:43:13 +01:00
committed by GitHub
parent 509c84e3c5
commit c45ba4d624
15 changed files with 516 additions and 498 deletions

View File

@@ -163,8 +163,8 @@ comp_method_zlib_init(LIBSSH2_SESSION * session, int compr,
if(status != Z_OK) {
LIBSSH2_FREE(session, strm);
_libssh2_debug(session, LIBSSH2_TRACE_TRANS,
"unhandled zlib error %d", status);
_libssh2_debug((session, LIBSSH2_TRACE_TRANS,
"unhandled zlib error %d", status));
return LIBSSH2_ERROR_COMPRESS;
}
*abstract = strm;
@@ -204,9 +204,9 @@ comp_method_zlib_comp(LIBSSH2_SESSION *session,
return 0;
}
_libssh2_debug(session, LIBSSH2_TRACE_TRANS,
_libssh2_debug((session, LIBSSH2_TRACE_TRANS,
"unhandled zlib compression error %d, avail_out",
status, strm->avail_out);
status, strm->avail_out));
return _libssh2_error(session, LIBSSH2_ERROR_ZLIB, "compression failure");
}
@@ -276,8 +276,8 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session,
else {
/* error state */
LIBSSH2_FREE(session, out);
_libssh2_debug(session, LIBSSH2_TRACE_TRANS,
"unhandled zlib error %d", status);
_libssh2_debug((session, LIBSSH2_TRACE_TRANS,
"unhandled zlib error %d", status));
return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"decompression failure");
}