msgpack 1.5.6 → 1.6.1

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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +14 -0
  3. data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +4 -9
  4. data/ext/msgpack/buffer.c +51 -38
  5. data/ext/msgpack/buffer.h +5 -9
  6. data/ext/msgpack/buffer_class.c +62 -32
  7. data/ext/msgpack/extconf.rb +3 -5
  8. data/ext/msgpack/factory_class.c +49 -26
  9. data/ext/msgpack/packer.c +3 -4
  10. data/ext/msgpack/packer.h +2 -2
  11. data/ext/msgpack/packer_class.c +58 -63
  12. data/ext/msgpack/packer_class.h +11 -0
  13. data/ext/msgpack/packer_ext_registry.c +2 -2
  14. data/ext/msgpack/packer_ext_registry.h +2 -2
  15. data/ext/msgpack/rbinit.c +1 -1
  16. data/ext/msgpack/sysdep.h +5 -2
  17. data/ext/msgpack/unpacker.c +6 -9
  18. data/ext/msgpack/unpacker.h +4 -3
  19. data/ext/msgpack/unpacker_class.c +55 -37
  20. data/ext/msgpack/unpacker_class.h +11 -0
  21. data/ext/msgpack/unpacker_ext_registry.c +2 -2
  22. data/ext/msgpack/unpacker_ext_registry.h +2 -2
  23. data/lib/msgpack/buffer.rb +9 -0
  24. data/lib/msgpack/packer.rb +4 -0
  25. data/lib/msgpack/unpacker.rb +4 -0
  26. data/lib/msgpack/version.rb +1 -1
  27. data/lib/msgpack.rb +1 -0
  28. data/msgpack.gemspec +5 -2
  29. metadata +18 -46
  30. data/.github/workflows/ci.yaml +0 -57
  31. data/.gitignore +0 -23
  32. data/.rubocop.yml +0 -36
  33. data/Gemfile +0 -9
  34. data/Rakefile +0 -70
  35. data/appveyor.yml +0 -18
  36. data/bench/bench.rb +0 -78
  37. data/doclib/msgpack/buffer.rb +0 -193
  38. data/doclib/msgpack/core_ext.rb +0 -101
  39. data/doclib/msgpack/error.rb +0 -19
  40. data/doclib/msgpack/extension_value.rb +0 -9
  41. data/doclib/msgpack/factory.rb +0 -145
  42. data/doclib/msgpack/packer.rb +0 -209
  43. data/doclib/msgpack/time.rb +0 -22
  44. data/doclib/msgpack/timestamp.rb +0 -44
  45. data/doclib/msgpack/unpacker.rb +0 -183
  46. data/doclib/msgpack.rb +0 -87
  47. data/msgpack.org.md +0 -46
  48. data/spec/bigint_spec.rb +0 -26
  49. data/spec/cases.json +0 -1
  50. data/spec/cases.msg +0 -0
  51. data/spec/cases_compact.msg +0 -0
  52. data/spec/cases_spec.rb +0 -39
  53. data/spec/cruby/buffer_io_spec.rb +0 -255
  54. data/spec/cruby/buffer_packer.rb +0 -29
  55. data/spec/cruby/buffer_spec.rb +0 -575
  56. data/spec/cruby/buffer_unpacker.rb +0 -19
  57. data/spec/cruby/unpacker_spec.rb +0 -70
  58. data/spec/ext_value_spec.rb +0 -99
  59. data/spec/exttypes.rb +0 -51
  60. data/spec/factory_spec.rb +0 -688
  61. data/spec/format_spec.rb +0 -301
  62. data/spec/jruby/benchmarks/shootout_bm.rb +0 -73
  63. data/spec/jruby/benchmarks/symbolize_keys_bm.rb +0 -25
  64. data/spec/jruby/unpacker_spec.rb +0 -186
  65. data/spec/msgpack_spec.rb +0 -214
  66. data/spec/pack_spec.rb +0 -61
  67. data/spec/packer_spec.rb +0 -575
  68. data/spec/random_compat.rb +0 -24
  69. data/spec/spec_helper.rb +0 -71
  70. data/spec/timestamp_spec.rb +0 -159
  71. data/spec/unpack_spec.rb +0 -57
  72. data/spec/unpacker_spec.rb +0 -859
@@ -37,15 +37,10 @@ struct msgpack_factory_t {
37
37
  int symbol_ext_type;
38
38
  };
39
39
 
