mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 21:25:04 -07:00
Merge #9532 from justinmk/fix-fpclassify
This commit is contained in:
commit
969618ebb5
@ -19,6 +19,7 @@
|
||||
#include "nvim/eval/typval.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/mbyte.h"
|
||||
#include "nvim/math.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/charset.h" // vim_isprintc()
|
||||
@ -28,11 +29,6 @@
|
||||
#include "nvim/lib/kvec.h"
|
||||
#include "nvim/eval/typval_encode.h"
|
||||
|
||||
#ifdef __MINGW32__
|
||||
# undef fpclassify
|
||||
# define fpclassify __fpclassify
|
||||
#endif
|
||||
|
||||
#define ga_concat(a, b) ga_concat(a, (char_u *)b)
|
||||
#define utf_ptr2char(b) utf_ptr2char((char_u *)b)
|
||||
#define utf_ptr2len(b) ((size_t)utf_ptr2len((char_u *)b))
|
||||
@ -327,7 +323,7 @@ int encode_read_from_list(ListReaderState *const state, char *const buf,
|
||||
#define TYPVAL_ENCODE_CONV_FLOAT(tv, flt) \
|
||||
do { \
|
||||
const float_T flt_ = (flt); \
|
||||
switch (fpclassify(flt_)) { \
|
||||
switch (xfpclassify(flt_)) { \
|
||||
case FP_NAN: { \
|
||||
ga_concat(gap, (char_u *) "str2float('nan')"); \
|
||||
break; \
|
||||
@ -531,7 +527,7 @@ int encode_read_from_list(ListReaderState *const state, char *const buf,
|
||||
#define TYPVAL_ENCODE_CONV_FLOAT(tv, flt) \
|
||||
do { \
|
||||
const float_T flt_ = (flt); \
|
||||
switch (fpclassify(flt_)) { \
|
||||
switch (xfpclassify(flt_)) { \
|
||||
case FP_NAN: { \
|
||||
EMSG(_("E474: Unable to represent NaN value in JSON")); \
|
||||
return FAIL; \
|
||||
|
42
src/nvim/math.c
Normal file
42
src/nvim/math.c
Normal file
@ -0,0 +1,42 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
||||
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "nvim/math.h"
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "math.c.generated.h"
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) && __clang__ == 1 && __clang_major__ >= 6
|
||||
// Workaround glibc + Clang 6+ bug. #8274
|
||||
// https://bugzilla.redhat.com/show_bug.cgi?id=1472437
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wconversion"
|
||||
#endif
|
||||
int xfpclassify(double d)
|
||||
{
|
||||
#if defined(__MINGW32__)
|
||||
// Workaround mingw warning. #7863
|
||||
return __fpclassify(d);
|
||||
#else
|
||||
return fpclassify(d);
|
||||
#endif
|
||||
}
|
||||
int xisinf(double d)
|
||||
{
|
||||
return isinf(d);
|
||||
}
|
||||
int xisnan(double d)
|
||||
{
|
||||
#if defined(__MINGW32__)
|
||||
// Workaround mingw warning. #7863
|
||||
return _isnan(d);
|
||||
#else
|
||||
return isnan(d);
|
||||
#endif
|
||||
}
|
||||
#if defined(__clang__) && __clang__ == 1 && __clang_major__ >= 6
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
7
src/nvim/math.h
Normal file
7
src/nvim/math.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef NVIM_MATH_H
|
||||
#define NVIM_MATH_H
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "math.h.generated.h"
|
||||
#endif
|
||||
#endif // NVIM_MATH_H
|
@ -27,6 +27,7 @@
|
||||
#include "nvim/func_attr.h"
|
||||
#include "nvim/getchar.h"
|
||||
#include "nvim/mark.h"
|
||||
#include "nvim/math.h"
|
||||
#include "nvim/mbyte.h"
|
||||
#include "nvim/memfile.h"
|
||||
#include "nvim/memline.h"
|
||||
@ -50,16 +51,7 @@
|
||||
#include "nvim/os/shell.h"
|
||||
#include "nvim/eval/encode.h"
|
||||
|
||||
#ifdef __MINGW32__
|
||||
# undef fpclassify
|
||||
# define fpclassify __fpclassify
|
||||
# undef isnan
|
||||
# define isnan _isnan
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copy "string" into newly allocated memory.
|
||||
*/
|
||||
/// Copy "string" into newly allocated memory.
|
||||
char_u *vim_strsave(const char_u *string)
|
||||
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
@ -1214,14 +1206,14 @@ int vim_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap,
|
||||
remove_trailing_zeroes = true;
|
||||
}
|
||||
|
||||
if (isinf(f)
|
||||
if (xisinf(f)
|
||||
|| (strchr("fF", fmt_spec) != NULL && abs_f > 1.0e307)) {
|
||||
xstrlcpy(tmp, infinity_str(f > 0.0, fmt_spec,
|
||||
force_sign, space_for_positive),
|
||||
sizeof(tmp));
|
||||
str_arg_l = strlen(tmp);
|
||||
zero_padding = 0;
|
||||
} else if (isnan(f)) {
|
||||
} else if (xisnan(f)) {
|
||||
// Not a number: nan or NAN
|
||||
memmove(tmp, ASCII_ISUPPER(fmt_spec) ? "NAN" : "nan", 4);
|
||||
str_arg_l = 3;
|
||||
|
Loading…
Reference in New Issue
Block a user