Skip to content

Commit 6004839

Browse files
committed
Re-apply changes on top of 3.0.3 files
1 parent fed4608 commit 6004839

File tree

120 files changed

+1259
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+1259
-377
lines changed

lib/cext/include/internal/imemo.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,17 @@ static inline enum imemo_type imemo_type(VALUE imemo);
137137
static inline int imemo_type_p(VALUE imemo, enum imemo_type imemo_type);
138138
static inline bool imemo_throw_data_p(VALUE imemo);
139139
static inline struct vm_ifunc *rb_vm_ifunc_proc_new(rb_block_call_func_t func, const void *data);
140+
#ifdef TRUFFLERUBY
141+
VALUE rb_imemo_tmpbuf_auto_free_pointer(void);
142+
#else
140143
static inline VALUE rb_imemo_tmpbuf_auto_free_pointer(void);
144+
#endif
141145
static inline void *RB_IMEMO_TMPBUF_PTR(VALUE v);
146+
#ifdef TRUFFLERUBY
147+
void *rb_imemo_tmpbuf_set_ptr(VALUE v, void *ptr);
148+
#else
142149
static inline void *rb_imemo_tmpbuf_set_ptr(VALUE v, void *ptr);
150+
#endif
143151
static inline VALUE rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str);
144152
static inline void MEMO_V1_SET(struct MEMO *m, VALUE v);
145153
static inline void MEMO_V2_SET(struct MEMO *m, VALUE v);
@@ -189,11 +197,13 @@ rb_vm_ifunc_proc_new(rb_block_call_func_t func, const void *data)
189197
return rb_vm_ifunc_new(func, data, 0, UNLIMITED_ARGUMENTS);
190198
}
191199

200+
#ifndef TRUFFLERUBY
192201
static inline VALUE
193202
rb_imemo_tmpbuf_auto_free_pointer(void)
194203
{
195204
return rb_imemo_new(imemo_tmpbuf, 0, 0, 0, 0);
196205
}
206+
#endif
197207

198208
static inline void *
199209
RB_IMEMO_TMPBUF_PTR(VALUE v)
@@ -202,11 +212,13 @@ RB_IMEMO_TMPBUF_PTR(VALUE v)
202212
return p->ptr;
203213
}
204214

215+
#ifndef TRUFFLERUBY
205216
static inline void *
206217
rb_imemo_tmpbuf_set_ptr(VALUE v, void *ptr)
207218
{
208219
return ((rb_imemo_tmpbuf_t *)v)->ptr = ptr;
209220
}
221+
#endif
210222

211223
static inline VALUE
212224
rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str)

lib/cext/include/ruby/encoding.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,27 @@ enum ruby_encoding_consts {
3030
#define ENCODING_SHIFT RUBY_ENCODING_SHIFT
3131
#define ENCODING_MASK RUBY_ENCODING_MASK
3232

33+
#ifdef TRUFFLERUBY
34+
#define RB_ENCODING_SET_INLINED(obj,i) RB_ENCODING_SET(obj,i)
35+
#else
3336
#define RB_ENCODING_SET_INLINED(obj,i) do {\
3437
RBASIC(obj)->flags &= ~RUBY_ENCODING_MASK;\
3538
RBASIC(obj)->flags |= (VALUE)(i) << RUBY_ENCODING_SHIFT;\
3639
} while (0)
40+
#endif
3741
#define RB_ENCODING_SET(obj,i) rb_enc_set_index((obj), (i))
3842

43+
#ifdef TRUFFLERUBY
44+
#define RB_ENCODING_GET_INLINED(obj) RB_ENCODING_GET(obj)
45+
#define RB_ENCODING_GET(obj) rb_enc_get_index(obj)
46+
#else
3947
#define RB_ENCODING_GET_INLINED(obj) \
4048
(int)((RBASIC(obj)->flags & RUBY_ENCODING_MASK)>>RUBY_ENCODING_SHIFT)
4149
#define RB_ENCODING_GET(obj) \
4250
(RB_ENCODING_GET_INLINED(obj) != RUBY_ENCODING_INLINE_MAX ? \
4351
RB_ENCODING_GET_INLINED(obj) : \
4452
rb_enc_get_index(obj))
53+
#endif
4554

4655
#define RB_ENCODING_IS_ASCII8BIT(obj) (RB_ENCODING_GET_INLINED(obj) == 0)
4756