40
- #define FACTORY(from, name) \
41
- msgpack_factory_t *name = NULL; \
42
- Data_Get_Struct(from, msgpack_factory_t, name); \
43
- if(name == NULL) { \
44
- rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
45
- }
46
-
47
- static void Factory_free(msgpack_factory_t* fc)
40
+ static void Factory_free(void *ptr)
48
41
  {
42
+ msgpack_factory_t *fc = ptr;
43
+
49
44
  if(fc == NULL) {
50
45
  return;
51
46
  }
@@ -54,23 +49,54 @@ static void Factory_free(msgpack_factory_t* fc)
54
49
  xfree(fc);
55
50
  }
56
51
 
57
- void Factory_mark(msgpack_factory_t* fc)
52
+ void Factory_mark(void *ptr)
58
53
  {
54
+ msgpack_factory_t *fc = ptr;
59
55
  msgpack_packer_ext_registry_mark(&fc->pkrg);
60
56
  msgpack_unpacker_ext_registry_mark(fc->ukrg);
61
57
  }
62
58
 
63
- static VALUE Factory_alloc(VALUE klass)
59
+ static size_t Factory_memsize(const void *ptr)
64
60
  {
65
- msgpack_factory_t* fc = ZALLOC_N(msgpack_factory_t, 1);
61
+ const msgpack_factory_t *fc = ptr;
62
+ size_t total_size = sizeof(msgpack_factory_t);
66
63
 
67
- VALUE self = Data_Wrap_Struct(klass, Factory_mark, Factory_free, fc);
68
- return self;
64
+ if (fc->ukrg) {
65
+ total_size += sizeof(msgpack_unpacker_ext_registry_t) / (fc->ukrg->borrow_count + 1);
66
+ }
67
+
68
+ return total_size;
69
+ }
70
+
71
+ static const rb_data_type_t factory_data_type = {
72
+ .wrap_struct_name = "msgpack:factory",
73
+ .function = {
74
+ .dmark = Factory_mark,
75
+ .dfree = Factory_free,
76
+ .dsize = Factory_memsize,
77
+ },
78
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
79
+ };
80
+
81
+ static inline msgpack_factory_t *Factory_get(VALUE object)
82
+ {
83
+ msgpack_factory_t *factory;
84
+ TypedData_Get_Struct(object, msgpack_factory_t, &factory_data_type, factory);
85
+ if (!factory) {
86
+ rb_raise(rb_eArgError, "Uninitialized Factory object");
87
+ }
88
+ return factory;
89
+ }
90
+
91
+ static VALUE Factory_alloc(VALUE klass)
92
+ {
93
+ msgpack_factory_t *fc;
94
+ return TypedData_Make_Struct(klass, msgpack_factory_t, &factory_data_type, fc);
69
95
  }
70
96
 
71
97
  static VALUE Factory_initialize(int argc, VALUE* argv, VALUE self)
