2017-09-12 07:52:23 -04:00
|
|
|
# frozen_string_literal: true
|
2020-04-18 02:57:41 -04:00
|
|
|
|
2010-05-06 02:59:24 -04:00
|
|
|
require 'fiddle.so'
|
|
|
|
require 'fiddle/closure'
|
2020-04-18 02:57:41 -04:00
|
|
|
require 'fiddle/function'
|
|
|
|
require 'fiddle/version'
|
2010-05-06 02:59:24 -04:00
|
|
|
|
|
|
|
module Fiddle
|
|
|
|
if WINDOWS
|
2011-08-15 19:48:59 -04:00
|
|
|
# Returns the last win32 +Error+ of the current executing +Thread+ or nil
|
|
|
|
# if none
|
2010-05-06 02:59:24 -04:00
|
|
|
def self.win32_last_error
|
|
|
|
Thread.current[:__FIDDLE_WIN32_LAST_ERROR__]
|
|
|
|
end
|
|
|
|
|
2011-08-15 19:48:59 -04:00
|
|
|
# Sets the last win32 +Error+ of the current executing +Thread+ to +error+
|
2010-05-06 02:59:24 -04:00
|
|
|
def self.win32_last_error= error
|
|
|
|
Thread.current[:__FIDDLE_WIN32_LAST_ERROR__] = error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-15 19:48:59 -04:00
|
|
|
# Returns the last +Error+ of the current executing +Thread+ or nil if none
|
2010-05-06 02:59:24 -04:00
|
|
|
def self.last_error
|
|
|
|
Thread.current[:__FIDDLE_LAST_ERROR__]
|
|
|
|
end
|
|
|
|
|
2011-08-15 19:48:59 -04:00
|
|
|
# Sets the last +Error+ of the current executing +Thread+ to +error+
|
2010-05-06 02:59:24 -04:00
|
|
|
def self.last_error= error
|
|
|
|
Thread.current[:__DL2_LAST_ERROR__] = error
|
|
|
|
Thread.current[:__FIDDLE_LAST_ERROR__] = error
|
|
|
|
end
|
2012-11-27 14:54:50 -05:00
|
|
|
|
2012-11-27 18:26:07 -05:00
|
|
|
# call-seq: dlopen(library) => Fiddle::Handle
|
|
|
|
#
|
|
|
|
# Creates a new handler that opens +library+, and returns an instance of
|
|
|
|
# Fiddle::Handle.
|
|
|
|
#
|
2013-07-26 00:11:27 -04:00
|
|
|
# If +nil+ is given for the +library+, Fiddle::Handle::DEFAULT is used, which
|
2013-07-26 01:06:57 -04:00
|
|
|
# is the equivalent to RTLD_DEFAULT. See <code>man 3 dlopen</code> for more.
|
2013-07-26 00:11:27 -04:00
|
|
|
#
|
2013-07-26 01:06:57 -04:00
|
|
|
# lib = Fiddle.dlopen(nil)
|
|
|
|
#
|
|
|
|
# The default is dependent on OS, and provide a handle for all libraries
|
|
|
|
# already loaded. For example, in most cases you can use this to access
|
|
|
|
# +libc+ functions, or ruby functions like +rb_str_new+.
|
2013-07-26 00:11:27 -04:00
|
|
|
#
|
2012-11-27 18:26:07 -05:00
|
|
|
# See Fiddle::Handle.new for more.
|
2012-11-27 14:54:50 -05:00
|
|
|
def dlopen library
|
|
|
|
Fiddle::Handle.new library
|
|
|
|
end
|
|
|
|
module_function :dlopen
|
|
|
|
|
|
|
|
# Add constants for backwards compat
|
|
|
|
|
|
|
|
RTLD_GLOBAL = Handle::RTLD_GLOBAL # :nodoc:
|
|
|
|
RTLD_LAZY = Handle::RTLD_LAZY # :nodoc:
|
|
|
|
RTLD_NOW = Handle::RTLD_NOW # :nodoc:
|
2010-05-06 02:59:24 -04:00
|
|
|
end
|