Method: FFI::ArrayType#initialize
- Defined in:
- ext/ffi_c/ArrayType.c
#initialize(component_type, length) ⇒ self
A new instance of ArrayType.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'ext/ffi_c/ArrayType.c', line 117
static VALUE
array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength)
{
ArrayType* array;
int i;
TypedData_Get_Struct(self, ArrayType, &rbffi_array_type_data_type, array);
array->length = NUM2UINT(rbLength);
RB_OBJ_WRITE(self, &array->rbComponentType, rbComponentType);
TypedData_Get_Struct(rbComponentType, Type, &rbffi_type_data_type, array->componentType);
array->ffiTypes = xcalloc(array->length + 1, sizeof(*array->ffiTypes));
array->base.ffiType->elements = array->ffiTypes;
array->base.ffiType->size = array->componentType->ffiType->size * array->length;
array->base.ffiType->alignment = array->componentType->ffiType->alignment;
for (i = 0; i < array->length; ++i) {
array->ffiTypes[i] = array->componentType->ffiType;
}
return self;
}
|