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_compat.c
    CHANGED
    
    | 
         @@ -7,26 +7,24 @@ 
     | 
|
| 
       7 
7 
     | 
    
         
             
            #include "trace.h"
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
            // Workaround in case INFINITY is not defined in math.h or if the OS is CentOS
         
     | 
| 
       10 
     | 
    
         
            -
            #define OJ_INFINITY (1.0/0.0)
         
     | 
| 
      
 10 
     | 
    
         
            +
            #define OJ_INFINITY (1.0 / 0.0)
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
            bool 
     | 
| 
       13 
     | 
    
         
            -
            bool 
     | 
| 
      
 12 
     | 
    
         
            +
            bool oj_use_hash_alt  = false;
         
     | 
| 
      
 13 
     | 
    
         
            +
            bool oj_use_array_alt = false;
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
            static bool 
     | 
| 
       16 
     | 
    
         
            -
            static bool 
     | 
| 
       17 
     | 
    
         
            -
            static bool 
     | 
| 
      
 15 
     | 
    
         
            +
            static bool use_struct_alt    = false;
         
     | 
| 
      
 16 
     | 
    
         
            +
            static bool use_exception_alt = false;
         
     | 
| 
      
 17 
     | 
    
         
            +
            static bool use_bignum_alt    = false;
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
            static void
         
     | 