@@ -54,12 +63,18 @@ enum ruby_encoding_consts {
5463

5564
enum ruby_coderange_type {
5665
RUBY_ENC_CODERANGE_UNKNOWN = 0,
66+
#ifdef TRUFFLERUBY
67+
RUBY_ENC_CODERANGE_7BIT = 1,
68+
RUBY_ENC_CODERANGE_VALID = 2,
69+
RUBY_ENC_CODERANGE_BROKEN = 4
70+
#else
5771
RUBY_ENC_CODERANGE_7BIT = ((int)RUBY_FL_USER8),
5872
RUBY_ENC_CODERANGE_VALID = ((int)RUBY_FL_USER9),
5973
RUBY_ENC_CODERANGE_BROKEN = ((int)(RUBY_FL_USER8|RUBY_FL_USER9)),
6074
RUBY_ENC_CODERANGE_MASK = (RUBY_ENC_CODERANGE_7BIT|
6175
RUBY_ENC_CODERANGE_VALID|
6276
RUBY_ENC_CODERANGE_BROKEN)
77+
#endif
6378
};
6479

6580
static inline int
@@ -68,12 +83,23 @@ rb_enc_coderange_clean_p(int cr)
6883
return (cr ^ (cr >> 1)) & RUBY_ENC_CODERANGE_7BIT;
6984
}
7085
#define RB_ENC_CODERANGE_CLEAN_P(cr) rb_enc_coderange_clean_p(cr)
86+
#ifdef TRUFFLERUBY
87+
enum ruby_coderange_type RB_ENC_CODERANGE(VALUE obj);
88+
#else
7189
#define RB_ENC_CODERANGE(obj) ((int)RBASIC(obj)->flags & RUBY_ENC_CODERANGE_MASK)
90+
#endif
7291
#define RB_ENC_CODERANGE_ASCIIONLY(obj) (RB_ENC_CODERANGE(obj) == RUBY_ENC_CODERANGE_7BIT)
92+
93+
#ifdef TRUFFLERUBY
94+
void RB_ENC_CODERANGE_SET(VALUE obj, int cr);
95+
void rb_enc_coderange_clear(VALUE);
96+
#define RB_ENC_CODERANGE_CLEAR(obj) rb_enc_coderange_clear(obj)
97+
#else
7398
#define RB_ENC_CODERANGE_SET(obj,cr) (\
7499
RBASIC(obj)->flags = \
75100
(RBASIC(obj)->flags & ~RUBY_ENC_CODERANGE_MASK) | (cr))
76101
#define RB_ENC_CODERANGE_CLEAR(obj) RB_ENC_CODERANGE_SET((obj),0)
102+
#endif
77103

78104
/* assumed ASCII compatibility */
79105
#define RB_ENC_CODERANGE_AND(a, b) \
@@ -138,6 +164,9 @@ VALUE rb_obj_encoding(VALUE);
138164
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc);
139165
VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc);
140166

167+
VALUE rb_external_str_with_enc(VALUE string, rb_encoding *eenc);
168+
rb_encoding *get_encoding(VALUE string);
169+
#define STR_ENC_GET(string) get_encoding(string)
141170
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *);
142171
VALUE rb_str_export_to_enc(VALUE, rb_encoding *);
143172
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to);
@@ -168,8 +197,13 @@ rb_encoding *rb_enc_find(const char *name);
168197
#define rb_enc_name(enc) (enc)->name
169198

170199
/* rb_encoding * -> minlen/maxlen */
200+
#ifdef TRUFFLERUBY
201+
int rb_enc_mbminlen(rb_encoding *enc);
202+
int rb_enc_mbmaxlen(rb_encoding *enc);
203+
#else
171204
#define rb_enc_mbminlen(enc) (enc)->min_enc_len
172205
#define rb_enc_mbmaxlen(enc) (enc)->max_enc_len
206+
#endif
173207

174208
/* -> mbclen (no error notification: 0 < ret <= e-p, no exception) */
175209
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc);
@@ -196,7 +230,12 @@ unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len, rb_enc
196230
unsigned int rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc);
197231
/* overriding macro */
198232
#define rb_enc_codepoint(p,e,enc) rb_enc_codepoint_len((p),(e),0,(enc))
233+
#ifdef TRUFFLERUBY
234+
int rb_enc_mbc_to_codepoint(char *p, char *e, rb_encoding *enc);
235+
#define rb_enc_mbc_to_codepoint(p, e, enc) rb_enc_mbc_to_codepoint(p, e, enc)
236+
#else
199237
#define rb_enc_mbc_to_codepoint(p, e, enc) ONIGENC_MBC_TO_CODE((enc),(UChar*)(p),(UChar*)(e))
238+
#endif
200239

