Ruby  2.5.0dev(2017-10-22revision60238)
sizes.c
Go to the documentation of this file.
1 #include "ruby/ruby.h"
2 
3 #if defined(HAVE_TYPE_SIG_ATOMIC_T)
4 # include <signal.h>
5 #endif
6 
7 #if defined(HAVE_TYPE_WINT_T) || defined(HAVE_TYPE_WCTRANS_T) || defined(HAVE_TYPE_WCTYPE_T)
8 # include <wctype.h>
9 #endif
10 
11 extern void Init_limits(void);
12 void
14 {
15  VALUE s = rb_hash_new();
16  rb_define_const(rb_define_module("RbConfig"), "SIZEOF", s);
17 
18 #define DEFINE(type, size) rb_hash_aset(s, rb_str_new_cstr(#type), INT2FIX(SIZEOF_##size))
19 #define DEFINE_SIZE(type) rb_hash_aset(s, rb_str_new_cstr(#type), INT2FIX(sizeof(type)))
20 
21 #if SIZEOF_INT != 0
22  DEFINE(int, INT);
23 #endif
24 #if SIZEOF_SHORT != 0
25  DEFINE(short, SHORT);
26 #endif
27 #if SIZEOF_LONG != 0
28  DEFINE(long, LONG);
29 #endif
30 #if SIZEOF_LONG_LONG != 0 && defined(HAVE_TRUE_LONG_LONG)
31  DEFINE(long long, LONG_LONG);
32 #endif
33 #if SIZEOF___INT64 != 0
34  DEFINE(__int64, __INT64);
35 #endif
36 #ifdef HAVE_TYPE___INT128
37  DEFINE_SIZE(__int128);
38 #endif
39 #if SIZEOF_OFF_T != 0
40  DEFINE(off_t, OFF_T);
41 #endif
42 #if SIZEOF_VOIDP != 0
43  DEFINE(void*, VOIDP);
44 #endif
45 #if SIZEOF_FLOAT != 0
46  DEFINE(float, FLOAT);
47 #endif
48 #if SIZEOF_DOUBLE != 0
49  DEFINE(double, DOUBLE);
50 #endif
51 #if SIZEOF_TIME_T != 0
52  DEFINE(time_t, TIME_T);
53 #endif
54 #if SIZEOF_CLOCK_T != 0
55  DEFINE(clock_t, CLOCK_T);
56 #endif
57 #if SIZEOF_SIZE_T != 0
58  DEFINE(size_t, SIZE_T);
59 #endif
60 #if SIZEOF_PTRDIFF_T != 0
61  DEFINE(ptrdiff_t, PTRDIFF_T);
62 #endif
63 #if SIZEOF_INT8_T != 0
64  DEFINE(int8_t, INT8_T);
65 #endif
66 #if SIZEOF_UINT8_T != 0
67  DEFINE(uint8_t, UINT8_T);
68 #endif
69 #if SIZEOF_INT16_T != 0
70  DEFINE(int16_t, INT16_T);
71 #endif
72 #if SIZEOF_UINT16_T != 0
73  DEFINE(uint16_t, UINT16_T);
74 #endif
75 #if SIZEOF_INT32_T != 0
76  DEFINE(int32_t, INT32_T);
77 #endif
78 #if SIZEOF_UINT32_T != 0
79  DEFINE(uint32_t, UINT32_T);
80 #endif
81 #if SIZEOF_INT64_T != 0
82  DEFINE(int64_t, INT64_T);
83 #endif
84 #if SIZEOF_UINT64_T != 0
85  DEFINE(uint64_t, UINT64_T);
86 #endif
87 #if SIZEOF_INT128_T != 0
88  DEFINE(int128_t, INT128_T);
89 #endif
90 #if SIZEOF_UINT128_T != 0
91  DEFINE(uint128_t, UINT128_T);
92 #endif
93 #if SIZEOF_INTPTR_T != 0
94  DEFINE(intptr_t, INTPTR_T);
95 #endif
96 #if SIZEOF_UINTPTR_T != 0
97  DEFINE(uintptr_t, UINTPTR_T);
98 #endif
99 #if SIZEOF_SSIZE_T != 0
100  DEFINE(ssize_t, SSIZE_T);
101 #endif
102 #ifdef HAVE_TYPE_INT_LEAST8_T
103  DEFINE_SIZE(int_least8_t);
104 #endif
105 #ifdef HAVE_TYPE_INT_LEAST16_T
106  DEFINE_SIZE(int_least16_t);
107 #endif
108 #ifdef HAVE_TYPE_INT_LEAST32_T
109  DEFINE_SIZE(int_least32_t);
110 #endif
111 #ifdef HAVE_TYPE_INT_LEAST64_T
112  DEFINE_SIZE(int_least64_t);
113 #endif
114 #ifdef HAVE_TYPE_INT_FAST8_T
115  DEFINE_SIZE(int_fast8_t);
116 #endif
117 #ifdef HAVE_TYPE_INT_FAST16_T
118  DEFINE_SIZE(int_fast16_t);
119 #endif
120 #ifdef HAVE_TYPE_INT_FAST32_T
121  DEFINE_SIZE(int_fast32_t);
122 #endif
123 #ifdef HAVE_TYPE_INT_FAST64_T
124  DEFINE_SIZE(int_fast64_t);
125 #endif
126 #ifdef HAVE_TYPE_INTMAX_T
127  DEFINE_SIZE(intmax_t);
128 #endif
129 #ifdef HAVE_TYPE_SIG_ATOMIC_T
130  DEFINE_SIZE(sig_atomic_t);
131 #endif
132 #ifdef HAVE_TYPE_WCHAR_T
133  DEFINE_SIZE(wchar_t);
134 #endif
135 #ifdef HAVE_TYPE_WINT_T
136  DEFINE_SIZE(wint_t);
137 #endif
138 #ifdef HAVE_TYPE_WCTRANS_T
139  DEFINE_SIZE(wctrans_t);
140 #endif
141 #ifdef HAVE_TYPE_WCTYPE_T
142  DEFINE_SIZE(wctype_t);
143 #endif
144 #ifdef HAVE_TYPE__BOOL
145  DEFINE_SIZE(_Bool);
146 #endif
147 #ifdef HAVE_TYPE_LONG_DOUBLE
148  DEFINE_SIZE(long double);
149 #endif
150 #ifdef HAVE_TYPE_FLOAT__COMPLEX
151  DEFINE_SIZE(float _Complex);
152 #endif
153 #ifdef HAVE_TYPE_DOUBLE__COMPLEX
154  DEFINE_SIZE(double _Complex);
155 #endif
156 #ifdef HAVE_TYPE_LONG_DOUBLE__COMPLEX
157  DEFINE_SIZE(long double _Complex);
158 #endif
159 #ifdef HAVE_TYPE_FLOAT__IMAGINARY
160  DEFINE_SIZE(float _Imaginary);
161 #endif
162 #ifdef HAVE_TYPE_DOUBLE__IMAGINARY
163  DEFINE_SIZE(double _Imaginary);
164 #endif
165 #ifdef HAVE_TYPE_LONG_DOUBLE__IMAGINARY
166  DEFINE_SIZE(long double _Imaginary);
167 #endif
168 #ifdef HAVE_TYPE___INT128
169  DEFINE_SIZE(__int128);
170 #endif
171 #ifdef HAVE_TYPE___FLOAT128
172  DEFINE_SIZE(__float128);
173 #endif
174 #ifdef HAVE_TYPE__DECIMAL32
175  DEFINE_SIZE(_Decimal32);
176 #endif
177 #ifdef HAVE_TYPE__DECIMAL64
178  DEFINE_SIZE(_Decimal64);
179 #endif
180 #ifdef HAVE_TYPE__DECIMAL128
181  DEFINE_SIZE(_Decimal128);
182 #endif
183 #ifdef HAVE_TYPE___M64
184  DEFINE_SIZE(__m64);
185 #endif
186 #ifdef HAVE_TYPE___M128
187  DEFINE_SIZE(__m128);
188 #endif
189 #ifdef HAVE_TYPE___FLOAT80
190  DEFINE_SIZE(__float80);
191 #endif
192  OBJ_FREEZE(s);
193 
194 #undef DEFINE
195  Init_limits();
196 }
#define OBJ_FREEZE(x)
Definition: ruby.h:1306
#define DEFINE_SIZE(type)
void Init_limits(void)
Definition: limits.c:14
unsigned char uint8_t
Definition: sha2.h:100
unsigned long long uint64_t
Definition: sha2.h:102
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2691
void Init_sizeof(void)
Definition: sizes.c:13
#define off_t
Definition: io.c:61
VALUE rb_hash_new(void)
Definition: hash.c:424
#define DEFINE(type, size)
unsigned int uintptr_t
Definition: win32.h:106
unsigned long VALUE
Definition: ruby.h:85
int intptr_t
Definition: win32.h:90
unsigned int uint32_t
Definition: sha2.h:101
VALUE rb_define_module(const char *name)
Definition: class.c:768