From 2364f7d445f7fd21695c0c651b1b80a581602980 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 30 May 2020 18:08:31 -0700 Subject: streams: maintain integer format string detector. * configure: provide LONGLONG_TYPE and INTPTR_TYPE macros in config.h that expand to a string literal capturing the original tokens of the type that was probed. * stream.c (struct fmt): Removed size member, replaced with type string. We can match format strings to the textual type, which will work even if we cannot compile that type. So that is to say, for instance the "%I64d" entry in the table is associated with "int64", whereas an expression like sizeof (int64) won't compile where that type doesn't exist. (fmt_tab): Replace sizes with type names. Also fix an issue: %llx was replicated in three rows of the table. (detect_format_string): Determine the textual type of cnum. It is a typedef for intptr_t, and the new INPTR_TYPE macro gives the tokens that were used to typedef intptr_t. If INTPTR_TYPE happens to be "longlong_t", we use LONGLONG_TYPE in its place. Then using the determined type, we can search the table for an appropriate entry: one which matches the type and whose conversion specifier works. Also, we now test all four conversion specifiers rather than assuming that if the decimal one is okay, the others work. Plus, if a working format string is not found, we now abort. --- configure | 2 ++ 1 file changed, 2 insertions(+) (limited to 'configure') diff --git a/configure b/configure index 57c66094..f22de6b9 100755 --- a/configure +++ b/configure @@ -1205,6 +1205,7 @@ done if [ -n "$longlong" ] ; then printf '"%s"\n' "$longlong" printf "#define HAVE_LONGLONG_T 1\n" >> config.h + printf "#define LONGLONG_TYPE \"%s\"\n" "$longlong" >> config.h printf "typedef $longlong longlong_t;\n" >> config.h else printf "none\n" @@ -1411,6 +1412,7 @@ fi printf '"%s"\n' "$intptr" printf "typedef $intptr int_ptr_t;\n" >> config.h printf "typedef unsigned $intptr uint_ptr_t;\n" >> config.h +printf "#define INTPTR_TYPE \"%s\"\n" "$intptr" >> config.h intptr_max_expr="((((convert(int_ptr_t, 1) << $((SIZEOF_PTR * SIZEOF_BYTE - 2))) - 1) << 1) + 1)" printf "#define INT_PTR_MAX %s\n" "$intptr_max_expr" >> config.h printf "#define INT_PTR_MIN (-INT_PTR_MAX-1)\n" >> config.h -- cgit v1.2.3