msgpack 1.5.2 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7de0658b1f87162270c3cc2aac70ffff8d408d974faac6ff5ad009fa11dba4dd
4
- data.tar.gz: 9da35f2cc47ced45efd96b10ad8a3b491f0658b5ba247ad7b4aa22b901c66110
3
+ metadata.gz: e2f5a7cb55341aa8e930c92374b3aeb7bc74b1ccdfe0dede04e36169ce63354f
4
+ data.tar.gz: 42d92aff731b1a0ba35d775390c381bcff95fdb25ad8993248ca61753fb4b9e3
5
5
  SHA512:
6
- metadata.gz: b23c683b4c7fbbedd8dedc5d6eb8f5d6778aa3d3f7afef839cfe3227fc2edff713d9f17d6c8ce3808a6103325d7923ca6abfaf8792dba11485ed9d067fe6aa42
7
- data.tar.gz: ced82946481b00d99a69aea792efbeb93982d39836bc763c7c4a0f71844ca48044cff1f58c9695aa4ebb19d0be6a0b43f2e3b4af04ca06d7ad4bfc798cacd0b8
6
+ metadata.gz: 3cae7bc28afab9c63303d2aab6eb66e892fdacb0a5ba21113d7d4f8deac7647a18e2f2e708c66764671e78221a04b388c0bda93a3c8b2d2732c4b66d805408c5
7
+ data.tar.gz: d7fb26c1078340d7eed9d3589500c0fd4fcbb3aa995af82fbe632167494bd2400c9247f3d8c8b5091a3b0ad0e77a9f2624a154adc1781dbf611d6dc50f682afe
data/ChangeLog CHANGED
@@ -1,3 +1,17 @@
1
+ 2022-08-22 1.5.5:
2
+
3
+ * Fix a segfault when GC triggers inside a recursive extension.
4
+
5
+ 2022-07-25 1.5.4:
6
+
7
+ * Fix a segfault when deserializing empty symbol (`:""`).
8
+ * Improve compilation flags to not strip debug symbols.
9
+
10
+ 2022-05-30 version 1.5.3:
11
+
12
+ * Fix deduplication of empty strings when using the `freeze: true` option.
13
+ * Use `rb_hash_new_capa` when available (Ruby 3.2) for improved performance when parsing large hashes.
14
+
1
15
  2022-05-27 version 1.5.2:
2
16
 
3
17
  * Fix bug about unpacking ext type objects with the recursive option
data/README.md CHANGED
@@ -40,7 +40,7 @@ or build msgpack-ruby and install:
40
40
  MessagePack for Ruby should run on x86, ARM, PowerPC, SPARC and other CPU architectures.
41
41
 
42
42
  And it works with MRI (CRuby) and Rubinius.
43
- Patches to improve portability is highly welcomed.
43
+ Patches to improve portability are highly welcomed.
44
44
 
45
45
 
46
46
  ## Serializing objects
@@ -51,6 +51,7 @@ Use `MessagePack.pack` or `to_msgpack`:
51
51
  require 'msgpack'
52
52
  msg = MessagePack.pack(obj) # or
53
53
  msg = obj.to_msgpack
54
+ File.binwrite('mydata.msgpack', msg)
54
55
  ```
55
56
 
56
57
  ### Streaming serialization
@@ -71,6 +72,7 @@ Use `MessagePack.unpack`:
71
72
 
72
73
  ```ruby
73
74
  require 'msgpack'
75
+ msg = File.binread('mydata.msgpack')
74
76
  obj = MessagePack.unpack(msg)
