msgpack 1.5.6 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
 
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,36 @@ 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;
55
50
  msgpack_packer_mark(pk);
56
51
  msgpack_packer_ext_registry_mark(&pk->ext_registry);
57
52
  }
58
53
 
59
- VALUE MessagePack_Packer_alloc(VALUE klass)
54
+ static size_t Packer_memsize(const void *ptr)
60
55
  {
61
- msgpack_packer_t* pk = ZALLOC_N(msgpack_packer_t, 1);
62
- msgpack_packer_init(pk);
56
+ const msgpack_packer_t* pk = ptr;
57
+ return sizeof(msgpack_packer_t) + msgpack_buffer_memsize(&pk->buffer);
58
+ }
63
59
 
64
- VALUE self = Data_Wrap_Struct(klass, Packer_mark, Packer_free, pk);
60
+ const rb_data_type_t packer_data_type = {
61
+ .wrap_struct_name = "msgpack:packer",
62
+ .function = {
63
+ .dmark = Packer_mark,
64
+ .dfree = Packer_free,
65
+ .dsize = Packer_memsize,
66
+ },
67
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
68
+ };
65
69
 
66
- msgpack_packer_set_to_msgpack_method(pk, s_to_msgpack, self);
67
70
 
71
+ VALUE MessagePack_Packer_alloc(VALUE klass)
72
+ {
73
+ msgpack_packer_t* pk;
74
+ VALUE self = TypedData_Make_Struct(klass, msgpack_packer_t, &packer_data_type, pk);
75
+ msgpack_packer_init(pk);
76
+ msgpack_packer_set_to_msgpack_method(pk, s_to_msgpack, self);
68
77
  return self;
69
78
  }
70
79
 
@@ -94,7 +103,7 @@ VALUE MessagePack_Packer_initialize(int argc, VALUE* argv, VALUE self)
94
103
  Check_Type(options, T_HASH);
95
104
  }
96
105
 
97
- PACKER(self, pk);
106
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
98
107
 
99
108
  msgpack_packer_ext_registry_init(&pk->ext_registry);
100
109
  pk->buffer_ref = MessagePack_Buffer_wrap(PACKER_BUFFER_(pk), self);
@@ -113,54 +122,54 @@ VALUE MessagePack_Packer_initialize(int argc, VALUE* argv, VALUE self)
113
122
 
114
123
  static VALUE Packer_compatibility_mode_p(VALUE self)
115
124
  {
116
- PACKER(self, pk);
125
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
117
126
  return pk->compatibility_mode ? Qtrue : Qfalse;
118
127
  }
119
128
 
120
129
  static VALUE Packer_buffer(VALUE self)
121
130
  {
122
- PACKER(self, pk);
131
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
123
132
  return pk->buffer_ref;
124
133
  }
125
134
 
126
135
  static VALUE Packer_write(VALUE self, VALUE v)
127
136
  {
128
- PACKER(self, pk);
137
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
129
138
  msgpack_packer_write_value(pk, v);
130
139
  return self;
131
140
  }
132
141
 
133
142
  static VALUE Packer_write_nil(VALUE self)
134
143
  {
135
- PACKER(self, pk);
144
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
136
145
  msgpack_packer_write_nil(pk);
137
146
  return self;
138
147
  }
139
148
 
140
149
  static VALUE Packer_write_true(VALUE self)
141
150
  {
142
- PACKER(self, pk);
151
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
143
152
  msgpack_packer_write_true(pk);
144
153
  return self;
145
154
  }
146
155
 
147
156
  static VALUE Packer_write_false(VALUE self)
148
157
  {
149
- PACKER(self, pk);
158
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
150
159
  msgpack_packer_write_false(pk);
151
160
  return self;
152
161
  }
153
162
 
154
163
  static VALUE Packer_write_float(VALUE self, VALUE obj)
155
164
  {
156
- PACKER(self, pk);
165
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
157
166
  msgpack_packer_write_float_value(pk, obj);
158
167
  return self;
159
168
  }
160
169
 
161
170
  static VALUE Packer_write_string(VALUE self, VALUE obj)
