Skip to content

Commit 2b4cd4c

Browse files
committed
Re-apply changes on top of 2.7.4 files
1 parent a232c9a commit 2b4cd4c

File tree

107 files changed

+1576
-1442
lines changed

Some content is hidden

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

107 files changed

+1576
-1442
lines changed

lib/cext/include/ruby/encoding.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,27 @@ enum ruby_encoding_consts {
4141
#define ENCODING_SHIFT RUBY_ENCODING_SHIFT
4242
#define ENCODING_MASK RUBY_ENCODING_MASK
4343

44+
#ifdef TRUFFLERUBY
45+
#define RB_ENCODING_SET_INLINED(obj,i) RB_ENCODING_SET(obj,i)
46+
#else
4447
#define RB_ENCODING_SET_INLINED(obj,i) do {\
4548
RBASIC(obj)->flags &= ~RUBY_ENCODING_MASK;\
4649
RBASIC(obj)->flags |= (VALUE)(i) << RUBY_ENCODING_SHIFT;\
4750
} while (0)
51+
#endif
4852
#define RB_ENCODING_SET(obj,i) rb_enc_set_index((obj), (i))
4953

54+
#ifdef TRUFFLERUBY
55+
#define RB_ENCODING_GET_INLINED(obj) RB_ENCODING_GET(obj)
56+
#define RB_ENCODING_GET(obj) rb_enc_get_index(obj)
57+
#else
5058
#define RB_ENCODING_GET_INLINED(obj) \
5159
(int)((RBASIC(obj)->flags & RUBY_ENCODING_MASK)>>RUBY_ENCODING_SHIFT)
5260
#define RB_ENCODING_GET(obj) \
5361
(RB_ENCODING_GET_INLINED(obj) != RUBY_ENCODING_INLINE_MAX ? \
5462
RB_ENCODING_GET_INLINED(obj) : \
5563
rb_enc_get_index(obj))
64+
#endif
5665

5766
#define RB_ENCODING_IS_ASCII8BIT(obj) (RB_ENCODING_GET_INLINED(obj) == 0)
5867

@@ -65,12 +74,18 @@ enum ruby_encoding_consts {
6574

6675
enum ruby_coderange_type {
6776
RUBY_ENC_CODERANGE_UNKNOWN = 0,
77+
#ifdef TRUFFLERUBY
78+
RUBY_ENC_CODERANGE_7BIT = 1,
79+
RUBY_ENC_CODERANGE_VALID = 2,
80+
RUBY_ENC_CODERANGE_BROKEN = 4
81+
#else
6882
RUBY_ENC_CODERANGE_7BIT = ((int)RUBY_FL_USER8),
6983
RUBY_ENC_CODERANGE_VALID = ((int)RUBY_FL_USER9),
7084
RUBY_ENC_CODERANGE_BROKEN = ((int)(RUBY_FL_USER8|RUBY_FL_USER9)),
7185
RUBY_ENC_CODERANGE_MASK = (RUBY_ENC_CODERANGE_7BIT|
7286
RUBY_ENC_CODERANGE_VALID|
7387
RUBY_ENC_CODERANGE_BROKEN)
88+
#endif
7489
};
7590

7691
static inline int
@@ -79,12 +94,23 @@ rb_enc_coderange_clean_p(int cr)
7994
return (cr ^ (cr >> 1)) & RUBY_ENC_CODERANGE_7BIT;
8095
}
8196
#define RB_ENC_CODERANGE_CLEAN_P(cr) rb_enc_coderange_clean_p(cr)
97+
#ifdef TRUFFLERUBY
98+
enum ruby_coderange_type RB_ENC_CODERANGE(VALUE obj);
99+
#else
82100
#define RB_ENC_CODERANGE(obj) ((int)RBASIC(obj)->flags & RUBY_ENC_CODERANGE_MASK)
101+
#endif
83102
#define RB_ENC_CODERANGE_ASCIIONLY(obj) (RB_ENC_CODERANGE(obj) == RUBY_ENC_CODERANGE_7BIT)
103+
104+
#ifdef TRUFFLERUBY
105+
void RB_ENC_CODERANGE_SET(VALUE obj, int cr);
106+
void rb_enc_coderange_clear(VALUE);
107+
#define RB_ENC_CODERANGE_CLEAR(obj) rb_enc_coderange_clear(obj)
108+
#else
84109
#define RB_ENC_CODERANGE_SET(obj,cr) (\
85110
RBASIC(obj)->flags = \
86111
(RBASIC(obj)->flags & ~RUBY_ENC_CODERANGE_MASK) | (cr))
87112
#define RB_ENC_CODERANGE_CLEAR(obj) RB_ENC_CODERANGE_SET((obj),0)
113+
#endif
88114