75
77
  ```
76
78
 
data/bench/bench.rb ADDED
@@ -0,0 +1,78 @@
1
+ # % bundle install
2
+ # % bundle exec ruby bench/bench.rb
3
+
4
+ require 'msgpack'
5
+
6
+ require 'benchmark/ips'
7
+
8
+ object_plain = {
9
+ 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"'
10
+ }
11
+
12
+ data_plain = MessagePack.pack(object_plain)
13
+
14
+ object_structured = {
15
+ 'remote_host' => '127.0.0.1',
16
+ 'remote_user' => '-',
17
+ 'date' => '10/Oct/2000:13:55:36 -0700',
18
+ 'request' => 'GET /apache_pb.gif HTTP/1.0',
19
+ 'method' => 'GET',
20
+ 'path' => '/apache_pb.gif',
21
+ 'protocol' => 'HTTP/1.0',
22
+ 'status' => 200,
23
+ 'bytes' => 2326,
24
+ 'referer' => 'http://www.example.com/start.html',
25
+ 'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
26
+ }
27
+
28
+ data_structured = MessagePack.pack(object_structured)
29
+
30
+ class Extended
31
+ def to_msgpack_ext
32
+ MessagePack.pack({})
33
+ end
34
+
35
+ def self.from_msgpack_ext(data)
36
+ MessagePack.unpack(data)
37
+ Extended.new
38
+ end
39
+ end
40
+
41
+ object_extended = {
42
+ 'extended' => Extended.new
43
+ }
44
+
45
+ extended_packer = MessagePack::Packer.new
46
+ extended_packer.register_type(0x00, Extended, :to_msgpack_ext)
47
+ data_extended = extended_packer.pack(object_extended).to_s
48
+
49
+ Benchmark.ips do |x|
50
+ x.report('pack-plain') do
51
+ MessagePack.pack(object_plain)
52
+ end
53
+
54
+ x.report('pack-structured') do
55
+ MessagePack.pack(object_structured)
56
+ end
57
+
58
+ x.report('pack-extended') do
59
+ packer = MessagePack::Packer.new
60
+ packer.register_type(0x00, Extended, :to_msgpack_ext)
61
+ packer.pack(object_extended).to_s
62
+ end
63
+
64
+ x.report('unpack-plain') do
65
+ MessagePack.unpack(data_plain)
66
+ end
67
+
68
+ x.report('unpack-structured') do
69
+ MessagePack.unpack(data_structured)
70
+ end
71
+
72
+ x.report('unpack-extended') do
73
+ unpacker = MessagePack::Unpacker.new
74
+ unpacker.register_type(0x00, Extended, :from_msgpack_ext)
75
+ unpacker.feed data_extended
76
+ unpacker.read
77
+ end
78
+ end
data/ext/msgpack/buffer.c CHANGED
@@ -300,30 +300,6 @@ static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b)
300
300
  }
301
301
  }
302
302
 
303
- static inline void _msgpack_buffer_append_reference(msgpack_buffer_t* b, VALUE string)
304
- {
305
- VALUE mapped_string = rb_str_dup(string);
306
- ENCODING_SET(mapped_string, msgpack_rb_encindex_ascii8bit);
307
-
308
- _msgpack_buffer_add_new_chunk(b);
309
-
310
- char* data = RSTRING_PTR(mapped_string);
311
- size_t length = RSTRING_LEN(mapped_string);
312
-
313
- b->tail.first = (char*) data;
314
- b->tail.last = (char*) data + length;
315
- b->tail.mapped_string = mapped_string;
316
- b->tail.mem = NULL;
317
-
318
- /* msgpack_buffer_writable_size should return 0 for mapped chunk */
319
- b->tail_buffer_end = b->tail.last;
320
-
321
- /* consider read_buffer */
322
- if(b->head == &b->tail) {
323
- b->read_buffer = b->tail.first;
324
- }
325
- }
326
-
327
303
  void _msgpack_buffer_append_long_string(msgpack_buffer_t* b, VALUE string)
328
304
  {
329
305
  size_t length = RSTRING_LEN(string);
@@ -332,16 +308,9 @@ void _msgpack_buffer_append_long_string(msgpack_buffer_t* b, VALUE string)
332
308
  msgpack_buffer_flush(b);
333
309
  if (ENCODING_GET(string) == msgpack_rb_encindex_ascii8bit) {
334
310
  rb_funcall(b->io, b->io_write_all_method, 1, string);
335
- } else if(!STR_DUP_LIKELY_DOES_COPY(string)) {
336
- VALUE s = rb_str_dup(string);
337
- ENCODING_SET(s, msgpack_rb_encindex_ascii8bit);
338
- rb_funcall(b->io, b->io_write_all_method, 1, s);
339
311
  } else {
340
312
  msgpack_buffer_append(b, RSTRING_PTR(string), length);
341
313
  }
342
- } else if(!STR_DUP_LIKELY_DOES_COPY(string)) {
343
- _msgpack_buffer_append_reference(b, string);
344
-
345
314
  } else {
346
315
  msgpack_buffer_append(b, RSTRING_PTR(string), length);
347
316
  }
@@ -619,13 +588,13 @@ size_t msgpack_buffer_flush_to_io(msgpack_buffer_t* b, VALUE io, ID write_method
619
588
  size_t _msgpack_buffer_feed_from_io(msgpack_buffer_t* b)
620
589
  {
621
590
  if(b->io_buffer == Qnil) {
622
- b->io_buffer = rb_funcall(b->io, b->io_partial_read_method, 1, LONG2NUM(b->io_buffer_size));
591
+ b->io_buffer = rb_funcall(b->io, b->io_partial_read_method, 1, SIZET2NUM(b->io_buffer_size));
623
592
  if(b->io_buffer == Qnil) {
624
593
  rb_raise(rb_eEOFError, "IO reached end of file");
625
594
  }
626
595
  StringValue(b->io_buffer);
627
596
  } else {
628
- VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, LONG2NUM(b->io_buffer_size), b->io_buffer);
597
+ VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, SIZET2NUM(b->io_buffer_size), b->io_buffer);
629
598
  if(ret == Qnil) {
630
599
  rb_raise(rb_eEOFError, "IO reached end of file");
631
600
  }
@@ -644,9 +613,11 @@ size_t _msgpack_buffer_feed_from_io(msgpack_buffer_t* b)
644
613
 
645
614
  size_t _msgpack_buffer_read_from_io_to_string(msgpack_buffer_t* b, VALUE string, size_t length)
646
615
  {
616
+ #define MIN(x, y) (((x) < (y)) ? (x) : (y))
617
+
647
618
  if(RSTRING_LEN(string) == 0) {
648
619
  /* direct read */
649
- VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, LONG2NUM(length), string);
620
+ VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, SIZET2NUM(MIN(b->io_buffer_size, length)), string);
650
621
  if(ret == Qnil) {
651
622
  return 0;
652
623
  }
@@ -658,7 +629,7 @@ size_t _msgpack_buffer_read_from_io_to_string(msgpack_buffer_t* b, VALUE string,
658
629
  b->io_buffer = rb_str_buf_new(0);
659
630
  }
660
631
 
661
- VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, LONG2NUM(length), b->io_buffer);
632
+ VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, SIZET2NUM(MIN(b->io_buffer_size, length)), b->io_buffer);
662
633
  if(ret == Qnil) {
663
634
  return 0;
664
635
  }
@@ -666,6 +637,8 @@ size_t _msgpack_buffer_read_from_io_to_string(msgpack_buffer_t* b, VALUE string,
666
637
 
667
638
  rb_str_buf_cat(string, (const void*)RSTRING_PTR(b->io_buffer), rl);
668
639
  return rl;
640
+
641
+ #undef MIN
669
642
  }
670
643
 
671
644
  size_t _msgpack_buffer_skip_from_io(msgpack_buffer_t* b, size_t length)
@@ -674,7 +647,7 @@ size_t _msgpack_buffer_skip_from_io(msgpack_buffer_t* b, size_t length)
674
647
  b->io_buffer = rb_str_buf_new(0);
675
648
  }
676
649
 
677
- VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, LONG2NUM(length), b->io_buffer);
650
+ VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, SIZET2NUM(length), b->io_buffer);
678
651
  if(ret == Qnil) {
679
652
  return 0;
680
653
  }
data/ext/msgpack/buffer.h CHANGED
@@ -49,6 +49,10 @@
49
49
 
50
50
  #define NO_MAPPED_STRING ((VALUE)0)
51
51
 
52
+ #ifndef RB_ENC_INTERNED_STR_NULL_CHECK
53
+ #define RB_ENC_INTERNED_STR_NULL_CHECK 0
54
+ #endif
55
+
52
56
  extern int msgpack_rb_encindex_utf8;
53
57
  extern int msgpack_rb_encindex_usascii;
54
58
  extern int msgpack_rb_encindex_ascii8bit;
@@ -456,7 +460,11 @@ static inline VALUE msgpack_buffer_read_top_as_string(msgpack_buffer_t* b, size_
456
460
 
457
461
  #ifdef HAVE_RB_ENC_INTERNED_STR
458
462
  if (will_be_frozen) {
459
- result = rb_enc_interned_str(b->read_buffer, length, utf8 ? rb_utf8_encoding() : rb_ascii8bit_encoding());
463
+ if (RB_ENC_INTERNED_STR_NULL_CHECK && length == 0) {
464
+ result = rb_enc_interned_str("", length, utf8 ? rb_utf8_encoding() : rb_ascii8bit_encoding());
465
+ } else {
466
+ result = rb_enc_interned_str(b->read_buffer, length, utf8 ? rb_utf8_encoding() : rb_ascii8bit_encoding());
467
+ }
460
468
  } else {
461
469
  if (utf8) {
462
470
  result = rb_utf8_str_new(b->read_buffer, length);
@@ -96,17 +96,17 @@ void MessagePack_Buffer_set_options(msgpack_buffer_t* b, VALUE io, VALUE options
96
96
 
97
97
  v = rb_hash_aref(options, sym_read_reference_threshold);
98
98
  if(v != Qnil) {
99
- msgpack_buffer_set_read_reference_threshold(b, NUM2ULONG(v));
99
+ msgpack_buffer_set_read_reference_threshold(b, NUM2SIZET(v));
100
100
  }
101
101
 
102
102
  v = rb_hash_aref(options, sym_write_reference_threshold);
103
103
  if(v != Qnil) {
104
- msgpack_buffer_set_write_reference_threshold(b, NUM2ULONG(v));
104
+ msgpack_buffer_set_write_reference_threshold(b, NUM2SIZET(v));
105
105
  }
106
106
 
107
107
  v = rb_hash_aref(options, sym_io_buffer_size);
108
108
  if(v != Qnil) {
109
- msgpack_buffer_set_io_buffer_size(b, NUM2ULONG(v));
109
+ msgpack_buffer_set_io_buffer_size(b, NUM2SIZET(v));
110
110
  }
111
111
  }
112
112
  }
@@ -301,11 +301,11 @@ static VALUE Buffer_skip(VALUE self, VALUE sn)
301
301
 
302
302
  /* do nothing */
303
303
  if(n == 0) {
304
- return ULONG2NUM(0);
304
+ return INT2NUM(0);
305
305
  }
306
306
 
307
307
  size_t sz = read_until_eof(b, Qnil, n);
308
- return ULONG2NUM(sz);
308
+ return SIZET2NUM(sz);
309
309
  }
310
310
 
311
311
  static VALUE Buffer_skip_all(VALUE self, VALUE sn)
@@ -473,7 +473,7 @@ static VALUE Buffer_write_to(VALUE self, VALUE io)
473
473
  {
474
474
  BUFFER(self, b);
475
475
  size_t sz = msgpack_buffer_flush_to_io(b, io, s_write, true);
476
- return ULONG2NUM(sz);
476
+ return SIZET2NUM(sz);
477
477
  }
478
478
 
479
479
  void MessagePack_Buffer_module_init(VALUE mMessagePack)
data/ext/msgpack/compat.h CHANGED
@@ -22,104 +22,5 @@
22
22
  #include "ruby.h"
23
23
  #include "ruby/encoding.h"
24
24
 
25
- #if defined(HAVE_RUBY_ST_H)
26
- # include "ruby/st.h" /* ruby hash on Ruby 1.9 */
27
- #elif defined(HAVE_ST_H)
28
- # include "st.h" /* ruby hash on Ruby 1.8 */
29
- #endif
30
-
31
-
32
- /*
33
- * ZALLOC_N (ruby 2.2 or later)
34
- */
35
- #ifndef RB_ZALLOC_N
36
- # define RB_ZALLOC_N(type,n) ((type*)ruby_xcalloc((size_t)(n),sizeof(type)))
37
- #endif
38
- #ifndef ZALLOC_N
39
- # define ZALLOC_N(type,n) RB_ZALLOC_N(type,n)
40
- #endif
41
-
42
-
43
- /*
44
- * define STR_DUP_LIKELY_DOES_COPY
45
- * check rb_str_dup actually copies the string or not
46
- */
47
- #if defined(RUBY_VM) && defined(FL_ALL) && defined(FL_USER1) && defined(FL_USER3) /* MRI 1.9 */
48
- # define STR_DUP_LIKELY_DOES_COPY(str) FL_ALL(str, FL_USER1|FL_USER3) /* same as STR_ASSOC_P(str) */
49
-
50
- #elif defined(FL_TEST) && defined(ELTS_SHARED) /* MRI 1.8 */
51
- # define STR_DUP_LIKELY_DOES_COPY(str) (!FL_TEST(str, ELTS_SHARED))
52
-
53
- //#elif defined(RUBINIUS) || defined(JRUBY) /* Rubinius and JRuby */
54
- #else
55
- # define STR_DUP_LIKELY_DOES_COPY(str) (1)
56
-
57
- #endif
58
-
59
-
60
- /*
61
- * SIZET2NUM
62
- */
63
- #ifndef SIZET2NUM /* MRI 1.8 */
64
- # define SIZET2NUM(v) ULL2NUM(v)
65
- #endif
66
-
67
-
68
- /*
69
- * rb_errinfo()
70
- */
71
- #if defined(RUBY_VM) /* MRI 1.9 */
72
- # define COMPAT_RERAISE rb_exc_raise(rb_errinfo())
73
-
74
- #elif defined(JRUBY) /* JRuby */
75
- # define COMPAT_RERAISE rb_exc_raise(rb_gv_get("$!"))
76
-
77
- #else /* MRI 1.8 and Rubinius */
78
- # define COMPAT_RERAISE rb_exc_raise(ruby_errinfo)
79
- #endif
80
-
81
-
82
- /*
83
- * RBIGNUM_POSITIVE_P
84
- */
85
- #ifndef RBIGNUM_POSITIVE_P
86
- # if defined(RUBINIUS) /* Rubinius <= v1.2.3 */
87
- # define RBIGNUM_POSITIVE_P(b) (rb_funcall(b, rb_intern(">="), 1, INT2FIX(0)) == Qtrue)
88
-
89
- # elif defined(JRUBY) /* JRuby */
90
- # define RBIGNUM_POSITIVE_P(b) (rb_funcall(b, rb_intern(">="), 1, INT2FIX(0)) == Qtrue)
91
- # define rb_big2ull(b) rb_num2ull(b)
92
- /*#define rb_big2ll(b) rb_num2ll(b)*/
93
-
94
- # else /* MRI 1.8 */
95
- # define RBIGNUM_POSITIVE_P(b) (RBIGNUM(b)->sign)
96
- # endif
97
- #endif
98
-
99
-
100
- /*
101
- * RSTRING_PTR, RSTRING_LEN
102
- */
103
- #ifndef RSTRING_PTR /* MRI 1.8.5 */
104
- # define RSTRING_PTR(s) (RSTRING(s)->ptr)
105
- #endif
106
-
107
- #ifndef RSTRING_LEN /* MRI 1.8.5 */
108
- # define RSTRING_LEN(s) (RSTRING(s)->len)
109
- #endif
110
-
111
-
112
- /*
113
- * RSTRUCT_GET
114
- */
115
- #ifndef RSTRUCT_GET
116
- # ifdef RSTRUCT_PTR /* MRI <= 2.0.0 */
117
- # define RSTRUCT_GET(st, idx) (RSTRUCT_PTR(st)[idx])
118
- # else /* Rubinius */
119
- # define RSTRUCT_GET(st, idx) (rb_struct_aref(st, INT2FIX(idx)))
120
- # endif
121
- #endif
122
-
123
-
124
25
  #endif
125
26
 
@@ -2,24 +2,23 @@ require 'mkmf'
2
2
 
3
3
  have_header("ruby/st.h")
4
4
  have_header("st.h")
5
- have_func("rb_enc_interned_str", "ruby.h")
5
+ have_func("rb_enc_interned_str", "ruby.h") # Ruby 3.0+
6
+ have_func("rb_hash_new_capa", "ruby.h") # Ruby 3.2+
6
7
 
7
8
  unless RUBY_PLATFORM.include? 'mswin'
8
- $CFLAGS << %[ -I.. -Wall -O3 -g -std=gnu99]
9
+ $CFLAGS << %[ -I.. -Wall -O3 #{RbConfig::CONFIG["debugflags"]} -std=gnu99]
9
10
  end
10
11
  #$CFLAGS << %[ -DDISABLE_RMEM]
11
12
  #$CFLAGS << %[ -DDISABLE_RMEM_REUSE_INTERNAL_FRAGMENT]
12
13
  #$CFLAGS << %[ -DDISABLE_BUFFER_READ_REFERENCE_OPTIMIZE]
13
14
  #$CFLAGS << %[ -DDISABLE_BUFFER_READ_TO_S_OPTIMIZE]
14
15
 
15
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
16
- # msgpack-ruby doesn't modify data came from RSTRING_PTR(str)
17
- $CFLAGS << %[ -DRSTRING_NOT_MODIFIED]
18
- # Rubinius C extensions don't grab GVL while rmem is not thread safe
19
- $CFLAGS << %[ -DDISABLE_RMEM]
16
+ if RUBY_VERSION.start_with?('3.0.')
17
+ # https://bugs.ruby-lang.org/issues/18772
18
+ $CFLAGS << ' -DRB_ENC_INTERNED_STR_NULL_CHECK=1 '
20
19
  end
21
20
 
22
- # checking if Hash#[]= (rb_hash_aset) dedupes string keys
21
+ # checking if Hash#[]= (rb_hash_aset) dedupes string keys (Ruby 2.6+)
23
22
  h = {}
24
23
  x = {}
25
24
  r = rand.to_s
@@ -32,7 +31,7 @@ else
32
31
  end
33
32
 
34
33
 
35
- # checking if String#-@ (str_uminus) dedupes... '
34
+ # checking if String#-@ (str_uminus) dedupes... ' (Ruby 2.5+)
36
35
  begin
37
36
  a = -(%w(t e s t).join)
38
37
  b = -(%w(t e s t).join)
@@ -45,7 +44,7 @@ rescue NoMethodError
45
44
  $CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
46
45
  end
47
46
 
48
- # checking if String#-@ (str_uminus) directly interns frozen strings... '
47
+ # checking if String#-@ (str_uminus) directly interns frozen strings... ' (Ruby 3.0+)
49
48
  begin
50
49
  s = rand.to_s.freeze
51
50
  if (-s).equal?(s) && (-s.dup).equal?(s)
@@ -62,4 +61,3 @@ if warnflags = CONFIG['warnflags']
62
61
  end
63
62
 
64
63
  create_makefile('msgpack/msgpack')
65
-
data/ext/msgpack/packer.c CHANGED
@@ -18,24 +18,10 @@
18
18
 
19
19
  #include "packer.h"
20
20
 
21
- #ifdef RUBINIUS
22
- static ID s_to_iter;
23
- static ID s_next;
24
- static ID s_key;
25
- static ID s_value;
26
- #endif
27
-
28
21
  static ID s_call;
29
22
 
30
23
  void msgpack_packer_static_init()
31
24
  {
32
- #ifdef RUBINIUS
33
- s_to_iter = rb_intern("to_iter");
34
- s_next = rb_intern("next");
35
- s_key = rb_intern("key");
36
- s_value = rb_intern("value");
37
- #endif
38
-
39
25
  s_call = rb_intern("call");
40
26
  }
41
27
 
@@ -108,17 +94,7 @@ void msgpack_packer_write_hash_value(msgpack_packer_t* pk, VALUE v)
108
94
  unsigned int len32 = (unsigned int)len;
109
95
  msgpack_packer_write_map_header(pk, len32);
110
96
 
111
- #ifdef RUBINIUS
112
- VALUE iter = rb_funcall(v, s_to_iter, 0);
113
- VALUE entry = Qnil;
114
- while(RTEST(entry = rb_funcall(iter, s_next, 1, entry))) {
115
- VALUE key = rb_funcall(entry, s_key, 0);
116
- VALUE val = rb_funcall(entry, s_value, 0);
117
- write_hash_foreach(key, val, (VALUE) pk);
118
- }
119
- #else
120
97
  rb_hash_foreach(v, write_hash_foreach, (VALUE) pk);
121
- #endif
122
98
  }
123
99
 
124
100
  struct msgpack_call_proc_args_t;
data/ext/msgpack/packer.h CHANGED
@@ -408,13 +408,7 @@ static inline bool msgpack_packer_is_utf8_compat_string(VALUE v, int encindex)
408
408
  {
409
409
  return encindex == msgpack_rb_encindex_utf8
410
410
  || encindex == msgpack_rb_encindex_usascii
411
- #ifdef ENC_CODERANGE_ASCIIONLY
412
- /* Because ENC_CODERANGE_ASCIIONLY does not scan string, it may return ENC_CODERANGE_UNKNOWN unlike */
413
- /* rb_enc_str_asciionly_p. It is always faster than rb_str_encode if it is available. */
414
- /* Very old Rubinius (< v1.3.1) doesn't have ENC_CODERANGE_ASCIIONLY. */
415
- || (rb_enc_asciicompat(rb_enc_from_index(encindex)) && ENC_CODERANGE_ASCIIONLY(v))
416
- #endif
417
- ;
411
+ || (rb_enc_asciicompat(rb_enc_from_index(encindex)) && ENC_CODERANGE_ASCIIONLY(v));
418
412
  }
419
413
 
420
414
  static inline void msgpack_packer_write_string_value(msgpack_packer_t* pk, VALUE v)
@@ -322,7 +322,7 @@ static VALUE Packer_write_to(VALUE self, VALUE io)
322
322
  {
323
323
  PACKER(self, pk);
324
324
  size_t sz = msgpack_buffer_flush_to_io(PACKER_BUFFER_(pk), io, s_write, true);
325
- return ULONG2NUM(sz);
325
+ return SIZET2NUM(sz);
326
326
  }
327
327
 
328
328
  //static VALUE Packer_append(VALUE self, VALUE string_or_buffer)