msgpack 1.5.1 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +55 -0
- data/README.md +30 -1
- data/ext/java/org/msgpack/jruby/Buffer.java +3 -3
- data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +11 -20
- data/ext/java/org/msgpack/jruby/ExtensionValue.java +1 -1
- data/ext/java/org/msgpack/jruby/Factory.java +11 -50
- data/ext/java/org/msgpack/jruby/Packer.java +9 -24
- data/ext/java/org/msgpack/jruby/Unpacker.java +15 -32
- data/ext/msgpack/buffer.c +54 -69
- data/ext/msgpack/buffer.h +16 -18
- data/ext/msgpack/buffer_class.c +138 -37
- data/ext/msgpack/buffer_class.h +1 -0
- data/ext/msgpack/compat.h +0 -99
- data/ext/msgpack/extconf.rb +25 -39
- data/ext/msgpack/factory_class.c +75 -86
- data/ext/msgpack/packer.c +12 -39
- data/ext/msgpack/packer.h +1 -11
- data/ext/msgpack/packer_class.c +73 -99
- data/ext/msgpack/packer_class.h +11 -0
- data/ext/msgpack/packer_ext_registry.c +31 -28
- data/ext/msgpack/packer_ext_registry.h +10 -14
- data/ext/msgpack/rbinit.c +1 -1
- data/ext/msgpack/rmem.c +3 -4
- data/ext/msgpack/sysdep.h +5 -2
- data/ext/msgpack/unpacker.c +66 -94
- data/ext/msgpack/unpacker.h +13 -12
- data/ext/msgpack/unpacker_class.c +64 -80
- data/ext/msgpack/unpacker_class.h +11 -0
- data/ext/msgpack/unpacker_ext_registry.c +4 -16
- data/ext/msgpack/unpacker_ext_registry.h +3 -7
- data/lib/msgpack/buffer.rb +9 -0
- data/lib/msgpack/factory.rb +90 -63
- data/lib/msgpack/packer.rb +10 -1
- data/lib/msgpack/unpacker.rb +14 -1
- data/lib/msgpack/version.rb +1 -1
- data/lib/msgpack.rb +1 -0
- data/msgpack.gemspec +7 -3
- metadata +33 -56
- data/.github/workflows/ci.yaml +0 -57
- data/.gitignore +0 -23
- data/.rubocop.yml +0 -36
- data/Gemfile +0 -9
- data/Rakefile +0 -70
- data/appveyor.yml +0 -18
- data/bench/pack.rb +0 -23
- data/bench/pack_log.rb +0 -33
- data/bench/pack_log_long.rb +0 -65
- data/bench/pack_symbols.rb +0 -28
- data/bench/run.sh +0 -14
- data/bench/run_long.sh +0 -35
- data/bench/run_symbols.sh +0 -26
- data/bench/unpack.rb +0 -21
- data/bench/unpack_log.rb +0 -34
- data/bench/unpack_log_long.rb +0 -67
- data/doclib/msgpack/buffer.rb +0 -193
- data/doclib/msgpack/core_ext.rb +0 -101
- data/doclib/msgpack/error.rb +0 -19
- data/doclib/msgpack/extension_value.rb +0 -9
- data/doclib/msgpack/factory.rb +0 -145
- data/doclib/msgpack/packer.rb +0 -209
- data/doclib/msgpack/time.rb +0 -22
- data/doclib/msgpack/timestamp.rb +0 -44
- data/doclib/msgpack/unpacker.rb +0 -183
- data/doclib/msgpack.rb +0 -87
- data/msgpack.org.md +0 -46
- data/spec/bigint_spec.rb +0 -26
- data/spec/cases.json +0 -1
- data/spec/cases.msg +0 -0
- data/spec/cases_compact.msg +0 -0
- data/spec/cases_spec.rb +0 -39
- data/spec/cruby/buffer_io_spec.rb +0 -255
- data/spec/cruby/buffer_packer.rb +0 -29
- data/spec/cruby/buffer_spec.rb +0 -575
- data/spec/cruby/buffer_unpacker.rb +0 -19
- data/spec/cruby/unpacker_spec.rb +0 -70
- data/spec/ext_value_spec.rb +0 -99
- data/spec/exttypes.rb +0 -51
- data/spec/factory_spec.rb +0 -654
- data/spec/format_spec.rb +0 -301
- data/spec/jruby/benchmarks/shootout_bm.rb +0 -73
- data/spec/jruby/benchmarks/symbolize_keys_bm.rb +0 -25
- data/spec/jruby/unpacker_spec.rb +0 -186
- data/spec/msgpack_spec.rb +0 -214
- data/spec/pack_spec.rb +0 -61
- data/spec/packer_spec.rb +0 -575
- data/spec/random_compat.rb +0 -24
- data/spec/spec_helper.rb +0 -65
- data/spec/timestamp_spec.rb +0 -159
- data/spec/unpack_spec.rb +0 -57
- data/spec/unpacker_spec.rb +0 -847
data/ext/msgpack/packer_class.c
CHANGED
@@ -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
|
-
|
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(
|
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
|
-
|
55
|
+
static size_t Packer_memsize(const void *ptr)
|
60
56
|
{
|
61
|
-
msgpack_packer_t* pk =
|
62
|
-
|
57
|
+
const msgpack_packer_t* pk = ptr;
|
58
|
+
return sizeof(msgpack_packer_t) + msgpack_buffer_memsize(&pk->buffer);
|
59
|
+
}
|
63
60
|
|
64
|
-
|
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,9 +104,9 @@ VALUE MessagePack_Packer_initialize(int argc, VALUE* argv, VALUE self)
|
|
94
104
|
Check_Type(options, T_HASH);
|
95
105
|
}
|
96
106
|
|
97
|
-
|
107
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
98
108
|
|
99
|
-
msgpack_packer_ext_registry_init(&pk->ext_registry);
|
109
|
+
msgpack_packer_ext_registry_init(self, &pk->ext_registry);
|
100
110
|
pk->buffer_ref = MessagePack_Buffer_wrap(PACKER_BUFFER_(pk), self);
|
101
111
|
|
102
112
|
MessagePack_Buffer_set_options(PACKER_BUFFER_(pk), io, options);
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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,10 +230,15 @@ 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
|
-
|
233
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
221
234
|
Check_Type(obj, T_STRUCT);
|
222
235
|
|
223
|
-
|
236
|
+
VALUE rb_ext_type = RSTRUCT_GET(obj, 0);
|
237
|
+
if(!RB_TYPE_P(rb_ext_type, T_FIXNUM)) {
|
238
|
+
rb_raise(rb_eRangeError, "integer %s too big to convert to `signed char'", RSTRING_PTR(rb_String(rb_ext_type)));
|
239
|
+
}
|
240
|
+
|
241
|
+
int ext_type = FIX2INT(rb_ext_type);
|
224
242
|
if(ext_type < -128 || ext_type > 127) {
|
225
243
|
rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type);
|
226
244
|
}
|
@@ -233,21 +251,21 @@ static VALUE Packer_write_extension(VALUE self, VALUE obj)
|
|
233
251
|
|
234
252
|
static VALUE Packer_write_array_header(VALUE self, VALUE n)
|
235
253
|
{
|
236
|
-
|
254
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
237
255
|
msgpack_packer_write_array_header(pk, NUM2UINT(n));
|
238
256
|
return self;
|
239
257
|
}
|
240
258
|
|
241
259
|
static VALUE Packer_write_map_header(VALUE self, VALUE n)
|
242
260
|
{
|
243
|
-
|
261
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
244
262
|
msgpack_packer_write_map_header(pk, NUM2UINT(n));
|
245
263
|
return self;
|
246
264
|
}
|
247
265
|
|
248
266
|
static VALUE Packer_write_bin_header(VALUE self, VALUE n)
|
249
267
|
{
|
250
|
-
|
268
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
251
269
|
msgpack_packer_write_bin_header(pk, NUM2UINT(n));
|
252
270
|
return self;
|
253
271
|
}
|
@@ -258,14 +276,14 @@ static VALUE Packer_write_float32(VALUE self, VALUE numeric)
|
|
258
276
|
rb_raise(rb_eArgError, "Expected numeric");
|
259
277
|
}
|
260
278
|
|
261
|
-
|
279
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
262
280
|
msgpack_packer_write_float(pk, (float)rb_num2dbl(numeric));
|
263
281
|
return self;
|
264
282
|
}
|
265
283
|
|
266
284
|
static VALUE Packer_write_ext(VALUE self, VALUE type, VALUE data)
|
267
285
|
{
|
268
|
-
|
286
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
269
287
|
int ext_type = NUM2INT(type);
|
270
288
|
if(ext_type < -128 || ext_type > 127) {
|
271
289
|
rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type);
|
@@ -277,28 +295,28 @@ static VALUE Packer_write_ext(VALUE self, VALUE type, VALUE data)
|
|
277
295
|
|
278
296
|
static VALUE Packer_flush(VALUE self)
|
279
297
|
{
|
280
|
-
|
298
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
281
299
|
msgpack_buffer_flush(PACKER_BUFFER_(pk));
|
282
300
|
return self;
|
283
301
|
}
|
284
302
|
|
285
303
|
static VALUE Packer_reset(VALUE self)
|
286
304
|
{
|
287
|
-
|
305
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
288
306
|
msgpack_buffer_clear(PACKER_BUFFER_(pk));
|
289
307
|
return Qnil;
|
290
308
|
}
|
291
309
|
|
292
310
|
static VALUE Packer_size(VALUE self)
|
293
311
|
{
|
294
|
-
|
312
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
295
313
|
size_t size = msgpack_buffer_all_readable_size(PACKER_BUFFER_(pk));
|
296
314
|
return SIZET2NUM(size);
|
297
315
|
}
|
298
316
|
|
299
317
|
static VALUE Packer_empty_p(VALUE self)
|
300
318
|
{
|
301
|
-
|
319
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
302
320
|
if(msgpack_buffer_top_readable_size(PACKER_BUFFER_(pk)) == 0) {
|
303
321
|
return Qtrue;
|
304
322
|
} else {
|
@@ -308,80 +326,46 @@ static VALUE Packer_empty_p(VALUE self)
|
|
308
326
|
|
309
327
|
static VALUE Packer_to_str(VALUE self)
|
310
328
|
{
|
311
|
-
|
329
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
312
330
|
return msgpack_buffer_all_as_string(PACKER_BUFFER_(pk));
|
313
331
|
}
|
314
332
|
|
315
333
|
static VALUE Packer_to_a(VALUE self)
|
316
334
|
{
|
317
|
-
|
335
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
318
336
|
return msgpack_buffer_all_as_string_array(PACKER_BUFFER_(pk));
|
319
337
|
}
|
320
338
|
|
321
339
|
static VALUE Packer_write_to(VALUE self, VALUE io)
|
322
340
|
{
|
323
|
-
|
341
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
324
342
|
size_t sz = msgpack_buffer_flush_to_io(PACKER_BUFFER_(pk), io, s_write, true);
|
325
|
-
return
|
343
|
+
return SIZET2NUM(sz);
|
326
344
|
}
|
327
345
|
|
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
346
|
static VALUE Packer_registered_types_internal(VALUE self)
|
341
347
|
{
|
342
|
-
|
348
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
343
349
|
if (RTEST(pk->ext_registry.hash)) {
|
344
350
|
return rb_hash_dup(pk->ext_registry.hash);
|
345
351
|
}
|
346
352
|
return rb_hash_new();
|
347
353
|
}
|
348
354
|
|
349
|
-
static VALUE
|
350
|
-
{
|
351
|
-
|
352
|
-
|
353
|
-
int ext_type;
|
354
|
-
VALUE ext_module;
|
355
|
-
VALUE proc;
|
356
|
-
VALUE arg;
|
357
|
-
|
358
|
-
switch (argc) {
|
359
|
-
case 2:
|
360
|
-
/* register_type(0x7f, Time) {|obj| block... } */
|
361
|
-
rb_need_block();
|
362
|
-
proc = rb_block_lambda();
|
363
|
-
arg = proc;
|
364
|
-
break;
|
365
|
-
case 3:
|
366
|
-
/* register_type(0x7f, Time, :to_msgpack_ext) */
|
367
|
-
arg = argv[2];
|
368
|
-
proc = rb_funcall(arg, rb_intern("to_proc"), 0);
|
369
|
-
break;
|
370
|
-
default:
|
371
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..3)", argc);
|
355
|
+
static VALUE Packer_register_type_internal(VALUE self, VALUE rb_ext_type, VALUE ext_module, VALUE proc)
|
356
|
+
{
|
357
|
+
if (OBJ_FROZEN(self)) {
|
358
|
+
rb_raise(rb_eFrozenError, "can't modify frozen MessagePack::Packer");
|
372
359
|
}
|
373
360
|
|
374
|
-
|
361
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
362
|
+
|
363
|
+
int ext_type = NUM2INT(rb_ext_type);
|
375
364
|
if(ext_type < -128 || ext_type > 127) {
|
376
365
|
rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type);
|
377
366
|
}
|
378
367
|
|
379
|
-
ext_module
|
380
|
-
if(rb_type(ext_module) != T_MODULE && rb_type(ext_module) != T_CLASS) {
|
381
|
-
rb_raise(rb_eArgError, "expected Module/Class but found %s.", rb_obj_classname(ext_module));
|
382
|
-
}
|
383
|
-
|
384
|
-
msgpack_packer_ext_registry_put(&pk->ext_registry, ext_module, ext_type, 0, proc, arg);
|
368
|
+
msgpack_packer_ext_registry_put(self, &pk->ext_registry, ext_module, ext_type, 0, proc);
|
385
369
|
|
386
370
|
if (ext_module == rb_cSymbol) {
|
387
371
|
pk->has_symbol_ext_type = true;
|
@@ -394,7 +378,7 @@ VALUE Packer_full_pack(VALUE self)
|
|
394
378
|
{
|
395
379
|
VALUE retval;
|
396
380
|
|
397
|
-
|
381
|
+
msgpack_packer_t *pk = MessagePack_Packer_get(self);
|
398
382
|
|
399
383
|
if(msgpack_buffer_has_io(PACKER_BUFFER_(pk))) {
|
400
384
|
msgpack_buffer_flush(PACKER_BUFFER_(pk));
|
@@ -414,10 +398,6 @@ void MessagePack_Packer_module_init(VALUE mMessagePack)
|
|
414
398
|
s_write = rb_intern("write");
|
415
399
|
|
416
400
|
sym_compatibility_mode = ID2SYM(rb_intern("compatibility_mode"));
|
417
|
-
|
418
|
-
msgpack_packer_static_init();
|
419
|
-
msgpack_packer_ext_registry_static_init();
|
420
|
-
|
421
401
|
cMessagePack_Packer = rb_define_class_under(mMessagePack, "Packer", rb_cObject);
|
422
402
|
|
423
403
|
rb_define_alloc_func(cMessagePack_Packer, MessagePack_Packer_alloc);
|
@@ -454,15 +434,9 @@ void MessagePack_Packer_module_init(VALUE mMessagePack)
|
|
454
434
|
rb_define_method(cMessagePack_Packer, "to_str", Packer_to_str, 0);
|
455
435
|
rb_define_alias(cMessagePack_Packer, "to_s", "to_str");
|
456
436
|
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
437
|
|
460
438
|
rb_define_private_method(cMessagePack_Packer, "registered_types_internal", Packer_registered_types_internal, 0);
|
461
|
-
rb_define_method(cMessagePack_Packer, "
|
462
|
-
|
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);
|
439
|
+
rb_define_method(cMessagePack_Packer, "register_type_internal", Packer_register_type_internal, 3);
|
466
440
|
|
467
441
|
rb_define_method(cMessagePack_Packer, "full_pack", Packer_full_pack, 0);
|
468
442
|
}
|
data/ext/msgpack/packer_class.h
CHANGED
@@ -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);
|
@@ -18,20 +18,10 @@
|
|
18
18
|
|
19
19
|
#include "packer_ext_registry.h"
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
void msgpack_packer_ext_registry_static_init()
|
24
|
-
{
|
25
|
-
s_call = rb_intern("call");
|
26
|
-
}
|
27
|
-
|
28
|
-
void msgpack_packer_ext_registry_static_destroy()
|
29
|
-
{ }
|
30
|
-
|
31
|
-
void msgpack_packer_ext_registry_init(msgpack_packer_ext_registry_t* pkrg)
|
21
|
+
void msgpack_packer_ext_registry_init(VALUE owner, msgpack_packer_ext_registry_t* pkrg)
|
32
22
|
{
|
33
|
-
pkrg->hash
|
34
|
-
pkrg->cache
|
23
|
+
RB_OBJ_WRITE(owner, &pkrg->hash, Qnil);
|
24
|
+
RB_OBJ_WRITE(owner, &pkrg->cache, Qnil);
|
35
25
|
}
|
36
26
|
|
37
27
|
void msgpack_packer_ext_registry_mark(msgpack_packer_ext_registry_t* pkrg)
|
@@ -40,32 +30,45 @@ void msgpack_packer_ext_registry_mark(msgpack_packer_ext_registry_t* pkrg)
|
|
40
30
|
rb_gc_mark(pkrg->cache);
|
41
31
|
}
|
42
32
|
|
43
|
-
void
|
33
|
+
void msgpack_packer_ext_registry_borrow(VALUE owner, msgpack_packer_ext_registry_t* src,
|
44
34
|
msgpack_packer_ext_registry_t* dst)
|
45
35
|
{
|
46
|
-
if(RTEST(src->hash)
|
47
|
-
|
48
|
-
|
36
|
+
if(RTEST(src->hash)) {
|
37
|
+
if(rb_obj_frozen_p(src->hash)) {
|
38
|
+
// If the type registry is frozen we can safely share it, and share the cache as well.
|
39
|
+
RB_OBJ_WRITE(owner, &dst->hash, src->hash);
|
40
|
+
RB_OBJ_WRITE(owner, &dst->cache, src->cache);
|
41
|
+
} else {
|
42
|
+
RB_OBJ_WRITE(owner, &dst->hash, rb_hash_dup(src->hash));
|
43
|
+
RB_OBJ_WRITE(owner, &dst->cache, NIL_P(src->cache) ? Qnil : rb_hash_dup(src->cache));
|
44
|
+
}
|
49
45
|
} else {
|
50
|
-
|
51
|
-
dst->
|
52
|
-
dst->cache = src->cache;
|
46
|
+
RB_OBJ_WRITE(owner, &dst->hash, Qnil);
|
47
|
+
RB_OBJ_WRITE(owner, &dst->cache, Qnil);
|
53
48
|
}
|
54
49
|
}
|
55
50
|
|
56
|
-
VALUE
|
57
|
-
|
51
|
+
void msgpack_packer_ext_registry_dup(VALUE owner, msgpack_packer_ext_registry_t* src,
|
52
|
+
msgpack_packer_ext_registry_t* dst)
|
58
53
|
{
|
59
|
-
|
60
|
-
|
54
|
+
RB_OBJ_WRITE(owner, &dst->hash, NIL_P(src->hash) ? Qnil : rb_hash_dup(src->hash));
|
55
|
+
RB_OBJ_WRITE(owner, &dst->cache, NIL_P(src->cache) ? Qnil : rb_hash_dup(src->cache));
|
56
|
+
}
|
57
|
+
|
58
|
+
void msgpack_packer_ext_registry_put(VALUE owner, msgpack_packer_ext_registry_t* pkrg,
|
59
|
+
VALUE ext_module, int ext_type, int flags, VALUE proc)
|
60
|
+
{
|
61
|
+
if(NIL_P(pkrg->hash)) {
|
62
|
+
RB_OBJ_WRITE(owner, &pkrg->hash, rb_hash_new());
|
61
63
|
}
|
62
64
|
|
63
|
-
if
|
65
|
+
if(NIL_P(pkrg->cache)) {
|
66
|
+
RB_OBJ_WRITE(owner, &pkrg->cache, rb_hash_new());
|
67
|
+
} else {
|
64
68
|
/* clear lookup cache not to miss added type */
|
65
69
|
rb_hash_clear(pkrg->cache);
|
66
70
|
}
|
67
71
|
|
68
|
-
|
69
|
-
|
70
|
-
return rb_hash_aset(pkrg->hash, ext_module, entry);
|
72
|
+
VALUE entry = rb_ary_new3(3, INT2FIX(ext_type), proc, INT2FIX(flags));
|
73
|
+
rb_hash_aset(pkrg->hash, ext_module, entry);
|
71
74
|
}
|
@@ -31,22 +31,21 @@ 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
|
35
|
-
|
36
|
-
void msgpack_packer_ext_registry_static_destroy();
|
37
|
-
|
38
|
-
void msgpack_packer_ext_registry_init(msgpack_packer_ext_registry_t* pkrg);
|
34
|
+
void msgpack_packer_ext_registry_init(VALUE owner, msgpack_packer_ext_registry_t* pkrg);
|
39
35
|
|
40
36
|
static inline void msgpack_packer_ext_registry_destroy(msgpack_packer_ext_registry_t* pkrg)
|
41
37
|
{ }
|
42
38
|
|
43
39
|
void msgpack_packer_ext_registry_mark(msgpack_packer_ext_registry_t* pkrg);
|
44
40
|
|
45
|
-
void
|
41
|
+
void msgpack_packer_ext_registry_borrow(VALUE owner, msgpack_packer_ext_registry_t* src,
|
46
42
|
msgpack_packer_ext_registry_t* dst);
|
47
43
|
|
48
|
-
VALUE
|
49
|
-
|
44
|
+
void msgpack_packer_ext_registry_dup(VALUE owner, msgpack_packer_ext_registry_t* src,
|
45
|
+
msgpack_packer_ext_registry_t* dst);
|
46
|
+
|
47
|
+
void msgpack_packer_ext_registry_put(VALUE owner, msgpack_packer_ext_registry_t* pkrg,
|
48
|
+
VALUE ext_module, int ext_type, int flags, VALUE proc);
|
50
49
|
|
51
50
|
static int msgpack_packer_ext_find_superclass(VALUE key, VALUE value, VALUE arg)
|
52
51
|
{
|
@@ -68,7 +67,7 @@ static inline VALUE msgpack_packer_ext_registry_fetch(msgpack_packer_ext_registr
|
|
68
67
|
VALUE type = rb_hash_lookup(pkrg->hash, lookup_class);
|
69
68
|
if(type != Qnil) {
|
70
69
|
*ext_type_result = FIX2INT(rb_ary_entry(type, 0));
|
71
|
-
*ext_flags_result = FIX2INT(rb_ary_entry(type,
|
70
|
+
*ext_flags_result = FIX2INT(rb_ary_entry(type, 2));
|
72
71
|
return rb_ary_entry(type, 1);
|
73
72
|
}
|
74
73
|
|
@@ -77,7 +76,7 @@ static inline VALUE msgpack_packer_ext_registry_fetch(msgpack_packer_ext_registr
|
|
77
76
|
VALUE type_inht = rb_hash_lookup(pkrg->cache, lookup_class);
|
78
77
|
if(type_inht != Qnil) {
|
79
78
|
*ext_type_result = FIX2INT(rb_ary_entry(type_inht, 0));
|
80
|
-
*ext_flags_result = FIX2INT(rb_ary_entry(type_inht,
|
79
|
+
*ext_flags_result = FIX2INT(rb_ary_entry(type_inht, 2));
|
81
80
|
return rb_ary_entry(type_inht, 1);
|
82
81
|
}
|
83
82
|
}
|
@@ -129,12 +128,9 @@ static inline VALUE msgpack_packer_ext_registry_lookup(msgpack_packer_ext_regist
|
|
129
128
|
VALUE superclass = args[1];
|
130
129
|
if(superclass != Qnil) {
|
131
130
|
VALUE superclass_type = rb_hash_lookup(pkrg->hash, superclass);
|
132
|
-
if (!RTEST(pkrg->cache)) {
|
133
|
-
pkrg->cache = rb_hash_new();
|
134
|
-
}
|
135
131
|
rb_hash_aset(pkrg->cache, lookup_class, superclass_type);
|
136
132
|
*ext_type_result = FIX2INT(rb_ary_entry(superclass_type, 0));
|
137
|
-
*ext_flags_result = FIX2INT(rb_ary_entry(superclass_type,
|
133
|
+
*ext_flags_result = FIX2INT(rb_ary_entry(superclass_type, 2));
|
138
134
|
return rb_ary_entry(superclass_type, 1);
|
139
135
|
}
|
140
136
|
|
data/ext/msgpack/rbinit.c
CHANGED
data/ext/msgpack/rmem.c
CHANGED
@@ -65,11 +65,10 @@ void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm)
|
|
65
65
|
/* allocate new chunk */
|
66
66
|
c = pm->array_last++;
|
67
67
|
|
68
|
-
/* move to
|
69
|
-
|
70
|
-
pm->head = *c;
|
71
|
-
*c = tmp;
|
68
|
+
/* move head to array */
|
69
|
+
*c = pm->head;
|
72
70
|
|
71
|
+
pm->head.pages = NULL; /* make sure we don't point to another chunk's pages in case xmalloc triggers GC */
|
73
72
|
pm->head.mask = 0xffffffff & (~1); /* "& (~1)" means first chunk is already allocated */
|
74
73
|
pm->head.pages = xmalloc(MSGPACK_RMEM_PAGE_SIZE * 32);
|
75
74
|
|
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
|
-
(
|
39
|
-
|
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)
|