123456789_123456789_123456789_123456789_123456789_

Class: FFI::Type

Relationships & Source Files
Namespace Children
Classes:
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: ext/ffi_c/Type.c,
ext/ffi_c/StructByValue.c

Overview

This class manages C types.

It embbed Builtin objects as constants (for names, see NativeType).

Constant Summary

Class Method Summary

Instance Method Summary

Constructor Details

.new(value)

[ GitHub ]

  
# File 'ext/ffi_c/Type.c', line 113

static VALUE
type_initialize(VALUE self, VALUE value)
{
    Type* type;
    Type* other;

    TypedData_Get_Struct(self, Type, &rbffi_type_data_type, type);

    if (FIXNUM_P(value)) {
        type->nativeType = FIX2INT(value);
    } else if (rb_obj_is_kind_of(value, rbffi_TypeClass)) {
        TypedData_Get_Struct(value, Type, &rbffi_type_data_type, other);
        type->nativeType = other->nativeType;
        type->ffiType = other->ffiType;
    } else {
        rb_raise(rb_eArgError, "wrong type");
    }

    rb_obj_freeze(self);

    return self;
}

Instance Method Details

#alignment Type(alignment)

[ GitHub ]

  
# File 'ext/ffi_c/Type.c', line 156

static VALUE
type_alignment(VALUE self)
{
    Type *type;

    TypedData_Get_Struct(self, Type, &rbffi_type_data_type, type);

    return INT2FIX(type->ffiType->alignment);
}

#inspect Inspect({Type} object.)

[ GitHub ]

  
# File 'ext/ffi_c/Type.c', line 171

static VALUE
type_inspect(VALUE self)
{
    char buf[100];
    Type *type;

    TypedData_Get_Struct(self, Type, &rbffi_type_data_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);
}

#size Return(type's size, in bytes.)

[ GitHub ]

  
# File 'ext/ffi_c/Type.c', line 141

static VALUE
type_size(VALUE self)
{
    Type *type;

    TypedData_Get_Struct(self, Type, &rbffi_type_data_type, type);

    return INT2FIX(type->ffiType->size);
}