json 2.9.0 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +11 -0
- data/LEGAL +0 -52
- data/README.md +75 -2
- data/ext/json/ext/fbuffer/fbuffer.h +1 -10
- data/ext/json/ext/generator/generator.c +394 -263
- data/ext/json/ext/parser/extconf.rb +1 -0
- data/ext/json/ext/parser/parser.c +769 -2521
- data/json.gemspec +3 -4
- data/lib/json/add/symbol.rb +7 -2
- data/lib/json/common.rb +107 -10
- data/lib/json/ext/generator/state.rb +1 -11
- data/lib/json/ext.rb +26 -4
- data/lib/json/truffle_ruby/generator.rb +111 -50
- data/lib/json/version.rb +1 -1
- metadata +6 -11
- data/ext/json/ext/parser/parser.rl +0 -1457
@@ -1,1457 +0,0 @@
|
|
1
|
-
#include "ruby.h"
|
2
|
-
#include "../fbuffer/fbuffer.h"
|
3
|
-
|
4
|
-
static VALUE mJSON, mExt, cParser, eNestingError, Encoding_UTF_8;
|
5
|
-
static VALUE CNaN, CInfinity, CMinusInfinity;
|
6
|
-
|
7
|
-
static ID i_json_creatable_p, i_json_create, i_create_id,
|
8
|
-
i_chr, i_deep_const_get, i_match, i_aset, i_aref,
|
9
|
-
i_leftshift, i_new, i_try_convert, i_uminus, i_encode;
|
10
|
-
|
11
|
-
static VALUE sym_max_nesting, sym_allow_nan, sym_allow_trailing_comma, sym_symbolize_names, sym_freeze,
|
12
|
-
sym_create_additions, sym_create_id, sym_object_class, sym_array_class,
|
13
|
-
sym_decimal_class, sym_match_string;
|
14
|
-
|
15
|
-
static int binary_encindex;
|
16
|
-
static int utf8_encindex;
|
17
|
-
|
18
|
-
#ifdef HAVE_RB_CATEGORY_WARN
|
19
|
-
# define json_deprecated(message) rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, message)
|
20
|
-
#else
|
21
|
-
# define json_deprecated(message) rb_warn(message)
|
22
|
-
#endif
|
23
|
-
|
24
|
-
static const char deprecated_create_additions_warning[] =
|
25
|
-
"JSON.load implicit support for `create_additions: true` is deprecated "
|
26
|
-
"and will be removed in 3.0, use JSON.unsafe_load or explicitly "
|
27
|
-
"pass `create_additions: true`";
|
28
|
-
|
29
|
-
#ifndef HAVE_RB_HASH_BULK_INSERT
|
30
|
-
// For TruffleRuby
|
31
|
-
void rb_hash_bulk_insert(long count, const VALUE *pairs, VALUE hash)
|
32
|
-
{
|
33
|
-
long index = 0;
|
34
|
-
while (index < count) {
|
35
|
-
VALUE name = pairs[index++];
|
36
|
-
VALUE value = pairs[index++];
|
37
|
-
rb_hash_aset(hash, name, value);
|
38
|
-
}
|
39
|
-
RB_GC_GUARD(hash);
|
40
|
-
}
|
41
|
-
#endif
|
42
|
-
|
43
|
-
/* name cache */
|
44
|
-
|
45
|
-
#include <string.h>
|
46
|
-
#include <ctype.h>
|
47
|
-
|
48
|
-
// Object names are likely to be repeated, and are frozen.
|
49
|
-
// As such we can re-use them if we keep a cache of the ones we've seen so far,
|
50
|
-
// and save much more expensive lookups into the global fstring table.
|
51
|
-
// This cache implementation is deliberately simple, as we're optimizing for compactness,
|
52
|
-
// to be able to fit safely on the stack.
|
53
|
-
// As such, binary search into a sorted array gives a good tradeoff between compactness and
|
54
|
-
// performance.
|
55
|
-
#define JSON_RVALUE_CACHE_CAPA 63
|
56
|
-
typedef struct rvalue_cache_struct {
|
57
|
-
int length;
|
58
|
-
VALUE entries[JSON_RVALUE_CACHE_CAPA];
|
59
|
-
} rvalue_cache;
|
60
|
-
|
61
|
-
static rb_encoding *enc_utf8;
|
62
|
-
|
63
|
-
#define JSON_RVALUE_CACHE_MAX_ENTRY_LENGTH 55
|
64
|
-
|
65
|
-
static inline VALUE build_interned_string(const char *str, const long length)
|
66
|
-
{
|
67
|
-
# ifdef HAVE_RB_ENC_INTERNED_STR
|
68
|
-
return rb_enc_interned_str(str, length, enc_utf8);
|
69
|
-
# else
|
70
|
-
VALUE rstring = rb_utf8_str_new(str, length);
|
71
|
-
return rb_funcall(rb_str_freeze(rstring), i_uminus, 0);
|
72
|
-
# endif
|
73
|
-
}
|
74
|
-
|
75
|
-
static inline VALUE build_symbol(const char *str, const long length)
|
76
|
-
{
|
77
|
-
return rb_str_intern(build_interned_string(str, length));
|
78
|
-
}
|
79
|
-
|
80
|
-
static void rvalue_cache_insert_at(rvalue_cache *cache, int index, VALUE rstring)
|
81
|
-
{
|
82
|
-
MEMMOVE(&cache->entries[index + 1], &cache->entries[index], VALUE, cache->length - index);
|
83
|
-
cache->length++;
|
84
|
-
cache->entries[index] = rstring;
|
85
|
-
}
|
86
|
-
|
87
|
-
static inline int rstring_cache_cmp(const char *str, const long length, VALUE rstring)
|
88
|
-
{
|
89
|
-
long rstring_length = RSTRING_LEN(rstring);
|
90
|
-
if (length == rstring_length) {
|
91
|
-
return memcmp(str, RSTRING_PTR(rstring), length);
|
92
|
-
} else {
|
93
|
-
return (int)(length - rstring_length);
|
94
|
-
}
|
95
|
-
}
|
96
|
-
|
97
|
-
static VALUE rstring_cache_fetch(rvalue_cache *cache, const char *str, const long length)
|
98
|
-
{
|
99
|
-
if (RB_UNLIKELY(length > JSON_RVALUE_CACHE_MAX_ENTRY_LENGTH)) {
|
100
|
-
// Common names aren't likely to be very long. So we just don't
|
101
|
-
// cache names above an arbitrary threshold.
|
102
|
-
return Qfalse;
|
103
|
-
}
|
104
|
-
|
105
|
-
if (RB_UNLIKELY(!isalpha(str[0]))) {
|
106
|
-
// Simple heuristic, if the first character isn't a letter,
|
107
|
-
// we're much less likely to see this string again.
|
108
|
-
// We mostly want to cache strings that are likely to be repeated.
|
109
|
-
return Qfalse;
|
110
|
-
}
|
111
|
-
|
112
|
-
int low = 0;
|
113
|
-
int high = cache->length - 1;
|
114
|
-
int mid = 0;
|
115
|
-
int last_cmp = 0;
|
116
|
-
|
117
|
-
while (low <= high) {
|
118
|
-
mid = (high + low) >> 1;
|
119
|
-
VALUE entry = cache->entries[mid];
|
120
|
-
last_cmp = rstring_cache_cmp(str, length, entry);
|
121
|
-
|
122
|
-
if (last_cmp == 0) {
|
123
|
-
return entry;
|
124
|
-
} else if (last_cmp > 0) {
|
125
|
-
low = mid + 1;
|
126
|
-
} else {
|
127
|
-
high = mid - 1;
|
128
|
-
}
|
129
|
-
}
|
130
|
-
|
131
|
-
if (RB_UNLIKELY(memchr(str, '\\', length))) {
|
132
|
-
// We assume the overwhelming majority of names don't need to be escaped.
|
133
|
-
// But if they do, we have to fallback to the slow path.
|
134
|
-
return Qfalse;
|
135
|
-
}
|
136
|
-
|
137
|
-
VALUE rstring = build_interned_string(str, length);
|
138
|
-
|
139
|
-
if (cache->length < JSON_RVALUE_CACHE_CAPA) {
|
140
|
-
if (last_cmp > 0) {
|
141
|
-
mid += 1;
|
142
|
-
}
|
143
|
-
|
144
|
-
rvalue_cache_insert_at(cache, mid, rstring);
|
145
|
-
}
|
146
|
-
return rstring;
|
147
|
-
}
|
148
|
-
|
149
|
-
static VALUE rsymbol_cache_fetch(rvalue_cache *cache, const char *str, const long length)
|
150
|
-
{
|
151
|
-
if (RB_UNLIKELY(length > JSON_RVALUE_CACHE_MAX_ENTRY_LENGTH)) {
|
152
|
-
// Common names aren't likely to be very long. So we just don't
|
153
|
-
// cache names above an arbitrary threshold.
|
154
|
-
return Qfalse;
|
155
|
-
}
|
156
|
-
|
157
|
-
if (RB_UNLIKELY(!isalpha(str[0]))) {
|
158
|
-
// Simple heuristic, if the first character isn't a letter,
|
159
|
-
// we're much less likely to see this string again.
|
160
|
-
// We mostly want to cache strings that are likely to be repeated.
|
161
|
-
return Qfalse;
|
162
|
-
}
|
163
|
-
|
164
|
-
int low = 0;
|
165
|
-
int high = cache->length - 1;
|
166
|
-
int mid = 0;
|
167
|
-
int last_cmp = 0;
|
168
|
-
|
169
|
-
while (low <= high) {
|
170
|
-
mid = (high + low) >> 1;
|
171
|
-
VALUE entry = cache->entries[mid];
|
172
|
-
last_cmp = rstring_cache_cmp(str, length, rb_sym2str(entry));
|
173
|
-
|
174
|
-
if (last_cmp == 0) {
|
175
|
-
return entry;
|
176
|
-
} else if (last_cmp > 0) {
|
177
|
-
low = mid + 1;
|
178
|
-
} else {
|
179
|
-
high = mid - 1;
|
180
|
-
}
|
181
|
-
}
|
182
|
-
|
183
|
-
if (RB_UNLIKELY(memchr(str, '\\', length))) {
|
184
|
-
// We assume the overwhelming majority of names don't need to be escaped.
|
185
|
-
// But if they do, we have to fallback to the slow path.
|
186
|
-
return Qfalse;
|
187
|
-
}
|
188
|
-
|
189
|
-
VALUE rsymbol = build_symbol(str, length);
|
190
|
-
|
191
|
-
if (cache->length < JSON_RVALUE_CACHE_CAPA) {
|
192
|
-
if (last_cmp > 0) {
|
193
|
-
mid += 1;
|
194
|
-
}
|
195
|
-
|
196
|
-
rvalue_cache_insert_at(cache, mid, rsymbol);
|
197
|
-
}
|
198
|
-
return rsymbol;
|
199
|
-
}
|
200
|
-
|
201
|
-
/* rvalue stack */
|
202
|
-
|
203
|
-
#define RVALUE_STACK_INITIAL_CAPA 128
|
204
|
-
|
205
|
-
enum rvalue_stack_type {
|
206
|
-
RVALUE_STACK_HEAP_ALLOCATED = 0,
|
207
|
-
RVALUE_STACK_STACK_ALLOCATED = 1,
|
208
|
-
};
|
209
|
-
|
210
|
-
typedef struct rvalue_stack_struct {
|
211
|
-
enum rvalue_stack_type type;
|
212
|
-
long capa;
|
213
|
-
long head;
|
214
|
-
VALUE *ptr;
|
215
|
-
} rvalue_stack;
|
216
|
-
|
217
|
-
static rvalue_stack *rvalue_stack_spill(rvalue_stack *old_stack, VALUE *handle, rvalue_stack **stack_ref);
|
218
|
-
|
219
|
-
static rvalue_stack *rvalue_stack_grow(rvalue_stack *stack, VALUE *handle, rvalue_stack **stack_ref)
|
220
|
-
{
|
221
|
-
long required = stack->capa * 2;
|
222
|
-
|
223
|
-
if (stack->type == RVALUE_STACK_STACK_ALLOCATED) {
|
224
|
-
stack = rvalue_stack_spill(stack, handle, stack_ref);
|
225
|
-
} else {
|
226
|
-
REALLOC_N(stack->ptr, VALUE, required);
|
227
|
-
stack->capa = required;
|
228
|
-
}
|
229
|
-
return stack;
|
230
|
-
}
|
231
|
-
|
232
|
-
static void rvalue_stack_push(rvalue_stack *stack, VALUE value, VALUE *handle, rvalue_stack **stack_ref)
|
233
|
-
{
|
234
|
-
if (RB_UNLIKELY(stack->head >= stack->capa)) {
|
235
|
-
stack = rvalue_stack_grow(stack, handle, stack_ref);
|
236
|
-
}
|
237
|
-
stack->ptr[stack->head] = value;
|
238
|
-
stack->head++;
|
239
|
-
}
|
240
|
-
|
241
|
-
static inline VALUE *rvalue_stack_peek(rvalue_stack *stack, long count)
|
242
|
-
{
|
243
|
-
return stack->ptr + (stack->head - count);
|
244
|
-
}
|
245
|
-
|
246
|
-
static inline void rvalue_stack_pop(rvalue_stack *stack, long count)
|
247
|
-
{
|
248
|
-
stack->head -= count;
|
249
|
-
}
|
250
|
-
|
251
|
-
static void rvalue_stack_mark(void *ptr)
|
252
|
-
{
|
253
|
-
rvalue_stack *stack = (rvalue_stack *)ptr;
|
254
|
-
long index;
|
255
|
-
for (index = 0; index < stack->head; index++) {
|
256
|
-
rb_gc_mark(stack->ptr[index]);
|
257
|
-
}
|
258
|
-
}
|
259
|
-
|
260
|
-
static void rvalue_stack_free(void *ptr)
|
261
|
-
{
|
262
|
-
rvalue_stack *stack = (rvalue_stack *)ptr;
|
263
|
-
if (stack) {
|
264
|
-
ruby_xfree(stack->ptr);
|
265
|
-
ruby_xfree(stack);
|
266
|
-
}
|
267
|
-
}
|
268
|
-
|
269
|
-
static size_t rvalue_stack_memsize(const void *ptr)
|
270
|
-
{
|
271
|
-
const rvalue_stack *stack = (const rvalue_stack *)ptr;
|
272
|
-
return sizeof(rvalue_stack) + sizeof(VALUE) * stack->capa;
|
273
|
-
}
|
274
|
-
|
275
|
-
static const rb_data_type_t JSON_Parser_rvalue_stack_type = {
|
276
|
-
"JSON::Ext::Parser/rvalue_stack",
|
277
|
-
{
|
278
|
-
.dmark = rvalue_stack_mark,
|
279
|
-
.dfree = rvalue_stack_free,
|
280
|
-
.dsize = rvalue_stack_memsize,
|
281
|
-
},
|
282
|
-
0, 0,
|
283
|
-
RUBY_TYPED_FREE_IMMEDIATELY,
|
284
|
-
};
|
285
|
-
|
286
|
-
static rvalue_stack *rvalue_stack_spill(rvalue_stack *old_stack, VALUE *handle, rvalue_stack **stack_ref)
|
287
|
-
{
|
288
|
-
rvalue_stack *stack;
|
289
|
-
*handle = TypedData_Make_Struct(0, rvalue_stack, &JSON_Parser_rvalue_stack_type, stack);
|
290
|
-
*stack_ref = stack;
|
291
|
-
MEMCPY(stack, old_stack, rvalue_stack, 1);
|
292
|
-
|
293
|
-
stack->capa = old_stack->capa << 1;
|
294
|
-
stack->ptr = ALLOC_N(VALUE, stack->capa);
|
295
|
-
stack->type = RVALUE_STACK_HEAP_ALLOCATED;
|
296
|
-
MEMCPY(stack->ptr, old_stack->ptr, VALUE, old_stack->head);
|
297
|
-
return stack;
|
298
|
-
}
|
299
|
-
|
300
|
-
static void rvalue_stack_eagerly_release(VALUE handle)
|
301
|
-
{
|
302
|
-
rvalue_stack *stack;
|
303
|
-
TypedData_Get_Struct(handle, rvalue_stack, &JSON_Parser_rvalue_stack_type, stack);
|
304
|
-
RTYPEDDATA_DATA(handle) = NULL;
|
305
|
-
rvalue_stack_free(stack);
|
306
|
-
}
|
307
|
-
|
308
|
-
/* unicode */
|
309
|
-
|
310
|
-
static const signed char digit_values[256] = {
|
311
|
-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
312
|
-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
313
|
-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
|
314
|
-
-1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1,
|
315
|
-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
316
|
-
10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
317
|
-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
318
|
-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
319
|
-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
320
|
-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
321
|
-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
322
|
-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
323
|
-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
324
|
-
-1, -1, -1, -1, -1, -1, -1
|
325
|
-
};
|
326
|
-
|
327
|
-
static uint32_t unescape_unicode(const unsigned char *p)
|
328
|
-
{
|
329
|
-
const uint32_t replacement_char = 0xFFFD;
|
330
|
-
|
331
|
-
signed char b;
|
332
|
-
uint32_t result = 0;
|
333
|
-
b = digit_values[p[0]];
|
334
|
-
if (b < 0) return replacement_char;
|
335
|
-
result = (result << 4) | (unsigned char)b;
|
336
|
-
b = digit_values[p[1]];
|
337
|
-
if (b < 0) return replacement_char;
|
338
|
-
result = (result << 4) | (unsigned char)b;
|
339
|
-
b = digit_values[p[2]];
|
340
|
-
if (b < 0) return replacement_char;
|
341
|
-
result = (result << 4) | (unsigned char)b;
|
342
|
-
b = digit_values[p[3]];
|
343
|
-
if (b < 0) return replacement_char;
|
344
|
-
result = (result << 4) | (unsigned char)b;
|
345
|
-
return result;
|
346
|
-
}
|
347
|
-
|
348
|
-
static int convert_UTF32_to_UTF8(char *buf, uint32_t ch)
|
349
|
-
{
|
350
|
-
int len = 1;
|
351
|
-
if (ch <= 0x7F) {
|
352
|
-
buf[0] = (char) ch;
|
353
|
-
} else if (ch <= 0x07FF) {
|
354
|
-
buf[0] = (char) ((ch >> 6) | 0xC0);
|
355
|
-
buf[1] = (char) ((ch & 0x3F) | 0x80);
|
356
|
-
len++;
|
357
|
-
} else if (ch <= 0xFFFF) {
|
358
|
-
buf[0] = (char) ((ch >> 12) | 0xE0);
|
359
|
-
buf[1] = (char) (((ch >> 6) & 0x3F) | 0x80);
|
360
|
-
buf[2] = (char) ((ch & 0x3F) | 0x80);
|
361
|
-
len += 2;
|
362
|
-
} else if (ch <= 0x1fffff) {
|
363
|
-
buf[0] =(char) ((ch >> 18) | 0xF0);
|
364
|
-
buf[1] =(char) (((ch >> 12) & 0x3F) | 0x80);
|
365
|
-
buf[2] =(char) (((ch >> 6) & 0x3F) | 0x80);
|
366
|
-
buf[3] =(char) ((ch & 0x3F) | 0x80);
|
367
|
-
len += 3;
|
368
|
-
} else {
|
369
|
-
buf[0] = '?';
|
370
|
-
}
|
371
|
-
return len;
|
372
|
-
}
|
373
|
-
|
374
|
-
typedef struct JSON_ParserStruct {
|
375
|
-
VALUE Vsource;
|
376
|
-
char *source;
|
377
|
-
long len;
|
378
|
-
char *memo;
|
379
|
-
VALUE create_id;
|
380
|
-
VALUE object_class;
|
381
|
-
VALUE array_class;
|
382
|
-
VALUE decimal_class;
|
383
|
-
VALUE match_string;
|
384
|
-
FBuffer fbuffer;
|
385
|
-
int in_array;
|
386
|
-
int max_nesting;
|
387
|
-
bool allow_nan;
|
388
|
-
bool allow_trailing_comma;
|
389
|
-
bool parsing_name;
|
390
|
-
bool symbolize_names;
|
391
|
-
bool freeze;
|
392
|
-
bool create_additions;
|
393
|
-
bool deprecated_create_additions;
|
394
|
-
rvalue_cache name_cache;
|
395
|
-
rvalue_stack *stack;
|
396
|
-
VALUE stack_handle;
|
397
|
-
} JSON_Parser;
|
398
|
-
|
399
|
-
#define GET_PARSER \
|
400
|
-
GET_PARSER_INIT; \
|
401
|
-
if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance")
|
402
|
-
|
403
|
-
#define GET_PARSER_INIT \
|
404
|
-
JSON_Parser *json; \
|
405
|
-
TypedData_Get_Struct(self, JSON_Parser, &JSON_Parser_type, json)
|
406
|
-
|
407
|
-
#define MinusInfinity "-Infinity"
|
408
|
-
#define EVIL 0x666
|
409
|
-
|
410
|
-
static const rb_data_type_t JSON_Parser_type;
|
411
|
-
static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result);
|
412
|
-
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting);
|
413
|
-
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting);
|
414
|
-
static char *JSON_parse_number(JSON_Parser *json, char *p, char *pe, VALUE *result);
|
415
|
-
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting);
|
416
|
-
|
417
|
-
|
418
|
-
#define PARSE_ERROR_FRAGMENT_LEN 32
|
419
|
-
#ifdef RBIMPL_ATTR_NORETURN
|
420
|
-
RBIMPL_ATTR_NORETURN()
|
421
|
-
#endif
|
422
|
-
static void raise_parse_error(const char *format, const char *start)
|
423
|
-
{
|
424
|
-
char buffer[PARSE_ERROR_FRAGMENT_LEN + 1];
|
425
|
-
|
426
|
-
size_t len = strnlen(start, PARSE_ERROR_FRAGMENT_LEN);
|
427
|
-
const char *ptr = start;
|
428
|
-
|
429
|
-
if (len == PARSE_ERROR_FRAGMENT_LEN) {
|
430
|
-
MEMCPY(buffer, start, char, PARSE_ERROR_FRAGMENT_LEN);
|
431
|
-
buffer[PARSE_ERROR_FRAGMENT_LEN] = '\0';
|
432
|
-
ptr = buffer;
|
433
|
-
}
|
434
|
-
|
435
|
-
rb_enc_raise(enc_utf8, rb_path2class("JSON::ParserError"), format, ptr);
|
436
|
-
}
|
437
|
-
|
438
|
-
|
439
|
-
%%{
|
440
|
-
machine JSON_common;
|
441
|
-
|
442
|
-
cr = '\n';
|
443
|
-
cr_neg = [^\n];
|
444
|
-
ws = [ \t\r\n];
|
445
|
-
c_comment = '/*' ( any* - (any* '*/' any* ) ) '*/';
|
446
|
-
cpp_comment = '//' cr_neg* cr;
|
447
|
-
comment = c_comment | cpp_comment;
|
448
|
-
ignore = ws | comment;
|
449
|
-
name_separator = ':';
|
450
|
-
value_separator = ',';
|
451
|
-
Vnull = 'null';
|
452
|
-
Vfalse = 'false';
|
453
|
-
Vtrue = 'true';
|
454
|
-
VNaN = 'NaN';
|
455
|
-
VInfinity = 'Infinity';
|
456
|
-
VMinusInfinity = '-Infinity';
|
457
|
-
begin_value = [nft\"\-\[\{NI] | digit;
|
458
|
-
begin_object = '{';
|
459
|
-
end_object = '}';
|
460
|
-
begin_array = '[';
|
461
|
-
end_array = ']';
|
462
|
-
begin_string = '"';
|
463
|
-
begin_name = begin_string;
|
464
|
-
begin_number = digit | '-';
|
465
|
-
}%%
|
466
|
-
|
467
|
-
%%{
|
468
|
-
machine JSON_object;
|
469
|
-
include JSON_common;
|
470
|
-
|
471
|
-
write data;
|
472
|
-
|
473
|
-
action parse_value {
|
474
|
-
char *np = JSON_parse_value(json, fpc, pe, result, current_nesting);
|
475
|
-
if (np == NULL) {
|
476
|
-
fhold; fbreak;
|
477
|
-
} else {
|
478
|
-
fexec np;
|
479
|
-
}
|
480
|
-
}
|
481
|
-
|
482
|
-
action allow_trailing_comma { json->allow_trailing_comma }
|
483
|
-
|
484
|
-
action parse_name {
|
485
|
-
char *np;
|
486
|
-
json->parsing_name = true;
|
487
|
-
np = JSON_parse_string(json, fpc, pe, result);
|
488
|
-
json->parsing_name = false;
|
489
|
-
if (np == NULL) { fhold; fbreak; } else {
|
490
|
-
PUSH(*result);
|
491
|
-
fexec np;
|
492
|
-
}
|
493
|
-
}
|
494
|
-
|
495
|
-
action exit { fhold; fbreak; }
|
496
|
-
|
497
|
-
pair = ignore* begin_name >parse_name ignore* name_separator ignore* begin_value >parse_value;
|
498
|
-
next_pair = ignore* value_separator pair;
|
499
|
-
|
500
|
-
main := (
|
501
|
-
begin_object
|
502
|
-
(pair (next_pair)*((ignore* value_separator) when allow_trailing_comma)?)? ignore*
|
503
|
-
end_object
|
504
|
-
) @exit;
|
505
|
-
}%%
|
506
|
-
|
507
|
-
#define PUSH(result) rvalue_stack_push(json->stack, result, &json->stack_handle, &json->stack)
|
508
|
-
|
509
|
-
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
510
|
-
{
|
511
|
-
int cs = EVIL;
|
512
|
-
|
513
|
-
if (json->max_nesting && current_nesting > json->max_nesting) {
|
514
|
-
rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
|
515
|
-
}
|
516
|
-
|
517
|
-
long stack_head = json->stack->head;
|
518
|
-
|
519
|
-
%% write init;
|
520
|
-
%% write exec;
|
521
|
-
|
522
|
-
if (cs >= JSON_object_first_final) {
|
523
|
-
long count = json->stack->head - stack_head;
|
524
|
-
|
525
|
-
if (RB_UNLIKELY(json->object_class)) {
|
526
|
-
VALUE object = rb_class_new_instance(0, 0, json->object_class);
|
527
|
-
long index = 0;
|
528
|
-
VALUE *items = rvalue_stack_peek(json->stack, count);
|
529
|
-
while (index < count) {
|
530
|
-
VALUE name = items[index++];
|
531
|
-
VALUE value = items[index++];
|
532
|
-
rb_funcall(object, i_aset, 2, name, value);
|
533
|
-
}
|
534
|
-
*result = object;
|
535
|
-
} else {
|
536
|
-
VALUE hash;
|
537
|
-
#ifdef HAVE_RB_HASH_NEW_CAPA
|
538
|
-
hash = rb_hash_new_capa(count >> 1);
|
539
|
-
#else
|
540
|
-
hash = rb_hash_new();
|
541
|
-
#endif
|
542
|
-
rb_hash_bulk_insert(count, rvalue_stack_peek(json->stack, count), hash);
|
543
|
-
*result = hash;
|
544
|
-
}
|
545
|
-
rvalue_stack_pop(json->stack, count);
|
546
|
-
|
547
|
-
if (RB_UNLIKELY(json->create_additions)) {
|
548
|
-
VALUE klassname;
|
549
|
-
if (json->object_class) {
|
550
|
-
klassname = rb_funcall(*result, i_aref, 1, json->create_id);
|
551
|
-
} else {
|
552
|
-
klassname = rb_hash_aref(*result, json->create_id);
|
553
|
-
}
|
554
|
-
if (!NIL_P(klassname)) {
|
555
|
-
VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname);
|
556
|
-
if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) {
|
557
|
-
if (json->deprecated_create_additions) {
|
558
|
-
json_deprecated(deprecated_create_additions_warning);
|
559
|
-
}
|
560
|
-
*result = rb_funcall(klass, i_json_create, 1, *result);
|
561
|
-
}
|
562
|
-
}
|
563
|
-
}
|
564
|
-
return p + 1;
|
565
|
-
} else {
|
566
|
-
return NULL;
|
567
|
-
}
|
568
|
-
}
|
569
|
-
|
570
|
-
%%{
|
571
|
-
machine JSON_value;
|
572
|
-
include JSON_common;
|
573
|
-
|
574
|
-
write data;
|
575
|
-
|
576
|
-
action parse_null {
|
577
|
-
*result = Qnil;
|
578
|
-
}
|
579
|
-
action parse_false {
|
580
|
-
*result = Qfalse;
|
581
|
-
}
|
582
|
-
action parse_true {
|
583
|
-
*result = Qtrue;
|
584
|
-
}
|
585
|
-
action parse_nan {
|
586
|
-
if (json->allow_nan) {
|
587
|
-
*result = CNaN;
|
588
|
-
} else {
|
589
|
-
raise_parse_error("unexpected token at '%s'", p - 2);
|
590
|
-
}
|
591
|
-
}
|
592
|
-
action parse_infinity {
|
593
|
-
if (json->allow_nan) {
|
594
|
-
*result = CInfinity;
|
595
|
-
} else {
|
596
|
-
raise_parse_error("unexpected token at '%s'", p - 7);
|
597
|
-
}
|
598
|
-
}
|
599
|
-
action parse_string {
|
600
|
-
char *np = JSON_parse_string(json, fpc, pe, result);
|
601
|
-
if (np == NULL) {
|
602
|
-
fhold;
|
603
|
-
fbreak;
|
604
|
-
} else {
|
605
|
-
fexec np;
|
606
|
-
}
|
607
|
-
}
|
608
|
-
|
609
|
-
action parse_number {
|
610
|
-
char *np;
|
611
|
-
if(pe > fpc + 8 && !strncmp(MinusInfinity, fpc, 9)) {
|
612
|
-
if (json->allow_nan) {
|
613
|
-
*result = CMinusInfinity;
|
614
|
-
fexec p + 10;
|
615
|
-
fhold; fbreak;
|
616
|
-
} else {
|
617
|
-
raise_parse_error("unexpected token at '%s'", p);
|
618
|
-
}
|
619
|
-
}
|
620
|
-
np = JSON_parse_number(json, fpc, pe, result);
|
621
|
-
if (np != NULL) {
|
622
|
-
fexec np;
|
623
|
-
}
|
624
|
-
fhold; fbreak;
|
625
|
-
}
|
626
|
-
|
627
|
-
action parse_array {
|
628
|
-
char *np;
|
629
|
-
json->in_array++;
|
630
|
-
np = JSON_parse_array(json, fpc, pe, result, current_nesting + 1);
|
631
|
-
json->in_array--;
|
632
|
-
if (np == NULL) { fhold; fbreak; } else fexec np;
|
633
|
-
}
|
634
|
-
|
635
|
-
action parse_object {
|
636
|
-
char *np;
|
637
|
-
np = JSON_parse_object(json, fpc, pe, result, current_nesting + 1);
|
638
|
-
if (np == NULL) { fhold; fbreak; } else fexec np;
|
639
|
-
}
|
640
|
-
|
641
|
-
action exit { fhold; fbreak; }
|
642
|
-
|
643
|
-
main := ignore* (
|
644
|
-
Vnull @parse_null |
|
645
|
-
Vfalse @parse_false |
|
646
|
-
Vtrue @parse_true |
|
647
|
-
VNaN @parse_nan |
|
648
|
-
VInfinity @parse_infinity |
|
649
|
-
begin_number @parse_number |
|
650
|
-
begin_string @parse_string |
|
651
|
-
begin_array @parse_array |
|
652
|
-
begin_object @parse_object
|
653
|
-
) ignore* %*exit;
|
654
|
-
}%%
|
655
|
-
|
656
|
-
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
657
|
-
{
|
658
|
-
int cs = EVIL;
|
659
|
-
|
660
|
-
%% write init;
|
661
|
-
%% write exec;
|
662
|
-
|
663
|
-
if (json->freeze) {
|
664
|
-
OBJ_FREEZE(*result);
|
665
|
-
}
|
666
|
-
|
667
|
-
if (cs >= JSON_value_first_final) {
|
668
|
-
PUSH(*result);
|
669
|
-
return p;
|
670
|
-
} else {
|
671
|
-
return NULL;
|
672
|
-
}
|
673
|
-
}
|
674
|
-
|
675
|
-
%%{
|
676
|
-
machine JSON_integer;
|
677
|
-
|
678
|
-
write data;
|
679
|
-
|
680
|
-
action exit { fhold; fbreak; }
|
681
|
-
|
682
|
-
main := '-'? ('0' | [1-9][0-9]*) (^[0-9]? @exit);
|
683
|
-
}%%
|
684
|
-
|
685
|
-
#define MAX_FAST_INTEGER_SIZE 18
|
686
|
-
static inline VALUE fast_parse_integer(char *p, char *pe)
|
687
|
-
{
|
688
|
-
bool negative = false;
|
689
|
-
if (*p == '-') {
|
690
|
-
negative = true;
|
691
|
-
p++;
|
692
|
-
}
|
693
|
-
|
694
|
-
long long memo = 0;
|
695
|
-
while (p < pe) {
|
696
|
-
memo *= 10;
|
697
|
-
memo += *p - '0';
|
698
|
-
p++;
|
699
|
-
}
|
700
|
-
|
701
|
-
if (negative) {
|
702
|
-
memo = -memo;
|
703
|
-
}
|
704
|
-
return LL2NUM(memo);
|
705
|
-
}
|
706
|
-
|
707
|
-
static char *JSON_decode_integer(JSON_Parser *json, char *p, VALUE *result)
|
708
|
-
{
|
709
|
-
long len = p - json->memo;
|
710
|
-
if (RB_LIKELY(len < MAX_FAST_INTEGER_SIZE)) {
|
711
|
-
*result = fast_parse_integer(json->memo, p);
|
712
|
-
} else {
|
713
|
-
fbuffer_clear(&json->fbuffer);
|
714
|
-
fbuffer_append(&json->fbuffer, json->memo, len);
|
715
|
-
fbuffer_append_char(&json->fbuffer, '\0');
|
716
|
-
*result = rb_cstr2inum(FBUFFER_PTR(&json->fbuffer), 10);
|
717
|
-
}
|
718
|
-
return p + 1;
|
719
|
-
}
|
720
|
-
|
721
|
-
%%{
|
722
|
-
machine JSON_float;
|
723
|
-
include JSON_common;
|
724
|
-
|
725
|
-
write data;
|
726
|
-
|
727
|
-
action exit { fhold; fbreak; }
|
728
|
-
action isFloat { is_float = true; }
|
729
|
-
|
730
|
-
main := '-'? (
|
731
|
-
(('0' | [1-9][0-9]*)
|
732
|
-
((('.' [0-9]+ ([Ee] [+\-]?[0-9]+)?) |
|
733
|
-
([Ee] [+\-]?[0-9]+)) > isFloat)?
|
734
|
-
) (^[0-9Ee.\-]? @exit ));
|
735
|
-
}%%
|
736
|
-
|
737
|
-
static char *JSON_parse_number(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
738
|
-
{
|
739
|
-
int cs = EVIL;
|
740
|
-
bool is_float = false;
|
741
|
-
|
742
|
-
%% write init;
|
743
|
-
json->memo = p;
|
744
|
-
%% write exec;
|
745
|
-
|
746
|
-
if (cs >= JSON_float_first_final) {
|
747
|
-
if (!is_float) {
|
748
|
-
return JSON_decode_integer(json, p, result);
|
749
|
-
}
|
750
|
-
VALUE mod = Qnil;
|
751
|
-
ID method_id = 0;
|
752
|
-
if (json->decimal_class) {
|
753
|
-
if (rb_respond_to(json->decimal_class, i_try_convert)) {
|
754
|
-
mod = json->decimal_class;
|
755
|
-
method_id = i_try_convert;
|
756
|
-
} else if (rb_respond_to(json->decimal_class, i_new)) {
|
757
|
-
mod = json->decimal_class;
|
758
|
-
method_id = i_new;
|
759
|
-
} else if (RB_TYPE_P(json->decimal_class, T_CLASS)) {
|
760
|
-
VALUE name = rb_class_name(json->decimal_class);
|
761
|
-
const char *name_cstr = RSTRING_PTR(name);
|
762
|
-
const char *last_colon = strrchr(name_cstr, ':');
|
763
|
-
if (last_colon) {
|
764
|
-
const char *mod_path_end = last_colon - 1;
|
765
|
-
VALUE mod_path = rb_str_substr(name, 0, mod_path_end - name_cstr);
|
766
|
-
mod = rb_path_to_class(mod_path);
|
767
|
-
|
768
|
-
const char *method_name_beg = last_colon + 1;
|
769
|
-
long before_len = method_name_beg - name_cstr;
|
770
|
-
long len = RSTRING_LEN(name) - before_len;
|
771
|
-
VALUE method_name = rb_str_substr(name, before_len, len);
|
772
|
-
method_id = SYM2ID(rb_str_intern(method_name));
|
773
|
-
} else {
|
774
|
-
mod = rb_mKernel;
|
775
|
-
method_id = SYM2ID(rb_str_intern(name));
|
776
|
-
}
|
777
|
-
}
|
778
|
-
}
|
779
|
-
|
780
|
-
long len = p - json->memo;
|
781
|
-
fbuffer_clear(&json->fbuffer);
|
782
|
-
fbuffer_append(&json->fbuffer, json->memo, len);
|
783
|
-
fbuffer_append_char(&json->fbuffer, '\0');
|
784
|
-
|
785
|
-
if (method_id) {
|
786
|
-
VALUE text = rb_str_new2(FBUFFER_PTR(&json->fbuffer));
|
787
|
-
*result = rb_funcallv(mod, method_id, 1, &text);
|
788
|
-
} else {
|
789
|
-
*result = DBL2NUM(rb_cstr_to_dbl(FBUFFER_PTR(&json->fbuffer), 1));
|
790
|
-
}
|
791
|
-
|
792
|
-
return p + 1;
|
793
|
-
} else {
|
794
|
-
return NULL;
|
795
|
-
}
|
796
|
-
}
|
797
|
-
|
798
|
-
|
799
|
-
%%{
|
800
|
-
machine JSON_array;
|
801
|
-
include JSON_common;
|
802
|
-
|
803
|
-
write data;
|
804
|
-
|
805
|
-
action parse_value {
|
806
|
-
VALUE v = Qnil;
|
807
|
-
char *np = JSON_parse_value(json, fpc, pe, &v, current_nesting);
|
808
|
-
if (np == NULL) {
|
809
|
-
fhold; fbreak;
|
810
|
-
} else {
|
811
|
-
fexec np;
|
812
|
-
}
|
813
|
-
}
|
814
|
-
|
815
|
-
action allow_trailing_comma { json->allow_trailing_comma }
|
816
|
-
|
817
|
-
action exit { fhold; fbreak; }
|
818
|
-
|
819
|
-
next_element = value_separator ignore* begin_value >parse_value;
|
820
|
-
|
821
|
-
main := begin_array ignore*
|
822
|
-
((begin_value >parse_value ignore*)
|
823
|
-
(ignore* next_element ignore*)*((value_separator ignore*) when allow_trailing_comma)?)?
|
824
|
-
end_array @exit;
|
825
|
-
}%%
|
826
|
-
|
827
|
-
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
828
|
-
{
|
829
|
-
int cs = EVIL;
|
830
|
-
|
831
|
-
if (json->max_nesting && current_nesting > json->max_nesting) {
|
832
|
-
rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
|
833
|
-
}
|
834
|
-
long stack_head = json->stack->head;
|
835
|
-
|
836
|
-
%% write init;
|
837
|
-
%% write exec;
|
838
|
-
|
839
|
-
if(cs >= JSON_array_first_final) {
|
840
|
-
long count = json->stack->head - stack_head;
|
841
|
-
|
842
|
-
if (RB_UNLIKELY(json->array_class)) {
|
843
|
-
VALUE array = rb_class_new_instance(0, 0, json->array_class);
|
844
|
-
VALUE *items = rvalue_stack_peek(json->stack, count);
|
845
|
-
long index;
|
846
|
-
for (index = 0; index < count; index++) {
|
847
|
-
rb_funcall(array, i_leftshift, 1, items[index]);
|
848
|
-
}
|
849
|
-
*result = array;
|
850
|
-
} else {
|
851
|
-
VALUE array = rb_ary_new_from_values(count, rvalue_stack_peek(json->stack, count));
|
852
|
-
*result = array;
|
853
|
-
}
|
854
|
-
rvalue_stack_pop(json->stack, count);
|
855
|
-
|
856
|
-
return p + 1;
|
857
|
-
} else {
|
858
|
-
raise_parse_error("unexpected token at '%s'", p);
|
859
|
-
return NULL;
|
860
|
-
}
|
861
|
-
}
|
862
|
-
|
863
|
-
static inline VALUE build_string(const char *start, const char *end, bool intern, bool symbolize)
|
864
|
-
{
|
865
|
-
if (symbolize) {
|
866
|
-
intern = true;
|
867
|
-
}
|
868
|
-
VALUE result;
|
869
|
-
# ifdef HAVE_RB_ENC_INTERNED_STR
|
870
|
-
if (intern) {
|
871
|
-
result = rb_enc_interned_str(start, (long)(end - start), enc_utf8);
|
872
|
-
} else {
|
873
|
-
result = rb_utf8_str_new(start, (long)(end - start));
|
874
|
-
}
|
875
|
-
# else
|
876
|
-
result = rb_utf8_str_new(start, (long)(end - start));
|
877
|
-
if (intern) {
|
878
|
-
result = rb_funcall(rb_str_freeze(result), i_uminus, 0);
|
879
|
-
}
|
880
|
-
# endif
|
881
|
-
|
882
|
-
if (symbolize) {
|
883
|
-
result = rb_str_intern(result);
|
884
|
-
}
|
885
|
-
|
886
|
-
return result;
|
887
|
-
}
|
888
|
-
|
889
|
-
static VALUE json_string_fastpath(JSON_Parser *json, char *string, char *stringEnd, bool is_name, bool intern, bool symbolize)
|
890
|
-
{
|
891
|
-
size_t bufferSize = stringEnd - string;
|
892
|
-
|
893
|
-
if (is_name && json->in_array) {
|
894
|
-
VALUE cached_key;
|
895
|
-
if (RB_UNLIKELY(symbolize)) {
|
896
|
-
cached_key = rsymbol_cache_fetch(&json->name_cache, string, bufferSize);
|
897
|
-
} else {
|
898
|
-
cached_key = rstring_cache_fetch(&json->name_cache, string, bufferSize);
|
899
|
-
}
|
900
|
-
|
901
|
-
if (RB_LIKELY(cached_key)) {
|
902
|
-
return cached_key;
|
903
|
-
}
|
904
|
-
}
|
905
|
-
|
906
|
-
return build_string(string, stringEnd, intern, symbolize);
|
907
|
-
}
|
908
|
-
|
909
|
-
static VALUE json_string_unescape(JSON_Parser *json, char *string, char *stringEnd, bool is_name, bool intern, bool symbolize)
|
910
|
-
{
|
911
|
-
size_t bufferSize = stringEnd - string;
|
912
|
-
char *p = string, *pe = string, *unescape, *bufferStart, *buffer;
|
913
|
-
int unescape_len;
|
914
|
-
char buf[4];
|
915
|
-
|
916
|
-
if (is_name && json->in_array) {
|
917
|
-
VALUE cached_key;
|
918
|
-
if (RB_UNLIKELY(symbolize)) {
|
919
|
-
cached_key = rsymbol_cache_fetch(&json->name_cache, string, bufferSize);
|
920
|
-
} else {
|
921
|
-
cached_key = rstring_cache_fetch(&json->name_cache, string, bufferSize);
|
922
|
-
}
|
923
|
-
|
924
|
-
if (RB_LIKELY(cached_key)) {
|
925
|
-
return cached_key;
|
926
|
-
}
|
927
|
-
}
|
928
|
-
|
929
|
-
pe = memchr(p, '\\', bufferSize);
|
930
|
-
if (RB_UNLIKELY(pe == NULL)) {
|
931
|
-
return build_string(string, stringEnd, intern, symbolize);
|
932
|
-
}
|
933
|
-
|
934
|
-
VALUE result = rb_str_buf_new(bufferSize);
|
935
|
-
rb_enc_associate_index(result, utf8_encindex);
|
936
|
-
buffer = bufferStart = RSTRING_PTR(result);
|
937
|
-
|
938
|
-
while (pe < stringEnd) {
|
939
|
-
if (*pe == '\\') {
|
940
|
-
unescape = (char *) "?";
|
941
|
-
unescape_len = 1;
|
942
|
-
if (pe > p) {
|
943
|
-
MEMCPY(buffer, p, char, pe - p);
|
944
|
-
buffer += pe - p;
|
945
|
-
}
|
946
|
-
switch (*++pe) {
|
947
|
-
case 'n':
|
948
|
-
unescape = (char *) "\n";
|
949
|
-
break;
|
950
|
-
case 'r':
|
951
|
-
unescape = (char *) "\r";
|
952
|
-
break;
|
953
|
-
case 't':
|
954
|
-
unescape = (char *) "\t";
|
955
|
-
break;
|
956
|
-
case '"':
|
957
|
-
unescape = (char *) "\"";
|
958
|
-
break;
|
959
|
-
case '\\':
|
960
|
-
unescape = (char *) "\\";
|
961
|
-
break;
|
962
|
-
case 'b':
|
963
|
-
unescape = (char *) "\b";
|
964
|
-
break;
|
965
|
-
case 'f':
|
966
|
-
unescape = (char *) "\f";
|
967
|
-
break;
|
968
|
-
case 'u':
|
969
|
-
if (pe > stringEnd - 4) {
|
970
|
-
raise_parse_error("incomplete unicode character escape sequence at '%s'", p);
|
971
|
-
} else {
|
972
|
-
uint32_t ch = unescape_unicode((unsigned char *) ++pe);
|
973
|
-
pe += 3;
|
974
|
-
/* To handle values above U+FFFF, we take a sequence of
|
975
|
-
* \uXXXX escapes in the U+D800..U+DBFF then
|
976
|
-
* U+DC00..U+DFFF ranges, take the low 10 bits from each
|
977
|
-
* to make a 20-bit number, then add 0x10000 to get the
|
978
|
-
* final codepoint.
|
979
|
-
*
|
980
|
-
* See Unicode 15: 3.8 "Surrogates", 5.3 "Handling
|
981
|
-
* Surrogate Pairs in UTF-16", and 23.6 "Surrogates
|
982
|
-
* Area".
|
983
|
-
*/
|
984
|
-
if ((ch & 0xFC00) == 0xD800) {
|
985
|
-
pe++;
|
986
|
-
if (pe > stringEnd - 6) {
|
987
|
-
raise_parse_error("incomplete surrogate pair at '%s'", p);
|
988
|
-
}
|
989
|
-
if (pe[0] == '\\' && pe[1] == 'u') {
|
990
|
-
uint32_t sur = unescape_unicode((unsigned char *) pe + 2);
|
991
|
-
ch = (((ch & 0x3F) << 10) | ((((ch >> 6) & 0xF) + 1) << 16)
|
992
|
-
| (sur & 0x3FF));
|
993
|
-
pe += 5;
|
994
|
-
} else {
|
995
|
-
unescape = (char *) "?";
|
996
|
-
break;
|
997
|
-
}
|
998
|
-
}
|
999
|
-
unescape_len = convert_UTF32_to_UTF8(buf, ch);
|
1000
|
-
unescape = buf;
|
1001
|
-
}
|
1002
|
-
break;
|
1003
|
-
default:
|
1004
|
-
p = pe;
|
1005
|
-
continue;
|
1006
|
-
}
|
1007
|
-
MEMCPY(buffer, unescape, char, unescape_len);
|
1008
|
-
buffer += unescape_len;
|
1009
|
-
p = ++pe;
|
1010
|
-
} else {
|
1011
|
-
pe++;
|
1012
|
-
}
|
1013
|
-
}
|
1014
|
-
|
1015
|
-
if (pe > p) {
|
1016
|
-
MEMCPY(buffer, p, char, pe - p);
|
1017
|
-
buffer += pe - p;
|
1018
|
-
}
|
1019
|
-
rb_str_set_len(result, buffer - bufferStart);
|
1020
|
-
|
1021
|
-
if (symbolize) {
|
1022
|
-
result = rb_str_intern(result);
|
1023
|
-
} else if (intern) {
|
1024
|
-
result = rb_funcall(rb_str_freeze(result), i_uminus, 0);
|
1025
|
-
}
|
1026
|
-
|
1027
|
-
return result;
|
1028
|
-
}
|
1029
|
-
|
1030
|
-
%%{
|
1031
|
-
machine JSON_string;
|
1032
|
-
include JSON_common;
|
1033
|
-
|
1034
|
-
write data;
|
1035
|
-
|
1036
|
-
action parse_complex_string {
|
1037
|
-
*result = json_string_unescape(json, json->memo + 1, p, json->parsing_name, json->parsing_name || json-> freeze, json->parsing_name && json->symbolize_names);
|
1038
|
-
fexec p + 1;
|
1039
|
-
fhold;
|
1040
|
-
fbreak;
|
1041
|
-
}
|
1042
|
-
|
1043
|
-
action parse_simple_string {
|
1044
|
-
*result = json_string_fastpath(json, json->memo + 1, p, json->parsing_name, json->parsing_name || json-> freeze, json->parsing_name && json->symbolize_names);
|
1045
|
-
fexec p + 1;
|
1046
|
-
fhold;
|
1047
|
-
fbreak;
|
1048
|
-
}
|
1049
|
-
|
1050
|
-
double_quote = '"';
|
1051
|
-
escape = '\\';
|
1052
|
-
control = 0..0x1f;
|
1053
|
-
simple = any - escape - double_quote - control;
|
1054
|
-
|
1055
|
-
main := double_quote (
|
1056
|
-
(simple*)(
|
1057
|
-
(double_quote) @parse_simple_string |
|
1058
|
-
((^([\"\\] | control) | escape[\"\\/bfnrt] | '\\u'[0-9a-fA-F]{4} | escape^([\"\\/bfnrtu]|0..0x1f))* double_quote) @parse_complex_string
|
1059
|
-
)
|
1060
|
-
);
|
1061
|
-
}%%
|
1062
|
-
|
1063
|
-
static int
|
1064
|
-
match_i(VALUE regexp, VALUE klass, VALUE memo)
|
1065
|
-
{
|
1066
|
-
if (regexp == Qundef) return ST_STOP;
|
1067
|
-
if (RTEST(rb_funcall(klass, i_json_creatable_p, 0)) &&
|
1068
|
-
RTEST(rb_funcall(regexp, i_match, 1, rb_ary_entry(memo, 0)))) {
|
1069
|
-
rb_ary_push(memo, klass);
|
1070
|
-
return ST_STOP;
|
1071
|
-
}
|
1072
|
-
return ST_CONTINUE;
|
1073
|
-
}
|
1074
|
-
|
1075
|
-
static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
1076
|
-
{
|
1077
|
-
int cs = EVIL;
|
1078
|
-
VALUE match_string;
|
1079
|
-
|
1080
|
-
%% write init;
|
1081
|
-
json->memo = p;
|
1082
|
-
%% write exec;
|
1083
|
-
|
1084
|
-
if (json->create_additions && RTEST(match_string = json->match_string)) {
|
1085
|
-
VALUE klass;
|
1086
|
-
VALUE memo = rb_ary_new2(2);
|
1087
|
-
rb_ary_push(memo, *result);
|
1088
|
-
rb_hash_foreach(match_string, match_i, memo);
|
1089
|
-
klass = rb_ary_entry(memo, 1);
|
1090
|
-
if (RTEST(klass)) {
|
1091
|
-
*result = rb_funcall(klass, i_json_create, 1, *result);
|
1092
|
-
}
|
1093
|
-
}
|
1094
|
-
|
1095
|
-
if (cs >= JSON_string_first_final) {
|
1096
|
-
return p + 1;
|
1097
|
-
} else {
|
1098
|
-
return NULL;
|
1099
|
-
}
|
1100
|
-
}
|
1101
|
-
|
1102
|
-
/*
|
1103
|
-
* Document-class: JSON::Ext::Parser
|
1104
|
-
*
|
1105
|
-
* This is the JSON parser implemented as a C extension. It can be configured
|
1106
|
-
* to be used by setting
|
1107
|
-
*
|
1108
|
-
* JSON.parser = JSON::Ext::Parser
|
1109
|
-
*
|
1110
|
-
* with the method parser= in JSON.
|
1111
|
-
*
|
1112
|
-
*/
|
1113
|
-
|
1114
|
-
static VALUE convert_encoding(VALUE source)
|
1115
|
-
{
|
1116
|
-
int encindex = RB_ENCODING_GET(source);
|
1117
|
-
|
1118
|
-
if (RB_LIKELY(encindex == utf8_encindex)) {
|
1119
|
-
return source;
|
1120
|
-
}
|
1121
|
-
|
1122
|
-
if (encindex == binary_encindex) {
|
1123
|
-
// For historical reason, we silently reinterpret binary strings as UTF-8
|
1124
|
-
return rb_enc_associate_index(rb_str_dup(source), utf8_encindex);
|
1125
|
-
}
|
1126
|
-
|
1127
|
-
return rb_funcall(source, i_encode, 1, Encoding_UTF_8);
|
1128
|
-
}
|
1129
|
-
|
1130
|
-
static int configure_parser_i(VALUE key, VALUE val, VALUE data)
|
1131
|
-
{
|
1132
|
-
JSON_Parser *json = (JSON_Parser *)data;
|
1133
|
-
|
1134
|
-
if (key == sym_max_nesting) { json->max_nesting = RTEST(val) ? FIX2INT(val) : 0; }
|
1135
|
-
else if (key == sym_allow_nan) { json->allow_nan = RTEST(val); }
|
1136
|
-
else if (key == sym_allow_trailing_comma) { json->allow_trailing_comma = RTEST(val); }
|
1137
|
-
else if (key == sym_symbolize_names) { json->symbolize_names = RTEST(val); }
|
1138
|
-
else if (key == sym_freeze) { json->freeze = RTEST(val); }
|
1139
|
-
else if (key == sym_create_id) { json->create_id = RTEST(val) ? val : Qfalse; }
|
1140
|
-
else if (key == sym_object_class) { json->object_class = RTEST(val) ? val : Qfalse; }
|
1141
|
-
else if (key == sym_array_class) { json->array_class = RTEST(val) ? val : Qfalse; }
|
1142
|
-
else if (key == sym_decimal_class) { json->decimal_class = RTEST(val) ? val : Qfalse; }
|
1143
|
-
else if (key == sym_match_string) { json->match_string = RTEST(val) ? val : Qfalse; }
|
1144
|
-
else if (key == sym_create_additions) {
|
1145
|
-
if (NIL_P(val)) {
|
1146
|
-
json->create_additions = true;
|
1147
|
-
json->deprecated_create_additions = true;
|
1148
|
-
} else {
|
1149
|
-
json->create_additions = RTEST(val);
|
1150
|
-
json->deprecated_create_additions = false;
|
1151
|
-
}
|
1152
|
-
}
|
1153
|
-
|
1154
|
-
return ST_CONTINUE;
|
1155
|
-
}
|
1156
|
-
|
1157
|
-
static void parser_init(JSON_Parser *json, VALUE source, VALUE opts)
|
1158
|
-
{
|
1159
|
-
if (json->Vsource) {
|
1160
|
-
rb_raise(rb_eTypeError, "already initialized instance");
|
1161
|
-
}
|
1162
|
-
|
1163
|
-
json->fbuffer.initial_length = FBUFFER_INITIAL_LENGTH_DEFAULT;
|
1164
|
-
json->max_nesting = 100;
|
1165
|
-
|
1166
|
-
if (!NIL_P(opts)) {
|
1167
|
-
Check_Type(opts, T_HASH);
|
1168
|
-
if (RHASH_SIZE(opts) > 0) {
|
1169
|
-
// We assume in most cases few keys are set so it's faster to go over
|
1170
|
-
// the provided keys than to check all possible keys.
|
1171
|
-
rb_hash_foreach(opts, configure_parser_i, (VALUE)json);
|
1172
|
-
|
1173
|
-
if (json->symbolize_names && json->create_additions) {
|
1174
|
-
rb_raise(rb_eArgError,
|
1175
|
-
"options :symbolize_names and :create_additions cannot be "
|
1176
|
-
" used in conjunction");
|
1177
|
-
}
|
1178
|
-
|
1179
|
-
if (json->create_additions && !json->create_id) {
|
1180
|
-
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
1181
|
-
}
|
1182
|
-
}
|
1183
|
-
|
1184
|
-
}
|
1185
|
-
source = convert_encoding(StringValue(source));
|
1186
|
-
StringValue(source);
|
1187
|
-
json->len = RSTRING_LEN(source);
|
1188
|
-
json->source = RSTRING_PTR(source);
|
1189
|
-
json->Vsource = source;
|
1190
|
-
}
|
1191
|
-
|
1192
|
-
/*
|
1193
|
-
* call-seq: new(source, opts => {})
|
1194
|
-
*
|
1195
|
-
* Creates a new JSON::Ext::Parser instance for the string _source_.
|
1196
|
-
*
|
1197
|
-
* It will be configured by the _opts_ hash. _opts_ can have the following
|
1198
|
-
* keys:
|
1199
|
-
*
|
1200
|
-
* _opts_ can have the following keys:
|
1201
|
-
* * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
1202
|
-
* structures. Disable depth checking with :max_nesting => false|nil|0, it
|
1203
|
-
* defaults to 100.
|
1204
|
-
* * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
1205
|
-
* defiance of RFC 4627 to be parsed by the Parser. This option defaults to
|
1206
|
-
* false.
|
1207
|
-
* * *symbolize_names*: If set to true, returns symbols for the names
|
1208
|
-
* (keys) in a JSON object. Otherwise strings are returned, which is
|
1209
|
-
* also the default. It's not possible to use this option in
|
1210
|
-
* conjunction with the *create_additions* option.
|
1211
|
-
* * *create_additions*: If set to false, the Parser doesn't create
|
1212
|
-
* additions even if a matching class and create_id was found. This option
|
1213
|
-
* defaults to false.
|
1214
|
-
* * *object_class*: Defaults to Hash. If another type is provided, it will be used
|
1215
|
-
* instead of Hash to represent JSON objects. The type must respond to
|
1216
|
-
* +new+ without arguments, and return an object that respond to +[]=+.
|
1217
|
-
* * *array_class*: Defaults to Array If another type is provided, it will be used
|
1218
|
-
* instead of Hash to represent JSON arrays. The type must respond to
|
1219
|
-
* +new+ without arguments, and return an object that respond to +<<+.
|
1220
|
-
* * *decimal_class*: Specifies which class to use instead of the default
|
1221
|
-
* (Float) when parsing decimal numbers. This class must accept a single
|
1222
|
-
* string argument in its constructor.
|
1223
|
-
*/
|
1224
|
-
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
1225
|
-
{
|
1226
|
-
GET_PARSER_INIT;
|
1227
|
-
|
1228
|
-
rb_check_arity(argc, 1, 2);
|
1229
|
-
|
1230
|
-
parser_init(json, argv[0], argc == 2 ? argv[1] : Qnil);
|
1231
|
-
return self;
|
1232
|
-
}
|
1233
|
-
|
1234
|
-
%%{
|
1235
|
-
machine JSON;
|
1236
|
-
|
1237
|
-
write data;
|
1238
|
-
|
1239
|
-
include JSON_common;
|
1240
|
-
|
1241
|
-
action parse_value {
|
1242
|
-
char *np = JSON_parse_value(json, fpc, pe, &result, 0);
|
1243
|
-
if (np == NULL) { fhold; fbreak; } else fexec np;
|
1244
|
-
}
|
1245
|
-
|
1246
|
-
main := ignore* (
|
1247
|
-
begin_value >parse_value
|
1248
|
-
) ignore*;
|
1249
|
-
}%%
|
1250
|
-
|
1251
|
-
/*
|
1252
|
-
* call-seq: parse()
|
1253
|
-
*
|
1254
|
-
* Parses the current JSON text _source_ and returns the complete data
|
1255
|
-
* structure as a result.
|
1256
|
-
* It raises JSON::ParserError if fail to parse.
|
1257
|
-
*/
|
1258
|
-
static VALUE cParser_parse(VALUE self)
|
1259
|
-
{
|
1260
|
-
char *p, *pe;
|
1261
|
-
int cs = EVIL;
|
1262
|
-
VALUE result = Qnil;
|
1263
|
-
GET_PARSER;
|
1264
|
-
|
1265
|
-
char stack_buffer[FBUFFER_STACK_SIZE];
|
1266
|
-
fbuffer_stack_init(&json->fbuffer, FBUFFER_INITIAL_LENGTH_DEFAULT, stack_buffer, FBUFFER_STACK_SIZE);
|
1267
|
-
|
1268
|
-
VALUE rvalue_stack_buffer[RVALUE_STACK_INITIAL_CAPA];
|
1269
|
-
rvalue_stack stack = {
|
1270
|
-
.type = RVALUE_STACK_STACK_ALLOCATED,
|
1271
|
-
.ptr = rvalue_stack_buffer,
|
1272
|
-
.capa = RVALUE_STACK_INITIAL_CAPA,
|
1273
|
-
};
|
1274
|
-
json->stack = &stack;
|
1275
|
-
|
1276
|
-
%% write init;
|
1277
|
-
p = json->source;
|
1278
|
-
pe = p + json->len;
|
1279
|
-
%% write exec;
|
1280
|
-
|
1281
|
-
if (json->stack_handle) {
|
1282
|
-
rvalue_stack_eagerly_release(json->stack_handle);
|
1283
|
-
}
|
1284
|
-
|
1285
|
-
if (cs >= JSON_first_final && p == pe) {
|
1286
|
-
return result;
|
1287
|
-
} else {
|
1288
|
-
raise_parse_error("unexpected token at '%s'", p);
|
1289
|
-
return Qnil;
|
1290
|
-
}
|
1291
|
-
}
|
1292
|
-
|
1293
|
-
static VALUE cParser_m_parse(VALUE klass, VALUE source, VALUE opts)
|
1294
|
-
{
|
1295
|
-
char *p, *pe;
|
1296
|
-
int cs = EVIL;
|
1297
|
-
VALUE result = Qnil;
|
1298
|
-
|
1299
|
-
JSON_Parser _parser = {0};
|
1300
|
-
JSON_Parser *json = &_parser;
|
1301
|
-
parser_init(json, source, opts);
|
1302
|
-
|
1303
|
-
char stack_buffer[FBUFFER_STACK_SIZE];
|
1304
|
-
fbuffer_stack_init(&json->fbuffer, FBUFFER_INITIAL_LENGTH_DEFAULT, stack_buffer, FBUFFER_STACK_SIZE);
|
1305
|
-
|
1306
|
-
VALUE rvalue_stack_buffer[RVALUE_STACK_INITIAL_CAPA];
|
1307
|
-
rvalue_stack stack = {
|
1308
|
-
.type = RVALUE_STACK_STACK_ALLOCATED,
|
1309
|
-
.ptr = rvalue_stack_buffer,
|
1310
|
-
.capa = RVALUE_STACK_INITIAL_CAPA,
|
1311
|
-
};
|
1312
|
-
json->stack = &stack;
|
1313
|
-
|
1314
|
-
%% write init;
|
1315
|
-
p = json->source;
|
1316
|
-
pe = p + json->len;
|
1317
|
-
%% write exec;
|
1318
|
-
|
1319
|
-
if (json->stack_handle) {
|
1320
|
-
rvalue_stack_eagerly_release(json->stack_handle);
|
1321
|
-
}
|
1322
|
-
|
1323
|
-
if (cs >= JSON_first_final && p == pe) {
|
1324
|
-
return result;
|
1325
|
-
} else {
|
1326
|
-
raise_parse_error("unexpected token at '%s'", p);
|
1327
|
-
return Qnil;
|
1328
|
-
}
|
1329
|
-
}
|
1330
|
-
|
1331
|
-
static void JSON_mark(void *ptr)
|
1332
|
-
{
|
1333
|
-
JSON_Parser *json = ptr;
|
1334
|
-
rb_gc_mark(json->Vsource);
|
1335
|
-
rb_gc_mark(json->create_id);
|
1336
|
-
rb_gc_mark(json->object_class);
|
1337
|
-
rb_gc_mark(json->array_class);
|
1338
|
-
rb_gc_mark(json->decimal_class);
|
1339
|
-
rb_gc_mark(json->match_string);
|
1340
|
-
rb_gc_mark(json->stack_handle);
|
1341
|
-
|
1342
|
-
long index;
|
1343
|
-
for (index = 0; index < json->name_cache.length; index++) {
|
1344
|
-
rb_gc_mark(json->name_cache.entries[index]);
|
1345
|
-
}
|
1346
|
-
}
|
1347
|
-
|
1348
|
-
static void JSON_free(void *ptr)
|
1349
|
-
{
|
1350
|
-
JSON_Parser *json = ptr;
|
1351
|
-
fbuffer_free(&json->fbuffer);
|
1352
|
-
ruby_xfree(json);
|
1353
|
-
}
|
1354
|
-
|
1355
|
-
static size_t JSON_memsize(const void *ptr)
|
1356
|
-
{
|
1357
|
-
const JSON_Parser *json = ptr;
|
1358
|
-
return sizeof(*json) + FBUFFER_CAPA(&json->fbuffer);
|
1359
|
-
}
|
1360
|
-
|
1361
|
-
static const rb_data_type_t JSON_Parser_type = {
|
1362
|
-
"JSON/Parser",
|
1363
|
-
{JSON_mark, JSON_free, JSON_memsize,},
|
1364
|
-
0, 0,
|
1365
|
-
RUBY_TYPED_FREE_IMMEDIATELY,
|
1366
|
-
};
|
1367
|
-
|
1368
|
-
static VALUE cJSON_parser_s_allocate(VALUE klass)
|
1369
|
-
{
|
1370
|
-
JSON_Parser *json;
|
1371
|
-
VALUE obj = TypedData_Make_Struct(klass, JSON_Parser, &JSON_Parser_type, json);
|
1372
|
-
fbuffer_stack_init(&json->fbuffer, 0, NULL, 0);
|
1373
|
-
return obj;
|
1374
|
-
}
|
1375
|
-
|
1376
|
-
/*
|
1377
|
-
* call-seq: source()
|
1378
|
-
*
|
1379
|
-
* Returns a copy of the current _source_ string, that was used to construct
|
1380
|
-
* this Parser.
|
1381
|
-
*/
|
1382
|
-
static VALUE cParser_source(VALUE self)
|
1383
|
-
{
|
1384
|
-
GET_PARSER;
|
1385
|
-
return rb_str_dup(json->Vsource);
|
1386
|
-
}
|
1387
|
-
|
1388
|
-
void Init_parser(void)
|
1389
|
-
{
|
1390
|
-
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
1391
|
-
rb_ext_ractor_safe(true);
|
1392
|
-
#endif
|
1393
|
-
|
1394
|
-
#undef rb_intern
|
1395
|
-
rb_require("json/common");
|
1396
|
-
mJSON = rb_define_module("JSON");
|
1397
|
-
mExt = rb_define_module_under(mJSON, "Ext");
|
1398
|
-
cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
|
1399
|
-
eNestingError = rb_path2class("JSON::NestingError");
|
1400
|
-
rb_gc_register_mark_object(eNestingError);
|
1401
|
-
rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
|
1402
|
-
rb_define_method(cParser, "initialize", cParser_initialize, -1);
|
1403
|
-
rb_define_method(cParser, "parse", cParser_parse, 0);
|
1404
|
-
rb_define_method(cParser, "source", cParser_source, 0);
|
1405
|
-
|
1406
|
-
rb_define_singleton_method(cParser, "parse", cParser_m_parse, 2);
|
1407
|
-
|
1408
|
-
CNaN = rb_const_get(mJSON, rb_intern("NaN"));
|
1409
|
-
rb_gc_register_mark_object(CNaN);
|
1410
|
-
|
1411
|
-
CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
|
1412
|
-
rb_gc_register_mark_object(CInfinity);
|
1413
|
-
|
1414
|
-
CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
|
1415
|
-
rb_gc_register_mark_object(CMinusInfinity);
|
1416
|
-
|
1417
|
-
rb_global_variable(&Encoding_UTF_8);
|
1418
|
-
Encoding_UTF_8 = rb_const_get(rb_path2class("Encoding"), rb_intern("UTF_8"));
|
1419
|
-
|
1420
|
-
sym_max_nesting = ID2SYM(rb_intern("max_nesting"));
|
1421
|
-
sym_allow_nan = ID2SYM(rb_intern("allow_nan"));
|
1422
|
-
sym_allow_trailing_comma = ID2SYM(rb_intern("allow_trailing_comma"));
|
1423
|
-
sym_symbolize_names = ID2SYM(rb_intern("symbolize_names"));
|
1424
|
-
sym_freeze = ID2SYM(rb_intern("freeze"));
|
1425
|
-
sym_create_additions = ID2SYM(rb_intern("create_additions"));
|
1426
|
-
sym_create_id = ID2SYM(rb_intern("create_id"));
|
1427
|
-
sym_object_class = ID2SYM(rb_intern("object_class"));
|
1428
|
-
sym_array_class = ID2SYM(rb_intern("array_class"));
|
1429
|
-
sym_decimal_class = ID2SYM(rb_intern("decimal_class"));
|
1430
|
-
sym_match_string = ID2SYM(rb_intern("match_string"));
|
1431
|
-
|
1432
|
-
i_create_id = rb_intern("create_id");
|
1433
|
-
i_json_creatable_p = rb_intern("json_creatable?");
|
1434
|
-
i_json_create = rb_intern("json_create");
|
1435
|
-
i_chr = rb_intern("chr");
|
1436
|
-
i_match = rb_intern("match");
|
1437
|
-
i_deep_const_get = rb_intern("deep_const_get");
|
1438
|
-
i_aset = rb_intern("[]=");
|
1439
|
-
i_aref = rb_intern("[]");
|
1440
|
-
i_leftshift = rb_intern("<<");
|
1441
|
-
i_new = rb_intern("new");
|
1442
|
-
i_try_convert = rb_intern("try_convert");
|
1443
|
-
i_uminus = rb_intern("-@");
|
1444
|
-
i_encode = rb_intern("encode");
|
1445
|
-
|
1446
|
-
binary_encindex = rb_ascii8bit_encindex();
|
1447
|
-
utf8_encindex = rb_utf8_encindex();
|
1448
|
-
enc_utf8 = rb_utf8_encoding();
|
1449
|
-
}
|
1450
|
-
|
1451
|
-
/*
|
1452
|
-
* Local variables:
|
1453
|
-
* mode: c
|
1454
|
-
* c-file-style: ruby
|
1455
|
-
* indent-tabs-mode: nil
|
1456
|
-
* End:
|
1457
|
-
*/
|