89115
/* assumed ASCII compatibility */
90116
#define RB_ENC_CODERANGE_AND(a, b) \
@@ -147,6 +173,9 @@ VALUE rb_obj_encoding(VALUE);
147173
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc);
148174
VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc);
149175

176+
VALUE rb_external_str_with_enc(VALUE string, rb_encoding *eenc);
177+
rb_encoding *get_encoding(VALUE string);
178+
#define STR_ENC_GET(string) get_encoding(string)
150179
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *);
151180
VALUE rb_str_export_to_enc(VALUE, rb_encoding *);
152181
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to);
@@ -177,8 +206,13 @@ rb_encoding *rb_enc_find(const char *name);
177206
#define rb_enc_name(enc) (enc)->name
178207

179208
/* rb_encoding * -> minlen/maxlen */
209+
#ifdef TRUFFLERUBY
210+
int rb_enc_mbminlen(rb_encoding *enc);
211+
int rb_enc_mbmaxlen(rb_encoding *enc);
212+
#else
180213
#define rb_enc_mbminlen(enc) (enc)->min_enc_len
181214
#define rb_enc_mbmaxlen(enc) (enc)->max_enc_len
215+
#endif
182216

183217
/* -> mbclen (no error notification: 0 < ret <= e-p, no exception) */
184218
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc);
@@ -205,7 +239,12 @@ unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len, rb_enc
205239
unsigned int rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc);
206240
/* overriding macro */
207241
#define rb_enc_codepoint(p,e,enc) rb_enc_codepoint_len((p),(e),0,(enc))
242+
#ifdef TRUFFLERUBY
243+
int rb_enc_mbc_to_codepoint(char *p, char *e, rb_encoding *enc);
244+
#define rb_enc_mbc_to_codepoint(p, e, enc) rb_enc_mbc_to_codepoint(p, e, enc)
245+
#else
208246
#define rb_enc_mbc_to_codepoint(p, e, enc) ONIGENC_MBC_TO_CODE((enc),(UChar*)(p),(UChar*)(e))
247+
#endif
209248

210249
/* -> codelen>0 or raise exception */
211250
int rb_enc_codelen(int code, rb_encoding *enc);
@@ -219,7 +258,11 @@ int rb_enc_code_to_mbclen(int code, rb_encoding *enc);
219258
/* start, ptr, end, encoding -> prev_char */
220259
#define rb_enc_prev_char(s,p,e,enc) ((char *)onigenc_get_prev_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
221260
/* start, ptr, end, encoding -> next_char */
261+
#ifdef TRUFFLERUBY
262+
char* rb_enc_left_char_head(char *start, char *p, char *end, rb_encoding *enc);
263+
#else
222264
#define rb_enc_left_char_head(s,p,e,enc) ((char *)onigenc_get_left_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
265+
#endif
223266
#define rb_enc_right_char_head(s,p,e,enc) ((char *)onigenc_get_right_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
224267
#define rb_enc_step_back(s,p,e,n,enc) ((char *)onigenc_step_back((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e),(int)(n)))
225268

