msgpack 1.5.5 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +12 -0
- data/bin/console +8 -0
- data/ext/msgpack/buffer.c +51 -38
- data/ext/msgpack/buffer.h +5 -9
- data/ext/msgpack/buffer_class.c +62 -32
- data/ext/msgpack/extconf.rb +0 -4
- data/ext/msgpack/factory_class.c +49 -26
- data/ext/msgpack/packer.c +2 -4
- data/ext/msgpack/packer.h +2 -2
- data/ext/msgpack/packer_class.c +54 -45
- data/ext/msgpack/packer_class.h +11 -0
- data/ext/msgpack/packer_ext_registry.c +2 -2
- data/ext/msgpack/packer_ext_registry.h +2 -2
- data/ext/msgpack/sysdep.h +5 -2
- data/ext/msgpack/unpacker.c +5 -9
- data/ext/msgpack/unpacker.h +4 -3
- data/ext/msgpack/unpacker_class.c +50 -30
- data/ext/msgpack/unpacker_class.h +11 -0
- data/ext/msgpack/unpacker_ext_registry.c +2 -2
- data/ext/msgpack/unpacker_ext_registry.h +2 -2
- data/lib/msgpack/version.rb +1 -1
- data/spec/cruby/buffer_spec.rb +17 -0
- data/spec/factory_spec.rb +18 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/unpacker_spec.rb +10 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb08f890b2d9a36312600e284933cd0de93a00a6b949507bfc3d7c5c7eab1638
|
4
|
+
data.tar.gz: 11e536f8bde329edbc966e5e1050134350024f89f1cb911878f86fd59ff1fc79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9491cdf494d1826cce7f5e420d73a65ce88c029e060338d9c28fb1e20e4d01dc71fdb46b91859d025bbcc8f5a0471100b171cb9b3bac5fed6f0f0715fd76abb2
|
7
|
+
data.tar.gz: 8d0b4db4f93ebf98063f275c0629648ab9316c7cc3cd81738f7f083c6ed4c47fc647c2fc5df1308089b96c36d7e13944028e75bae7e5897b5bb357701c0bcfd9
|
data/ChangeLog
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
2022-09-30 1.6.0:
|
2
|
+
|
3
|
+
* Fix a potential use-after-free bug in Buffer_free when accessing a packer or unpacker buffer.
|
4
|
+
* `old-style-definition` compilation warnings.
|
5
|
+
* Restore zero-copy buffer feed when provided a Ruby string. This was accidentally broken in 1.5.4.
|
6
|
+
* Provide implementations for `ObjectSpace.memsize`. Message pack objects now properly report their size to Ruby.
|
7
|
+
* Fix an endianess bug on Windows platform.
|
8
|
+
|
9
|
+
2022-08-23 1.5.6:
|
10
|
+
|
11
|
+
* No actual code change, just re-release the `java` version properly.
|
12
|
+
|
1
13
|
2022-08-22 1.5.5:
|
2
14
|
|
3
15
|
* Fix a segfault when GC triggers inside a recursive extension.
|
data/bin/console
ADDED
data/ext/msgpack/buffer.c
CHANGED
@@ -29,11 +29,9 @@ int msgpack_rb_encindex_ascii8bit;
|
|
29
29
|
|
30
30
|
ID s_uminus;
|
31
31
|
|
32
|
-
#ifndef DISABLE_RMEM
|
33
32
|
static msgpack_rmem_t s_rmem;
|
34
|
-
#endif
|
35
33
|
|
36
|
-
void msgpack_buffer_static_init()
|
34
|
+
void msgpack_buffer_static_init(void)
|
37
35
|
{
|
38
36
|
s_uminus = rb_intern("-@");
|
39
37
|
|
@@ -41,20 +39,16 @@ void msgpack_buffer_static_init()
|
|
41
39
|
msgpack_rb_encindex_usascii = rb_usascii_encindex();
|
42
40
|
msgpack_rb_encindex_ascii8bit = rb_ascii8bit_encindex();
|
43
41
|
|
44
|
-
#ifndef DISABLE_RMEM
|
45
42
|
msgpack_rmem_init(&s_rmem);
|
46
|
-
#endif
|
47
43
|
|
48
44
|
#ifndef HAVE_RB_STR_REPLACE
|
49
45
|
s_replace = rb_intern("replace");
|
50
46
|
#endif
|
51
47
|
}
|
52
48
|
|
53
|
-
void msgpack_buffer_static_destroy()
|
49
|
+
void msgpack_buffer_static_destroy(void)
|
54
50
|
{
|
55
|
-
#ifndef DISABLE_RMEM
|
56
51
|
msgpack_rmem_destroy(&s_rmem);
|
57
|
-
#endif
|
58
52
|
}
|
59
53
|
|
60
54
|
void msgpack_buffer_init(msgpack_buffer_t* b)
|
@@ -72,16 +66,12 @@ void msgpack_buffer_init(msgpack_buffer_t* b)
|
|
72
66
|
static void _msgpack_buffer_chunk_destroy(msgpack_buffer_chunk_t* c)
|
73
67
|
{
|
74
68
|
if(c->mem != NULL) {
|
75
|
-
#ifndef DISABLE_RMEM
|
76
69
|
if(!msgpack_rmem_free(&s_rmem, c->mem)) {
|
77
70
|
xfree(c->mem);
|
78
71
|
}
|
79
72
|
/* no needs to update rmem_owner because chunks will not be
|
80
73
|
* free()ed (left in free_list) and thus *rmem_owner is
|
81
74
|
* always valid. */
|
82
|
-
#else
|
83
|
-
xfree(c->mem);
|
84
|
-
#endif
|
85
75
|
}
|
86
76
|
c->first = NULL;
|
87
77
|
c->last = NULL;
|
@@ -108,8 +98,25 @@ void msgpack_buffer_destroy(msgpack_buffer_t* b)
|
|
108
98
|
}
|
109
99
|
}
|
110
100
|
|
111
|
-
|
101
|
+
size_t msgpack_buffer_memsize(const msgpack_buffer_t* b)
|
102
|
+
{
|
103
|
+
size_t memsize = 0;
|
104
|
+
msgpack_buffer_chunk_t* c = b->head;
|
105
|
+
|
106
|
+
while(c) {
|
107
|
+
memsize += sizeof(msgpack_buffer_chunk_t);
|
108
|
+
if(c->mapped_string != NO_MAPPED_STRING) {
|
109
|
+
memsize += (c->last - c->first);
|
110
|
+
}
|
111
|
+
c = c->next;
|
112
|
+
}
|
113
|
+
|
114
|
+
return memsize;
|
115
|
+
}
|
116
|
+
|
117
|
+
void msgpack_buffer_mark(void *ptr)
|
112
118
|
{
|
119
|
+
msgpack_buffer_t* b = ptr;
|
113
120
|
/* head is always available */
|
114
121
|
msgpack_buffer_chunk_t* c = b->head;
|
115
122
|
while(c != &b->tail) {
|
@@ -120,8 +127,6 @@ void msgpack_buffer_mark(msgpack_buffer_t* b)
|
|
120
127
|
|
121
128
|
rb_gc_mark(b->io);
|
122
129
|
rb_gc_mark(b->io_buffer);
|
123
|
-
|
124
|
-
rb_gc_mark(b->owner);
|
125
130
|
}
|
126
131
|
|
127
132
|
bool _msgpack_buffer_shift_chunk(msgpack_buffer_t* b)
|
@@ -158,7 +163,6 @@ size_t msgpack_buffer_read_to_string_nonblock(msgpack_buffer_t* b, VALUE string,
|
|
158
163
|
{
|
159
164
|
size_t avail = msgpack_buffer_top_readable_size(b);
|
160
165
|
|
161
|
-
#ifndef DISABLE_BUFFER_READ_REFERENCE_OPTIMIZE
|
162
166
|
/* optimize */
|
163
167
|
if(length <= avail && RSTRING_LEN(string) == 0 &&
|
164
168
|
b->head->mapped_string != NO_MAPPED_STRING &&
|
@@ -170,7 +174,6 @@ size_t msgpack_buffer_read_to_string_nonblock(msgpack_buffer_t* b, VALUE string,
|
|
170
174
|
_msgpack_buffer_consumed(b, length);
|
171
175
|
return length;
|
172
176
|
}
|
173
|
-
#endif
|
174
177
|
|
175
178
|
size_t const length_orig = length;
|
176
179
|
|
@@ -283,15 +286,11 @@ static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b)
|
|
283
286
|
|
284
287
|
msgpack_buffer_chunk_t* nc = _msgpack_buffer_alloc_new_chunk(b);
|
285
288
|
|
286
|
-
#ifndef DISABLE_RMEM
|
287
|
-
#ifndef DISABLE_RMEM_REUSE_INTERNAL_FRAGMENT
|
288
289
|
if(b->rmem_last == b->tail_buffer_end) {
|
289
290
|
/* reuse unused rmem space */
|
290
291
|
size_t unused = b->tail_buffer_end - b->tail.last;
|
291
292
|
b->rmem_last -= unused;
|
292
293
|
}
|
293
|
-
#endif
|
294
|
-
#endif
|
295
294
|
|
296
295
|
/* rebuild tail */
|
297
296
|
*nc = b->tail;
|
@@ -300,6 +299,35 @@ static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b)
|
|
300
299
|
}
|
301
300
|
}
|
302
301
|
|
302
|
+
static inline void _msgpack_buffer_append_reference(msgpack_buffer_t* b, VALUE string)
|
303
|
+
{
|
304
|
+
VALUE mapped_string;
|
305
|
+
if(ENCODING_GET(string) == msgpack_rb_encindex_ascii8bit && RTEST(rb_obj_frozen_p(string))) {
|
306
|
+
mapped_string = string;
|
307
|
+
} else {
|
308
|
+
mapped_string = rb_str_dup(string);
|
309
|
+
ENCODING_SET(mapped_string, msgpack_rb_encindex_ascii8bit);
|
310
|
+
}
|
311
|
+
|
312
|
+
_msgpack_buffer_add_new_chunk(b);
|
313
|
+
|
314
|
+
char* data = RSTRING_PTR(mapped_string);
|
315
|
+
size_t length = RSTRING_LEN(mapped_string);
|
316
|
+
|
317
|
+
b->tail.first = (char*) data;
|
318
|
+
b->tail.last = (char*) data + length;
|
319
|
+
b->tail.mapped_string = mapped_string;
|
320
|
+
b->tail.mem = NULL;
|
321
|
+
|
322
|
+
/* msgpack_buffer_writable_size should return 0 for mapped chunk */
|
323
|
+
b->tail_buffer_end = b->tail.last;
|
324
|
+
|
325
|
+
/* consider read_buffer */
|
326
|
+
if(b->head == &b->tail) {
|
327
|
+
b->read_buffer = b->tail.first;
|
328
|
+
}
|
329
|
+
}
|
330
|
+
|
303
331
|
void _msgpack_buffer_append_long_string(msgpack_buffer_t* b, VALUE string)
|
304
332
|
{
|
305
333
|
size_t length = RSTRING_LEN(string);
|
@@ -312,7 +340,7 @@ void _msgpack_buffer_append_long_string(msgpack_buffer_t* b, VALUE string)
|
|
312
340
|
msgpack_buffer_append(b, RSTRING_PTR(string), length);
|
313
341
|
}
|
314
342
|
} else {
|
315
|
-
|
343
|
+
_msgpack_buffer_append_reference(b, string);
|
316
344
|
}
|
317
345
|
}
|
318
346
|
|
@@ -320,11 +348,8 @@ static inline void* _msgpack_buffer_chunk_malloc(
|
|
320
348
|
msgpack_buffer_t* b, msgpack_buffer_chunk_t* c,
|
321
349
|
size_t required_size, size_t* allocated_size)
|
322
350
|
{
|
323
|
-
#ifndef DISABLE_RMEM
|
324
351
|
if(required_size <= MSGPACK_RMEM_PAGE_SIZE) {
|
325
|
-
#ifndef DISABLE_RMEM_REUSE_INTERNAL_FRAGMENT
|
326
352
|
if((size_t)(b->rmem_end - b->rmem_last) < required_size) {
|
327
|
-
#endif
|
328
353
|
/* alloc new rmem page */
|
329
354
|
*allocated_size = MSGPACK_RMEM_PAGE_SIZE;
|
330
355
|
char* buffer = msgpack_rmem_alloc(&s_rmem);
|
@@ -335,8 +360,6 @@ static inline void* _msgpack_buffer_chunk_malloc(
|
|
335
360
|
b->rmem_last = b->rmem_end = buffer + MSGPACK_RMEM_PAGE_SIZE;
|
336
361
|
|
337
362
|
return buffer;
|
338
|
-
|
339
|
-
#ifndef DISABLE_RMEM_REUSE_INTERNAL_FRAGMENT
|
340
363
|
} else {
|
341
364
|
/* reuse unused rmem */
|
342
365
|
*allocated_size = (size_t)(b->rmem_end - b->rmem_last);
|
@@ -350,13 +373,7 @@ static inline void* _msgpack_buffer_chunk_malloc(
|
|
350
373
|
|
351
374
|
return buffer;
|
352
375
|
}
|
353
|
-
#endif
|
354
|
-
}
|
355
|
-
#else
|
356
|
-
if(required_size < 72) {
|
357
|
-
required_size = 72;
|
358
376
|
}
|
359
|
-
#endif
|
360
377
|
|
361
378
|
// TODO alignment?
|
362
379
|
*allocated_size = required_size;
|
@@ -411,11 +428,7 @@ void _msgpack_buffer_expand(msgpack_buffer_t* b, const char* data, size_t length
|
|
411
428
|
size_t capacity = b->tail.last - b->tail.first;
|
412
429
|
|
413
430
|
/* can't realloc mapped chunk or rmem page */
|
414
|
-
if(b->tail.mapped_string != NO_MAPPED_STRING
|
415
|
-
#ifndef DISABLE_RMEM
|
416
|
-
|| capacity <= MSGPACK_RMEM_PAGE_SIZE
|
417
|
-
#endif
|
418
|
-
) {
|
431
|
+
if(b->tail.mapped_string != NO_MAPPED_STRING || capacity <= MSGPACK_RMEM_PAGE_SIZE) {
|
419
432
|
/* allocate new chunk */
|
420
433
|
_msgpack_buffer_add_new_chunk(b);
|
421
434
|
|
data/ext/msgpack/buffer.h
CHANGED
@@ -102,11 +102,9 @@ struct msgpack_buffer_t {
|
|
102
102
|
msgpack_buffer_chunk_t* head;
|
103
103
|
msgpack_buffer_chunk_t* free_list;
|
104
104
|
|
105
|
-
#ifndef DISABLE_RMEM
|
106
105
|
char* rmem_last;
|
107
106
|
char* rmem_end;
|
108
107
|
void** rmem_owner;
|
109
|
-
#endif
|
110
108
|
|
111
109
|
union msgpack_buffer_cast_block_t cast_block;
|
112
110
|
|
@@ -118,25 +116,25 @@ struct msgpack_buffer_t {
|
|
118
116
|
size_t write_reference_threshold;
|
119
117
|
size_t read_reference_threshold;
|
120
118
|
size_t io_buffer_size;
|
121
|
-
|
122
|
-
VALUE owner;
|
123
119
|
};
|
124
120
|
|
125
121
|
/*
|
126
122
|
* initialization functions
|
127
123
|
*/
|
128
|
-
void msgpack_buffer_static_init();
|
124
|
+
void msgpack_buffer_static_init(void);
|
129
125
|
|
130
|
-
void msgpack_buffer_static_destroy();
|
126
|
+
void msgpack_buffer_static_destroy(void);
|
131
127
|
|
132
128
|
void msgpack_buffer_init(msgpack_buffer_t* b);
|
133
129
|
|
134
130
|
void msgpack_buffer_destroy(msgpack_buffer_t* b);
|
135
131
|
|
136
|
-
void msgpack_buffer_mark(
|
132
|
+
void msgpack_buffer_mark(void* b);
|
137
133
|
|
138
134
|
void msgpack_buffer_clear(msgpack_buffer_t* b);
|
139
135
|
|
136
|
+
size_t msgpack_buffer_memsize(const msgpack_buffer_t* b);
|
137
|
+
|
140
138
|
static inline void msgpack_buffer_set_write_reference_threshold(msgpack_buffer_t* b, size_t length)
|
141
139
|
{
|
142
140
|
if(length < MSGPACK_BUFFER_STRING_WRITE_REFERENCE_MINIMUM) {
|
@@ -444,7 +442,6 @@ static inline VALUE _msgpack_buffer_refer_head_mapped_string(msgpack_buffer_t* b
|
|
444
442
|
|
445
443
|
static inline VALUE msgpack_buffer_read_top_as_string(msgpack_buffer_t* b, size_t length, bool will_be_frozen, bool utf8)
|
446
444
|
{
|
447
|
-
#ifndef DISABLE_BUFFER_READ_REFERENCE_OPTIMIZE
|
448
445
|
/* optimize */
|
449
446
|
if(!will_be_frozen &&
|
450
447
|
b->head->mapped_string != NO_MAPPED_STRING &&
|
@@ -454,7 +451,6 @@ static inline VALUE msgpack_buffer_read_top_as_string(msgpack_buffer_t* b, size_
|
|
454
451
|
_msgpack_buffer_consumed(b, length);
|
455
452
|
return result;
|
456
453
|
}
|
457
|
-
#endif
|
458
454
|
|
459
455
|
VALUE result;
|
460
456
|
|
data/ext/msgpack/buffer_class.c
CHANGED
@@ -28,19 +28,13 @@ static ID s_readpartial;
|
|
28
28
|
static ID s_write;
|
29
29
|
static ID s_append;
|
30
30
|
static ID s_close;
|
31
|
+
static ID s_at_owner;
|
31
32
|
|
32
33
|
static VALUE sym_read_reference_threshold;
|
33
34
|
static VALUE sym_write_reference_threshold;
|
34
35
|
static VALUE sym_io_buffer_size;
|
35
36
|
|
36
37
|
|
37
|
-
#define BUFFER(from, name) \
|
38
|
-
msgpack_buffer_t *name = NULL; \
|
39
|
-
Data_Get_Struct(from, msgpack_buffer_t, name); \
|
40
|
-
if(name == NULL) { \
|
41
|
-
rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
|
42
|
-
}
|
43
|
-
|
44
38
|
#define CHECK_STRING_TYPE(value) \
|
45
39
|
value = rb_check_string_type(value); \
|
46
40
|
if( NIL_P(value) ) { \
|
@@ -57,12 +51,49 @@ static void Buffer_free(void* data)
|
|
57
51
|
xfree(b);
|
58
52
|
}
|
59
53
|
|
54
|
+
static size_t Buffer_memsize(const void *data)
|
55
|
+
{
|
56
|
+
return sizeof(msgpack_buffer_t) + msgpack_buffer_memsize(data);
|
57
|
+
}
|
58
|
+
|
59
|
+
const rb_data_type_t buffer_data_type = {
|
60
|
+
.wrap_struct_name = "msgpack:buffer",
|
61
|
+
.function = {
|
62
|
+
.dmark = msgpack_buffer_mark,
|
63
|
+
.dfree = Buffer_free,
|
64
|
+
.dsize = Buffer_memsize,
|
65
|
+
},
|
66
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
67
|
+
};
|
68
|
+
|
69
|
+
const rb_data_type_t buffer_view_data_type = {
|
70
|
+
.wrap_struct_name = "msgpack:buffer_view",
|
71
|
+
.function = {
|
72
|
+
.dmark = msgpack_buffer_mark,
|
73
|
+
.dfree = NULL,
|
74
|
+
.dsize = NULL,
|
75
|
+
},
|
76
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
77
|
+
};
|
78
|
+
|
79
|
+
static inline msgpack_buffer_t *MessagePack_Buffer_get(VALUE object)
|
80
|
+
{
|
81
|
+
msgpack_buffer_t *buffer;
|
82
|
+
bool view = RTEST(rb_ivar_get(object, s_at_owner));
|
83
|
+
TypedData_Get_Struct(object, msgpack_buffer_t, view ? &buffer_view_data_type : &buffer_data_type, buffer);
|
84
|
+
if (!buffer) {
|
85
|
+
rb_raise(rb_eArgError, "Uninitialized Buffer object");
|
86
|
+
}
|
87
|
+
return buffer;
|
88
|
+
}
|
89
|
+
|
60
90
|
static VALUE Buffer_alloc(VALUE klass)
|
61
91
|
{
|
62
|
-
msgpack_buffer_t* b
|
92
|
+
msgpack_buffer_t* b;
|
93
|
+
VALUE buffer = TypedData_Make_Struct(klass, msgpack_buffer_t, &buffer_data_type, b);
|
94
|
+
rb_ivar_set(buffer, s_at_owner, Qnil);
|
63
95
|
msgpack_buffer_init(b);
|
64
|
-
|
65
|
-
return Data_Wrap_Struct(klass, msgpack_buffer_mark, Buffer_free, b);
|
96
|
+
return buffer;
|
66
97
|
}
|
67
98
|
|
68
99
|
static ID get_partial_read_method(VALUE io)
|
@@ -113,8 +144,9 @@ void MessagePack_Buffer_set_options(msgpack_buffer_t* b, VALUE io, VALUE options
|
|
113
144
|
|
114
145
|
VALUE MessagePack_Buffer_wrap(msgpack_buffer_t* b, VALUE owner)
|
115
146
|
{
|
116
|
-
|
117
|
-
|
147
|
+
VALUE buffer = TypedData_Wrap_Struct(cMessagePack_Buffer, &buffer_view_data_type, b);
|
148
|
+
rb_ivar_set(buffer, s_at_owner, owner);
|
149
|
+
return buffer;
|
118
150
|
}
|
119
151
|
|
120
152
|
static VALUE Buffer_initialize(int argc, VALUE* argv, VALUE self)
|
@@ -144,7 +176,7 @@ static VALUE Buffer_initialize(int argc, VALUE* argv, VALUE self)
|
|
144
176
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..1)", argc);
|
145
177
|
}
|
146
178
|
|
147
|
-
|
179
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
148
180
|
|
149
181
|
MessagePack_Buffer_set_options(b, io, options);
|
150
182
|
|
@@ -153,21 +185,21 @@ static VALUE Buffer_initialize(int argc, VALUE* argv, VALUE self)
|
|
153
185
|
|
154
186
|
static VALUE Buffer_clear(VALUE self)
|
155
187
|
{
|
156
|
-
|
188
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
157
189
|
msgpack_buffer_clear(b);
|
158
190
|
return Qnil;
|
159
191
|
}
|
160
192
|
|
161
193
|
static VALUE Buffer_size(VALUE self)
|
162
194
|
{
|
163
|
-
|
195
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
164
196
|
size_t size = msgpack_buffer_all_readable_size(b);
|
165
197
|
return SIZET2NUM(size);
|
166
198
|
}
|
167
199
|
|
168
200
|
static VALUE Buffer_empty_p(VALUE self)
|
169
201
|
{
|
170
|
-
|
202
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
171
203
|
if(msgpack_buffer_top_readable_size(b) == 0) {
|
172
204
|
return Qtrue;
|
173
205
|
} else {
|
@@ -177,7 +209,7 @@ static VALUE Buffer_empty_p(VALUE self)
|
|
177
209
|
|
178
210
|
static VALUE Buffer_write(VALUE self, VALUE string_or_buffer)
|
179
211
|
{
|
180
|
-
|
212
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
181
213
|
|
182
214
|
VALUE string = string_or_buffer; // TODO optimize if string_or_buffer is a Buffer
|
183
215
|
StringValue(string);
|
@@ -189,7 +221,7 @@ static VALUE Buffer_write(VALUE self, VALUE string_or_buffer)
|
|
189
221
|
|
190
222
|
static VALUE Buffer_append(VALUE self, VALUE string_or_buffer)
|
191
223
|
{
|
192
|
-
|
224
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
193
225
|
|
194
226
|
VALUE string = string_or_buffer; // TODO optimize if string_or_buffer is a Buffer
|
195
227
|
StringValue(string);
|
@@ -280,14 +312,13 @@ static inline size_t read_until_eof(msgpack_buffer_t* b, VALUE out, unsigned lon
|
|
280
312
|
|
281
313
|
static inline VALUE read_all(msgpack_buffer_t* b, VALUE out)
|
282
314
|
{
|
283
|
-
#ifndef DISABLE_BUFFER_READ_TO_S_OPTIMIZE
|
284
315
|
if(out == Qnil && !msgpack_buffer_has_io(b)) {
|
285
316
|
/* same as to_s && clear; optimize */
|
286
317
|
VALUE str = msgpack_buffer_all_as_string(b);
|
287
318
|
msgpack_buffer_clear(b);
|
288
319
|
return str;
|
289
320
|
}
|
290
|
-
|
321
|
+
|
291
322
|
MAKE_EMPTY_STRING(out);
|
292
323
|
read_until_eof(b, out, 0);
|
293
324
|
return out;
|
@@ -295,7 +326,7 @@ static inline VALUE read_all(msgpack_buffer_t* b, VALUE out)
|
|
295
326
|
|
296
327
|
static VALUE Buffer_skip(VALUE self, VALUE sn)
|
297
328
|
{
|
298
|
-
|
329
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
299
330
|
|
300
331
|
unsigned long n = FIX2ULONG(sn);
|
301
332
|
|
@@ -310,7 +341,7 @@ static VALUE Buffer_skip(VALUE self, VALUE sn)
|
|
310
341
|
|
311
342
|
static VALUE Buffer_skip_all(VALUE self, VALUE sn)
|
312
343
|
{
|
313
|
-
|
344
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
314
345
|
|
315
346
|
unsigned long n = FIX2ULONG(sn);
|
316
347
|
|
@@ -348,7 +379,7 @@ static VALUE Buffer_read_all(int argc, VALUE* argv, VALUE self)
|
|
348
379
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
349
380
|
}
|
350
381
|
|
351
|
-
|
382
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
352
383
|
|
353
384
|
if(out != Qnil) {
|
354
385
|
CHECK_STRING_TYPE(out);
|
@@ -394,7 +425,7 @@ static VALUE Buffer_read(int argc, VALUE* argv, VALUE self)
|
|
394
425
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
395
426
|
}
|
396
427
|
|
397
|
-
|
428
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
398
429
|
|
399
430
|
if(out != Qnil) {
|
400
431
|
CHECK_STRING_TYPE(out);
|
@@ -410,7 +441,6 @@ static VALUE Buffer_read(int argc, VALUE* argv, VALUE self)
|
|
410
441
|
return out;
|
411
442
|
}
|
412
443
|
|
413
|
-
#ifndef DISABLE_BUFFER_READ_TO_S_OPTIMIZE
|
414
444
|
if(!msgpack_buffer_has_io(b) && out == Qnil &&
|
415
445
|
msgpack_buffer_all_readable_size(b) <= n) {
|
416
446
|
/* same as to_s && clear; optimize */
|
@@ -423,7 +453,6 @@ static VALUE Buffer_read(int argc, VALUE* argv, VALUE self)
|
|
423
453
|
return str;
|
424
454
|
}
|
425
455
|
}
|
426
|
-
#endif
|
427
456
|
|
428
457
|
MAKE_EMPTY_STRING(out);
|
429
458
|
read_until_eof(b, out, n);
|
@@ -437,32 +466,32 @@ static VALUE Buffer_read(int argc, VALUE* argv, VALUE self)
|
|
437
466
|
|
438
467
|
static VALUE Buffer_to_str(VALUE self)
|
439
468
|
{
|
440
|
-
|
469
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
441
470
|
return msgpack_buffer_all_as_string(b);
|
442
471
|
}
|
443
472
|
|
444
473
|
static VALUE Buffer_to_a(VALUE self)
|
445
474
|
{
|
446
|
-
|
475
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
447
476
|
return msgpack_buffer_all_as_string_array(b);
|
448
477
|
}
|
449
478
|
|
450
479
|
static VALUE Buffer_flush(VALUE self)
|
451
480
|
{
|
452
|
-
|
481
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
453
482
|
msgpack_buffer_flush(b);
|
454
483
|
return self;
|
455
484
|
}
|
456
485
|
|
457
486
|
static VALUE Buffer_io(VALUE self)
|
458
487
|
{
|
459
|
-
|
488
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
460
489
|
return b->io;
|
461
490
|
}
|
462
491
|
|
463
492
|
static VALUE Buffer_close(VALUE self)
|
464
493
|
{
|
465
|
-
|
494
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
466
495
|
if(b->io != Qnil) {
|
467
496
|
return rb_funcall(b->io, s_close, 0);
|
468
497
|
}
|
@@ -471,7 +500,7 @@ static VALUE Buffer_close(VALUE self)
|
|
471
500
|
|
472
501
|
static VALUE Buffer_write_to(VALUE self, VALUE io)
|
473
502
|
{
|
474
|
-
|
503
|
+
msgpack_buffer_t *b = MessagePack_Buffer_get(self);
|
475
504
|
size_t sz = msgpack_buffer_flush_to_io(b, io, s_write, true);
|
476
505
|
return SIZET2NUM(sz);
|
477
506
|
}
|
@@ -483,6 +512,7 @@ void MessagePack_Buffer_module_init(VALUE mMessagePack)
|
|
483
512
|
s_write = rb_intern("write");
|
484
513
|
s_append = rb_intern("<<");
|
485
514
|
s_close = rb_intern("close");
|
515
|
+
s_at_owner = rb_intern("@owner");
|
486
516
|
|
487
517
|
sym_read_reference_threshold = ID2SYM(rb_intern("read_reference_threshold"));
|
488
518
|
sym_write_reference_threshold = ID2SYM(rb_intern("write_reference_threshold"));
|
data/ext/msgpack/extconf.rb
CHANGED
@@ -8,10 +8,6 @@ have_func("rb_hash_new_capa", "ruby.h") # Ruby 3.2+
|
|
8
8
|
unless RUBY_PLATFORM.include? 'mswin'
|
9
9
|
$CFLAGS << %[ -I.. -Wall -O3 #{RbConfig::CONFIG["debugflags"]} -std=gnu99]
|
10
10
|
end
|
11
|
-
#$CFLAGS << %[ -DDISABLE_RMEM]
|
12
|
-
#$CFLAGS << %[ -DDISABLE_RMEM_REUSE_INTERNAL_FRAGMENT]
|
13
|
-
#$CFLAGS << %[ -DDISABLE_BUFFER_READ_REFERENCE_OPTIMIZE]
|
14
|
-
#$CFLAGS << %[ -DDISABLE_BUFFER_READ_TO_S_OPTIMIZE]
|
15
11
|
|
16
12
|
if RUBY_VERSION.start_with?('3.0.')
|
17
13
|
# https://bugs.ruby-lang.org/issues/18772
|