From bd0a3dfd65a164f422e7e2e92bfc3fddb084cde5 Mon Sep 17 00:00:00 2001 From: naruse Date: Sun, 7 Feb 2010 10:29:39 +0000 Subject: * test/dl/test_handle.rb (test_NEXT): fix for BSD. Linux and Darwin's RTLD_NEXT searchs second occurrence of the function. But FreeBSD and NetBSD's RTLD_NEXT searchs in libraries loaded after dl. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26613 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/dl/test_handle.rb | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/dl/test_handle.rb b/test/dl/test_handle.rb index 70a5f858e2..7a7d5bd71c 100644 --- a/test/dl/test_handle.rb +++ b/test/dl/test_handle.rb @@ -124,8 +124,35 @@ module DL end def test_NEXT - handle = DL::Handle::NEXT - assert handle['malloc'] + begin + # Linux / Darwin + # + # There are two special pseudo-handles, RTLD_DEFAULT and RTLD_NEXT. The former will find + # the first occurrence of the desired symbol using the default library search order. The + # latter will find the next occurrence of a function in the search order after the current + # library. This allows one to provide a wrapper around a function in another shared + # library. + # --- Ubuntu Linux 8.04 dlsym(3) + handle = DL::Handle::NEXT + assert handle['malloc'] + rescue + # BSD + # + # If dlsym() is called with the special handle RTLD_NEXT, then the search + # for the symbol is limited to the shared objects which were loaded after + # the one issuing the call to dlsym(). Thus, if the function is called + # from the main program, all the shared libraries are searched. If it is + # called from a shared library, all subsequent shared libraries are + # searched. RTLD_NEXT is useful for implementing wrappers around library + # functions. For example, a wrapper function getpid() could access the + # “real” getpid() with dlsym(RTLD_NEXT, "getpid"). (Actually, the dlfunc() + # interface, below, should be used, since getpid() is a function and not a + # data object.) + # --- FreeBSD 8.0 dlsym(3) + require 'objspace' + handle = DL::Handle::NEXT + assert handle['Init_objspace'] + end end def test_DEFAULT -- cgit v1.2.3