Class: FFI::Type
- Inherits:
-
Object
- Object
- FFI::Type
- Defined in:
- ext/ffi_c/Type.c,
ext/ffi_c/Type.c
Overview
This class manages C types.
It embbed Builtin objects as constants (for names, see NativeType).
Direct Known Subclasses
ArrayType, FunctionType, StructByValue, StructLayout, Builtin, Mapped
Defined Under Namespace
Constant Summary
- Array =
FFI::Type::Array
Document-constant
- Function =
rbffi_FunctionTypeClass- Struct =
rbffi_StructByValueClass
Instance Method Summary (collapse)
- - (Fixnum) alignment
- - (self) initialize(value) constructor
-
- (String) inspect
Inspect Type object.
-
- (Fixnum) size
Return type's size, in bytes.
Constructor Details
- (self) initialize(value)
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'ext/ffi_c/Type.c', line 63
static VALUE
type_initialize(VALUE self, VALUE value)
{
Type* type;
Type* other;
Data_Get_Struct(self, Type, type);
if (FIXNUM_P(value)) {
type->nativeType = FIX2INT(value);
} else if (rb_obj_is_kind_of(value, rbffi_TypeClass)) {
Data_Get_Struct(value, Type, other);
type->nativeType = other->nativeType;
type->ffiType = other->ffiType;
} else {
rb_raise(rb_eArgError, "wrong type");
}
return self;
}
|
Instance Method Details
- (Fixnum) alignment
103 104 105 106 107 108 109 110 111 |
# File 'ext/ffi_c/Type.c', line 103
static VALUE
type_alignment(VALUE self)
{
Type *type;
Data_Get_Struct(self, Type, type);
return INT2FIX(type->ffiType->alignment);
}
|
- (String) inspect
Inspect FFI::Type object.
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'ext/ffi_c/Type.c', line 118
static VALUE
type_inspect(VALUE self)
{
char buf[100];
Type *type;
Data_Get_Struct(self, Type, type);
snprintf(buf, sizeof(buf), "#<%s:%p size=%d alignment=%d>",
rb_obj_classname(self), type, (int) type->ffiType->size, (int) type->ffiType->alignment);
return rb_str_new2(buf);
}
|
- (Fixnum) size
Return type's size, in bytes.
89 90 91 92 93 94 95 96 97 |
# File 'ext/ffi_c/Type.c', line 89
static VALUE
type_size(VALUE self)
{
Type *type;
Data_Get_Struct(self, Type, type);
return INT2FIX(type->ffiType->size);
}
|