201240
/* -> codelen>0 or raise exception */
202241
int rb_enc_codelen(int code, rb_encoding *enc);
@@ -210,7 +249,11 @@ int rb_enc_code_to_mbclen(int code, rb_encoding *enc);
210249
/* start, ptr, end, encoding -> prev_char */
211250
#define rb_enc_prev_char(s,p,e,enc) ((char *)onigenc_get_prev_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
212251
/* start, ptr, end, encoding -> next_char */
252+
#ifdef TRUFFLERUBY
253+
char* rb_enc_left_char_head(char *start, char *p, char *end, rb_encoding *enc);
254+
#else
213255
#define rb_enc_left_char_head(s,p,e,enc) ((char *)onigenc_get_left_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
256+
#endif
214257
#define rb_enc_right_char_head(s,p,e,enc) ((char *)onigenc_get_right_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
215258
#define rb_enc_step_back(s,p,e,n,enc) ((char *)onigenc_step_back((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e),(int)(n)))
216259

@@ -223,17 +266,31 @@ int rb_enc_code_to_mbclen(int code, rb_encoding *enc);
223266
#define rb_enc_islower(c,enc) ONIGENC_IS_CODE_LOWER((enc),(c))
224267
#define rb_enc_isupper(c,enc) ONIGENC_IS_CODE_UPPER((enc),(c))
225268
#define rb_enc_ispunct(c,enc) ONIGENC_IS_CODE_PUNCT((enc),(c))
269+
#ifdef TRUFFLERUBY
270+
int rb_enc_isalnum(unsigned char c, rb_encoding *enc);
271+
#define rb_enc_isalnum(c,enc) rb_enc_isalnum(c,enc)
272+
#else
226273
#define rb_enc_isalnum(c,enc) ONIGENC_IS_CODE_ALNUM((enc),(c))
274+
#endif
227275
#define rb_enc_isprint(c,enc) ONIGENC_IS_CODE_PRINT((enc),(c))
276+
#ifdef TRUFFLERUBY
277+
int rb_enc_isspace(unsigned char c, rb_encoding *enc);
278+
#define rb_enc_isspace(c,enc) rb_enc_isspace(c,enc)
279+
#else
228280
#define rb_enc_isspace(c,enc) ONIGENC_IS_CODE_SPACE((enc),(c))
281+
#endif
229282
#define rb_enc_isdigit(c,enc) ONIGENC_IS_CODE_DIGIT((enc),(c))
230283

284+
#ifdef TRUFFLERUBY
285+
int rb_enc_asciicompat(rb_encoding *enc);
286+
#else
231287
static inline int
232288
rb_enc_asciicompat_inline(rb_encoding *enc)
233289
{
234290
return rb_enc_mbminlen(enc)==1 && !rb_enc_dummy_p(enc);
235291
}
236292
#define rb_enc_asciicompat(enc) rb_enc_asciicompat_inline(enc)
293+
#endif
237294

238295
int rb_enc_casefold(char *to, const char *p, const char *e, rb_encoding *enc);
239296
CONSTFUNC(int rb_enc_toupper(int c, rb_encoding *enc));
@@ -284,6 +341,9 @@ VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc);
284341
RUBY_EXTERN VALUE rb_cEncoding;
285342

286343
/* econv stuff */
344+
#ifdef TRUFFLERUBY
345+
struct rb_econv_t {};
346+
#endif
287347

