[ruby/strscan] jruby: Check if len++ walked off the end
[ruby.git] / universal_parser.c
blobad2e2fbd11418ac3b18edb3d40fc5bba11ba18c3
1 #include <alloca.h>
2 #include <string.h>
3 #include <stdarg.h>
4 #include <stdbool.h>
5 #include <stddef.h>
7 /* Dependency */
8 #include "internal/parse.h"
9 #include "node.h"
10 #include "id.h"
12 #include "internal/compilers.h"
13 #include "ruby/backward/2/inttypes.h"
14 #include "probes.h"
16 #define LIKELY(x) RB_LIKELY(x)
17 #define UNLIKELY(x) RB_UNLIKELY(x)
18 #ifndef TRUE
19 # define TRUE 1
20 #endif
22 #ifndef FALSE
23 # define FALSE 0
24 #endif
25 #define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
26 #define rb_strlen_lit(str) ((sizeof(str "") / sizeof(str ""[0])) - 1)
27 #undef FIXNUM_MAX
28 #define FIXNUM_MAX (LONG_MAX / 2)
30 /* parser_st */
31 #define st_table parser_st_table
32 #define st_data_t parser_st_data_t
33 #define st_hash_type parser_st_hash_type
34 #define ST_CONTINUE ST2_CONTINUE
35 #define ST_STOP ST2_STOP
36 #define ST_DELETE ST2_DELETE
37 #define ST_CHECK ST2_CHECK
38 #define ST_REPLACE ST2_REPLACE
39 #undef st_init_numtable
40 #define st_init_numtable rb_parser_st_init_numtable
41 #undef st_free_table
42 #define st_free_table rb_parser_st_free_table
43 #undef st_init_table_with_size
44 #define st_init_table_with_size rb_parser_st_init_table_with_size
45 #undef st_insert
46 #define st_insert rb_parser_st_insert
47 #undef st_foreach
48 #define st_foreach rb_parser_st_foreach
49 #undef st_delete
50 #define st_delete rb_parser_st_delete
51 #undef st_is_member
52 #define st_is_member parser_st_is_member
53 #undef st_init_table
54 #define st_init_table rb_parser_st_init_table
55 #undef st_lookup
56 #define st_lookup rb_parser_st_lookup
58 #define rb_encoding const void
60 #undef xmalloc
61 #define xmalloc p->config->malloc
62 #undef xcalloc
63 #define xcalloc p->config->calloc
64 #undef xrealloc
65 #define xrealloc p->config->realloc
66 #undef ALLOC_N
67 #define ALLOC_N(type,n) ((type *)p->config->alloc_n((n), sizeof(type)))
68 #undef ALLOC
69 #define ALLOC(type) ((type *)p->config->alloc(sizeof(type)))
70 #undef xfree
71 #define xfree p->config->free
72 #undef ALLOCA_N
73 // alloca(rbimpl_size_mul_or_raise(x, y));
74 #define ALLOCA_N(type,n) ((type *)alloca(sizeof(type) * (n)))
75 #undef REALLOC_N
76 #define REALLOC_N(var,type,n) ((var) = (type *)p->config->realloc_n((void *)var, n, sizeof(type)))
77 #undef ZALLOC
78 #define ZALLOC(type) ((type *)p->config->zalloc(sizeof(type)))
79 #undef MEMMOVE
80 #define MEMMOVE(p1,p2,type,n) (p->config->rb_memmove((p1), (p2), sizeof(type), (n)))
81 #undef MEMCPY
82 #define MEMCPY(p1,p2,type,n) (p->config->nonempty_memcpy((p1), (p2), sizeof(type), (n)))
84 #define compile_callback p->config->compile_callback
85 #define reg_named_capture_assign p->config->reg_named_capture_assign
87 #define rb_attr_get p->config->attr_get
89 #undef rb_ary_new_from_args
90 #define rb_ary_new_from_args p->config->ary_new_from_args
91 #define rb_ary_unshift p->config->ary_unshift
93 #define rb_make_temporary_id p->config->make_temporary_id
94 #define is_local_id p->config->is_local_id
95 #define is_attrset_id p->config->is_attrset_id
96 #define is_global_name_punct p->config->is_global_name_punct
97 #define id_type p->config->id_type
98 #define rb_id_attrset p->config->id_attrset
99 #undef rb_intern
100 #define rb_intern p->config->intern
101 #define rb_intern2 p->config->intern2
102 #define rb_intern3 p->config->intern3
103 #define rb_intern_str p->config->intern_str
104 #define is_notop_id p->config->is_notop_id
105 #define rb_enc_symname_type p->config->enc_symname_type
106 #define rb_id2name p->config->id2name
107 #define rb_id2str p->config->id2str
108 #undef ID2SYM
109 #define ID2SYM p->config->id2sym
111 #define rb_str_catf p->config->str_catf
112 #undef rb_str_cat_cstr
113 #define rb_str_cat_cstr p->config->str_cat_cstr
114 #define rb_str_resize p->config->str_resize
115 #undef rb_str_new
116 #define rb_str_new p->config->str_new
117 #undef rb_str_new_cstr
118 #define rb_str_new_cstr p->config->str_new_cstr
119 #define rb_str_to_interned_str p->config->str_to_interned_str
120 #define rb_enc_str_new p->config->enc_str_new
121 #define rb_str_vcatf p->config->str_vcatf
122 #define rb_sprintf p->config->rb_sprintf
123 #undef RSTRING_PTR
124 #define RSTRING_PTR p->config->rstring_ptr
125 #undef RSTRING_LEN
126 #define RSTRING_LEN p->config->rstring_len
128 #undef INT2NUM
129 #define INT2NUM p->config->int2num
131 #define rb_stderr_tty_p p->config->stderr_tty_p
132 #define rb_write_error_str p->config->write_error_str
133 #define rb_io_write p->config->io_write
134 #define rb_io_flush p->config->io_flush
135 #define rb_io_puts p->config->io_puts
137 #define rb_ractor_stdout p->config->debug_output_stdout
138 #define rb_ractor_stderr p->config->debug_output_stderr
140 #define rb_is_usascii_enc p->config->is_usascii_enc
141 #define rb_enc_isalnum p->config->enc_isalnum
142 #define rb_enc_precise_mbclen p->config->enc_precise_mbclen
143 #define MBCLEN_CHARFOUND_P p->config->mbclen_charfound_p
144 #define MBCLEN_CHARFOUND_LEN p->config->mbclen_charfound_len
145 #define rb_enc_name p->config->enc_name
146 #define rb_enc_prev_char p->config->enc_prev_char
147 #define rb_enc_get p->config->enc_get
148 #define rb_enc_asciicompat p->config->enc_asciicompat
149 #define rb_utf8_encoding p->config->utf8_encoding
150 #define rb_ascii8bit_encoding p->config->ascii8bit_encoding
151 #define rb_enc_codelen p->config->enc_codelen
152 #define rb_enc_mbcput p->config->enc_mbcput
153 #define rb_enc_find_index p->config->enc_find_index
154 #define rb_enc_from_index p->config->enc_from_index
155 #define rb_enc_isspace p->config->enc_isspace
156 #define ENC_CODERANGE_7BIT p->config->enc_coderange_7bit
157 #define ENC_CODERANGE_UNKNOWN p->config->enc_coderange_unknown
159 #define rb_local_defined p->config->local_defined
160 #define rb_dvar_defined p->config->dvar_defined
162 #define rb_syntax_error_append p->config->syntax_error_append
163 #define rb_raise p->config->raise
164 #define syntax_error_new p->config->syntax_error_new
166 #define rb_errinfo p->config->errinfo
167 #define rb_set_errinfo p->config->set_errinfo
168 #define rb_make_exception p->config->make_exception
170 #define ruby_sized_xfree p->config->sized_xfree
171 #define SIZED_REALLOC_N(v, T, m, n) ((v) = (T *)p->config->sized_realloc_n((void *)(v), (m), sizeof(T), (n)))
172 #undef RB_GC_GUARD
173 #define RB_GC_GUARD p->config->gc_guard
174 #define rb_gc_mark p->config->gc_mark
176 #define rb_reg_compile p->config->reg_compile
177 #define rb_reg_check_preprocess p->config->reg_check_preprocess
178 #define rb_memcicmp p->config->memcicmp
180 #define rb_compile_warn p->config->compile_warn
181 #define rb_compile_warning p->config->compile_warning
182 #define rb_bug p->config->bug
183 #define rb_fatal p->config->fatal
184 #undef ruby_verbose
185 #define ruby_verbose p->config->verbose()
186 #undef errno
187 #define errno (*p->config->errno_ptr())
189 #define rb_make_backtrace p->config->make_backtrace
191 #define ruby_scan_hex p->config->scan_hex
192 #define ruby_scan_oct p->config->scan_oct
193 #define ruby_scan_digits p->config->scan_digits
194 #define strtod p->config->strtod
196 #undef RTEST
197 #define RTEST p->config->rtest
198 #undef NIL_P
199 #define NIL_P p->config->nil_p
200 #undef Qnil
201 #define Qnil p->config->qnil
202 #undef Qfalse
203 #define Qfalse p->config->qfalse
204 #define rb_eArgError p->config->eArgError()
205 #undef rb_long2int
206 #define rb_long2int p->config->long2int
207 #define rb_enc_mbminlen p->config->enc_mbminlen
208 #define rb_enc_isascii p->config->enc_isascii
209 #define rb_enc_mbc_to_codepoint p->config->enc_mbc_to_codepoint
211 #define rb_ast_new() \
212 rb_ast_new(p->config)