Skip to content

Commit 8cbca84

Browse files
committed
Move some definitions to missing.h
1 parent c2b22cc commit 8cbca84

File tree

5 files changed

+240
-167
lines changed

5 files changed

+240
-167
lines changed

ext/bigdecimal/bigdecimal.c

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
#define SIGNED_VALUE_MIN INTPTR_MIN
4040
#define MUL_OVERFLOW_SIGNED_VALUE_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, SIGNED_VALUE_MIN, SIGNED_VALUE_MAX)
4141

42-
#define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
43-
#define roomof(x, y) (((x) + (y) - 1) / (y))
44-
#define type_roomof(x, y) roomof(sizeof(x), sizeof(y))
45-
4642
VALUE rb_cBigDecimal;
4743
VALUE rb_mBigMath;
4844

@@ -106,54 +102,6 @@ static ID id_half;
106102
# define RB_OBJ_STRING(obj) StringValueCStr(obj)
107103
#endif
108104

109-
#ifndef HAVE_RB_RATIONAL_NUM
110-
static inline VALUE
111-
rb_rational_num(VALUE rat)
112-
{
113-
#ifdef HAVE_TYPE_STRUCT_RRATIONAL
114-
return RRATIONAL(rat)->num;
115-
#else
116-
return rb_funcall(rat, rb_intern("numerator"), 0);
117-
#endif
118-
}
119-
#endif
120-
121-
#ifndef HAVE_RB_RATIONAL_DEN
122-
static inline VALUE
123-
rb_rational_den(VALUE rat)
124-
{
125-
#ifdef HAVE_TYPE_STRUCT_RRATIONAL
126-
return RRATIONAL(rat)->den;
127-
#else
128-
return rb_funcall(rat, rb_intern("denominator"), 0);
129-
#endif
130-
}
131-
#endif
132-
133-
#ifndef HAVE_RB_COMPLEX_REAL
134-
static inline VALUE
135-
rb_complex_real(VALUE cmp)
136-
{
137-
#ifdef HAVE_TYPE_STRUCT_RCOMPLEX
138-
return RCOMPLEX(cmp)->real;
139-
#else
140-
return rb_funcall(cmp, rb_intern("real"), 0);
141-
#endif
142-
}
143-
#endif
144-
145-
#ifndef HAVE_RB_COMPLEX_IMAG
146-
static inline VALUE
147-
rb_complex_imag(VALUE cmp)
148-
{
149-
#ifdef HAVE_TYPE_STRUCT_RCOMPLEX
150-
return RCOMPLEX(cmp)->imag;
151-
#else
152-
return rb_funcall(cmp, rb_intern("imag"), 0);
153-
#endif
154-
}
155-
#endif
156-
157105
#define BIGDECIMAL_POSITIVE_P(bd) ((bd)->sign > 0)
158106
#define BIGDECIMAL_NEGATIVE_P(bd) ((bd)->sign < 0)
159107

ext/bigdecimal/bigdecimal.h

Lines changed: 1 addition & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,12 @@
1111

1212
#define RUBY_NO_OLD_COMPATIBILITY
1313
#include "ruby/ruby.h"
14+
#include "missing.h"
1415

1516
#ifdef HAVE_FLOAT_H
1617
# include <float.h>
1718
#endif
1819

