ffi 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +1 -27
- data/Rakefile +9 -12
- data/ext/ffi_c/AbstractMemory.c +11 -8
- data/ext/ffi_c/AbstractMemory.h +23 -21
- data/ext/ffi_c/AutoPointer.c +0 -1
- data/ext/ffi_c/Buffer.c +24 -8
- data/ext/ffi_c/Call.c +28 -0
- data/ext/ffi_c/Call.h +8 -4
- data/ext/ffi_c/ClosurePool.c +7 -5
- data/ext/ffi_c/DynamicLibrary.c +0 -1
- data/ext/ffi_c/Function.c +19 -2
- data/ext/ffi_c/MemoryPointer.c +3 -3
- data/ext/ffi_c/MethodHandle.c +1 -1
- data/ext/ffi_c/Pointer.c +23 -9
- data/ext/ffi_c/Struct.c +142 -69
- data/ext/ffi_c/Struct.h +16 -7
- data/ext/ffi_c/StructLayout.c +92 -55
- data/ext/ffi_c/Type.c +5 -22
- data/ext/ffi_c/Type.h +1 -1
- data/ext/ffi_c/Types.c +8 -2
- data/ext/ffi_c/Types.h +2 -0
- data/ext/ffi_c/Variadic.c +7 -19
- data/ext/ffi_c/endian.h +1 -1
- data/ext/ffi_c/extconf.rb +20 -11
- data/ext/ffi_c/libffi/ChangeLog +900 -84
- data/ext/ffi_c/libffi/ChangeLog.libffi +311 -0
- data/ext/ffi_c/libffi/LICENSE +1 -1
- data/ext/ffi_c/libffi/Makefile.am +14 -4
- data/ext/ffi_c/libffi/Makefile.in +362 -211
- data/ext/ffi_c/libffi/README +70 -92
- data/ext/ffi_c/libffi/aclocal.m4 +6068 -4586
- data/ext/ffi_c/libffi/config.guess +125 -143
- data/ext/ffi_c/libffi/config.sub +103 -27
- data/ext/ffi_c/libffi/configure +11364 -18497
- data/ext/ffi_c/libffi/configure.ac +43 -4
- data/ext/ffi_c/libffi/doc/libffi.info +15 -15
- data/ext/ffi_c/libffi/doc/libffi.texi +1 -1
- data/ext/ffi_c/libffi/doc/stamp-vti +4 -4
- data/ext/ffi_c/libffi/doc/version.texi +4 -4
- data/ext/ffi_c/libffi/fficonfig.h.in +24 -3
- data/ext/ffi_c/libffi/include/Makefile.am +1 -1
- data/ext/ffi_c/libffi/include/Makefile.in +97 -50
- data/ext/ffi_c/libffi/include/ffi.h.in +8 -2
- data/ext/ffi_c/libffi/include/ffi_common.h +24 -0
- data/ext/ffi_c/libffi/libtool-version +1 -1
- data/ext/ffi_c/libffi/ltmain.sh +7346 -5870
- data/ext/ffi_c/libffi/m4/libtool.m4 +7360 -0
- data/ext/ffi_c/libffi/m4/ltoptions.m4 +368 -0
- data/ext/ffi_c/libffi/m4/ltsugar.m4 +123 -0
- data/ext/ffi_c/libffi/m4/ltversion.m4 +23 -0
- data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +92 -0
- data/ext/ffi_c/libffi/man/Makefile.in +115 -62
- data/ext/ffi_c/libffi/man/ffi_call.3 +3 -3
- data/ext/ffi_c/libffi/missing +15 -8
- data/ext/ffi_c/libffi/src/arm/sysv.S +15 -8
- data/ext/ffi_c/libffi/src/avr32/ffi.c +421 -0
- data/ext/ffi_c/libffi/src/avr32/ffitarget.h +50 -0
- data/ext/ffi_c/libffi/src/avr32/sysv.S +208 -0
- data/ext/ffi_c/libffi/src/closures.c +47 -10
- data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/java_raw_api.c +0 -3
- data/ext/ffi_c/libffi/src/mips/ffi.c +135 -32
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +37 -4
- data/ext/ffi_c/libffi/src/mips/n32.S +67 -10
- data/ext/ffi_c/libffi/src/mips/o32.S +8 -8
- data/ext/ffi_c/libffi/src/pa/ffi.c +7 -0
- data/ext/ffi_c/libffi/src/powerpc/aix.S +163 -64
- data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +308 -112
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +20 -7
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +208 -80
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +11 -3
- data/ext/ffi_c/libffi/src/powerpc/sysv.S +12 -23
- data/ext/ffi_c/libffi/src/s390/sysv.S +1 -1
- data/ext/ffi_c/libffi/src/sh/sysv.S +9 -9
- data/ext/ffi_c/libffi/src/sh64/ffi.c +37 -22
- data/ext/ffi_c/libffi/src/sh64/sysv.S +23 -14
- data/ext/ffi_c/libffi/src/sparc/ffi.c +21 -6
- data/ext/ffi_c/libffi/src/sparc/v8.S +55 -14
- data/ext/ffi_c/libffi/src/x86/darwin.S +10 -9
- data/ext/ffi_c/libffi/src/x86/ffi.c +293 -86
- data/ext/ffi_c/libffi/src/x86/ffi64.c +73 -19
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +30 -0
- data/ext/ffi_c/libffi/src/x86/sysv.S +21 -4
- data/ext/ffi_c/libffi/src/x86/unix64.S +8 -4
- data/ext/ffi_c/libffi/src/x86/win32.S +633 -147
- data/ext/ffi_c/libffi/src/x86/win64.S +460 -0
- data/ext/ffi_c/libffi/testsuite/Makefile.am +63 -54
- data/ext/ffi_c/libffi/testsuite/Makefile.in +112 -77
- data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +12 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +7 -14
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c +95 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_stdcall.c +6 -14
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +134 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +117 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +11 -17
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +66 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +57 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +4 -13
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +105 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +57 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +74 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +140 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +8 -16
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +37 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +25 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +31 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +2 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +342 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +145 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +148 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +124 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +124 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +4 -5
- data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest.cc +17 -16
- data/ext/ffi_c/libffi/texinfo.tex +155 -427
- data/ext/ffi_c/libffi.bsd.mk +1 -1
- data/lib/ffi/autopointer.rb +79 -20
- data/lib/ffi/buffer.rb +4 -0
- data/lib/ffi/callback.rb +4 -10
- data/lib/ffi/enum.rb +28 -0
- data/lib/ffi/ffi.rb +0 -1
- data/lib/ffi/io.rb +28 -0
- data/lib/ffi/library.rb +237 -182
- data/lib/ffi/memorypointer.rb +28 -62
- data/lib/ffi/platform.rb +27 -0
- data/lib/ffi/pointer.rb +28 -0
- data/lib/ffi/struct.rb +55 -1
- data/lib/ffi/types.rb +29 -0
- data/lib/ffi/variadic.rb +29 -0
- data/spec/ffi/library_spec.rb +31 -5
- data/spec/ffi/managed_struct_spec.rb +1 -1
- data/spec/ffi/pointer_spec.rb +1 -1
- data/spec/ffi/rbx/attach_function_spec.rb +2 -1
- data/spec/ffi/rbx/memory_pointer_spec.rb +2 -1
- data/spec/ffi/spec_helper.rb +5 -1
- data/spec/ffi/struct_spec.rb +77 -0
- metadata +28 -18
- data/ext/ffi_c/libffi/TODO +0 -1
- data/ext/ffi_c/libffi/ltcf-c.sh +0 -861
- data/ext/ffi_c/libffi/ltcf-cxx.sh +0 -1069
- data/ext/ffi_c/libffi/ltcf-gcj.sh +0 -700
- data/ext/ffi_c/libffi/ltconfig +0 -2862
- data/ext/ffi_c/libffi/mkinstalldirs +0 -158
data/ext/ffi_c/StructLayout.c
CHANGED
|
@@ -53,7 +53,6 @@ static void struct_field_mark(StructField* );
|
|
|
53
53
|
|
|
54
54
|
VALUE rbffi_StructLayoutFieldClass = Qnil;
|
|
55
55
|
VALUE rbffi_StructLayoutFunctionFieldClass = Qnil, rbffi_StructLayoutArrayFieldClass = Qnil;
|
|
56
|
-
VALUE rbffi_StructLayoutStructFieldClass = Qnil;
|
|
57
56
|
|
|
58
57
|
VALUE rbffi_StructLayoutClass = Qnil;
|
|
59
58
|
|
|
@@ -105,6 +104,7 @@ struct_field_initialize(int argc, VALUE* argv, VALUE self)
|
|
|
105
104
|
field->rbName = (TYPE(rbName) == T_SYMBOL) ? rbName : rb_str_intern(rbName);
|
|
106
105
|
field->rbType = rbType;
|
|
107
106
|
Data_Get_Struct(field->rbType, Type, field->type);
|
|
107
|
+
field->memoryOp = get_memory_op(field->type);
|
|
108
108
|
|
|
109
109
|
return self;
|
|
110
110
|
}
|
|
@@ -134,10 +134,11 @@ struct_field_alignment(VALUE self)
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
static VALUE
|
|
137
|
-
|
|
137
|
+
struct_field_type(VALUE self)
|
|
138
138
|
{
|
|
139
139
|
StructField* field;
|
|
140
140
|
Data_Get_Struct(self, StructField, field);
|
|
141
|
+
|
|
141
142
|
return field->rbType;
|
|
142
143
|
}
|
|
143
144
|
|
|
@@ -153,34 +154,28 @@ static VALUE
|
|
|
153
154
|
struct_field_get(VALUE self, VALUE pointer)
|
|
154
155
|
{
|
|
155
156
|
StructField* f;
|
|
156
|
-
MemoryOp* op;
|
|
157
|
-
AbstractMemory* memory = MEMORY(pointer);
|
|
158
157
|
|
|
159
158
|
Data_Get_Struct(self, StructField, f);
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
rb_raise(rb_eArgError, "get not supported for %s", rb_obj_classname(self));
|
|
159
|
+
if (f->memoryOp == NULL) {
|
|
160
|
+
rb_raise(rb_eArgError, "get not supported for %s", rb_obj_classname(f->rbType));
|
|
163
161
|
return Qnil;
|
|
164
162
|
}
|
|
165
163
|
|
|
166
|
-
return (*
|
|
164
|
+
return (*f->memoryOp->get)(MEMORY(pointer), f->offset);
|
|
167
165
|
}
|
|
168
166
|
|
|
169
167
|
static VALUE
|
|
170
168
|
struct_field_put(VALUE self, VALUE pointer, VALUE value)
|
|
171
169
|
{
|
|
172
170
|
StructField* f;
|
|
173
|
-
|
|
174
|
-
AbstractMemory* memory = MEMORY(pointer);
|
|
175
|
-
|
|
171
|
+
|
|
176
172
|
Data_Get_Struct(self, StructField, f);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
rb_raise(rb_eArgError, "put not supported for %s", rb_obj_classname(self));
|
|
173
|
+
if (f->memoryOp == NULL) {
|
|
174
|
+
rb_raise(rb_eArgError, "put not supported for %s", rb_obj_classname(f->rbType));
|
|
180
175
|
return self;
|
|
181
176
|
}
|
|
182
177
|
|
|
183
|
-
(*
|
|
178
|
+
(*f->memoryOp->put)(MEMORY(pointer), f->offset, value);
|
|
184
179
|
|
|
185
180
|
return self;
|
|
186
181
|
}
|
|
@@ -189,33 +184,19 @@ static VALUE
|
|
|
189
184
|
function_field_get(VALUE self, VALUE pointer)
|
|
190
185
|
{
|
|
191
186
|
StructField* f;
|
|
192
|
-
|
|
193
|
-
AbstractMemory* memory = MEMORY(pointer);
|
|
194
|
-
|
|
187
|
+
|
|
195
188
|
Data_Get_Struct(self, StructField, f);
|
|
196
|
-
op = memory->ops->pointer;
|
|
197
|
-
if (op == NULL) {
|
|
198
|
-
rb_raise(rb_eArgError, "get not supported for %s", rb_obj_classname(self));
|
|
199
|
-
return Qnil;
|
|
200
|
-
}
|
|
201
189
|
|
|
202
|
-
return rbffi_Function_NewInstance(f->rbType, (*
|
|
190
|
+
return rbffi_Function_NewInstance(f->rbType, (*rbffi_AbstractMemoryOps.pointer->get)(MEMORY(pointer), f->offset));
|
|
203
191
|
}
|
|
204
192
|
|
|
205
193
|
static VALUE
|
|
206
194
|
function_field_put(VALUE self, VALUE pointer, VALUE proc)
|
|
207
195
|
{
|
|
208
196
|
StructField* f;
|
|
209
|
-
MemoryOp* op;
|
|
210
|
-
AbstractMemory* memory = MEMORY(pointer);
|
|
211
197
|
VALUE value = Qnil;
|
|
212
198
|
|
|
213
199
|
Data_Get_Struct(self, StructField, f);
|
|
214
|
-
op = memory->ops->pointer;
|
|
215
|
-
if (op == NULL) {
|
|
216
|
-
rb_raise(rb_eArgError, "put not supported for %s", rb_obj_classname(self));
|
|
217
|
-
return self;
|
|
218
|
-
}
|
|
219
200
|
|
|
220
201
|
if (NIL_P(proc) || rb_obj_is_kind_of(proc, rbffi_FunctionClass)) {
|
|
221
202
|
value = proc;
|
|
@@ -225,51 +206,110 @@ function_field_put(VALUE self, VALUE pointer, VALUE proc)
|
|
|
225
206
|
rb_raise(rb_eTypeError, "wrong type (expected Proc or Function)");
|
|
226
207
|
}
|
|
227
208
|
|
|
228
|
-
(*
|
|
209
|
+
(*rbffi_AbstractMemoryOps.pointer->put)(MEMORY(pointer), f->offset, value);
|
|
229
210
|
|
|
230
211
|
return self;
|
|
231
212
|
}
|
|
232
213
|
|
|
214
|
+
static inline bool
|
|
215
|
+
isCharArray(ArrayType* arrayType)
|
|
216
|
+
{
|
|
217
|
+
return arrayType->componentType->nativeType == NATIVE_INT8
|
|
218
|
+
|| arrayType->componentType->nativeType == NATIVE_UINT8;
|
|
219
|
+
}
|
|
220
|
+
|
|
233
221
|
static VALUE
|
|
234
222
|
array_field_get(VALUE self, VALUE pointer)
|
|
235
223
|
{
|
|
236
224
|
StructField* f;
|
|
237
225
|
ArrayType* array;
|
|
238
|
-
MemoryOp* op;
|
|
239
|
-
AbstractMemory* memory = MEMORY(pointer);
|
|
240
226
|
VALUE argv[2];
|
|
241
227
|
|
|
242
228
|
Data_Get_Struct(self, StructField, f);
|
|
243
229
|
Data_Get_Struct(f->rbType, ArrayType, array);
|
|
244
230
|
|
|
245
|
-
op = memory_get_op(memory, array->componentType);
|
|
246
|
-
if (op == NULL) {
|
|
247
|
-
rb_raise(rb_eArgError, "get not supported for %s", rb_obj_classname(array->rbComponentType));
|
|
248
|
-
return Qnil;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
231
|
argv[0] = pointer;
|
|
252
232
|
argv[1] = self;
|
|
253
233
|
|
|
254
|
-
return rb_class_new_instance(2, argv,
|
|
234
|
+
return rb_class_new_instance(2, argv, isCharArray(array)
|
|
235
|
+
? rbffi_StructLayoutCharArrayClass : rbffi_StructInlineArrayClass);
|
|
255
236
|
}
|
|
256
237
|
|
|
257
238
|
static VALUE
|
|
258
|
-
|
|
239
|
+
array_field_put(VALUE self, VALUE pointer, VALUE value)
|
|
259
240
|
{
|
|
260
241
|
StructField* f;
|
|
261
|
-
|
|
262
|
-
|
|
242
|
+
ArrayType* array;
|
|
243
|
+
|
|
263
244
|
|
|
264
245
|
Data_Get_Struct(self, StructField, f);
|
|
265
|
-
Data_Get_Struct(f->rbType,
|
|
246
|
+
Data_Get_Struct(f->rbType, ArrayType, array);
|
|
247
|
+
|
|
248
|
+
if (isCharArray(array) && rb_obj_is_instance_of(value, rb_cString)) {
|
|
249
|
+
VALUE argv[2];
|
|
250
|
+
|
|
251
|
+
argv[0] = INT2FIX(f->offset);
|
|
252
|
+
argv[1] = value;
|
|
266
253
|
|
|
267
|
-
|
|
268
|
-
rbPointer = rb_funcall2(pointer, rb_intern("+"), 1, &rbOffset);
|
|
254
|
+
rb_funcall2(pointer, rb_intern("put_string"), 2, argv);
|
|
269
255
|
|
|
270
|
-
|
|
256
|
+
} else {
|
|
257
|
+
#ifdef notyet
|
|
258
|
+
MemoryOp* op;
|
|
259
|
+
int count = RARRAY_LEN(value);
|
|
260
|
+
int i;
|
|
261
|
+
AbstractMemory* memory = MEMORY(pointer);
|
|
262
|
+
|
|
263
|
+
if (count > array->length) {
|
|
264
|
+
rb_raise(rb_eIndexError, "array too large");
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// clear the contents in case of a short write
|
|
268
|
+
checkWrite(memory);
|
|
269
|
+
checkBounds(memory, f->offset, f->type->ffiType->size);
|
|
270
|
+
if (count < array->length) {
|
|
271
|
+
memset(memory->address + f->offset + (count * array->componentType->ffiType->size),
|
|
272
|
+
0, (array->length - count) * array->componentType->ffiType->size);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// now copy each element in
|
|
276
|
+
if ((op = get_memory_op(array->componentType)) != NULL) {
|
|
277
|
+
|
|
278
|
+
for (i = 0; i < count; ++i) {
|
|
279
|
+
(*op->put)(memory, f->offset + (i * array->componentType->ffiType->size), rb_ary_entry(value, i));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
} else if (array->componentType->nativeType == NATIVE_STRUCT) {
|
|
283
|
+
|
|
284
|
+
for (i = 0; i < count; ++i) {
|
|
285
|
+
VALUE entry = rb_ary_entry(value, i);
|
|
286
|
+
Struct* s;
|
|
287
|
+
|
|
288
|
+
if (!rb_obj_is_kind_of(entry, rbffi_StructClass)) {
|
|
289
|
+
rb_raise(rb_eTypeError, "array element not an instance of FFI::Struct");
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
Data_Get_Struct(entry, Struct, s);
|
|
294
|
+
checkRead(s->pointer);
|
|
295
|
+
checkBounds(s->pointer, 0, array->componentType->ffiType->size);
|
|
296
|
+
|
|
297
|
+
memcpy(memory->address + f->offset + (i * array->componentType->ffiType->size),
|
|
298
|
+
s->pointer->address, array->componentType->ffiType->size);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
} else {
|
|
302
|
+
rb_raise(rb_eNotImpError, "put not supported for arrays of type %s", rb_obj_classname(array->rbComponentType));
|
|
303
|
+
}
|
|
304
|
+
#else
|
|
305
|
+
rb_raise(rb_eNotImpError, "cannot set array field");
|
|
306
|
+
#endif
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return value;
|
|
271
310
|
}
|
|
272
311
|
|
|
312
|
+
|
|
273
313
|
static VALUE
|
|
274
314
|
struct_layout_allocate(VALUE klass)
|
|
275
315
|
{
|
|
@@ -309,7 +349,7 @@ struct_layout_initialize(VALUE self, VALUE field_names, VALUE fields, VALUE size
|
|
|
309
349
|
layout->base.ffiType->alignment = 1;
|
|
310
350
|
|
|
311
351
|
ltype = layout->base.ffiType;
|
|
312
|
-
for (i = 0; i < layout->fieldCount; ++i) {
|
|
352
|
+
for (i = 0; i < (int) layout->fieldCount; ++i) {
|
|
313
353
|
VALUE rbName = rb_ary_entry(field_names, i);
|
|
314
354
|
VALUE rbField = rb_hash_aref(fields, rbName);
|
|
315
355
|
StructField* field;
|
|
@@ -405,6 +445,7 @@ struct_layout_free(StructLayout *layout)
|
|
|
405
445
|
xfree(layout);
|
|
406
446
|
}
|
|
407
447
|
|
|
448
|
+
|
|
408
449
|
void
|
|
409
450
|
rbffi_StructLayout_Init(VALUE moduleFFI)
|
|
410
451
|
{
|
|
@@ -417,9 +458,6 @@ rbffi_StructLayout_Init(VALUE moduleFFI)
|
|
|
417
458
|
rbffi_StructLayoutFunctionFieldClass = rb_define_class_under(rbffi_StructLayoutClass, "Function", rbffi_StructLayoutFieldClass);
|
|
418
459
|
rb_global_variable(&rbffi_StructLayoutFunctionFieldClass);
|
|
419
460
|
|
|
420
|
-
rbffi_StructLayoutStructFieldClass = rb_define_class_under(rbffi_StructLayoutClass, "StructByValue", rbffi_StructLayoutFieldClass);
|
|
421
|
-
rb_global_variable(&rbffi_StructLayoutStructFieldClass);
|
|
422
|
-
|
|
423
461
|
rbffi_StructLayoutArrayFieldClass = rb_define_class_under(rbffi_StructLayoutClass, "Array", rbffi_StructLayoutFieldClass);
|
|
424
462
|
rb_global_variable(&rbffi_StructLayoutArrayFieldClass);
|
|
425
463
|
|
|
@@ -429,7 +467,7 @@ rbffi_StructLayout_Init(VALUE moduleFFI)
|
|
|
429
467
|
rb_define_method(rbffi_StructLayoutFieldClass, "size", struct_field_size, 0);
|
|
430
468
|
rb_define_method(rbffi_StructLayoutFieldClass, "alignment", struct_field_alignment, 0);
|
|
431
469
|
rb_define_method(rbffi_StructLayoutFieldClass, "name", struct_field_name, 0);
|
|
432
|
-
rb_define_method(rbffi_StructLayoutFieldClass, "
|
|
470
|
+
rb_define_method(rbffi_StructLayoutFieldClass, "type", struct_field_type, 0);
|
|
433
471
|
rb_define_method(rbffi_StructLayoutFieldClass, "put", struct_field_put, 2);
|
|
434
472
|
rb_define_method(rbffi_StructLayoutFieldClass, "get", struct_field_get, 1);
|
|
435
473
|
|
|
@@ -437,8 +475,7 @@ rbffi_StructLayout_Init(VALUE moduleFFI)
|
|
|
437
475
|
rb_define_method(rbffi_StructLayoutFunctionFieldClass, "get", function_field_get, 1);
|
|
438
476
|
|
|
439
477
|
rb_define_method(rbffi_StructLayoutArrayFieldClass, "get", array_field_get, 1);
|
|
440
|
-
rb_define_method(
|
|
441
|
-
|
|
478
|
+
rb_define_method(rbffi_StructLayoutArrayFieldClass, "put", array_field_put, 2);
|
|
442
479
|
|
|
443
480
|
rb_define_alloc_func(rbffi_StructLayoutClass, struct_layout_allocate);
|
|
444
481
|
rb_define_method(rbffi_StructLayoutClass, "initialize", struct_layout_initialize, 4);
|
data/ext/ffi_c/Type.c
CHANGED
|
@@ -42,7 +42,7 @@ typedef struct BuiltinType_ {
|
|
|
42
42
|
|
|
43
43
|
static void builtin_type_free(BuiltinType *);
|
|
44
44
|
|
|
45
|
-
VALUE rbffi_TypeClass = Qnil;
|
|
45
|
+
VALUE rbffi_TypeClass = Qnil, rbffi_EnumTypeClass = Qnil;
|
|
46
46
|
|
|
47
47
|
static VALUE classBuiltinType = Qnil;
|
|
48
48
|
static VALUE typeMap = Qnil, sizeMap = Qnil;
|
|
@@ -243,7 +243,7 @@ rbffi_Type_Init(VALUE moduleFFI)
|
|
|
243
243
|
{
|
|
244
244
|
VALUE moduleNativeType;
|
|
245
245
|
VALUE classType = rbffi_TypeClass = rb_define_class_under(moduleFFI, "Type", rb_cObject);
|
|
246
|
-
VALUE classEnum =
|
|
246
|
+
VALUE classEnum = rbffi_EnumTypeClass = rb_define_class_under(moduleFFI, "Enum", classType);
|
|
247
247
|
|
|
248
248
|
rb_define_const(moduleFFI, "TypeDefs", typeMap = rb_hash_new());
|
|
249
249
|
rb_define_const(moduleFFI, "SizeTypes", sizeMap = rb_hash_new());
|
|
@@ -293,6 +293,8 @@ rbffi_Type_Init(VALUE moduleFFI)
|
|
|
293
293
|
T(UINT32, &ffi_type_uint32);
|
|
294
294
|
T(INT64, &ffi_type_sint64);
|
|
295
295
|
T(UINT64, &ffi_type_uint64);
|
|
296
|
+
T(LONG, &ffi_type_slong);
|
|
297
|
+
T(ULONG, &ffi_type_ulong);
|
|
296
298
|
T(FLOAT32, &ffi_type_float);
|
|
297
299
|
T(FLOAT64, &ffi_type_double);
|
|
298
300
|
T(POINTER, &ffi_type_pointer);
|
|
@@ -302,28 +304,9 @@ rbffi_Type_Init(VALUE moduleFFI)
|
|
|
302
304
|
T(BUFFER_OUT, &ffi_type_pointer);
|
|
303
305
|
T(BUFFER_INOUT, &ffi_type_pointer);
|
|
304
306
|
T(ENUM, &ffi_type_sint);
|
|
305
|
-
T(BOOL, &
|
|
307
|
+
T(BOOL, &ffi_type_uchar);
|
|
306
308
|
|
|
307
309
|
|
|
308
310
|
T(CHAR_ARRAY, &ffi_type_void);
|
|
309
311
|
T(VARARGS, &ffi_type_void);
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (sizeof(long) == 4) {
|
|
313
|
-
VALUE t = Qnil;
|
|
314
|
-
rb_define_const(classType, "LONG", t = builtin_type_new(classBuiltinType, NATIVE_INT32, &ffi_type_slong, "LONG"));
|
|
315
|
-
rb_define_const(moduleNativeType, "LONG", t);
|
|
316
|
-
rb_define_const(moduleFFI, "TYPE_LONG", t);
|
|
317
|
-
rb_define_const(classType, "ULONG", t = builtin_type_new(classBuiltinType, NATIVE_UINT32, &ffi_type_slong, "ULONG"));
|
|
318
|
-
rb_define_const(moduleNativeType, "ULONG", t);
|
|
319
|
-
rb_define_const(moduleFFI, "TYPE_ULONG", t);
|
|
320
|
-
} else {
|
|
321
|
-
VALUE t = Qnil;
|
|
322
|
-
rb_define_const(classType, "LONG", t = builtin_type_new(classBuiltinType, NATIVE_INT64, &ffi_type_slong, "LONG"));
|
|
323
|
-
rb_define_const(moduleNativeType, "LONG", t);
|
|
324
|
-
rb_define_const(moduleFFI, "TYPE_LONG", t);
|
|
325
|
-
rb_define_const(classType, "ULONG", t = builtin_type_new(classBuiltinType, NATIVE_UINT64, &ffi_type_slong, "ULONG"));
|
|
326
|
-
rb_define_const(moduleNativeType, "ULONG", t);
|
|
327
|
-
rb_define_const(moduleFFI, "TYPE_ULONG", t);
|
|
328
|
-
}
|
|
329
312
|
}
|
data/ext/ffi_c/Type.h
CHANGED
|
@@ -44,7 +44,7 @@ struct Type_ {
|
|
|
44
44
|
ffi_type* ffiType;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
extern VALUE rbffi_TypeClass;
|
|
47
|
+
extern VALUE rbffi_TypeClass, rbffi_EnumTypeClass;
|
|
48
48
|
extern int rbffi_Type_GetIntValue(VALUE type);
|
|
49
49
|
extern VALUE rbffi_Type_Lookup(VALUE type);
|
|
50
50
|
extern VALUE rbffi_Type_Find(VALUE type);
|
data/ext/ffi_c/Types.c
CHANGED
|
@@ -51,16 +51,22 @@ rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr, VALUE enums)
|
|
|
51
51
|
return INT2NUM((signed short) *(ffi_sarg *) ptr);
|
|
52
52
|
case NATIVE_INT32:
|
|
53
53
|
return INT2NUM((signed int) *(ffi_sarg *) ptr);
|
|
54
|
+
case NATIVE_LONG:
|
|
55
|
+
return LONG2NUM((signed long) *(ffi_sarg *) ptr);
|
|
56
|
+
case NATIVE_INT64:
|
|
57
|
+
return LL2NUM(*(signed long long *) ptr);
|
|
58
|
+
|
|
54
59
|
case NATIVE_UINT8:
|
|
55
60
|
return UINT2NUM((unsigned char) *(ffi_arg *) ptr);
|
|
56
61
|
case NATIVE_UINT16:
|
|
57
62
|
return UINT2NUM((unsigned short) *(ffi_arg *) ptr);
|
|
58
63
|
case NATIVE_UINT32:
|
|
59
64
|
return UINT2NUM((unsigned int) *(ffi_arg *) ptr);
|
|
60
|
-
case
|
|
61
|
-
return
|
|
65
|
+
case NATIVE_ULONG:
|
|
66
|
+
return ULONG2NUM((unsigned long) *(ffi_arg *) ptr);
|
|
62
67
|
case NATIVE_UINT64:
|
|
63
68
|
return ULL2NUM(*(unsigned long long *) ptr);
|
|
69
|
+
|
|
64
70
|
case NATIVE_FLOAT32:
|
|
65
71
|
return rb_float_new(*(float *) ptr);
|
|
66
72
|
case NATIVE_FLOAT64:
|
data/ext/ffi_c/Types.h
CHANGED
data/ext/ffi_c/Variadic.c
CHANGED
|
@@ -145,28 +145,12 @@ variadic_initialize(VALUE self, VALUE rbFunction, VALUE rbParameterTypes, VALUE
|
|
|
145
145
|
return retval;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
static inline VALUE
|
|
150
|
-
ffi_invoke(ffi_cif* cif, void* function, Type* returnType, void** ffiValues,
|
|
151
|
-
VALUE rbReturnType, VALUE rbEnums)
|
|
152
|
-
{
|
|
153
|
-
FFIStorage retval;
|
|
154
|
-
|
|
155
|
-
#ifdef USE_RAW
|
|
156
|
-
ffi_raw_call(cif, function, &retval, (ffi_raw *) ffiValues[0]);
|
|
157
|
-
#else
|
|
158
|
-
ffi_call(cif, function, &retval, ffiValues);
|
|
159
|
-
#endif
|
|
160
|
-
rbffi_save_errno();
|
|
161
|
-
|
|
162
|
-
return rbffi_NativeValue_ToRuby(returnType, rbReturnType, &retval, rbEnums);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
148
|
static VALUE
|
|
166
149
|
variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
|
|
167
150
|
{
|
|
168
151
|
VariadicInvoker* invoker;
|
|
169
152
|
FFIStorage* params;
|
|
153
|
+
void* retval;
|
|
170
154
|
ffi_cif cif;
|
|
171
155
|
void** ffiValues;
|
|
172
156
|
ffi_type** ffiParamTypes;
|
|
@@ -186,6 +170,7 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
|
|
|
186
170
|
params = ALLOCA_N(FFIStorage, paramCount);
|
|
187
171
|
ffiValues = ALLOCA_N(void*, paramCount);
|
|
188
172
|
argv = ALLOCA_N(VALUE, paramCount);
|
|
173
|
+
retval = alloca(MAX(invoker->returnType->ffiType->size, FFI_SIZEOF_ARG));
|
|
189
174
|
|
|
190
175
|
for (i = 0; i < paramCount; ++i) {
|
|
191
176
|
VALUE entry = rb_ary_entry(parameterTypes, i);
|
|
@@ -241,8 +226,11 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
|
|
|
241
226
|
rbffi_SetupCallParams(paramCount, argv, -1, paramTypes, params,
|
|
242
227
|
ffiValues, NULL, 0, invoker->rbEnums);
|
|
243
228
|
|
|
244
|
-
|
|
245
|
-
|
|
229
|
+
ffi_call(&cif, invoker->function, retval, ffiValues);
|
|
230
|
+
|
|
231
|
+
rbffi_save_errno();
|
|
232
|
+
|
|
233
|
+
return rbffi_NativeValue_ToRuby(invoker->returnType, invoker->rbReturnType, retval, invoker->rbEnums);
|
|
246
234
|
}
|
|
247
235
|
|
|
248
236
|
|
data/ext/ffi_c/endian.h
CHANGED
data/ext/ffi_c/extconf.rb
CHANGED
|
@@ -3,22 +3,31 @@ require 'mkmf'
|
|
|
3
3
|
require 'rbconfig'
|
|
4
4
|
dir_config("ffi_c")
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
unless Config::CONFIG['host_os'] =~ /mswin32|mingw32/
|
|
7
|
+
if pkg_config("libffi") || find_header("ffi.h", "/usr/local/include")
|
|
8
|
+
|
|
9
|
+
# We need at least ffi_call and ffi_prep_closure
|
|
10
|
+
libffi_ok = have_library("ffi", "ffi_call", [ "ffi.h" ]) && have_func("ffi_prep_closure")
|
|
11
|
+
|
|
12
|
+
# Check if the raw api is available.
|
|
13
|
+
$defs << "-DHAVE_RAW_API" if have_func("ffi_raw_call") && have_func("ffi_prep_raw_closure")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
12
16
|
|
|
13
17
|
have_func('rb_thread_blocking_region')
|
|
14
18
|
|
|
19
|
+
$defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works
|
|
20
|
+
$defs << "-DUSE_INTERNAL_LIBFFI" unless libffi_ok
|
|
21
|
+
|
|
22
|
+
create_header
|
|
23
|
+
|
|
24
|
+
$CFLAGS << " -mwin32 " if Config::CONFIG['host_os'] =~ /cygwin/
|
|
25
|
+
#$CFLAGS << " -Werror -Wunused -Wformat -Wimplicit -Wreturn-type "
|
|
26
|
+
|
|
15
27
|
create_makefile("ffi_c")
|
|
16
|
-
|
|
17
|
-
File.open("Makefile", "a") do |mf|
|
|
18
|
-
mf.puts "CPPFLAGS += -Werror -Wunused -Wformat -Wimplicit -Wreturn-type"
|
|
19
|
-
unless libffi_ok
|
|
28
|
+
unless libffi_ok
|
|
29
|
+
File.open("Makefile", "a") do |mf|
|
|
20
30
|
mf.puts "LIBFFI_HOST=--host=#{Config::CONFIG['host_alias']}" if Config::CONFIG.has_key?("host_alias")
|
|
21
|
-
mf.puts "FFI_MMAP_EXEC=-DFFI_MMAP_EXEC_WRIT=#{Config::CONFIG['host_os'] =~ /(win32|mingw)/ ? 0 : 1}"
|
|
22
31
|
if Config::CONFIG['host_os'].downcase =~ /darwin/
|
|
23
32
|
mf.puts "include ${srcdir}/libffi.darwin.mk"
|
|
24
33
|
elsif Config::CONFIG['host_os'].downcase =~ /bsd/
|