-
Notifications
You must be signed in to change notification settings - Fork 37
/
RubyLib.h
170 lines (120 loc) · 2.97 KB
/
RubyLib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#ifndef SU_UTILS_RUBYLIB_H_
#define SU_UTILS_RUBYLIB_H_
///// Visual Studio CRT Config /////////////////////////////////////////////////
// Disable all warnings.
// http://stackoverflow.com/a/2541990/486990
#pragma warning(push, 0)
// Must disable the min/max macros defined by windows.h to avoid conflict with
// std::max and std:min. Ruby includes windows.h so it must be disabled here.
// http://stackoverflow.com/a/2789509/486990
#define NOMINMAX
// Ruby was configured for Visual Studio 2010. These macros are needed to
// prevent compiler errors with Visual Studio 2013. This relate to release
// builds which are compiled with MT.
#if _MT
// Visual Studio 2013
#if _MSC_VER >= 1800
// Ruby 2.0
#define HAVE_ACOSH 1
#define HAVE_CBRT 1
#define HAVE_ERF 1
#define HAVE_TGAMMA 1
#define HAVE_ROUND 1
// Ruby 2.2
#define HAVE_NEXTAFTER 1
#endif // VS 2013
// Visual Studio 2015
#if _MSC_VER >= 1900
#define HAVE_STRUCT_TIMESPEC 1
#endif // VS2015
#endif // _MT
///// Ruby Headers /////////////////////////////////////////////////////////////
// For some reason Xcode will flag warnings (which are treated as errors) in
// the Ruby headers. This works around that.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-conversion"
#include <ruby.h>
#ifdef HAVE_RUBY_ENCODING_H
#include <ruby/encoding.h>
#endif
#pragma clang diagnostic pop
///// Compatibility Macros /////////////////////////////////////////////////////
/* The structures changes between Ruby 1.8 and 2.0 so the access to the
* properties are different. There are new macros in Ruby 2.0 that should be
* used instead. In order to make the code compile for both we need to add
* matching macros for 1.8.
*/
#ifndef RARRAY_LEN
#define RARRAY_LEN(x) (RARRAY(x)->len)
#endif
#ifndef DBL2NUM
#define DBL2NUM(dbl) rb_float_new(dbl)
#endif
#ifndef NUM2SIZET
#if defined(HAVE_LONG_LONG) && SIZEOF_SIZE_T > SIZEOF_LONG
# define NUM2SIZET(x) ((size_t)NUM2ULL(x))
#else
# define NUM2SIZET(x) NUM2ULONG(x)
#endif
#endif
// Ruby 2.0 renamed some functions. Need to add some compatibility macros for
// older Ruby.
#ifndef rb_ary_new2
#define rb_ary_new_capa rb_ary_new2
#define rb_ary_new_from_args rb_ary_new3
#define rb_ary_new_from_values rb_ary_new4
#endif
// Ruby 1.8 headers conflict with ostream because it defined a lot of macros
// that completely mess up the environment.
// win32.h
#ifdef getc
#undef getc
#endif
#ifdef putc
#undef putc
#endif
#ifdef fgetc
#undef fgetc
#endif
#ifdef fputc
#undef fputc
#endif
#ifdef getchar
#undef getchar
#endif
#ifdef putchar
#undef putchar
#endif
#ifdef fgetchar
#undef fgetchar
#endif
#ifdef fputchar
#undef fputchar
#endif
#ifdef utime
#undef utime
#endif
#ifdef close
#undef close
#endif
#ifdef fclose
#undef fclose
#endif
#ifdef read
#undef read
#endif
#ifdef write
#undef write
#endif
#ifdef getpid
#undef getpid
#endif
#ifdef sleep
#undef sleep
#endif
// config.h
#ifdef inline
#undef inline
#endif
#pragma warning (pop)
#endif // SU_UTILS_RUBYLIB_H_