@@ -232,17 +275,31 @@ int rb_enc_code_to_mbclen(int code, rb_encoding *enc);
232275
#define rb_enc_islower(c,enc) ONIGENC_IS_CODE_LOWER((enc),(c))
233276
#define rb_enc_isupper(c,enc) ONIGENC_IS_CODE_UPPER((enc),(c))
234277
#define rb_enc_ispunct(c,enc) ONIGENC_IS_CODE_PUNCT((enc),(c))
278+
#ifdef TRUFFLERUBY
279+
int rb_enc_isalnum(unsigned char c, rb_encoding *enc);
280+
#define rb_enc_isalnum(c,enc) rb_enc_isalnum(c,enc)
281+
#else
235282
#define rb_enc_isalnum(c,enc) ONIGENC_IS_CODE_ALNUM((enc),(c))
283+
#endif
236284
#define rb_enc_isprint(c,enc) ONIGENC_IS_CODE_PRINT((enc),(c))
285+
#ifdef TRUFFLERUBY
286+
int rb_enc_isspace(unsigned char c, rb_encoding *enc);
287+
#define rb_enc_isspace(c,enc) rb_enc_isspace(c,enc)
288+
#else
237289
#define rb_enc_isspace(c,enc) ONIGENC_IS_CODE_SPACE((enc),(c))
290+
#endif
238291
#define rb_enc_isdigit(c,enc) ONIGENC_IS_CODE_DIGIT((enc),(c))
239292

293+
#ifdef TRUFFLERUBY
294+
int rb_enc_asciicompat(rb_encoding *enc);
295+
#else
240296
static inline int
241297
rb_enc_asciicompat_inline(rb_encoding *enc)
242298
{
243299
return rb_enc_mbminlen(enc)==1 && !rb_enc_dummy_p(enc);
244300
}
245301
#define rb_enc_asciicompat(enc) rb_enc_asciicompat_inline(enc)
302+
#endif
246303

247304
int rb_enc_casefold(char *to, const char *p, const char *e, rb_encoding *enc);
248305
CONSTFUNC(int rb_enc_toupper(int c, rb_encoding *enc));
@@ -293,6 +350,9 @@ VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc);
293350
RUBY_EXTERN VALUE rb_cEncoding;
294351

295352
/* econv stuff */
353+
#ifdef TRUFFLERUBY
354+
struct rb_econv_t {};
355+
#endif
296356

297357
typedef enum {
298358
econv_invalid_byte_sequence,

lib/cext/include/ruby/intern.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ void rb_check_trusted(VALUE);
308308
rb_error_frozen_object(frozen_obj); \
309309
} \
310310
} while (0)
311+
#define rb_check_trusted_internal(obj) ((void) 0)
312+
#ifndef TRUFFLERUBY
311313
#ifdef __GNUC__
312314
#define rb_check_frozen(obj) __extension__({rb_check_frozen_internal(obj);})
313315
#else
@@ -324,6 +326,7 @@ rb_check_trusted_inline(VALUE obj)
324326
}
325327
#define rb_check_trusted(obj) rb_check_trusted_inline(obj)
326328
#endif
329+
#endif
327330
void rb_check_copyable(VALUE obj, VALUE orig);
328331

329332
#define RB_OBJ_INIT_COPY(obj, orig) \
@@ -580,11 +583,13 @@ VALUE rb_hash_size(VALUE);
580583
void rb_hash_free(VALUE);
581584
/* io.c */
582585
#define rb_defout rb_stdout
586+
#ifndef TRUFFLERUBY
583587
RUBY_EXTERN VALUE rb_fs;
584588
RUBY_EXTERN VALUE rb_output_fs;
585589
RUBY_EXTERN VALUE rb_rs;
586590
RUBY_EXTERN VALUE rb_default_rs;
587591
RUBY_EXTERN VALUE rb_output_rs;
592+
#endif
588593
VALUE rb_io_write(VALUE, VALUE);
589594
VALUE rb_io_gets(VALUE);
590595
VALUE rb_io_getbyte(VALUE);
@@ -837,6 +842,7 @@ VALUE rb_str_scrub(VALUE, VALUE);
837842
/* symbol.c */
838843
VALUE rb_sym_all_symbols(void);
839844

845+
#ifndef TRUFFLERUBY
840846
#ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P
841847
#define rb_str_new(str, len) RB_GNUC_EXTENSION_BLOCK( \
842848
(__builtin_constant_p(str) && __builtin_constant_p(len)) ? \
@@ -900,6 +906,7 @@ VALUE rb_sym_all_symbols(void);
900906
rb_exc_new_cstr((klass), (ptr)) \
901907
)
902908
#endif
909+
#endif
903910
#define rb_str_new2 rb_str_new_cstr
904911
#define rb_str_new3 rb_str_new_shared
905912
#define rb_str_new4 rb_str_new_frozen

