Skip to content

Commit

Permalink
Remove old references to ruby-1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
larskanis committed Jan 31, 2020
1 parent b54e735 commit 6845314
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 47 deletions.
60 changes: 30 additions & 30 deletions ext/ffi_c/Struct.c
Expand Up @@ -90,7 +90,7 @@ struct_allocate(VALUE klass)
{
Struct* s;
VALUE obj = Data_Make_Struct(klass, Struct, struct_mark, struct_free, s);

s->rbPointer = Qnil;
s->rbLayout = Qnil;

Expand All @@ -112,7 +112,7 @@ struct_initialize(int argc, VALUE* argv, VALUE self)
int nargs;

Data_Get_Struct(self, Struct, s);

nargs = rb_scan_args(argc, argv, "01*", &rbPointer, &rest);

/* Call up into ruby code to adjust the layout */
Expand All @@ -127,7 +127,7 @@ struct_initialize(int argc, VALUE* argv, VALUE self)
}

Data_Get_Struct(s->rbLayout, StructLayout, s->layout);

if (rbPointer != Qnil) {
s->pointer = MEMORY(rbPointer);
s->rbPointer = rbPointer;
Expand All @@ -148,16 +148,16 @@ struct_initialize_copy(VALUE self, VALUE other)
{
Struct* src;
Struct* dst;

Data_Get_Struct(self, Struct, dst);
Data_Get_Struct(other, Struct, src);
if (dst == src) {
return self;
}

dst->rbLayout = src->rbLayout;
dst->layout = src->layout;

/*
* A new MemoryPointer instance is allocated here instead of just calling
* #dup on rbPointer, since the Pointer may not know its length, or may
Expand All @@ -176,7 +176,7 @@ struct_initialize_copy(VALUE self, VALUE other)
dst->rbReferences = ALLOC_N(VALUE, dst->layout->referenceFieldCount);
memcpy(dst->rbReferences, src->rbReferences, dst->layout->referenceFieldCount * sizeof(VALUE));
}

return self;
}

Expand Down Expand Up @@ -318,12 +318,12 @@ struct_aref(VALUE self, VALUE fieldName)

if (f->get != NULL) {
return (*f->get)(f, s);

} else if (f->memoryOp != NULL) {
return (*f->memoryOp->get)(s->pointer, f->offset);

} else {

/* call up to the ruby code to fetch the value */
return rb_funcall2(rbField, id_get, 1, &s->rbPointer);
}
Expand Down Expand Up @@ -354,7 +354,7 @@ struct_aset(VALUE self, VALUE fieldName, VALUE value)
} else if (f->memoryOp != NULL) {

(*f->memoryOp->put)(s->pointer, f->offset, value);

} else {
/* call up to the ruby code to set the value */
VALUE argv[2];
Expand All @@ -366,7 +366,7 @@ struct_aset(VALUE self, VALUE fieldName, VALUE value)
if (f->referenceRequired) {
store_reference_value(f, s, value);
}

return value;
}

Expand All @@ -389,7 +389,7 @@ struct_set_pointer(VALUE self, VALUE pointer)
return Qnil;
}


Data_Get_Struct(self, Struct, s);
Data_Get_Struct(pointer, AbstractMemory, memory);
layout = struct_layout(self);
Expand All @@ -398,7 +398,7 @@ struct_set_pointer(VALUE self, VALUE pointer)
rb_raise(rb_eArgError, "memory of %ld bytes too small for struct %s (expected at least %ld)",
memory->size, rb_obj_classname(self), (long) layout->base.ffiType->size);
}

s->pointer = MEMORY(pointer);
s->rbPointer = pointer;
rb_ivar_set(self, id_pointer_ivar, pointer);
Expand Down Expand Up @@ -491,7 +491,7 @@ struct_order(int argc, VALUE* argv, VALUE self)
VALUE retval = rb_obj_dup(self);
VALUE rbPointer = rb_funcall2(s->rbPointer, rb_intern("order"), argc, argv);
struct_set_pointer(retval, rbPointer);

