]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Determine when typeof(ssize_t) == typeof(int64_t) and fix _Generic expressions which...
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 26 Oct 2021 18:21:42 +0000 (14:21 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 26 Oct 2021 18:22:01 +0000 (14:22 -0400)
configure
configure.ac
m4/ax_cc.m4
src/include/autoconf.h.in
src/lib/util/sbuff.h

index 120dfbad0b0601144c3b6a26d7711accba6482f1..f17604003844125202ca6b030d4fa41cd0c756c6 100755 (executable)
--- a/configure
+++ b/configure
@@ -3094,6 +3094,10 @@ ac_config_headers="$ac_config_headers src/include/autoconf.h"
 
 
 
+
+
+
+
 
 
 
@@ -15287,7 +15291,6 @@ printf "%s\n" "#define HAVE_BUILTIN_CLZLL 1" >>confdefs.h
 fi
 
 
-
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for _Generic support in compiler" >&5
 printf %s "checking for _Generic support in compiler... " >&6; }
 if test ${ax_cv_cc_c11_generic+y}
@@ -15339,6 +15342,105 @@ if test "x$ax_cv_cc_c11_generic" != "xyes"; then
 fi
 
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if size_t == uint64_t" >&5
+printf %s "checking if size_t == uint64_t... " >&6; }
+if test ${ax_cv_cc_size_same_as_uint64+y}
+then :
+  printf %s "(cached) " >&6
+else $as_nop
+
+  if test "$cross_compiling" = yes
+then :
+  { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else $as_nop
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+
+        #include <stdint.h>
+        #include <stddef.h>
+
+        int main(int argc, char **argv) {
+          return _Generic((size_t)(0), uint64_t: 1, default: 0);
+        }
+
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"
+then :
+  ax_cv_cc_size_same_as_uint64=no
+else $as_nop
+  ax_cv_cc_size_same_as_uint64=yes
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_cc_size_same_as_uint64" >&5
+printf "%s\n" "$ax_cv_cc_size_same_as_uint64" >&6; }
+if test "x$ax_cv_cc_size_same_as_uint64" = "xyes"; then
+
+printf "%s\n" "#define SIZE_SAME_AS_UINT64 1" >>confdefs.h
+
+fi
+
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if ssize_t == int64_t" >&5
+printf %s "checking if ssize_t == int64_t... " >&6; }
+if test ${ax_cv_cc_ssize_same_as_int64+y}
+then :
+  printf %s "(cached) " >&6
+else $as_nop
+
+  if test "$cross_compiling" = yes
+then :
+  { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else $as_nop
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+
+        #include <stdint.h>
+        #include <stddef.h>
+
+        int main(int argc, char **argv) {
+          return _Generic((ssize_t)(0), int64_t: 1, default: 0);
+        }
+
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"
+then :
+  ax_cv_cc_ssize_same_as_int64=no
+else $as_nop
+  ax_cv_cc_ssize_same_as_int64=yes
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_cc_ssize_same_as_int64" >&5
+printf "%s\n" "$ax_cv_cc_ssize_same_as_int64" >&6; }
+if test "x$ax_cv_cc_ssize_same_as_int64" = "xyes"; then
+
+printf "%s\n" "#define SSIZE_SAME_AS_INT64 1" >>confdefs.h
+
+fi
+
+
+
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for crypt in -lcrypt" >&5
 printf %s "checking for crypt in -lcrypt... " >&6; }
 if test ${ac_cv_lib_crypt_crypt+y}
index 1fbab0e3d60109cef8d979ea51d040a33f0a4ef9..3168cd47b915d1c32eb06fe4ba2efe0348ea4304 100644 (file)
@@ -1929,12 +1929,14 @@ AX_CC_BUILTIN_CHOOSE_EXPR
 AX_CC_BUILTIN_TYPES_COMPATIBLE_P
 AX_CC_BUILTIN_BSWAP64
 AX_CC_BUILTIN_CLZLL
-
 AX_CC_HAVE_C11_GENERIC
 if test "x$ax_cv_cc_c11_generic" != "xyes"; then
   AC_MSG_ERROR([FreeRADIUS requires support for the C11 _Generic keyword])
 fi
 
+AX_CC_SIZE_SAME_AS_UINT64
+AX_CC_SSIZE_SAME_AS_INT64
+
 dnl #############################################################
 dnl #
 dnl #  7. Checks for library functions
