diff options
-rw-r--r--[-rwxr-xr-x] | b.rb | 0 | ||||
-rwxr-xr-x | doc/b.rb (renamed from docs/b.rb) | 0 | ||||
-rw-r--r-- | doc/mmap.rb (renamed from docs/mmap.rb) | 0 | ||||
-rw-r--r-- | ext/runtest.rb | 11 | ||||
-rw-r--r-- | extconf.rb | 24 | ||||
-rw-r--r-- | mmap.c | 37 | ||||
-rw-r--r-- | test/mmapt.rb (renamed from tests/mmapt.rb) | 46 | ||||
-rw-r--r-- | test/runit_.rb (renamed from tests/runit_.rb) | 3 |
8 files changed, 83 insertions, 38 deletions
diff --git a/docs/mmap.rb b/doc/mmap.rb index 2c585a0..2c585a0 100644 --- a/docs/mmap.rb +++ b/doc/mmap.rb diff --git a/ext/runtest.rb b/ext/runtest.rb new file mode 100644 index 0000000..5ad822c --- /dev/null +++ b/ext/runtest.rb @@ -0,0 +1,11 @@ +#!/usr/bin/ruby +#-- +# don't use it's for gem +$LOAD_PATH.each do |p| + if p.gsub!(%r{/ext\Z}, '/test') && + File.exists?(p + '/mmapt.rb') + load(p + '/mmapt.rb') + break + end +end + @@ -26,10 +26,10 @@ create_makefile "mmap" begin make = open("Makefile", "a") make.puts "\ntest: $(DLLIB)" - Dir.foreach('tests') do |x| + Dir.foreach('test') do |x| next if /^\./ =~ x || /(_\.rb|~)$/ =~ x next if FileTest.directory?(x) - make.print "\truby tests/#{x}\n" + make.print "\truby test/#{x}\n" end if unknown make.print <<-EOT @@ -47,22 +47,22 @@ EOT EOT make.print "HTML = mmap.html" - docs = Dir['docs/*.rd'] - docs.each {|x| make.print " \\\n\t#{x.sub(/\.rd$/, '.html')}" } - make.print "\n\nRDOC = docs/mmap.rb" + doc = Dir['doc/*.rd'] + doc.each {|x| make.print " \\\n\t#{x.sub(/\.rd$/, '.html')}" } + make.print "\n\nRDOC = doc/mmap.rb" make.puts make.print <<-EOF -rdoc: docs/doc/index.html +rdoc: doc/doc/index.html -docs/doc/index.html: $(RDOC) -\t@-(cd docs; rdoc mmap.rb) +doc/doc/index.html: $(RDOC) +\t@-(cd doc; rdoc mmap.rb) -ri: docs/mmap.rb -\t@-(cd docs; rdoc -r mmap.rb) +ri: doc/mmap.rb +\t@-(cd doc; rdoc -r mmap.rb) -ri-site: docs/mmap.rb -\t@-(cd docs; rdoc -R mmap.rb) +ri-site: doc/mmap.rb +\t@-(cd doc; rdoc -R mmap.rb) rd2: html @@ -273,7 +273,7 @@ mm_extend(obj, a) if (len > 0) { mm_expandf(t_mm, t_mm->len + len); } - return INT2NUM(t_mm->len); + return UINT2NUM(t_mm->len); } static VALUE @@ -290,7 +290,7 @@ mm_i_options(arg, obj) key = rb_obj_as_string(key); options = StringValuePtr(key); if (strcmp(options, "length") == 0) { - t_mm->len = NUM2INT(value); + t_mm->len = NUM2UINT(value); if (t_mm->len <= 0) { rb_raise(rb_eArgError, "Invalid value for length %d", t_mm->len); } @@ -406,8 +406,15 @@ mm_init(argc, argv, obj) if (NIL_P(vmode)) { mode = "r"; } - else if (TYPE(vmode) == T_ARRAY && RARRAY(vmode)->len >= 2) { - VALUE tmp = RARRAY(vmode)->ptr[0]; + else if (rb_respond_to(vmode, rb_intern("to_ary"))) { + VALUE tmp; + + vmode = rb_convert_type(vmode, T_ARRAY, "Array", "to_ary"); + if (RARRAY(vmode)->len != 2) { + rb_raise(rb_eArgError, "Invalid length %d (expected 2)", + RARRAY(vmode)->len); + } + tmp = RARRAY(vmode)->ptr[0]; mode = StringValuePtr(tmp); perm = NUM2INT(RARRAY(vmode)->ptr[1]); } @@ -420,10 +427,7 @@ mm_init(argc, argv, obj) } else if (strcmp(mode, "w") == 0) { smode = O_RDWR | O_TRUNC; - pmode = PROT_WRITE; - if (!NIL_P(fdv)) { - pmode |= PROT_READ; - } + pmode = PROT_READ | PROT_WRITE; } else if (strcmp(mode, "rw") == 0 || strcmp(mode, "wr") == 0) { smode = O_RDWR; @@ -1281,11 +1285,16 @@ mm_equal(a, b) VALUE a, b; { VALUE result; - + mm_mmap *t_mm, *u_mm; + if (a == b) return Qtrue; if (TYPE(b) != T_DATA || RDATA(b)->dfree != (RUBY_DATA_FUNC)mm_free) return Qfalse; + GetMmap(a, t_mm, 0); + GetMmap(b, u_mm, 0); + if (t_mm->real != u_mm->real) + return Qfalse; a = mm_str(a, MM_ORIGIN); b = mm_str(b, MM_ORIGIN); result = rb_funcall2(a, rb_intern("=="), 1, &b); @@ -1299,11 +1308,16 @@ mm_eql(a, b) VALUE a, b; { VALUE result; + mm_mmap *t_mm, *u_mm; if (a == b) return Qtrue; if (TYPE(b) != T_DATA || RDATA(b)->dfree != (RUBY_DATA_FUNC)mm_free) return Qfalse; + GetMmap(a, t_mm, 0); + GetMmap(b, u_mm, 0); + if (t_mm->real != u_mm->real) + return Qfalse; a = mm_str(a, MM_ORIGIN); b = mm_str(b, MM_ORIGIN); result = rb_funcall2(a, rb_intern("eql?"), 1, &b); @@ -1332,7 +1346,7 @@ mm_size(a) mm_mmap *t_mm; GetMmap(a, t_mm, 0); - return INT2NUM(t_mm->real); + return UINT2NUM(t_mm->real); } static VALUE @@ -1722,9 +1736,10 @@ Init_mmap() #ifdef MAP_NOSYNC rb_define_const(mm_cMap, "MAP_NOSYNC", INT2FIX(MAP_NOSYNC)); #endif +#ifdef MCL_CURRENT rb_define_const(mm_cMap, "MCL_CURRENT", INT2FIX(MCL_CURRENT)); rb_define_const(mm_cMap, "MCL_FUTURE", INT2FIX(MCL_FUTURE)); - +#endif rb_include_module(mm_cMap, rb_mComparable); rb_include_module(mm_cMap, rb_mEnumerable); diff --git a/tests/mmapt.rb b/test/mmapt.rb index 6b81505..80c64c2 100644 --- a/tests/mmapt.rb +++ b/test/mmapt.rb @@ -1,33 +1,51 @@ #!/usr/bin/ruby -$LOAD_PATH.unshift *%w{.. . tests} +$LOAD_PATH.unshift *%w{.. . test} require 'mmap' require 'ftools' -require 'runit_' + +$pathmm = $LOAD_PATH.find {|p| File.exist?(p + "/mmap.c") } +unless $pathmm + $LOAD_PATH.each do |p| + p p + if p.gsub!(%r{/test\Z}, '/') && + File.exists?(p + '/mmap.c') + $pathmm = p + break + end + end +end +raise "unable to find mmap.c" unless $pathmm + +load "#{$pathmm}/test/runit_.rb" $mmap, $str = nil, nil Inh = defined?(RUNIT) ? RUNIT : Test::Unit -Dir["tmp/*"].each do |f| +$pathmm = $LOAD_PATH.find {|p| File.exist?(p + "/mmap.c") } +raise "unable to find mmap.c" unless $pathmm + +Dir.mkdir("#{$pathmm}/tmp") unless FileTest.directory?("#{$pathmm}/tmp") + +Dir["#{$pathmm}/tmp/*"].each do |f| File.unlink(f) if FileTest.file?(f) end class TestMmap < Inh::TestCase def internal_read - File.readlines("tmp/mmap", nil)[0] + File.readlines("#{$pathmm}/tmp/mmap", nil)[0] end def internal_init(io = false) $mmap.unmap if $mmap - file = "mmap.c" - file = "../mmap.c" unless File.exist? file - File.syscopy file, "tmp/mmap" + file = "#{$pathmm}/mmap.c" + File.syscopy file, "#{$pathmm}/tmp/mmap" $str = internal_read if io - assert_kind_of(Mmap, $mmap = Mmap.new(File.new("tmp/mmap", "r+"), "rw"), "<open io>") + assert_kind_of(Mmap, $mmap = Mmap.new(File.new("#{$pathmm}/tmp/mmap", "r+"), "rw"), "<open io>") else - assert_kind_of(Mmap, $mmap = Mmap.new("tmp/mmap", "rw"), "<open>") + assert_kind_of(Mmap, $mmap = Mmap.new("#{$pathmm}/tmp/mmap", "rw"), "<open>") end end @@ -297,9 +315,9 @@ class TestMmap < Inh::TestCase def test_13_div string = "azertyuiopqsdfghjklm" - assert_kind_of(Mmap, m0 = Mmap.new("tmp/aa", "a"), "new a") - File.open("tmp/bb", "w") {|f| f.puts "aaa" } - assert_kind_of(Mmap, m1 = Mmap.new("tmp/bb", "w"), "new a") + assert_kind_of(Mmap, m0 = Mmap.new("#{$pathmm}/tmp/aa", "a"), "new a") + File.open("#{$pathmm}/tmp/bb", "w") {|f| f.puts "aaa" } + assert_kind_of(Mmap, m1 = Mmap.new("#{$pathmm}/tmp/bb", "w"), "new a") assert_equal(true, m0.empty?, "empty") assert_equal(true, m1.empty?, "empty") assert_equal(m0, m0 << string, "<<") @@ -326,9 +344,9 @@ class TestMmap < Inh::TestCase end def test_14_other - if File.exist?("tmp/aa") + if File.exist?("#{$pathmm}/tmp/aa") string = "azertyuiopqsdfghjklm" - assert_kind_of(Mmap, m0 = Mmap.new("tmp/aa", "r"), "new r") + assert_kind_of(Mmap, m0 = Mmap.new("#{$pathmm}/tmp/aa", "r"), "new r") assert_equal(string, m0.to_str, "content") assert_raises(TypeError) { m0[0] = 12 } assert_raises(TypeError) { m0 << 12 } diff --git a/tests/runit_.rb b/test/runit_.rb index 0479592..639c149 100644 --- a/tests/runit_.rb +++ b/test/runit_.rb @@ -1,6 +1,7 @@ +#:nodoc:all begin require 'test/unit' -rescue LoadError +rescue LoadError require 'runit/testcase' require 'runit/cui/testrunner' |