return retval;
}
}
Expand Down Expand Up @@ -527,7 +527,7 @@ static VALUE
inline_array_initialize(VALUE self, VALUE rbMemory, VALUE rbField)
{
InlineArray* array;

Data_Get_Struct(self, InlineArray, array);
array->rbMemory = rbMemory;
array->rbField = rbField;
Expand All @@ -536,12 +536,12 @@ inline_array_initialize(VALUE self, VALUE rbMemory, VALUE rbField)
Data_Get_Struct(rbField, StructField, array->field);
Data_Get_Struct(array->field->rbType, ArrayType, array->arrayType);
Data_Get_Struct(array->arrayType->rbComponentType, Type, array->componentType);

array->op = get_memory_op(array->componentType);
if (array->op == NULL && array->componentType->nativeType == NATIVE_MAPPED) {
array->op = get_memory_op(((MappedType *) array->componentType)->type);
}

array->length = array->arrayType->length;

return self;
Expand Down Expand Up @@ -585,15 +585,15 @@ inline_array_aref(VALUE self, VALUE rbIndex)
Data_Get_Struct(self, InlineArray, array);

if (array->op != NULL) {
VALUE rbNativeValue = array->op->get(array->memory,
VALUE rbNativeValue = array->op->get(array->memory,
inline_array_offset(array, NUM2INT(rbIndex)));
if (unlikely(array->componentType->nativeType == NATIVE_MAPPED)) {
return rb_funcall(((MappedType *) array->componentType)->rbConverter,
return rb_funcall(((MappedType *) array->componentType)->rbConverter,
rb_intern("from_native"), 2, rbNativeValue, Qnil);
} else {
return rbNativeValue;
return rbNativeValue;
}

} else if (array->componentType->nativeType == NATIVE_STRUCT) {
VALUE rbOffset = INT2NUM(inline_array_offset(array, NUM2INT(rbIndex)));
VALUE rbLength = INT2NUM(array->componentType->ffiType->size);
Expand Down Expand Up @@ -622,12 +622,12 @@ inline_array_aset(VALUE self, VALUE rbIndex, VALUE rbValue)

if (array->op != NULL) {
if (unlikely(array->componentType->nativeType == NATIVE_MAPPED)) {
rbValue = rb_funcall(((MappedType *) array->componentType)->rbConverter,
rbValue = rb_funcall(((MappedType *) array->componentType)->rbConverter,
rb_intern("to_native"), 2, rbValue, Qnil);
}
array->op->put(array->memory, inline_array_offset(array, NUM2INT(rbIndex)),
rbValue);

} else if (array->componentType->nativeType == NATIVE_STRUCT) {
int offset = inline_array_offset(array, NUM2INT(rbIndex));
Struct* s;
Expand Down Expand Up @@ -665,11 +665,11 @@ static VALUE
inline_array_each(VALUE self)
{
InlineArray* array;

int i;

Data_Get_Struct(self, InlineArray, array);

for (i = 0; i < array->length; ++i) {
rb_yield(inline_array_aref(self, INT2FIX(i)));
}
Expand All @@ -692,7 +692,7 @@ inline_array_to_a(VALUE self)
Data_Get_Struct(self, InlineArray, array);
obj = rb_ary_new2(array->length);


for (i = 0; i < array->length; ++i) {
rb_ary_push(obj, inline_array_aref(self, INT2FIX(i)));
}
Expand All @@ -713,7 +713,7 @@ inline_array_to_s(VALUE self)
VALUE argv[2];

Data_Get_Struct(self, InlineArray, array);

if (array->componentType->nativeType != NATIVE_INT8 && array->componentType->nativeType != NATIVE_UINT8) {
VALUE dummy = Qnil;
return rb_call_super(0, &dummy);
Expand All @@ -734,7 +734,7 @@ static VALUE
inline_array_to_ptr(VALUE self)
{
InlineArray* array;

Data_Get_Struct(self, InlineArray, array);

return rb_funcall(array->rbMemory, rb_intern("slice"), 2,
Expand Down Expand Up @@ -778,7 +778,7 @@ rbffi_Struct_Init(VALUE moduleFFI)
/*
* Document-class: FFI::StructLayout::CharArray < FFI::Struct::InlineArray
*/
rbffi_StructLayoutCharArrayClass = rb_define_class_under(rbffi_StructLayoutClass, "CharArray",
rbffi_StructLayoutCharArrayClass = rb_define_class_under(rbffi_StructLayoutClass, "CharArray",
rbffi_StructInlineArrayClass);
rb_global_variable(&rbffi_StructLayoutCharArrayClass);

Expand All @@ -787,7 +787,7 @@ rbffi_Struct_Init(VALUE moduleFFI)
rb_define_method(StructClass, "initialize", struct_initialize, -1);
rb_define_method(StructClass, "initialize_copy", struct_initialize_copy, 1);
rb_define_method(StructClass, "order", struct_order, -1);

rb_define_alias(rb_singleton_class(StructClass), "alloc_in", "new");
rb_define_alias(rb_singleton_class(StructClass), "alloc_out", "new");
rb_define_alias(rb_singleton_class(StructClass), "alloc_inout", "new");
Expand Down
6 changes: 1 addition & 5 deletions ext/ffi_c/Struct.h
Expand Up @@ -34,11 +34,7 @@
#include "extconf.h"
#include "AbstractMemory.h"
#include "Type.h"
#ifdef RUBY_1_9
#include <ruby/st.h>
#else
#include <st.h>
#endif

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -77,7 +73,7 @@ extern "C" {

/** The number of reference tracking fields in this struct */
int referenceFieldCount;

VALUE rbFieldNames;
VALUE rbFieldMap;
VALUE rbFields;
Expand Down
18 changes: 9 additions & 9 deletions ext/ffi_c/StructLayout.c
Expand Up @@ -138,7 +138,7 @@ struct_field_initialize(int argc, VALUE* argv, VALUE self)
&& RTEST(rb_funcall2(rbType, rb_intern("reference_required?"), 0, NULL)));
break;
}

return self;
}

Expand Down Expand Up @@ -239,7 +239,7 @@ static VALUE
struct_field_put(VALUE self, VALUE pointer, VALUE value)
{
StructField* f;

Data_Get_Struct(self, StructField, f);
if (f->memoryOp == NULL) {
rb_raise(rb_eArgError, "put not supported for %s", rb_obj_classname(f->rbType));
Expand All @@ -261,7 +261,7 @@ static VALUE
function_field_get(VALUE self, VALUE pointer)
{
StructField* f;

Data_Get_Struct(self, StructField, f);

return rbffi_Function_NewInstance(f->rbType, (*rbffi_AbstractMemoryOps.pointer->get)(MEMORY(pointer), f->offset));
Expand All @@ -272,7 +272,7 @@ function_field_get(VALUE self, VALUE pointer)
* @param [AbstractMemory] pointer pointer to a {Struct}
* @param [Function, Proc] proc
* @return [Function]
* Set a {Function} to memory pointed by +pointer+ as a function.
* Set a {Function} to memory pointed by +pointer+ as a function.
*
* If a Proc is submitted as +proc+, it is automatically transformed to a {Function}.
*/
Expand Down Expand Up @@ -339,11 +339,11 @@ array_field_put(VALUE self, VALUE pointer, VALUE value)
{
StructField* f;
ArrayType* array;


Data_Get_Struct(self, StructField, f);
Data_Get_Struct(f->rbType, ArrayType, array);

if (isCharArray(array) && rb_obj_is_instance_of(value, rb_cString)) {
VALUE argv[2];

Expand Down Expand Up @@ -501,14 +501,14 @@ struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align)
return self;
}

/*
/*
* call-seq: [](field)
* @param [Symbol] field
* @return [StructLayout::Field]
* Get a field from the layout.
*/
static VALUE
struct_layout_union_bang(VALUE self)
struct_layout_union_bang(VALUE self)
{
const ffi_type *alignment_types[] = { &ffi_type_sint8, &ffi_type_sint16, &ffi_type_sint32, &ffi_type_sint64,
&ffi_type_float, &ffi_type_double, &ffi_type_longdouble, NULL };
Expand Down Expand Up @@ -627,7 +627,7 @@ rbffi_StructLayout_Init(VALUE moduleFFI)
*/
rbffi_StructLayoutClass = rb_define_class_under(moduleFFI, "StructLayout", ffi_Type);
rb_global_variable(&rbffi_StructLayoutClass);

/*
* Document-class: FFI::StructLayout::Field
* A field in a {StructLayout}.
Expand Down
1 change: 0 additions & 1 deletion ext/ffi_c/extconf.rb
Expand Up @@ -53,7 +53,6 @@ def system_libffi_usable?
end

$defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works
$defs << "-DRUBY_1_9" if RUBY_VERSION >= "1.9.0"
$defs << "-DFFI_BUILDING" if RbConfig::CONFIG['host_os'] =~ /mswin/ # for compatibility with newer libffi

create_header
Expand Down
3 changes: 1 addition & 2 deletions lib/ffi/struct.rb
Expand Up @@ -190,7 +190,7 @@ class << self
# :field2, :pointer, 6, # set offset to 6 for this field
# :field3, :string
# end
# @example Creating a layout from a hash +spec+ (Ruby 1.9 only)
# @example Creating a layout from a hash +spec+
# class MyStructFromHash < Struct
# layout :field1 => :int,
# :field2 => :pointer,
Expand All @@ -202,7 +202,6 @@ class << self
# :function2, callback([:pointer], :void),
# :field3, :string
# end
# @note Creating a layout from a hash +spec+ is supported only for Ruby 1.9.
def layout(*spec)
warn "[DEPRECATION] Struct layout is already defined for class #{self.inspect}. Redefinition as in #{caller[0]} will be disallowed in ffi-2.0." if defined?(@layout)
return @layout if spec.size == 0
Expand Down

0 comments on commit 6845314

Please sign in to comment.