ffi 0.5.4-x86-mingw32 → 0.6.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ffi might be problematic. Click here for more details.
- data/History.txt +102 -0
- data/LICENSE +1 -27
- data/Rakefile +4 -12
- data/ext/ffi_c/AbstractMemory.c +6 -8
- data/ext/ffi_c/AbstractMemory.h +23 -21
- data/ext/ffi_c/AutoPointer.c +0 -1
- data/ext/ffi_c/Buffer.c +23 -8
- data/ext/ffi_c/Call.c +31 -3
- data/ext/ffi_c/Call.h +5 -1
- data/ext/ffi_c/DynamicLibrary.c +0 -1
- data/ext/ffi_c/Function.c +22 -4
- data/ext/ffi_c/MemoryPointer.c +2 -3
- data/ext/ffi_c/Pointer.c +23 -9
- data/ext/ffi_c/Struct.c +227 -79
- 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 +9 -3
- data/ext/ffi_c/Types.h +2 -0
- data/ext/ffi_c/extconf.rb +11 -7
- data/ext/ffi_c/libffi.gnu.mk +1 -1
- data/ext/ffi_c/libffi.mk +1 -1
- 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 +11340 -18473
- 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/gen/Rakefile +4 -2
- data/lib/1.8/ffi_c.so +0 -0
- data/lib/1.9/ffi_c.so +0 -0
- data/lib/ffi/autopointer.rb +79 -20
- data/lib/ffi/callback.rb +4 -10
- data/lib/ffi/enum.rb +28 -0
- data/lib/ffi/ffi.rb +1 -0
- 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/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 +82 -0
- data/tasks/ann.rake +80 -0
- data/tasks/extension.rake +25 -0
- data/tasks/gem.rake +200 -0
- data/tasks/git.rake +41 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +34 -0
- data/tasks/rdoc.rake +50 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +300 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- metadata +312 -279
- 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/Struct.h
CHANGED
@@ -39,16 +39,24 @@ extern "C" {
|
|
39
39
|
|
40
40
|
extern void rbffi_Struct_Init(VALUE ffiModule);
|
41
41
|
extern void rbffi_StructLayout_Init(VALUE ffiModule);
|
42
|
+
typedef struct StructField_ StructField;
|
43
|
+
typedef struct StructLayout_ StructLayout;
|
44
|
+
typedef struct Struct_ Struct;
|
42
45
|
|
43
|
-
|
46
|
+
struct StructField_ {
|
44
47
|
Type* type;
|
45
48
|
unsigned int offset;
|
46
49
|
|
47
50
|
VALUE rbType;
|
48
51
|
VALUE rbName;
|
49
|
-
} StructField;
|
50
52
|
|
51
|
-
|
53
|
+
VALUE (*get)(StructField* field, Struct* s);
|
54
|
+
void (*put)(StructField* field, Struct* s, VALUE value);
|
55
|
+
|
56
|
+
MemoryOp* memoryOp;
|
57
|
+
};
|
58
|
+
|
59
|
+
struct StructLayout_ {
|
52
60
|
Type base;
|
53
61
|
StructField** fields;
|
54
62
|
unsigned int fieldCount;
|
@@ -58,19 +66,20 @@ extern "C" {
|
|
58
66
|
VALUE rbFieldNames;
|
59
67
|
VALUE rbFieldMap;
|
60
68
|
VALUE rbFields;
|
61
|
-
}
|
69
|
+
};
|
62
70
|
|
63
|
-
|
71
|
+
struct Struct_ {
|
64
72
|
StructLayout* layout;
|
65
73
|
AbstractMemory* pointer;
|
66
74
|
VALUE rbLayout;
|
67
75
|
VALUE rbPointer;
|
68
|
-
}
|
76
|
+
};
|
69
77
|
|
70
78
|
extern VALUE rbffi_StructClass, rbffi_StructLayoutClass;
|
71
79
|
extern VALUE rbffi_StructLayoutFieldClass, rbffi_StructLayoutFunctionFieldClass;
|
72
|
-
extern VALUE rbffi_StructLayoutArrayFieldClass
|
80
|
+
extern VALUE rbffi_StructLayoutArrayFieldClass;
|
73
81
|
extern VALUE rbffi_StructInlineArrayClass;
|
82
|
+
extern VALUE rbffi_StructLayoutCharArrayClass;
|
74
83
|
|
75
84
|
#ifdef __cplusplus
|
76
85
|
}
|
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:
|
@@ -70,7 +76,7 @@ rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr, VALUE enums)
|
|
70
76
|
case NATIVE_POINTER:
|
71
77
|
return rbffi_Pointer_NewInstance(*(void **) ptr);
|
72
78
|
case NATIVE_BOOL:
|
73
|
-
return ((
|
79
|
+
return ((unsigned char) *(ffi_arg *) ptr) ? Qtrue : Qfalse;
|
74
80
|
case NATIVE_ENUM:
|
75
81
|
return rb_funcall(rbType, id_find, 1, INT2NUM((unsigned int) *(ffi_arg *) ptr));
|
76
82
|
|
data/ext/ffi_c/Types.h
CHANGED
data/ext/ffi_c/extconf.rb
CHANGED
@@ -4,21 +4,25 @@ require 'rbconfig'
|
|
4
4
|
dir_config("ffi_c")
|
5
5
|
|
6
6
|
unless Config::CONFIG['host_os'] =~ /mswin32|mingw32/
|
7
|
-
pkg_config("libffi") || find_header("ffi.h", "/usr/local/include"
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
13
15
|
end
|
16
|
+
|
14
17
|
have_func('rb_thread_blocking_region')
|
15
18
|
|
16
19
|
$defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works
|
20
|
+
$defs << "-DUSE_INTERNAL_LIBFFI" unless libffi_ok
|
17
21
|
|
18
22
|
create_header
|
19
23
|
|
20
24
|
$CFLAGS << " -mwin32 " if Config::CONFIG['host_os'] =~ /cygwin/
|
21
|
-
|
25
|
+
#$CFLAGS << " -Werror -Wunused -Wformat -Wimplicit -Wreturn-type "
|
22
26
|
|
23
27
|
create_makefile("ffi_c")
|
24
28
|
unless libffi_ok
|