MacOS portability: printf and VCL_INT (int64_t) leads to errors.
When attempting to compile the project on macos 11.6 (Big Sur), I get the following errors:
/Applications/Xcode.app/Contents/Developer/usr/bin/make all-recursive
Making all in src
CC vfp_brotli.lo
vfp_brotli.c:781:19: error: format specifies type 'long' but the argument has type 'VCL_INT' (aka 'long long') [-Werror,-Wformat]
vcl_name, quality, BROTLI_MIN_QUALITY,
^~~~~~~
vfp_brotli.c:49:53: note: expanded from macro 'VFAIL'
VRT_fail((ctx), "vfp brotli failure: " fmt, __VA_ARGS__)
~~~ ^~~~~~~~~~~
vfp_brotli.c:788:19: error: format specifies type 'long' but the argument has type 'VCL_INT' (aka 'long long') [-Werror,-Wformat]
vcl_name, lgwin, BROTLI_MIN_WINDOW_BITS,
^~~~~
vfp_brotli.c:49:53: note: expanded from macro 'VFAIL'
VRT_fail((ctx), "vfp brotli failure: " fmt, __VA_ARGS__)
~~~ ^~~~~~~~~~~
2 errors generated.
The issue here are the two format strings (from vfp_brotli.c, lines 779 - 791, on the 6.2 branch):
if (quality < BROTLI_MIN_QUALITY || quality > BROTLI_MAX_QUALITY) {
VFAIL(ctx, "new %s: quality %ld out of range (%d to %d)",
vcl_name, quality, BROTLI_MIN_QUALITY,
BROTLI_MAX_QUALITY);
return;
}
if (lgwin < BROTLI_MIN_WINDOW_BITS || lgwin > BROTLI_MAX_WINDOW_BITS) {
VFAIL(ctx, "new %s: lgwin %ld out of range (%d to %d)",
vcl_name, lgwin, BROTLI_MIN_WINDOW_BITS,
BROTLI_MAX_WINDOW_BITS);
return;
}
Both quality
and lgwin
are VCL_INT
and those are long long
on my platform, and %ld
won't accept these values.
There are two options here:
-
add
#include <inttypes.h>
and injectPRId64
into the format strings:VFAIL(ctx, "new %s: quality %" PRId64 " out of range (%d to %d)", // ... VFAIL(ctx, "new %s: lgwin %" PRId64 " out of range (%d to %d)",
-
cast to
intmax_t
and use%jd
; this is what the varnish project uses throughout (e.g. inVRT_INT_string(VRT_CTX, VCL_INT num)
):VFAIL(ctx, "new %s: quality %jd out of range (%d to %d)", vcl_name, (intmax_t)quality, BROTLI_MIN_QUALITY, // ... VFAIL(ctx, "new %s: lgwin %jd out of range (%d to %d)", vcl_name, (intmax_t)lgwin, BROTLI_MIN_WINDOW_BITS,
I'll make a PR, assuming that what varnish uses is preferred here.