288348
typedef enum {
289349
econv_invalid_byte_sequence,

lib/cext/include/ruby/internal/arithmetic/fixnum.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,19 @@
3535
* represent is 4,611,686,018,427,387,904, which is not fixable. The
3636
* seemingly-stragne "< FIXNUM_MAX + 1" expression below is due to this.
3737
*/
38+
#ifdef TRUFFLERUBY
39+
#define RB_POSFIXABLE(f) ((f) <= RUBY_FIXNUM_MAX)
40+
#else
3841
#define RB_POSFIXABLE(_) ((_) < RUBY_FIXNUM_MAX + 1)
42+
#endif
3943
#define RB_NEGFIXABLE(_) ((_) >= RUBY_FIXNUM_MIN)
4044
#define RB_FIXABLE(_) (RB_POSFIXABLE(_) && RB_NEGFIXABLE(_))
45+
#ifdef TRUFFLERUBY
46+
#define RUBY_FIXNUM_MAX LONG_MAX
47+
#define RUBY_FIXNUM_MIN LONG_MIN
48+
#else
4149
#define RUBY_FIXNUM_MAX (LONG_MAX / 2)
4250
#define RUBY_FIXNUM_MIN (LONG_MIN / 2)
51+
#endif
4352

4453
#endif /* RBIMPL_ARITHMETIC_FIXNUM_H */

lib/cext/include/ruby/internal/arithmetic/long.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,28 @@
5050
#define LONG2NUM RB_LONG2NUM
5151
#define NUM2LONG RB_NUM2LONG
5252
#define NUM2ULONG RB_NUM2ULONG
53+
#ifdef TRUFFLERUBY
54+
#define RB_FIX2LONG(x) ((long)polyglot_as_i64(rb_tr_unwrap(x)))
55+
#else
5356
#define RB_FIX2LONG rb_fix2long
57+
#endif
5458
#define RB_FIX2ULONG rb_fix2ulong
59+
#ifdef TRUFFLERUBY
60+
#define RB_LONG2FIX(i) (VALUE)rb_tr_longwrap((long)(i))
61+
#else
5562
#define RB_LONG2FIX RB_INT2FIX
63+
#endif
5664
#define RB_LONG2NUM rb_long2num_inline
5765
#define RB_NUM2LONG rb_num2long_inline
5866
#define RB_NUM2ULONG rb_num2ulong_inline
5967
#define RB_ULONG2NUM rb_ulong2num_inline
6068
#define ULONG2NUM RB_ULONG2NUM
6169
#define rb_fix_new RB_INT2FIX
70+
#ifdef TRUFFLERUBY
71+
#define rb_long2int rb_long2int
72+
#else
6273
#define rb_long2int rb_long2int_inline
74+
#endif
6375

6476
/** @cond INTERNAL_MACRO */
6577
#define RB_INT2FIX RB_INT2FIX
@@ -73,6 +85,9 @@ void rb_out_of_int(SIGNED_VALUE num);
7385

7486
long rb_num2long(VALUE num);
7587
unsigned long rb_num2ulong(VALUE num);
88+
#ifdef TRUFFLERUBY
89+
int rb_long2int(long value);
90+
#endif
7691
RBIMPL_SYMBOL_EXPORT_END()
7792

7893
RBIMPL_ATTR_CONST_UNLESS_DEBUG()
@@ -95,6 +110,7 @@ RB_INT2FIX(long i)
95110
return n;
96111
}
97112

113+
#ifndef TRUFFLERUBY
98114
static inline int
99115
rb_long2int_inline(long n)
100116
{
@@ -109,6 +125,7 @@ rb_long2int_inline(long n)
109125

110126
return i;
111127
}
128+
#endif
112129

113130
RBIMPL_ATTR_CONST_UNLESS_DEBUG()
114131
RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14)
@@ -154,16 +171,22 @@ rbimpl_right_shift_is_arithmetic_p(void)
154171
}
155172

156173
RBIMPL_ATTR_CONST_UNLESS_DEBUG()
174+
#ifndef TRUFFLERUBY
157175
RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14)
176+
#endif
158177
static inline long
159178
rb_fix2long(VALUE x)
160179
{
180+
#ifdef TRUFFLERUBY
181+
return ((long)polyglot_as_i64(rb_tr_unwrap(x)));
182+
#else
161183
if /* constexpr */ (rbimpl_right_shift_is_arithmetic_p()) {
162184
return rbimpl_fix2long_by_shift(x);
163185
}
164186
else {
165187
return rbimpl_fix2long_by_idiv(x);
166188
}
189+
#endif
167190
}
168191

169192
RBIMPL_ATTR_CONST_UNLESS_DEBUG()
@@ -213,7 +236,11 @@ rb_ulong2num_inline(unsigned long v)
213236
if (RB_POSFIXABLE(v))
214237
return RB_LONG2FIX(v);
215238
else
239+
#ifdef TRUFFLERUBY
240+
return rb_tr_wrap(polyglot_invoke(RUBY_CEXT, "rb_ulong2num", (long) v));
241+
#else
216242
return rb_uint2big(v);
243+
#endif
217244
}
218245

219246
/**

lib/cext/include/ruby/internal/attr/const.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "ruby/internal/compiler_since.h"
2424
#include "ruby/internal/has/attribute.h"
2525
#include "ruby/internal/has/declspec_attribute.h"
26+
#include "ruby/assert.h"
2627

2728
/** Wraps (or simulates) `__attribute__((const))` */
2829
#if RBIMPL_HAS_ATTRIBUTE(const)

lib/cext/include/ruby/internal/config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* extension libraries. They could be written in C++98.
2121
* @brief Thin wrapper to ruby/config.h
2222
*/
23+
// Must be first, as it defines feature test macros like _GNU_SOURCE,
24+
// which influences the definitions exposed by system header files.
2325
#include "ruby/config.h"
2426

2527
#ifdef RUBY_EXTCONF_H
@@ -141,4 +143,7 @@
141143
# undef RBIMPL_TEST3
142144
#endif /* HAVE_VA_ARGS_MACRO */
143145

146+
// Loaded at the end of config.h, included from defines.h. Needs STRINGIZE().
147+
#include <truffleruby/truffleruby-pre.h>
148+
144149
#endif /* RBIMPL_CONFIG_H */

0 commit comments

Comments
 (0)