From: Arran Cudbard-Bell Date: Tue, 26 Oct 2021 18:21:42 +0000 (-0400) Subject: Determine when typeof(ssize_t) == typeof(int64_t) and fix _Generic expressions which... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f49e2cf59ef7fa5bcf0e191fd71780ff0bd5464f;p=thirdparty%2Ffreeradius-server.git Determine when typeof(ssize_t) == typeof(int64_t) and fix _Generic expressions which use both --- diff --git a/configure b/configure index 120dfbad0b0..f1760400384 100755 --- 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 + #include + + 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 + #include + + 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} diff --git a/configure.ac b/configure.ac index 1fbab0e3d60..3168cd47b91 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/m4/ax_cc.m4 b/m4/ax_cc.m4 index 24e6c64cd15..5a3afc6328e 100644 --- a/m4/ax_cc.m4 +++ b/m4/ax_cc.m4 @@ -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 + #include + + 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 + #include + + 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 # diff --git a/src/include/autoconf.h.in b/src/include/autoconf.h.in index 6defb3610c9..7bae9952b09 100644 --- a/src/include/autoconf.h.in +++ b/src/include/autoconf.h.in @@ -596,10 +596,17 @@ /* 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 */ diff --git a/src/lib/util/sbuff.h b/src/lib/util/sbuff.h index 8780d8e3d20..6973c80253b 100644 --- a/src/lib/util/sbuff.h +++ b/src/lib/util/sbuff.h @@ -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) \ )