summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortduehr <tduehr@gmail.com>2015-05-22 12:54:36 -0500
committertduehr <tduehr@gmail.com>2015-05-22 12:54:36 -0500
commitc305ee696e466f9504a73767750d8f08de295149 (patch)
tree2f82a61f5b163890b5e8c49a8631f4fdda7b9f19
parent5aae84e8c926d02ed06d0c200f575d2f530adf02 (diff)
downloadffi-c305ee696e466f9504a73767750d8f08de295149.tar.gz
doc tweaks
-rw-r--r--lib/ffi/autopointer.rb6
-rw-r--r--lib/ffi/library.rb57
-rw-r--r--lib/ffi/struct_layout_builder.rb41
3 files changed, 55 insertions, 49 deletions
diff --git a/lib/ffi/autopointer.rb b/lib/ffi/autopointer.rb
index f4ca7a1..e6946d8 100644
--- a/lib/ffi/autopointer.rb
+++ b/lib/ffi/autopointer.rb
@@ -161,9 +161,9 @@ module FFI
# CallableReleaser is a {Releaser} used when an {AutoPointer} is defined with a
# Proc or a Method.
class CallableReleaser < Releaser
+ # Release +ptr+ by using Proc or Method defined at +ptr+ {AutoPointer#initialize initialization}.
# @param [Pointer] ptr
# @return [nil]
- # Release +ptr+ by using Proc or Method defined at +ptr+ {AutoPointer#initialize initialization}.
def release(ptr)
@proc.call(ptr)
end
@@ -183,8 +183,8 @@ module FFI
#
# Override {DataConverter#from_native}.
# @overload self.from_native(ptr, ctx)
- # @param [Pointer] ptr
- # @param ctx not used. Please set +nil+.
+ # @param [Pointer] ptr
+ # @param ctx not used. Please set +nil+.
# @return [AutoPointer]
def self.from_native(val, ctx)
self.new(val)
diff --git a/lib/ffi/library.rb b/lib/ffi/library.rb
index be54b7a..9849a3a 100644
--- a/lib/ffi/library.rb
+++ b/lib/ffi/library.rb
@@ -292,26 +292,26 @@ module FFI
end
# @overload attach_variable(mname, cname, type)
- # @param [#to_s] mname name of ruby method to attach as
- # @param [#to_s] cname name of C variable to attach
- # @param [DataConverter, Struct, Symbol, Type] type C variable's type
- # @example
- # module Bar
- # extend FFI::Library
- # ffi_lib 'my_lib'
- # attach_variable :c_myvar, :myvar, :long
- # end
- # # now callable via Bar.c_myvar
+ # @param [#to_s] mname name of ruby method to attach as
+ # @param [#to_s] cname name of C variable to attach
+ # @param [DataConverter, Struct, Symbol, Type] type C variable's type
+ # @example
+ # module Bar
+ # extend FFI::Library
+ # ffi_lib 'my_lib'
+ # attach_variable :c_myvar, :myvar, :long
+ # end
+ # # now callable via Bar.c_myvar
# @overload attach_variable(cname, type)
- # @param [#to_s] mname name of ruby method to attach as
- # @param [DataConverter, Struct, Symbol, Type] type C variable's type
- # @example
- # module Bar
- # extend FFI::Library
- # ffi_lib 'my_lib'
- # attach_variable :myvar, :long
- # end
- # # now callable via Bar.myvar
+ # @param [#to_s] mname name of ruby method to attach as
+ # @param [DataConverter, Struct, Symbol, Type] type C variable's type
+ # @example
+ # module Bar
+ # extend FFI::Library
+ # ffi_lib 'my_lib'
+ # attach_variable :myvar, :long
+ # end
+ # # now callable via Bar.myvar
# @return [DynamicLibrary::Symbol]
# @raise {FFI::NotFoundError} if +cname+ cannot be found in libraries
#
@@ -362,12 +362,12 @@ module FFI
# @overload callback(name, params, ret)
- # @param name callback name to add to type map
- # @param [Array] params array of parameters' types
- # @param [DataConverter, Struct, Symbol, Type] ret callback return type
+ # @param name callback name to add to type map
+ # @param [Array] params array of parameters' types
+ # @param [DataConverter, Struct, Symbol, Type] ret callback return type
# @overload callback(params, ret)
- # @param [Array] params array of parameters' types
- # @param [DataConverter, Struct, Symbol, Type] ret callback return type
+ # @param [Array] params array of parameters' types
+ # @param [DataConverter, Struct, Symbol, Type] ret callback return type
# @return [FFI::CallbackInfo]
def callback(*args)
raise ArgumentError, "wrong number of arguments" if args.length < 2 || args.length > 3
@@ -392,10 +392,6 @@ module FFI
cb
end
- # @param [DataConverter, Symbol, Type] old
- # @param add
- # @param info
- # @return [FFI::Enum, FFI::Type]
# Register or get an already registered type definition.
#
# To register a new type definition, +old+ should be a {FFI::Type}. +add+
@@ -408,6 +404,11 @@ module FFI
# * in others cases, +info+ is used to create a named enum.
#
# If +old+ is a key for type map, #typedef get +old+ type definition.
+ #
+ # @param [DataConverter, Symbol, Type] old
+ # @param [Symbol] add
+ # @param [Symbol] info
+ # @return [FFI::Enum, FFI::Type]
def typedef(old, add, info=nil)
@ffi_typedefs = Hash.new unless defined?(@ffi_typedefs)
diff --git a/lib/ffi/struct_layout_builder.rb b/lib/ffi/struct_layout_builder.rb
index 5e9e740..918c790 100644
--- a/lib/ffi/struct_layout_builder.rb
+++ b/lib/ffi/struct_layout_builder.rb
@@ -30,12 +30,12 @@
#
module FFI
-
+
# Build a {StructLayout struct layout}.
class StructLayoutBuilder
attr_reader :size
attr_reader :alignment
-
+
def initialize
@size = 0
@alignment = 1
@@ -45,42 +45,47 @@ module FFI
@fields = Array.new
end
- # @param [Numeric] size
# Set size attribute with +size+ only if +size+ is greater than attribute value.
+ # @param [Numeric] size
def size=(size)
@size = size if size > @size
end
- # @param [Numeric] align
# Set alignment attribute with +align+ only if it is greater than attribute value.
+ # @param [Numeric] align
def alignment=(align)
@alignment = align if align > @alignment
@min_alignment = align
end
- # @param [Boolean] is_union
- # @return [is_union]
# Set union attribute.
# Set to +true+ to build a {Union} instead of a {Struct}.
+ # @param [Boolean] is_union
+ # @return [is_union]
def union=(is_union)
@union = is_union
end
- # @return [Boolean]
# Building a {Union} or a {Struct} ?
+ #
+ # @return [Boolean]
+ #
def union?
@union
end
# Set packed attribute
- # @overload packed=(packed)
- # @param [Fixnum] packed
- # @return [packed]
- # Set alignment and packed attributes to +packed+.
- # @overload packed=(packed)
- # @param packed
- # @return [0,1]
- # Set packed attribute.
+ # @overload packed=(packed) Set alignment and packed attributes to
+ # +packed+.
+ #
+ # @param [Fixnum] packed
+ #
+ # @return [packed]
+ # @overload packed=(packed) Set packed attribute.
+ # @param packed
+ #
+ # @return [0,1]
+ #
def packed=(packed)
if packed.is_a?(Fixnum)
@alignment = packed
@@ -139,7 +144,7 @@ module FFI
def add_field(name, type, offset = nil)
add(name, type, offset)
end
-
+
# @param (see #add)
# @return (see #add)
# Add a struct as a field to the builder.
@@ -162,14 +167,14 @@ module FFI
def build
# Add tail padding if the struct is not packed
size = @packed ? @size : align(@size, @alignment)
-
+
layout = StructLayout.new(@fields, size, @alignment)
layout.__union! if @union
layout
end
private
-
+
# @param [Numeric] offset
# @param [Numeric] align
# @return [Numeric]