Class: FFI::StructByValue

Inherits:
Type
  • Object
show all
Defined in:
ext/ffi_c/StructByValue.c

Constant Summary

Constants inherited from Type

Type::Struct

Instance Method Summary collapse

Methods inherited from Type

#alignment, #inspect, #size

Constructor Details

#initialize(rbStructClass) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'ext/ffi_c/StructByValue.c', line 92

static VALUE
sbv_initialize(VALUE self, VALUE rbStructClass)
{
    StructByValue* sbv = NULL;
    StructLayout* layout = NULL;
    VALUE rbLayout = Qnil;

    rbLayout = rb_ivar_get(rbStructClass, rb_intern("@layout"));
    if (!rb_obj_is_instance_of(rbLayout, rbffi_StructLayoutClass)) {
        rb_raise(rb_eTypeError, "wrong type in @layout ivar (expected FFI::StructLayout)");
    }

    TypedData_Get_Struct(rbLayout, StructLayout, &rbffi_struct_layout_data_type, layout);
    TypedData_Get_Struct(self, StructByValue, &sbv_type_data_type, sbv);
    RB_OBJ_WRITE(self, &sbv->rbStructClass, rbStructClass);
    RB_OBJ_WRITE(self, &sbv->rbStructLayout, rbLayout);

    /* We can just use everything from the ffi_type directly */
    *sbv->base.ffiType = *layout->base.ffiType;

    return self;
}

Instance Method Details

#layoutObject



146
147
148
149
150
151
152
153
# File 'ext/ffi_c/StructByValue.c', line 146

static VALUE
sbv_layout(VALUE self)
{
    StructByValue* sbv;

    TypedData_Get_Struct(self, StructByValue, &sbv_type_data_type, sbv);
    return sbv->rbStructLayout;
}

#struct_classObject



155
156
157
158
159
160
161
162
163
# File 'ext/ffi_c/StructByValue.c', line 155

static VALUE
sbv_struct_class(VALUE self)
{
    StructByValue* sbv;

    TypedData_Get_Struct(self, StructByValue, &sbv_type_data_type, sbv);

    return sbv->rbStructClass;
}