oj 3.13.23 → 3.16.9
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/CHANGELOG.md +81 -0
 - data/README.md +2 -2
 - data/ext/oj/buf.h +7 -6
 - data/ext/oj/cache.c +29 -26
 - data/ext/oj/cache.h +3 -2
 - data/ext/oj/cache8.c +10 -9
 - data/ext/oj/circarray.c +7 -5
 - data/ext/oj/circarray.h +2 -2
 - data/ext/oj/code.c +5 -12
 - data/ext/oj/code.h +2 -2
 - data/ext/oj/compat.c +20 -60
 - data/ext/oj/custom.c +26 -59
 - data/ext/oj/debug.c +3 -9
 - data/ext/oj/dump.c +103 -53
 - data/ext/oj/dump.h +1 -4
 - data/ext/oj/dump_compat.c +557 -592
 - data/ext/oj/dump_leaf.c +3 -5
 - data/ext/oj/dump_object.c +42 -48
 - data/ext/oj/dump_strict.c +10 -22
 - data/ext/oj/encoder.c +1 -1
 - data/ext/oj/err.c +2 -13
 - data/ext/oj/err.h +9 -12
 - data/ext/oj/extconf.rb +16 -7
 - data/ext/oj/fast.c +60 -92
 - data/ext/oj/intern.c +62 -47
 - data/ext/oj/intern.h +3 -7
 - data/ext/oj/mem.c +318 -0
 - data/ext/oj/mem.h +53 -0
 - data/ext/oj/mimic_json.c +51 -32
 - data/ext/oj/object.c +33 -43
 - data/ext/oj/odd.c +8 -6
 - data/ext/oj/odd.h +4 -4
 - data/ext/oj/oj.c +243 -212
 - data/ext/oj/oj.h +83 -81
 - data/ext/oj/parse.c +94 -148
 - data/ext/oj/parse.h +21 -24
 - data/ext/oj/parser.c +80 -67
 - data/ext/oj/parser.h +7 -8
 - data/ext/oj/rails.c +70 -92
 - data/ext/oj/reader.c +9 -14
 - data/ext/oj/reader.h +4 -2
 - data/ext/oj/resolve.c +3 -4
 - data/ext/oj/rxclass.c +6 -5
 - data/ext/oj/rxclass.h +1 -1
 - data/ext/oj/saj.c +10 -9
 - data/ext/oj/saj2.c +37 -49
 - data/ext/oj/saj2.h +1 -1
 - data/ext/oj/scp.c +3 -14
 - data/ext/oj/sparse.c +22 -70
 - data/ext/oj/stream_writer.c +45 -41
 - data/ext/oj/strict.c +20 -52
 - data/ext/oj/string_writer.c +64 -38
 - data/ext/oj/trace.h +31 -4
 - data/ext/oj/usual.c +125 -114
 - data/ext/oj/usual.h +7 -6
 - data/ext/oj/util.h +1 -1
 - data/ext/oj/val_stack.c +13 -2
 - data/ext/oj/val_stack.h +8 -7
 - data/ext/oj/wab.c +25 -57
 - data/lib/oj/active_support_helper.rb +1 -3
 - data/lib/oj/bag.rb +7 -1
 - data/lib/oj/easy_hash.rb +4 -5
 - data/lib/oj/error.rb +0 -1
 - data/lib/oj/json.rb +162 -150
 - data/lib/oj/mimic.rb +7 -7
 - data/lib/oj/schandler.rb +5 -4
 - data/lib/oj/state.rb +8 -5
 - data/lib/oj/version.rb +1 -2
 - data/lib/oj.rb +2 -0
 - data/pages/InstallOptions.md +20 -0
 - data/pages/Options.md +4 -0
 - data/test/_test_active.rb +8 -9
 - data/test/_test_active_mimic.rb +7 -8
 - data/test/_test_mimic_rails.rb +17 -20
 - data/test/activerecord/result_test.rb +5 -6
 - data/test/activesupport6/encoding_test.rb +63 -28
 - data/test/activesupport7/abstract_unit.rb +4 -1
 - data/test/activesupport7/encoding_test.rb +72 -22
 - data/test/files.rb +15 -15
 - data/test/foo.rb +18 -69
 - data/test/helper.rb +5 -8
 - data/test/isolated/shared.rb +3 -2
 - data/test/json_gem/json_addition_test.rb +2 -2
 - data/test/json_gem/json_common_interface_test.rb +8 -6
 - data/test/json_gem/json_encoding_test.rb +0 -0
 - data/test/json_gem/json_ext_parser_test.rb +1 -0
 - data/test/json_gem/json_fixtures_test.rb +3 -2
 - data/test/json_gem/json_generator_test.rb +50 -33
 - data/test/json_gem/json_generic_object_test.rb +11 -11
 - data/test/json_gem/json_parser_test.rb +46 -46
 - data/test/json_gem/json_string_matching_test.rb +9 -9
 - data/test/mem.rb +13 -12
 - data/test/perf.rb +21 -26
 - data/test/perf_compat.rb +31 -33
 - data/test/perf_dump.rb +28 -28
 - data/test/perf_fast.rb +80 -82
 - data/test/perf_file.rb +27 -29
 - data/test/perf_object.rb +65 -69
 - data/test/perf_once.rb +12 -11
 - data/test/perf_parser.rb +42 -48
 - data/test/perf_saj.rb +46 -54
 - data/test/perf_scp.rb +57 -69
 - data/test/perf_simple.rb +41 -39
 - data/test/perf_strict.rb +68 -70
 - data/test/perf_wab.rb +67 -69
 - data/test/prec.rb +5 -5
 - data/test/sample/change.rb +0 -1
 - data/test/sample/dir.rb +0 -1
 - data/test/sample/doc.rb +0 -1
 - data/test/sample/file.rb +0 -1
 - data/test/sample/group.rb +0 -1
 - data/test/sample/hasprops.rb +0 -1
 - data/test/sample/layer.rb +0 -1
 - data/test/sample/rect.rb +0 -1
 - data/test/sample/shape.rb +0 -1
 - data/test/sample/text.rb +0 -1
 - data/test/sample.rb +16 -16
 - data/test/sample_json.rb +8 -8
 - data/test/test_compat.rb +81 -54
 - data/test/test_custom.rb +63 -52
 - data/test/test_debian.rb +7 -10
 - data/test/test_fast.rb +86 -90
 - data/test/test_file.rb +24 -29
 - data/test/test_gc.rb +5 -5
 - data/test/test_generate.rb +5 -5
 - data/test/test_hash.rb +4 -4
 - data/test/test_integer_range.rb +9 -9
 - data/test/test_null.rb +20 -20
 - data/test/test_object.rb +92 -87
 - data/test/test_parser.rb +4 -4
 - data/test/test_parser_debug.rb +5 -5
 - data/test/test_parser_saj.rb +27 -25
 - data/test/test_parser_usual.rb +44 -6
 - data/test/test_rails.rb +2 -2
 - data/test/test_saj.rb +10 -8
 - data/test/test_scp.rb +35 -35
 - data/test/test_strict.rb +38 -32
 - data/test/test_various.rb +146 -97
 - data/test/test_wab.rb +46 -44
 - data/test/test_writer.rb +63 -47
 - data/test/tests.rb +7 -7
 - data/test/tests_mimic.rb +6 -6
 - data/test/tests_mimic_addition.rb +6 -6
 - metadata +46 -26
 - data/test/activesupport4/decoding_test.rb +0 -108
 - data/test/activesupport4/encoding_test.rb +0 -531
 - data/test/activesupport4/test_helper.rb +0 -41
 - data/test/activesupport5/abstract_unit.rb +0 -45
 - data/test/activesupport5/decoding_test.rb +0 -133
 - data/test/activesupport5/encoding_test.rb +0 -500
 - data/test/activesupport5/encoding_test_cases.rb +0 -98
 - data/test/activesupport5/test_helper.rb +0 -72
 - data/test/activesupport5/time_zone_test_helpers.rb +0 -39
 - data/test/bar.rb +0 -11
 - data/test/baz.rb +0 -16
 - data/test/bug.rb +0 -16
 - data/test/zoo.rb +0 -13
 
    
        data/ext/oj/parser.c
    CHANGED
    
    | 
         @@ -20,7 +20,7 @@ 
     | 
