json_pure 1.8.1 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 554b04ceae9f2a29bf212f6dd0fa7c4c0bb82fb9
4
- data.tar.gz: 23d48e4ae89c28309d00b7d6a82aa681b36fab59
3
+ metadata.gz: 4307c6679a57b7b356e8aa9b2f762aa767d7c6bf
4
+ data.tar.gz: 8a23ea3e83b70f13baec317e33528ed3d77d1010
5
5
  SHA512:
6
- metadata.gz: ca664cfceddec6eaf5bd7c7fef9df30a5cd89722c84c65728913d8ba53df0b03ea2b21aeb69d5433f55a375a9f23b962f618d53ef12de4564287154c496afaa0
7
- data.tar.gz: 9f9543babe457b825c9a9215881eb7282c11e7860613dcfebe7ad5756abdb1185fe66ce82492d3366812b871c5c6a143677de888a5d08ce3bb546efa646fa27f
6
+ metadata.gz: f62cb222ca6b639b0f61f7c2163628c9b3044c031c6e246574e467b76dd0a93513344ad9ca05d00444cefe43071ce0e0bbd1e9fe76c6e5938164ce6351b1793e
7
+ data.tar.gz: e3b6bc925f26a298d13a08740f7ffe9f18b87c8c18aaadc14681e22f830d89eb55fcc055373e0c6f45ebfdeff4cd93b67f4cdc37535d761716bce9f2493bfcd3
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  .*.sw[pon]
2
+ *.bundle
2
3
  coverage
3
4
  tags
4
5
  pkg
@@ -11,3 +12,5 @@ Gemfile.lock
11
12
  .rbx
12
13
  .AppleDouble
13
14
  .DS_Store
15
+ */**/Makefile
16
+ */**/*.o
@@ -1,5 +1,6 @@
1
1
  # Passes arguments to bundle install (http://gembundler.com/man/bundle-install.1.html)
2
- bundler_args: --binstubs
2
+ #bundler_args: --binstubs
3
+ language: ruby
3
4
 
4
5
  # Specify which ruby versions you wish to run your tests on, each version will be used
5
6
  rvm:
@@ -7,14 +8,17 @@ rvm:
7
8
  - 1.9.2
8
9
  - 1.9.3
9
10
  - 2.0.0
11
+ - 2.1
12
+ - 2.2
10
13
  - ree
11
- - rbx-18mode
12
- - rbx-19mode
14
+ - rbx-2
13
15
  - jruby-18mode
14
16
  - jruby-19mode
15
17
  - ruby-head
16
18
  matrix:
17
19
  allow_failures:
18
- - rvm: rbx-18mode
19
- - rvm: rbx-19mode
20
+ - rvm: rbx-2
21
+ - rvm: ruby-head
20
22
  script: "bundle exec rake"
23
+
24
+ sudo: false
data/CHANGES CHANGED
@@ -1,3 +1,12 @@
1
+ 2015-01-08 (1.8.2)
2
+ * Some performance improvements by Vipul A M <vipulnsward@gmail.com>.
3
+ * Fix by Jason R. Clark <jclark@newrelic.com> to avoid mutation of
4
+ JSON.dump_default_options.
5
+ * More tests by Michael Mac-Vicar <mmacvicar@gmail.com> and fixing
6
+ space_before accessor in generator.
7
+ * Performance on Jruby improvemed by Ben Browning <bbrownin@redhat.com>.
8
+ * Some fixes to be compatible with the new Ruby 2.2 by Zachary Scott <e@zzak.io>
9
+ and SHIBATA Hiroshi <hsbt@ruby-lang.org>.
1
10
  2013-05-13 (1.8.1)
2
11
  * Remove Rubinius exception since transcoding should be working now.
3
12
  2013-05-13 (1.8.0)
data/Gemfile CHANGED
@@ -8,4 +8,3 @@ gemspec :name => 'json-java'
8
8
 
9
9
  gem 'utils'
