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