fiddle/import.rb: suppress warnings

* ext/fiddle/lib/fiddle/import.rb (type_alias, handler): suppress
  "not initialized instance variable" warnings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-04-11 04:28:16 +00:00
parent e9bb167bfb
commit bf6a8134f8

View File

@ -63,6 +63,9 @@ module Fiddle
include CParser include CParser
extend Importer extend Importer
attr_reader :type_alias
private :type_alias
# Creates an array of handlers for the given +libs+, can be an instance of # Creates an array of handlers for the given +libs+, can be an instance of
# Fiddle::Handle, Fiddle::Importer, or will create a new instance of # Fiddle::Handle, Fiddle::Importer, or will create a new instance of
# Fiddle::Handle using Fiddle.dlopen # Fiddle::Handle using Fiddle.dlopen
@ -102,7 +105,7 @@ module Fiddle
def sizeof(ty) def sizeof(ty)
case ty case ty
when String when String
ty = parse_ctype(ty, @type_alias).abs() ty = parse_ctype(ty, type_alias).abs()
case ty case ty
when TYPE_CHAR when TYPE_CHAR
return SIZEOF_CHAR return SIZEOF_CHAR
@ -160,7 +163,7 @@ module Fiddle
# Creates a global method from the given C +signature+. # Creates a global method from the given C +signature+.
def extern(signature, *opts) def extern(signature, *opts)
symname, ctype, argtype = parse_signature(signature, @type_alias) symname, ctype, argtype = parse_signature(signature, type_alias)
opt = parse_bind_options(opts) opt = parse_bind_options(opts)
f = import_function(symname, ctype, argtype, opt[:call_type]) f = import_function(symname, ctype, argtype, opt[:call_type])
name = symname.gsub(/@.+/,'') name = symname.gsub(/@.+/,'')
@ -184,7 +187,7 @@ module Fiddle
# Creates a global method from the given C +signature+ using the given # Creates a global method from the given C +signature+ using the given
# +opts+ as bind parameters with the given block. # +opts+ as bind parameters with the given block.
def bind(signature, *opts, &blk) def bind(signature, *opts, &blk)
name, ctype, argtype = parse_signature(signature, @type_alias) name, ctype, argtype = parse_signature(signature, type_alias)
h = parse_bind_options(opts) h = parse_bind_options(opts)
case h[:callback_type] case h[:callback_type]
when :bind, nil when :bind, nil
@ -213,7 +216,7 @@ module Fiddle
# #
# MyStruct = struct ['int i', 'char c'] # MyStruct = struct ['int i', 'char c']
def struct(signature) def struct(signature)
tys, mems = parse_struct_signature(signature, @type_alias) tys, mems = parse_struct_signature(signature, type_alias)
Fiddle::CStructBuilder.create(CStruct, tys, mems) Fiddle::CStructBuilder.create(CStruct, tys, mems)
end end
@ -221,7 +224,7 @@ module Fiddle
# #
# MyUnion = union ['int i', 'char c'] # MyUnion = union ['int i', 'char c']
def union(signature) def union(signature)
tys, mems = parse_struct_signature(signature, @type_alias) tys, mems = parse_struct_signature(signature, type_alias)
Fiddle::CStructBuilder.create(CUnion, tys, mems) Fiddle::CStructBuilder.create(CUnion, tys, mems)
end end
@ -257,7 +260,7 @@ module Fiddle
# #
# Will raise an error if no handlers are open. # Will raise an error if no handlers are open.
def handler def handler
@handler or raise "call dlload before importing symbols and functions" (@handler ||= nil) or raise "call dlload before importing symbols and functions"
end end
# Returns a new Fiddle::Pointer instance at the memory address of the given # Returns a new Fiddle::Pointer instance at the memory address of the given