From a154ea0c91b64cd7fb4d56e7ea6840488a68cb1d Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Thu, 22 Feb 2024 21:22:56 -0500 Subject: [PATCH] [ruby/prism] Ignore other ERANGE errors for floats https://github.com/ruby/prism/commit/4267161ca7 --- prism/defines.h | 12 ++++++++++++ prism/prism.c | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/prism/defines.h b/prism/defines.h index 0abfa86e66..6c09f108c2 100644 --- a/prism/defines.h +++ b/prism/defines.h @@ -10,6 +10,7 @@ #define PRISM_DEFINES_H #include +#include #include #include #include @@ -113,4 +114,15 @@ # endif #endif +/** + * isinf on Windows is defined as accepting a float, but on POSIX systems it + * accepts a float, a double, or a long double. We want to mirror this behavior + * on windows. + */ +#ifdef _WIN32 +# include +# undef isinf +# define isinf(x) (sizeof(x) == sizeof(float) ? !_finitef(x) : !_finite(x)) +#endif + #endif diff --git a/prism/prism.c b/prism/prism.c index 4f268fc952..afd7969ae1 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -3181,7 +3181,7 @@ pm_double_parse(pm_parser_t *parser, const pm_token_t *token) { // If errno is set, then it should only be ERANGE. At this point we need to // check if it's infinity (it should be). - if (errno == ERANGE) { + if (errno == ERANGE && isinf(value)) { int warn_width; const char *ellipsis; @@ -3194,7 +3194,7 @@ pm_double_parse(pm_parser_t *parser, const pm_token_t *token) { } pm_diagnostic_list_append_format(&parser->warning_list, token->start, token->end, PM_WARN_FLOAT_OUT_OF_RANGE, warn_width, (const char *) token->start, ellipsis); - value = (value < 0x0) ? -HUGE_VAL : HUGE_VAL; + value = (value < 0.0) ? -HUGE_VAL : HUGE_VAL; } // Finally we can free the buffer and return the value.