https://gcc.gnu.org/g:b6aafe9a5b1452f3bafae5889aebad0b3de408a3
commit r15-9183-gb6aafe9a5b1452f3bafae5889aebad0b3de408a3 Author: Iain Sandoe <i...@sandoe.co.uk> Date: Tue Mar 25 15:10:12 2025 +0000 libgcobol: Provide fallbacks for C32 strfromf32/64 functions. strfrom{f,d,l,fN) are all C23 and might not be available in general. This uses snprintf() to provide fall-backs where the libc does not yet have support. libgcobol/ChangeLog: * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Check for availability of strfromf32 and strfromf64. * libgcobol.cc (strfromf32, strfromf64): New. Signed-off-by: Iain Sandoe <i...@sandoe.co.uk> Diff: --- libgcobol/config.h.in | 6 ++++++ libgcobol/configure | 13 +++++++++++-- libgcobol/configure.ac | 3 +++ libgcobol/libgcobol.cc | 24 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/libgcobol/config.h.in b/libgcobol/config.h.in index b201266e0610..5dd2b5071ff1 100644 --- a/libgcobol/config.h.in +++ b/libgcobol/config.h.in @@ -36,6 +36,12 @@ /* Define to 1 if you have the <stdlib.h> header file. */ #undef HAVE_STDLIB_H +/* Define to 1 if you have the `strfromf32' function. */ +#undef HAVE_STRFROMF32 + +/* Define to 1 if you have the `strfromf64' function. */ +#undef HAVE_STRFROMF64 + /* Define to 1 if you have the <strings.h> header file. */ #undef HAVE_STRINGS_H diff --git a/libgcobol/configure b/libgcobol/configure index 44190d7e2fe0..e12b72e0817c 100755 --- a/libgcobol/configure +++ b/libgcobol/configure @@ -2520,6 +2520,8 @@ as_fn_append ac_func_list " random_r" as_fn_append ac_func_list " srandom_r" as_fn_append ac_func_list " initstate_r" as_fn_append ac_func_list " setstate_r" +as_fn_append ac_func_list " strfromf32" +as_fn_append ac_func_list " strfromf64" # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false @@ -12906,7 +12908,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 12909 "configure" +#line 12911 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -13012,7 +13014,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 13015 "configure" +#line 13017 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -16385,6 +16387,13 @@ done +# These are C23, and might not be available in libc. + + + + + + if test "${multilib}" = "yes"; then multilib_arg="--enable-multilib" else diff --git a/libgcobol/configure.ac b/libgcobol/configure.ac index 383b4134b130..34c0235c56b9 100644 --- a/libgcobol/configure.ac +++ b/libgcobol/configure.ac @@ -218,6 +218,9 @@ AC_SUBST(enable_static) # These are GLIBC AC_CHECK_FUNCS_ONCE(random_r srandom_r initstate_r setstate_r) +# These are C23, and might not be available in libc. +AC_CHECK_FUNCS_ONCE(strfromf32 strfromf64) + if test "${multilib}" = "yes"; then multilib_arg="--enable-multilib" else diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc index d8f4deda863a..c163e2c92f2b 100644 --- a/libgcobol/libgcobol.cc +++ b/libgcobol/libgcobol.cc @@ -68,6 +68,30 @@ #include "exceptl.h" +#if !defined (HAVE_STRFROMF32) +# if __FLT_MANT_DIG__ == 24 && __FLT_MAX_EXP__ == 128 +static int +strfromf32 (char *s, size_t n, const char *f, float v) +{ + return snprintf (s, n, f, (double) v); +} +# else +# error "It looks like float on this platform is not IEEE754" +# endif +#endif + +#if !defined (HAVE_STRFROMF64) +# if __DBL_MANT_DIG__ == 53 && __DBL_MAX_EXP__ == 1024 +static int +strfromf64 (char *s, size_t n, const char *f, double v) +{ + return snprintf (s, n, f, v); +} +# else +# error "It looks like double on this platform is not IEEE754" +# endif +#endif + // This couldn't be defined in symbols.h because it conflicts with a LEVEL66 // in parse.h #define LEVEL66 (66)