ruby-changes:15105
From: wanabe <ko1@a...>
Date: Sat, 20 Mar 2010 01:18:15 +0900 (JST)
Subject: [ruby-changes:15105] Ruby:r26982 (trunk): * test/dl/test_dl2.rb (DL::TestDL#ptr2num): add for LLP64.
wanabe 2010-03-20 01:18:05 +0900 (Sat, 20 Mar 2010) New Revision: 26982 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26982 Log: * test/dl/test_dl2.rb (DL::TestDL#ptr2num): add for LLP64. Modified files: trunk/test/dl/test_dl2.rb Index: test/dl/test_dl2.rb =================================================================== --- test/dl/test_dl2.rb (revision 26981) +++ test/dl/test_dl2.rb (revision 26982) @@ -1,9 +1,14 @@ require_relative 'test_base.rb' require 'dl/callback' require 'dl/func' +require 'dl/pack' module DL class TestDL < TestBase + def ptr2num(*list) + list.pack("p*").unpack(PackInfo::PACK_MAP[TYPE_VOIDP] + "*") + end + # TODO: refactor test repetition def test_free_secure @@ -112,21 +117,21 @@ buff = "xxxx" str = "abc" cfunc = CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy') - x = cfunc.call([buff,str].pack("pp").unpack("l!*")) + x = cfunc.call(ptr2num(buff,str)) assert_equal("abc\0", buff) assert_equal("abc\0", CPtr.new(x).to_s(4)) buff = "xxxx" str = "abc" cfunc = CFunc.new(@libc['strncpy'], TYPE_VOIDP, 'strncpy') - x = cfunc.call([buff,str,3].pack("ppL!").unpack("l!*")) + x = cfunc.call(ptr2num(buff,str) + [3]) assert_equal("abcx", buff) assert_equal("abcx", CPtr.new(x).to_s(4)) ptr = CPtr.malloc(4) str = "abc" cfunc = CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy') - x = cfunc.call([ptr.to_i,str].pack("l!p").unpack("l!*")) + x = cfunc.call([ptr.to_i, *ptr2num(str)]) assert_equal("abc\0", ptr[0,4]) assert_equal("abc\0", CPtr.new(x).to_s(4)) end @@ -135,7 +140,7 @@ buff = "foobarbaz" cb = set_callback(TYPE_INT,2){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]} cfunc = CFunc.new(@libc['qsort'], TYPE_VOID, 'qsort') - cfunc.call([buff, buff.size, 1, cb].pack("pL!L!L!").unpack("l!*")) + cfunc.call(ptr2num(buff) + [buff.size, 1, cb]) assert_equal('aabbfoorz', buff) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/