72
98
  {
73
- FACTORY(self, fc);
99
+ msgpack_factory_t *fc = Factory_get(self);
74
100
 
75
101
  msgpack_packer_ext_registry_init(&fc->pkrg);
76
102
  // fc->ukrg is lazily initialized
@@ -92,8 +118,8 @@ static VALUE Factory_dup(VALUE self)
92
118
  {
93
119
  VALUE clone = Factory_alloc(rb_obj_class(self));
94
120
 
95
- FACTORY(self, fc);
96
- FACTORY(clone, cloned_fc);
121
+ msgpack_factory_t *fc = Factory_get(self);
122
+ msgpack_factory_t *cloned_fc = Factory_get(clone);
97
123
 
98
124
  cloned_fc->has_symbol_ext_type = fc->has_symbol_ext_type;
99
125
  cloned_fc->pkrg = fc->pkrg;
@@ -105,7 +131,7 @@ static VALUE Factory_dup(VALUE self)
105
131
 
106
132
  static VALUE Factory_freeze(VALUE self) {
107
133
  if(!rb_obj_frozen_p(self)) {
108
- FACTORY(self, fc);
134
+ msgpack_factory_t *fc = Factory_get(self);
109
135
 
110
136
  if (RTEST(fc->pkrg.hash)) {
111
137
  rb_hash_freeze(fc->pkrg.hash);
@@ -125,14 +151,12 @@ static VALUE Factory_freeze(VALUE self) {
125
151
 
126
152
  VALUE MessagePack_Factory_packer(int argc, VALUE* argv, VALUE self)
127
153
  {
128
- FACTORY(self, fc);
154
+ msgpack_factory_t *fc = Factory_get(self);
129
155
 
130
156
  VALUE packer = MessagePack_Packer_alloc(cMessagePack_Packer);
131
157
  MessagePack_Packer_initialize(argc, argv, packer);
132
158
 
133
- msgpack_packer_t* pk;
134
- Data_Get_Struct(packer, msgpack_packer_t, pk);
135
-
159
+ msgpack_packer_t* pk = MessagePack_Packer_get(packer);
136
160
  msgpack_packer_ext_registry_destroy(&pk->ext_registry);
137
161
  msgpack_packer_ext_registry_dup(&fc->pkrg, &pk->ext_registry);
138
162
  pk->has_bigint_ext_type = fc->has_bigint_ext_type;
@@ -143,13 +167,12 @@ VALUE MessagePack_Factory_packer(int argc, VALUE* argv, VALUE self)
143
167
 
144
168
  VALUE MessagePack_Factory_unpacker(int argc, VALUE* argv, VALUE self)
145
169
  {
146
- FACTORY(self, fc);
170
+ msgpack_factory_t *fc = Factory_get(self);
147
171
 
148
172
  VALUE unpacker = MessagePack_Unpacker_alloc(cMessagePack_Unpacker);
149
173
  MessagePack_Unpacker_initialize(argc, argv, unpacker);
150
174
 
151
- msgpack_unpacker_t* uk;
152
- Data_Get_Struct(unpacker, msgpack_unpacker_t, uk);
175
+ msgpack_unpacker_t* uk = MessagePack_Unpacker_get(unpacker);
153
176
  msgpack_unpacker_ext_registry_borrow(fc->ukrg, &uk->ext_registry);
154
177
  uk->optimized_symbol_ext_type = fc->optimized_symbol_ext_type;
155
178
  uk->symbol_ext_type = fc->symbol_ext_type;
@@ -159,7 +182,7 @@ VALUE MessagePack_Factory_unpacker(int argc, VALUE* argv, VALUE self)
159
182
 
160
183
  static VALUE Factory_registered_types_internal(VALUE self)
161
184
  {
162
- FACTORY(self, fc);
185
+ msgpack_factory_t *fc = Factory_get(self);
163
186
 
164
187
  VALUE uk_mapping = rb_hash_new();
165
188
  if (fc->ukrg) {
@@ -179,7 +202,7 @@ static VALUE Factory_registered_types_internal(VALUE self)
179
202
 
180
203
  static VALUE Factory_register_type(int argc, VALUE* argv, VALUE self)
181
204
  {
182
- FACTORY(self, fc);
205
+ msgpack_factory_t *fc = Factory_get(self);
183
206
 
184
207
  int ext_type;
185
208
  int flags = 0;
data/ext/msgpack/packer.c CHANGED
@@ -20,18 +20,16 @@
20
20
 
21
21
  static ID s_call;
22
22
 
23
- void msgpack_packer_static_init()
23
+ void msgpack_packer_static_init(void)
24
24
  {
25
25
  s_call = rb_intern("call");
26
26
  }
27
27
 
28
- void msgpack_packer_static_destroy()
28
+ void msgpack_packer_static_destroy(void)
29
29
  { }
30
30
 
31
31
  void msgpack_packer_init(msgpack_packer_t* pk)
32
32
  {
33
- memset(pk, 0, sizeof(msgpack_packer_t));
34
-
35
33
  msgpack_buffer_init(PACKER_BUFFER_(pk));
36
34
  }
37
35
 
@@ -45,6 +43,7 @@ void msgpack_packer_mark(msgpack_packer_t* pk)
45
43
  /* See MessagePack_Buffer_wrap */
46
44
  /* msgpack_buffer_mark(PACKER_BUFFER_(pk)); */
47
45
  rb_gc_mark(pk->buffer_ref);
46
+ rb_gc_mark(pk->to_msgpack_arg);
48
47
  }
49
48
 
50
49
  void msgpack_packer_reset(msgpack_packer_t* pk)
data/ext/msgpack/packer.h CHANGED
@@ -47,9 +47,9 @@ struct msgpack_packer_t {
47
47
 
48
48
  #define PACKER_BUFFER_(pk) (&(pk)->buffer)
49
49
 
50
- void msgpack_packer_static_init();
50
+ void msgpack_packer_static_init(void);
51
51
 
52
- void msgpack_packer_static_destroy();
52
+ void msgpack_packer_static_destroy(void);
53
53
 
54
54
  void msgpack_packer_init(msgpack_packer_t* pk);
55
55
 
@@ -33,15 +33,9 @@ static VALUE sym_compatibility_mode;
33
33
  //static VALUE s_packer_value;
34
34
  //static msgpack_packer_t* s_packer;
35
35
 
36
- #define PACKER(from, name) \
37
- msgpack_packer_t* name; \
38
- Data_Get_Struct(from, msgpack_packer_t, name); \
39
- if(name == NULL) { \
40
- rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
41
- }
42
-
43
- static void Packer_free(msgpack_packer_t* pk)
36
+ static void Packer_free(void *ptr)
44
37
  {
38
+ msgpack_packer_t* pk = ptr;
45
39
  if(pk == NULL) {
46
40
  return;
47
41
  }
@@ -50,21 +44,37 @@ static void Packer_free(msgpack_packer_t* pk)
50
44
  xfree(pk);
51
45
  }
52
46
 
53
- static void Packer_mark(msgpack_packer_t* pk)
47
+ static void Packer_mark(void *ptr)
54
48
  {
49
+ msgpack_packer_t* pk = ptr;
50
+ msgpack_buffer_mark(pk);
55
51
  msgpack_packer_mark(pk);
56
52
  msgpack_packer_ext_registry_mark(&pk->ext_registry);
57
53
  }
58
54
 
59
- VALUE MessagePack_Packer_alloc(VALUE klass)
55
+ static size_t Packer_memsize(const void *ptr)
60
56
  {
61
- msgpack_packer_t* pk = ZALLOC_N(msgpack_packer_t, 1);
62
- msgpack_packer_init(pk);
57
+ const msgpack_packer_t* pk = ptr;
58
+ return sizeof(msgpack_packer_t) + msgpack_buffer_memsize(&pk->buffer);
59
+ }
63
60
 
64
- VALUE self = Data_Wrap_Struct(klass, Packer_mark, Packer_free, pk);
61
+ const rb_data_type_t packer_data_type = {
62
+ .wrap_struct_name = "msgpack:packer",
63
+ .function = {
64
+ .dmark = Packer_mark,
65
+ .dfree = Packer_free,
66
+ .dsize = Packer_memsize,
67
+ },
68
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
69
+ };
65
70
 
66
- msgpack_packer_set_to_msgpack_method(pk, s_to_msgpack, self);
67
71
 
72
+ VALUE MessagePack_Packer_alloc(VALUE klass)
73
+ {
74
+ msgpack_packer_t* pk;
75
+ VALUE self = TypedData_Make_Struct(klass, msgpack_packer_t, &packer_data_type, pk);
76
+ msgpack_packer_init(pk);
77
+ msgpack_packer_set_to_msgpack_method(pk, s_to_msgpack, self);
68
78
  return self;
69
79
  }
70
80
 
@@ -94,10 +104,10 @@ VALUE MessagePack_Packer_initialize(int argc, VALUE* argv, VALUE self)
94
104
  Check_Type(options, T_HASH);
95
105
  }
96
106
 
97
- PACKER(self, pk);
107
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
98
108
 
99
109
  msgpack_packer_ext_registry_init(&pk->ext_registry);
100
- pk->buffer_ref = MessagePack_Buffer_wrap(PACKER_BUFFER_(pk), self);
110
+ pk->buffer_ref = Qnil;
101
111
 
102
112
  MessagePack_Buffer_set_options(PACKER_BUFFER_(pk), io, options);
103
113
 
@@ -113,54 +123,57 @@ VALUE MessagePack_Packer_initialize(int argc, VALUE* argv, VALUE self)
113
123
 
114
124
  static VALUE Packer_compatibility_mode_p(VALUE self)
115
125
  {
116
- PACKER(self, pk);
126
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
117
127
  return pk->compatibility_mode ? Qtrue : Qfalse;
118
128
  }
119
129
 
120
130
  static VALUE Packer_buffer(VALUE self)
121
131
  {
122
- PACKER(self, pk);
132
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
133
+ if (!RTEST(pk->buffer_ref)) {
134
+ pk->buffer_ref = MessagePack_Buffer_wrap(PACKER_BUFFER_(pk), self);
135
+ }
123
136
  return pk->buffer_ref;
124
137
  }
125
138
 
126
139
  static VALUE Packer_write(VALUE self, VALUE v)
127
140
  {
128
- PACKER(self, pk);
141
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
129
142
  msgpack_packer_write_value(pk, v);
130
143
  return self;
131
144
  }
132
145
 
133
146
  static VALUE Packer_write_nil(VALUE self)
134
147
  {
135
- PACKER(self, pk);
148
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
136
149
  msgpack_packer_write_nil(pk);
137
150
  return self;
138
151
  }
139
152
 
140
153
  static VALUE Packer_write_true(VALUE self)
141
154
  {
142
- PACKER(self, pk);
155
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
143
156
  msgpack_packer_write_true(pk);
144
157
  return self;
145
158
  }
146
159
 
147
160
  static VALUE Packer_write_false(VALUE self)
148
161
  {
149
- PACKER(self, pk);
162
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
150
163
  msgpack_packer_write_false(pk);
151
164
  return self;
152
165
  }
153
166
 
154
167
  static VALUE Packer_write_float(VALUE self, VALUE obj)
155
168
  {
156
- PACKER(self, pk);
169
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
157
170
  msgpack_packer_write_float_value(pk, obj);
158
171
  return self;
159
172
  }
160
173
 
161
174
  static VALUE Packer_write_string(VALUE self, VALUE obj)
162
175
  {
163
- PACKER(self, pk);
176
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
164
177
  Check_Type(obj, T_STRING);
165
178
  msgpack_packer_write_string_value(pk, obj);
166
179
  return self;
@@ -168,7 +181,7 @@ static VALUE Packer_write_string(VALUE self, VALUE obj)
168
181
 
169
182
  static VALUE Packer_write_bin(VALUE self, VALUE obj)
170
183
  {
171
- PACKER(self, pk);
184
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
172
185
  Check_Type(obj, T_STRING);
173
186
 
174
187
  VALUE enc = rb_enc_from_encoding(rb_ascii8bit_encoding());
@@ -180,7 +193,7 @@ static VALUE Packer_write_bin(VALUE self, VALUE obj)
180
193
 
181
194
  static VALUE Packer_write_array(VALUE self, VALUE obj)
182
195
  {
183
- PACKER(self, pk);
196
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
184
197
  Check_Type(obj, T_ARRAY);
185
198
  msgpack_packer_write_array_value(pk, obj);
186
199
  return self;
@@ -188,7 +201,7 @@ static VALUE Packer_write_array(VALUE self, VALUE obj)
188
201
 
189
202
  static VALUE Packer_write_hash(VALUE self, VALUE obj)
190
203
  {
191
- PACKER(self, pk);
204
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
192
205
  Check_Type(obj, T_HASH);
193
206
  msgpack_packer_write_hash_value(pk, obj);
194
207
  return self;
@@ -196,7 +209,7 @@ static VALUE Packer_write_hash(VALUE self, VALUE obj)
196
209
 
197
210
  static VALUE Packer_write_symbol(VALUE self, VALUE obj)
198
211
  {
199
- PACKER(self, pk);
212
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
200
213
  Check_Type(obj, T_SYMBOL);
201
214
  msgpack_packer_write_symbol_value(pk, obj);
202
215
  return self;
@@ -204,7 +217,7 @@ static VALUE Packer_write_symbol(VALUE self, VALUE obj)
204
217
 
205
218
  static VALUE Packer_write_int(VALUE self, VALUE obj)
206
219
  {
207
- PACKER(self, pk);
220
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
208
221
 
209
222
  if (FIXNUM_P(obj)) {
210
223
  msgpack_packer_write_fixnum_value(pk, obj);
@@ -217,7 +230,7 @@ static VALUE Packer_write_int(VALUE self, VALUE obj)
217
230
 
218
231
  static VALUE Packer_write_extension(VALUE self, VALUE obj)
219
232
  {
220
- PACKER(self, pk);
233
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
221
234
  Check_Type(obj, T_STRUCT);
222
235
 
223
236
  int ext_type = FIX2INT(RSTRUCT_GET(obj, 0));
@@ -233,21 +246,21 @@ static VALUE Packer_write_extension(VALUE self, VALUE obj)
233
246
 
234
247
  static VALUE Packer_write_array_header(VALUE self, VALUE n)
235
248
  {
236
- PACKER(self, pk);
249
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
237
250
  msgpack_packer_write_array_header(pk, NUM2UINT(n));
238
251
  return self;
239
252
  }
240
253
 
241
254
  static VALUE Packer_write_map_header(VALUE self, VALUE n)
242
255
  {
243
- PACKER(self, pk);
256
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
244
257
  msgpack_packer_write_map_header(pk, NUM2UINT(n));
245
258
  return self;
246
259
  }
247
260
 
248
261
  static VALUE Packer_write_bin_header(VALUE self, VALUE n)
249
262
  {
250
- PACKER(self, pk);
263
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
251
264
  msgpack_packer_write_bin_header(pk, NUM2UINT(n));
252
265
  return self;
253
266
  }
@@ -258,14 +271,14 @@ static VALUE Packer_write_float32(VALUE self, VALUE numeric)
258
271
  rb_raise(rb_eArgError, "Expected numeric");
259
272
  }
260
273
 
261
- PACKER(self, pk);
274
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
262
275
  msgpack_packer_write_float(pk, (float)rb_num2dbl(numeric));
263
276
  return self;
264
277
  }
265
278
 
266
279
  static VALUE Packer_write_ext(VALUE self, VALUE type, VALUE data)
267
280
  {
268
- PACKER(self, pk);
281
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
269
282
  int ext_type = NUM2INT(type);
270
283
  if(ext_type < -128 || ext_type > 127) {
271
284
  rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type);
@@ -277,28 +290,28 @@ static VALUE Packer_write_ext(VALUE self, VALUE type, VALUE data)
277
290
 
278
291
  static VALUE Packer_flush(VALUE self)
279
292
  {
280
- PACKER(self, pk);
293
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
281
294
  msgpack_buffer_flush(PACKER_BUFFER_(pk));
282
295
  return self;
283
296
  }
284
297
 
285
298
  static VALUE Packer_reset(VALUE self)
286
299
  {
287
- PACKER(self, pk);
300
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
288
301
  msgpack_buffer_clear(PACKER_BUFFER_(pk));
289
302
  return Qnil;
290
303
  }
291
304
 
292
305
  static VALUE Packer_size(VALUE self)
293
306
  {
294
- PACKER(self, pk);
307
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
295
308
  size_t size = msgpack_buffer_all_readable_size(PACKER_BUFFER_(pk));
296
309
  return SIZET2NUM(size);
297
310
  }
298
311
 
299
312
  static VALUE Packer_empty_p(VALUE self)
300
313
  {
301
- PACKER(self, pk);
314
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
302
315
  if(msgpack_buffer_top_readable_size(PACKER_BUFFER_(pk)) == 0) {
303
316
  return Qtrue;
304
317
  } else {
@@ -308,38 +321,26 @@ static VALUE Packer_empty_p(VALUE self)
308
321
 
309
322
  static VALUE Packer_to_str(VALUE self)
310
323
  {
311
- PACKER(self, pk);
324
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
312
325
  return msgpack_buffer_all_as_string(PACKER_BUFFER_(pk));
313
326
  }
314
327
 
315
328
  static VALUE Packer_to_a(VALUE self)
316
329
  {
317
- PACKER(self, pk);
330
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
318
331
  return msgpack_buffer_all_as_string_array(PACKER_BUFFER_(pk));
319
332
  }
320
333
 
321
334
  static VALUE Packer_write_to(VALUE self, VALUE io)
322
335
  {
323
- PACKER(self, pk);
336
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
324
337
  size_t sz = msgpack_buffer_flush_to_io(PACKER_BUFFER_(pk), io, s_write, true);
325
338
  return SIZET2NUM(sz);
326
339
  }
327
340
 
328
- //static VALUE Packer_append(VALUE self, VALUE string_or_buffer)
329
- //{
330
- // PACKER(self, pk);
331
- //
332
- // // TODO if string_or_buffer is a Buffer
333
- // VALUE string = string_or_buffer;
334
- //
335
- // msgpack_buffer_append_string(PACKER_BUFFER_(pk), string);
336
- //
337
- // return self;
338
- //}
339
-
340
341
  static VALUE Packer_registered_types_internal(VALUE self)
341
342
  {
342
- PACKER(self, pk);
343
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
343
344
  if (RTEST(pk->ext_registry.hash)) {
344
345
  return rb_hash_dup(pk->ext_registry.hash);
345
346
  }
@@ -348,7 +349,7 @@ static VALUE Packer_registered_types_internal(VALUE self)
348
349
 
349
350
  static VALUE Packer_register_type(int argc, VALUE* argv, VALUE self)
350
351
  {
351
- PACKER(self, pk);
352
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
352
353
 
353
354
  int ext_type;
354
355
  VALUE ext_module;
@@ -394,7 +395,7 @@ VALUE Packer_full_pack(VALUE self)
394
395
  {
395
396
  VALUE retval;
396
397
 
397
- PACKER(self, pk);
398
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
398
399
 
399
400
  if(msgpack_buffer_has_io(PACKER_BUFFER_(pk))) {
400
401
  msgpack_buffer_flush(PACKER_BUFFER_(pk));
@@ -454,15 +455,9 @@ void MessagePack_Packer_module_init(VALUE mMessagePack)
454
455
  rb_define_method(cMessagePack_Packer, "to_str", Packer_to_str, 0);
455
456
  rb_define_alias(cMessagePack_Packer, "to_s", "to_str");
456
457
  rb_define_method(cMessagePack_Packer, "to_a", Packer_to_a, 0);
457
- //rb_define_method(cMessagePack_Packer, "append", Packer_append, 1);
458
- //rb_define_alias(cMessagePack_Packer, "<<", "append");
459
458
 
460
459
  rb_define_private_method(cMessagePack_Packer, "registered_types_internal", Packer_registered_types_internal, 0);
461
460
  rb_define_method(cMessagePack_Packer, "register_type", Packer_register_type, -1);
462
461
 
463
- //s_packer_value = MessagePack_Packer_alloc(cMessagePack_Packer);
464
- //rb_gc_register_address(&s_packer_value);
465
- //Data_Get_Struct(s_packer_value, msgpack_packer_t, s_packer);
466
-
467
462
  rb_define_method(cMessagePack_Packer, "full_pack", Packer_full_pack, 0);
468
463
  }
@@ -22,6 +22,17 @@
22
22
 
23
23
  extern VALUE cMessagePack_Packer;
24
24
 
25
+ extern const rb_data_type_t packer_data_type;
26
+
27
+ static inline msgpack_packer_t *MessagePack_Packer_get(VALUE object) {
28
+ msgpack_packer_t *packer;
29
+ TypedData_Get_Struct(object, msgpack_packer_t, &packer_data_type, packer);
30
+ if (!packer) {
31
+ rb_raise(rb_eArgError, "Uninitialized Packer object");
32
+ }
33
+ return packer;
34
+ }
35
+
25
36
  void MessagePack_Packer_module_init(VALUE mMessagePack);
26
37
 
27
38
  VALUE MessagePack_Packer_alloc(VALUE klass);
@@ -20,12 +20,12 @@
20
20
 
21
21
  static ID s_call;
22
22
 
23
- void msgpack_packer_ext_registry_static_init()
23
+ void msgpack_packer_ext_registry_static_init(void)
24
24
  {
25
25
  s_call = rb_intern("call");
26
26
  }
27
27
 
28
- void msgpack_packer_ext_registry_static_destroy()
28
+ void msgpack_packer_ext_registry_static_destroy(void)
29
29
  { }
30
30
 
31
31
  void msgpack_packer_ext_registry_init(msgpack_packer_ext_registry_t* pkrg)
@@ -31,9 +31,9 @@ struct msgpack_packer_ext_registry_t {
31
31
  VALUE cache; // lookup cache for ext types inherited from a super class
32
32
  };
33
33
 
34
- void msgpack_packer_ext_registry_static_init();
34
+ void msgpack_packer_ext_registry_static_init(void);
35
35
 
36
- void msgpack_packer_ext_registry_static_destroy();
36
+ void msgpack_packer_ext_registry_static_destroy(void);
37
37
 
38
38
  void msgpack_packer_ext_registry_init(msgpack_packer_ext_registry_t* pkrg);
39
39
 
data/ext/msgpack/rbinit.c CHANGED
@@ -22,7 +22,7 @@
22
22
  #include "factory_class.h"
23
23
  #include "extension_value_class.h"
24
24
 
25
- void Init_msgpack(void)
25
+ RUBY_FUNC_EXPORTED void Init_msgpack(void)
26
26
  {
27
27
  VALUE mMessagePack = rb_define_module("MessagePack");
28
28
 
data/ext/msgpack/sysdep.h CHANGED
@@ -35,8 +35,11 @@
35
35
  # define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x))
36
36
  # else
37
37
  # define _msgpack_be16(x) ( \
38
- ((((uint16_t)x) << 8) ) | \
39
- ((((uint16_t)x) >> 8) ) )
38
+ ( \
39
+ ((((uint16_t)x) << 8) ) | \
40
+ ((((uint16_t)x) >> 8) ) \
41
+ ) \
42
+ & 0x0000FFFF )
40
43
  # endif
41
44
  #else
42
45
  # define _msgpack_be16(x) ntohs(x)
@@ -20,7 +20,7 @@
20
20
  #include "rmem.h"
21
21
  #include "extension_value_class.h"
22
22
 
23
- #if !defined(DISABLE_RMEM) && !defined(DISABLE_UNPACKER_STACK_RMEM) && \
23
+ #if !defined(DISABLE_UNPACKER_STACK_RMEM) && \
24
24
  MSGPACK_UNPACKER_STACK_CAPACITY * MSGPACK_UNPACKER_STACK_SIZE <= MSGPACK_RMEM_PAGE_SIZE
25
25
  #define UNPACKER_STACK_RMEM
26
26
  #endif
@@ -41,7 +41,7 @@ static inline VALUE rb_hash_new_capa(long capa)
41
41
  }
42
42
  #endif
43
43
 
44
- void msgpack_unpacker_static_init()
44
+ void msgpack_unpacker_static_init(void)
45
45
  {
46
46
  #ifdef UNPACKER_STACK_RMEM
47
47
  msgpack_rmem_init(&s_stack_rmem);
@@ -50,7 +50,7 @@ void msgpack_unpacker_static_init()
50
50
  s_call = rb_intern("call");
51
51
  }
52
52
 
53
- void msgpack_unpacker_static_destroy()
53
+ void msgpack_unpacker_static_destroy(void)
54
54
  {
55
55
  #ifdef UNPACKER_STACK_RMEM
56
56
  msgpack_rmem_destroy(&s_stack_rmem);
@@ -72,10 +72,8 @@ static inline msgpack_unpacker_stack_t* _msgpack_unpacker_new_stack(void) {
72
72
  return stack;
73
73
  }
74
74
 
75
- msgpack_unpacker_t* _msgpack_unpacker_new(void)
75
+ void _msgpack_unpacker_init(msgpack_unpacker_t* uk)
76
76
  {
77
- msgpack_unpacker_t* uk = ZALLOC_N(msgpack_unpacker_t, 1);
78
-
79
77
  msgpack_buffer_init(UNPACKER_BUFFER_(uk));
80
78
 
81
79
  uk->head_byte = HEAD_BYTE_REQUIRED;
@@ -84,8 +82,6 @@ msgpack_unpacker_t* _msgpack_unpacker_new(void)
84
82
  uk->reading_raw = Qnil;
85
83
 
86
84
  uk->stack = _msgpack_unpacker_new_stack();
87
-
88
- return uk;
89
85
  }
90
86
 
91
87
  static inline void _msgpack_unpacker_free_stack(msgpack_unpacker_stack_t* stack) {
@@ -124,6 +120,7 @@ void msgpack_unpacker_mark(msgpack_unpacker_t* uk)
124
120
  /* See MessagePack_Buffer_wrap */
125
121
  /* msgpack_buffer_mark(UNPACKER_BUFFER_(uk)); */
126
122
  rb_gc_mark(uk->buffer_ref);
123
+ rb_gc_mark(uk->self);
127
124
  }
128
125
 
129
126
  void _msgpack_unpacker_reset(msgpack_unpacker_t* uk)
@@ -326,7 +323,7 @@ static inline int read_raw_body_begin(msgpack_unpacker_t* uk, int raw_type)
326
323
  child_stack->parent = uk->stack;
327
324
  uk->stack = child_stack;
328
325
 
329
- obj = rb_funcall(proc, s_call, 1, uk->buffer.owner);
326
+ obj = rb_funcall(proc, s_call, 1, uk->self);
330
327
 
331
328
  uk->stack = child_stack->parent;
332
329
  _msgpack_unpacker_free_stack(child_stack);
@@ -56,6 +56,7 @@ struct msgpack_unpacker_t {
56
56
  msgpack_unpacker_stack_t *stack;
57
57
  unsigned int head_byte;
58
58
 
59
+ VALUE self;
59
60
  VALUE last_object;
60
61
 
61
62
  VALUE reading_raw;
@@ -86,11 +87,11 @@ enum msgpack_unpacker_object_type {
86
87
  TYPE_MAP,
87
88
  };
88
89
 
89
- void msgpack_unpacker_static_init();
90
+ void msgpack_unpacker_static_init(void);
90
91
 
91
- void msgpack_unpacker_static_destroy();
92
+ void msgpack_unpacker_static_destroy(void);
92
93
 
93
- msgpack_unpacker_t* _msgpack_unpacker_new(void);
94
+ void _msgpack_unpacker_init(msgpack_unpacker_t*);
94
95
 
95
96
  void _msgpack_unpacker_destroy(msgpack_unpacker_t* uk);
96
97