json 2.7.2 → 2.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/BSDL +22 -0
- data/CHANGES.md +50 -17
- data/LEGAL +60 -0
- data/README.md +13 -165
- data/ext/json/ext/fbuffer/fbuffer.h +21 -62
- data/ext/json/ext/generator/extconf.rb +8 -2
- data/ext/json/ext/generator/generator.c +497 -668
- data/ext/json/ext/generator/generator.h +16 -75
- data/ext/json/ext/parser/extconf.rb +3 -1
- data/ext/json/ext/parser/parser.c +279 -253
- data/ext/json/ext/parser/parser.h +4 -40
- data/ext/json/ext/parser/parser.rl +208 -182
- data/json.gemspec +42 -49
- data/lib/json/add/bigdecimal.rb +1 -1
- data/lib/json/add/complex.rb +1 -1
- data/lib/json/add/core.rb +1 -1
- data/lib/json/add/date.rb +1 -1
- data/lib/json/add/date_time.rb +1 -1
- data/lib/json/add/exception.rb +1 -1
- data/lib/json/add/ostruct.rb +1 -1
- data/lib/json/add/range.rb +1 -1
- data/lib/json/add/rational.rb +1 -1
- data/lib/json/add/regexp.rb +1 -1
- data/lib/json/add/struct.rb +1 -1
- data/lib/json/add/symbol.rb +1 -2
- data/lib/json/add/time.rb +3 -10
- data/lib/json/common.rb +79 -43
- data/lib/json/ext/generator/state.rb +135 -0
- data/lib/json/ext.rb +15 -5
- data/lib/json/generic_object.rb +1 -1
- data/lib/json/pure/generator.rb +96 -29
- data/lib/json/pure/parser.rb +27 -33
- data/lib/json/pure.rb +1 -0
- data/lib/json/version.rb +3 -7
- data/lib/json.rb +1 -1
- metadata +17 -15
- data/ext/json/ext/generator/depend +0 -1
- data/ext/json/ext/parser/depend +0 -1
- data/ext/json/extconf.rb +0 -3
- /data/{LICENSE → COPYING} +0 -0
@@ -6,51 +6,23 @@
|
|
6
6
|
|
7
7
|
#include "ruby.h"
|
8
8
|
|
9
|
-
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
|
15
|
-
#
|
16
|
-
#
|
9
|
+
/* This is the fallback definition from Ruby 3.4 */
|
10
|
+
#ifndef RBIMPL_STDBOOL_H
|
11
|
+
#if defined(__cplusplus)
|
12
|
+
# if defined(HAVE_STDBOOL_H) && (__cplusplus >= 201103L)
|
13
|
+
# include <cstdbool>
|
14
|
+
# endif
|
15
|
+
#elif defined(HAVE_STDBOOL_H)
|
16
|
+
# include <stdbool.h>
|
17
|
+
#elif !defined(HAVE__BOOL)
|
18
|
+
typedef unsigned char _Bool;
|
19
|
+
# define bool _Bool
|
20
|
+
# define true ((_Bool)+1)
|
21
|
+
# define false ((_Bool)+0)
|
22
|
+
# define __bool_true_false_are_defined
|
17
23
|
#endif
|
18
|
-
|
19
|
-
#ifndef rb_obj_instance_variables
|
20
|
-
#define rb_obj_instance_variables(object) rb_funcall(object, rb_intern("instance_variables"), 0)
|
21
24
|
#endif
|
22
25
|
|
23
|
-
#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
|
24
|
-
|
25
|
-
/* unicode definitions */
|
26
|
-
|
27
|
-
#define UNI_STRICT_CONVERSION 1
|
28
|
-
|
29
|
-
typedef unsigned long UTF32; /* at least 32 bits */
|
30
|
-
typedef unsigned short UTF16; /* at least 16 bits */
|
31
|
-
typedef unsigned char UTF8; /* typically 8 bits */
|
32
|
-
|
33
|
-
#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
|
34
|
-
#define UNI_MAX_BMP (UTF32)0x0000FFFF
|
35
|
-
#define UNI_MAX_UTF16 (UTF32)0x0010FFFF
|
36
|
-
#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
|
37
|
-
#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
|
38
|
-
|
39
|
-
#define UNI_SUR_HIGH_START (UTF32)0xD800
|
40
|
-
#define UNI_SUR_HIGH_END (UTF32)0xDBFF
|
41
|
-
#define UNI_SUR_LOW_START (UTF32)0xDC00
|
42
|
-
#define UNI_SUR_LOW_END (UTF32)0xDFFF
|
43
|
-
|
44
|
-
static const int halfShift = 10; /* used for shifting by 10 bits */
|
45
|
-
|
46
|
-
static const UTF32 halfBase = 0x0010000UL;
|
47
|
-
static const UTF32 halfMask = 0x3FFUL;
|
48
|
-
|
49
|
-
static unsigned char isLegalUTF8(const UTF8 *source, unsigned long length);
|
50
|
-
static void unicode_escape(char *buf, UTF16 character);
|
51
|
-
static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
|
52
|
-
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char script_safe);
|
53
|
-
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char script_safe);
|
54
26
|
static char *fstrndup(const char *ptr, unsigned long len);
|
55
27
|
|
56
28
|
/* ruby api and some helpers */
|
@@ -66,9 +38,6 @@ typedef struct JSON_Generator_StateStruct {
|
|
66
38
|
long object_nl_len;
|
67
39
|
char *array_nl;
|
68
40
|
long array_nl_len;
|
69
|
-
FBuffer *array_delim;
|
70
|
-
FBuffer *object_delim;
|
71
|
-
FBuffer *object_delim2;
|
72
41
|
long max_nesting;
|
73
42
|
char allow_nan;
|
74
43
|
char ascii_only;
|
@@ -85,17 +54,6 @@ typedef struct JSON_Generator_StateStruct {
|
|
85
54
|
JSON_Generator_State *state; \
|
86
55
|
GET_STATE_TO(self, state)
|
87
56
|
|
88
|
-
#define GENERATE_JSON(type) \
|
89
|
-
FBuffer *buffer; \
|
90
|
-
VALUE Vstate; \
|
91
|
-
JSON_Generator_State *state; \
|
92
|
-
\
|
93
|
-
rb_scan_args(argc, argv, "01", &Vstate); \
|
94
|
-
Vstate = cState_from_state_s(cState, Vstate); \
|
95
|
-
TypedData_Get_Struct(Vstate, JSON_Generator_State, &JSON_Generator_State_type, state); \
|
96
|
-
buffer = cState_prepare_buffer(Vstate); \
|
97
|
-
generate_json_##type(buffer, Vstate, state, self); \
|
98
|
-
return fbuffer_to_s(buffer)
|
99
57
|
|
100
58
|
static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);
|
101
59
|
static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self);
|
@@ -117,8 +75,6 @@ static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self);
|
|
117
75
|
static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self);
|
118
76
|
static void State_free(void *state);
|
119
77
|
static VALUE cState_s_allocate(VALUE klass);
|
120
|
-
static VALUE cState_configure(VALUE self, VALUE opts);
|
121
|
-
static VALUE cState_to_h(VALUE self);
|
122
78
|
static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
123
79
|
static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
124
80
|
static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
@@ -132,9 +88,8 @@ static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_
|
|
132
88
|
static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
133
89
|
static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
134
90
|
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
135
|
-
static VALUE cState_partial_generate(VALUE self, VALUE obj);
|
91
|
+
static VALUE cState_partial_generate(VALUE self, VALUE obj, void (*func)(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj));
|
136
92
|
static VALUE cState_generate(VALUE self, VALUE obj);
|
137
|
-
static VALUE cState_initialize(int argc, VALUE *argv, VALUE self);
|
138
93
|
static VALUE cState_from_state_s(VALUE self, VALUE opts);
|
139
94
|
static VALUE cState_indent(VALUE self);
|
140
95
|
static VALUE cState_indent_set(VALUE self, VALUE indent);
|
@@ -157,21 +112,7 @@ static VALUE cState_script_safe_set(VALUE self, VALUE depth);
|
|
157
112
|
static VALUE cState_strict(VALUE self);
|
158
113
|
static VALUE cState_strict_set(VALUE self, VALUE strict);
|
159
114
|
static FBuffer *cState_prepare_buffer(VALUE self);
|
160
|
-
|
161
|
-
#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
|
162
|
-
static inline void *ruby_zalloc(size_t n)
|
163
|
-
{
|
164
|
-
void *p = ruby_xmalloc(n);
|
165
|
-
memset(p, 0, n);
|
166
|
-
return p;
|
167
|
-
}
|
168
|
-
#endif
|
169
|
-
#ifdef TypedData_Make_Struct
|
115
|
+
|
170
116
|
static const rb_data_type_t JSON_Generator_State_type;
|
171
|
-
#define NEW_TYPEDDATA_WRAPPER 1
|
172
|
-
#else
|
173
|
-
#define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, State_free, json)
|
174
|
-
#define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json)
|
175
|
-
#endif
|
176
117
|
|
177
118
|
#endif
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
require 'mkmf'
|
3
3
|
|
4
4
|
have_func("rb_enc_raise", "ruby.h")
|
@@ -29,4 +29,6 @@ rescue NoMethodError
|
|
29
29
|
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
|
30
30
|
end
|
31
31
|
|
32
|
+
append_cflags("-std=c99")
|
33
|
+
|
32
34
|
create_makefile 'json/ext/parser'
|