index 24e6c64cd1555986520fcb39a0ff7e3e5c18c649..5a3afc6328ee3acd910dc81ac94ae2004e9f52cc 100644 (file)
@@ -335,6 +335,58 @@ if test "x$ax_cv_cc_builtin_clzll" = "xyes"; then
 fi
 ])
 
+dnl #
+dnl #  Check if size_t and int64_t are identical
+dnl #
+AC_DEFUN([AX_CC_SIZE_SAME_AS_UINT64],
+[
+AC_CACHE_CHECK([if size_t == uint64_t], [ax_cv_cc_size_same_as_uint64],[
+  AC_RUN_IFELSE(
+    [
+      AC_LANG_SOURCE([
+        #include <stdint.h>
+        #include <stddef.h>
+
+        int main(int argc, char **argv) {
+          return _Generic((size_t)(0), uint64_t: 1, default: 0);
+        }
+      ])
+    ],
+    [ax_cv_cc_size_same_as_uint64=no],
+    [ax_cv_cc_size_same_as_uint64=yes]
+  )
+])
+if test "x$ax_cv_cc_size_same_as_uint64" = "xyes"; then
+  AC_DEFINE([SIZE_SAME_AS_UINT64],1,[Define if the compiler supports size_t has the same underlying type as uint64])
+fi
+])
+
+dnl #
+dnl #  Check if ssize_t and int64_t are identical
+dnl #
+AC_DEFUN([AX_CC_SSIZE_SAME_AS_INT64],
+[
+AC_CACHE_CHECK([if ssize_t == int64_t], [ax_cv_cc_ssize_same_as_int64],[
+  AC_RUN_IFELSE(
+    [
+      AC_LANG_SOURCE([
+        #include <stdint.h>
+        #include <stddef.h>
+
+        int main(int argc, char **argv) {
+          return _Generic((ssize_t)(0), int64_t: 1, default: 0);
+        }
+      ])
+    ],
+    [ax_cv_cc_ssize_same_as_int64=no],
+    [ax_cv_cc_ssize_same_as_int64=yes]
+  )
+])
+if test "x$ax_cv_cc_ssize_same_as_int64" = "xyes"; then
+  AC_DEFINE([SSIZE_SAME_AS_INT64],1,[Define if the compiler supports ssize_t has the same underlying type as int64])
+fi
+])
+
 dnl #
 dnl # Determine the number of system cores we have
 dnl #
index 6defb3610c9998b1fe2152574cf490e9b7f7da0d..7bae9952b091bcea4cedad921b5ede9baf125926 100644 (file)
 /* Define as the return type of signal handlers (`int' or `void'). */
 #undef RETSIGTYPE
 
+/* Define if the compiler supports size_t has the same underlying type as
+   uint64 */
+#undef SIZE_SAME_AS_UINT64
+
 /* Solaris-Style ctime_r */
 #undef SOLARISSTYLE
 
 /* Define to 1 if you have the ANSI C header files. */
+/* Define if the compiler supports ssize_t has the same underlying type as
+   int64 */
+#undef SSIZE_SAME_AS_INT64
 #undef STDC_HEADERS
 
 /* SYSV-Style get*byaddr_r */
