From 22afc6bdd99959a7789873d178df9ea2a9c12c99 Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Fri, 13 Jan 2017 09:48:05 -0800 Subject: [PATCH] msvcrt: Implement nan Linux and Windows behave a bit differently Windows ignores the input (https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/nan-nanf-nanl) Linux crashes on NULL input a constant, known value is used for both cases where nan/nanf is and is not available Signed-off-by: Daniel Lehman --- configure.ac | 2 ++ .../api-ms-win-crt-math-l1-1-0.spec | 6 ++-- dlls/msvcr120/msvcr120.spec | 6 ++-- dlls/msvcr120_app/msvcr120_app.spec | 6 ++-- dlls/msvcrt/math.c | 35 ++++++++++++++++++++++ dlls/ucrtbase/ucrtbase.spec | 6 ++-- include/config.h.in | 6 ++++ 7 files changed, 55 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 353f271..4adb473 100644 --- a/configure.ac +++ b/configure.ac @@ -2554,6 +2554,8 @@ AC_CHECK_FUNCS(\ lrintf \ lround \ lroundf \ + nan \ + nanf \ nearbyint \ nearbyintf \ powl \ diff --git a/dlls/api-ms-win-crt-math-l1-1-0/api-ms-win-crt-math-l1-1-0.spec b/dlls/api-ms-win-crt-math-l1-1-0/api-ms-win-crt-math-l1-1-0.spec index 6a31197..8ff4c58 100644 --- a/dlls/api-ms-win-crt-math-l1-1-0/api-ms-win-crt-math-l1-1-0.spec +++ b/dlls/api-ms-win-crt-math-l1-1-0/api-ms-win-crt-math-l1-1-0.spec @@ -288,9 +288,9 @@ @ cdecl lroundl(double) ucrtbase.lroundl @ cdecl modf(double ptr) ucrtbase.modf @ cdecl -arch=arm,x86_64 modff(float ptr) ucrtbase.modff -@ stub nan -@ stub nanf -@ stub nanl +@ cdecl nan(str) ucrtbase.nan +@ cdecl nanf(str) ucrtbase.nanf +@ cdecl nanl(str) ucrtbase.nanl @ cdecl nearbyint(double) ucrtbase.nearbyint @ cdecl nearbyintf(float) ucrtbase.nearbyintf @ cdecl nearbyintl(double) ucrtbase.nearbyintl diff --git a/dlls/msvcr120/msvcr120.spec b/dlls/msvcr120/msvcr120.spec index edd31e3..e38de79 100644 --- a/dlls/msvcr120/msvcr120.spec +++ b/dlls/msvcr120/msvcr120.spec @@ -2293,9 +2293,9 @@ @ cdecl memset(ptr long long) MSVCRT_memset @ cdecl modf(double ptr) MSVCRT_modf @ cdecl -arch=arm,x86_64 modff(float ptr) MSVCRT_modff -@ stub nan -@ stub nanf -@ stub nanl +@ cdecl nan(str) MSVCR120_nan +@ cdecl nanf(str) MSVCR120_nanf +@ cdecl nanl(str) MSVCR120_nanl @ cdecl nearbyint(double) MSVCRT_nearbyint @ cdecl nearbyintf(float) MSVCRT_nearbyintf @ cdecl nearbyintl(double) MSVCRT_nearbyint diff --git a/dlls/msvcr120_app/msvcr120_app.spec b/dlls/msvcr120_app/msvcr120_app.spec index 3c1c343..e6ab0f7 100644 --- a/dlls/msvcr120_app/msvcr120_app.spec +++ b/dlls/msvcr120_app/msvcr120_app.spec @@ -1956,9 +1956,9 @@ @ cdecl memset(ptr long long) msvcr120.memset @ cdecl modf(double ptr) msvcr120.modf @ cdecl -arch=arm,x86_64 modff(float ptr) msvcr120.modff -@ stub nan -@ stub nanf -@ stub nanl +@ cdecl nan(str) msvcr120.nan +@ cdecl nanf(str) msvcr120.nanf +@ cdecl nanl(str) msvcr120.nanl @ cdecl nearbyint(double) msvcr120.nearbyint @ cdecl nearbyintf(float) msvcr120.nearbyintf @ cdecl nearbyintl(double) msvcr120.nearbyintl diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c index 6880d6c..dcaafb4 100644 --- a/dlls/msvcrt/math.c +++ b/dlls/msvcrt/math.c @@ -2901,3 +2901,38 @@ LDOUBLE CDECL MSVCR120_lgammal(LDOUBLE x) { return MSVCR120_lgamma(x); } + +/********************************************************************* + * nan (MSVCR120.@) + */ +double CDECL MSVCR120_nan(const char *tagp) +{ + /* Windows ignores input (MSDN) and Linux crashes on NULL */ + const char *dummy = "NAN"; +#ifdef HAVE_NAN + return nan(dummy); +#else + return strtod(dummy, NULL); +#endif +} + +/********************************************************************* + * nanf (MSVCR120.@) + */ +float CDECL MSVCR120_nanf(const char *tagp) +{ + const char *dummy = "NAN"; +#ifdef HAVE_NANF + return nanf(dummy); +#else + return strtof(dummy, NULL); +#endif +} + +/********************************************************************* + * nanl (MSVCR120.@) + */ +LDOUBLE CDECL MSVCR120_nanl(const char *tagp) +{ + return MSVCR120_nan(tagp); +} diff --git a/dlls/ucrtbase/ucrtbase.spec b/dlls/ucrtbase/ucrtbase.spec index 4cd3760..df7cc93 100644 --- a/dlls/ucrtbase/ucrtbase.spec +++ b/dlls/ucrtbase/ucrtbase.spec @@ -2429,9 +2429,9 @@ @ cdecl memset(ptr long long) MSVCRT_memset @ cdecl modf(double ptr) MSVCRT_modf @ cdecl -arch=arm,x86_64 modff(float ptr) MSVCRT_modff -@ stub nan -@ stub nanf -@ stub nanl +@ cdecl nan(str) MSVCR120_nan +@ cdecl nanf(str) MSVCR120_nanf +@ cdecl nanl(str) MSVCR120_nanl @ cdecl nearbyint(double) MSVCRT_nearbyint @ cdecl nearbyintf(float) MSVCRT_nearbyintf @ cdecl nearbyintl(double) MSVCRT_nearbyint diff --git a/include/config.h.in b/include/config.h.in index 5dcd90b..a5e6520 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -561,6 +561,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MPG123_H +/* Define to 1 if you have the `nan' function. */ +#undef HAVE_NAN + +/* Define to 1 if you have the `nanf' function. */ +#undef HAVE_NANF + /* Define to 1 if you have the header file. */ #undef HAVE_NCURSES_H -- 1.9.5