lib/cext/include/ruby/io.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ typedef struct rb_io_enc_t rb_io_enc_t;
124124
/* #define FMODE_INET 0x00400000 */
125125
/* #define FMODE_INET6 0x00800000 */
126126

127+
#ifdef TRUFFLERUBY
128+
POLYGLOT_DECLARE_STRUCT(rb_io_t)
129+
#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = polyglot_as_rb_io_t(RUBY_CEXT_INVOKE_NO_WRAP("GetOpenFile", obj)))
130+
#else
127131
#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
132+
#endif
128133

129134
#define MakeOpenFile(obj, fp) do {\
130135
(fp) = rb_io_make_open_file(obj);\

lib/cext/include/ruby/onigmo.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,24 @@ int onigenc_ascii_only_case_map(OnigCaseFoldType* flagP, const OnigUChar** pp, c
324324
#define ONIGENC_IS_MBC_ASCII_WORD(enc,s,end) \
325325
onigenc_ascii_is_code_ctype( \
326326
ONIGENC_MBC_TO_CODE(enc,s,end),ONIGENC_CTYPE_WORD,enc)
327+
#ifdef TRUFFLERUBY
328+
int enc_is_unicode(const OnigEncodingType *enc);
329+
#define ONIGENC_IS_UNICODE(enc) enc_is_unicode(enc)
330+
#else
327331
#define ONIGENC_IS_UNICODE(enc) ((enc)->flags & ONIGENC_FLAG_UNICODE)
332+
#endif
328333

329334

330335
#define ONIGENC_NAME(enc) ((enc)->name)
331336

337+
#ifdef TRUFFLERUBY
338+
int rb_tr_enc_mbc_case_fold(const OnigEncodingType *enc, int flag, const UChar** p, const UChar* end, UChar* lower);
339+
#define ONIGENC_MBC_CASE_FOLD(enc,flag,pp,end,buf) \
340+
rb_tr_enc_mbc_case_fold(enc,flag,pp,end,buf)
341+
#else
332342
#define ONIGENC_MBC_CASE_FOLD(enc,flag,pp,end,buf) \
333343
(enc)->mbc_case_fold(flag,(const OnigUChar** )pp,end,buf,enc)
344+
#endif
334345
#define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc,s,end) \
335346
(enc)->is_allowed_reverse_match(s,end,enc)
336347
#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s,end) \
@@ -364,8 +375,15 @@ int onigenc_mbclen_approximate(const OnigUChar* p,const OnigUChar* e, const stru
364375
#define ONIGENC_MBC_MINLEN(enc) ((enc)->min_enc_len)
365376
#define ONIGENC_IS_MBC_NEWLINE(enc,p,end) (enc)->is_mbc_newline((p),(end),enc)
366377
#define ONIGENC_MBC_TO_CODE(enc,p,end) (enc)->mbc_to_code((p),(end),enc)
378+
#ifdef TRUFFLERUBY
379+
int rb_tr_code_to_mbclen(OnigCodePoint code, OnigEncodingType *encoding);
380+
#define ONIGENC_CODE_TO_MBCLEN(enc,code) rb_tr_code_to_mbclen(code,enc)
381+
int rb_tr_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc);
382+
#define ONIGENC_CODE_TO_MBC(enc,code,buf) rb_tr_code_to_mbc(code,buf,enc)
383+
#else
367384
#define ONIGENC_CODE_TO_MBCLEN(enc,code) (enc)->code_to_mbclen(code,enc)
368385
#define ONIGENC_CODE_TO_MBC(enc,code,buf) (enc)->code_to_mbc(code,buf,enc)
386+
#endif
369387
#define ONIGENC_PROPERTY_NAME_TO_CTYPE(enc,p,end) \
370388
(enc)->property_name_to_ctype(enc,p,end)
371389

0 commit comments

Comments
 (0)