19-
#if defined(__bool_true_false_are_defined)
20-
# /* Take that. */
21-
22-
#elif defined(HAVE_STDBOOL_H)
23-
# include <stdbool.h>
24-
25-
#else
26-
typedef unsigned char _Bool;
27-
# define bool _Bool
28-
# define true ((_Bool)+1)
29-
# define false ((_Bool)-1)
30-
# define __bool_true_false_are_defined
31-
#endif
32-
33-
#ifndef RB_UNUSED_VAR
34-
# ifdef __GNUC__
35-
# define RB_UNUSED_VAR(x) x __attribute__ ((unused))
36-
# else
37-
# define RB_UNUSED_VAR(x) x
38-
# endif
39-
#endif
40-
41-
#ifndef UNREACHABLE
42-
# define UNREACHABLE /* unreachable */
43-
#endif
44-
4520
#undef BDIGIT
4621
#undef SIZEOF_BDIGITS
4722
#undef BDIGIT_DBL
@@ -90,95 +65,6 @@ extern "C" {
9065
#endif
9166
#endif
9267

93-
#ifndef HAVE_LABS
94-
static inline long
95-
labs(long const x)
96-
{
97-
if (x < 0) return -x;
98-
return x;
99-
}
100-
#endif
101-
102-
#ifndef HAVE_LLABS
103-
static inline LONG_LONG
104-
llabs(LONG_LONG const x)
105-
{
106-
if (x < 0) return -x;
107-
return x;
108-
}
109-
#endif
110-
111-
#ifndef HAVE_FINITE
112-
static int
113-
finite(double)
114-
{
115-
return !isnan(n) && !isinf(n);
116-
}
117-
#endif
118-
119-
#ifndef isfinite
120-
# ifndef HAVE_ISFINITE
121-
# define HAVE_ISFINITE 1
122-
# define isfinite(x) finite(x)
123-
# endif
124-
#endif
125-
126-
#ifndef FIX_CONST_VALUE_PTR
127-
# if defined(__fcc__) || defined(__fcc_version) || \
128-
defined(__FCC__) || defined(__FCC_VERSION)
129-
/* workaround for old version of Fujitsu C Compiler (fcc) */
130-
# define FIX_CONST_VALUE_PTR(x) ((const VALUE *)(x))
131-
# else
132-
# define FIX_CONST_VALUE_PTR(x) (x)
133-
# endif
134-
#endif
135-
136-
#ifndef HAVE_RB_ARRAY_CONST_PTR
137-
static inline const VALUE *
138-
rb_array_const_ptr(VALUE a)
139-
{
140-
return FIX_CONST_VALUE_PTR((RBASIC(a)->flags & RARRAY_EMBED_FLAG) ?
141-
RARRAY(a)->as.ary : RARRAY(a)->as.heap.ptr);
142-
}
143-
#endif
144-
145-
#ifndef RARRAY_CONST_PTR
146-
# define RARRAY_CONST_PTR(a) rb_array_const_ptr(a)
147-
#endif
148-
149-
#ifndef RARRAY_AREF
150-
# define RARRAY_AREF(a, i) (RARRAY_CONST_PTR(a)[i])
151-
#endif
152-
153-
#ifndef HAVE_RB_SYM2STR
154-
static inline VALUE
155-
rb_sym2str(VALUE sym)
156-
{
157-
return rb_id2str(SYM2ID(sym));
158-
}
159-
#endif
160-
161-
#ifndef ST2FIX
162-
# undef RB_ST2FIX
163-
# define RB_ST2FIX(h) LONG2FIX((long)(h))
164-
# define ST2FIX(h) RB_ST2FIX(h)
165-
#endif
166-
167-
#ifdef vabs
168-
# undef vabs
169-
#endif
170-
#if SIZEOF_VALUE <= SIZEOF_INT
171-
# define vabs abs
172-
#elif SIZEOF_VALUE <= SIZEOF_LONG
173-
# define vabs labs
174-
#elif SIZEOF_VALUE <= SIZEOF_LONG_LONG
175-
# define vabs llabs
176-
#endif
177-
178-
#if !defined(HAVE_RB_CATEGORY_WARN) || !defined(HAVE_CONST_RB_WARN_CATEGORY_DEPRECATED)
179-
# define rb_category_warn(category, ...) rb_warn(__VA_ARGS__)
180-
#endif
181-
18268
extern VALUE rb_cBigDecimal;
18369

18470
#if 0 || SIZEOF_BDIGITS >= 16

ext/bigdecimal/bits.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# pragma intrinsic(__lzcnt64)
1616
#endif
1717

18+
#define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
19+
#define roomof(x, y) (((x) + (y) - 1) / (y))
20+
#define type_roomof(x, y) roomof(sizeof(x), sizeof(y))
21+
1822
#define MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) ( \
1923
(a) == 0 ? 0 : \
2024
(a) == -1 ? (b) < -(max) : \

ext/bigdecimal/extconf.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ def have_builtin_func(name, check_expr, opt = "", &b)
4646
have_builtin_func("__builtin_clzl", "__builtin_clzl(0)")
4747

4848
have_header("float.h")
49+
have_header("math.h")
4950
have_header("stdbool.h")
51+
have_header("stdlib.h")
52+
5053
if have_func("_lzcnt_u64", "x86intrin.h") # check availability
5154
$defs << "-DHAVE_X86INTRIN_H"
5255
end

0 commit comments

Comments
 (0)