ruby-changes:25092
From: naruse <ko1@a...>
Date: Fri, 12 Oct 2012 00:35:41 +0900 (JST)
Subject: [ruby-changes:25092] naruse:r37144 (ruby_1_9_3): merge revision(s) 33819,33839:
naruse 2012-10-12 00:34:34 +0900 (Fri, 12 Oct 2012) New Revision: 37144 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37144 Log: merge revision(s) 33819,33839: * io.c (ioctl_narg_len): don't use _IOC_SIZE macro on Linux. On Linux some constants for ioctl(2) doesn't include the size of its return value and 16bit value; for example FIONREAD 0x541B. Moreover the manual, ioctl_list(2), says "Note that the size bits are very unreliable: in lots of cases they are wrong, either because of buggy macros using sizeof(sizeof(struct)), or because of legacy values." So we shouldn't use it. * io.c (ioctl_narg_len, linux_iocparm_len): reinstantiate linux specific narg length calculation. * test/ruby/test_io.rb (test_ioctl_linux2): add new test for old and unstructured ioctl. Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/io.c branches/ruby_1_9_3/test/ruby/test_io.rb branches/ruby_1_9_3/version.h Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 37143) +++ ruby_1_9_3/ChangeLog (revision 37144) @@ -1,3 +1,21 @@ +Fri Oct 12 00:30:17 2012 KOSAKI Motohiro <kosaki.motohiro@g...> + + * io.c (ioctl_narg_len, linux_iocparm_len): reinstantiate linux + specific narg length calculation. + * test/ruby/test_io.rb (test_ioctl_linux2): add new test for old and + unstructured ioctl. + +Fri Oct 12 00:30:17 2012 NARUSE, Yui <naruse@r...> + + * io.c (ioctl_narg_len): don't use _IOC_SIZE macro on Linux. + On Linux some constants for ioctl(2) doesn't include the size of + its return value and 16bit value; for example FIONREAD 0x541B. + Moreover the manual, ioctl_list(2), says "Note that the size + bits are very unreliable: in lots of cases they are wrong, + either because of buggy macros using sizeof(sizeof(struct)), + or because of legacy values." + So we shouldn't use it. + Tue Sep 25 09:30:36 2012 NAKAMURA Usaku <usa@r...> * win32/mkexports.rb: should not export DllMain(). Index: ruby_1_9_3/io.c =================================================================== --- ruby_1_9_3/io.c (revision 37143) +++ ruby_1_9_3/io.c (revision 37144) @@ -8019,7 +8019,30 @@ return retval; } +#define DEFULT_IOCTL_NARG_LEN (256) + +#ifdef __linux__ static long +linux_iocparm_len(ioctl_req_t cmd) +{ + long len; + + if ((cmd & 0xFFFF0000) == 0) { + /* legacy and unstructured ioctl number. */ + return DEFULT_IOCTL_NARG_LEN; + } + + len = _IOC_SIZE(cmd); + + /* paranoia check for silly drivers which don't keep ioctl convention */ + if (len < DEFULT_IOCTL_NARG_LEN) + len = DEFULT_IOCTL_NARG_LEN; + + return len; +} +#endif + +static long ioctl_narg_len(ioctl_req_t cmd) { long len; @@ -8031,10 +8054,11 @@ #endif #ifdef IOCPARM_LEN len = IOCPARM_LEN(cmd); /* on BSDish systems we're safe */ -#elif defined(_IOC_SIZE) - len = _IOC_SIZE(cmd); +#elif defined(__linux__) + len = linux_iocparm_len(cmd); #else - len = 256; /* otherwise guess at what's safe */ + /* otherwise guess at what's safe */ + len = DEFULT_IOCTL_NARG_LEN; #endif return len; Index: ruby_1_9_3/version.h =================================================================== --- ruby_1_9_3/version.h (revision 37143) +++ ruby_1_9_3/version.h (revision 37144) @@ -1,10 +1,10 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 277 +#define RUBY_PATCHLEVEL 278 -#define RUBY_RELEASE_DATE "2012-10-11" +#define RUBY_RELEASE_DATE "2012-10-12" #define RUBY_RELEASE_YEAR 2012 #define RUBY_RELEASE_MONTH 10 -#define RUBY_RELEASE_DAY 11 +#define RUBY_RELEASE_DAY 12 #include "ruby/version.h" Index: ruby_1_9_3/test/ruby/test_io.rb =================================================================== --- ruby_1_9_3/test/ruby/test_io.rb (revision 37143) +++ ruby_1_9_3/test/ruby/test_io.rb (revision 37144) @@ -2042,4 +2042,124 @@ write_file.close file.close! end + + def test_warn + stderr = EnvUtil.verbose_warning do + warn "warning" + end + assert_equal("warning\n", stderr) + + stderr = EnvUtil.verbose_warning do + warn + end + assert_equal("", stderr) + + stderr = EnvUtil.verbose_warning do + warn "[Feature #5029]", "[ruby-core:38070]" + end + assert_equal("[Feature #5029]\n[ruby-core:38070]\n", stderr) + end + + def test_cloexec + return unless defined? Fcntl::FD_CLOEXEC + open(__FILE__) {|f| + assert(f.close_on_exec?) + g = f.dup + begin + assert(g.close_on_exec?) + f.reopen(g) + assert(f.close_on_exec?) + ensure + g.close + end + g = IO.new(f.fcntl(Fcntl::F_DUPFD)) + begin + assert(g.close_on_exec?) + ensure + g.close + end + } + IO.pipe {|r,w| + assert(r.close_on_exec?) + assert(w.close_on_exec?) + } + end + + def test_ioctl_linux + return if /linux/ !~ RUBY_PLATFORM + + assert_nothing_raised do + File.open('/dev/urandom'){|f1| + entropy_count = "" + # get entropy count + f1.ioctl(0x80045200, entropy_count) + } + end + + buf = '' + assert_nothing_raised do + fionread = 0x541B + File.open(__FILE__){|f1| + f1.ioctl(fionread, buf) + } + end + assert_equal(File.size(__FILE__), buf.unpack('i!')[0]) + end + + def test_ioctl_linux2 + return if /linux/ !~ RUBY_PLATFORM + return if /^i?86|^x86_64/ !~ RUBY_PLATFORM + + File.open('/dev/tty') { |f| + tiocgwinsz=0x5413 + winsize="" + assert_nothing_raised { + f.ioctl(tiocgwinsz, winsize) + } + } + end + + def test_setpos + mkcdtmpdir { + File.open("tmp.txt", "w") {|f| + f.puts "a" + f.puts "bc" + f.puts "def" + } + pos1 = pos2 = pos3 = nil + File.open("tmp.txt") {|f| + assert_equal("a\n", f.gets) + pos1 = f.pos + assert_equal("bc\n", f.gets) + pos2 = f.pos + assert_equal("def\n", f.gets) + pos3 = f.pos + assert_equal(nil, f.gets) + } + File.open("tmp.txt") {|f| + f.pos = pos1 + assert_equal("bc\n", f.gets) + assert_equal("def\n", f.gets) + assert_equal(nil, f.gets) + } + File.open("tmp.txt") {|f| + f.pos = pos2 + assert_equal("def\n", f.gets) + assert_equal(nil, f.gets) + } + File.open("tmp.txt") {|f| + f.pos = pos3 + assert_equal(nil, f.gets) + } + } + end + + def test_std_fileno + assert_equal(0, STDIN.fileno) + assert_equal(1, STDOUT.fileno) + assert_equal(2, STDERR.fileno) + assert_equal(0, $stdin.fileno) + assert_equal(1, $stdout.fileno) + assert_equal(2, $stderr.fileno) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/