| 
       20 
     | 
    
         
            -
            raise_json_err(const char *msg, const char *err_classname) {
         
     | 
| 
      
 19 
     | 
    
         
            +
            static void raise_json_err(const char *msg, const char *err_classname) {
         
     | 
| 
       21 
20 
     | 
    
         
             
                rb_raise(oj_get_json_err_class(err_classname), "%s", msg);
         
     | 
| 
       22 
21 
     | 
    
         
             
            }
         
     | 
| 
       23 
22 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
            static void
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                 
     | 
| 
       27 
     | 
    
         
            -
                size_t 
     | 
| 
       28 
     | 
    
         
            -
                size_t 
     | 
| 
       29 
     | 
    
         
            -
                size_t	size = d2 * out->indent + 10 + len + out->opts->create_id_len + sep_len;
         
     | 
| 
      
 23 
     | 
    
         
            +
            static void dump_obj_classname(const char *classname, int depth, Out out) {
         
     | 
| 
      
 24 
     | 
    
         
            +
                int    d2      = depth + 1;
         
     | 
| 
      
 25 
     | 
    
         
            +
                size_t len     = strlen(classname);
         
     | 
| 
      
 26 
     | 
    
         
            +
                size_t sep_len = out->opts->dump_opts.before_size + out->opts->dump_opts.after_size + 2;
         
     | 
| 
      
 27 
     | 
    
         
            +
                size_t size    = d2 * out->indent + 10 + len + out->opts->create_id_len + sep_len;
         
     | 
| 
       30 
28 
     | 
    
         | 
| 
       31 
29 
     | 
    
         
             
                assure_size(out, size);
         
     | 
| 
       32 
30 
     | 
    
         
             
                *out->cur++ = '{';
         
     | 
| 
         @@ -35,93 +33,88 @@ dump_obj_classname(const char *classname, int depth, Out out) { 
     | 
|
| 
       35 
33 
     | 
    
         
             
                APPEND_CHARS(out->cur, out->opts->create_id, out->opts->create_id_len);
         
     | 
| 
       36 
34 
     | 
    
         
             
                *out->cur++ = '"';
         
     | 
| 
       37 
35 
     | 
    
         
             
                if (0 < out->opts->dump_opts.before_size) {
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
      
 36 
     | 
    
         
            +
                    APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
         
     | 
| 
       39 
37 
     | 
    
         
             
                }
         
     | 
| 
       40 
38 
     | 
    
         
             
                *out->cur++ = ':';
         
     | 
| 
       41 
39 
     | 
    
         
             
                if (0 < out->opts->dump_opts.after_size) {
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
                    APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
         
     | 
| 
       43 
41 
     | 
    
         
             
                }
         
     | 
| 
       44 
42 
     | 
    
         
             
                *out->cur++ = '"';
         
     | 
| 
       45 
43 
     | 
    
         
             
                APPEND_CHARS(out->cur, classname, len);
         
     | 
| 
       46 
44 
     | 
    
         
             
                *out->cur++ = '"';
         
     | 
| 
       47 
45 
     | 
    
         
             
            }
         
     | 
| 
       48 
46 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
            static void
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                 
     | 
| 
       52 
     | 
    
         
            -
                int		d2 = depth + 1;
         
     | 
| 
      
 47 
     | 
    
         
            +
            static void dump_values_array(VALUE *values, int depth, Out out) {
         
     | 
| 
      
 48 
     | 
    
         
            +
                size_t size;
         
     | 
| 
      
 49 
     | 
    
         
            +
                int    d2 = depth + 1;
         
     | 
| 
       53 
50 
     | 
    
         | 
| 
       54 
51 
     | 
    
         
             
                assure_size(out, d2 * out->indent + 3);
         
     | 
| 
       55 
52 
     | 
    
         
             
                *out->cur++ = '[';
         
     | 
| 
       56 
53 
     | 
    
         
             
                if (Qundef == *values) {
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
      
 54 
     | 
    
         
            +
                    *out->cur++ = ']';
         
     | 
| 
       58 
55 
     | 
    
         
             
                } else {
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
      
 56 
     | 
    
         
            +
                    if (out->opts->dump_opts.use) {
         
     | 
| 
      
 57 
     | 
    
         
            +
                        size = d2 * out->opts->dump_opts.indent_size + out->opts->dump_opts.array_size + 2;
         
     | 
| 
      
 58 
     | 
    
         
            +
                        size += out->opts->dump_opts.array_size;
         
     | 
| 
      
 59 
     | 
    
         
            +
                        size += out->opts->dump_opts.indent_size;
         
     | 
| 
      
 60 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 61 
     | 
    
         
            +
                        size = d2 * out->indent + 3;
         
     | 
| 
      
 62 
     | 
    
         
            +
                    }
         
     | 
| 
      
 63 
     | 
    
         
            +
                    for (; Qundef != *values; values++) {
         
     | 
| 
      
 64 
     | 
    
         
            +
                        assure_size(out, size);
         
     | 
| 
      
 65 
     | 
    
         
            +
                        if (out->opts->dump_opts.use) {
         
     | 
| 
      
 66 
     | 
    
         
            +
                            if (0 < out->opts->dump_opts.array_size) {
         
     | 
| 
      
 67 
     | 
    
         
            +
                                APPEND_CHARS(out->cur, out->opts->dump_opts.array_nl, out->opts->dump_opts.array_size);
         
     | 
| 
      
 68 
     | 
    
         
            +
                            }
         
     | 
| 
      
 69 
     | 
    
         
            +
                            if (0 < out->opts->dump_opts.indent_size) {
         
     | 
| 
      
 70 
     | 
    
         
            +
                                int i;
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                                for (i = d2; 0 < i; i--) {
         
     | 
| 
      
 73 
     | 
    
         
            +
                                    APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
         
     | 
| 
      
 74 
     | 
    
         
            +
                                }
         
     | 
| 
      
 75 
     | 
    
         
            +
                            }
         
     | 
| 
      
 76 
     | 
    
         
            +
                        } else {
         
     | 
| 
      
 77 
     | 
    
         
            +
                            fill_indent(out, d2);
         
     | 
| 
      
 78 
     | 
    
         
            +
                        }
         
     | 
| 
      
 79 
     | 
    
         
            +
                        oj_dump_compat_val(*values, d2, out, true);
         
     | 
| 
      
 80 
     | 
    
         
            +
                        if (Qundef != *(values + 1)) {
         
     | 
| 
      
 81 
     | 
    
         
            +
                            *out->cur++ = ',';
         
     | 
| 
      
 82 
     | 
    
         
            +
                        }
         
     | 
| 
      
 83 
     | 
    
         
            +
                    }
         
     | 
| 
      
 84 
     | 
    
         
            +
                    assure_size(out, size);
         
     | 
| 
      
 85 
     | 
    
         
            +
                    if (out->opts->dump_opts.use) {
         
     | 
| 
      
 86 
     | 
    
         
            +
                        if (0 < out->opts->dump_opts.array_size) {
         
     | 
| 
      
 87 
     | 
    
         
            +
                            APPEND_CHARS(out->cur, out->opts->dump_opts.array_nl, out->opts->dump_opts.array_size);
         
     | 
| 
      
 88 
     | 
    
         
            +
                        }
         
     | 
| 
      
 89 
     | 
    
         
            +
                        if (0 < out->opts->dump_opts.indent_size) {
         
     | 
| 
      
 90 
     | 
    
         
            +
                            int i;
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                            for (i = depth; 0 < i; i--) {
         
     | 
| 
      
 93 
     | 
    
         
            +
                                APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
         
     | 
| 
      
 94 
     | 
    
         
            +
                            }
         
     | 
| 
      
 95 
     | 
    
         
            +
                        }
         
     | 
| 
      
 96 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 97 
     | 
    
         
            +
                        fill_indent(out, depth);
         
     | 
| 
      
 98 
     | 
    
         
            +
                    }
         
     | 
| 
      
 99 
     | 
    
         
            +
                    *out->cur++ = ']';
         
     | 
| 
       103 
100 
     | 
    
         
             
                }
         
     | 
| 
       104 
101 
     | 
    
         
             
            }
         
     | 
| 
       105 
102 
     | 
    
         | 
| 
       106 
     | 
    
         
            -
            static void
         
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
                 
     | 
| 
       109 
     | 
    
         
            -
                 
     | 
| 
       110 
     | 
    
         
            -
                int			len;
         
     | 
| 
      
 103 
     | 
    
         
            +
            static void dump_to_json(VALUE obj, Out out) {
         
     | 
| 
      
 104 
     | 
    
         
            +
                volatile VALUE rs;
         
     | 
| 
      
 105 
     | 
    
         
            +
                const char    *s;
         
     | 
| 
      
 106 
     | 
    
         
            +
                int            len;
         
     | 
| 
       111 
107 
     | 
    
         | 
| 
       112 
     | 
    
         
            -
                 
     | 
| 
       113 
     | 
    
         
            -
            	oj_trace("to_json", obj, __FILE__, __LINE__, 0, TraceRubyIn);
         
     | 
| 
       114 
     | 
    
         
            -
                }
         
     | 
| 
      
 108 
     | 
    
         
            +
                TRACE(out->opts->trace, "to_json", obj, 0, TraceRubyIn);
         
     | 
| 
       115 
109 
     | 
    
         
             
                if (0 == rb_obj_method_arity(obj, oj_to_json_id)) {
         
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
      
 110 
     | 
    
         
            +
                    rs = rb_funcall(obj, oj_to_json_id, 0);
         
     | 
| 
       117 
111 
     | 
    
         
             
                } else {
         
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
                }
         
     | 
| 
       120 
     | 
    
         
            -
                if (RB_UNLIKELY(Yes == out->opts->trace)) {
         
     | 
| 
       121 
     | 
    
         
            -
            	oj_trace("to_json", obj, __FILE__, __LINE__, 0, TraceRubyOut);
         
     | 
| 
      
 112 
     | 
    
         
            +
                    rs = rb_funcall2(obj, oj_to_json_id, out->argc, out->argv);
         
     | 
| 
       122 
113 
     | 
    
         
             
                }
         
     | 
| 
      
 114 
     | 
    
         
            +
                TRACE(out->opts->trace, "to_json", obj, 0, TraceRubyOut);
         
     | 
| 
       123 
115 
     | 
    
         | 
| 
       124 
     | 
    
         
            -
                 
     | 
| 
      
 116 
     | 
    
         
            +
                StringValue(rs);
         
     | 
| 
      
 117 
     | 
    
         
            +
                s   = RSTRING_PTR(rs);
         
     | 
| 
       125 
118 
     | 
    
         
             
                len = (int)RSTRING_LEN(rs);
         
     | 
| 
       126 
119 
     | 
    
         | 
| 
       127 
120 
     | 
    
         
             
                assure_size(out, len + 1);
         
     | 
| 
         @@ -129,107 +122,104 @@ dump_to_json(VALUE obj, Out out) { 
     | 
|
| 
       129 
122 
     | 
    
         
             
                *out->cur = '\0';
         
     | 
| 
       130 
123 
     | 
    
         
             
            }
         
     | 
| 
       131 
124 
     | 
    
         | 
| 
       132 
     | 
    
         
            -
            static void
         
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
                 
     | 
| 
       135 
     | 
    
         
            -
                int 
     | 
| 
       136 
     | 
    
         
            -
                 
     | 
| 
       137 
     | 
    
         
            -
                long	id = oj_check_circular(a, out);
         
     | 
| 
      
 125 
     | 
    
         
            +
            static void dump_array(VALUE a, int depth, Out out, bool as_ok) {
         
     | 
| 
      
 126 
     | 
    
         
            +
                size_t size;
         
     | 
| 
      
 127 
     | 
    
         
            +
                int    i, cnt;
         
     | 
| 
      
 128 
     | 
    
         
            +
                int    d2 = depth + 1;
         
     | 
| 
      
 129 
     | 
    
         
            +
                long   id = oj_check_circular(a, out);
         
     | 
| 
       138 
130 
     | 
    
         | 
| 
       139 
131 
     | 
    
         
             
                if (0 > id) {
         
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
      
 132 
     | 
    
         
            +
                    raise_json_err("Too deeply nested", "NestingError");
         
     | 
| 
      
 133 
     | 
    
         
            +
                    return;
         
     | 
| 
       142 
134 
     | 
    
         
             
                }
         
     | 
| 
       143 
     | 
    
         
            -
                if (as_ok && ! 
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
      
 135 
     | 
    
         
            +
                if (as_ok && !oj_use_array_alt && rb_obj_class(a) != rb_cArray && rb_respond_to(a, oj_to_json_id)) {
         
     | 
| 
      
 136 
     | 
    
         
            +
                    dump_to_json(a, out);
         
     | 
| 
      
 137 
     | 
    
         
            +
                    return;
         
     | 
| 
       146 
138 
     | 
    
         
             
                }
         
     | 
| 
       147 
     | 
    
         
            -
                cnt 
     | 
| 
      
 139 
     | 
    
         
            +
                cnt         = (int)RARRAY_LEN(a);
         
     | 
| 
       148 
140 
     | 
    
         
             
                *out->cur++ = '[';
         
     | 
| 
       149 
141 
     | 
    
         
             
                assure_size(out, 2);
         
     | 
| 
       150 
142 
     | 
    
         
             
                if (0 == cnt) {
         
     | 
| 
       151 
     | 
    
         
            -
             
     | 
| 
      
 143 
     | 
    
         
            +
                    *out->cur++ = ']';
         
     | 
| 
       152 
144 
     | 
    
         
             
                } else {
         
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
             
     | 
| 
       160 
     | 
    
         
            -
             
     | 
| 
       161 
     | 
    
         
            -
             
     | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
       165 
     | 
    
         
            -
             
     | 
| 
       166 
     | 
    
         
            -
             
     | 
| 
       167 
     | 
    
         
            -
             
     | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
       169 
     | 
    
         
            -
             
     | 
| 
       170 
     | 
    
         
            -
             
     | 
| 
       171 
     | 
    
         
            -
             
     | 
| 
       172 
     | 
    
         
            -
             
     | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
       174 
     | 
    
         
            -
             
     | 
| 
       175 
     | 
    
         
            -
             
     | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
       177 
     | 
    
         
            -
             
     | 
| 
       178 
     | 
    
         
            -
             
     | 
| 
       179 
     | 
    
         
            -
             
     | 
| 
       180 
     | 
    
         
            -
             
     | 
| 
       181 
     | 
    
         
            -
             
     | 
| 
       182 
     | 
    
         
            -
             
     | 
| 
       183 
     | 
    
         
            -
             
     | 
| 
       184 
     | 
    
         
            -
             
     | 
| 
       185 
     | 
    
         
            -
             
     | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
       188 
     | 
    
         
            -
             
     | 
| 
       189 
     | 
    
         
            -
             
     | 
| 
       190 
     | 
    
         
            -
             
     | 
| 
       191 
     | 
    
         
            -
             
     | 
| 
       192 
     | 
    
         
            -
             
     | 
| 
       193 
     | 
    
         
            -
             
     | 
| 
       194 
     | 
    
         
            -
             
     | 
| 
       195 
     | 
    
         
            -
             
     | 
| 
       196 
     | 
    
         
            -
             
     | 
| 
       197 
     | 
    
         
            -
             
     | 
| 
      
 145 
     | 
    
         
            +
                    if (out->opts->dump_opts.use) {
         
     | 
| 
      
 146 
     | 
    
         
            +
                        size = d2 * out->opts->dump_opts.indent_size + out->opts->dump_opts.array_size + 1;
         
     | 
| 
      
 147 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 148 
     | 
    
         
            +
                        size = d2 * out->indent + 2;
         
     | 
| 
      
 149 
     | 
    
         
            +
                    }
         
     | 
| 
      
 150 
     | 
    
         
            +
                    assure_size(out, size * cnt);
         
     | 
| 
      
 151 
     | 
    
         
            +
                    cnt--;
         
     | 
| 
      
 152 
     | 
    
         
            +
                    for (i = 0; i <= cnt; i++) {
         
     | 
| 
      
 153 
     | 
    
         
            +
                        if (out->opts->dump_opts.use) {
         
     | 
| 
      
 154 
     | 
    
         
            +
                            if (0 < out->opts->dump_opts.array_size) {
         
     | 
| 
      
 155 
     | 
    
         
            +
                                APPEND_CHARS(out->cur, out->opts->dump_opts.array_nl, out->opts->dump_opts.array_size);
         
     | 
| 
      
 156 
     | 
    
         
            +
                            }
         
     | 
| 
      
 157 
     | 
    
         
            +
                            if (0 < out->opts->dump_opts.indent_size) {
         
     | 
| 
      
 158 
     | 
    
         
            +
                                int i;
         
     | 
| 
      
 159 
     | 
    
         
            +
                                for (i = d2; 0 < i; i--) {
         
     | 
| 
      
 160 
     | 
    
         
            +
                                    APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
         
     | 
| 
      
 161 
     | 
    
         
            +
                                }
         
     | 
| 
      
 162 
     | 
    
         
            +
                            }
         
     | 
| 
      
 163 
     | 
    
         
            +
                        } else {
         
     | 
| 
      
 164 
     | 
    
         
            +
                            fill_indent(out, d2);
         
     | 
| 
      
 165 
     | 
    
         
            +
                        }
         
     | 
| 
      
 166 
     | 
    
         
            +
                        oj_dump_compat_val(RARRAY_AREF(a, i), d2, out, true);
         
     | 
| 
      
 167 
     | 
    
         
            +
                        if (i < cnt) {
         
     | 
| 
      
 168 
     | 
    
         
            +
                            *out->cur++ = ',';
         
     | 
| 
      
 169 
     | 
    
         
            +
                        }
         
     | 
| 
      
 170 
     | 
    
         
            +
                    }
         
     | 
| 
      
 171 
     | 
    
         
            +
                    if (out->opts->dump_opts.use) {
         
     | 
| 
      
 172 
     | 
    
         
            +
                        size = out->opts->dump_opts.array_size + out->opts->dump_opts.indent_size * depth + 1;
         
     | 
| 
      
 173 
     | 
    
         
            +
                        assure_size(out, size);
         
     | 
| 
      
 174 
     | 
    
         
            +
                        if (0 < out->opts->dump_opts.array_size) {
         
     | 
| 
      
 175 
     | 
    
         
            +
                            APPEND_CHARS(out->cur, out->opts->dump_opts.array_nl, out->opts->dump_opts.array_size);
         
     | 
| 
      
 176 
     | 
    
         
            +
                        }
         
     | 
| 
      
 177 
     | 
    
         
            +
                        if (0 < out->opts->dump_opts.indent_size) {
         
     | 
| 
      
 178 
     | 
    
         
            +
                            int i;
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
                            for (i = depth; 0 < i; i--) {
         
     | 
| 
      
 181 
     | 
    
         
            +
                                APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
         
     | 
| 
      
 182 
     | 
    
         
            +
                            }
         
     | 
| 
      
 183 
     | 
    
         
            +
                        }
         
     | 
| 
      
 184 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 185 
     | 
    
         
            +
                        size = depth * out->indent + 1;
         
     | 
| 
      
 186 
     | 
    
         
            +
                        assure_size(out, size);
         
     | 
| 
      
 187 
     | 
    
         
            +
                        fill_indent(out, depth);
         
     | 
| 
      
 188 
     | 
    
         
            +
                    }
         
     | 
| 
      
 189 
     | 
    
         
            +
                    *out->cur++ = ']';
         
     | 
| 
       198 
190 
     | 
    
         
             
                }
         
     | 
| 
       199 
191 
     | 
    
         
             
                *out->cur = '\0';
         
     | 
| 
       200 
192 
     | 
    
         
             
            }
         
     | 
| 
       201 
193 
     | 
    
         | 
| 
       202 
     | 
    
         
            -
            static ID 
     | 
| 
      
 194 
     | 
    
         
            +
            static ID _dump_id = 0;
         
     | 
| 
       203 
195 
     | 
    
         | 
| 
       204 
     | 
    
         
            -
            static void
         
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
       206 
     | 
    
         
            -
             
     | 
| 
       207 
     | 
    
         
            -
             
     | 
| 
       208 
     | 
    
         
            -
            	{ NULL, 0, Qnil },
         
     | 
| 
      
 196 
     | 
    
         
            +
            static void bigdecimal_alt(VALUE obj, int depth, Out out) {
         
     | 
| 
      
 197 
     | 
    
         
            +
                struct _attr attrs[] = {
         
     | 
| 
      
 198 
     | 
    
         
            +
                    {"b", 1, Qnil},
         
     | 
| 
      
 199 
     | 
    
         
            +
                    {NULL, 0, Qnil},
         
     | 
| 
       209 
200 
     | 
    
         
             
                };
         
     | 
| 
       210 
201 
     | 
    
         | 
| 
       211 
202 
     | 
    
         
             
                if (0 == _dump_id) {
         
     | 
| 
       212 
     | 
    
         
            -
             
     | 
| 
      
 203 
     | 
    
         
            +
                    _dump_id = rb_intern("_dump");
         
     | 
| 
       213 
204 
     | 
    
         
             
                }
         
     | 
| 
       214 
205 
     | 
    
         
             
                attrs[0].value = rb_funcall(obj, _dump_id, 0);
         
     | 
| 
       215 
206 
     | 
    
         | 
| 
       216 
207 
     | 
    
         
             
                oj_code_attrs(obj, attrs, depth, out, true);
         
     | 
| 
       217 
208 
     | 
    
         
             
            }
         
     | 
| 
       218 
209 
     | 
    
         | 
| 
       219 
     | 
    
         
            -
            static ID 
     | 
| 
       220 
     | 
    
         
            -
            static ID 
     | 
| 
      
 210 
     | 
    
         
            +
            static ID real_id = 0;
         
     | 
| 
      
 211 
     | 
    
         
            +
            static ID imag_id = 0;
         
     | 
| 
       221 
212 
     | 
    
         | 
| 
       222 
     | 
    
         
            -
            static void
         
     | 
| 
       223 
     | 
    
         
            -
             
     | 
| 
       224 
     | 
    
         
            -
             
     | 
| 
       225 
     | 
    
         
            -
             
     | 
| 
       226 
     | 
    
         
            -
             
     | 
| 
       227 
     | 
    
         
            -
            	{ NULL, 0, Qnil },
         
     | 
| 
      
 213 
     | 
    
         
            +
            static void complex_alt(VALUE obj, int depth, Out out) {
         
     | 
| 
      
 214 
     | 
    
         
            +
                struct _attr attrs[] = {
         
     | 
| 
      
 215 
     | 
    
         
            +
                    {"r", 1, Qnil},
         
     | 
| 
      
 216 
     | 
    
         
            +
                    {"i", 1, Qnil},
         
     | 
| 
      
 217 
     | 
    
         
            +
                    {NULL, 0, Qnil},
         
     | 
| 
       228 
218 
     | 
    
         
             
                };
         
     | 
| 
       229 
219 
     | 
    
         | 
| 
       230 
220 
     | 
    
         
             
                if (0 == real_id) {
         
     | 
| 
       231 
     | 
    
         
            -
             
     | 
| 
       232 
     | 
    
         
            -
             
     | 
| 
      
 221 
     | 
    
         
            +
                    real_id = rb_intern("real");
         
     | 
| 
      
 222 
     | 
    
         
            +
                    imag_id = rb_intern("imag");
         
     | 
| 
       233 
223 
     | 
    
         
             
                }
         
     | 
| 
       234 
224 
     | 
    
         
             
                attrs[0].value = rb_funcall(obj, real_id, 0);
         
     | 
| 
       235 
225 
     | 
    
         
             
                attrs[1].value = rb_funcall(obj, imag_id, 0);
         
     | 
| 
         @@ -237,25 +227,24 @@ complex_alt(VALUE obj, int depth, Out out) { 
     | 
|
| 
       237 
227 
     | 
    
         
             
                oj_code_attrs(obj, attrs, depth, out, true);
         
     | 
| 
       238 
228 
     | 
    
         
             
            }
         
     | 
| 
       239 
229 
     | 
    
         | 
| 
       240 
     | 
    
         
            -
            static ID 
     | 
| 
       241 
     | 
    
         
            -
            static ID 
     | 
| 
       242 
     | 
    
         
            -
            static ID 
     | 
| 
       243 
     | 
    
         
            -
            static ID 
     | 
| 
       244 
     | 
    
         
            -
             
     | 
| 
       245 
     | 
    
         
            -
            static void
         
     | 
| 
       246 
     | 
    
         
            -
             
     | 
| 
       247 
     | 
    
         
            -
             
     | 
| 
       248 
     | 
    
         
            -
             
     | 
| 
       249 
     | 
    
         
            -
             
     | 
| 
       250 
     | 
    
         
            -
             
     | 
| 
       251 
     | 
    
         
            -
             
     | 
| 
       252 
     | 
    
         
            -
            	{ NULL, 0, Qnil },
         
     | 
| 
      
 230 
     | 
    
         
            +
            static ID year_id  = 0;
         
     | 
| 
      
 231 
     | 
    
         
            +
            static ID month_id = 0;
         
     | 
| 
      
 232 
     | 
    
         
            +
            static ID day_id   = 0;
         
     | 
| 
      
 233 
     | 
    
         
            +
            static ID start_id = 0;
         
     | 
| 
      
 234 
     | 
    
         
            +
             
     | 
| 
      
 235 
     | 
    
         
            +
            static void date_alt(VALUE obj, int depth, Out out) {
         
     | 
| 
      
 236 
     | 
    
         
            +
                struct _attr attrs[] = {
         
     | 
| 
      
 237 
     | 
    
         
            +
                    {"y", 1, Qnil},
         
     | 
| 
      
 238 
     | 
    
         
            +
                    {"m", 1, Qnil},
         
     | 
| 
      
 239 
     | 
    
         
            +
                    {"d", 1, Qnil},
         
     | 
| 
      
 240 
     | 
    
         
            +
                    {"sg", 2, Qnil},
         
     | 
| 
      
 241 
     | 
    
         
            +
                    {NULL, 0, Qnil},
         
     | 
| 
       253 
242 
     | 
    
         
             
                };
         
     | 
| 
       254 
243 
     | 
    
         
             
                if (0 == year_id) {
         
     | 
| 
       255 
     | 
    
         
            -
             
     | 
| 
       256 
     | 
    
         
            -
             
     | 
| 
       257 
     | 
    
         
            -
             
     | 
| 
       258 
     | 
    
         
            -
             
     | 
| 
      
 244 
     | 
    
         
            +
                    year_id  = rb_intern("year");
         
     | 
| 
      
 245 
     | 
    
         
            +
                    month_id = rb_intern("month");
         
     | 
| 
      
 246 
     | 
    
         
            +
                    day_id   = rb_intern("day");
         
     | 
| 
      
 247 
     | 
    
         
            +
                    start_id = rb_intern("start");
         
     | 
| 
       259 
248 
     | 
    
         
             
                }
         
     | 
| 
       260 
249 
     | 
    
         
             
                attrs[0].value = rb_funcall(obj, year_id, 0);
         
     | 
| 
       261 
250 
     | 
    
         
             
                attrs[1].value = rb_funcall(obj, month_id, 0);
         
     | 
| 
         @@ -265,33 +254,32 @@ date_alt(VALUE obj, int depth, Out out) { 
     | 
|
| 
       265 
254 
     | 
    
         
             
                oj_code_attrs(obj, attrs, depth, out, true);
         
     | 
| 
       266 
255 
     | 
    
         
             
            }
         
     | 
| 
       267 
256 
     | 
    
         | 
| 
       268 
     | 
    
         
            -
            static ID 
     | 
| 
       269 
     | 
    
         
            -
            static ID 
     | 
| 
       270 
     | 
    
         
            -
            static ID 
     | 
| 
       271 
     | 
    
         
            -
            static ID 
     | 
| 
       272 
     | 
    
         
            -
             
     | 
| 
       273 
     | 
    
         
            -
            static void
         
     | 
| 
       274 
     | 
    
         
            -
             
     | 
| 
       275 
     | 
    
         
            -
             
     | 
| 
       276 
     | 
    
         
            -
             
     | 
| 
       277 
     | 
    
         
            -
             
     | 
| 
       278 
     | 
    
         
            -
             
     | 
| 
       279 
     | 
    
         
            -
             
     | 
| 
       280 
     | 
    
         
            -
             
     | 
| 
       281 
     | 
    
         
            -
             
     | 
| 
       282 
     | 
    
         
            -
             
     | 
| 
       283 
     | 
    
         
            -
             
     | 
| 
       284 
     | 
    
         
            -
            	{ NULL, 0, Qnil },
         
     | 
| 
      
 257 
     | 
    
         
            +
            static ID hour_id   = 0;
         
     | 
| 
      
 258 
     | 
    
         
            +
            static ID min_id    = 0;
         
     | 
| 
      
 259 
     | 
    
         
            +
            static ID sec_id    = 0;
         
     | 
| 
      
 260 
     | 
    
         
            +
            static ID offset_id = 0;
         
     | 
| 
      
 261 
     | 
    
         
            +
             
     | 
| 
      
 262 
     | 
    
         
            +
            static void datetime_alt(VALUE obj, int depth, Out out) {
         
     | 
| 
      
 263 
     | 
    
         
            +
                struct _attr attrs[] = {
         
     | 
| 
      
 264 
     | 
    
         
            +
                    {"y", 1, Qnil},
         
     | 
| 
      
 265 
     | 
    
         
            +
                    {"m", 1, Qnil},
         
     | 
| 
      
 266 
     | 
    
         
            +
                    {"d", 1, Qnil},
         
     | 
| 
      
 267 
     | 
    
         
            +
                    {"H", 1, Qnil},
         
     | 
| 
      
 268 
     | 
    
         
            +
                    {"M", 1, Qnil},
         
     | 
| 
      
 269 
     | 
    
         
            +
                    {"S", 1, Qnil},
         
     | 
| 
      
 270 
     | 
    
         
            +
                    {"of", 2, Qnil},
         
     | 
| 
      
 271 
     | 
    
         
            +
                    {"sg", 2, Qnil},
         
     | 
| 
      
 272 
     | 
    
         
            +
                    {NULL, 0, Qnil},
         
     | 
| 
       285 
273 
     | 
    
         
             
                };
         
     | 
| 
       286 
274 
     | 
    
         
             
                if (0 == hour_id) {
         
     | 
| 
       287 
     | 
    
         
            -
             
     | 
| 
       288 
     | 
    
         
            -
             
     | 
| 
       289 
     | 
    
         
            -
             
     | 
| 
       290 
     | 
    
         
            -
             
     | 
| 
       291 
     | 
    
         
            -
             
     | 
| 
       292 
     | 
    
         
            -
             
     | 
| 
       293 
     | 
    
         
            -
             
     | 
| 
       294 
     | 
    
         
            -
             
     | 
| 
      
 275 
     | 
    
         
            +
                    year_id   = rb_intern("year");
         
     | 
| 
      
 276 
     | 
    
         
            +
                    month_id  = rb_intern("month");
         
     | 
| 
      
 277 
     | 
    
         
            +
                    day_id    = rb_intern("day");
         
     | 
| 
      
 278 
     | 
    
         
            +
                    hour_id   = rb_intern("hour");
         
     | 
| 
      
 279 
     | 
    
         
            +
                    min_id    = rb_intern("min");
         
     | 
| 
      
 280 
     | 
    
         
            +
                    sec_id    = rb_intern("sec");
         
     | 
| 
      
 281 
     | 
    
         
            +
                    offset_id = rb_intern("offset");
         
     | 
| 
      
 282 
     | 
    
         
            +
                    start_id  = rb_intern("start");
         
     | 
| 
       295 
283 
     | 
    
         
             
                }
         
     | 
| 
       296 
284 
     | 
    
         
             
                attrs[0].value = rb_funcall(obj, year_id, 0);
         
     | 
| 
       297 
285 
     | 
    
         
             
                attrs[1].value = rb_funcall(obj, month_id, 0);
         
     | 
| 
         @@ -299,24 +287,23 @@ datetime_alt(VALUE obj, int depth, Out out) { 
     | 
|
| 
       299 
287 
     | 
    
         
             
                attrs[3].value = rb_funcall(obj, hour_id, 0);
         
     | 
| 
       300 
288 
     | 
    
         
             
                attrs[4].value = rb_funcall(obj, min_id, 0);
         
     | 
| 
       301 
289 
     | 
    
         
             
                attrs[5].value = rb_funcall(obj, sec_id, 0);
         
     | 
| 
       302 
     | 
    
         
            -
                attrs[6].value =  
     | 
| 
      
 290 
     | 
    
         
            +
                attrs[6].value = oj_safe_string_convert(rb_funcall(obj, offset_id, 0));
         
     | 
| 
       303 
291 
     | 
    
         
             
                attrs[7].value = rb_funcall(obj, start_id, 0);
         
     | 
| 
       304 
292 
     | 
    
         | 
| 
       305 
293 
     | 
    
         
             
                oj_code_attrs(obj, attrs, depth, out, true);
         
     | 
| 
       306 
294 
     | 
    
         
             
            }
         
     | 
| 
       307 
295 
     | 
    
         | 
| 
       308 
     | 
    
         
            -
            static ID 
     | 
| 
       309 
     | 
    
         
            -
            static ID 
     | 
| 
      
 296 
     | 
    
         
            +
            static ID message_id   = 0;
         
     | 
| 
      
 297 
     | 
    
         
            +
            static ID backtrace_id = 0;
         
     | 
| 
       310 
298 
     | 
    
         | 
| 
       311 
     | 
    
         
            -
            static void
         
     | 
| 
       312 
     | 
    
         
            -
             
     | 
| 
       313 
     | 
    
         
            -
                 
     | 
| 
       314 
     | 
    
         
            -
                size_t 
     | 
| 
       315 
     | 
    
         
            -
                size_t	sep_len = out->opts->dump_opts.before_size + out->opts->dump_opts.after_size + 2;
         
     | 
| 
      
 299 
     | 
    
         
            +
            static void exception_alt(VALUE obj, int depth, Out out) {
         
     | 
| 
      
 300 
     | 
    
         
            +
                int    d3      = depth + 2;
         
     | 
| 
      
 301 
     | 
    
         
            +
                size_t size    = d3 * out->indent + 2;
         
     | 
| 
      
 302 
     | 
    
         
            +
                size_t sep_len = out->opts->dump_opts.before_size + out->opts->dump_opts.after_size + 2;
         
     | 
| 
       316 
303 
     | 
    
         | 
| 
       317 
304 
     | 
    
         
             
                if (0 == message_id) {
         
     | 
| 
       318 
     | 
    
         
            -
             
     | 
| 
       319 
     | 
    
         
            -
             
     | 
| 
      
 305 
     | 
    
         
            +
                    message_id   = rb_intern("message");
         
     | 
| 
      
 306 
     | 
    
         
            +
                    backtrace_id = rb_intern("backtrace");
         
     | 
| 
       320 
307 
     | 
    
         
             
                }
         
     | 
| 
       321 
308 
     | 
    
         
             
                dump_obj_classname(rb_class2name(rb_obj_class(obj)), depth, out);
         
     | 
| 
       322 
309 
     | 
    
         | 
| 
         @@ -325,11 +312,11 @@ exception_alt(VALUE obj, int depth, Out out) { 
     | 
|
| 
       325 
312 
     | 
    
         
             
                fill_indent(out, d3);
         
     | 
| 
       326 
313 
     | 
    
         
             
                APPEND_CHARS(out->cur, "\"m\"", 3);
         
     | 
| 
       327 
314 
     | 
    
         
             
                if (0 < out->opts->dump_opts.before_size) {
         
     | 
| 
       328 
     | 
    
         
            -
             
     | 
| 
      
 315 
     | 
    
         
            +
                    APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
         
     | 
| 
       329 
316 
     | 
    
         
             
                }
         
     | 
| 
       330 
317 
     | 
    
         
             
                *out->cur++ = ':';
         
     | 
| 
       331 
318 
     | 
    
         
             
                if (0 < out->opts->dump_opts.after_size) {
         
     | 
| 
       332 
     | 
    
         
            -
             
     | 
| 
      
 319 
     | 
    
         
            +
                    APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
         
     | 
| 
       333 
320 
     | 
    
         
             
                }
         
     | 
| 
       334 
321 
     | 
    
         
             
                oj_dump_str(rb_funcall(obj, message_id, 0), 0, out, false);
         
     | 
| 
       335 
322 
     | 
    
         
             
                assure_size(out, size + sep_len + 6);
         
     | 
| 
         @@ -337,40 +324,38 @@ exception_alt(VALUE obj, int depth, Out out) { 
     | 
|
| 
       337 
324 
     | 
    
         
             
                fill_indent(out, d3);
         
     | 
| 
       338 
325 
     | 
    
         
             
                APPEND_CHARS(out->cur, "\"b\"", 3);
         
     | 
| 
       339 
326 
     | 
    
         
             
                if (0 < out->opts->dump_opts.before_size) {
         
     | 
| 
       340 
     | 
    
         
            -
             
     | 
| 
      
 327 
     | 
    
         
            +
                    APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
         
     | 
| 
       341 
328 
     | 
    
         
             
                }
         
     | 
| 
       342 
329 
     | 
    
         
             
                *out->cur++ = ':';
         
     | 
| 
       343 
330 
     | 
    
         
             
                if (0 < out->opts->dump_opts.after_size) {
         
     | 
| 
       344 
     | 
    
         
            -
             
     | 
| 
      
 331 
     | 
    
         
            +
                    APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
         
     | 
| 
       345 
332 
     | 
    
         
             
                }
         
     | 
| 
       346 
333 
     | 
    
         
             
                dump_array(rb_funcall(obj, backtrace_id, 0), depth, out, false);
         
     | 
| 
       347 
334 
     | 
    
         
             
                fill_indent(out, depth);
         
     | 
| 
       348 
335 
     | 
    
         
             
                *out->cur++ = '}';
         
     | 
| 
       349 
     | 
    
         
            -
                *out->cur 
     | 
| 
      
 336 
     | 
    
         
            +
                *out->cur   = '\0';
         
     | 
| 
       350 
337 
     | 
    
         
             
            }
         
     | 
| 
       351 
338 
     | 
    
         | 
| 
       352 
     | 
    
         
            -
            static ID 
     | 
| 
      
 339 
     | 
    
         
            +
            static ID table_id = 0;
         
     | 
| 
       353 
340 
     | 
    
         | 
| 
       354 
     | 
    
         
            -
            static void
         
     | 
| 
       355 
     | 
    
         
            -
             
     | 
| 
       356 
     | 
    
         
            -
             
     | 
| 
       357 
     | 
    
         
            -
             
     | 
| 
       358 
     | 
    
         
            -
            	{ NULL, 0, Qnil },
         
     | 
| 
      
 341 
     | 
    
         
            +
            static void openstruct_alt(VALUE obj, int depth, Out out) {
         
     | 
| 
      
 342 
     | 
    
         
            +
                struct _attr attrs[] = {
         
     | 
| 
      
 343 
     | 
    
         
            +
                    {"t", 1, Qnil},
         
     | 
| 
      
 344 
     | 
    
         
            +
                    {NULL, 0, Qnil},
         
     | 
| 
       359 
345 
     | 
    
         
             
                };
         
     | 
| 
       360 
346 
     | 
    
         
             
                if (0 == table_id) {
         
     | 
| 
       361 
     | 
    
         
            -
             
     | 
| 
      
 347 
     | 
    
         
            +
                    table_id = rb_intern("table");
         
     | 
| 
       362 
348 
     | 
    
         
             
                }
         
     | 
| 
       363 
349 
     | 
    
         
             
                attrs[0].value = rb_funcall(obj, table_id, 0);
         
     | 
| 
       364 
350 
     | 
    
         | 
| 
       365 
351 
     | 
    
         
             
                oj_code_attrs(obj, attrs, depth, out, true);
         
     | 
| 
       366 
352 
     | 
    
         
             
            }
         
     | 
| 
       367 
353 
     | 
    
         | 
| 
       368 
     | 
    
         
            -
            static void
         
     | 
| 
       369 
     | 
    
         
            -
             
     | 
| 
       370 
     | 
    
         
            -
                 
     | 
| 
       371 
     | 
    
         
            -
                size_t 
     | 
| 
       372 
     | 
    
         
            -
                 
     | 
| 
       373 
     | 
    
         
            -
                VALUE	args[] = { Qundef, Qundef, Qundef, Qundef };
         
     | 
| 
      
 354 
     | 
    
         
            +
            static void range_alt(VALUE obj, int depth, Out out) {
         
     | 
| 
      
 355 
     | 
    
         
            +
                int    d3      = depth + 2;
         
     | 
| 
      
 356 
     | 
    
         
            +
                size_t size    = d3 * out->indent + 2;
         
     | 
| 
      
 357 
     | 
    
         
            +
                size_t sep_len = out->opts->dump_opts.before_size + out->opts->dump_opts.after_size + 2;
         
     | 
| 
      
 358 
     | 
    
         
            +
                VALUE  args[]  = {Qundef, Qundef, Qundef, Qundef};
         
     | 
| 
       374 
359 
     | 
    
         | 
| 
       375 
360 
     | 
    
         
             
                dump_obj_classname(rb_class2name(rb_obj_class(obj)), depth, out);
         
     | 
| 
       376 
361 
     | 
    
         | 
| 
         @@ -379,11 +364,11 @@ range_alt(VALUE obj, int depth, Out out) { 
     | 
|
| 
       379 
364 
     | 
    
         
             
                fill_indent(out, d3);
         
     | 
| 
       380 
365 
     | 
    
         
             
                APPEND_CHARS(out->cur, "\"a\"", 3);
         
     | 
| 
       381 
366 
     | 
    
         
             
                if (0 < out->opts->dump_opts.before_size) {
         
     | 
| 
       382 
     | 
    
         
            -
             
     | 
| 
      
 367 
     | 
    
         
            +
                    APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
         
     | 
| 
       383 
368 
     | 
    
         
             
                }
         
     | 
| 
       384 
369 
     | 
    
         
             
                *out->cur++ = ':';
         
     | 
| 
       385 
370 
     | 
    
         
             
                if (0 < out->opts->dump_opts.after_size) {
         
     | 
| 
       386 
     | 
    
         
            -
             
     | 
| 
      
 371 
     | 
    
         
            +
                    APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
         
     | 
| 
       387 
372 
     | 
    
         
             
                }
         
     | 
| 
       388 
373 
     | 
    
         
             
                args[0] = rb_funcall(obj, oj_begin_id, 0);
         
     | 
| 
       389 
374 
     | 
    
         
             
                args[1] = rb_funcall(obj, oj_end_id, 0);
         
     | 
| 
         @@ -391,22 +376,21 @@ range_alt(VALUE obj, int depth, Out out) { 
     | 
|
| 
       391 
376 
     | 
    
         
             
                dump_values_array(args, depth, out);
         
     | 
| 
       392 
377 
     | 
    
         
             
                fill_indent(out, depth);
         
     | 
| 
       393 
378 
     | 
    
         
             
                *out->cur++ = '}';
         
     | 
| 
       394 
     | 
    
         
            -
                *out->cur 
     | 
| 
      
 379 
     | 
    
         
            +
                *out->cur   = '\0';
         
     | 
| 
       395 
380 
     | 
    
         
             
            }
         
     | 
| 
       396 
381 
     | 
    
         | 
| 
       397 
     | 
    
         
            -
            static ID 
     | 
| 
       398 
     | 
    
         
            -
            static ID 
     | 
| 
      
 382 
     | 
    
         
            +
            static ID numerator_id   = 0;
         
     | 
| 
      
 383 
     | 
    
         
            +
            static ID denominator_id = 0;
         
     | 
| 
       399 
384 
     | 
    
         | 
| 
       400 
     | 
    
         
            -
            static void
         
     | 
| 
       401 
     | 
    
         
            -
             
     | 
| 
       402 
     | 
    
         
            -
             
     | 
| 
       403 
     | 
    
         
            -
             
     | 
| 
       404 
     | 
    
         
            -
             
     | 
| 
       405 
     | 
    
         
            -
            	{ NULL, 0, Qnil },
         
     | 
| 
      
 385 
     | 
    
         
            +
            static void rational_alt(VALUE obj, int depth, Out out) {
         
     | 
| 
      
 386 
     | 
    
         
            +
                struct _attr attrs[] = {
         
     | 
| 
      
 387 
     | 
    
         
            +
                    {"n", 1, Qnil},
         
     | 
| 
      
 388 
     | 
    
         
            +
                    {"d", 1, Qnil},
         
     | 
| 
      
 389 
     | 
    
         
            +
                    {NULL, 0, Qnil},
         
     | 
| 
       406 
390 
     | 
    
         
             
                };
         
     | 
| 
       407 
391 
     | 
    
         
             
                if (0 == numerator_id) {
         
     | 
| 
       408 
     | 
    
         
            -
             
     | 
| 
       409 
     | 
    
         
            -
             
     | 
| 
      
 392 
     | 
    
         
            +
                    numerator_id   = rb_intern("numerator");
         
     | 
| 
      
 393 
     | 
    
         
            +
                    denominator_id = rb_intern("denominator");
         
     | 
| 
       410 
394 
     | 
    
         
             
                }
         
     | 
| 
       411 
395 
     | 
    
         
             
                attrs[0].value = rb_funcall(obj, numerator_id, 0);
         
     | 
| 
       412 
396 
     | 
    
         
             
                attrs[1].value = rb_funcall(obj, denominator_id, 0);
         
     | 
| 
         @@ -414,19 +398,18 @@ rational_alt(VALUE obj, int depth, Out out) { 
     | 
|
| 
       414 
398 
     | 
    
         
             
                oj_code_attrs(obj, attrs, depth, out, true);
         
     | 
| 
       415 
399 
     | 
    
         
             
            }
         
     | 
| 
       416 
400 
     | 
    
         | 
| 
       417 
     | 
    
         
            -
            static ID 
     | 
| 
       418 
     | 
    
         
            -
            static ID 
     | 
| 
      
 401 
     | 
    
         
            +
            static ID options_id = 0;
         
     | 
| 
      
 402 
     | 
    
         
            +
            static ID source_id  = 0;
         
     | 
| 
       419 
403 
     | 
    
         | 
| 
       420 
     | 
    
         
            -
            static void
         
     | 
| 
       421 
     | 
    
         
            -
             
     | 
| 
       422 
     | 
    
         
            -
             
     | 
| 
       423 
     | 
    
         
            -
             
     | 
| 
       424 
     | 
    
         
            -
             
     | 
| 
       425 
     | 
    
         
            -
            	{ NULL, 0, Qnil },
         
     | 
| 
      
 404 
     | 
    
         
            +
            static void regexp_alt(VALUE obj, int depth, Out out) {
         
     | 
| 
      
 405 
     | 
    
         
            +
                struct _attr attrs[] = {
         
     | 
| 
      
 406 
     | 
    
         
            +
                    {"o", 1, Qnil},
         
     | 
| 
      
 407 
     | 
    
         
            +
                    {"s", 1, Qnil},
         
     | 
| 
      
 408 
     | 
    
         
            +
                    {NULL, 0, Qnil},
         
     | 
| 
       426 
409 
     | 
    
         
             
                };
         
     | 
| 
       427 
410 
     | 
    
         
             
                if (0 == options_id) {
         
     | 
| 
       428 
     | 
    
         
            -
             
     | 
| 
       429 
     | 
    
         
            -
             
     | 
| 
      
 411 
     | 
    
         
            +
                    options_id = rb_intern("options");
         
     | 
| 
      
 412 
     | 
    
         
            +
                    source_id  = rb_intern("source");
         
     | 
| 
       430 
413 
     | 
    
         
             
                }
         
     | 
| 
       431 
414 
     | 
    
         
             
                attrs[0].value = rb_funcall(obj, options_id, 0);
         
     | 
| 
       432 
415 
     | 
    
         
             
                attrs[1].value = rb_funcall(obj, source_id, 0);
         
     | 
| 
         @@ -434,24 +417,23 @@ regexp_alt(VALUE obj, int depth, Out out) { 
     | 
|
| 
       434 
417 
     | 
    
         
             
                oj_code_attrs(obj, attrs, depth, out, true);
         
     | 
| 
       435 
418 
     | 
    
         
             
            }
         
     | 
| 
       436 
419 
     | 
    
         | 
| 
       437 
     | 
    
         
            -
            static void
         
     | 
| 
       438 
     | 
    
         
            -
             
     | 
| 
       439 
     | 
    
         
            -
             
     | 
| 
       440 
     | 
    
         
            -
             
     | 
| 
       441 
     | 
    
         
            -
             
     | 
| 
       442 
     | 
    
         
            -
            	{ NULL, 0, Qnil },
         
     | 
| 
      
 420 
     | 
    
         
            +
            static void time_alt(VALUE obj, int depth, Out out) {
         
     | 
| 
      
 421 
     | 
    
         
            +
                struct _attr attrs[] = {
         
     | 
| 
      
 422 
     | 
    
         
            +
                    {"s", 1, Qundef, 0, Qundef},
         
     | 
| 
      
 423 
     | 
    
         
            +
                    {"n", 1, Qundef, 0, Qundef},
         
     | 
| 
      
 424 
     | 
    
         
            +
                    {NULL, 0, Qnil},
         
     | 
| 
       443 
425 
     | 
    
         
             
                };
         
     | 
| 
       444 
     | 
    
         
            -
                time_t 
     | 
| 
       445 
     | 
    
         
            -
                long long 
     | 
| 
      
 426 
     | 
    
         
            +
                time_t    sec;
         
     | 
| 
      
 427 
     | 
    
         
            +
                long long nsec;
         
     | 
| 
       446 
428 
     | 
    
         | 
| 
       447 
429 
     | 
    
         
             
                if (16 <= sizeof(struct timespec)) {
         
     | 
| 
       448 
     | 
    
         
            -
             
     | 
| 
      
 430 
     | 
    
         
            +
                    struct timespec ts = rb_time_timespec(obj);
         
     | 
| 
       449 
431 
     | 
    
         | 
| 
       450 
     | 
    
         
            -
             
     | 
| 
       451 
     | 
    
         
            -
             
     | 
| 
      
 432 
     | 
    
         
            +
                    sec  = (long long)ts.tv_sec;
         
     | 
| 
      
 433 
     | 
    
         
            +
                    nsec = ts.tv_nsec;
         
     | 
| 
       452 
434 
     | 
    
         
             
                } else {
         
     | 
| 
       453 
     | 
    
         
            -
             
     | 
| 
       454 
     | 
    
         
            -
             
     | 
| 
      
 435 
     | 
    
         
            +
                    sec  = NUM2LL(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
         
     | 
| 
      
 436 
     | 
    
         
            +
                    nsec = NUM2LL(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
         
     | 
| 
       455 
437 
     | 
    
         
             
                }
         
     | 
| 
       456 
438 
     | 
    
         | 
| 
       457 
439 
     | 
    
         
             
                attrs[0].num = sec;
         
     | 
| 
         @@ -460,68 +442,68 @@ time_alt(VALUE obj, int depth, Out out) { 
     | 
|
| 
       460 
442 
     | 
    
         
             
                oj_code_attrs(obj, attrs, depth, out, true);
         
     | 
| 
       461 
443 
     | 
    
         
             
            }
         
     | 
| 
       462 
444 
     | 
    
         | 
| 
       463 
     | 
    
         
            -
            struct _code 
     | 
| 
       464 
     | 
    
         
            -
                { 
     | 
| 
       465 
     | 
    
         
            -
                { 
     | 
| 
       466 
     | 
    
         
            -
                { 
     | 
| 
       467 
     | 
    
         
            -
                { 
     | 
| 
       468 
     | 
    
         
            -
                { 
     | 
| 
       469 
     | 
    
         
            -
                { 
     | 
| 
       470 
     | 
    
         
            -
                { 
     | 
| 
       471 
     | 
    
         
            -
                { 
     | 
| 
       472 
     | 
    
         
            -
                { 
     | 
| 
      
 445 
     | 
    
         
            +
            struct _code oj_compat_codes[] = {
         
     | 
| 
      
 446 
     | 
    
         
            +
                {"BigDecimal", Qnil, bigdecimal_alt, NULL, false},
         
     | 
| 
      
 447 
     | 
    
         
            +
                {"Complex", Qnil, complex_alt, NULL, false},
         
     | 
| 
      
 448 
     | 
    
         
            +
                {"Date", Qnil, date_alt, false},
         
     | 
| 
      
 449 
     | 
    
         
            +
                {"DateTime", Qnil, datetime_alt, NULL, false},
         
     | 
| 
      
 450 
     | 
    
         
            +
                {"OpenStruct", Qnil, openstruct_alt, NULL, false},
         
     | 
| 
      
 451 
     | 
    
         
            +
                {"Range", Qnil, range_alt, NULL, false},
         
     | 
| 
      
 452 
     | 
    
         
            +
                {"Rational", Qnil, rational_alt, NULL, false},
         
     | 
| 
      
 453 
     | 
    
         
            +
                {"Regexp", Qnil, regexp_alt, NULL, false},
         
     | 
| 
      
 454 
     | 
    
         
            +
                {"Time", Qnil, time_alt, NULL, false},
         
     | 
| 
       473 
455 
     | 
    
         
             
                // TBD the rest of the library classes
         
     | 
| 
       474 
     | 
    
         
            -
                { 
     | 
| 
      
 456 
     | 
    
         
            +
                {NULL, Qundef, NULL, NULL, false},
         
     | 
| 
       475 
457 
     | 
    
         
             
            };
         
     | 
| 
       476 
458 
     | 
    
         | 
| 
       477 
459 
     | 
    
         
             
            VALUE
         
     | 
| 
       478 
460 
     | 
    
         
             
            oj_add_to_json(int argc, VALUE *argv, VALUE self) {
         
     | 
| 
       479 
     | 
    
         
            -
                Code 
     | 
| 
      
 461 
     | 
    
         
            +
                Code a;
         
     | 
| 
       480 
462 
     | 
    
         | 
| 
       481 
463 
     | 
    
         
             
                if (0 == argc) {
         
     | 
| 
       482 
     | 
    
         
            -
             
     | 
| 
       483 
     | 
    
         
            -
             
     | 
| 
       484 
     | 
    
         
            -
             
     | 
| 
       485 
     | 
    
         
            -
             
     | 
| 
       486 
     | 
    
         
            -
             
     | 
| 
       487 
     | 
    
         
            -
             
     | 
| 
       488 
     | 
    
         
            -
             
     | 
| 
       489 
     | 
    
         
            -
             
     | 
| 
       490 
     | 
    
         
            -
             
     | 
| 
       491 
     | 
    
         
            -
             
     | 
| 
       492 
     | 
    
         
            -
             
     | 
| 
      
 464 
     | 
    
         
            +
                    for (a = oj_compat_codes; NULL != a->name; a++) {
         
     | 
| 
      
 465 
     | 
    
         
            +
                        if (Qnil == a->clas || Qundef == a->clas) {
         
     | 
| 
      
 466 
     | 
    
         
            +
                            a->clas = rb_const_get_at(rb_cObject, rb_intern(a->name));
         
     | 
| 
      
 467 
     | 
    
         
            +
                        }
         
     | 
| 
      
 468 
     | 
    
         
            +
                        a->active = true;
         
     | 
| 
      
 469 
     | 
    
         
            +
                    }
         
     | 
| 
      
 470 
     | 
    
         
            +
                    use_struct_alt    = true;
         
     | 
| 
      
 471 
     | 
    
         
            +
                    use_exception_alt = true;
         
     | 
| 
      
 472 
     | 
    
         
            +
                    use_bignum_alt    = true;
         
     | 
| 
      
 473 
     | 
    
         
            +
                    oj_use_hash_alt   = true;
         
     | 
| 
      
 474 
     | 
    
         
            +
                    oj_use_array_alt  = true;
         
     | 
| 
       493 
475 
     | 
    
         
             
                } else {
         
     | 
| 
       494 
     | 
    
         
            -
             
     | 
| 
       495 
     | 
    
         
            -
             
     | 
| 
       496 
     | 
    
         
            -
             
     | 
| 
       497 
     | 
    
         
            -
             
     | 
| 
       498 
     | 
    
         
            -
             
     | 
| 
       499 
     | 
    
         
            -
             
     | 
| 
       500 
     | 
    
         
            -
             
     | 
| 
       501 
     | 
    
         
            -
             
     | 
| 
       502 
     | 
    
         
            -
             
     | 
| 
       503 
     | 
    
         
            -
             
     | 
| 
       504 
     | 
    
         
            -
             
     | 
| 
       505 
     | 
    
         
            -
             
     | 
| 
       506 
     | 
    
         
            -
             
     | 
| 
       507 
     | 
    
         
            -
             
     | 
| 
       508 
     | 
    
         
            -
             
     | 
| 
       509 
     | 
    
         
            -
             
     | 
| 
       510 
     | 
    
         
            -
             
     | 
| 
       511 
     | 
    
         
            -
             
     | 
| 
       512 
     | 
    
         
            -
             
     | 
| 
       513 
     | 
    
         
            -
             
     | 
| 
       514 
     | 
    
         
            -
             
     | 
| 
       515 
     | 
    
         
            -
             
     | 
| 
       516 
     | 
    
         
            -
             
     | 
| 
       517 
     | 
    
         
            -
             
     | 
| 
       518 
     | 
    
         
            -
             
     | 
| 
       519 
     | 
    
         
            -
             
     | 
| 
       520 
     | 
    
         
            -
             
     | 
| 
       521 
     | 
    
         
            -
             
     | 
| 
       522 
     | 
    
         
            -
             
     | 
| 
       523 
     | 
    
         
            -
             
     | 
| 
       524 
     | 
    
         
            -
             
     | 
| 
      
 476 
     | 
    
         
            +
                    for (; 0 < argc; argc--, argv++) {
         
     | 
| 
      
 477 
     | 
    
         
            +
                        if (rb_cStruct == *argv) {
         
     | 
| 
      
 478 
     | 
    
         
            +
                            use_struct_alt = true;
         
     | 
| 
      
 479 
     | 
    
         
            +
                            continue;
         
     | 
| 
      
 480 
     | 
    
         
            +
                        }
         
     | 
| 
      
 481 
     | 
    
         
            +
                        if (rb_eException == *argv) {
         
     | 
| 
      
 482 
     | 
    
         
            +
                            use_exception_alt = true;
         
     | 
| 
      
 483 
     | 
    
         
            +
                            continue;
         
     | 
| 
      
 484 
     | 
    
         
            +
                        }
         
     | 
| 
      
 485 
     | 
    
         
            +
                        if (rb_cInteger == *argv) {
         
     | 
| 
      
 486 
     | 
    
         
            +
                            use_bignum_alt = true;
         
     | 
| 
      
 487 
     | 
    
         
            +
                            continue;
         
     | 
| 
      
 488 
     | 
    
         
            +
                        }
         
     | 
| 
      
 489 
     | 
    
         
            +
                        if (rb_cHash == *argv) {
         
     | 
| 
      
 490 
     | 
    
         
            +
                            oj_use_hash_alt = true;
         
     | 
| 
      
 491 
     | 
    
         
            +
                            continue;
         
     | 
| 
      
 492 
     | 
    
         
            +
                        }
         
     | 
| 
      
 493 
     | 
    
         
            +
                        if (rb_cArray == *argv) {
         
     | 
| 
      
 494 
     | 
    
         
            +
                            oj_use_array_alt = true;
         
     | 
| 
      
 495 
     | 
    
         
            +
                            continue;
         
     | 
| 
      
 496 
     | 
    
         
            +
                        }
         
     | 
| 
      
 497 
     | 
    
         
            +
                        for (a = oj_compat_codes; NULL != a->name; a++) {
         
     | 
| 
      
 498 
     | 
    
         
            +
                            if (Qnil == a->clas || Qundef == a->clas) {
         
     | 
| 
      
 499 
     | 
    
         
            +
                                a->clas = rb_const_get_at(rb_cObject, rb_intern(a->name));
         
     | 
| 
      
 500 
     | 
    
         
            +
                            }
         
     | 
| 
      
 501 
     | 
    
         
            +
                            if (*argv == a->clas) {
         
     | 
| 
      
 502 
     | 
    
         
            +
                                a->active = true;
         
     | 
| 
      
 503 
     | 
    
         
            +
                                break;
         
     | 
| 
      
 504 
     | 
    
         
            +
                            }
         
     | 
| 
      
 505 
     | 
    
         
            +
                        }
         
     | 
| 
      
 506 
     | 
    
         
            +
                    }
         
     | 
| 
       525 
507 
     | 
    
         
             
                }
         
     | 
| 
       526 
508 
     | 
    
         
             
                return Qnil;
         
     | 
| 
       527 
509 
     | 
    
         
             
            }
         
     | 
| 
         @@ -529,36 +511,36 @@ oj_add_to_json(int argc, VALUE *argv, VALUE self) { 
     | 
|
| 
       529 
511 
     | 
    
         
             
            VALUE
         
     | 
| 
       530 
512 
     | 
    
         
             
            oj_remove_to_json(int argc, VALUE *argv, VALUE self) {
         
     | 
| 
       531 
513 
     | 
    
         
             
                if (0 == argc) {
         
     | 
| 
       532 
     | 
    
         
            -
             
     | 
| 
       533 
     | 
    
         
            -
             
     | 
| 
       534 
     | 
    
         
            -
             
     | 
| 
       535 
     | 
    
         
            -
             
     | 
| 
       536 
     | 
    
         
            -
             
     | 
| 
       537 
     | 
    
         
            -
             
     | 
| 
      
 514 
     | 
    
         
            +
                    oj_code_set_active(oj_compat_codes, Qnil, false);
         
     | 
| 
      
 515 
     | 
    
         
            +
                    use_struct_alt    = false;
         
     | 
| 
      
 516 
     | 
    
         
            +
                    use_exception_alt = false;
         
     | 
| 
      
 517 
     | 
    
         
            +
                    use_bignum_alt    = false;
         
     | 
| 
      
 518 
     | 
    
         
            +
                    oj_use_hash_alt   = false;
         
     | 
| 
      
 519 
     | 
    
         
            +
                    oj_use_array_alt  = false;
         
     | 
| 
       538 
520 
     | 
    
         
             
                } else {
         
     | 
| 
       539 
     | 
    
         
            -
             
     | 
| 
       540 
     | 
    
         
            -
             
     | 
| 
       541 
     | 
    
         
            -
             
     | 
| 
       542 
     | 
    
         
            -
             
     | 
| 
       543 
     | 
    
         
            -
             
     | 
| 
       544 
     | 
    
         
            -
             
     | 
| 
       545 
     | 
    
         
            -
             
     | 
| 
       546 
     | 
    
         
            -
             
     | 
| 
       547 
     | 
    
         
            -
             
     | 
| 
       548 
     | 
    
         
            -
             
     | 
| 
       549 
     | 
    
         
            -
             
     | 
| 
       550 
     | 
    
         
            -
             
     | 
| 
       551 
     | 
    
         
            -
             
     | 
| 
       552 
     | 
    
         
            -
             
     | 
| 
       553 
     | 
    
         
            -
             
     | 
| 
       554 
     | 
    
         
            -
             
     | 
| 
       555 
     | 
    
         
            -
             
     | 
| 
       556 
     | 
    
         
            -
             
     | 
| 
       557 
     | 
    
         
            -
             
     | 
| 
       558 
     | 
    
         
            -
             
     | 
| 
       559 
     | 
    
         
            -
             
     | 
| 
       560 
     | 
    
         
            -
             
     | 
| 
       561 
     | 
    
         
            -
             
     | 
| 
      
 521 
     | 
    
         
            +
                    for (; 0 < argc; argc--, argv++) {
         
     | 
| 
      
 522 
     | 
    
         
            +
                        if (rb_cStruct == *argv) {
         
     | 
| 
      
 523 
     | 
    
         
            +
                            use_struct_alt = false;
         
     | 
| 
      
 524 
     | 
    
         
            +
                            continue;
         
     | 
| 
      
 525 
     | 
    
         
            +
                        }
         
     | 
| 
      
 526 
     | 
    
         
            +
                        if (rb_eException == *argv) {
         
     | 
| 
      
 527 
     | 
    
         
            +
                            use_exception_alt = false;
         
     | 
| 
      
 528 
     | 
    
         
            +
                            continue;
         
     | 
| 
      
 529 
     | 
    
         
            +
                        }
         
     | 
| 
      
 530 
     | 
    
         
            +
                        if (rb_cInteger == *argv) {
         
     | 
| 
      
 531 
     | 
    
         
            +
                            use_bignum_alt = false;
         
     | 
| 
      
 532 
     | 
    
         
            +
                            continue;
         
     | 
| 
      
 533 
     | 
    
         
            +
                        }
         
     | 
| 
      
 534 
     | 
    
         
            +
                        if (rb_cHash == *argv) {
         
     | 
| 
      
 535 
     | 
    
         
            +
                            oj_use_hash_alt = false;
         
     | 
| 
      
 536 
     | 
    
         
            +
                            continue;
         
     | 
| 
      
 537 
     | 
    
         
            +
                        }
         
     | 
| 
      
 538 
     | 
    
         
            +
                        if (rb_cArray == *argv) {
         
     | 
| 
      
 539 
     | 
    
         
            +
                            oj_use_array_alt = false;
         
     | 
| 
      
 540 
     | 
    
         
            +
                            continue;
         
     | 
| 
      
 541 
     | 
    
         
            +
                        }
         
     | 
| 
      
 542 
     | 
    
         
            +
                        oj_code_set_active(oj_compat_codes, *argv, false);
         
     | 
| 
      
 543 
     | 
    
         
            +
                    }
         
     | 
| 
       562 
544 
     | 
    
         
             
                }
         
     | 
| 
       563 
545 
     | 
    
         
             
                return Qnil;
         
     | 
| 
       564 
546 
     | 
    
         
             
            }
         
     | 
| 
         @@ -566,366 +548,349 @@ oj_remove_to_json(int argc, VALUE *argv, VALUE self) { 
     | 
|
| 
       566 
548 
     | 
    
         
             
            // The JSON gem is inconsistent with handling of infinity. Using
         
     | 
| 
       567 
549 
     | 
    
         
             
            // JSON.dump(0.1/0) returns the string Infinity but (0.1/0).to_json raise and
         
     | 
| 
       568 
550 
     | 
    
         
             
            // exception. Worse, for BigDecimals a quoted "Infinity" is returned.
         
     | 
| 
       569 
     | 
    
         
            -
            static void
         
     | 
| 
       570 
     | 
    
         
            -
             
     | 
| 
       571 
     | 
    
         
            -
                char 
     | 
| 
       572 
     | 
    
         
            -
                 
     | 
| 
       573 
     | 
    
         
            -
                 
     | 
| 
       574 
     | 
    
         
            -
                int		cnt = 0;
         
     | 
| 
      
 551 
     | 
    
         
            +
            static void dump_float(VALUE obj, int depth, Out out, bool as_ok) {
         
     | 
| 
      
 552 
     | 
    
         
            +
                char   buf[64];
         
     | 
| 
      
 553 
     | 
    
         
            +
                char  *b;
         
     | 
| 
      
 554 
     | 
    
         
            +
                double d   = rb_num2dbl(obj);
         
     | 
| 
      
 555 
     | 
    
         
            +
                int    cnt = 0;
         
     | 
| 
       575 
556 
     | 
    
         | 
| 
       576 
557 
     | 
    
         
             
                if (0.0 == d) {
         
     | 
| 
       577 
     | 
    
         
            -
             
     | 
| 
       578 
     | 
    
         
            -
             
     | 
| 
       579 
     | 
    
         
            -
             
     | 
| 
       580 
     | 
    
         
            -
             
     | 
| 
       581 
     | 
    
         
            -
             
     | 
| 
       582 
     | 
    
         
            -
             
     | 
| 
      
 558 
     | 
    
         
            +
                    b    = buf;
         
     | 
| 
      
 559 
     | 
    
         
            +
                    *b++ = '0';
         
     | 
| 
      
 560 
     | 
    
         
            +
                    *b++ = '.';
         
     | 
| 
      
 561 
     | 
    
         
            +
                    *b++ = '0';
         
     | 
| 
      
 562 
     | 
    
         
            +
                    *b++ = '\0';
         
     | 
| 
      
 563 
     | 
    
         
            +
                    cnt  = 3;
         
     | 
| 
       583 
564 
     | 
    
         
             
                } else if (OJ_INFINITY == d) {
         
     | 
| 
       584 
     | 
    
         
            -
             
     | 
| 
       585 
     | 
    
         
            -
             
     | 
| 
       586 
     | 
    
         
            -
             
     | 
| 
       587 
     | 
    
         
            -
             
     | 
| 
       588 
     | 
    
         
            -
             
     | 
| 
       589 
     | 
    
         
            -
             
     | 
| 
      
 565 
     | 
    
         
            +
                    if (WordNan == out->opts->dump_opts.nan_dump) {
         
     | 
| 
      
 566 
     | 
    
         
            +
                        strcpy(buf, "Infinity");
         
     | 
| 
      
 567 
     | 
    
         
            +
                        cnt = 8;
         
     | 
| 
      
 568 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 569 
     | 
    
         
            +
                        raise_json_err("Infinity not allowed in JSON.", "GeneratorError");
         
     | 
| 
      
 570 
     | 
    
         
            +
                    }
         
     | 
| 
       590 
571 
     | 
    
         
             
                } else if (-OJ_INFINITY == d) {
         
     | 
| 
       591 
     | 
    
         
            -
             
     | 
| 
       592 
     | 
    
         
            -
             
     | 
| 
       593 
     | 
    
         
            -
             
     | 
| 
       594 
     | 
    
         
            -
             
     | 
| 
       595 
     | 
    
         
            -
             
     | 
| 
       596 
     | 
    
         
            -
             
     | 
| 
      
 572 
     | 
    
         
            +
                    if (WordNan == out->opts->dump_opts.nan_dump) {
         
     | 
| 
      
 573 
     | 
    
         
            +
                        strcpy(buf, "-Infinity");
         
     | 
| 
      
 574 
     | 
    
         
            +
                        cnt = 9;
         
     | 
| 
      
 575 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 576 
     | 
    
         
            +
                        raise_json_err("-Infinity not allowed in JSON.", "GeneratorError");
         
     | 
| 
      
 577 
     | 
    
         
            +
                    }
         
     | 
| 
       597 
578 
     | 
    
         
             
                } else if (isnan(d)) {
         
     | 
| 
       598 
     | 
    
         
            -
             
     | 
| 
       599 
     | 
    
         
            -
             
     | 
| 
       600 
     | 
    
         
            -
             
     | 
| 
       601 
     | 
    
         
            -
             
     | 
| 
       602 
     | 
    
         
            -
             
     | 
| 
       603 
     | 
    
         
            -
             
     | 
| 
      
 579 
     | 
    
         
            +
                    if (WordNan == out->opts->dump_opts.nan_dump) {
         
     | 
| 
      
 580 
     | 
    
         
            +
                        strcpy(buf, "NaN");
         
     | 
| 
      
 581 
     | 
    
         
            +
                        cnt = 3;
         
     | 
| 
      
 582 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 583 
     | 
    
         
            +
                        raise_json_err("NaN not allowed in JSON.", "GeneratorError");
         
     | 
| 
      
 584 
     | 
    
         
            +
                    }
         
     | 
| 
       604 
585 
     | 
    
         
             
                } else if (d == (double)(long long int)d) {
         
     | 
| 
       605 
     | 
    
         
            -
             
     | 
| 
      
 586 
     | 
    
         
            +
                    cnt = snprintf(buf, sizeof(buf), "%.1f", d);
         
     | 
| 
       606 
587 
     | 
    
         
             
                } else if (oj_rails_float_opt) {
         
     | 
| 
       607 
     | 
    
         
            -
             
     | 
| 
      
 588 
     | 
    
         
            +
                    cnt = oj_dump_float_printf(buf, sizeof(buf), obj, d, "%0.16g");
         
     | 
| 
       608 
589 
     | 
    
         
             
                } else {
         
     | 
| 
       609 
     | 
    
         
            -
             
     | 
| 
      
 590 
     | 
    
         
            +
                    volatile VALUE rstr = oj_safe_string_convert(obj);
         
     | 
| 
       610 
591 
     | 
    
         | 
| 
       611 
     | 
    
         
            -
             
     | 
| 
       612 
     | 
    
         
            -
             
     | 
| 
      
 592 
     | 
    
         
            +
                    strcpy(buf, RSTRING_PTR(rstr));
         
     | 
| 
      
 593 
     | 
    
         
            +
                    cnt = (int)RSTRING_LEN(rstr);
         
     | 
| 
       613 
594 
     | 
    
         
             
                }
         
     | 
| 
       614 
595 
     | 
    
         
             
                assure_size(out, cnt);
         
     | 
| 
       615 
596 
     | 
    
         
             
                APPEND_CHARS(out->cur, buf, cnt);
         
     | 
| 
       616 
597 
     | 
    
         
             
                *out->cur = '\0';
         
     | 
| 
       617 
598 
     | 
    
         
             
            }
         
     | 
| 
       618 
599 
     | 
    
         | 
| 
       619 
     | 
    
         
            -
            static int
         
     | 
| 
       620 
     | 
    
         
            -
             
     | 
| 
       621 
     | 
    
         
            -
                 
     | 
| 
       622 
     | 
    
         
            -
                int	depth = out->depth;
         
     | 
| 
      
 600 
     | 
    
         
            +
            static int hash_cb(VALUE key, VALUE value, VALUE ov) {
         
     | 
| 
      
 601 
     | 
    
         
            +
                Out out   = (Out)ov;
         
     | 
| 
      
 602 
     | 
    
         
            +
                int depth = out->depth;
         
     | 
| 
       623 
603 
     | 
    
         | 
| 
       624 
604 
     | 
    
         
             
                if (out->omit_nil && Qnil == value) {
         
     | 
| 
       625 
     | 
    
         
            -
             
     | 
| 
      
 605 
     | 
    
         
            +
                    return ST_CONTINUE;
         
     | 
| 
       626 
606 
     | 
    
         
             
                }
         
     | 
| 
       627 
607 
     | 
    
         
             
                if (!out->opts->dump_opts.use) {
         
     | 
| 
       628 
     | 
    
         
            -
             
     | 
| 
       629 
     | 
    
         
            -
             
     | 
| 
      
 608 
     | 
    
         
            +
                    assure_size(out, depth * out->indent + 1);
         
     | 
| 
      
 609 
     | 
    
         
            +
                    fill_indent(out, depth);
         
     | 
| 
       630 
610 
     | 
    
         
             
                } else {
         
     | 
| 
       631 
     | 
    
         
            -
             
     | 
| 
       632 
     | 
    
         
            -
             
     | 
| 
       633 
     | 
    
         
            -
             
     | 
| 
       634 
     | 
    
         
            -
             
     | 
| 
       635 
     | 
    
         
            -
             
     | 
| 
       636 
     | 
    
         
            -
             
     | 
| 
       637 
     | 
    
         
            -
             
     | 
| 
       638 
     | 
    
         
            -
             
     | 
| 
       639 
     | 
    
         
            -
             
     | 
| 
       640 
     | 
    
         
            -
             
     | 
| 
      
 611 
     | 
    
         
            +
                    assure_size(out, depth * out->opts->dump_opts.indent_size + out->opts->dump_opts.hash_size + 1);
         
     | 
| 
      
 612 
     | 
    
         
            +
                    if (0 < out->opts->dump_opts.hash_size) {
         
     | 
| 
      
 613 
     | 
    
         
            +
                        APPEND_CHARS(out->cur, out->opts->dump_opts.hash_nl, out->opts->dump_opts.hash_size);
         
     | 
| 
      
 614 
     | 
    
         
            +
                    }
         
     | 
| 
      
 615 
     | 
    
         
            +
                    if (0 < out->opts->dump_opts.indent_size) {
         
     | 
| 
      
 616 
     | 
    
         
            +
                        int i;
         
     | 
| 
      
 617 
     | 
    
         
            +
                        for (i = depth; 0 < i; i--) {
         
     | 
| 
      
 618 
     | 
    
         
            +
                            APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
         
     | 
| 
      
 619 
     | 
    
         
            +
                        }
         
     | 
| 
      
 620 
     | 
    
         
            +
                    }
         
     | 
| 
       641 
621 
     | 
    
         
             
                }
         
     | 
| 
       642 
622 
     | 
    
         
             
                switch (rb_type(key)) {
         
     | 
| 
       643 
     | 
    
         
            -
                case T_STRING:
         
     | 
| 
       644 
     | 
    
         
            -
             
     | 
| 
       645 
     | 
    
         
            -
            	break;
         
     | 
| 
       646 
     | 
    
         
            -
                case T_SYMBOL:
         
     | 
| 
       647 
     | 
    
         
            -
            	oj_dump_sym(key, 0, out, false);
         
     | 
| 
       648 
     | 
    
         
            -
            	break;
         
     | 
| 
      
 623 
     | 
    
         
            +
                case T_STRING: oj_dump_str(key, 0, out, false); break;
         
     | 
| 
      
 624 
     | 
    
         
            +
                case T_SYMBOL: oj_dump_sym(key, 0, out, false); break;
         
     | 
| 
       649 
625 
     | 
    
         
             
                default:
         
     | 
| 
       650 
     | 
    
         
            -
             
     | 
| 
       651 
     | 
    
         
            -
             
     | 
| 
       652 
     | 
    
         
            -
             
     | 
| 
      
 626 
     | 
    
         
            +
                    /*rb_raise(rb_eTypeError, "In :compat mode all Hash keys must be Strings or Symbols, not %s.\n",
         
     | 
| 
      
 627 
     | 
    
         
            +
                     * rb_class2name(rb_obj_class(key)));*/
         
     | 
| 
      
 628 
     | 
    
         
            +
                    oj_dump_str(oj_safe_string_convert(key), 0, out, false);
         
     | 
| 
      
 629 
     | 
    
         
            +
                    break;
         
     | 
| 
       653 
630 
     | 
    
         
             
                }
         
     | 
| 
       654 
631 
     | 
    
         
             
                if (!out->opts->dump_opts.use) {
         
     | 
| 
       655 
     | 
    
         
            -
             
     | 
| 
      
 632 
     | 
    
         
            +
                    *out->cur++ = ':';
         
     | 
| 
       656 
633 
     | 
    
         
             
                } else {
         
     | 
| 
       657 
     | 
    
         
            -
             
     | 
| 
       658 
     | 
    
         
            -
             
     | 
| 
       659 
     | 
    
         
            -
             
     | 
| 
       660 
     | 
    
         
            -
             
     | 
| 
       661 
     | 
    
         
            -
             
     | 
| 
       662 
     | 
    
         
            -
             
     | 
| 
       663 
     | 
    
         
            -
             
     | 
| 
       664 
     | 
    
         
            -
             
     | 
| 
      
 634 
     | 
    
         
            +
                    assure_size(out, out->opts->dump_opts.before_size + out->opts->dump_opts.after_size + 2);
         
     | 
| 
      
 635 
     | 
    
         
            +
                    if (0 < out->opts->dump_opts.before_size) {
         
     | 
| 
      
 636 
     | 
    
         
            +
                        APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
         
     | 
| 
      
 637 
     | 
    
         
            +
                    }
         
     | 
| 
      
 638 
     | 
    
         
            +
                    *out->cur++ = ':';
         
     | 
| 
      
 639 
     | 
    
         
            +
                    if (0 < out->opts->dump_opts.after_size) {
         
     | 
| 
      
 640 
     | 
    
         
            +
                        APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
         
     | 
| 
      
 641 
     | 
    
         
            +
                    }
         
     | 
| 
       665 
642 
     | 
    
         
             
                }
         
     | 
| 
       666 
643 
     | 
    
         
             
                oj_dump_compat_val(value, depth, out, true);
         
     | 
| 
       667 
     | 
    
         
            -
                out->depth 
     | 
| 
      
 644 
     | 
    
         
            +
                out->depth  = depth;
         
     | 
| 
       668 
645 
     | 
    
         
             
                *out->cur++ = ',';
         
     | 
| 
       669 
646 
     | 
    
         | 
| 
       670 
647 
     | 
    
         
             
                return ST_CONTINUE;
         
     | 
| 
       671 
648 
     | 
    
         
             
            }
         
     | 
| 
       672 
649 
     | 
    
         | 
| 
       673 
     | 
    
         
            -
            static void
         
     | 
| 
       674 
     | 
    
         
            -
             
     | 
| 
       675 
     | 
    
         
            -
                 
     | 
| 
       676 
     | 
    
         
            -
                long	id = oj_check_circular(obj, out);
         
     | 
| 
      
 650 
     | 
    
         
            +
            static void dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
         
     | 
| 
      
 651 
     | 
    
         
            +
                int  cnt;
         
     | 
| 
      
 652 
     | 
    
         
            +
                long id = oj_check_circular(obj, out);
         
     | 
| 
       677 
653 
     | 
    
         | 
| 
       678 
654 
     | 
    
         
             
                if (0 > id) {
         
     | 
| 
       679 
     | 
    
         
            -
             
     | 
| 
       680 
     | 
    
         
            -
             
     | 
| 
      
 655 
     | 
    
         
            +
                    raise_json_err("Too deeply nested", "NestingError");
         
     | 
| 
      
 656 
     | 
    
         
            +
                    return;
         
     | 
| 
       681 
657 
     | 
    
         
             
                }
         
     | 
| 
       682 
658 
     | 
    
         
             
                if (as_ok && !oj_use_hash_alt && rb_obj_class(obj) != rb_cHash && rb_respond_to(obj, oj_to_json_id)) {
         
     | 
| 
       683 
     | 
    
         
            -
             
     | 
| 
       684 
     | 
    
         
            -
             
     | 
| 
      
 659 
     | 
    
         
            +
                    dump_to_json(obj, out);
         
     | 
| 
      
 660 
     | 
    
         
            +
                    return;
         
     | 
| 
       685 
661 
     | 
    
         
             
                }
         
     | 
| 
       686 
662 
     | 
    
         
             
                cnt = (int)RHASH_SIZE(obj);
         
     | 
| 
       687 
663 
     | 
    
         
             
                assure_size(out, 2);
         
     | 
| 
       688 
664 
     | 
    
         
             
                if (0 == cnt) {
         
     | 
| 
       689 
     | 
    
         
            -
             
     | 
| 
      
 665 
     | 
    
         
            +
                    APPEND_CHARS(out->cur, "{}", 2);
         
     | 
| 
       690 
666 
     | 
    
         
             
                } else {
         
     | 
| 
       691 
     | 
    
         
            -
             
     | 
| 
       692 
     | 
    
         
            -
             
     | 
| 
       693 
     | 
    
         
            -
             
     | 
| 
       694 
     | 
    
         
            -
             
     | 
| 
       695 
     | 
    
         
            -
             
     | 
| 
       696 
     | 
    
         
            -
             
     | 
| 
       697 
     | 
    
         
            -
             
     | 
| 
       698 
     | 
    
         
            -
             
     | 
| 
       699 
     | 
    
         
            -
             
     | 
| 
       700 
     | 
    
         
            -
             
     | 
| 
       701 
     | 
    
         
            -
             
     | 
| 
       702 
     | 
    
         
            -
             
     | 
| 
       703 
     | 
    
         
            -
             
     | 
| 
       704 
     | 
    
         
            -
             
     | 
| 
       705 
     | 
    
         
            -
             
     | 
| 
       706 
     | 
    
         
            -
             
     | 
| 
       707 
     | 
    
         
            -
             
     | 
| 
       708 
     | 
    
         
            -
             
     | 
| 
       709 
     | 
    
         
            -
             
     | 
| 
       710 
     | 
    
         
            -
             
     | 
| 
       711 
     | 
    
         
            -
             
     | 
| 
       712 
     | 
    
         
            -
             
     | 
| 
       713 
     | 
    
         
            -
             
     | 
| 
      
 667 
     | 
    
         
            +
                    *out->cur++ = '{';
         
     | 
| 
      
 668 
     | 
    
         
            +
                    out->depth  = depth + 1;
         
     | 
| 
      
 669 
     | 
    
         
            +
                    rb_hash_foreach(obj, hash_cb, (VALUE)out);
         
     | 
| 
      
 670 
     | 
    
         
            +
                    if (',' == *(out->cur - 1)) {
         
     | 
| 
      
 671 
     | 
    
         
            +
                        out->cur--;  // backup to overwrite last comma
         
     | 
| 
      
 672 
     | 
    
         
            +
                    }
         
     | 
| 
      
 673 
     | 
    
         
            +
                    if (!out->opts->dump_opts.use) {
         
     | 
| 
      
 674 
     | 
    
         
            +
                        assure_size(out, depth * out->indent + 2);
         
     | 
| 
      
 675 
     | 
    
         
            +
                        fill_indent(out, depth);
         
     | 
| 
      
 676 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 677 
     | 
    
         
            +
                        assure_size(out, depth * out->opts->dump_opts.indent_size + out->opts->dump_opts.hash_size + 1);
         
     | 
| 
      
 678 
     | 
    
         
            +
                        if (0 < out->opts->dump_opts.hash_size) {
         
     | 
| 
      
 679 
     | 
    
         
            +
                            APPEND_CHARS(out->cur, out->opts->dump_opts.hash_nl, out->opts->dump_opts.hash_size);
         
     | 
| 
      
 680 
     | 
    
         
            +
                        }
         
     | 
| 
      
 681 
     | 
    
         
            +
                        if (0 < out->opts->dump_opts.indent_size) {
         
     | 
| 
      
 682 
     | 
    
         
            +
                            int i;
         
     | 
| 
      
 683 
     | 
    
         
            +
             
     | 
| 
      
 684 
     | 
    
         
            +
                            for (i = depth; 0 < i; i--) {
         
     | 
| 
      
 685 
     | 
    
         
            +
                                APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
         
     | 
| 
      
 686 
     | 
    
         
            +
                            }
         
     | 
| 
      
 687 
     | 
    
         
            +
                        }
         
     | 
| 
      
 688 
     | 
    
         
            +
                    }
         
     | 
| 
      
 689 
     | 
    
         
            +
                    *out->cur++ = '}';
         
     | 
| 
       714 
690 
     | 
    
         
             
                }
         
     | 
| 
       715 
691 
     | 
    
         
             
                *out->cur = '\0';
         
     | 
| 
       716 
692 
     | 
    
         
             
            }
         
     | 
| 
       717 
693 
     | 
    
         | 
| 
       718 
694 
     | 
    
         
             
            // In compat mode only the first call check for to_json. After that to_s is
         
     | 
| 
       719 
695 
     | 
    
         
             
            // called.
         
     | 
| 
       720 
     | 
    
         
            -
            static void
         
     | 
| 
       721 
     | 
    
         
            -
            dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
         
     | 
| 
      
 696 
     | 
    
         
            +
            static void dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
         
     | 
| 
       722 
697 
     | 
    
         
             
                if (oj_code_dump(oj_compat_codes, obj, depth, out)) {
         
     | 
| 
       723 
     | 
    
         
            -
             
     | 
| 
      
 698 
     | 
    
         
            +
                    return;
         
     | 
| 
       724 
699 
     | 
    
         
             
                }
         
     | 
| 
       725 
700 
     | 
    
         
             
                if (use_exception_alt && rb_obj_is_kind_of(obj, rb_eException)) {
         
     | 
| 
       726 
     | 
    
         
            -
             
     | 
| 
       727 
     | 
    
         
            -
             
     | 
| 
      
 701 
     | 
    
         
            +
                    exception_alt(obj, depth, out);
         
     | 
| 
      
 702 
     | 
    
         
            +
                    return;
         
     | 
| 
       728 
703 
     | 
    
         
             
                }
         
     | 
| 
       729 
704 
     | 
    
         
             
                if (Yes == out->opts->raw_json && rb_respond_to(obj, oj_raw_json_id)) {
         
     | 
| 
       730 
     | 
    
         
            -
             
     | 
| 
       731 
     | 
    
         
            -
             
     | 
| 
      
 705 
     | 
    
         
            +
                    oj_dump_raw_json(obj, depth, out);
         
     | 
| 
      
 706 
     | 
    
         
            +
                    return;
         
     | 
| 
       732 
707 
     | 
    
         
             
                }
         
     | 
| 
       733 
708 
     | 
    
         
             
                if (as_ok && rb_respond_to(obj, oj_to_json_id)) {
         
     | 
| 
       734 
     | 
    
         
            -
             
     | 
| 
       735 
     | 
    
         
            -
             
     | 
| 
      
 709 
     | 
    
         
            +
                    dump_to_json(obj, out);
         
     | 
| 
      
 710 
     | 
    
         
            +
                    return;
         
     | 
| 
       736 
711 
     | 
    
         
             
                }
         
     | 
| 
       737 
712 
     | 
    
         
             
                // Nothing else matched so encode as a JSON object with Ruby obj members
         
     | 
| 
       738 
713 
     | 
    
         
             
                // as JSON object members.
         
     | 
| 
       739 
714 
     | 
    
         
             
                oj_dump_obj_to_s(obj, out);
         
     | 
| 
       740 
715 
     | 
    
         
             
            }
         
     | 
| 
       741 
716 
     | 
    
         | 
| 
       742 
     | 
    
         
            -
            static void
         
     | 
| 
       743 
     | 
    
         
            -
             
     | 
| 
       744 
     | 
    
         
            -
                VALUE	clas = rb_obj_class(obj);
         
     | 
| 
      
 717 
     | 
    
         
            +
            static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
         
     | 
| 
      
 718 
     | 
    
         
            +
                VALUE clas = rb_obj_class(obj);
         
     | 
| 
       745 
719 
     | 
    
         | 
| 
       746 
720 
     | 
    
         
             
                if (oj_code_dump(oj_compat_codes, obj, depth, out)) {
         
     | 
| 
       747 
     | 
    
         
            -
             
     | 
| 
      
 721 
     | 
    
         
            +
                    return;
         
     | 
| 
       748 
722 
     | 
    
         
             
                }
         
     | 
| 
       749 
723 
     | 
    
         
             
                if (rb_cRange == clas) {
         
     | 
| 
       750 
     | 
    
         
            -
             
     | 
| 
       751 
     | 
    
         
            -
             
     | 
| 
       752 
     | 
    
         
            -
             
     | 
| 
       753 
     | 
    
         
            -
             
     | 
| 
       754 
     | 
    
         
            -
             
     | 
| 
       755 
     | 
    
         
            -
             
     | 
| 
       756 
     | 
    
         
            -
             
     | 
| 
       757 
     | 
    
         
            -
             
     | 
| 
       758 
     | 
    
         
            -
             
     | 
| 
       759 
     | 
    
         
            -
             
     | 
| 
       760 
     | 
    
         
            -
             
     | 
| 
      
 724 
     | 
    
         
            +
                    *out->cur++ = '"';
         
     | 
| 
      
 725 
     | 
    
         
            +
                    oj_dump_compat_val(rb_funcall(obj, oj_begin_id, 0), 0, out, false);
         
     | 
| 
      
 726 
     | 
    
         
            +
                    assure_size(out, 3);
         
     | 
| 
      
 727 
     | 
    
         
            +
                    APPEND_CHARS(out->cur, "..", 2);
         
     | 
| 
      
 728 
     | 
    
         
            +
                    if (Qtrue == rb_funcall(obj, oj_exclude_end_id, 0)) {
         
     | 
| 
      
 729 
     | 
    
         
            +
                        *out->cur++ = '.';
         
     | 
| 
      
 730 
     | 
    
         
            +
                    }
         
     | 
| 
      
 731 
     | 
    
         
            +
                    oj_dump_compat_val(rb_funcall(obj, oj_end_id, 0), 0, out, false);
         
     | 
| 
      
 732 
     | 
    
         
            +
                    *out->cur++ = '"';
         
     | 
| 
      
 733 
     | 
    
         
            +
             
     | 
| 
      
 734 
     | 
    
         
            +
                    return;
         
     | 
| 
       761 
735 
     | 
    
         
             
                }
         
     | 
| 
       762 
736 
     | 
    
         
             
                if (as_ok && rb_respond_to(obj, oj_to_json_id)) {
         
     | 
| 
       763 
     | 
    
         
            -
             
     | 
| 
      
 737 
     | 
    
         
            +
                    dump_to_json(obj, out);
         
     | 
| 
       764 
738 
     | 
    
         | 
| 
       765 
     | 
    
         
            -
             
     | 
| 
      
 739 
     | 
    
         
            +
                    return;
         
     | 
| 
       766 
740 
     | 
    
         
             
                }
         
     | 
| 
       767 
741 
     | 
    
         
             
                if (use_struct_alt) {
         
     | 
| 
       768 
     | 
    
         
            -
             
     | 
| 
       769 
     | 
    
         
            -
             
     | 
| 
       770 
     | 
    
         
            -
             
     | 
| 
       771 
     | 
    
         
            -
             
     | 
| 
       772 
     | 
    
         
            -
             
     | 
| 
       773 
     | 
    
         
            -
             
     | 
| 
       774 
     | 
    
         
            -
             
     | 
| 
       775 
     | 
    
         
            -
             
     | 
| 
       776 
     | 
    
         
            -
             
     | 
| 
       777 
     | 
    
         
            -
             
     | 
| 
       778 
     | 
    
         
            -
             
     | 
| 
      
 742 
     | 
    
         
            +
                    int         d3        = depth + 2;
         
     | 
| 
      
 743 
     | 
    
         
            +
                    size_t      size      = d3 * out->indent + 2;
         
     | 
| 
      
 744 
     | 
    
         
            +
                    size_t      sep_len   = out->opts->dump_opts.before_size + out->opts->dump_opts.after_size + 2;
         
     | 
| 
      
 745 
     | 
    
         
            +
                    const char *classname = rb_class2name(rb_obj_class(obj));
         
     | 
| 
      
 746 
     | 
    
         
            +
                    VALUE       args[100];
         
     | 
| 
      
 747 
     | 
    
         
            +
                    int         cnt;
         
     | 
| 
      
 748 
     | 
    
         
            +
                    int         i;
         
     | 
| 
      
 749 
     | 
    
         
            +
             
     | 
| 
      
 750 
     | 
    
         
            +
                    if (NULL == classname || '#' == *classname) {
         
     | 
| 
      
 751 
     | 
    
         
            +
                        raise_json_err("Only named structs are supported.", "JSONError");
         
     | 
| 
      
 752 
     | 
    
         
            +
                    }
         
     | 
| 
       779 
753 
     | 
    
         
             
            #ifdef RSTRUCT_LEN
         
     | 
| 
       780 
754 
     | 
    
         
             
            #if RSTRUCT_LEN_RETURNS_INTEGER_OBJECT
         
     | 
| 
       781 
     | 
    
         
            -
             
     | 
| 
       782 
     | 
    
         
            -
            #else 
     | 
| 
       783 
     | 
    
         
            -
             
     | 
| 
       784 
     | 
    
         
            -
            #endif 
     | 
| 
      
 755 
     | 
    
         
            +
                    cnt = (int)NUM2LONG(RSTRUCT_LEN(obj));
         
     | 
| 
      
 756 
     | 
    
         
            +
            #else   // RSTRUCT_LEN_RETURNS_INTEGER_OBJECT
         
     | 
| 
      
 757 
     | 
    
         
            +
                    cnt = (int)RSTRUCT_LEN(obj);
         
     | 
| 
      
 758 
     | 
    
         
            +
            #endif  // RSTRUCT_LEN_RETURNS_INTEGER_OBJECT
         
     | 
| 
       785 
759 
     | 
    
         
             
            #else
         
     | 
| 
       786 
     | 
    
         
            -
             
     | 
| 
       787 
     | 
    
         
            -
             
     | 
| 
       788 
     | 
    
         
            -
             
     | 
| 
      
 760 
     | 
    
         
            +
                    // This is a bit risky as a struct in C ruby is not the same as a Struct
         
     | 
| 
      
 761 
     | 
    
         
            +
                    // class in interpreted Ruby so length() may not be defined.
         
     | 
| 
      
 762 
     | 
    
         
            +
                    cnt = FIX2INT(rb_funcall2(obj, oj_length_id, 0, 0));
         
     | 
| 
       789 
763 
     | 
    
         
             
            #endif
         
     | 
| 
       790 
     | 
    
         
            -
             
     | 
| 
       791 
     | 
    
         
            -
             
     | 
| 
       792 
     | 
    
         
            -
             
     | 
| 
       793 
     | 
    
         
            -
             
     | 
| 
       794 
     | 
    
         
            -
             
     | 
| 
       795 
     | 
    
         
            -
             
     | 
| 
       796 
     | 
    
         
            -
             
     | 
| 
       797 
     | 
    
         
            -
             
     | 
| 
       798 
     | 
    
         
            -
             
     | 
| 
       799 
     | 
    
         
            -
             
     | 
| 
       800 
     | 
    
         
            -
             
     | 
| 
       801 
     | 
    
         
            -
             
     | 
| 
       802 
     | 
    
         
            -
             
     | 
| 
       803 
     | 
    
         
            -
             
     | 
| 
       804 
     | 
    
         
            -
             
     | 
| 
       805 
     | 
    
         
            -
             
     | 
| 
       806 
     | 
    
         
            -
             
     | 
| 
       807 
     | 
    
         
            -
             
     | 
| 
      
 764 
     | 
    
         
            +
                    if (sizeof(args) / sizeof(*args) <= (size_t)cnt) {
         
     | 
| 
      
 765 
     | 
    
         
            +
                        // TBD allocate and try again
         
     | 
| 
      
 766 
     | 
    
         
            +
                        cnt = 99;
         
     | 
| 
      
 767 
     | 
    
         
            +
                    }
         
     | 
| 
      
 768 
     | 
    
         
            +
                    dump_obj_classname(rb_class2name(rb_obj_class(obj)), depth, out);
         
     | 
| 
      
 769 
     | 
    
         
            +
             
     | 
| 
      
 770 
     | 
    
         
            +
                    assure_size(out, size + sep_len + 6);
         
     | 
| 
      
 771 
     | 
    
         
            +
                    *out->cur++ = ',';
         
     | 
| 
      
 772 
     | 
    
         
            +
                    fill_indent(out, d3);
         
     | 
| 
      
 773 
     | 
    
         
            +
                    APPEND_CHARS(out->cur, "\"v\"", 3);
         
     | 
| 
      
 774 
     | 
    
         
            +
                    if (0 < out->opts->dump_opts.before_size) {
         
     | 
| 
      
 775 
     | 
    
         
            +
                        APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
         
     | 
| 
      
 776 
     | 
    
         
            +
                    }
         
     | 
| 
      
 777 
     | 
    
         
            +
                    *out->cur++ = ':';
         
     | 
| 
      
 778 
     | 
    
         
            +
                    if (0 < out->opts->dump_opts.after_size) {
         
     | 
| 
      
 779 
     | 
    
         
            +
                        APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
         
     | 
| 
      
 780 
     | 
    
         
            +
                    }
         
     | 
| 
      
 781 
     | 
    
         
            +
                    for (i = 0; i < cnt; i++) {
         
     | 
| 
       808 
782 
     | 
    
         
             
            #ifdef RSTRUCT_LEN
         
     | 
| 
       809 
     | 
    
         
            -
             
     | 
| 
      
 783 
     | 
    
         
            +
                        args[i] = RSTRUCT_GET(obj, i);
         
     | 
| 
       810 
784 
     | 
    
         
             
            #else
         
     | 
| 
       811 
     | 
    
         
            -
             
     | 
| 
      
 785 
     | 
    
         
            +
                        args[i] = rb_struct_aref(obj, INT2FIX(i));
         
     | 
| 
       812 
786 
     | 
    
         
             
            #endif
         
     | 
| 
       813 
     | 
    
         
            -
             
     | 
| 
       814 
     | 
    
         
            -
             
     | 
| 
       815 
     | 
    
         
            -
             
     | 
| 
       816 
     | 
    
         
            -
             
     | 
| 
       817 
     | 
    
         
            -
             
     | 
| 
       818 
     | 
    
         
            -
             
     | 
| 
      
 787 
     | 
    
         
            +
                    }
         
     | 
| 
      
 788 
     | 
    
         
            +
                    args[cnt] = Qundef;
         
     | 
| 
      
 789 
     | 
    
         
            +
                    dump_values_array(args, depth, out);
         
     | 
| 
      
 790 
     | 
    
         
            +
                    fill_indent(out, depth);
         
     | 
| 
      
 791 
     | 
    
         
            +
                    *out->cur++ = '}';
         
     | 
| 
      
 792 
     | 
    
         
            +
                    *out->cur   = '\0';
         
     | 
| 
       819 
793 
     | 
    
         
             
                } else {
         
     | 
| 
       820 
     | 
    
         
            -
             
     | 
| 
      
 794 
     | 
    
         
            +
                    oj_dump_obj_to_s(obj, out);
         
     | 
| 
       821 
795 
     | 
    
         
             
                }
         
     | 
| 
       822 
796 
     | 
    
         
             
            }
         
     | 
| 
       823 
797 
     | 
    
         | 
| 
       824 
     | 
    
         
            -
            static void
         
     | 
| 
       825 
     | 
    
         
            -
            dump_bignum(VALUE obj, int depth, Out out, bool as_ok) {
         
     | 
| 
      
 798 
     | 
    
         
            +
            static void dump_bignum(VALUE obj, int depth, Out out, bool as_ok) {
         
     | 
| 
       826 
799 
     | 
    
         
             
                // The json gem uses to_s explicitly. to_s can be overridden while
         
     | 
| 
       827 
800 
     | 
    
         
             
                // rb_big2str can not so unless overridden by using add_to_json(Integer)
         
     | 
| 
       828 
801 
     | 
    
         
             
                // this must use to_s to pass the json gem unit tests.
         
     | 
| 
       829 
     | 
    
         
            -
                volatile VALUE 
     | 
| 
       830 
     | 
    
         
            -
                int 
     | 
| 
       831 
     | 
    
         
            -
                bool 
     | 
| 
      
 802 
     | 
    
         
            +
                volatile VALUE rs;
         
     | 
| 
      
 803 
     | 
    
         
            +
                int            cnt;
         
     | 
| 
      
 804 
     | 
    
         
            +
                bool           dump_as_string = false;
         
     | 
| 
       832 
805 
     | 
    
         | 
| 
       833 
806 
     | 
    
         
             
                if (use_bignum_alt) {
         
     | 
| 
       834 
     | 
    
         
            -
             
     | 
| 
      
 807 
     | 
    
         
            +
                    rs = rb_big2str(obj, 10);
         
     | 
| 
       835 
808 
     | 
    
         
             
                } else {
         
     | 
| 
       836 
     | 
    
         
            -
             
     | 
| 
      
 809 
     | 
    
         
            +
                    rs = oj_safe_string_convert(obj);
         
     | 
| 
       837 
810 
     | 
    
         
             
                }
         
     | 
| 
       838 
811 
     | 
    
         
             
                rb_check_type(rs, T_STRING);
         
     | 
| 
       839 
812 
     | 
    
         
             
                cnt = (int)RSTRING_LEN(rs);
         
     | 
| 
       840 
813 
     | 
    
         | 
| 
       841 
814 
     | 
    
         
             
                if (out->opts->int_range_min != 0 || out->opts->int_range_max != 0) {
         
     | 
| 
       842 
     | 
    
         
            -
             
     | 
| 
       843 
     | 
    
         
            -
             
     | 
| 
       844 
     | 
    
         
            -
             
     | 
| 
      
 815 
     | 
    
         
            +
                    dump_as_string = true;  // Bignum cannot be inside of Fixnum range
         
     | 
| 
      
 816 
     | 
    
         
            +
                    assure_size(out, cnt + 2);
         
     | 
| 
      
 817 
     | 
    
         
            +
                    *out->cur++ = '"';
         
     | 
| 
       845 
818 
     | 
    
         
             
                } else {
         
     | 
| 
       846 
     | 
    
         
            -
             
     | 
| 
      
 819 
     | 
    
         
            +
                    assure_size(out, cnt);
         
     | 
| 
       847 
820 
     | 
    
         
             
                }
         
     | 
| 
       848 
821 
     | 
    
         
             
                APPEND_CHARS(out->cur, RSTRING_PTR(rs), cnt);
         
     | 
| 
       849 
822 
     | 
    
         
             
                if (dump_as_string) {
         
     | 
| 
       850 
     | 
    
         
            -
             
     | 
| 
      
 823 
     | 
    
         
            +
                    *out->cur++ = '"';
         
     | 
| 
       851 
824 
     | 
    
         
             
                }
         
     | 
| 
       852 
825 
     | 
    
         
             
                *out->cur = '\0';
         
     | 
| 
       853 
826 
     | 
    
         
             
            }
         
     | 
| 
       854 
827 
     | 
    
         | 
| 
       855 
     | 
    
         
            -
            static DumpFunc 
     | 
| 
       856 
     | 
    
         
            -
                NULL, 
     | 
| 
       857 
     | 
    
         
            -
                dump_obj, 
     | 
| 
       858 
     | 
    
         
            -
                oj_dump_class, 
     | 
| 
       859 
     | 
    
         
            -
                oj_dump_class, 
     | 
| 
       860 
     | 
    
         
            -
                dump_float, 
     | 
| 
       861 
     | 
    
         
            -
                oj_dump_str, 
     | 
| 
       862 
     | 
    
         
            -
                dump_obj, 
     | 
| 
       863 
     | 
    
         
            -
                dump_array, 
     | 
| 
       864 
     | 
    
         
            -
                dump_hash, 
     | 
| 
       865 
     | 
    
         
            -
                dump_struct, 
     | 
| 
       866 
     | 
    
         
            -
                dump_bignum, 
     | 
| 
       867 
     | 
    
         
            -
                NULL, 
     | 
| 
       868 
     | 
    
         
            -
                dump_obj, 
     | 
| 
       869 
     | 
    
         
            -
                NULL, 
     | 
| 
       870 
     | 
    
         
            -
                dump_obj, 
     | 
| 
       871 
     | 
    
         
            -
                dump_obj, 
     | 
| 
       872 
     | 
    
         
            -
                NULL, 
     | 
| 
       873 
     | 
    
         
            -
                oj_dump_nil, 
     | 
| 
       874 
     | 
    
         
            -
                oj_dump_true, 
     | 
| 
       875 
     | 
    
         
            -
                oj_dump_false, 
     | 
| 
       876 
     | 
    
         
            -
                oj_dump_sym, 
     | 
| 
       877 
     | 
    
         
            -
                oj_dump_fixnum, 
     | 
| 
      
 828 
     | 
    
         
            +
            static DumpFunc compat_funcs[] = {
         
     | 
| 
      
 829 
     | 
    
         
            +
                NULL,            // RUBY_T_NONE   = 0x00,
         
     | 
| 
      
 830 
     | 
    
         
            +
                dump_obj,        // RUBY_T_OBJECT = 0x01,
         
     | 
| 
      
 831 
     | 
    
         
            +
                oj_dump_class,   // RUBY_T_CLASS  = 0x02,
         
     | 
| 
      
 832 
     | 
    
         
            +
                oj_dump_class,   // RUBY_T_MODULE = 0x03,
         
     | 
| 
      
 833 
     | 
    
         
            +
                dump_float,      // RUBY_T_FLOAT  = 0x04,
         
     | 
| 
      
 834 
     | 
    
         
            +
                oj_dump_str,     // RUBY_T_STRING = 0x05,
         
     | 
| 
      
 835 
     | 
    
         
            +
                dump_obj,        // RUBY_T_REGEXP = 0x06,
         
     | 
| 
      
 836 
     | 
    
         
            +
                dump_array,      // RUBY_T_ARRAY  = 0x07,
         
     | 
| 
      
 837 
     | 
    
         
            +
                dump_hash,       // RUBY_T_HASH   = 0x08,
         
     | 
| 
      
 838 
     | 
    
         
            +
                dump_struct,     // RUBY_T_STRUCT = 0x09,
         
     | 
| 
      
 839 
     | 
    
         
            +
                dump_bignum,     // RUBY_T_BIGNUM = 0x0a,
         
     | 
| 
      
 840 
     | 
    
         
            +
                NULL,            // RUBY_T_FILE   = 0x0b,
         
     | 
| 
      
 841 
     | 
    
         
            +
                dump_obj,        // RUBY_T_DATA   = 0x0c,
         
     | 
| 
      
 842 
     | 
    
         
            +
                NULL,            // RUBY_T_MATCH  = 0x0d,
         
     | 
| 
      
 843 
     | 
    
         
            +
                dump_obj,        // RUBY_T_COMPLEX  = 0x0e,
         
     | 
| 
      
 844 
     | 
    
         
            +
                dump_obj,        // RUBY_T_RATIONAL = 0x0f,
         
     | 
| 
      
 845 
     | 
    
         
            +
                NULL,            // 0x10
         
     | 
| 
      
 846 
     | 
    
         
            +
                oj_dump_nil,     // RUBY_T_NIL    = 0x11,
         
     | 
| 
      
 847 
     | 
    
         
            +
                oj_dump_true,    // RUBY_T_TRUE   = 0x12,
         
     | 
| 
      
 848 
     | 
    
         
            +
                oj_dump_false,   // RUBY_T_FALSE  = 0x13,
         
     | 
| 
      
 849 
     | 
    
         
            +
                oj_dump_sym,     // RUBY_T_SYMBOL = 0x14,
         
     | 
| 
      
 850 
     | 
    
         
            +
                oj_dump_fixnum,  // RUBY_T_FIXNUM = 0x15,
         
     | 
| 
       878 
851 
     | 
    
         
             
            };
         
     | 
| 
       879 
852 
     | 
    
         | 
| 
       880 
     | 
    
         
            -
            static void
         
     | 
| 
       881 
     | 
    
         
            -
             
     | 
| 
       882 
     | 
    
         
            -
             
     | 
| 
       883 
     | 
    
         
            -
                 
     | 
| 
       884 
     | 
    
         
            -
                 
     | 
| 
       885 
     | 
    
         
            -
             
     | 
| 
      
 853 
     | 
    
         
            +
            static void set_state_depth(VALUE state, int depth) {
         
     | 
| 
      
 854 
     | 
    
         
            +
                if (0 == rb_const_defined(rb_cObject, rb_intern("JSON"))) {
         
     | 
| 
      
 855 
     | 
    
         
            +
                    rb_require("oj/json");
         
     | 
| 
      
 856 
     | 
    
         
            +
                }
         
     | 
| 
      
 857 
     | 
    
         
            +
                {
         
     | 
| 
      
 858 
     | 
    
         
            +
                    VALUE json_module = rb_const_get_at(rb_cObject, rb_intern("JSON"));
         
     | 
| 
      
 859 
     | 
    
         
            +
                    VALUE ext         = rb_const_get(json_module, rb_intern("Ext"));
         
     | 
| 
      
 860 
     | 
    
         
            +
                    VALUE generator   = rb_const_get(ext, rb_intern("Generator"));
         
     | 
| 
      
 861 
     | 
    
         
            +
                    VALUE state_class = rb_const_get(generator, rb_intern("State"));
         
     | 
| 
       886 
862 
     | 
    
         | 
| 
       887 
     | 
    
         
            -
             
     | 
| 
       888 
     | 
    
         
            -
             
     | 
| 
      
 863 
     | 
    
         
            +
                    if (state_class == rb_obj_class(state)) {
         
     | 
| 
      
 864 
     | 
    
         
            +
                        rb_funcall(state, rb_intern("depth="), 1, INT2NUM(depth));
         
     | 
| 
      
 865 
     | 
    
         
            +
                    }
         
     | 
| 
       889 
866 
     | 
    
         
             
                }
         
     | 
| 
       890 
867 
     | 
    
         
             
            }
         
     | 
| 
       891 
868 
     | 
    
         | 
| 
       892 
     | 
    
         
            -
            void
         
     | 
| 
       893 
     | 
    
         
            -
             
     | 
| 
       894 
     | 
    
         
            -
                int	type = rb_type(obj);
         
     | 
| 
      
 869 
     | 
    
         
            +
            void oj_dump_compat_val(VALUE obj, int depth, Out out, bool as_ok) {
         
     | 
| 
      
 870 
     | 
    
         
            +
                int type = rb_type(obj);
         
     | 
| 
       895 
871 
     | 
    
         | 
| 
       896 
     | 
    
         
            -
                 
     | 
| 
       897 
     | 
    
         
            -
             
     | 
| 
       898 
     | 
    
         
            -
                 
     | 
| 
      
 872 
     | 
    
         
            +
                TRACE(out->opts->trace, "dump", obj, depth, TraceIn);
         
     | 
| 
      
 873 
     | 
    
         
            +
                // The max_nesting logic is that an empty Array or Hash is assumed to have
         
     | 
| 
      
 874 
     | 
    
         
            +
                // content so the max_nesting should fail but a non-collection value is
         
     | 
| 
      
 875 
     | 
    
         
            +
                // okay. That means a check for a collectable value is needed before
         
     | 
| 
      
 876 
     | 
    
         
            +
                // raising.
         
     | 
| 
       899 
877 
     | 
    
         
             
                if (out->opts->dump_opts.max_depth <= depth) {
         
     | 
| 
       900 
     | 
    
         
            -
             
     | 
| 
       901 
     | 
    
         
            -
             
     | 
| 
       902 
     | 
    
         
            -
             
     | 
| 
       903 
     | 
    
         
            -
             
     | 
| 
       904 
     | 
    
         
            -
             
     | 
| 
       905 
     | 
    
         
            -
             
     | 
| 
       906 
     | 
    
         
            -
            		set_state_depth(*out->argv, depth);
         
     | 
| 
       907 
     | 
    
         
            -
            	    }
         
     | 
| 
       908 
     | 
    
         
            -
            	    rb_raise(rb_eArgError, "Too deeply nested.");
         
     | 
| 
       909 
     | 
    
         
            -
            	} else if (out->opts->dump_opts.max_depth < depth) {
         
     | 
| 
       910 
     | 
    
         
            -
            	    if (0 < out->argc) {
         
     | 
| 
       911 
     | 
    
         
            -
            		set_state_depth(*out->argv, depth - 1);
         
     | 
| 
       912 
     | 
    
         
            -
            	    }
         
     | 
| 
       913 
     | 
    
         
            -
            	    raise_json_err("Too deeply nested", "NestingError");
         
     | 
| 
       914 
     | 
    
         
            -
            	}
         
     | 
| 
      
 878 
     | 
    
         
            +
                    if (RUBY_T_ARRAY == type || RUBY_T_HASH == type) {
         
     | 
| 
      
 879 
     | 
    
         
            +
                        if (0 < out->argc) {
         
     | 
| 
      
 880 
     | 
    
         
            +
                            set_state_depth(*out->argv, depth);
         
     | 
| 
      
 881 
     | 
    
         
            +
                        }
         
     | 
| 
      
 882 
     | 
    
         
            +
                        raise_json_err("Too deeply nested", "NestingError");
         
     | 
| 
      
 883 
     | 
    
         
            +
                    }
         
     | 
| 
       915 
884 
     | 
    
         
             
                }
         
     | 
| 
       916 
885 
     | 
    
         
             
                if (0 < type && type <= RUBY_T_FIXNUM) {
         
     | 
| 
       917 
     | 
    
         
            -
             
     | 
| 
      
 886 
     | 
    
         
            +
                    DumpFunc f = compat_funcs[type];
         
     | 
| 
       918 
887 
     | 
    
         | 
| 
       919 
     | 
    
         
            -
             
     | 
| 
       920 
     | 
    
         
            -
             
     | 
| 
       921 
     | 
    
         
            -
             
     | 
| 
       922 
     | 
    
         
            -
             
     | 
| 
       923 
     | 
    
         
            -
             
     | 
| 
       924 
     | 
    
         
            -
            	    return;
         
     | 
| 
       925 
     | 
    
         
            -
            	}
         
     | 
| 
      
 888 
     | 
    
         
            +
                    if (NULL != f) {
         
     | 
| 
      
 889 
     | 
    
         
            +
                        f(obj, depth, out, as_ok);
         
     | 
| 
      
 890 
     | 
    
         
            +
                        TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
         
     | 
| 
      
 891 
     | 
    
         
            +
                        return;
         
     | 
| 
      
 892 
     | 
    
         
            +
                    }
         
     | 
| 
       926 
893 
     | 
    
         
             
                }
         
     | 
| 
       927 
894 
     | 
    
         
             
                oj_dump_nil(Qnil, depth, out, false);
         
     | 
| 
       928 
     | 
    
         
            -
                 
     | 
| 
       929 
     | 
    
         
            -
            	oj_trace("dump", Qnil, __FILE__, __LINE__, depth, TraceOut);
         
     | 
| 
       930 
     | 
    
         
            -
                }
         
     | 
| 
      
 895 
     | 
    
         
            +
                TRACE(out->opts->trace, "dump", Qnil, depth, TraceOut);
         
     | 
| 
       931 
896 
     | 
    
         
             
            }
         
     |