msgpack 1.5.6 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +50 -0
- data/README.md +48 -12
- 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 +69 -56
- data/ext/msgpack/buffer.h +138 -44
- data/ext/msgpack/buffer_class.c +132 -31
- data/ext/msgpack/buffer_class.h +1 -0
- data/ext/msgpack/extconf.rb +20 -30
- data/ext/msgpack/factory_class.c +75 -86
- data/ext/msgpack/packer.c +13 -16
- data/ext/msgpack/packer.h +24 -21
- data/ext/msgpack/packer_class.c +72 -98
- 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 +201 -113
- data/ext/msgpack/unpacker.h +22 -15
- data/ext/msgpack/unpacker_class.c +87 -92
- 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 +8 -3
- metadata +21 -51
- 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/bench.rb +0 -78
- 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 -688
- 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 -71
- data/spec/timestamp_spec.rb +0 -159
- data/spec/unpack_spec.rb +0 -57
- data/spec/unpacker_spec.rb +0 -859
data/ext/msgpack/unpacker.h
CHANGED
@@ -21,9 +21,7 @@
|
|
21
21
|
#include "buffer.h"
|
22
22
|
#include "unpacker_ext_registry.h"
|
23
23
|
|
24
|
-
#ifndef MSGPACK_UNPACKER_STACK_CAPACITY
|
25
24
|
#define MSGPACK_UNPACKER_STACK_CAPACITY 128
|
26
|
-
#endif
|
27
25
|
|
28
26
|
struct msgpack_unpacker_t;
|
29
27
|
typedef struct msgpack_unpacker_t msgpack_unpacker_t;
|
@@ -33,6 +31,7 @@ enum stack_type_t {
|
|
33
31
|
STACK_TYPE_ARRAY,
|
34
32
|
STACK_TYPE_MAP_KEY,
|
35
33
|
STACK_TYPE_MAP_VALUE,
|
34
|
+
STACK_TYPE_RECURSIVE,
|
36
35
|
};
|
37
36
|
|
38
37
|
typedef struct {
|
@@ -46,32 +45,34 @@ struct msgpack_unpacker_stack_t {
|
|
46
45
|
size_t depth;
|
47
46
|
size_t capacity;
|
48
47
|
msgpack_unpacker_stack_entry_t *data;
|
49
|
-
msgpack_unpacker_stack_t *parent;
|
50
48
|
};
|
51
49
|
|
52
|
-
#define MSGPACK_UNPACKER_STACK_SIZE (8+4+8+8) /* assumes size_t <= 64bit, enum <= 32bit, VALUE <= 64bit */
|
53
|
-
|
54
50
|
struct msgpack_unpacker_t {
|
55
51
|
msgpack_buffer_t buffer;
|
56
|
-
msgpack_unpacker_stack_t
|
57
|
-
|
52
|
+
msgpack_unpacker_stack_t stack;
|
53
|
+
msgpack_key_cache_t key_cache;
|
58
54
|
|
55
|
+
VALUE self;
|
59
56
|
VALUE last_object;
|
60
57
|
|
61
58
|
VALUE reading_raw;
|
62
59
|
size_t reading_raw_remaining;
|
63
|
-
int reading_raw_type;
|
64
60
|
|
65
61
|
VALUE buffer_ref;
|
66
62
|
|
67
63
|
msgpack_unpacker_ext_registry_t *ext_registry;
|
68
64
|
|
65
|
+
int reading_raw_type;
|
66
|
+
unsigned int head_byte;
|
67
|
+
|
69
68
|
/* options */
|
70
|
-
bool symbolize_keys;
|
71
|
-
bool freeze;
|
72
|
-
bool allow_unknown_ext;
|
73
|
-
bool optimized_symbol_ext_type;
|
74
69
|
int symbol_ext_type;
|
70
|
+
|
71
|
+
bool use_key_cache: 1;
|
72
|
+
bool symbolize_keys: 1;
|
73
|
+
bool freeze: 1;
|
74
|
+
bool allow_unknown_ext: 1;
|
75
|
+
bool optimized_symbol_ext_type: 1;
|
75
76
|
};
|
76
77
|
|
77
78
|
#define UNPACKER_BUFFER_(uk) (&(uk)->buffer)
|
@@ -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*
|
94
|
+
void _msgpack_unpacker_init(msgpack_unpacker_t*);
|
94
95
|
|
95
96
|
void _msgpack_unpacker_destroy(msgpack_unpacker_t* uk);
|
96
97
|
|
@@ -103,6 +104,11 @@ static inline void msgpack_unpacker_set_symbolized_keys(msgpack_unpacker_t* uk,
|
|
103
104
|
uk->symbolize_keys = enable;
|
104
105
|
}
|
105
106
|
|
107
|
+
static inline void msgpack_unpacker_set_key_cache(msgpack_unpacker_t* uk, bool enable)
|
108
|
+
{
|
109
|
+
uk->use_key_cache = enable;
|
110
|
+
}
|
111
|
+
|
106
112
|
static inline void msgpack_unpacker_set_freeze(msgpack_unpacker_t* uk, bool enable)
|
107
113
|
{
|
108
114
|
uk->freeze = enable;
|
@@ -122,6 +128,7 @@ static inline void msgpack_unpacker_set_allow_unknown_ext(msgpack_unpacker_t* uk
|
|
122
128
|
#define PRIMITIVE_STACK_TOO_DEEP -3
|
123
129
|
#define PRIMITIVE_UNEXPECTED_TYPE -4
|
124
130
|
#define PRIMITIVE_UNEXPECTED_EXT_TYPE -5
|
131
|
+
#define PRIMITIVE_RECURSIVE_RAISED -6
|
125
132
|
|
126
133
|
int msgpack_unpacker_read(msgpack_unpacker_t* uk, size_t target_stack_depth);
|
127
134
|
|
@@ -34,18 +34,13 @@ static VALUE eUnknownExtTypeError;
|
|
34
34
|
static VALUE mTypeError; // obsoleted. only for backward compatibility. See #86.
|
35
35
|
|
36
36
|
static VALUE sym_symbolize_keys;
|
37
|
+
static VALUE sym_key_cache;
|
37
38
|
static VALUE sym_freeze;
|
38
39
|
static VALUE sym_allow_unknown_ext;
|
39
40
|
|
40
|
-
|
41
|
-
msgpack_unpacker_t *name = NULL; \
|
42
|
-
Data_Get_Struct(from, msgpack_unpacker_t, name); \
|
43
|
-
if(name == NULL) { \
|
44
|
-
rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
|
45
|
-
}
|
46
|
-
|
47
|
-
static void Unpacker_free(msgpack_unpacker_t* uk)
|
41
|
+
static void Unpacker_free(void *ptr)
|
48
42
|
{
|
43
|
+
msgpack_unpacker_t* uk = ptr;
|
49
44
|
if(uk == NULL) {
|
50
45
|
return;
|
51
46
|
}
|
@@ -54,17 +49,47 @@ static void Unpacker_free(msgpack_unpacker_t* uk)
|
|
54
49
|
xfree(uk);
|
55
50
|
}
|
56
51
|
|
57
|
-
static void Unpacker_mark(
|
52
|
+
static void Unpacker_mark(void *ptr)
|
58
53
|
{
|
54
|
+
msgpack_unpacker_t* uk = ptr;
|
55
|
+
msgpack_buffer_mark(uk);
|
59
56
|
msgpack_unpacker_mark(uk);
|
60
57
|
msgpack_unpacker_ext_registry_mark(uk->ext_registry);
|
61
58
|
}
|
62
59
|
|
63
|
-
|
60
|
+
static size_t Unpacker_memsize(const void *ptr)
|
64
61
|
{
|
65
|
-
msgpack_unpacker_t* uk =
|
62
|
+
const msgpack_unpacker_t* uk = ptr;
|
63
|
+
|
64
|
+
size_t total_size = sizeof(msgpack_unpacker_t);
|
65
|
+
|
66
|
+
if (uk->ext_registry) {
|
67
|
+
total_size += sizeof(msgpack_unpacker_ext_registry_t) / (uk->ext_registry->borrow_count + 1);
|
68
|
+
}
|
66
69
|
|
67
|
-
|
70
|
+
if (uk->stack.data) {
|
71
|
+
total_size += (uk->stack.depth + 1) * sizeof(msgpack_unpacker_stack_t);
|
72
|
+
}
|
73
|
+
|
74
|
+
return total_size + msgpack_buffer_memsize(&uk->buffer);
|
75
|
+
}
|
76
|
+
|
77
|
+
const rb_data_type_t unpacker_data_type = {
|
78
|
+
.wrap_struct_name = "msgpack:unpacker",
|
79
|
+
.function = {
|
80
|
+
.dmark = Unpacker_mark,
|
81
|
+
.dfree = Unpacker_free,
|
82
|
+
.dsize = Unpacker_memsize,
|
83
|
+
},
|
84
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
85
|
+
};
|
86
|
+
|
87
|
+
VALUE MessagePack_Unpacker_alloc(VALUE klass)
|
88
|
+
{
|
89
|
+
msgpack_unpacker_t* uk;
|
90
|
+
VALUE self = TypedData_Make_Struct(klass, msgpack_unpacker_t, &unpacker_data_type, uk);
|
91
|
+
_msgpack_unpacker_init(uk);
|
92
|
+
uk->self = self;
|
68
93
|
return self;
|
69
94
|
}
|
70
95
|
|
@@ -95,15 +120,18 @@ VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self)
|
|
95
120
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
96
121
|
}
|
97
122
|
|
98
|
-
|
123
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
99
124
|
|
100
|
-
uk->buffer_ref =
|
125
|
+
uk->buffer_ref = Qnil;
|
101
126
|
|
102
127
|
MessagePack_Buffer_set_options(UNPACKER_BUFFER_(uk), io, options);
|
103
128
|
|
104
129
|
if(options != Qnil) {
|
105
130
|
VALUE v;
|
106
131
|
|
132
|
+
v = rb_hash_aref(options, sym_key_cache);
|
133
|
+
msgpack_unpacker_set_key_cache(uk, RTEST(v));
|
134
|
+
|
107
135
|
v = rb_hash_aref(options, sym_symbolize_keys);
|
108
136
|
msgpack_unpacker_set_symbolized_keys(uk, RTEST(v));
|
109
137
|
|
@@ -119,36 +147,44 @@ VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self)
|
|
119
147
|
|
120
148
|
static VALUE Unpacker_symbolized_keys_p(VALUE self)
|
121
149
|
{
|
122
|
-
|
150
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
123
151
|
return uk->symbolize_keys ? Qtrue : Qfalse;
|
124
152
|
}
|
125
153
|
|
126
154
|
static VALUE Unpacker_freeze_p(VALUE self)
|
127
155
|
{
|
128
|
-
|
156
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
129
157
|
return uk->freeze ? Qtrue : Qfalse;
|
130
158
|
}
|
131
159
|
|
132
160
|
static VALUE Unpacker_allow_unknown_ext_p(VALUE self)
|
133
161
|
{
|
134
|
-
|
162
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
135
163
|
return uk->allow_unknown_ext ? Qtrue : Qfalse;
|
136
164
|
}
|
137
165
|
|
138
|
-
NORETURN(static void raise_unpacker_error(int r))
|
166
|
+
NORETURN(static void raise_unpacker_error(msgpack_unpacker_t *uk, int r))
|
139
167
|
{
|
168
|
+
uk->stack.depth = 0;
|
140
169
|
switch(r) {
|
141
170
|
case PRIMITIVE_EOF:
|
142
171
|
rb_raise(rb_eEOFError, "end of buffer reached");
|
172
|
+
break;
|
143
173
|
case PRIMITIVE_INVALID_BYTE:
|
144
174
|
rb_raise(eMalformedFormatError, "invalid byte");
|
175
|
+
break;
|
145
176
|
case PRIMITIVE_STACK_TOO_DEEP:
|
146
177
|
rb_raise(eStackError, "stack level too deep");
|
178
|
+
break;
|
147
179
|
case PRIMITIVE_UNEXPECTED_TYPE:
|
148
180
|
rb_raise(eUnexpectedTypeError, "unexpected type");
|
181
|
+
break;
|
149
182
|
case PRIMITIVE_UNEXPECTED_EXT_TYPE:
|
150
|
-
// rb_bug("unexpected extension type");
|
151
183
|
rb_raise(eUnknownExtTypeError, "unexpected extension type");
|
184
|
+
break;
|
185
|
+
case PRIMITIVE_RECURSIVE_RAISED:
|
186
|
+
rb_exc_raise(msgpack_unpacker_get_last_object(uk));
|
187
|
+
break;
|
152
188
|
default:
|
153
189
|
rb_raise(eUnpackError, "logically unknown error %d", r);
|
154
190
|
}
|
@@ -156,17 +192,20 @@ NORETURN(static void raise_unpacker_error(int r))
|
|
156
192
|
|
157
193
|
static VALUE Unpacker_buffer(VALUE self)
|
158
194
|
{
|
159
|
-
|
195
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
196
|
+
if (!RTEST(uk->buffer_ref)) {
|
197
|
+
uk->buffer_ref = MessagePack_Buffer_wrap(UNPACKER_BUFFER_(uk), self);
|
198
|
+
}
|
160
199
|
return uk->buffer_ref;
|
161
200
|
}
|
162
201
|
|
163
202
|
static VALUE Unpacker_read(VALUE self)
|
164
203
|
{
|
165
|
-
|
204
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
166
205
|
|
167
206
|
int r = msgpack_unpacker_read(uk, 0);
|
168
207
|
if(r < 0) {
|
169
|
-
raise_unpacker_error(r);
|
208
|
+
raise_unpacker_error(uk, r);
|
170
209
|
}
|
171
210
|
|
172
211
|
return msgpack_unpacker_get_last_object(uk);
|
@@ -174,11 +213,11 @@ static VALUE Unpacker_read(VALUE self)
|
|
174
213
|
|
175
214
|
static VALUE Unpacker_skip(VALUE self)
|
176
215
|
{
|
177
|
-
|
216
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
178
217
|
|
179
218
|
int r = msgpack_unpacker_skip(uk, 0);
|
180
219
|
if(r < 0) {
|
181
|
-
raise_unpacker_error(r);
|
220
|
+
raise_unpacker_error(uk, r);
|
182
221
|
}
|
183
222
|
|
184
223
|
return Qnil;
|
@@ -186,11 +225,11 @@ static VALUE Unpacker_skip(VALUE self)
|
|
186
225
|
|
187
226
|
static VALUE Unpacker_skip_nil(VALUE self)
|
188
227
|
{
|
189
|
-
|
228
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
190
229
|
|
191
230
|
int r = msgpack_unpacker_skip_nil(uk);
|
192
231
|
if(r < 0) {
|
193
|
-
raise_unpacker_error(r);
|
232
|
+
raise_unpacker_error(uk, r);
|
194
233
|
}
|
195
234
|
|
196
235
|
if(r) {
|
@@ -201,12 +240,12 @@ static VALUE Unpacker_skip_nil(VALUE self)
|
|
201
240
|
|
202
241
|
static VALUE Unpacker_read_array_header(VALUE self)
|
203
242
|
{
|
204
|
-
|
243
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
205
244
|
|
206
245
|
uint32_t size;
|
207
246
|
int r = msgpack_unpacker_read_array_header(uk, &size);
|
208
247
|
if(r < 0) {
|
209
|
-
raise_unpacker_error(r);
|
248
|
+
raise_unpacker_error(uk, r);
|
210
249
|
}
|
211
250
|
|
212
251
|
return ULONG2NUM(size); // long at least 32 bits
|
@@ -214,32 +253,20 @@ static VALUE Unpacker_read_array_header(VALUE self)
|
|
214
253
|
|
215
254
|
static VALUE Unpacker_read_map_header(VALUE self)
|
216
255
|
{
|
217
|
-
|
256
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
218
257
|
|
219
258
|
uint32_t size;
|
220
259
|
int r = msgpack_unpacker_read_map_header(uk, &size);
|
221
260
|
if(r < 0) {
|
222
|
-
raise_unpacker_error(
|
261
|
+
raise_unpacker_error(uk, r);
|
223
262
|
}
|
224
263
|
|
225
264
|
return ULONG2NUM(size); // long at least 32 bits
|
226
265
|
}
|
227
266
|
|
228
|
-
|
229
|
-
static VALUE Unpacker_feed(VALUE self, VALUE data)
|
230
|
-
{
|
231
|
-
UNPACKER(self, uk);
|
232
|
-
|
233
|
-
StringValue(data);
|
234
|
-
|
235
|
-
msgpack_buffer_append_string(UNPACKER_BUFFER_(uk), data);
|
236
|
-
|
237
|
-
return self;
|
238
|
-
}
|
239
|
-
|
240
267
|
static VALUE Unpacker_feed_reference(VALUE self, VALUE data)
|
241
268
|
{
|
242
|
-
|
269
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
243
270
|
|
244
271
|
StringValue(data);
|
245
272
|
|
@@ -250,7 +277,7 @@ static VALUE Unpacker_feed_reference(VALUE self, VALUE data)
|
|
250
277
|
|
251
278
|
static VALUE Unpacker_each_impl(VALUE self)
|
252
279
|
{
|
253
|
-
|
280
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
254
281
|
|
255
282
|
while(true) {
|
256
283
|
int r = msgpack_unpacker_read(uk, 0);
|
@@ -258,15 +285,9 @@ static VALUE Unpacker_each_impl(VALUE self)
|
|
258
285
|
if(r == PRIMITIVE_EOF) {
|
259
286
|
return Qnil;
|
260
287
|
}
|
261
|
-
raise_unpacker_error(r);
|
288
|
+
raise_unpacker_error(uk, r);
|
262
289
|
}
|
263
290
|
VALUE v = msgpack_unpacker_get_last_object(uk);
|
264
|
-
#ifdef JRUBY
|
265
|
-
/* TODO JRuby's rb_yield behaves differently from Ruby 1.9.3 or Rubinius. */
|
266
|
-
if(rb_type(v) == T_ARRAY) {
|
267
|
-
v = rb_ary_new3(1, v);
|
268
|
-
}
|
269
|
-
#endif
|
270
291
|
rb_yield(v);
|
271
292
|
}
|
272
293
|
}
|
@@ -280,7 +301,7 @@ static VALUE Unpacker_rescue_EOFError(VALUE args, VALUE error)
|
|
280
301
|
|
281
302
|
static VALUE Unpacker_each(VALUE self)
|
282
303
|
{
|
283
|
-
|
304
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
284
305
|
|
285
306
|
#ifdef RETURN_ENUMERATOR
|
286
307
|
RETURN_ENUMERATOR(self, 0, 0);
|
@@ -311,7 +332,7 @@ static VALUE Unpacker_feed_each(VALUE self, VALUE data)
|
|
311
332
|
|
312
333
|
static VALUE Unpacker_reset(VALUE self)
|
313
334
|
{
|
314
|
-
|
335
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
315
336
|
|
316
337
|
_msgpack_unpacker_reset(uk);
|
317
338
|
|
@@ -320,7 +341,7 @@ static VALUE Unpacker_reset(VALUE self)
|
|
320
341
|
|
321
342
|
static VALUE Unpacker_registered_types_internal(VALUE self)
|
322
343
|
{
|
323
|
-
|
344
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
324
345
|
|
325
346
|
VALUE mapping = rb_hash_new();
|
326
347
|
if (uk->ext_registry) {
|
@@ -334,50 +355,30 @@ static VALUE Unpacker_registered_types_internal(VALUE self)
|
|
334
355
|
return mapping;
|
335
356
|
}
|
336
357
|
|
337
|
-
static VALUE
|
358
|
+
static VALUE Unpacker_register_type_internal(VALUE self, VALUE rb_ext_type, VALUE ext_module, VALUE proc)
|
338
359
|
{
|
339
|
-
|
340
|
-
|
341
|
-
int ext_type;
|
342
|
-
VALUE proc;
|
343
|
-
VALUE arg;
|
344
|
-
VALUE ext_module;
|
345
|
-
|
346
|
-
switch (argc) {
|
347
|
-
case 1:
|
348
|
-
/* register_type(0x7f) {|data| block... } */
|
349
|
-
rb_need_block();
|
350
|
-
proc = rb_block_lambda();
|
351
|
-
arg = proc;
|
352
|
-
ext_module = Qnil;
|
353
|
-
break;
|
354
|
-
case 3:
|
355
|
-
/* register_type(0x7f, Time, :from_msgpack_ext) */
|
356
|
-
ext_module = argv[1];
|
357
|
-
arg = argv[2];
|
358
|
-
proc = rb_obj_method(ext_module, arg);
|
359
|
-
break;
|
360
|
-
default:
|
361
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 3)", argc);
|
360
|
+
if (OBJ_FROZEN(self)) {
|
361
|
+
rb_raise(rb_eFrozenError, "can't modify frozen MessagePack::Unpacker");
|
362
362
|
}
|
363
363
|
|
364
|
-
ext_type = NUM2INT(
|
364
|
+
int ext_type = NUM2INT(rb_ext_type);
|
365
365
|
if(ext_type < -128 || ext_type > 127) {
|
366
366
|
rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type);
|
367
367
|
}
|
368
368
|
|
369
|
-
|
369
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
370
|
+
msgpack_unpacker_ext_registry_put(self, &uk->ext_registry, ext_module, ext_type, 0, proc);
|
370
371
|
|
371
372
|
return Qnil;
|
372
373
|
}
|
373
374
|
|
374
375
|
static VALUE Unpacker_full_unpack(VALUE self)
|
375
376
|
{
|
376
|
-
|
377
|
+
msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self);
|
377
378
|
|
378
379
|
int r = msgpack_unpacker_read(uk, 0);
|
379
380
|
if(r < 0) {
|
380
|
-
raise_unpacker_error(r);
|
381
|
+
raise_unpacker_error(uk, r);
|
381
382
|
}
|
382
383
|
|
383
384
|
/* raise if extra bytes follow */
|
@@ -399,7 +400,6 @@ VALUE MessagePack_Unpacker_new(int argc, VALUE* argv)
|
|
399
400
|
void MessagePack_Unpacker_module_init(VALUE mMessagePack)
|
400
401
|
{
|
401
402
|
msgpack_unpacker_static_init();
|
402
|
-
msgpack_unpacker_ext_registry_static_init();
|
403
403
|
|
404
404
|
mTypeError = rb_define_module_under(mMessagePack, "TypeError");
|
405
405
|
|
@@ -417,6 +417,7 @@ void MessagePack_Unpacker_module_init(VALUE mMessagePack)
|
|
417
417
|
eUnknownExtTypeError = rb_define_class_under(mMessagePack, "UnknownExtTypeError", eUnpackError);
|
418
418
|
|
419
419
|
sym_symbolize_keys = ID2SYM(rb_intern("symbolize_keys"));
|
420
|
+
sym_key_cache = ID2SYM(rb_intern("key_cache"));
|
420
421
|
sym_freeze = ID2SYM(rb_intern("freeze"));
|
421
422
|
sym_allow_unknown_ext = ID2SYM(rb_intern("allow_unknown_ext"));
|
422
423
|
|
@@ -433,20 +434,14 @@ void MessagePack_Unpacker_module_init(VALUE mMessagePack)
|
|
433
434
|
rb_define_method(cMessagePack_Unpacker, "skip_nil", Unpacker_skip_nil, 0);
|
434
435
|
rb_define_method(cMessagePack_Unpacker, "read_array_header", Unpacker_read_array_header, 0);
|
435
436
|
rb_define_method(cMessagePack_Unpacker, "read_map_header", Unpacker_read_map_header, 0);
|
436
|
-
rb_define_method(cMessagePack_Unpacker, "feed",
|
437
|
-
|
437
|
+
rb_define_method(cMessagePack_Unpacker, "feed", Unpacker_feed_reference, 1);
|
438
|
+
rb_define_alias(cMessagePack_Unpacker, "feed_reference", "feed");
|
438
439
|
rb_define_method(cMessagePack_Unpacker, "each", Unpacker_each, 0);
|
439
440
|
rb_define_method(cMessagePack_Unpacker, "feed_each", Unpacker_feed_each, 1);
|
440
441
|
rb_define_method(cMessagePack_Unpacker, "reset", Unpacker_reset, 0);
|
441
442
|
|
442
443
|
rb_define_private_method(cMessagePack_Unpacker, "registered_types_internal", Unpacker_registered_types_internal, 0);
|
443
|
-
|
444
|
-
|
445
|
-
//s_unpacker_value = MessagePack_Unpacker_alloc(cMessagePack_Unpacker);
|
446
|
-
//rb_gc_register_address(&s_unpacker_value);
|
447
|
-
//Data_Get_Struct(s_unpacker_value, msgpack_unpacker_t, s_unpacker);
|
448
|
-
/* prefer reference than copying */
|
449
|
-
//msgpack_buffer_set_write_reference_threshold(UNPACKER_BUFFER_(s_unpacker), 0);
|
444
|
+
rb_define_private_method(cMessagePack_Unpacker, "register_type_internal", Unpacker_register_type_internal, 3);
|
450
445
|
|
451
446
|
rb_define_method(cMessagePack_Unpacker, "full_unpack", Unpacker_full_unpack, 0);
|
452
447
|
}
|
@@ -20,6 +20,17 @@
|
|
20
20
|
|
21
21
|
#include "unpacker.h"
|
22
22
|
|
23
|
+
extern const rb_data_type_t unpacker_data_type;
|
24
|
+
|
25
|
+
static inline msgpack_unpacker_t *MessagePack_Unpacker_get(VALUE object) {
|
26
|
+
msgpack_unpacker_t *unpacker;
|
27
|
+
TypedData_Get_Struct(object, msgpack_unpacker_t, &unpacker_data_type, unpacker);
|
28
|
+
if (!unpacker) {
|
29
|
+
rb_raise(rb_eArgError, "Uninitialized Unpacker object");
|
30
|
+
}
|
31
|
+
return unpacker;
|
32
|
+
}
|
33
|
+
|
23
34
|
extern VALUE cMessagePack_Unpacker;
|
24
35
|
|
25
36
|
void MessagePack_Unpacker_module_init(VALUE mMessagePack);
|
@@ -18,19 +18,6 @@
|
|
18
18
|
|
19
19
|
#include "unpacker_ext_registry.h"
|
20
20
|
|
21
|
-
static ID s_call;
|
22
|
-
static ID s_dup;
|
23
|
-
|
24
|
-
void msgpack_unpacker_ext_registry_static_init()
|
25
|
-
{
|
26
|
-
s_call = rb_intern("call");
|
27
|
-
s_dup = rb_intern("dup");
|
28
|
-
}
|
29
|
-
|
30
|
-
|
31
|
-
void msgpack_unpacker_ext_registry_static_destroy()
|
32
|
-
{ }
|
33
|
-
|
34
21
|
void msgpack_unpacker_ext_registry_mark(msgpack_unpacker_ext_registry_t* ukrg)
|
35
22
|
{
|
36
23
|
if (ukrg) {
|
@@ -76,11 +63,12 @@ void msgpack_unpacker_ext_registry_release(msgpack_unpacker_ext_registry_t* ukrg
|
|
76
63
|
}
|
77
64
|
}
|
78
65
|
|
79
|
-
void msgpack_unpacker_ext_registry_put(msgpack_unpacker_ext_registry_t** ukrg,
|
80
|
-
VALUE ext_module, int ext_type, int flags, VALUE proc
|
66
|
+
void msgpack_unpacker_ext_registry_put(VALUE owner, msgpack_unpacker_ext_registry_t** ukrg,
|
67
|
+
VALUE ext_module, int ext_type, int flags, VALUE proc)
|
81
68
|
{
|
82
69
|
msgpack_unpacker_ext_registry_t* ext_registry = msgpack_unpacker_ext_registry_cow(*ukrg);
|
83
70
|
|
84
|
-
|
71
|
+
VALUE entry = rb_ary_new3(3, ext_module, proc, INT2FIX(flags));
|
72
|
+
RB_OBJ_WRITE(owner, &ext_registry->array[ext_type + 128], entry);
|
85
73
|
*ukrg = ext_registry;
|
86
74
|
}
|
@@ -31,10 +31,6 @@ struct msgpack_unpacker_ext_registry_t {
|
|
31
31
|
VALUE array[256];
|
32
32
|
};
|
33
33
|
|
34
|
-
void msgpack_unpacker_ext_registry_static_init();
|
35
|
-
|
36
|
-
void msgpack_unpacker_ext_registry_static_destroy();
|
37
|
-
|
38
34
|
void msgpack_unpacker_ext_registry_release(msgpack_unpacker_ext_registry_t* ukrg);
|
39
35
|
|
40
36
|
static inline void msgpack_unpacker_ext_registry_borrow(msgpack_unpacker_ext_registry_t* src, msgpack_unpacker_ext_registry_t** dst)
|
@@ -47,8 +43,8 @@ static inline void msgpack_unpacker_ext_registry_borrow(msgpack_unpacker_ext_reg
|
|
47
43
|
|
48
44
|
void msgpack_unpacker_ext_registry_mark(msgpack_unpacker_ext_registry_t* ukrg);
|
49
45
|
|
50
|
-
void msgpack_unpacker_ext_registry_put(msgpack_unpacker_ext_registry_t** ukrg,
|
51
|
-
VALUE ext_module, int ext_type, int flags, VALUE proc
|
46
|
+
void msgpack_unpacker_ext_registry_put(VALUE owner, msgpack_unpacker_ext_registry_t** ukrg,
|
47
|
+
VALUE ext_module, int ext_type, int flags, VALUE proc);
|
52
48
|
|
53
49
|
static inline VALUE msgpack_unpacker_ext_registry_lookup(msgpack_unpacker_ext_registry_t* ukrg,
|
54
50
|
int ext_type, int* ext_flags_result)
|
@@ -56,7 +52,7 @@ static inline VALUE msgpack_unpacker_ext_registry_lookup(msgpack_unpacker_ext_re
|
|
56
52
|
if (ukrg) {
|
57
53
|
VALUE entry = ukrg->array[ext_type + 128];
|
58
54
|
if (entry != Qnil) {
|
59
|
-
*ext_flags_result = FIX2INT(rb_ary_entry(entry,
|
55
|
+
*ext_flags_result = FIX2INT(rb_ary_entry(entry, 2));
|
60
56
|
return rb_ary_entry(entry, 1);
|
61
57
|
}
|
62
58
|
}
|