+
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions lib/ffi/library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#

require 'pathname'
require_relative "platform.rb"

module FFI
CURRENT_PROCESS = USE_THIS_PROCESS_AS_LIBRARY = Object.new

Expand All @@ -43,6 +46,7 @@ module FFI
# FFI.map_library_name 'jpeg' # -> "jpeg.dll"
def self.map_library_name(lib)
# Mangle the library name to reflect the native library naming conventions
lib = lib.to_s
lib = Library::LIBC if lib == 'c'

if lib && File.basename(lib) == lib
Expand Down Expand Up @@ -102,14 +106,15 @@ def ffi_lib(*names)
FFI::DynamicLibrary.open(nil, FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL)

else
libnames = (name.is_a?(::Array) ? name : [ name ]).map(&:to_s).map { |n| [ n, FFI.map_library_name(n) ].uniq }.flatten.compact
libnames = (name.respond_to?(:map) ? name : [ name ]).map { |n| [ n, FFI.map_library_name(n) ].uniq }.flatten.compact
lib = nil
errors = {}

libnames.each do |libname|
begin
orig = libname
lib = FFI::DynamicLibrary.open(libname, lib_flags)
orig = libname = Pathname(libname)
next if libname.directory?
lib = FFI::DynamicLibrary.open(libname.to_path, lib_flags)
break if lib

rescue Exception => ex
Expand All @@ -124,19 +129,18 @@ def ffi_lib(*names)
if ldscript
retry
else
# TODO better library lookup logic
unless libname.start_with?("/") || FFI::Platform.windows?
path = ['/usr/lib/','/usr/local/lib/','/opt/local/lib/'].find do |pth|
File.exist?(pth + libname)
end
libname = Pathname(libname.to_s)
unless libname.absolute?
path = pathnames.map{|pn| pn.join(libname)}
.find{|pn| pn.exist? }
if path
libname = path + libname
libname = path
retry
end
end

libr = (orig == libname ? orig : "#{orig} #{libname}")
errors[libr] = ex
errors[libr.to_s] = ex
end
end
end
Expand Down Expand Up @@ -584,5 +588,24 @@ def find_type(t)

end || FFI.find_type(t)
end


# Look for libraries by using what's loaded in the env.
# @return [Array<String>]
def pathnames
path =
if FFI::Platform.mac? then
ENV["DYLD_FALLBACK_LIBRARY_PATH"] || # preferred for Mac
ENV["DYLD_FALLBACK_FRAMEWORK_PATH"] ||
ENV["DYLD_LIBRARY_PATH"]
elsif FFI::Platform.windows?
# No idea what to put here
elsif FFI::Platform.unix?
ENV["LD_LIBRARY_PATH"] || # Systems using ELF
ENV["LIBPATH"] # XCOFF-based Unix-like systems
end
paths = path.nil? ? [] : path.split(":")
(paths + ['/usr/local/lib/','/usr/lib/']).uniq.map{|path| Pathname(path) }
end
end
end
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载