10
10
  gem 'test-unit'
11
- gem 'debugger', :platform => :mri_19
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.1
1
+ 1.8.2
@@ -25,6 +25,15 @@
25
25
  #define RSTRING_LEN(string) RSTRING(string)->len
26
26
  #endif
27
27
 
28
+ #ifdef PRIsVALUE
29
+ # define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
30
+ # define RB_OBJ_STRING(obj) (obj)
31
+ #else
32
+ # define PRIsVALUE "s"
33
+ # define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
34
+ # define RB_OBJ_STRING(obj) StringValueCStr(obj)
35
+ #endif
36
+
28
37
  #ifdef HAVE_RUBY_ENCODING_H
29
38
  #include "ruby/encoding.h"
30
39
  #define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
@@ -172,7 +181,7 @@ static FBuffer *fbuffer_dup(FBuffer *fb)
172
181
 
173
182
  static VALUE fbuffer_to_s(FBuffer *fb)
174
183
  {
175
- VALUE result = rb_str_new(FBUFFER_PAIR(fb));
184
+ VALUE result = rb_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));
176
185
  fbuffer_free(fb);
177
186
  FORCE_UTF8(result);
178
187
  return result;
@@ -1,14 +1,4 @@
1
1
  require 'mkmf'
2
2
 
3
- unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
4
- $CFLAGS << ' -O3'
5
- end
6
- if CONFIG['CC'] =~ /gcc/
7
- $CFLAGS << ' -Wall'
8
- unless $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
9
- $CFLAGS << ' -O0 -ggdb'
10
- end
11
- end
12
-
13
3
  $defs << "-DJSON_GENERATOR"
14
4
  create_makefile 'json/ext/generator'
@@ -486,8 +486,9 @@ static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self)
486
486
  return cState_partial_generate(state, string);
487
487
  }
488
488
 
489
- static void State_free(JSON_Generator_State *state)
489
+ static void State_free(void *ptr)
490
490
  {
491
+ JSON_Generator_State *state = ptr;
491
492
  if (state->indent) ruby_xfree(state->indent);
492
493
  if (state->space) ruby_xfree(state->space);
493
494
  if (state->space_before) ruby_xfree(state->space_before);
@@ -499,7 +500,33 @@ static void State_free(JSON_Generator_State *state)
499
500
  ruby_xfree(state);
500
501
  }
501
502
 
