Skip to content

Commit beb3e1e

Browse files
authored
missing.h cleanup (#396)
* Remove unused ifndef branch and definition from missing.h `# define false ((_Bool)-1)` wrongly defines false as truthy value. `finite(double){return something(n);}` results in compile error. These ifdef branch were never used. isfinite, labs, llabs, vabs are not used anymore. These are never used. * Remove rb_rational_num/den check HAVE_RB_RATIONAL_NUM/DEN checks is to support ruby < 2.2.0. Currently, BigDecimal supports ruby >= 2.5.0 * Remove conditional include of stdlib.h and math.h stdlib.h and math.h are explicitly required in bigdecimal.c
1 parent 46fd1bd commit beb3e1e

File tree

2 files changed

+1
-100
lines changed

2 files changed

+1
-100
lines changed

ext/bigdecimal/extconf.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,10 @@ def have_builtin_func(name, check_expr, opt = "", &b)
3636
have_func("_BitScanReverse64", "intrin.h")
3737
end
3838

39-
have_func("labs", "stdlib.h")
40-
have_func("llabs", "stdlib.h")
41-
have_func("finite", "math.h")
42-
have_func("isfinite", "math.h")
43-
4439
have_header("ruby/atomic.h")
4540
have_header("ruby/internal/has/builtin.h")
4641
have_header("ruby/internal/static_assert.h")
4742

48-
have_func("rb_rational_num", "ruby.h")
49-
have_func("rb_rational_den", "ruby.h")
5043
have_func("rb_complex_real", "ruby.h")
5144
have_func("rb_complex_imag", "ruby.h")
5245
have_func("rb_opts_exception_p", "ruby.h")

ext/bigdecimal/missing.h

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ extern "C" {
88
#endif
99
#endif
1010

11-
#ifdef HAVE_STDLIB_H
12-
# include <stdlib.h>
13-
#endif
14-
15-
#ifdef HAVE_MATH_H
16-
# include <math.h>
17-
#endif
18-
1911
#ifndef RB_UNUSED_VAR
2012
# if defined(_MSC_VER) && _MSC_VER >= 1911
2113
# define RB_UNUSED_VAR(x) x [[maybe_unused]]
@@ -55,97 +47,13 @@ extern "C" {
5547

5648
/* bool */
5749

58-
#if defined(__bool_true_false_are_defined)
59-
# /* Take that. */
60-
61-
#elif defined(HAVE_STDBOOL_H)
50+
#ifndef __bool_true_false_are_defined
6251
# include <stdbool.h>
63-
64-
#else
65-
typedef unsigned char _Bool;
66-
# define bool _Bool
67-
# define true ((_Bool)+1)
68-
# define false ((_Bool)-1)
69-
# define __bool_true_false_are_defined
70-
#endif
71-
72-
/* abs */
73-
74-
#ifndef HAVE_LABS
75-
static inline long
76-
labs(long const x)
77-
{
78-
if (x < 0) return -x;
79-
return x;
80-
}
81-
#endif
82-
83-
#ifndef HAVE_LLABS
84-
static inline LONG_LONG
85-
llabs(LONG_LONG const x)
86-
{
87-
if (x < 0) return -x;
88-
return x;
89-
}
90-
#endif
91-
92-
#ifdef vabs
93-
# undef vabs
94-
#endif
95-
#if SIZEOF_VALUE <= SIZEOF_INT
96-
# define vabs abs
97-
#elif SIZEOF_VALUE <= SIZEOF_LONG
98-
# define vabs labs
99-
#elif SIZEOF_VALUE <= SIZEOF_LONG_LONG
100-
# define vabs llabs
101-
#endif
102-
103-
/* finite */
104-
105-
#ifndef HAVE_FINITE
106-
static int
107-
finite(double)
108-
{
109-
return !isnan(n) && !isinf(n);
110-
}
111-
#endif
112-
113-
#ifndef isfinite
114-
# ifndef HAVE_ISFINITE
115-
# define HAVE_ISFINITE 1
116-
# define isfinite(x) finite(x)
117-
# endif
11852
#endif
11953

12054
/* dtoa */
12155
char *BigDecimal_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve);
12256

123-
/* rational */
124-
125-
#ifndef HAVE_RB_RATIONAL_NUM
126-
static inline VALUE
127-
rb_rational_num(VALUE rat)
128-
{
129-
#ifdef RRATIONAL
130-
return RRATIONAL(rat)->num;
131-
#else
132-
return rb_funcall(rat, rb_intern("numerator"), 0);
133-
#endif
134-
}
135-
#endif
136-
137-
#ifndef HAVE_RB_RATIONAL_DEN
138-
static inline VALUE
139-
rb_rational_den(VALUE rat)
140-
{
141-
#ifdef RRATIONAL
142-
return RRATIONAL(rat)->den;
143-
#else
144-
return rb_funcall(rat, rb_intern("denominator"), 0);
145-
#endif
146-
}
147-
#endif
148-
14957
/* complex */
15058

15159
#ifndef HAVE_RB_COMPLEX_REAL

0 commit comments

Comments
 (0)