aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2020-10-15 22:47:35 +0200
committerJay Berkenbilt <ejb@ql.org>2020-10-16 13:02:23 +0200
commitff65e272a8f8e647a3db5187e5c4594ff01cbd34 (patch)
treecb86bf74c0b5c6d1d1f49a3dbcf519ac4fe3cbe2
parentbe21ede7ba05027829adaf7275e9bbbc1574a760 (diff)
downloadqpdf-ff65e272a8f8e647a3db5187e5c4594ff01cbd34.tar.zst
Fix printf formatting for newer msvc
Use autoconf rather than ifdefs to determine what format string to use for long long.
-rw-r--r--autofiles.sums4
-rwxr-xr-xconfigure57
-rw-r--r--configure.ac33
-rw-r--r--libqpdf/qpdf/qpdf-config.h.in3
-rw-r--r--make/libtool.mk6
-rw-r--r--make/mingw.mk6
-rw-r--r--make/msvc.mk6
-rw-r--r--qpdf/build.mk2
-rw-r--r--qpdf/qpdf-ctest.c9
9 files changed, 107 insertions, 19 deletions
diff --git a/autofiles.sums b/autofiles.sums
index d80a2bc7..89be5836 100644
--- a/autofiles.sums
+++ b/autofiles.sums
@@ -1,6 +1,6 @@
-be950d7be6b0aa2c9c926ac43ca9478ef864b1cb2c8184fd393c9ce4c0972bcc configure.ac
+055e54a34d94a0c2ed9451042a1c747e47b29259a9035af9e7327401a5c3fbd1 configure.ac
d3f9ee6f6f0846888d9a10fd3dad2e4b1258be84205426cf04d7cef02d61dad7 aclocal.m4
-b0ce6d1dba8effa47d25154b2bb56eddafc997254a0f3f903cf9b6abffc03616 libqpdf/qpdf/qpdf-config.h.in
+cf2c764639c4c94abc183a0976eca6ae500b80790ea25e3d0af97b23587363b7 libqpdf/qpdf/qpdf-config.h.in
5297971a0ef90bcd5563eb3f7127a032bb76d3ae2af7258bf13479caf8983a60 m4/ax_cxx_compile_stdcxx.m4
35bc5c645dc42d47f2daeea06f8f3e767c8a1aee6a35eb2b4854fd2ce66c3413 m4/ax_random_device.m4
6a1e4f8aa2902d7993300660c43e6ee479b4b6781ed7d5ef9c9f9f1cc46623b7 m4/libtool.m4
diff --git a/configure b/configure
index d6aebce8..47e08dad 100755
--- a/configure
+++ b/configure
@@ -17694,6 +17694,63 @@ $as_echo "no" >&6; }
fi
fi
+LL_FMT=""
+oCFLAGS=$CFLAGS
+CFLAGS="$WFLAGS $CFLAGS"
+for fmt in "%lld" "%I64d" "%I64lld"; do
+ if test "$LL_FMT" = ""; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking printf format for long long: $fmt" >&5
+$as_echo_n "checking printf format for long long: $fmt... " >&6; }
+ if test "$cross_compiling" = yes; then :
+ LL_FMT="%lld"
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+ #define _CRT_SECURE_NO_WARNINGS
+ #include <stdio.h>
+ #include <string.h>
+
+int
+main ()
+{
+
+ long long int a = 123456789012345ll;
+ char s[30];
+ sprintf(s, "$fmt", a);
+ return (strcmp(s, "123456789012345") == 0) ? 0 : 1
+
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ LL_FMT=$fmt
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+ if test "$LL_FMT" != ""; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ fi
+ fi
+done
+CFLAGS=$oCFLAGS
+if test "LL_FMT" = ""; then
+ LL_FMT="%lld%"
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define LL_FMT "$LL_FMT"
+_ACEOF
+
+
if test "$BUILDRULES" = "msvc"; then
diff --git a/configure.ac b/configure.ac
index 3e91ae19..83587b82 100644
--- a/configure.ac
+++ b/configure.ac
@@ -505,6 +505,39 @@ if test "$BUILDRULES" != "msvc"; then
fi
fi
+LL_FMT=""
+oCFLAGS=$CFLAGS
+CFLAGS="$WFLAGS $CFLAGS"
+for fmt in "%lld" "%I64d" "%I64lld"; do
+ if test "$LL_FMT" = ""; then
+ AC_MSG_CHECKING(printf format for long long: $fmt)
+ AC_RUN_IFELSE([AC_LANG_PROGRAM(
+ [[
+ #define _CRT_SECURE_NO_WARNINGS
+ #include <stdio.h>
+ #include <string.h>
+ ]],
+ [[
+ long long int a = 123456789012345ll;
+ char s[30];
+ sprintf(s, "]$fmt[", a);
+ return (strcmp(s, "123456789012345") == 0) ? 0 : 1
+ ]]
+ )],
+ [LL_FMT=$fmt],[],[LL_FMT="%lld"])
+ if test "$LL_FMT" != ""; then
+ AC_MSG_RESULT(yes)
+ else
+ AC_MSG_RESULT(no)
+ fi
+ fi
+done
+CFLAGS=$oCFLAGS
+if test "LL_FMT" = ""; then
+ LL_FMT="%lld%"
+fi
+AC_DEFINE_UNQUOTED([LL_FMT], ["$LL_FMT"], [printf format for long long])
+
AC_SUBST(WINDOWS_WMAIN_XLINK_FLAGS)
AC_SUBST(WINDOWS_MAIN_XLINK_FLAGS)
if test "$BUILDRULES" = "msvc"; then
diff --git a/libqpdf/qpdf/qpdf-config.h.in b/libqpdf/qpdf/qpdf-config.h.in
index c9886b57..2a279d6a 100644
--- a/libqpdf/qpdf/qpdf-config.h.in
+++ b/libqpdf/qpdf/qpdf-config.h.in
@@ -51,6 +51,9 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
+/* printf format for long long */
+#undef LL_FMT
+
/* Define to the sub-directory where libtool stores uninstalled libraries. */
#undef LT_OBJDIR
diff --git a/make/libtool.mk b/make/libtool.mk
index abd0aa7e..1ab92b75 100644
--- a/make/libtool.mk
+++ b/make/libtool.mk
@@ -47,10 +47,10 @@ define compile
-c $(1) -o $(call src_to_obj,$(1))
endef
-# 1 2
-# Usage: $(call c_compile,src,includes)
+# 1 2 3
+# Usage: $(call c_compile,src,includes,xflags)
define c_compile
- $(CC) $(CFLAGS) \
+ $(CC) $(CFLAGS) $(3) \
$(call depflags,$(basename $(call c_src_to_obj,$(1)))) \
$(foreach I,$(2),-I$(I)) \
$(CPPFLAGS) \
diff --git a/make/mingw.mk b/make/mingw.mk
index 9689ef94..20d648b0 100644
--- a/make/mingw.mk
+++ b/make/mingw.mk
@@ -24,10 +24,10 @@ define compile
-c $(1) -o $(call src_to_obj,$(1))
endef
-# 1 2
-# Usage: $(call c_compile,src,includes)
+# 1 2 3
+# Usage: $(call c_compile,src,includes,xflags)
define c_compile
- $(CC) $(CPPFLAGS) $(CFLAGS) \
+ $(CC) $(CPPFLAGS) $(CFLAGS) $(3) \
$(call depflags,$(basename $(call src_to_obj,$(1)))) \
$(foreach I,$(2),-I$(I)) \
-c $(1) -o $(call c_src_to_obj,$(1))
diff --git a/make/msvc.mk b/make/msvc.mk
index 108ce3b6..c8bc57bc 100644
--- a/make/msvc.mk
+++ b/make/msvc.mk
@@ -32,10 +32,10 @@ define compile
-c $(1) -Fo$(call src_to_obj,$(1))
endef
-# 1 2
-# Usage: $(call c_compile,src,includes)
+# 1 2 3
+# Usage: $(call c_compile,src,includes,xflags)
define c_compile
- cl -nologo -O2 -Zi -Gy -EHsc -MD $(CPPFLAGS) $(CFLAGS) \
+ cl -nologo -O2 -Zi -Gy -EHsc -MD $(CPPFLAGS) $(CFLAGS) $(3) \
$(foreach I,$(2),-I$(I)) \
-c $(1) -Fo$(call c_src_to_obj,$(1))
endef
diff --git a/qpdf/build.mk b/qpdf/build.mk
index a9dd7187..1bab58b7 100644
--- a/qpdf/build.mk
+++ b/qpdf/build.mk
@@ -48,7 +48,7 @@ $(foreach B,$(BINS_qpdf),$(eval \
$(foreach B,$(CBINS_qpdf),$(eval \
$(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.$(OBJ): qpdf/$(B).c ; \
- $(call c_compile,qpdf/$(B).c,$(INCLUDES_qpdf))))
+ $(call c_compile,qpdf/$(B).c,$(INCLUDES_qpdf),$(XCFLAGS_qpdf_$(B)))))
$(foreach B,$(BINS_qpdf) $(CBINS_qpdf),$(eval \
qpdf/$(OUTPUT_DIR)/$(call binname,$(B)): $(OBJS_$(B)) ; \
diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c
index 579d5890..fad121af 100644
--- a/qpdf/qpdf-ctest.c
+++ b/qpdf/qpdf-ctest.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include "../libqpdf/qpdf/qpdf-config.h" // for LL_FMT
static char* whoami = 0;
static qpdf_data qpdf = 0;
@@ -36,13 +37,7 @@ static FILE* safe_fopen(char const* filename, char const* mode)
static void report_errors()
{
-#ifdef _WIN32
-# define POS_FMT " pos : %I64d\n"
-#else
-/* If your compiler doesn't support lld, change to ld and lose
- precision on offsets in error messages. */
-# define POS_FMT " pos : %lld\n"
-#endif
+#define POS_FMT " pos : " LL_FMT "\n"
qpdf_error e = 0;
while (qpdf_more_warnings(qpdf))
{