502
- static JSON_Generator_State *State_allocate()
503
+ static size_t State_memsize(const void *ptr)
504
+ {
505
+ const JSON_Generator_State *state = ptr;
506
+ size_t size = sizeof(*state);
507
+ if (state->indent) size += state->indent_len + 1;
508
+ if (state->space) size += state->space_len + 1;
509
+ if (state->space_before) size += state->space_before_len + 1;
510
+ if (state->object_nl) size += state->object_nl_len + 1;
511
+ if (state->array_nl) size += state->array_nl_len + 1;
512
+ if (state->array_delim) size += FBUFFER_CAPA(state->array_delim);
513
+ if (state->object_delim) size += FBUFFER_CAPA(state->object_delim);
514
+ if (state->object_delim2) size += FBUFFER_CAPA(state->object_delim2);
515
+ return size;
516
+ }
517
+
518
+ #ifdef NEW_TYPEDDATA_WRAPPER
519
+ static const rb_data_type_t JSON_Generator_State_type = {
520
+ "JSON/Generator/State",
521
+ {NULL, State_free, State_memsize,},
522
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
523
+ 0, 0,
524
+ RUBY_TYPED_FREE_IMMEDIATELY,
525
+ #endif
526
+ };
527
+ #endif
528
+
529
+ static JSON_Generator_State *State_allocate(void)
503
530
  {
504
531
  JSON_Generator_State *state = ALLOC(JSON_Generator_State);
505
532
  MEMZERO(state, JSON_Generator_State, 1);
@@ -509,7 +536,7 @@ static JSON_Generator_State *State_allocate()
509
536
  static VALUE cState_s_allocate(VALUE klass)
510
537
  {
511
538
  JSON_Generator_State *state = State_allocate();
512
- return Data_Wrap_Struct(klass, NULL, State_free, state);
539
+ return TypedData_Wrap_Struct(klass, &JSON_Generator_State_type, state);
513
540
  }
514
541
 
515
542
  /*
@@ -646,7 +673,7 @@ static VALUE cState_to_h(VALUE self)
646
673
  /*
647
674
  * call-seq: [](name)
648
675
  *
649
- * Return the value returned by method +name+.
676
+ * Returns the value returned by method +name+.
650
677
  */
651
678
  static VALUE cState_aref(VALUE self, VALUE name)
652
679
  {
@@ -661,7 +688,7 @@ static VALUE cState_aref(VALUE self, VALUE name)
661
688
  /*
662
689
  * call-seq: []=(name, value)
663
690
  *
664
- * Set the attribute name to value.
691
+ * Sets the attribute name to value.
665
692
  */
666
693
  static VALUE cState_aset(VALUE self, VALUE name, VALUE value)
667
694
  {
@@ -812,10 +839,10 @@ static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_St
812
839
  if (!allow_nan) {
813
840
  if (isinf(value)) {
814
841
  fbuffer_free(buffer);
815
- rb_raise(eGeneratorError, "%u: %s not allowed in JSON", __LINE__, StringValueCStr(tmp));
842
+ rb_raise(eGeneratorError, "%u: %"PRIsVALUE" not allowed in JSON", __LINE__, RB_OBJ_STRING(tmp));
816
843
  } else if (isnan(value)) {
817
844
  fbuffer_free(buffer);
818
- rb_raise(eGeneratorError, "%u: %s not allowed in JSON", __LINE__, StringValueCStr(tmp));
845
+ rb_raise(eGeneratorError, "%u: %"PRIsVALUE" not allowed in JSON", __LINE__, RB_OBJ_STRING(tmp));
819
846
  }
820
847
  }
821
848
  fbuffer_append_str(buffer, tmp);
@@ -871,6 +898,7 @@ static FBuffer *cState_prepare_buffer(VALUE self)
871
898
  } else {
872
899
  state->object_delim2 = fbuffer_alloc(16);
873
900
  }
901
+ if (state->space_before) fbuffer_append(state->object_delim2, state->space_before, state->space_before_len);
874
902
  fbuffer_append_char(state->object_delim2, ':');
875
903
  if (state->space) fbuffer_append(state->object_delim2, state->space, state->space_len);
876
904
 
@@ -958,15 +986,16 @@ static VALUE cState_initialize(int argc, VALUE *argv, VALUE self)
958
986
  /*
959
987
  * call-seq: initialize_copy(orig)
960
988
  *
961
- * Initializes this object from orig if it to be duplicated/cloned and returns
989
+ * Initializes this object from orig if it can be duplicated/cloned and returns
962
990
  * it.
963
991
  */
964
992
  static VALUE cState_init_copy(VALUE obj, VALUE orig)
965
993
  {
966
994
  JSON_Generator_State *objState, *origState;
967
995
 
968
- Data_Get_Struct(obj, JSON_Generator_State, objState);
969
- Data_Get_Struct(orig, JSON_Generator_State, origState);
996
+ if (obj == orig) return obj;
997
+ GET_STATE_TO(obj, objState);
998
+ GET_STATE_TO(orig, origState);
970
999
  if (!objState) rb_raise(rb_eArgError, "unallocated JSON::State");
971
1000
 
972
1001
  MEMCPY(objState, origState, JSON_Generator_State, 1);
@@ -1005,7 +1034,7 @@ static VALUE cState_from_state_s(VALUE self, VALUE opts)
1005
1034
  /*
1006
1035
  * call-seq: indent()
1007
1036
  *
1008
- * This string is used to indent levels in the JSON text.
1037
+ * Returns the string that is used to indent levels in the JSON text.
1009
1038
  */
1010
1039
  static VALUE cState_indent(VALUE self)
1011
1040
  {
@@ -1016,7 +1045,7 @@ static VALUE cState_indent(VALUE self)
1016
1045
  /*
1017
1046
  * call-seq: indent=(indent)
1018
1047
  *
1019
- * This string is used to indent levels in the JSON text.
1048
+ * Sets the string that is used to indent levels in the JSON text.
1020
1049
  */
1021
1050
  static VALUE cState_indent_set(VALUE self, VALUE indent)
1022
1051
  {
@@ -1041,7 +1070,7 @@ static VALUE cState_indent_set(VALUE self, VALUE indent)
1041
1070
  /*
1042
1071
  * call-seq: space()
1043
1072
  *
1044
- * This string is used to insert a space between the tokens in a JSON
1073
+ * Returns the string that is used to insert a space between the tokens in a JSON
1045
1074
  * string.
1046
1075
  */
1047
1076
  static VALUE cState_space(VALUE self)
@@ -1053,7 +1082,7 @@ static VALUE cState_space(VALUE self)
1053
1082
  /*
1054
1083
  * call-seq: space=(space)
1055
1084
  *
1056
- * This string is used to insert a space between the tokens in a JSON
1085
+ * Sets _space_ to the string that is used to insert a space between the tokens in a JSON
1057
1086
  * string.
1058
1087
  */
1059
1088
  static VALUE cState_space_set(VALUE self, VALUE space)
@@ -1079,7 +1108,7 @@ static VALUE cState_space_set(VALUE self, VALUE space)
1079
1108
  /*
1080
1109
  * call-seq: space_before()
1081
1110
  *
1082
- * This string is used to insert a space before the ':' in JSON objects.
1111
+ * Returns the string that is used to insert a space before the ':' in JSON objects.
1083
1112
  */
1084
1113
  static VALUE cState_space_before(VALUE self)
1085
1114
  {
@@ -1090,7 +1119,7 @@ static VALUE cState_space_before(VALUE self)
1090
1119
  /*
1091
1120
  * call-seq: space_before=(space_before)
1092
1121
  *
1093
- * This string is used to insert a space before the ':' in JSON objects.
1122
+ * Sets the string that is used to insert a space before the ':' in JSON objects.
1094
1123
  */
1095
1124
  static VALUE cState_space_before_set(VALUE self, VALUE space_before)
1096
1125
  {
@@ -1297,7 +1326,7 @@ static VALUE cState_depth_set(VALUE self, VALUE depth)
1297
1326
  /*
1298
1327
  * call-seq: buffer_initial_length
1299
1328
  *
1300
- * This integer returns the current inital length of the buffer.
1329
+ * This integer returns the current initial length of the buffer.
1301
1330
  */
1302
1331
  static VALUE cState_buffer_initial_length(VALUE self)
1303
1332
  {
@@ -1326,7 +1355,7 @@ static VALUE cState_buffer_initial_length_set(VALUE self, VALUE buffer_initial_l
1326
1355
  /*
1327
1356
  *
1328
1357
  */
1329
- void Init_generator()
1358
+ void Init_generator(void)
1330
1359
  {
1331
1360
  rb_require("json/common");
1332
1361
 
@@ -23,7 +23,7 @@
23
23
 
24
24
  #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
25
25
 
26
- /* unicode defintions */
26
+ /* unicode definitions */
27
27
 
28
28
  #define UNI_STRICT_CONVERSION 1
29
29
 
@@ -78,9 +78,12 @@ typedef struct JSON_Generator_StateStruct {
78
78
  long buffer_initial_length;
79
79
  } JSON_Generator_State;
80
80
 
81
+ #define GET_STATE_TO(self, state) \
82
+ TypedData_Get_Struct(self, JSON_Generator_State, &JSON_Generator_State_type, state)
83
+
81
84
  #define GET_STATE(self) \
82
85
  JSON_Generator_State *state; \
83
- Data_Get_Struct(self, JSON_Generator_State, state)
86
+ GET_STATE_TO(self, state)
84
87
 
85
88
  #define GENERATE_JSON(type) \
86
89
  FBuffer *buffer; \
@@ -89,7 +92,7 @@ typedef struct JSON_Generator_StateStruct {
89
92
  \
90
93
  rb_scan_args(argc, argv, "01", &Vstate); \
91
94
  Vstate = cState_from_state_s(cState, Vstate); \
92
- Data_Get_Struct(Vstate, JSON_Generator_State, state); \
95
+ TypedData_Get_Struct(Vstate, JSON_Generator_State, &JSON_Generator_State_type, state); \
93
96
  buffer = cState_prepare_buffer(Vstate); \
94
97
  generate_json_##type(buffer, Vstate, state, self); \
95
98
  return fbuffer_to_s(buffer)
@@ -108,8 +111,8 @@ static VALUE mTrueClass_to_json(int argc, VALUE *argv, VALUE self);
108
111
  static VALUE mFalseClass_to_json(int argc, VALUE *argv, VALUE self);
109
112
  static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self);
110
113
  static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self);
111
- static void State_free(JSON_Generator_State *state);
112
- static JSON_Generator_State *State_allocate();
114
+ static void State_free(void *state);
115
+ static JSON_Generator_State *State_allocate(void);
113
116
  static VALUE cState_s_allocate(VALUE klass);
114
117
  static VALUE cState_configure(VALUE self, VALUE opts);
115
118
  static VALUE cState_to_h(VALUE self);
@@ -144,5 +147,12 @@ static VALUE cState_ascii_only_p(VALUE self);
144
147
  static VALUE cState_depth(VALUE self);
145
148
  static VALUE cState_depth_set(VALUE self, VALUE depth);
146
149
  static FBuffer *cState_prepare_buffer(VALUE self);
150
+ #ifdef TypedData_Wrap_Struct
151
+ static const rb_data_type_t JSON_Generator_State_type;
152
+ #define NEW_TYPEDDATA_WRAPPER 1
153
+ #else
154
+ #define TypedData_Wrap_Struct(klass, ignore, json) Data_Wrap_Struct(klass, NULL, State_free, json)
155
+ #define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json)
156
+ #endif
147
157
 
148
158
  #endif
@@ -1,13 +1,3 @@
1
1
  require 'mkmf'
2
2
 
3
- unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
4
- $CFLAGS << ' -O3'
5
- end
6
- if CONFIG['CC'] =~ /gcc/
7
- $CFLAGS << ' -Wall'
8
- if $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
9
- $CFLAGS << ' -O0 -ggdb'
10
- end
11
- end
12
-
13
3
  create_makefile 'json/ext/parser'
@@ -1626,8 +1626,8 @@ static VALUE convert_encoding(VALUE source)
1626
1626
  * (keys) in a JSON object. Otherwise strings are returned, which is also
1627
1627
  * the default.
1628
1628
  * * *create_additions*: If set to false, the Parser doesn't create
1629
- * additions even if a matchin class and create_id was found. This option
1630
- * defaults to true.
1629
+ * additions even if a matching class and create_id was found. This option
1630
+ * defaults to false.
1631
1631
  * * *object_class*: Defaults to Hash
1632
1632
  * * *array_class*: Defaults to Array
1633
1633
  */
@@ -2092,7 +2092,7 @@ static VALUE cParser_parse(VALUE self)
2092
2092
  }
2093
2093
 
2094
2094
 
2095
- static JSON_Parser *JSON_allocate()
2095
+ static JSON_Parser *JSON_allocate(void)
2096
2096
  {
2097
2097
  JSON_Parser *json = ALLOC(JSON_Parser);
2098
2098
  MEMZERO(json, JSON_Parser, 1);
@@ -2100,8 +2100,9 @@ static JSON_Parser *JSON_allocate()
2100
2100
  return json;
2101
2101
  }
2102
2102
 
2103
- static void JSON_mark(JSON_Parser *json)
2103
+ static void JSON_mark(void *ptr)
2104
2104
  {
2105
+ JSON_Parser *json = ptr;
2105
2106
  rb_gc_mark_maybe(json->Vsource);
2106
2107
  rb_gc_mark_maybe(json->create_id);
2107
2108
  rb_gc_mark_maybe(json->object_class);
@@ -2109,16 +2110,34 @@ static void JSON_mark(JSON_Parser *json)
2109
2110
  rb_gc_mark_maybe(json->match_string);
2110
2111
  }
2111
2112
 
2112
- static void JSON_free(JSON_Parser *json)
2113
+ static void JSON_free(void *ptr)
2113
2114
  {
2115
+ JSON_Parser *json = ptr;
2114
2116
  fbuffer_free(json->fbuffer);
2115
2117
  ruby_xfree(json);
2116
2118
  }
2117
2119
 
2120
+ static size_t JSON_memsize(const void *ptr)
2121
+ {
2122
+ const JSON_Parser *json = ptr;
2123
+ return sizeof(*json) + FBUFFER_CAPA(json->fbuffer);
2124
+ }
2125
+
2126
+ #ifdef NEW_TYPEDDATA_WRAPPER
2127
+ static const rb_data_type_t JSON_Parser_type = {
2128
+ "JSON/Parser",
2129
+ {JSON_mark, JSON_free, JSON_memsize,},
2130
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
2131
+ 0, 0,
2132
+ RUBY_TYPED_FREE_IMMEDIATELY,
2133
+ #endif
2134
+ };
2135
+ #endif
2136
+
2118
2137
  static VALUE cJSON_parser_s_allocate(VALUE klass)
2119
2138
  {
2120
2139
  JSON_Parser *json = JSON_allocate();
2121
- return Data_Wrap_Struct(klass, JSON_mark, JSON_free, json);
2140
+ return TypedData_Wrap_Struct(klass, &JSON_Parser_type, json);
2122
2141
  }
2123
2142
 
2124
2143
  /*
@@ -51,7 +51,7 @@ typedef struct JSON_ParserStruct {
51
51
  if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance")
52
52
  #define GET_PARSER_INIT \
53
53
  JSON_Parser *json; \
54
- Data_Get_Struct(self, JSON_Parser, json)
54
+ TypedData_Get_Struct(self, JSON_Parser, &JSON_Parser_type, json)
55
55
 
56
56
  #define MinusInfinity "-Infinity"
57
57
  #define EVIL 0x666
@@ -68,10 +68,17 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
68
68
  static VALUE convert_encoding(VALUE source);
69
69
  static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self);
70
70
  static VALUE cParser_parse(VALUE self);
71
- static JSON_Parser *JSON_allocate();
72
- static void JSON_mark(JSON_Parser *json);
73
- static void JSON_free(JSON_Parser *json);
71
+ static JSON_Parser *JSON_allocate(void);
72
+ static void JSON_mark(void *json);
73
+ static void JSON_free(void *json);
74
74
  static VALUE cJSON_parser_s_allocate(VALUE klass);
75
75
  static VALUE cParser_source(VALUE self);
76
+ #ifdef TypedData_Wrap_Struct
77
+ static const rb_data_type_t JSON_Parser_type;
78
+ #define NEW_TYPEDDATA_WRAPPER 1
79
+ #else
80
+ #define TypedData_Wrap_Struct(klass, ignore, json) Data_Wrap_Struct(klass, JSON_mark, JSON_free, json)
81
+ #define TypedData_Get_Struct(self, JSON_Parser, ignore, json) Data_Get_Struct(self, JSON_Parser, json)
82
+ #endif
76
83
 
77
84
  #endif