index 8780d8e3d20b1a0f9a5b6d579da35ad38dfb9f11..6973c80253b11109ed333e3b0514b154c951ad0c 100644 (file)
@@ -1459,22 +1459,37 @@ fr_slen_t fr_sbuff_out_uint16(fr_sbuff_parse_error_t *err, uint16_t *out, fr_sbu
 fr_slen_t fr_sbuff_out_uint32(fr_sbuff_parse_error_t *err, uint32_t *out, fr_sbuff_t *sbuff, bool no_trailing);
 fr_slen_t fr_sbuff_out_uint64(fr_sbuff_parse_error_t *err, uint64_t *out, fr_sbuff_t *sbuff, bool no_trailing);
 fr_slen_t fr_sbuff_out_size(fr_sbuff_parse_error_t *err, size_t *out, fr_sbuff_t *sbuff, bool no_trailing);
+fr_slen_t fr_sbuff_out_ssize(fr_sbuff_parse_error_t *err, ssize_t *out, fr_sbuff_t *sbuff, bool no_trailing);
 
 fr_slen_t fr_sbuff_out_uint8_oct(fr_sbuff_parse_error_t *err, uint8_t *out, fr_sbuff_t *sbuff, bool no_trailing);
 fr_slen_t fr_sbuff_out_uint16_oct(fr_sbuff_parse_error_t *err, uint16_t *out, fr_sbuff_t *sbuff, bool no_trailing);
 fr_slen_t fr_sbuff_out_uint32_oct(fr_sbuff_parse_error_t *err, uint32_t *out, fr_sbuff_t *sbuff, bool no_trailing);
 fr_slen_t fr_sbuff_out_uint64_oct(fr_sbuff_parse_error_t *err, uint64_t *out, fr_sbuff_t *sbuff, bool no_trailing);
 fr_slen_t fr_sbuff_out_size_oct(fr_sbuff_parse_error_t *err, size_t *out, fr_sbuff_t *sbuff, bool no_trailing);
+fr_slen_t fr_sbuff_out_ssize_oct(fr_sbuff_parse_error_t *err, ssize_t *out, fr_sbuff_t *sbuff, bool no_trailing);
 
 fr_slen_t fr_sbuff_out_uint8_hex(fr_sbuff_parse_error_t *err, uint8_t *out, fr_sbuff_t *sbuff, bool no_trailing);
 fr_slen_t fr_sbuff_out_uint16_hex(fr_sbuff_parse_error_t *err, uint16_t *out, fr_sbuff_t *sbuff, bool no_trailing);
 fr_slen_t fr_sbuff_out_uint32_hex(fr_sbuff_parse_error_t *err, uint32_t *out, fr_sbuff_t *sbuff, bool no_trailing);
 fr_slen_t fr_sbuff_out_uint64_hex(fr_sbuff_parse_error_t *err, uint64_t *out, fr_sbuff_t *sbuff, bool no_trailing);
 fr_slen_t fr_sbuff_out_size_hex(fr_sbuff_parse_error_t *err, size_t *out, fr_sbuff_t *sbuff, bool no_trailing);
+fr_slen_t fr_sbuff_out_ssize_hex(fr_sbuff_parse_error_t *err, ssize_t *out, fr_sbuff_t *sbuff, bool no_trailing);
 
 fr_slen_t fr_sbuff_out_float32(fr_sbuff_parse_error_t *err, float *out, fr_sbuff_t *sbuff, bool no_trailing);
 fr_slen_t fr_sbuff_out_float64(fr_sbuff_parse_error_t *err, double *out, fr_sbuff_t *sbuff, bool no_trailing);
 
+#ifndef SIZE_SAME_AS_UINT64
+#  define _fr_sbuff_out_size(_err, _out, _in)  size_t *        : fr_sbuff_out_size(_err, (size_t *)_out, _in, true),
+#else
+#  define _fr_sbuff_out_size(_err, _out, _in)
+#endif
+
+#ifndef SSIZE_SAME_AS_INT64
+#  define _fr_sbuff_out_ssize(_err, _out, _in) ssize_t *       : fr_sbuff_out_ssize(err, (ssize_t *)_out, _in, true),
+#else
+#  define _fr_sbuff_out_ssize(_err, _out, _in)
+#endif
+
 /** Parse a value based on the output type
  *
  * @param[out] _err    If not NULL a value describing the parse error
@@ -1495,7 +1510,8 @@ fr_slen_t fr_sbuff_out_float64(fr_sbuff_parse_error_t *err, double *out, fr_sbuf
                 uint16_t *     : fr_sbuff_out_uint16(_err, (uint16_t *)_out, _in, true), \
                 uint32_t *     : fr_sbuff_out_uint32(_err, (uint32_t *)_out, _in, true), \
                 uint64_t *     : fr_sbuff_out_uint64(_err, (uint64_t *)_out, _in, true), \
-                size_t *       : fr_sbuff_out_size(_err, (size_t *)_out, _in, true), \
+                _fr_sbuff_out_size(_err, _out, _in) \
+                _fr_sbuff_out_ssize(_err, _out, _in) \
                 float *        : fr_sbuff_out_float32(_err, (float *)_out, _in, true), \
                 double *       : fr_sbuff_out_float64(_err, (double *)_out, _in, true) \
        )