|
| 
       20 
20 
     | 
    
         
             
            #define FRAC_LIMIT 10000000000000000ULL
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
            // Give better performance with indented JSON but worse with unindented.
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
      
 23 
     | 
    
         
            +
            // #define SPACE_JUMP
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
            enum {
         
     | 
| 
       26 
26 
     | 
    
         
             
                SKIP_CHAR        = 'a',
         
     | 
| 
         @@ -1114,9 +1114,6 @@ static void parse(ojParser p, const byte *json) { 
     | 
|
| 
       1114 
1114 
     | 
    
         
             
                        p->map = trail_map;
         
     | 
| 
       1115 
1115 
     | 
    
         
             
                    }
         
     | 
| 
       1116 
1116 
     | 
    
         
             
                }
         
     | 
| 
       1117 
     | 
    
         
            -
                if (0 < p->depth) {
         
     | 
| 
       1118 
     | 
    
         
            -
                    parse_error(p, "parse error, not closed");
         
     | 
| 
       1119 
     | 
    
         
            -
                }
         
     | 
| 
       1120 
1117 
     | 
    
         
             
                if (0 == p->depth) {
         
     | 
| 
       1121 
1118 
     | 
    
         
             
                    switch (p->map[256]) {
         
     | 
| 
       1122 
1119 
     | 
    
         
             
                    case '0':
         
     | 
| 
         @@ -1148,7 +1145,7 @@ static void parser_free(void *ptr) { 
     | 
|
| 
       1148 
1145 
     | 
    
         
             
                if (NULL != p->free) {
         
     | 
| 
       1149 
1146 
     | 
    
         
             
                    p->free(p);
         
     | 
| 
       1150 
1147 
     | 
    
         
             
                }
         
     | 
| 
       1151 
     | 
    
         
            -
                 
     | 
| 
      
 1148 
     | 
    
         
            +
                OJ_R_FREE(ptr);
         
     | 
| 
       1152 
1149 
     | 
    
         
             
            }
         
     | 
| 
       1153 
1150 
     | 
    
         | 
| 
       1154 
1151 
     | 
    
         
             
            static void parser_mark(void *ptr) {
         
     | 
| 
         @@ -1164,6 +1161,17 @@ static void parser_mark(void *ptr) { 
     | 
|
| 
       1164 
1161 
     | 
    
         
             
                }
         
     | 
| 
       1165 
1162 
     | 
    
         
             
            }
         
     | 
| 
       1166 
1163 
     | 
    
         | 
| 
      
 1164 
     | 
    
         
            +
            static const rb_data_type_t oj_parser_type = {
         
     | 
| 
      
 1165 
     | 
    
         
            +
                "Oj/parser",
         
     | 
| 
      
 1166 
     | 
    
         
            +
                {
         
     | 
| 
      
 1167 
     | 
    
         
            +
                    parser_mark,
         
     | 
| 
      
 1168 
     | 
    
         
            +
                    parser_free,
         
     | 
| 
      
 1169 
     | 
    
         
            +
                    NULL,
         
     | 
| 
      
 1170 
     | 
    
         
            +
                },
         
     | 
| 
      
 1171 
     | 
    
         
            +
                0,
         
     | 
| 
      
 1172 
     | 
    
         
            +
                0,
         
     | 
| 
      
 1173 
     | 
    
         
            +
            };
         
     | 
| 
      
 1174 
     | 
    
         
            +
             
     | 
| 
       1167 
1175 
     | 
    
         
             
            extern void oj_set_parser_validator(ojParser p);
         
     | 
| 
       1168 
1176 
     | 
    
         
             
            extern void oj_set_parser_saj(ojParser p);
         
     | 
| 
       1169 
1177 
     | 
    
         
             
            extern void oj_set_parser_usual(ojParser p);
         
     | 
| 
         @@ -1180,7 +1188,7 @@ static int opt_cb(VALUE rkey, VALUE value, VALUE ptr) { 
     | 
|
| 
       1180 
1188 
     | 
    
         
             
                    rkey = rb_sym2str(rkey);
         
     | 
| 
       1181 
1189 
     | 
    
         
             
                    // fall through
         
     | 
| 
       1182 
1190 
     | 
    
         
             
                case RUBY_T_STRING:
         
     | 
| 
       1183 
     | 
    
         
            -
                    key  =  
     | 
| 
      
 1191 
     | 
    
         
            +
                    key  = StringValuePtr(rkey);
         
     | 
| 
       1184 
1192 
     | 
    
         
             
                    klen = RSTRING_LEN(rkey);
         
     | 
| 
       1185 
1193 
     | 
    
         
             
                    break;
         
     | 
| 
       1186 
1194 
     | 
    
         
             
                default: rb_raise(rb_eArgError, "option keys must be a symbol or string");
         
     | 
| 
         @@ -1205,7 +1213,7 @@ static int opt_cb(VALUE rkey, VALUE value, VALUE ptr) { 
     | 
|
| 
       1205 
1213 
     | 
    
         
             
             * Oj::Parser.new(:usual, cache_keys: true).
         
     | 
| 
       1206 
1214 
     | 
    
         
             
             */
         
     | 
| 
       1207 
1215 
     | 
    
         
             
            static VALUE parser_new(int argc, VALUE *argv, VALUE self) {
         
     | 
| 
       1208 
     | 
    
         
            -
                ojParser p =  
     | 
| 
      
 1216 
     | 
    
         
            +
                ojParser p = OJ_R_ALLOC(struct _ojParser);
         
     | 
| 
       1209 
1217 
     | 
    
         | 
| 
       1210 
1218 
     | 
    
         
             
            #if HAVE_RB_EXT_RACTOR_SAFE
         
     | 
| 
       1211 
1219 
     | 
    
         
             
                // This doesn't seem to do anything.
         
     | 
| 
         @@ -1255,7 +1263,7 @@ static VALUE parser_new(int argc, VALUE *argv, VALUE self) { 
     | 
|
| 
       1255 
1263 
     | 
    
         
             
                        rb_hash_foreach(ropts, opt_cb, (VALUE)p);
         
     | 
| 
       1256 
1264 
     | 
    
         
             
                    }
         
     | 
| 
       1257 
1265 
     | 
    
         
             
                }
         
     | 
| 
       1258 
     | 
    
         
            -
                return  
     | 
| 
      
 1266 
     | 
    
         
            +
                return TypedData_Wrap_Struct(parser_class, &oj_parser_type, p);
         
     | 
| 
       1259 
1267 
     | 
    
         
             
            }
         
     | 
| 
       1260 
1268 
     | 
    
         | 
| 
       1261 
1269 
     | 
    
         
             
            // Create a new parser without setting the delegate. The parser is
         
     | 
| 
         @@ -1263,8 +1271,8 @@ static VALUE parser_new(int argc, VALUE *argv, VALUE self) { 
     | 
|
| 
       1263 
1271 
     | 
    
         
             
            // from this function. A delegate must be added before the parser can be
         
     | 
| 
       1264 
1272 
     | 
    
         
             
            // used. Optionally oj_parser_set_options can be called if the options are not
         
     | 
| 
       1265 
1273 
     | 
    
         
             
            // set directly.
         
     | 
| 
       1266 
     | 
    
         
            -
            VALUE oj_parser_new() {
         
     | 
| 
       1267 
     | 
    
         
            -
                ojParser p =  
     | 
| 
      
 1274 
     | 
    
         
            +
            VALUE oj_parser_new(void) {
         
     | 
| 
      
 1275 
     | 
    
         
            +
                ojParser p = OJ_R_ALLOC(struct _ojParser);
         
     | 
| 
       1268 
1276 
     | 
    
         | 
| 
       1269 
1277 
     | 
    
         
             
            #if HAVE_RB_EXT_RACTOR_SAFE
         
     | 
| 
       1270 
1278 
     | 
    
         
             
                // This doesn't seem to do anything.
         
     | 
| 
         @@ -1275,7 +1283,7 @@ VALUE oj_parser_new() { 
     | 
|
| 
       1275 
1283 
     | 
    
         
             
                buf_init(&p->buf);
         
     | 
| 
       1276 
1284 
     | 
    
         
             
                p->map = value_map;
         
     | 
| 
       1277 
1285 
     | 
    
         | 
| 
       1278 
     | 
    
         
            -
                return  
     | 
| 
      
 1286 
     | 
    
         
            +
                return TypedData_Wrap_Struct(parser_class, &oj_parser_type, p);
         
     | 
| 
       1279 
1287 
     | 
    
         
             
            }
         
     | 
| 
       1280 
1288 
     | 
    
         | 
| 
       1281 
1289 
     | 
    
         
             
            // Set set the options from a hash (ropts).
         
     | 
| 
         @@ -1294,53 +1302,41 @@ void oj_parser_set_option(ojParser p, VALUE ropts) { 
     | 
|
| 
       1294 
1302 
     | 
    
         
             
             *   - no options
         
     | 
| 
       1295 
1303 
     | 
    
         
             
             *
         
     | 
| 
       1296 
1304 
     | 
    
         
             
             * - *:saj*
         
     | 
| 
       1297 
     | 
    
         
            -
             *   -  
     | 
| 
       1298 
     | 
    
         
            -
             *   -  
     | 
| 
       1299 
     | 
    
         
            -
             *   -  
     | 
| 
       1300 
     | 
    
         
            -
             * that length are cached.
         
     | 
| 
       1301 
     | 
    
         
            -
             *   - _cache_strings_ returns the value of the _cache_strings_ integer value.
         
     | 
| 
       1302 
     | 
    
         
            -
             *   - _handler=_ sets the SAJ handler
         
     | 
| 
       1303 
     | 
    
         
            -
             *   - _handler_ returns the SAJ handler
         
     | 
| 
      
 1305 
     | 
    
         
            +
             *   - _cache_keys_ is a flag indicating hash keys should be cached.
         
     | 
| 
      
 1306 
     | 
    
         
            +
             *   - _cache_strings_ is a positive integer less than 35. Strings shorter than that length are cached.
         
     | 
| 
      
 1307 
     | 
    
         
            +
             *   - _handler_ is the SAJ handler
         
     | 
| 
       1304 
1308 
     | 
    
         
             
             *
         
     | 
| 
       1305 
1309 
     | 
    
         
             
             * - *:usual*
         
     | 
| 
       1306 
     | 
    
         
            -
             *   -  
     | 
| 
       1307 
     | 
    
         
            -
             *   -  
     | 
| 
       1308 
     | 
    
         
            -
             *   -  
     | 
| 
       1309 
     | 
    
         
            -
             *  
     | 
| 
       1310 
     | 
    
         
            -
             *   -  
     | 
| 
       1311 
     | 
    
         
            -
             * 
     | 
| 
       1312 
     | 
    
         
            -
             *  
     | 
| 
       1313 
     | 
    
         
            -
             * 
     | 
| 
       1314 
     | 
    
         
            -
             * 
     | 
| 
       1315 
     | 
    
         
            -
             *  
     | 
| 
       1316 
     | 
    
         
            -
             * 
     | 
| 
       1317 
     | 
    
         
            -
             * 
     | 
| 
       1318 
     | 
    
         
            -
             * 
     | 
| 
       1319 
     | 
    
         
            -
             *  
     | 
| 
       1320 
     | 
    
         
            -
             * 
     | 
| 
       1321 
     | 
    
         
            -
             *  
     | 
| 
       1322 
     | 
    
         
            -
             * _: 
     | 
| 
       1323 
     | 
    
         
            -
             * 
     | 
| 
       1324 
     | 
    
         
            -
             *  
     | 
| 
       1325 
     | 
    
         
            -
             * 
     | 
| 
       1326 
     | 
    
         
            -
             *   -  
     | 
| 
       1327 
     | 
    
         
            -
             * ignored on parsing in favor of creating an instance and populating directly.
         
     | 
| 
       1328 
     | 
    
         
            -
             *   - _missing_class_ return the value of the _missing_class_ indicator.
         
     | 
| 
       1329 
     | 
    
         
            -
             *   - _missing_class=_ sets the value of the _missing_class_ flag. Valid values are _:auto_ which creates any missing
         
     | 
| 
       1330 
     | 
    
         
            -
             * classes on parse, :ignore which ignores and continues as a Hash (default), and :raise which raises an exception if
         
     | 
| 
       1331 
     | 
    
         
            -
             * the class is not found.
         
     | 
| 
       1332 
     | 
    
         
            -
             *   - _omit_null=_ sets the _omit_null_ flag. If true then null values in a map or object are omitted from the
         
     | 
| 
       1333 
     | 
    
         
            -
             * resulting Hash or Object.
         
     | 
| 
       1334 
     | 
    
         
            -
             *   - _omit_null_ returns the value of the _omit_null_ flag.
         
     | 
| 
       1335 
     | 
    
         
            -
             *   - _symbol_keys=_ sets the flag that indicates Hash keys should be parsed to Symbols versus Strings.
         
     | 
| 
       1336 
     | 
    
         
            -
             *   - _symbol_keys_ returns the value of the _symbol_keys_ flag.
         
     | 
| 
      
 1310 
     | 
    
         
            +
             *   - _cache_keys_ is a flag indicating hash keys should be cached.
         
     | 
| 
      
 1311 
     | 
    
         
            +
             *   - _cache_strings_ is a positive integer less than 35. Strings shorter than that length are cached.
         
     | 
| 
      
 1312 
     | 
    
         
            +
             *   - _cache_expunge_ dictates when the cache will be expunged where 0 never expunges,
         
     | 
| 
      
 1313 
     | 
    
         
            +
             *     1 expunges slowly, 2 expunges faster, and 3 or higher expunges agressively.
         
     | 
| 
      
 1314 
     | 
    
         
            +
             *   - _capacity_ is the capacity of the parser's internal stack. The parser grows automatically
         
     | 
| 
      
 1315 
     | 
    
         
            +
             *     but can be updated directly with this call.
         
     | 
| 
      
 1316 
     | 
    
         
            +
             *   - _create_id_ if non-nil is the key that is used to specify the type of object to create
         
     | 
| 
      
 1317 
     | 
    
         
            +
             *     when parsing. Parsed JSON objects that include the specified element use the element
         
     | 
| 
      
 1318 
     | 
    
         
            +
             *     value as the name of the class to create an object from instead of a Hash.
         
     | 
| 
      
 1319 
     | 
    
         
            +
             *   - _decimal_ is the approach to how decimals are parsed. If _:auto_ then
         
     | 
| 
      
 1320 
     | 
    
         
            +
             *     the decimals with significant digits are 16 or less are Floats and long
         
     | 
| 
      
 1321 
     | 
    
         
            +
             *     ones are BigDecimal. _:ruby_ uses a call to Ruby to convert a string to a Float.
         
     | 
| 
      
 1322 
     | 
    
         
            +
             *     _:float_ always generates a Float. _:bigdecimal_ always results in a BigDecimal.
         
     | 
| 
      
 1323 
     | 
    
         
            +
             *   - _ignore_json_create_ is a flag that when set the class json_create method is
         
     | 
| 
      
 1324 
     | 
    
         
            +
             *     ignored on parsing in favor of creating an instance and populating directly.
         
     | 
| 
      
 1325 
     | 
    
         
            +
             *   - _missing_class_ is an indicator that determines how unknown class names are handled.
         
     | 
| 
      
 1326 
     | 
    
         
            +
             *     Valid values are _:auto_ which creates any missing classes on parse, :ignore which ignores
         
     | 
| 
      
 1327 
     | 
    
         
            +
             *     and continues as a Hash (default), and :raise which raises an exception if the class is not found.
         
     | 
| 
      
 1328 
     | 
    
         
            +
             *   - _omit_null_ is a flag that if true then null values in a map or object are omitted
         
     | 
| 
      
 1329 
     | 
    
         
            +
             *     from the resulting Hash or Object.
         
     | 
| 
      
 1330 
     | 
    
         
            +
             *   - _symbol_keys_ is a flag that indicates Hash keys should be parsed to Symbols versus Strings.
         
     | 
| 
       1337 
1331 
     | 
    
         
             
             */
         
     | 
| 
       1338 
1332 
     | 
    
         
             
            static VALUE parser_missing(int argc, VALUE *argv, VALUE self) {
         
     | 
| 
       1339 
     | 
    
         
            -
                ojParser       p 
     | 
| 
      
 1333 
     | 
    
         
            +
                ojParser       p;
         
     | 
| 
       1340 
1334 
     | 
    
         
             
                const char    *key  = NULL;
         
     | 
| 
       1341 
1335 
     | 
    
         
             
                volatile VALUE rkey = *argv;
         
     | 
| 
       1342 
1336 
     | 
    
         
             
                volatile VALUE rv   = Qnil;
         
     | 
| 
       1343 
1337 
     | 
    
         | 
| 
      
 1338 
     | 
    
         
            +
                TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p);
         
     | 
| 
      
 1339 
     | 
    
         
            +
             
     | 
| 
       1344 
1340 
     | 
    
         
             
            #if HAVE_RB_EXT_RACTOR_SAFE
         
     | 
| 
       1345 
1341 
     | 
    
         
             
                // This doesn't seem to do anything.
         
     | 
| 
       1346 
1342 
     | 
    
         
             
                rb_ext_ractor_safe(true);
         
     | 
| 
         @@ -1349,7 +1345,7 @@ static VALUE parser_missing(int argc, VALUE *argv, VALUE self) { 
     | 
|
| 
       1349 
1345 
     | 
    
         
             
                case RUBY_T_SYMBOL:
         
     | 
| 
       1350 
1346 
     | 
    
         
             
                    rkey = rb_sym2str(rkey);
         
     | 
| 
       1351 
1347 
     | 
    
         
             
                    // fall through
         
     | 
| 
       1352 
     | 
    
         
            -
                case RUBY_T_STRING: key =  
     | 
| 
      
 1348 
     | 
    
         
            +
                case RUBY_T_STRING: key = StringValuePtr(rkey); break;
         
     | 
| 
       1353 
1349 
     | 
    
         
             
                default: rb_raise(rb_eArgError, "option method must be a symbol or string");
         
     | 
| 
       1354 
1350 
     | 
    
         
             
                }
         
     | 
| 
       1355 
1351 
     | 
    
         
             
                if (1 < argc) {
         
     | 
| 
         @@ -1366,12 +1362,14 @@ static VALUE parser_missing(int argc, VALUE *argv, VALUE self) { 
     | 
|
| 
       1366 
1362 
     | 
    
         
             
             * Returns the result according to the delegate of the parser.
         
     | 
| 
       1367 
1363 
     | 
    
         
             
             */
         
     | 
| 
       1368 
1364 
     | 
    
         
             
            static VALUE parser_parse(VALUE self, VALUE json) {
         
     | 
| 
       1369 
     | 
    
         
            -
                ojParser 
     | 
| 
      
 1365 
     | 
    
         
            +
                ojParser    p;
         
     | 
| 
      
 1366 
     | 
    
         
            +
                const byte *ptr = (const byte *)StringValuePtr(json);
         
     | 
| 
      
 1367 
     | 
    
         
            +
             
     | 
| 
      
 1368 
     | 
    
         
            +
                TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p);
         
     | 
| 
       1370 
1369 
     | 
    
         | 
| 
       1371 
     | 
    
         
            -
                Check_Type(json, T_STRING);
         
     | 
| 
       1372 
1370 
     | 
    
         
             
                parser_reset(p);
         
     | 
| 
       1373 
1371 
     | 
    
         
             
                p->start(p);
         
     | 
| 
       1374 
     | 
    
         
            -
                parse(p,  
     | 
| 
      
 1372 
     | 
    
         
            +
                parse(p, ptr);
         
     | 
| 
       1375 
1373 
     | 
    
         | 
| 
       1376 
1374 
     | 
    
         
             
                return p->result(p);
         
     | 
| 
       1377 
1375 
     | 
    
         
             
            }
         
     | 
| 
         @@ -1382,15 +1380,23 @@ static VALUE load_rescue(VALUE self, VALUE x) { 
     | 
|
| 
       1382 
1380 
     | 
    
         
             
            }
         
     | 
| 
       1383 
1381 
     | 
    
         | 
| 
       1384 
1382 
     | 
    
         
             
            static VALUE load(VALUE self) {
         
     | 
| 
       1385 
     | 
    
         
            -
                ojParser       p 
     | 
| 
      
 1383 
     | 
    
         
            +
                ojParser       p;
         
     | 
| 
       1386 
1384 
     | 
    
         
             
                volatile VALUE rbuf = rb_str_new2("");
         
     | 
| 
       1387 
1385 
     | 
    
         | 
| 
      
 1386 
     | 
    
         
            +
                TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p);
         
     | 
| 
      
 1387 
     | 
    
         
            +
             
     | 
| 
       1388 
1388 
     | 
    
         
             
                p->start(p);
         
     | 
| 
       1389 
1389 
     | 
    
         
             
                while (true) {
         
     | 
| 
       1390 
1390 
     | 
    
         
             
                    rb_funcall(p->reader, oj_readpartial_id, 2, INT2NUM(16385), rbuf);
         
     | 
| 
       1391 
1391 
     | 
    
         
             
                    if (0 < RSTRING_LEN(rbuf)) {
         
     | 
| 
       1392 
1392 
     | 
    
         
             
                        parse(p, (byte *)StringValuePtr(rbuf));
         
     | 
| 
       1393 
1393 
     | 
    
         
             
                    }
         
     | 
| 
      
 1394 
     | 
    
         
            +
                    if (Qtrue == rb_funcall(p->reader, oj_eofq_id, 0)) {
         
     | 
| 
      
 1395 
     | 
    
         
            +
                        if (0 < p->depth) {
         
     | 
| 
      
 1396 
     | 
    
         
            +
                            parse_error(p, "parse error, not closed");
         
     | 
| 
      
 1397 
     | 
    
         
            +
                        }
         
     | 
| 
      
 1398 
     | 
    
         
            +
                        break;
         
     | 
| 
      
 1399 
     | 
    
         
            +
                    }
         
     | 
| 
       1394 
1400 
     | 
    
         
             
                }
         
     | 
| 
       1395 
1401 
     | 
    
         
             
                return Qtrue;
         
     | 
| 
       1396 
1402 
     | 
    
         
             
            }
         
     | 
| 
         @@ -1403,7 +1409,9 @@ static VALUE load(VALUE self) { 
     | 
|
| 
       1403 
1409 
     | 
    
         
             
             * Returns the result according to the delegate of the parser.
         
     | 
| 
       1404 
1410 
     | 
    
         
             
             */
         
     | 
| 
       1405 
1411 
     | 
    
         
             
            static VALUE parser_load(VALUE self, VALUE reader) {
         
     | 
| 
       1406 
     | 
    
         
            -
                ojParser p 
     | 
| 
      
 1412 
     | 
    
         
            +
                ojParser p;
         
     | 
| 
      
 1413 
     | 
    
         
            +
             
     | 
| 
      
 1414 
     | 
    
         
            +
                TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p);
         
     | 
| 
       1407 
1415 
     | 
    
         | 
| 
       1408 
1416 
     | 
    
         
             
                parser_reset(p);
         
     | 
| 
       1409 
1417 
     | 
    
         
             
                p->reader = reader;
         
     | 
| 
         @@ -1420,12 +1428,13 @@ static VALUE parser_load(VALUE self, VALUE reader) { 
     | 
|
| 
       1420 
1428 
     | 
    
         
             
             * Returns the result according to the delegate of the parser.
         
     | 
| 
       1421 
1429 
     | 
    
         
             
             */
         
     | 
| 
       1422 
1430 
     | 
    
         
             
            static VALUE parser_file(VALUE self, VALUE filename) {
         
     | 
| 
       1423 
     | 
    
         
            -
                ojParser    p 
     | 
| 
      
 1431 
     | 
    
         
            +
                ojParser    p;
         
     | 
| 
       1424 
1432 
     | 
    
         
             
                const char *path;
         
     | 
| 
       1425 
1433 
     | 
    
         
             
                int         fd;
         
     | 
| 
       1426 
1434 
     | 
    
         | 
| 
       1427 
     | 
    
         
            -
                 
     | 
| 
       1428 
     | 
    
         
            -
             
     | 
| 
      
 1435 
     | 
    
         
            +
                TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p);
         
     | 
| 
      
 1436 
     | 
    
         
            +
             
     | 
| 
      
 1437 
     | 
    
         
            +
                path = StringValuePtr(filename);
         
     | 
| 
       1429 
1438 
     | 
    
         | 
| 
       1430 
1439 
     | 
    
         
             
                parser_reset(p);
         
     | 
| 
       1431 
1440 
     | 
    
         
             
                p->start(p);
         
     | 
| 
         @@ -1468,7 +1477,9 @@ static VALUE parser_file(VALUE self, VALUE filename) { 
     | 
|
| 
       1468 
1477 
     | 
    
         
             
             * Returns the current state of the just_one [_Boolean_] option.
         
     | 
| 
       1469 
1478 
     | 
    
         
             
             */
         
     | 
| 
       1470 
1479 
     | 
    
         
             
            static VALUE parser_just_one(VALUE self) {
         
     | 
| 
       1471 
     | 
    
         
            -
                ojParser p 
     | 
| 
      
 1480 
     | 
    
         
            +
                ojParser p;
         
     | 
| 
      
 1481 
     | 
    
         
            +
             
     | 
| 
      
 1482 
     | 
    
         
            +
                TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p);
         
     | 
| 
       1472 
1483 
     | 
    
         | 
| 
       1473 
1484 
     | 
    
         
             
                return p->just_one ? Qtrue : Qfalse;
         
     | 
| 
       1474 
1485 
     | 
    
         
             
            }
         
     | 
| 
         @@ -1482,7 +1493,9 @@ static VALUE parser_just_one(VALUE self) { 
     | 
|
| 
       1482 
1493 
     | 
    
         
             
             * Returns the current state of the just_one [_Boolean_] option.
         
     | 
| 
       1483 
1494 
     | 
    
         
             
             */
         
     | 
| 
       1484 
1495 
     | 
    
         
             
            static VALUE parser_just_one_set(VALUE self, VALUE v) {
         
     | 
| 
       1485 
     | 
    
         
            -
                ojParser p 
     | 
| 
      
 1496 
     | 
    
         
            +
                ojParser p;
         
     | 
| 
      
 1497 
     | 
    
         
            +
             
     | 
| 
      
 1498 
     | 
    
         
            +
                TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p);
         
     | 
| 
       1486 
1499 
     | 
    
         | 
| 
       1487 
1500 
     | 
    
         
             
                p->just_one = (Qtrue == v);
         
     | 
| 
       1488 
1501 
     | 
    
         | 
| 
         @@ -1499,14 +1512,14 @@ static VALUE usual_parser = Qundef; 
     | 
|
| 
       1499 
1512 
     | 
    
         
             
             */
         
     | 
| 
       1500 
1513 
     | 
    
         
             
            static VALUE parser_usual(VALUE self) {
         
     | 
| 
       1501 
1514 
     | 
    
         
             
                if (Qundef == usual_parser) {
         
     | 
| 
       1502 
     | 
    
         
            -
                    ojParser p =  
     | 
| 
      
 1515 
     | 
    
         
            +
                    ojParser p = OJ_R_ALLOC(struct _ojParser);
         
     | 
| 
       1503 
1516 
     | 
    
         | 
| 
       1504 
1517 
     | 
    
         
             
                    memset(p, 0, sizeof(struct _ojParser));
         
     | 
| 
       1505 
1518 
     | 
    
         
             
                    buf_init(&p->key);
         
     | 
| 
       1506 
1519 
     | 
    
         
             
                    buf_init(&p->buf);
         
     | 
| 
       1507 
1520 
     | 
    
         
             
                    p->map = value_map;
         
     | 
| 
       1508 
1521 
     | 
    
         
             
                    oj_set_parser_usual(p);
         
     | 
| 
       1509 
     | 
    
         
            -
                    usual_parser =  
     | 
| 
      
 1522 
     | 
    
         
            +
                    usual_parser = TypedData_Wrap_Struct(parser_class, &oj_parser_type, p);
         
     | 
| 
       1510 
1523 
     | 
    
         
             
                    rb_gc_register_address(&usual_parser);
         
     | 
| 
       1511 
1524 
     | 
    
         
             
                }
         
     | 
| 
       1512 
1525 
     | 
    
         
             
                return usual_parser;
         
     | 
| 
         @@ -1522,14 +1535,14 @@ static VALUE saj_parser = Qundef; 
     | 
|
| 
       1522 
1535 
     | 
    
         
             
             */
         
     | 
| 
       1523 
1536 
     | 
    
         
             
            static VALUE parser_saj(VALUE self) {
         
     | 
| 
       1524 
1537 
     | 
    
         
             
                if (Qundef == saj_parser) {
         
     | 
| 
       1525 
     | 
    
         
            -
                    ojParser p =  
     | 
| 
      
 1538 
     | 
    
         
            +
                    ojParser p = OJ_R_ALLOC(struct _ojParser);
         
     | 
| 
       1526 
1539 
     | 
    
         | 
| 
       1527 
1540 
     | 
    
         
             
                    memset(p, 0, sizeof(struct _ojParser));
         
     | 
| 
       1528 
1541 
     | 
    
         
             
                    buf_init(&p->key);
         
     | 
| 
       1529 
1542 
     | 
    
         
             
                    buf_init(&p->buf);
         
     | 
| 
       1530 
1543 
     | 
    
         
             
                    p->map = value_map;
         
     | 
| 
       1531 
1544 
     | 
    
         
             
                    oj_set_parser_saj(p);
         
     | 
| 
       1532 
     | 
    
         
            -
                    saj_parser =  
     | 
| 
      
 1545 
     | 
    
         
            +
                    saj_parser = TypedData_Wrap_Struct(parser_class, &oj_parser_type, p);
         
     | 
| 
       1533 
1546 
     | 
    
         
             
                    rb_gc_register_address(&saj_parser);
         
     | 
| 
       1534 
1547 
     | 
    
         
             
                }
         
     | 
| 
       1535 
1548 
     | 
    
         
             
                return saj_parser;
         
     | 
| 
         @@ -1544,14 +1557,14 @@ static VALUE validate_parser = Qundef; 
     | 
|
| 
       1544 
1557 
     | 
    
         
             
             */
         
     | 
| 
       1545 
1558 
     | 
    
         
             
            static VALUE parser_validate(VALUE self) {
         
     | 
| 
       1546 
1559 
     | 
    
         
             
                if (Qundef == validate_parser) {
         
     | 
| 
       1547 
     | 
    
         
            -
                    ojParser p =  
     | 
| 
      
 1560 
     | 
    
         
            +
                    ojParser p = OJ_R_ALLOC(struct _ojParser);
         
     | 
| 
       1548 
1561 
     | 
    
         | 
| 
       1549 
1562 
     | 
    
         
             
                    memset(p, 0, sizeof(struct _ojParser));
         
     | 
| 
       1550 
1563 
     | 
    
         
             
                    buf_init(&p->key);
         
     | 
| 
       1551 
1564 
     | 
    
         
             
                    buf_init(&p->buf);
         
     | 
| 
       1552 
1565 
     | 
    
         
             
                    p->map = value_map;
         
     | 
| 
       1553 
1566 
     | 
    
         
             
                    oj_set_parser_validator(p);
         
     | 
| 
       1554 
     | 
    
         
            -
                    validate_parser =  
     | 
| 
      
 1567 
     | 
    
         
            +
                    validate_parser = TypedData_Wrap_Struct(parser_class, &oj_parser_type, p);
         
     | 
| 
       1555 
1568 
     | 
    
         
             
                    rb_gc_register_address(&validate_parser);
         
     | 
| 
       1556 
1569 
     | 
    
         
             
                }
         
     | 
| 
       1557 
1570 
     | 
    
         
             
                return validate_parser;
         
     | 
    
        data/ext/oj/parser.h
    CHANGED
    
    | 
         @@ -4,8 +4,8 @@ 
     | 
|
| 
       4 
4 
     | 
    
         
             
            #ifndef OJ_PARSER_H
         
     | 
| 
       5 
5 
     | 
    
         
             
            #define OJ_PARSER_H
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
            #include <stdbool.h>
         
     | 
| 
       8 
7 
     | 
    
         
             
            #include <ruby.h>
         
     | 
| 
      
 8 
     | 
    
         
            +
            #include <stdbool.h>
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
            #include "buf.h"
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
         @@ -38,7 +38,7 @@ typedef struct _num { 
     | 
|
| 
       38 
38 
     | 
    
         
             
                bool        neg;
         
     | 
| 
       39 
39 
     | 
    
         
             
                bool        exp_neg;
         
     | 
| 
       40 
40 
     | 
    
         
             
                // for numbers as strings, reuse buf
         
     | 
| 
       41 
     | 
    
         
            -
            } * 
     | 
| 
      
 41 
     | 
    
         
            +
            } *Num;
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
            struct _ojParser;
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
         @@ -54,11 +54,11 @@ typedef struct _funcs { 
     | 
|
| 
       54 
54 
     | 
    
         
             
                void (*close_array)(struct _ojParser *p);
         
     | 
| 
       55 
55 
     | 
    
         
             
                void (*open_object)(struct _ojParser *p);
         
     | 
| 
       56 
56 
     | 
    
         
             
                void (*close_object)(struct _ojParser *p);
         
     | 
| 
       57 
     | 
    
         
            -
            } * 
     | 
| 
      
 57 
     | 
    
         
            +
            } *Funcs;
         
     | 
| 
       58 
58 
     | 
    
         | 
| 
       59 
59 
     | 
    
         
             
            typedef struct _ojParser {
         
     | 
| 
       60 
     | 
    
         
            -
                const char 
     | 
| 
       61 
     | 
    
         
            -
                const char 
     | 
| 
      
 60 
     | 
    
         
            +
                const char   *map;
         
     | 
| 
      
 61 
     | 
    
         
            +
                const char   *next_map;
         
     | 
| 
       62 
62 
     | 
    
         
             
                int           depth;
         
     | 
| 
       63 
63 
     | 
    
         
             
                unsigned char stack[1024];
         
     | 
| 
       64 
64 
     | 
    
         | 
| 
         @@ -67,7 +67,7 @@ typedef struct _ojParser { 
     | 
|
| 
       67 
67 
     | 
    
         
             
                struct _buf key;
         
     | 
| 
       68 
68 
     | 
    
         
             
                struct _buf buf;
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
       70 
     | 
    
         
            -
                struct _funcs funcs[3]; 
     | 
| 
      
 70 
     | 
    
         
            +
                struct _funcs funcs[3];  // indexed by XXX_FUN defines
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
       72 
72 
     | 
    
         
             
                void (*start)(struct _ojParser *p);
         
     | 
| 
       73 
73 
     | 
    
         
             
                VALUE (*option)(struct _ojParser *p, const char *key, VALUE value);
         
     | 
| 
         @@ -86,7 +86,7 @@ typedef struct _ojParser { 
     | 
|
| 
       86 
86 
     | 
    
         
             
                uint32_t ucode;
         
     | 
| 
       87 
87 
     | 
    
         
             
                ojType   type;  // valType
         
     | 
| 
       88 
88 
     | 
    
         
             
                bool     just_one;
         
     | 
| 
       89 
     | 
    
         
            -
            } * 
     | 
| 
      
 89 
     | 
    
         
            +
            } *ojParser;
         
     | 
| 
       90 
90 
     | 
    
         | 
| 
       91 
91 
     | 
    
         
             
            // Create a new parser without setting the delegate. The parser is
         
     | 
| 
       92 
92 
     | 
    
         
             
            // wrapped. The parser is (ojParser)DATA_PTR(value) where value is the return
         
     | 
| 
         @@ -98,5 +98,4 @@ extern VALUE oj_parser_new(); 
     | 
|
| 
       98 
98 
     | 
    
         
             
            // Set set the options from a hash (ropts).
         
     | 
| 
       99 
99 
     | 
    
         
             
            extern void oj_parser_set_option(ojParser p, VALUE ropts);
         
     | 
| 
       100 
100 
     | 
    
         | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
101 
     | 
    
         
             
            #endif /* OJ_PARSER_H */
         
     |