summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-07 10:29:39 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-07 10:29:39 +0000
commitbd0a3dfd65a164f422e7e2e92bfc3fddb084cde5 (patch)
tree16d8e2cb6c80238894fa441fbbc40e733f85b31b
parent666409ba5011a86267d7a54541ce6e69b9e59550 (diff)
* 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
-rw-r--r--test/dl/test_handle.rb31
1 files changed, 29 insertions, 2 deletions
diff --git a/test/dl/test_handle.rb b/test/dl/test_handle.rb
index 70a5f85..7a7d5bd 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