ruby-changes:42281
From: naruse <ko1@a...>
Date: Tue, 29 Mar 2016 14:16:52 +0900 (JST)
Subject: [ruby-changes:42281] naruse:r54355 (ruby_2_3): merge revision(s) 53557, 53561: [Backport #11958]
naruse 2016-03-29 14:16:47 +0900 (Tue, 29 Mar 2016) New Revision: 54355 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54355 Log: merge revision(s) 53557,53561: [Backport #11958] * ext/socket/option.c (check_size): extract a macro to check binary data size, with a consistent message. * ext/socket/option.c (sockopt_byte): fix error message, sizeof(int) differs from sizeof(unsigned char) in general. * ext/socket/option.c (sockopt_bool): relax boolean size to be one too not only sizeof(int). Winsock getsockopt() returns a single byte as a boolean socket option. [ruby-core:72730] [Bug #11958] Modified directories: branches/ruby_2_3/ Modified files: branches/ruby_2_3/ChangeLog branches/ruby_2_3/ext/socket/option.c branches/ruby_2_3/test/socket/test_sockopt.rb branches/ruby_2_3/version.h Index: ruby_2_3/ext/socket/option.c =================================================================== --- ruby_2_3/ext/socket/option.c (revision 54354) +++ ruby_2_3/ext/socket/option.c (revision 54355) @@ -27,6 +27,12 @@ VALUE rb_cSockOpt; https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ext/socket/option.c#L27 # define USE_INSPECT_BYTE 1 #endif +#define check_size(len, size) \ + ((len) == (size) ? \ + (void)0 : \ + rb_raise(rb_eTypeError, "size differ. expected as "#size"=%d but %ld", \ + (int)size, (long)(len))) + static VALUE sockopt_pack_byte(VALUE value) { @@ -211,12 +217,9 @@ sockopt_s_byte(VALUE klass, VALUE vfamil https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ext/socket/option.c#L217 static VALUE sockopt_byte(VALUE self) { - unsigned char i; VALUE data = sockopt_data(self); StringValue(data); - if (RSTRING_LEN(data) != sizeof(i)) - rb_raise(rb_eTypeError, "size differ. expected as sizeof(int)=%d but %ld", - (int)sizeof(i), (long)RSTRING_LEN(data)); + check_size(RSTRING_LEN(data), sizeof(char)); return CHR2FIX(*RSTRING_PTR(data)); } @@ -257,9 +260,7 @@ sockopt_int(VALUE self) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ext/socket/option.c#L260 int i; VALUE data = sockopt_data(self); StringValue(data); - if (RSTRING_LEN(data) != sizeof(int)) - rb_raise(rb_eTypeError, "size differ. expected as sizeof(int)=%d but %ld", - (int)sizeof(int), (long)RSTRING_LEN(data)); + check_size(RSTRING_LEN(data), sizeof(int)); memcpy((char*)&i, RSTRING_PTR(data), sizeof(int)); return INT2NUM(i); } @@ -301,12 +302,15 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ext/socket/option.c#L302 sockopt_bool(VALUE self) { int i; + long len; VALUE data = sockopt_data(self); StringValue(data); - if (RSTRING_LEN(data) != sizeof(int)) - rb_raise(rb_eTypeError, "size differ. expected as sizeof(int)=%d but %ld", - (int)sizeof(int), (long)RSTRING_LEN(data)); - memcpy((char*)&i, RSTRING_PTR(data), sizeof(int)); + len = RSTRING_LEN(data); + if (len == 1) { + return *RSTRING_PTR(data) == 0 ? Qfalse : Qtrue; + } + check_size(len, sizeof(int)); + memcpy((char*)&i, RSTRING_PTR(data), len); return i == 0 ? Qfalse : Qtrue; } @@ -358,9 +362,7 @@ sockopt_linger(VALUE self) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ext/socket/option.c#L362 if (level != SOL_SOCKET || optname != SO_LINGER) rb_raise(rb_eTypeError, "linger socket option expected"); - if (RSTRING_LEN(data) != sizeof(l)) - rb_raise(rb_eTypeError, "size differ. expected as sizeof(struct linger)=%d but %ld", - (int)sizeof(struct linger), (long)RSTRING_LEN(data)); + check_size(RSTRING_LEN(data), sizeof(struct linger)); memcpy((char*)&l, RSTRING_PTR(data), sizeof(struct linger)); switch (l.l_onoff) { case 0: vonoff = Qfalse; break; Index: ruby_2_3/version.h =================================================================== --- ruby_2_3/version.h (revision 54354) +++ ruby_2_3/version.h (revision 54355) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1 #define RUBY_VERSION "2.3.0" #define RUBY_RELEASE_DATE "2016-03-29" -#define RUBY_PATCHLEVEL 13 +#define RUBY_PATCHLEVEL 14 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 3 Index: ruby_2_3/test/socket/test_sockopt.rb =================================================================== --- ruby_2_3/test/socket/test_sockopt.rb (revision 54354) +++ ruby_2_3/test/socket/test_sockopt.rb (revision 54355) @@ -25,6 +25,12 @@ class TestSocketOption < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/socket/test_sockopt.rb#L25 assert_equal(true, opt.bool) opt = Socket::Option.int(:INET, :SOCKET, :KEEPALIVE, 2) assert_equal(true, opt.bool) + Socket.open(:INET, :STREAM) {|s| + s.setsockopt(Socket::Option.bool(:INET, :SOCKET, :KEEPALIVE, true)) + assert_equal(true, s.getsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE).bool) + s.setsockopt(Socket::Option.bool(:INET, :SOCKET, :KEEPALIVE, false)) + assert_equal(false, s.getsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE).bool) + } end def test_ipv4_multicast_loop Index: ruby_2_3/ChangeLog =================================================================== --- ruby_2_3/ChangeLog (revision 54354) +++ ruby_2_3/ChangeLog (revision 54355) @@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1 +Tue Mar 29 14:12:22 2016 Nobuyoshi Nakada <nobu@r...> + + * ext/socket/option.c (sockopt_bool): relax boolean size to be one + too not only sizeof(int). Winsock getsockopt() returns a single + byte as a boolean socket option. [ruby-core:72730] [Bug #11958] + +Tue Mar 29 14:12:22 2016 Nobuyoshi Nakada <nobu@r...> + + * ext/socket/option.c (check_size): extract a macro to check + binary data size, with a consistent message. + + * ext/socket/option.c (sockopt_byte): fix error message, + sizeof(int) differs from sizeof(unsigned char) in general. + Tue Mar 29 14:01:14 2016 NAKAMURA Usaku <usa@r...> * process.c (rb_execarg_parent_start1): need to convert the encoding to Property changes on: ruby_2_3 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r53557,53561 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/