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/dump_leaf.c
    CHANGED
    
    | 
         @@ -17,9 +17,7 @@ inline static void dump_chars(const char *s, size_t size, Out out) { 
     | 
|
| 
       17 
17 
     | 
    
         
             
            static void dump_leaf_str(Leaf leaf, Out out) {
         
     | 
| 
       18 
18 
     | 
    
         
             
                switch (leaf->value_type) {
         
     | 
| 
       19 
19 
     | 
    
         
             
                case STR_VAL: oj_dump_cstr(leaf->str, strlen(leaf->str), 0, 0, out); break;
         
     | 
| 
       20 
     | 
    
         
            -
                case RUBY_VAL:
         
     | 
| 
       21 
     | 
    
         
            -
                    oj_dump_cstr(rb_string_value_cstr(&leaf->value), (int)RSTRING_LEN(leaf->value), 0, 0, out);
         
     | 
| 
       22 
     | 
    
         
            -
                    break;
         
     | 
| 
      
 20 
     | 
    
         
            +
                case RUBY_VAL: oj_dump_cstr(StringValueCStr(leaf->value), (int)RSTRING_LEN(leaf->value), 0, 0, out); break;
         
     | 
| 
       23 
21 
     | 
    
         
             
                case COL_VAL:
         
     | 
| 
       24 
22 
     | 
    
         
             
                default: rb_raise(rb_eTypeError, "Unexpected value type %02x.\n", leaf->value_type); break;
         
     | 
| 
       25 
23 
     | 
    
         
             
                }
         
     | 
| 
         @@ -142,11 +140,11 @@ void oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out) { 
     | 
|
| 
       142 
140 
     | 
    
         
             
            void oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts) {
         
     | 
| 
       143 
141 
     | 
    
         
             
                struct _out out;
         
     | 
| 
       144 
142 
     | 
    
         
             
                size_t      size;
         
     | 
| 
       145 
     | 
    
         
            -
                FILE 
     | 
| 
      
 143 
     | 
    
         
            +
                FILE       *f;
         
     | 
| 
       146 
144 
     | 
    
         | 
| 
       147 
145 
     | 
    
         
             
                oj_out_init(&out);
         
     | 
| 
       148 
146 
     | 
    
         | 
| 
       149 
     | 
    
         
            -
                out.omit_nil 
     | 
| 
      
 147 
     | 
    
         
            +
                out.omit_nil = copts->dump_opts.omit_nil;
         
     | 
| 
       150 
148 
     | 
    
         
             
                oj_dump_leaf_to_json(leaf, copts, &out);
         
     | 
| 
       151 
149 
     | 
    
         
             
                size = out.cur - out.buf;
         
     | 
| 
       152 
150 
     | 
    
         
             
                if (0 == (f = fopen(path, "w"))) {
         
     | 
    
        data/ext/oj/dump_object.c
    CHANGED
    
    | 
         @@ -2,6 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            // Licensed under the MIT License. See LICENSE file in the project root for license details.
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            #include "dump.h"
         
     | 
| 
      
 5 
     | 
    
         
            +
            #include "mem.h"
         
     | 
| 
       5 
6 
     | 
    
         
             
            #include "odd.h"
         
     | 
| 
       6 
7 
     | 
    
         
             
            #include "trace.h"
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
         @@ -30,8 +31,8 @@ static void dump_data(VALUE obj, int depth, Out out, bool as_ok) { 
     | 
|
| 
       30 
31 
     | 
    
         
             
                    *out->cur   = '\0';
         
     | 
| 
       31 
32 
     | 
    
         
             
                } else {
         
     | 
| 
       32 
33 
     | 
    
         
             
                    if (oj_bigdecimal_class == clas) {
         
     | 
| 
       33 
     | 
    
         
            -
                        volatile VALUE rstr =  
     | 
| 
       34 
     | 
    
         
            -
                        const char 
     | 
| 
      
 34 
     | 
    
         
            +
                        volatile VALUE rstr = oj_safe_string_convert(obj);
         
     | 
| 
      
 35 
     | 
    
         
            +
                        const char    *str  = RSTRING_PTR(rstr);
         
     | 
| 
       35 
36 
     | 
    
         
             
                        int            len  = (int)RSTRING_LEN(rstr);
         
     | 
| 
       36 
37 
     | 
    
         | 
| 
       37 
38 
     | 
    
         
             
                        if (No != out->opts->bigdec_as_num) {
         
     | 
| 
         @@ -59,8 +60,8 @@ static void dump_obj(VALUE obj, int depth, Out out, bool as_ok) { 
     | 
|
| 
       59 
60 
     | 
    
         
             
                VALUE clas = rb_obj_class(obj);
         
     | 
| 
       60 
61 
     | 
    
         | 
| 
       61 
62 
     | 
    
         
             
                if (oj_bigdecimal_class == clas) {
         
     | 
| 
       62 
     | 
    
         
            -
                    volatile VALUE rstr =  
     | 
| 
       63 
     | 
    
         
            -
                    const char 
     | 
| 
      
 63 
     | 
    
         
            +
                    volatile VALUE rstr = oj_safe_string_convert(obj);
         
     | 
| 
      
 64 
     | 
    
         
            +
                    const char    *str  = RSTRING_PTR(rstr);
         
     | 
| 
       64 
65 
     | 
    
         
             
                    int            len  = (int)RSTRING_LEN(rstr);
         
     | 
| 
       65 
66 
     | 
    
         | 
| 
       66 
67 
     | 
    
         
             
                    if (0 == strcasecmp("Infinity", str)) {
         
     | 
| 
         @@ -223,37 +224,36 @@ static int hash_cb(VALUE key, VALUE value, VALUE ov) { 
     | 
|
| 
       223 
224 
     | 
    
         
             
                    oj_dump_obj_val(value, depth, out);
         
     | 
| 
       224 
225 
     | 
    
         
             
                    break;
         
     | 
| 
       225 
226 
     | 
    
         | 
| 
       226 
     | 
    
         
            -
                default:
         
     | 
| 
       227 
     | 
    
         
            -
                     
     | 
| 
       228 
     | 
    
         
            -
             
     | 
| 
       229 
     | 
    
         
            -
             
     | 
| 
       230 
     | 
    
         
            -
             
     | 
| 
       231 
     | 
    
         
            -
             
     | 
| 
       232 
     | 
    
         
            -
             
     | 
| 
       233 
     | 
    
         
            -
             
     | 
| 
       234 
     | 
    
         
            -
             
     | 
| 
       235 
     | 
    
         
            -
             
     | 
| 
       236 
     | 
    
         
            -
             
     | 
| 
       237 
     | 
    
         
            -
                         
     | 
| 
       238 
     | 
    
         
            -
             
     | 
| 
       239 
     | 
    
         
            -
                             
     | 
| 
       240 
     | 
    
         
            -
             
     | 
| 
       241 
     | 
    
         
            -
             
     | 
| 
       242 
     | 
    
         
            -
                             
     | 
| 
       243 
     | 
    
         
            -
                                *out->cur++ = hex_chars[b];
         
     | 
| 
       244 
     | 
    
         
            -
                            }
         
     | 
| 
      
 227 
     | 
    
         
            +
                default: {
         
     | 
| 
      
 228 
     | 
    
         
            +
                    int     d2 = depth + 1;
         
     | 
| 
      
 229 
     | 
    
         
            +
                    long    s2 = size + out->indent + 1;
         
     | 
| 
      
 230 
     | 
    
         
            +
                    int     i;
         
     | 
| 
      
 231 
     | 
    
         
            +
                    int     started = 0;
         
     | 
| 
      
 232 
     | 
    
         
            +
                    uint8_t b;
         
     | 
| 
      
 233 
     | 
    
         
            +
             
     | 
| 
      
 234 
     | 
    
         
            +
                    assure_size(out, s2 + 15);
         
     | 
| 
      
 235 
     | 
    
         
            +
                    APPEND_CHARS(out->cur, "\"^#", 3);
         
     | 
| 
      
 236 
     | 
    
         
            +
                    out->hash_cnt++;
         
     | 
| 
      
 237 
     | 
    
         
            +
                    for (i = 28; 0 <= i; i -= 4) {
         
     | 
| 
      
 238 
     | 
    
         
            +
                        b = (uint8_t)((out->hash_cnt >> i) & 0x0000000F);
         
     | 
| 
      
 239 
     | 
    
         
            +
                        if ('\0' != b) {
         
     | 
| 
      
 240 
     | 
    
         
            +
                            started = 1;
         
     | 
| 
      
 241 
     | 
    
         
            +
                        }
         
     | 
| 
      
 242 
     | 
    
         
            +
                        if (started) {
         
     | 
| 
      
 243 
     | 
    
         
            +
                            *out->cur++ = hex_chars[b];
         
     | 
| 
       245 
244 
     | 
    
         
             
                        }
         
     | 
| 
       246 
     | 
    
         
            -
                        APPEND_CHARS(out->cur, "\":[", 3);
         
     | 
| 
       247 
     | 
    
         
            -
                        fill_indent(out, d2);
         
     | 
| 
       248 
     | 
    
         
            -
                        oj_dump_obj_val(key, d2, out);
         
     | 
| 
       249 
     | 
    
         
            -
                        assure_size(out, s2);
         
     | 
| 
       250 
     | 
    
         
            -
                        *out->cur++ = ',';
         
     | 
| 
       251 
     | 
    
         
            -
                        fill_indent(out, d2);
         
     | 
| 
       252 
     | 
    
         
            -
                        oj_dump_obj_val(value, d2, out);
         
     | 
| 
       253 
     | 
    
         
            -
                        assure_size(out, size);
         
     | 
| 
       254 
     | 
    
         
            -
                        fill_indent(out, depth);
         
     | 
| 
       255 
     | 
    
         
            -
                        *out->cur++ = ']';
         
     | 
| 
       256 
245 
     | 
    
         
             
                    }
         
     | 
| 
      
 246 
     | 
    
         
            +
                    APPEND_CHARS(out->cur, "\":[", 3);
         
     | 
| 
      
 247 
     | 
    
         
            +
                    fill_indent(out, d2);
         
     | 
| 
      
 248 
     | 
    
         
            +
                    oj_dump_obj_val(key, d2, out);
         
     | 
| 
      
 249 
     | 
    
         
            +
                    assure_size(out, s2);
         
     | 
| 
      
 250 
     | 
    
         
            +
                    *out->cur++ = ',';
         
     | 
| 
      
 251 
     | 
    
         
            +
                    fill_indent(out, d2);
         
     | 
| 
      
 252 
     | 
    
         
            +
                    oj_dump_obj_val(value, d2, out);
         
     | 
| 
      
 253 
     | 
    
         
            +
                    assure_size(out, size);
         
     | 
| 
      
 254 
     | 
    
         
            +
                    fill_indent(out, depth);
         
     | 
| 
      
 255 
     | 
    
         
            +
                    *out->cur++ = ']';
         
     | 
| 
      
 256 
     | 
    
         
            +
                }
         
     | 
| 
       257 
257 
     | 
    
         
             
                }
         
     | 
| 
       258 
258 
     | 
    
         
             
                out->depth  = depth;
         
     | 
| 
       259 
259 
     | 
    
         
             
                *out->cur++ = ',';
         
     | 
| 
         @@ -363,10 +363,10 @@ static void dump_hash(VALUE obj, int depth, Out out, bool as_ok) { 
     | 
|
| 
       363 
363 
     | 
    
         
             
            }
         
     | 
| 
       364 
364 
     | 
    
         | 
| 
       365 
365 
     | 
    
         
             
            static void dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
         
     | 
| 
       366 
     | 
    
         
            -
                ID 
     | 
| 
       367 
     | 
    
         
            -
                AttrGetFunc 
     | 
| 
      
 366 
     | 
    
         
            +
                ID            *idp;
         
     | 
| 
      
 367 
     | 
    
         
            +
                AttrGetFunc   *fp;
         
     | 
| 
       368 
368 
     | 
    
         
             
                volatile VALUE v;
         
     | 
| 
       369 
     | 
    
         
            -
                const char 
     | 
| 
      
 369 
     | 
    
         
            +
                const char    *name;
         
     | 
| 
       370 
370 
     | 
    
         
             
                size_t         size;
         
     | 
| 
       371 
371 
     | 
    
         
             
                int            d2 = depth + 1;
         
     | 
| 
       372 
372 
     | 
    
         | 
| 
         @@ -422,7 +422,7 @@ static void dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) { 
     | 
|
| 
       422 
422 
     | 
    
         
             
                            ID    i;
         
     | 
| 
       423 
423 
     | 
    
         | 
| 
       424 
424 
     | 
    
         
             
                            if (sizeof(nbuf) <= nlen) {
         
     | 
| 
       425 
     | 
    
         
            -
                                if (NULL == (n2 =  
     | 
| 
      
 425 
     | 
    
         
            +
                                if (NULL == (n2 = OJ_STRDUP(name))) {
         
     | 
| 
       426 
426 
     | 
    
         
             
                                    rb_raise(rb_eNoMemError, "for attribute name.");
         
     | 
| 
       427 
427 
     | 
    
         
             
                                }
         
     | 
| 
       428 
428 
     | 
    
         
             
                            } else {
         
     | 
| 
         @@ -439,7 +439,7 @@ static void dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) { 
     | 
|
| 
       439 
439 
     | 
    
         
             
                            i = rb_intern(n);
         
     | 
| 
       440 
440 
     | 
    
         
             
                            v = rb_funcall(v, i, 0);
         
     | 
| 
       441 
441 
     | 
    
         
             
                            if (nbuf != n2) {
         
     | 
| 
       442 
     | 
    
         
            -
                                 
     | 
| 
      
 442 
     | 
    
         
            +
                                OJ_FREE(n2);
         
     | 
| 
       443 
443 
     | 
    
         
             
                            }
         
     | 
| 
       444 
444 
     | 
    
         
             
                        }
         
     | 
| 
       445 
445 
     | 
    
         
             
                        fill_indent(out, d2);
         
     | 
| 
         @@ -643,7 +643,7 @@ static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) { 
     | 
|
| 
       643 
643 
     | 
    
         
             
            #endif
         
     | 
| 
       644 
644 
     | 
    
         
             
                out->cur--;
         
     | 
| 
       645 
645 
     | 
    
         
             
                APPEND_CHARS(out->cur, "]}", 2);
         
     | 
| 
       646 
     | 
    
         
            -
                *out->cur 
     | 
| 
      
 646 
     | 
    
         
            +
                *out->cur = '\0';
         
     | 
| 
       647 
647 
     | 
    
         
             
            }
         
     | 
| 
       648 
648 
     | 
    
         | 
| 
       649 
649 
     | 
    
         
             
            static void dump_complex(VALUE obj, int depth, Out out, bool as_ok) {
         
     | 
| 
         @@ -682,9 +682,7 @@ static DumpFunc obj_funcs[] = { 
     | 
|
| 
       682 
682 
     | 
    
         
             
            void oj_dump_obj_val(VALUE obj, int depth, Out out) {
         
     | 
| 
       683 
683 
     | 
    
         
             
                int type = rb_type(obj);
         
     | 
| 
       684 
684 
     | 
    
         | 
| 
       685 
     | 
    
         
            -
                 
     | 
| 
       686 
     | 
    
         
            -
                    oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
         
     | 
| 
       687 
     | 
    
         
            -
                }
         
     | 
| 
      
 685 
     | 
    
         
            +
                TRACE(out->opts->trace, "dump", obj, depth, TraceIn);
         
     | 
| 
       688 
686 
     | 
    
         
             
                if (MAX_DEPTH < depth) {
         
     | 
| 
       689 
687 
     | 
    
         
             
                    rb_raise(rb_eNoMemError, "Too deeply nested.\n");
         
     | 
| 
       690 
688 
     | 
    
         
             
                }
         
     | 
| 
         @@ -693,14 +691,10 @@ void oj_dump_obj_val(VALUE obj, int depth, Out out) { 
     | 
|
| 
       693 
691 
     | 
    
         | 
| 
       694 
692 
     | 
    
         
             
                    if (NULL != f) {
         
     | 
| 
       695 
693 
     | 
    
         
             
                        f(obj, depth, out, false);
         
     | 
| 
       696 
     | 
    
         
            -
                         
     | 
| 
       697 
     | 
    
         
            -
                            oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
         
     | 
| 
       698 
     | 
    
         
            -
                        }
         
     | 
| 
      
 694 
     | 
    
         
            +
                        TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
         
     | 
| 
       699 
695 
     | 
    
         
             
                        return;
         
     | 
| 
       700 
696 
     | 
    
         
             
                    }
         
     | 
| 
       701 
697 
     | 
    
         
             
                }
         
     | 
| 
       702 
698 
     | 
    
         
             
                oj_dump_nil(Qnil, depth, out, false);
         
     | 
| 
       703 
     | 
    
         
            -
                 
     | 
| 
       704 
     | 
    
         
            -
                    oj_trace("dump", Qnil, __FILE__, __LINE__, depth, TraceOut);
         
     | 
| 
       705 
     | 
    
         
            -
                }
         
     | 
| 
      
 699 
     | 
    
         
            +
                TRACE(out->opts->trace, "dump", Qnil, depth, TraceOut);
         
     | 
| 
       706 
700 
     | 
    
         
             
            }
         
     | 
    
        data/ext/oj/dump_strict.c
    CHANGED
    
    | 
         @@ -22,15 +22,13 @@ static const char ninf_val[] = NINF_VAL; 
     | 
|
| 
       22 
22 
     | 
    
         
             
            static const char nan_val[]  = NAN_VAL;
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
            static void raise_strict(VALUE obj) {
         
     | 
| 
       25 
     | 
    
         
            -
                rb_raise(rb_eTypeError,
         
     | 
| 
       26 
     | 
    
         
            -
                         "Failed to dump %s Object to JSON in strict mode.\n",
         
     | 
| 
       27 
     | 
    
         
            -
                         rb_class2name(rb_obj_class(obj)));
         
     | 
| 
      
 25 
     | 
    
         
            +
                rb_raise(rb_eTypeError, "Failed to dump %s Object to JSON in strict mode.\n", rb_class2name(rb_obj_class(obj)));
         
     | 
| 
       28 
26 
     | 
    
         
             
            }
         
     | 
| 
       29 
27 
     | 
    
         | 
| 
       30 
28 
     | 
    
         
             
            // Removed dependencies on math due to problems with CentOS 5.4.
         
     | 
| 
       31 
29 
     | 
    
         
             
            static void dump_float(VALUE obj, int depth, Out out, bool as_ok) {
         
     | 
| 
       32 
30 
     | 
    
         
             
                char   buf[64];
         
     | 
| 
       33 
     | 
    
         
            -
                char 
     | 
| 
      
 31 
     | 
    
         
            +
                char*  b;
         
     | 
| 
       34 
32 
     | 
    
         
             
                double d   = rb_num2dbl(obj);
         
     | 
| 
       35 
33 
     | 
    
         
             
                int    cnt = 0;
         
     | 
| 
       36 
34 
     | 
    
         | 
| 
         @@ -92,7 +90,7 @@ static void dump_float(VALUE obj, int depth, Out out, bool as_ok) { 
     | 
|
| 
       92 
90 
     | 
    
         
             
                    } else if (d == (double)(long long int)d) {
         
     | 
| 
       93 
91 
     | 
    
         
             
                        cnt = snprintf(buf, sizeof(buf), "%.1f", d);
         
     | 
| 
       94 
92 
     | 
    
         
             
                    } else if (0 == out->opts->float_prec) {
         
     | 
| 
       95 
     | 
    
         
            -
                        volatile VALUE rstr =  
     | 
| 
      
 93 
     | 
    
         
            +
                        volatile VALUE rstr = oj_safe_string_convert(obj);
         
     | 
| 
       96 
94 
     | 
    
         | 
| 
       97 
95 
     | 
    
         
             
                        cnt = (int)RSTRING_LEN(rstr);
         
     | 
| 
       98 
96 
     | 
    
         
             
                        if ((int)sizeof(buf) <= cnt) {
         
     | 
| 
         @@ -290,7 +288,7 @@ static void dump_data_strict(VALUE obj, int depth, Out out, bool as_ok) { 
     | 
|
| 
       290 
288 
     | 
    
         
             
                VALUE clas = rb_obj_class(obj);
         
     | 
| 
       291 
289 
     | 
    
         | 
| 
       292 
290 
     | 
    
         
             
                if (oj_bigdecimal_class == clas) {
         
     | 
| 
       293 
     | 
    
         
            -
                    volatile VALUE rstr =  
     | 
| 
      
 291 
     | 
    
         
            +
                    volatile VALUE rstr = oj_safe_string_convert(obj);
         
     | 
| 
       294 
292 
     | 
    
         | 
| 
       295 
293 
     | 
    
         
             
                    oj_dump_raw(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), out);
         
     | 
| 
       296 
294 
     | 
    
         
             
                } else {
         
     | 
| 
         @@ -302,7 +300,7 @@ static void dump_data_null(VALUE obj, int depth, Out out, bool as_ok) { 
     | 
|
| 
       302 
300 
     | 
    
         
             
                VALUE clas = rb_obj_class(obj);
         
     | 
| 
       303 
301 
     | 
    
         | 
| 
       304 
302 
     | 
    
         
             
                if (oj_bigdecimal_class == clas) {
         
     | 
| 
       305 
     | 
    
         
            -
                    volatile VALUE rstr =  
     | 
| 
      
 303 
     | 
    
         
            +
                    volatile VALUE rstr = oj_safe_string_convert(obj);
         
     | 
| 
       306 
304 
     | 
    
         | 
| 
       307 
305 
     | 
    
         
             
                    oj_dump_raw(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), out);
         
     | 
| 
       308 
306 
     | 
    
         
             
                } else {
         
     | 
| 
         @@ -338,9 +336,7 @@ static DumpFunc strict_funcs[] = { 
     | 
|
| 
       338 
336 
     | 
    
         
             
            void oj_dump_strict_val(VALUE obj, int depth, Out out) {
         
     | 
| 
       339 
337 
     | 
    
         
             
                int type = rb_type(obj);
         
     | 
| 
       340 
338 
     | 
    
         | 
| 
       341 
     | 
    
         
            -
                 
     | 
| 
       342 
     | 
    
         
            -
                    oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
         
     | 
| 
       343 
     | 
    
         
            -
                }
         
     | 
| 
      
 339 
     | 
    
         
            +
                TRACE(out->opts->trace, "dump", obj, depth, TraceIn);
         
     | 
| 
       344 
340 
     | 
    
         
             
                if (MAX_DEPTH < depth) {
         
     | 
| 
       345 
341 
     | 
    
         
             
                    rb_raise(rb_eNoMemError, "Too deeply nested.\n");
         
     | 
| 
       346 
342 
     | 
    
         
             
                }
         
     | 
| 
         @@ -349,9 +345,7 @@ void oj_dump_strict_val(VALUE obj, int depth, Out out) { 
     | 
|
| 
       349 
345 
     | 
    
         | 
| 
       350 
346 
     | 
    
         
             
                    if (NULL != f) {
         
     | 
| 
       351 
347 
     | 
    
         
             
                        f(obj, depth, out, false);
         
     | 
| 
       352 
     | 
    
         
            -
                         
     | 
| 
       353 
     | 
    
         
            -
                            oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
         
     | 
| 
       354 
     | 
    
         
            -
                        }
         
     | 
| 
      
 348 
     | 
    
         
            +
                        TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
         
     | 
| 
       355 
349 
     | 
    
         
             
                        return;
         
     | 
| 
       356 
350 
     | 
    
         
             
                    }
         
     | 
| 
       357 
351 
     | 
    
         
             
                }
         
     | 
| 
         @@ -386,9 +380,7 @@ static DumpFunc null_funcs[] = { 
     | 
|
| 
       386 
380 
     | 
    
         
             
            void oj_dump_null_val(VALUE obj, int depth, Out out) {
         
     | 
| 
       387 
381 
     | 
    
         
             
                int type = rb_type(obj);
         
     | 
| 
       388 
382 
     | 
    
         | 
| 
       389 
     | 
    
         
            -
                 
     | 
| 
       390 
     | 
    
         
            -
                    oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
         
     | 
| 
       391 
     | 
    
         
            -
                }
         
     | 
| 
      
 383 
     | 
    
         
            +
                TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
         
     | 
| 
       392 
384 
     | 
    
         
             
                if (MAX_DEPTH < depth) {
         
     | 
| 
       393 
385 
     | 
    
         
             
                    rb_raise(rb_eNoMemError, "Too deeply nested.\n");
         
     | 
| 
       394 
386 
     | 
    
         
             
                }
         
     | 
| 
         @@ -397,14 +389,10 @@ void oj_dump_null_val(VALUE obj, int depth, Out out) { 
     | 
|
| 
       397 
389 
     | 
    
         | 
| 
       398 
390 
     | 
    
         
             
                    if (NULL != f) {
         
     | 
| 
       399 
391 
     | 
    
         
             
                        f(obj, depth, out, false);
         
     | 
| 
       400 
     | 
    
         
            -
                         
     | 
| 
       401 
     | 
    
         
            -
                            oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
         
     | 
| 
       402 
     | 
    
         
            -
                        }
         
     | 
| 
      
 392 
     | 
    
         
            +
                        TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
         
     | 
| 
       403 
393 
     | 
    
         
             
                        return;
         
     | 
| 
       404 
394 
     | 
    
         
             
                    }
         
     | 
| 
       405 
395 
     | 
    
         
             
                }
         
     | 
| 
       406 
396 
     | 
    
         
             
                oj_dump_nil(Qnil, depth, out, false);
         
     | 
| 
       407 
     | 
    
         
            -
                 
     | 
| 
       408 
     | 
    
         
            -
                    oj_trace("dump", Qnil, __FILE__, __LINE__, depth, TraceOut);
         
     | 
| 
       409 
     | 
    
         
            -
                }
         
     | 
| 
      
 397 
     | 
    
         
            +
                TRACE(out->opts->trace, "dump", Qnil, depth, TraceOut);
         
     | 
| 
       410 
398 
     | 
    
         
             
            }
         
     | 
    
        data/ext/oj/encoder.c
    CHANGED
    
    
    
        data/ext/oj/err.c
    CHANGED
    
    | 
         @@ -39,11 +39,7 @@ void _oj_err_set_with_location(Err         err, 
     | 
|
| 
       39 
39 
     | 
    
         
             
                oj_err_set(err, eclas, "%s at line %d, column %d [%s:%d]", msg, n, col, file, line);
         
     | 
| 
       40 
40 
     | 
    
         
             
            }
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
            void _oj_raise_error(const char *msg,
         
     | 
| 
       43 
     | 
    
         
            -
                                 const char *json,
         
     | 
| 
       44 
     | 
    
         
            -
                                 const char *current,
         
     | 
| 
       45 
     | 
    
         
            -
                                 const char *file,
         
     | 
| 
       46 
     | 
    
         
            -
                                 int         line) {
         
     | 
| 
      
 42 
     | 
    
         
            +
            void _oj_raise_error(const char *msg, const char *json, const char *current, const char *file, int line) {
         
     | 
| 
       47 
43 
     | 
    
         
             
                struct _err err;
         
     | 
| 
       48 
44 
     | 
    
         
             
                int         n   = 1;
         
     | 
| 
       49 
45 
     | 
    
         
             
                int         col = 1;
         
     | 
| 
         @@ -56,13 +52,6 @@ void _oj_raise_error(const char *msg, 
     | 
|
| 
       56 
52 
     | 
    
         
             
                        n++;
         
     | 
| 
       57 
53 
     | 
    
         
             
                    }
         
     | 
| 
       58 
54 
     | 
    
         
             
                }
         
     | 
| 
       59 
     | 
    
         
            -
                oj_err_set(&err,
         
     | 
| 
       60 
     | 
    
         
            -
                           oj_parse_error_class,
         
     | 
| 
       61 
     | 
    
         
            -
                           "%s at line %d, column %d [%s:%d]",
         
     | 
| 
       62 
     | 
    
         
            -
                           msg,
         
     | 
| 
       63 
     | 
    
         
            -
                           n,
         
     | 
| 
       64 
     | 
    
         
            -
                           col,
         
     | 
| 
       65 
     | 
    
         
            -
                           file,
         
     | 
| 
       66 
     | 
    
         
            -
                           line);
         
     | 
| 
      
 55 
     | 
    
         
            +
                oj_err_set(&err, oj_parse_error_class, "%s at line %d, column %d [%s:%d]", msg, n, col, file, line);
         
     | 
| 
       67 
56 
     | 
    
         
             
                rb_raise(err.clas, "%s", err.msg);
         
     | 
| 
       68 
57 
     | 
    
         
             
            }
         
     | 
    
        data/ext/oj/err.h
    CHANGED
    
    | 
         @@ -5,6 +5,7 @@ 
     | 
|
| 
       5 
5 
     | 
    
         
             
            #define OJ_ERR_H
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            #include <errno.h>
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       8 
9 
     | 
    
         
             
            #include "ruby.h"
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
11 
     | 
    
         
             
            // Needed to silence 2.4.0 warnings.
         
     | 
| 
         @@ -12,12 +13,12 @@ 
     | 
|
| 
       12 
13 
     | 
    
         
             
            #define NORETURN(x) x
         
     | 
| 
       13 
14 
     | 
    
         
             
            #endif
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
            #define OJ_ERR_START 
     | 
| 
      
 16 
     | 
    
         
            +
            #define OJ_ERR_START 300
         
     | 
| 
       16 
17 
     | 
    
         | 
| 
       17 
18 
     | 
    
         
             
            typedef enum {
         
     | 
| 
       18 
     | 
    
         
            -
                OJ_OK 
     | 
| 
       19 
     | 
    
         
            -
                OJ_ERR_MEMORY 
     | 
| 
       20 
     | 
    
         
            -
                OJ_ERR_PARSE 
     | 
| 
      
 19 
     | 
    
         
            +
                OJ_OK         = 0,
         
     | 
| 
      
 20 
     | 
    
         
            +
                OJ_ERR_MEMORY = ENOMEM,
         
     | 
| 
      
 21 
     | 
    
         
            +
                OJ_ERR_PARSE  = OJ_ERR_START,
         
     | 
| 
       21 
22 
     | 
    
         
             
                OJ_ERR_READ,
         
     | 
| 
       22 
23 
     | 
    
         
             
                OJ_ERR_WRITE,
         
     | 
| 
       23 
24 
     | 
    
         
             
                OJ_ERR_OVERFLOW,
         
     | 
| 
         @@ -29,13 +30,12 @@ typedef enum { 
     | 
|
| 
       29 
30 
     | 
    
         
             
                OJ_ERR_LAST,
         
     | 
| 
       30 
31 
     | 
    
         
             
            } ojStatus;
         
     | 
| 
       31 
32 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
            #define set_error(err, eclas, msg, json, current)  
     | 
| 
       33 
     | 
    
         
            -
                _oj_err_set_with_location(err, eclas, msg, json, current, FILE, LINE)
         
     | 
| 
      
 33 
     | 
    
         
            +
            #define set_error(err, eclas, msg, json, current) _oj_err_set_with_location(err, eclas, msg, json, current, FILE, LINE)
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
            typedef struct _err {
         
     | 
| 
       36 
36 
     | 
    
         
             
                VALUE clas;
         
     | 
| 
       37 
37 
     | 
    
         
             
                char  msg[128];
         
     | 
| 
       38 
     | 
    
         
            -
            } * 
     | 
| 
      
 38 
     | 
    
         
            +
            } *Err;
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
       40 
40 
     | 
    
         
             
            extern VALUE oj_parse_error_class;
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
         @@ -52,11 +52,8 @@ NORETURN(extern void oj_err_raise(Err e)); 
     | 
|
| 
       52 
52 
     | 
    
         | 
| 
       53 
53 
     | 
    
         
             
            #define raise_error(msg, json, current) _oj_raise_error(msg, json, current, __FILE__, __LINE__)
         
     | 
| 
       54 
54 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
            NORETURN( 
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
                                                 const char *current,
         
     | 
| 
       58 
     | 
    
         
            -
                                                 const char *file,
         
     | 
| 
       59 
     | 
    
         
            -
                                                 int         line));
         
     | 
| 
      
 55 
     | 
    
         
            +
            NORETURN(
         
     | 
| 
      
 56 
     | 
    
         
            +
                extern void _oj_raise_error(const char *msg, const char *json, const char *current, const char *file, int line));
         
     | 
| 
       60 
57 
     | 
    
         | 
| 
       61 
58 
     | 
    
         
             
            inline static void err_init(Err e) {
         
     | 
| 
       62 
59 
     | 
    
         
             
                e->clas = Qnil;
         
     | 
    
        data/ext/oj/extconf.rb
    CHANGED
    
    | 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'mkmf'
         
     | 
| 
       2 
4 
     | 
    
         
             
            require 'rbconfig'
         
     | 
| 
       3 
5 
     | 
    
         | 
| 
         @@ -6,7 +8,7 @@ dir_config(extension_name) 
     | 
|
| 
       6 
8 
     | 
    
         | 
| 
       7 
9 
     | 
    
         
             
            parts = RUBY_DESCRIPTION.split(' ')
         
     | 
| 
       8 
10 
     | 
    
         
             
            type = parts[0]
         
     | 
| 
       9 
     | 
    
         
            -
            type = type[4 
     | 
| 
      
 11 
     | 
    
         
            +
            type = type[4..] if type.start_with?('tcs-')
         
     | 
| 
       10 
12 
     | 
    
         
             
            is_windows = RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
         
     | 
| 
       11 
13 
     | 
    
         
             
            platform = RUBY_PLATFORM
         
     | 
| 
       12 
14 
     | 
    
         
             
            version = RUBY_VERSION.split('.')
         
     | 
| 
         @@ -27,19 +29,26 @@ dflags = { 
     | 
|
| 
       27 
29 
     | 
    
         
             
            have_func('rb_gc_mark_movable')
         
     | 
| 
       28 
30 
     | 
    
         
             
            have_func('stpcpy')
         
     | 
| 
       29 
31 
     | 
    
         
             
            have_func('pthread_mutex_init')
         
     | 
| 
      
 32 
     | 
    
         
            +
            have_func('getrlimit', 'sys/resource.h')
         
     | 
| 
       30 
33 
     | 
    
         
             
            have_func('rb_enc_interned_str')
         
     | 
| 
       31 
34 
     | 
    
         
             
            have_func('rb_ext_ractor_safe', 'ruby.h')
         
     | 
| 
       32 
     | 
    
         
            -
            # rb_hash_bulk_insert is deep down in a header not included in normal build and that seems to fool have_func.
         
     | 
| 
       33 
     | 
    
         
            -
            have_func('rb_hash_bulk_insert', 'ruby.h') unless '2' == version[0] && '6' == version[1]
         
     | 
| 
       34 
35 
     | 
    
         | 
| 
       35 
36 
     | 
    
         
             
            dflags['OJ_DEBUG'] = true unless ENV['OJ_DEBUG'].nil?
         
     | 
| 
       36 
37 
     | 
    
         | 
| 
       37 
38 
     | 
    
         
             
            if with_config('--with-sse42')
         
     | 
| 
       38 
     | 
    
         
            -
               
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
      
 39 
     | 
    
         
            +
              if try_cflags('-msse4.2')
         
     | 
| 
      
 40 
     | 
    
         
            +
                $CPPFLAGS += ' -msse4.2'
         
     | 
| 
      
 41 
     | 
    
         
            +
                dflags['OJ_USE_SSE4_2'] = 1
         
     | 
| 
      
 42 
     | 
    
         
            +
              else
         
     | 
| 
      
 43 
     | 
    
         
            +
                warn 'SSE 4.2 is not supported on this platform.'
         
     | 
| 
      
 44 
     | 
    
         
            +
              end
         
     | 
| 
      
 45 
     | 
    
         
            +
            end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            if enable_config('trace-log', false)
         
     | 
| 
      
 48 
     | 
    
         
            +
              dflags['OJ_ENABLE_TRACE_LOG'] = 1
         
     | 
| 
       40 
49 
     | 
    
         
             
            end
         
     | 
| 
       41 
50 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
            dflags.each do |k,v|
         
     | 
| 
      
 51 
     | 
    
         
            +
            dflags.each do |k, v|
         
     | 
| 
       43 
52 
     | 
    
         
             
              if v.nil?
         
     | 
| 
       44 
53 
     | 
    
         
             
                $CPPFLAGS += " -D#{k}"
         
     | 
| 
       45 
54 
     | 
    
         
             
              else
         
     | 
| 
         @@ -48,7 +57,7 @@ dflags.each do |k,v| 
     | 
|
| 
       48 
57 
     | 
    
         
             
            end
         
     | 
| 
       49 
58 
     | 
    
         | 
| 
       50 
59 
     | 
    
         
             
            $CPPFLAGS += ' -Wall'
         
     | 
| 
       51 
     | 
    
         
            -
            #puts "*** $CPPFLAGS: #{$CPPFLAGS}"
         
     | 
| 
      
 60 
     | 
    
         
            +
            # puts "*** $CPPFLAGS: #{$CPPFLAGS}"
         
     | 
| 
       52 
61 
     | 
    
         
             
            # Adding the __attribute__ flag only works with gcc compilers and even then it
         
     | 
| 
       53 
62 
     | 
    
         
             
            # does not work to check args with varargs so just remove the check.
         
     | 
| 
       54 
63 
     | 
    
         
             
            CONFIG['warnflags'].slice!(/ -Wsuggest-attribute=format/)
         
     |