162
171
  {
163
- PACKER(self, pk);
172
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
164
173
  Check_Type(obj, T_STRING);
165
174
  msgpack_packer_write_string_value(pk, obj);
166
175
  return self;
@@ -168,7 +177,7 @@ static VALUE Packer_write_string(VALUE self, VALUE obj)
168
177
 
169
178
  static VALUE Packer_write_bin(VALUE self, VALUE obj)
170
179
  {
171
- PACKER(self, pk);
180
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
172
181
  Check_Type(obj, T_STRING);
173
182
 
174
183
  VALUE enc = rb_enc_from_encoding(rb_ascii8bit_encoding());
@@ -180,7 +189,7 @@ static VALUE Packer_write_bin(VALUE self, VALUE obj)
180
189
 
181
190
  static VALUE Packer_write_array(VALUE self, VALUE obj)
182
191
  {
183
- PACKER(self, pk);
192
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
184
193
  Check_Type(obj, T_ARRAY);
185
194
  msgpack_packer_write_array_value(pk, obj);
186
195
  return self;
@@ -188,7 +197,7 @@ static VALUE Packer_write_array(VALUE self, VALUE obj)
188
197
 
189
198
  static VALUE Packer_write_hash(VALUE self, VALUE obj)
190
199
  {
191
- PACKER(self, pk);
200
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
192
201
  Check_Type(obj, T_HASH);
193
202
  msgpack_packer_write_hash_value(pk, obj);
194
203
  return self;
@@ -196,7 +205,7 @@ static VALUE Packer_write_hash(VALUE self, VALUE obj)
196
205
 
197
206
  static VALUE Packer_write_symbol(VALUE self, VALUE obj)
198
207
  {
199
- PACKER(self, pk);
208
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
200
209
  Check_Type(obj, T_SYMBOL);
201
210
  msgpack_packer_write_symbol_value(pk, obj);
202
211
  return self;
@@ -204,7 +213,7 @@ static VALUE Packer_write_symbol(VALUE self, VALUE obj)
204
213
 
205
214
  static VALUE Packer_write_int(VALUE self, VALUE obj)
206
215
  {
207
- PACKER(self, pk);
216
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
208
217
 
209
218
  if (FIXNUM_P(obj)) {
210
219
  msgpack_packer_write_fixnum_value(pk, obj);
@@ -217,7 +226,7 @@ static VALUE Packer_write_int(VALUE self, VALUE obj)
217
226
 
218
227
  static VALUE Packer_write_extension(VALUE self, VALUE obj)
219
228
  {
220
- PACKER(self, pk);
229
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
221
230
  Check_Type(obj, T_STRUCT);
222
231
 
223
232
  int ext_type = FIX2INT(RSTRUCT_GET(obj, 0));
@@ -233,21 +242,21 @@ static VALUE Packer_write_extension(VALUE self, VALUE obj)
233
242
 
234
243
  static VALUE Packer_write_array_header(VALUE self, VALUE n)
235
244
  {
236
- PACKER(self, pk);
245
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
237
246
  msgpack_packer_write_array_header(pk, NUM2UINT(n));
238
247
  return self;
239
248
  }
240
249
 
241
250
  static VALUE Packer_write_map_header(VALUE self, VALUE n)
242
251
  {
243
- PACKER(self, pk);
252
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
244
253
  msgpack_packer_write_map_header(pk, NUM2UINT(n));
245
254
  return self;
246
255
  }
247
256
 
248
257
  static VALUE Packer_write_bin_header(VALUE self, VALUE n)
249
258
  {
250
- PACKER(self, pk);
259
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
251
260
  msgpack_packer_write_bin_header(pk, NUM2UINT(n));
252
261
  return self;
253
262
  }
@@ -258,14 +267,14 @@ static VALUE Packer_write_float32(VALUE self, VALUE numeric)
258
267
  rb_raise(rb_eArgError, "Expected numeric");
259
268
  }
260
269
 
261
- PACKER(self, pk);
270
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
262
271
  msgpack_packer_write_float(pk, (float)rb_num2dbl(numeric));
263
272
  return self;
264
273
  }
265
274
 
266
275
  static VALUE Packer_write_ext(VALUE self, VALUE type, VALUE data)
267
276
  {
268
- PACKER(self, pk);
277
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
269
278
  int ext_type = NUM2INT(type);
270
279
  if(ext_type < -128 || ext_type > 127) {
271
280
  rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type);
@@ -277,28 +286,28 @@ static VALUE Packer_write_ext(VALUE self, VALUE type, VALUE data)
277
286
 
278
287
  static VALUE Packer_flush(VALUE self)
279
288
  {
280
- PACKER(self, pk);
289
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
281
290
  msgpack_buffer_flush(PACKER_BUFFER_(pk));
282
291
  return self;
283
292
  }
284
293
 
285
294
  static VALUE Packer_reset(VALUE self)
286
295
  {
287
- PACKER(self, pk);
296
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
288
297
  msgpack_buffer_clear(PACKER_BUFFER_(pk));
289
298
  return Qnil;
290
299
  }
291
300
 
292
301
  static VALUE Packer_size(VALUE self)
293
302
  {
294
- PACKER(self, pk);
303
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
295
304
  size_t size = msgpack_buffer_all_readable_size(PACKER_BUFFER_(pk));
296
305
  return SIZET2NUM(size);
297
306
  }
298
307
 
299
308
  static VALUE Packer_empty_p(VALUE self)
300
309
  {
301
- PACKER(self, pk);
310
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
302
311
  if(msgpack_buffer_top_readable_size(PACKER_BUFFER_(pk)) == 0) {
303
312
  return Qtrue;
304
313
  } else {
@@ -308,26 +317,26 @@ static VALUE Packer_empty_p(VALUE self)
308
317
 
309
318
  static VALUE Packer_to_str(VALUE self)
310
319
  {
311
- PACKER(self, pk);
320
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
312
321
  return msgpack_buffer_all_as_string(PACKER_BUFFER_(pk));
313
322
  }
314
323
 
315
324
  static VALUE Packer_to_a(VALUE self)
316
325
  {
317
- PACKER(self, pk);
326
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
318
327
  return msgpack_buffer_all_as_string_array(PACKER_BUFFER_(pk));
319
328
  }
320
329
 
321
330
  static VALUE Packer_write_to(VALUE self, VALUE io)
322
331
  {
323
- PACKER(self, pk);
332
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
324
333
  size_t sz = msgpack_buffer_flush_to_io(PACKER_BUFFER_(pk), io, s_write, true);
325
334
  return SIZET2NUM(sz);
326
335
  }
327
336
 
328
337
  //static VALUE Packer_append(VALUE self, VALUE string_or_buffer)
329
338
  //{
330
- // PACKER(self, pk);
339
+ // msgpack_packer_t *pk = MessagePack_Packer_get(self);
331
340
  //
332
341
  // // TODO if string_or_buffer is a Buffer
333
342
  // VALUE string = string_or_buffer;
@@ -339,7 +348,7 @@ static VALUE Packer_write_to(VALUE self, VALUE io)
339
348
 
340
349
  static VALUE Packer_registered_types_internal(VALUE self)
341
350
  {
342
- PACKER(self, pk);
351
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
343
352
  if (RTEST(pk->ext_registry.hash)) {
344
353
  return rb_hash_dup(pk->ext_registry.hash);
345
354
  }
@@ -348,7 +357,7 @@ static VALUE Packer_registered_types_internal(VALUE self)
348
357
 
349
358
  static VALUE Packer_register_type(int argc, VALUE* argv, VALUE self)
350
359
  {
351
- PACKER(self, pk);
360
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
352
361
 
353
362
  int ext_type;
354
363
  VALUE ext_module;
@@ -394,7 +403,7 @@ VALUE Packer_full_pack(VALUE self)
394
403
  {
395
404
  VALUE retval;
396
405
 
397
- PACKER(self, pk);
406
+ msgpack_packer_t *pk = MessagePack_Packer_get(self);
398
407
 
399
408
  if(msgpack_buffer_has_io(PACKER_BUFFER_(pk))) {
400
409
  msgpack_buffer_flush(PACKER_BUFFER_(pk));
@@ -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/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) {
@@ -326,7 +322,7 @@ static inline int read_raw_body_begin(msgpack_unpacker_t* uk, int raw_type)
326
322
  child_stack->parent = uk->stack;
327
323
  uk->stack = child_stack;
328
324
 
329
- obj = rb_funcall(proc, s_call, 1, uk->buffer.owner);
325
+ obj = rb_funcall(proc, s_call, 1, uk->self);
330
326
 
331
327
  uk->stack = child_stack->parent;
332
328
  _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