ffi 1.0.9-x86-mingw32 → 1.0.12.pre-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/Rakefile +16 -16
- data/ext/ffi_c/AbstractMemory.c +376 -14
- data/ext/ffi_c/AbstractMemory.h +8 -0
- data/ext/ffi_c/ArrayType.c +28 -0
- data/ext/ffi_c/Buffer.c +109 -25
- data/ext/ffi_c/Call.c +16 -5
- data/ext/ffi_c/ClosurePool.c +21 -8
- data/ext/ffi_c/DataConverter.c +29 -0
- data/ext/ffi_c/DynamicLibrary.c +71 -2
- data/ext/ffi_c/Function.c +122 -11
- data/ext/ffi_c/Function.h +6 -0
- data/ext/ffi_c/FunctionInfo.c +21 -1
- data/ext/ffi_c/LastError.c +24 -0
- data/ext/ffi_c/MappedType.c +22 -0
- data/ext/ffi_c/MemoryPointer.c +19 -1
- data/ext/ffi_c/MemoryPointer.h +6 -0
- data/ext/ffi_c/MethodHandle.c +26 -11
- data/ext/ffi_c/Platform.c +17 -3
- data/ext/ffi_c/Pointer.c +106 -0
- data/ext/ffi_c/Pointer.h +6 -0
- data/ext/ffi_c/Struct.c +10 -4
- data/ext/ffi_c/Struct.h +2 -1
- data/ext/ffi_c/StructByReference.c +8 -0
- data/ext/ffi_c/StructByValue.c +8 -0
- data/ext/ffi_c/StructLayout.c +8 -2
- data/ext/ffi_c/Thread.c +131 -1
- data/ext/ffi_c/Thread.h +6 -0
- data/ext/ffi_c/Type.c +111 -17
- data/ext/ffi_c/Types.c +9 -2
- data/ext/ffi_c/Types.h +4 -0
- data/ext/ffi_c/Variadic.c +13 -4
- data/ext/ffi_c/compat.h +8 -0
- data/ext/ffi_c/endian.h +10 -1
- data/ext/ffi_c/extconf.rb +51 -35
- data/ext/ffi_c/ffi.c +5 -0
- data/ext/ffi_c/libffi.darwin.mk +15 -15
- data/ext/ffi_c/libffi.gnu.mk +3 -3
- data/ext/ffi_c/libffi.mk +4 -4
- data/ext/ffi_c/libffi.vc.mk +26 -0
- data/ext/ffi_c/libffi.vc64.mk +26 -0
- data/ext/ffi_c/libffi/ChangeLog +541 -0
- data/ext/ffi_c/libffi/ChangeLog.libffi +13 -87
- data/ext/ffi_c/libffi/LICENSE +3 -3
- data/ext/ffi_c/libffi/Makefile.am +41 -32
- data/ext/ffi_c/libffi/Makefile.in +95 -66
- data/ext/ffi_c/libffi/Makefile.vc +141 -0
- data/ext/ffi_c/libffi/Makefile.vc64 +141 -0
- data/ext/ffi_c/libffi/README +40 -4
- data/ext/ffi_c/libffi/aclocal.m4 +729 -7854
- data/ext/ffi_c/libffi/build-ios.sh +67 -0
- data/ext/ffi_c/libffi/compile +11 -10
- data/ext/ffi_c/libffi/config.guess +4 -1
- data/ext/ffi_c/libffi/config.sub +6 -3
- data/ext/ffi_c/libffi/configure +6264 -6354
- data/ext/ffi_c/libffi/configure.ac +155 -63
- data/ext/ffi_c/libffi/depcomp +81 -35
- data/ext/ffi_c/libffi/doc/libffi.info +78 -18
- data/ext/ffi_c/libffi/doc/libffi.texi +64 -5
- 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 +18 -0
- data/ext/ffi_c/libffi/fficonfig.hw +57 -0
- data/ext/ffi_c/libffi/include/Makefile.in +21 -3
- data/ext/ffi_c/libffi/include/ffi.h.in +42 -14
- data/ext/ffi_c/libffi/include/ffi.h.vc +427 -0
- data/ext/ffi_c/libffi/include/ffi.h.vc64 +427 -0
- data/ext/ffi_c/libffi/include/ffi_common.h +9 -5
- data/ext/ffi_c/libffi/install-sh +364 -167
- data/ext/ffi_c/libffi/ltmain.sh +2599 -1369
- data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +176 -0
- data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +195 -0
- data/ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 +76 -0
- data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +63 -0
- data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
- data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +300 -0
- data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +215 -0
- data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +79 -0
- data/ext/ffi_c/libffi/m4/libtool.m4 +1239 -768
- data/ext/ffi_c/libffi/m4/ltoptions.m4 +7 -6
- data/ext/ffi_c/libffi/m4/ltversion.m4 +6 -6
- data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +9 -3
- data/ext/ffi_c/libffi/man/Makefile.in +21 -3
- data/ext/ffi_c/libffi/mdate-sh +0 -0
- data/ext/ffi_c/libffi/missing +60 -44
- data/ext/ffi_c/libffi/msvcc.sh +197 -0
- data/ext/ffi_c/libffi/src/alpha/osf.S +39 -18
- data/ext/ffi_c/libffi/src/arm/ffi.c +443 -24
- data/ext/ffi_c/libffi/src/arm/ffitarget.h +17 -1
- data/ext/ffi_c/libffi/src/arm/gentramp.sh +118 -0
- data/ext/ffi_c/libffi/src/arm/sysv.S +206 -15
- data/ext/ffi_c/libffi/src/arm/trampoline.S +4450 -0
- data/ext/ffi_c/libffi/src/avr32/ffi.c +4 -2
- data/ext/ffi_c/libffi/src/avr32/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/closures.c +17 -35
- data/ext/ffi_c/libffi/src/cris/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/cris/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/dlmalloc.c +66 -4
- data/ext/ffi_c/libffi/src/frv/ffitarget.h +2 -6
- data/ext/ffi_c/libffi/src/ia64/ffi.c +7 -5
- data/ext/ffi_c/libffi/src/ia64/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/java_raw_api.c +1 -1
- data/ext/ffi_c/libffi/src/m32r/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/m68k/ffi.c +10 -0
- data/ext/ffi_c/libffi/src/m68k/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/m68k/sysv.S +36 -0
- data/ext/ffi_c/libffi/src/mips/ffi.c +12 -5
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +18 -11
- data/ext/ffi_c/libffi/src/mips/n32.S +4 -4
- data/ext/ffi_c/libffi/src/moxie/eabi.S +128 -0
- data/ext/ffi_c/libffi/src/moxie/ffi.c +276 -0
- data/ext/ffi_c/libffi/src/pa/ffi.c +7 -4
- data/ext/ffi_c/libffi/src/pa/ffitarget.h +6 -5
- data/ext/ffi_c/libffi/src/powerpc/aix.S +5 -1
- data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +2 -0
- data/ext/ffi_c/libffi/src/powerpc/asm.h +1 -1
- data/ext/ffi_c/libffi/src/powerpc/darwin.S +215 -77
- data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +358 -100
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +11 -5
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +603 -172
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +17 -4
- data/ext/ffi_c/libffi/src/prep_cif.c +16 -13
- data/ext/ffi_c/libffi/src/s390/ffitarget.h +4 -2
- data/ext/ffi_c/libffi/src/sh/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/sh64/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/sparc/ffi.c +55 -11
- data/ext/ffi_c/libffi/src/sparc/ffitarget.h +5 -3
- data/ext/ffi_c/libffi/src/x86/ffi.c +54 -92
- data/ext/ffi_c/libffi/src/x86/ffi64.c +17 -8
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -14
- data/ext/ffi_c/libffi/src/x86/sysv.S +40 -26
- data/ext/ffi_c/libffi/src/x86/unix64.S +4 -0
- data/ext/ffi_c/libffi/src/x86/win32.S +379 -191
- data/ext/ffi_c/libffi/src/x86/win64.S +15 -7
- data/ext/ffi_c/libffi/testsuite/Makefile.am +1 -1
- data/ext/ffi_c/libffi/testsuite/Makefile.in +22 -4
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +350 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +1 -5
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +2 -3
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +2 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +36 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +17 -17
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +1 -3
- data/ext/ffi_c/win32/stdint.h +199 -0
- data/gen/Rakefile +18 -2
- data/lib/1.8/ffi_c.so +0 -0
- data/lib/ffi.rb +13 -9
- data/lib/ffi/autopointer.rb +88 -26
- data/lib/ffi/enum.rb +42 -0
- data/lib/ffi/errno.rb +6 -1
- data/lib/ffi/ffi.rb +1 -0
- data/lib/ffi/io.rb +13 -2
- data/lib/ffi/library.rb +219 -24
- data/lib/ffi/memorypointer.rb +1 -33
- data/lib/ffi/platform.rb +21 -7
- data/lib/ffi/platform/arm-linux/types.conf +102 -0
- data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
- data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
- data/lib/ffi/platform/i486-gnu/types.conf +107 -0
- data/lib/ffi/platform/ia64-linux/types.conf +102 -0
- data/lib/ffi/platform/mips-linux/types.conf +102 -0
- data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
- data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
- data/lib/ffi/platform/s390-linux/types.conf +102 -0
- data/lib/ffi/platform/s390x-linux/types.conf +102 -0
- data/lib/ffi/platform/sparc-linux/types.conf +102 -0
- data/lib/ffi/platform/x86_64-freebsd/types.conf +126 -0
- data/lib/ffi/platform/x86_64-netbsd/types.conf +126 -0
- data/lib/ffi/pointer.rb +44 -0
- data/lib/ffi/struct.rb +2 -6
- data/lib/ffi/struct_layout_builder.rb +2 -1
- data/lib/ffi/tools/const_generator.rb +78 -26
- data/lib/ffi/tools/types_generator.rb +8 -1
- data/lib/ffi/types.rb +21 -1
- data/spec/ffi/async_callback_spec.rb +2 -2
- data/spec/ffi/bool_spec.rb +6 -6
- data/spec/ffi/buffer_spec.rb +23 -23
- data/spec/ffi/callback_spec.rb +101 -102
- data/spec/ffi/custom_type_spec.rb +20 -24
- data/spec/ffi/dup_spec.rb +7 -7
- data/spec/ffi/enum_spec.rb +127 -127
- data/spec/ffi/errno_spec.rb +2 -2
- data/spec/ffi/ffi_spec.rb +3 -3
- data/spec/ffi/function_spec.rb +10 -10
- data/spec/ffi/library_spec.rb +30 -12
- data/spec/ffi/managed_struct_spec.rb +4 -4
- data/spec/ffi/number_spec.rb +40 -40
- data/spec/ffi/pointer_spec.rb +21 -24
- data/spec/ffi/rbx/memory_pointer_spec.rb +17 -15
- data/spec/ffi/rbx/struct_spec.rb +2 -2
- data/spec/ffi/spec_helper.rb +1 -1
- data/spec/ffi/string_spec.rb +9 -9
- data/spec/ffi/strptr_spec.rb +3 -3
- data/spec/ffi/struct_callback_spec.rb +7 -7
- data/spec/ffi/struct_initialize_spec.rb +2 -2
- data/spec/ffi/struct_packed_spec.rb +6 -6
- data/spec/ffi/struct_spec.rb +94 -84
- data/spec/ffi/typedef_spec.rb +15 -4
- data/spec/ffi/union_spec.rb +3 -3
- data/spec/ffi/variadic_spec.rb +17 -14
- data/tasks/extension.rake +0 -1
- data/tasks/gem.rake +0 -1
- data/tasks/rdoc.rake +1 -1
- data/tasks/yard.rake +11 -0
- metadata +50 -11
- data/lib/1.9/ffi_c.so +0 -0
data/ext/ffi_c/Function.h
CHANGED
data/ext/ffi_c/FunctionInfo.c
CHANGED
@@ -17,11 +17,19 @@
|
|
17
17
|
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
*/
|
19
19
|
|
20
|
+
#ifndef _MSC_VER
|
20
21
|
#include <sys/param.h>
|
22
|
+
#endif
|
21
23
|
#include <sys/types.h>
|
22
24
|
#include <stdio.h>
|
25
|
+
#ifndef _MSC_VER
|
23
26
|
#include <stdint.h>
|
24
27
|
#include <stdbool.h>
|
28
|
+
#else
|
29
|
+
typedef int bool;
|
30
|
+
#define true 1
|
31
|
+
#define false 0
|
32
|
+
#endif
|
25
33
|
#include <errno.h>
|
26
34
|
#include <ruby.h>
|
27
35
|
|
@@ -105,7 +113,7 @@ fntype_initialize(int argc, VALUE* argv, VALUE self)
|
|
105
113
|
Check_Type(rbParamTypes, T_ARRAY);
|
106
114
|
|
107
115
|
Data_Get_Struct(self, FunctionType, fnInfo);
|
108
|
-
fnInfo->parameterCount = RARRAY_LEN(rbParamTypes);
|
116
|
+
fnInfo->parameterCount = (int) RARRAY_LEN(rbParamTypes);
|
109
117
|
fnInfo->parameterTypes = xcalloc(fnInfo->parameterCount, sizeof(*fnInfo->parameterTypes));
|
110
118
|
fnInfo->ffiParameterTypes = xcalloc(fnInfo->parameterCount, sizeof(ffi_type *));
|
111
119
|
fnInfo->nativeParameterTypes = xcalloc(fnInfo->parameterCount, sizeof(*fnInfo->nativeParameterTypes));
|
@@ -201,10 +209,22 @@ fntype_param_types(VALUE self)
|
|
201
209
|
void
|
202
210
|
rbffi_FunctionInfo_Init(VALUE moduleFFI)
|
203
211
|
{
|
212
|
+
/*
|
213
|
+
* Document-class: FFI::FunctionType < FFI::Type
|
214
|
+
*/
|
204
215
|
rbffi_FunctionTypeClass = rb_define_class_under(moduleFFI, "FunctionType", rbffi_TypeClass);
|
205
216
|
rb_global_variable(&rbffi_FunctionTypeClass);
|
217
|
+
/*
|
218
|
+
* Document-const: FFI::CallbackInfo = FFI::FunctionType
|
219
|
+
*/
|
206
220
|
rb_define_const(moduleFFI, "CallbackInfo", rbffi_FunctionTypeClass);
|
221
|
+
/*
|
222
|
+
* Document-const: FFI::FunctionInfo = FFI::FunctionType
|
223
|
+
*/
|
207
224
|
rb_define_const(moduleFFI, "FunctionInfo", rbffi_FunctionTypeClass);
|
225
|
+
/*
|
226
|
+
* Document-const: FFI::Type::Function = FFI::FunctionType
|
227
|
+
*/
|
208
228
|
rb_define_const(rbffi_TypeClass, "Function", rbffi_FunctionTypeClass);
|
209
229
|
|
210
230
|
rb_define_alloc_func(rbffi_FunctionTypeClass, fntype_allocate);
|
data/ext/ffi_c/LastError.c
CHANGED
@@ -18,11 +18,19 @@
|
|
18
18
|
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
*/
|
20
20
|
|
21
|
+
#ifndef _MSC_VER
|
21
22
|
#include <sys/param.h>
|
23
|
+
#endif
|
22
24
|
#include <sys/types.h>
|
23
25
|
#include <stdio.h>
|
26
|
+
#ifndef _MSC_VER
|
24
27
|
#include <stdint.h>
|
25
28
|
#include <stdbool.h>
|
29
|
+
#else
|
30
|
+
typedef int bool;
|
31
|
+
#define true 1
|
32
|
+
#define false 0
|
33
|
+
#endif
|
26
34
|
#include <errno.h>
|
27
35
|
#include <ruby.h>
|
28
36
|
|
@@ -99,6 +107,11 @@ thread_data_get()
|
|
99
107
|
#endif
|
100
108
|
|
101
109
|
|
110
|
+
/*
|
111
|
+
* call-seq: error
|
112
|
+
* @return [Numeric]
|
113
|
+
* Get +errno+ value.
|
114
|
+
*/
|
102
115
|
static VALUE
|
103
116
|
get_last_error(VALUE self)
|
104
117
|
{
|
@@ -106,6 +119,12 @@ get_last_error(VALUE self)
|
|
106
119
|
}
|
107
120
|
|
108
121
|
|
122
|
+
/*
|
123
|
+
* call-seq: error(error)
|
124
|
+
* @param [Numeric] error
|
125
|
+
* @return [nil]
|
126
|
+
* Set +errno+ value.
|
127
|
+
*/
|
109
128
|
static VALUE
|
110
129
|
set_last_error(VALUE self, VALUE error)
|
111
130
|
{
|
@@ -138,6 +157,11 @@ rbffi_save_errno(void)
|
|
138
157
|
void
|
139
158
|
rbffi_LastError_Init(VALUE moduleFFI)
|
140
159
|
{
|
160
|
+
/*
|
161
|
+
* Document-module: FFI::LastError
|
162
|
+
* This module defines a couple of method to set and get +errno+
|
163
|
+
* for current thread.
|
164
|
+
*/
|
141
165
|
VALUE moduleError = rb_define_module_under(moduleFFI, "LastError");
|
142
166
|
|
143
167
|
rb_define_module_function(moduleError, "error", get_last_error, 0);
|
data/ext/ffi_c/MappedType.c
CHANGED
@@ -50,6 +50,12 @@ mapped_allocate(VALUE klass)
|
|
50
50
|
return obj;
|
51
51
|
}
|
52
52
|
|
53
|
+
/*
|
54
|
+
* call-seq: initialize(converter)
|
55
|
+
* @param [#native_type, #to_native, #from_native] converter +converter+ must respond to
|
56
|
+
* all these methods
|
57
|
+
* @return [self]
|
58
|
+
*/
|
53
59
|
static VALUE
|
54
60
|
mapped_initialize(VALUE self, VALUE rbConverter)
|
55
61
|
{
|
@@ -88,6 +94,11 @@ mapped_mark(MappedType* m)
|
|
88
94
|
rb_gc_mark(m->rbConverter);
|
89
95
|
}
|
90
96
|
|
97
|
+
/*
|
98
|
+
* call-seq: mapped_type.native_type
|
99
|
+
* @return [Type]
|
100
|
+
* Get native type of mapped type.
|
101
|
+
*/
|
91
102
|
static VALUE
|
92
103
|
mapped_native_type(VALUE self)
|
93
104
|
{
|
@@ -97,6 +108,10 @@ mapped_native_type(VALUE self)
|
|
97
108
|
return m->rbType;
|
98
109
|
}
|
99
110
|
|
111
|
+
/*
|
112
|
+
* call-seq: mapped_type.to_native(*args)
|
113
|
+
* @param args depends on {FFI::DataConverter} used to initialize +self+
|
114
|
+
*/
|
100
115
|
static VALUE
|
101
116
|
mapped_to_native(int argc, VALUE* argv, VALUE self)
|
102
117
|
{
|
@@ -107,6 +122,10 @@ mapped_to_native(int argc, VALUE* argv, VALUE self)
|
|
107
122
|
return rb_funcall2(m->rbConverter, id_to_native, argc, argv);
|
108
123
|
}
|
109
124
|
|
125
|
+
/*
|
126
|
+
* call-seq: mapped_type.from_native(*args)
|
127
|
+
* @param args depends on {FFI::DataConverter} used to initialize +self+
|
128
|
+
*/
|
110
129
|
static VALUE
|
111
130
|
mapped_from_native(int argc, VALUE* argv, VALUE self)
|
112
131
|
{
|
@@ -121,6 +140,9 @@ void
|
|
121
140
|
rbffi_MappedType_Init(VALUE moduleFFI)
|
122
141
|
{
|
123
142
|
|
143
|
+
/*
|
144
|
+
* Document-class: FFI::Type::Mapped
|
145
|
+
*/
|
124
146
|
rbffi_MappedTypeClass = rb_define_class_under(rbffi_TypeClass, "Mapped", rbffi_TypeClass);
|
125
147
|
|
126
148
|
rb_global_variable(&rbffi_MappedTypeClass);
|
data/ext/ffi_c/MemoryPointer.c
CHANGED
@@ -19,8 +19,16 @@
|
|
19
19
|
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
20
20
|
*/
|
21
21
|
|
22
|
+
#ifndef _MSC_VER
|
22
23
|
#include <stdbool.h>
|
24
|
+
#else
|
25
|
+
typedef int bool;
|
26
|
+
#define true 1
|
27
|
+
#define false 0
|
28
|
+
#endif
|
29
|
+
#ifndef _MSC_VER
|
23
30
|
#include <stdint.h>
|
31
|
+
#endif
|
24
32
|
#include <limits.h>
|
25
33
|
#include <ruby.h>
|
26
34
|
#include "rbffi.h"
|
@@ -88,7 +96,7 @@ memptr_malloc(VALUE self, long size, long count, bool clear)
|
|
88
96
|
return Qnil;
|
89
97
|
}
|
90
98
|
p->autorelease = true;
|
91
|
-
p->memory.typeSize = size;
|
99
|
+
p->memory.typeSize = (int) size;
|
92
100
|
p->memory.size = msize;
|
93
101
|
/* ensure the memory is aligned on at least a 8 byte boundary */
|
94
102
|
p->memory.address = (char *) (((uintptr_t) p->storage + 0x7) & (uintptr_t) ~0x7UL);;
|
@@ -135,6 +143,15 @@ memptr_mark(Pointer* ptr)
|
|
135
143
|
rb_gc_mark(ptr->rbParent);
|
136
144
|
}
|
137
145
|
|
146
|
+
static VALUE
|
147
|
+
memptr_s_from_string(VALUE klass, VALUE s)
|
148
|
+
{
|
149
|
+
VALUE args[] = { INT2FIX(1), LONG2NUM(RSTRING_LEN(s) + 1), Qfalse };
|
150
|
+
VALUE obj = rb_class_new_instance(3, args, klass);
|
151
|
+
rb_funcall(obj, rb_intern("put_string"), 2, INT2FIX(0), s);
|
152
|
+
|
153
|
+
return obj;
|
154
|
+
}
|
138
155
|
|
139
156
|
void
|
140
157
|
rbffi_MemoryPointer_Init(VALUE moduleFFI)
|
@@ -144,5 +161,6 @@ rbffi_MemoryPointer_Init(VALUE moduleFFI)
|
|
144
161
|
|
145
162
|
rb_define_alloc_func(rbffi_MemoryPointerClass, memptr_allocate);
|
146
163
|
rb_define_method(rbffi_MemoryPointerClass, "initialize", memptr_initialize, -1);
|
164
|
+
rb_define_singleton_method(rbffi_MemoryPointerClass, "from_string", memptr_s_from_string, 1);
|
147
165
|
}
|
148
166
|
|
data/ext/ffi_c/MemoryPointer.h
CHANGED
data/ext/ffi_c/MethodHandle.c
CHANGED
@@ -17,14 +17,22 @@
|
|
17
17
|
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
*/
|
19
19
|
|
20
|
+
#ifndef _MSC_VER
|
20
21
|
#include <sys/param.h>
|
22
|
+
#endif
|
21
23
|
#include <sys/types.h>
|
22
24
|
#ifndef _WIN32
|
23
25
|
# include <sys/mman.h>
|
24
26
|
#endif
|
25
27
|
#include <stdio.h>
|
28
|
+
#ifndef _MSC_VER
|
26
29
|
#include <stdint.h>
|
27
30
|
#include <stdbool.h>
|
31
|
+
#else
|
32
|
+
typedef int bool;
|
33
|
+
#define true 1
|
34
|
+
#define false 0
|
35
|
+
#endif
|
28
36
|
#ifndef _WIN32
|
29
37
|
# include <unistd.h>
|
30
38
|
#endif
|
@@ -67,7 +75,7 @@
|
|
67
75
|
|
68
76
|
|
69
77
|
static bool prep_trampoline(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize);
|
70
|
-
static
|
78
|
+
static long trampoline_size(void);
|
71
79
|
|
72
80
|
#if defined(__x86_64__) && defined(__GNUC__)
|
73
81
|
# define CUSTOM_TRAMPOLINE 1
|
@@ -143,14 +151,14 @@ prep_trampoline(void* ctx, void* code, Closure* closure, char* errmsg, size_t er
|
|
143
151
|
}
|
144
152
|
|
145
153
|
|
146
|
-
static
|
154
|
+
static long
|
147
155
|
trampoline_size(void)
|
148
156
|
{
|
149
157
|
return sizeof(METHOD_CLOSURE);
|
150
158
|
}
|
151
159
|
|
152
160
|
/*
|
153
|
-
*
|
161
|
+
* attached_method_invoke is used functions with more than 6 parameters, or
|
154
162
|
* with struct param or return values
|
155
163
|
*/
|
156
164
|
static void
|
@@ -211,7 +219,13 @@ static VALUE
|
|
211
219
|
custom_trampoline(int argc, VALUE* argv, VALUE self, Closure* handle)
|
212
220
|
{
|
213
221
|
FunctionType* fnInfo = (FunctionType *) handle->info;
|
214
|
-
|
222
|
+
VALUE rbReturnValue;
|
223
|
+
|
224
|
+
RB_GC_GUARD(rbReturnValue) = (*fnInfo->invoke)(argc, argv, handle->function, fnInfo);
|
225
|
+
RB_GC_GUARD_PTR(argv);
|
226
|
+
RB_GC_GUARD(self);
|
227
|
+
|
228
|
+
return rbReturnValue;
|
215
229
|
}
|
216
230
|
|
217
231
|
#elif defined(__i386__) && 0
|
@@ -258,11 +272,11 @@ custom_trampoline(caddr_t args, Closure* handle)
|
|
258
272
|
|
259
273
|
extern void ffi_trampoline(int argc, VALUE* argv, VALUE self);
|
260
274
|
extern void ffi_trampoline_end(void);
|
261
|
-
static int trampoline_offsets(
|
275
|
+
static int trampoline_offsets(long *, long *);
|
262
276
|
|
263
|
-
static
|
277
|
+
static long trampoline_ctx_offset, trampoline_func_offset;
|
264
278
|
|
265
|
-
static
|
279
|
+
static long
|
266
280
|
trampoline_offset(int off, const long value)
|
267
281
|
{
|
268
282
|
caddr_t ptr;
|
@@ -276,7 +290,7 @@ trampoline_offset(int off, const long value)
|
|
276
290
|
}
|
277
291
|
|
278
292
|
static int
|
279
|
-
trampoline_offsets(
|
293
|
+
trampoline_offsets(long* ctxOffset, long* fnOffset)
|
280
294
|
{
|
281
295
|
*ctxOffset = trampoline_offset(0, TRAMPOLINE_CTX_MAGIC);
|
282
296
|
if (*ctxOffset == -1) {
|
@@ -304,7 +318,7 @@ prep_trampoline(void* ctx, void* code, Closure* closure, char* errmsg, size_t er
|
|
304
318
|
return true;
|
305
319
|
}
|
306
320
|
|
307
|
-
static
|
321
|
+
static long
|
308
322
|
trampoline_size(void)
|
309
323
|
{
|
310
324
|
return (caddr_t) &ffi_trampoline_end - (caddr_t) &ffi_trampoline;
|
@@ -316,14 +330,15 @@ trampoline_size(void)
|
|
316
330
|
void
|
317
331
|
rbffi_MethodHandle_Init(VALUE module)
|
318
332
|
{
|
319
|
-
|
333
|
+
ffi_status ffiStatus;
|
334
|
+
defaultClosurePool = rbffi_ClosurePool_New((int) trampoline_size(), prep_trampoline, NULL);
|
320
335
|
|
321
336
|
#if defined(CUSTOM_TRAMPOLINE)
|
322
337
|
if (trampoline_offsets(&trampoline_ctx_offset, &trampoline_func_offset) != 0) {
|
323
338
|
rb_raise(rb_eFatal, "Could not locate offsets in trampoline code");
|
324
339
|
}
|
325
340
|
#else
|
326
|
-
|
341
|
+
ffiStatus = ffi_prep_cif(&mh_cif, FFI_DEFAULT_ABI, 3, &ffi_type_ulong,
|
327
342
|
methodHandleParamTypes);
|
328
343
|
if (ffiStatus != FFI_OK) {
|
329
344
|
rb_raise(rb_eFatal, "ffi_prep_cif failed. status=%#x", ffiStatus);
|
data/ext/ffi_c/Platform.c
CHANGED
@@ -18,14 +18,25 @@
|
|
18
18
|
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
*/
|
20
20
|
|
21
|
+
#ifndef _MSC_VER
|
21
22
|
#include <sys/param.h>
|
23
|
+
#endif
|
22
24
|
#include <sys/types.h>
|
25
|
+
#ifndef _MSC_VER
|
23
26
|
#include <stdint.h>
|
24
27
|
#include <stdbool.h>
|
28
|
+
#else
|
29
|
+
typedef int bool;
|
30
|
+
#define true 1
|
31
|
+
#define false 0
|
32
|
+
#endif
|
25
33
|
#include <ruby.h>
|
26
34
|
#include <ctype.h>
|
27
35
|
#include "endian.h"
|
28
36
|
#include "Platform.h"
|
37
|
+
#if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
|
38
|
+
#include <gnu/lib-names.h>
|
39
|
+
#endif
|
29
40
|
|
30
41
|
static VALUE PlatformModule = Qnil;
|
31
42
|
|
@@ -34,13 +45,13 @@ static VALUE PlatformModule = Qnil;
|
|
34
45
|
* system installed ruby incorrectly reports 'host_cpu' as 'powerpc' when running
|
35
46
|
* on intel.
|
36
47
|
*/
|
37
|
-
#if defined(__x86_64__) || defined(__x86_64) || defined(__amd64)
|
48
|
+
#if defined(__x86_64__) || defined(__x86_64) || defined(__amd64) || defined(_M_X64) || defined(_M_AMD64)
|
38
49
|
# define CPU "x86_64"
|
39
50
|
|
40
|
-
#elif defined(__i386__) || defined(__i386)
|
51
|
+
#elif defined(__i386__) || defined(__i386) || defined(_M_IX86)
|
41
52
|
# define CPU "i386"
|
42
53
|
|
43
|
-
#elif defined(__ppc64__) || defined(__powerpc64__)
|
54
|
+
#elif defined(__ppc64__) || defined(__powerpc64__) || defined(_M_PPC)
|
44
55
|
# define CPU "ppc64"
|
45
56
|
|
46
57
|
#elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc)
|
@@ -93,6 +104,9 @@ rbffi_Platform_Init(VALUE moduleFFI)
|
|
93
104
|
rb_define_const(PlatformModule, "LITTLE_ENDIAN", INT2FIX(LITTLE_ENDIAN));
|
94
105
|
rb_define_const(PlatformModule, "BIG_ENDIAN", INT2FIX(BIG_ENDIAN));
|
95
106
|
rb_define_const(PlatformModule, "CPU", rb_str_new2(CPU));
|
107
|
+
#if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
|
108
|
+
rb_define_const(PlatformModule, "GNU_LIBC", rb_str_new2(LIBC_SO));
|
109
|
+
#endif
|
96
110
|
export_primitive_types(PlatformModule);
|
97
111
|
}
|
98
112
|
|
data/ext/ffi_c/Pointer.c
CHANGED
@@ -18,8 +18,16 @@
|
|
18
18
|
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
*/
|
20
20
|
|
21
|
+
#ifndef _MSC_VER
|
21
22
|
#include <stdbool.h>
|
23
|
+
#else
|
24
|
+
typedef int bool;
|
25
|
+
#define true 1
|
26
|
+
#define false 0
|
27
|
+
#endif
|
28
|
+
#ifndef _MSC_VER
|
22
29
|
#include <stdint.h>
|
30
|
+
#endif
|
23
31
|
#include <limits.h>
|
24
32
|
#include <ruby.h>
|
25
33
|
#include "rbffi.h"
|
@@ -68,6 +76,17 @@ ptr_allocate(VALUE klass)
|
|
68
76
|
return obj;
|
69
77
|
}
|
70
78
|
|
79
|
+
/*
|
80
|
+
* @overload initialize(pointer)
|
81
|
+
* @param [Pointer] pointer another pointer to initialize from
|
82
|
+
* Create a new pointer from another {Pointer}.
|
83
|
+
* @overload initialize(type, address)
|
84
|
+
* @param [Type] type type for pointer
|
85
|
+
* @param [Integer] address base address for pointer
|
86
|
+
* Create a new pointer from a {Type} and a base adresse
|
87
|
+
* @return [self]
|
88
|
+
* A new instance of Pointer.
|
89
|
+
*/
|
71
90
|
static VALUE
|
72
91
|
ptr_initialize(int argc, VALUE* argv, VALUE self)
|
73
92
|
{
|
@@ -117,6 +136,16 @@ ptr_initialize(int argc, VALUE* argv, VALUE self)
|
|
117
136
|
return self;
|
118
137
|
}
|
119
138
|
|
139
|
+
/*
|
140
|
+
* call-seq: ptr.initialize_copy(other)
|
141
|
+
* @param [Pointer] other source for cloning or dupping
|
142
|
+
* @return [self]
|
143
|
+
* @raise {RuntimeError} if +other+ is an unbounded memory area, or is unreable/unwritable
|
144
|
+
* @raise {NoMemError} if failed to allocate memory for new object
|
145
|
+
* DO NOT CALL THIS METHOD.
|
146
|
+
*
|
147
|
+
* This method is internally used by #dup and #clone. Memory contents is copied from +other+.
|
148
|
+
*/
|
120
149
|
static VALUE
|
121
150
|
ptr_initialize_copy(VALUE self, VALUE other)
|
122
151
|
{
|
@@ -179,6 +208,13 @@ slice(VALUE self, long offset, long size)
|
|
179
208
|
return retval;
|
180
209
|
}
|
181
210
|
|
211
|
+
/*
|
212
|
+
* Document-method: +
|
213
|
+
* call-seq: ptr + offset
|
214
|
+
* @param [Numeric] offset
|
215
|
+
* @return [Pointer]
|
216
|
+
* Return a new {Pointer} from an existing pointer and an +offset+.
|
217
|
+
*/
|
182
218
|
static VALUE
|
183
219
|
ptr_plus(VALUE self, VALUE offset)
|
184
220
|
{
|
@@ -190,12 +226,25 @@ ptr_plus(VALUE self, VALUE offset)
|
|
190
226
|
return slice(self, off, ptr->size == LONG_MAX ? LONG_MAX : ptr->size - off);
|
191
227
|
}
|
192
228
|
|
229
|
+
/*
|
230
|
+
* call-seq: ptr.slice(offset, length)
|
231
|
+
* @param [Numeric] offset
|
232
|
+
* @param [Numeric] length
|
233
|
+
* @return [Pointer]
|
234
|
+
* Return a new {Pointer} from an existing one. This pointer points on same contents
|
235
|
+
* from +offset+ for a length +length+.
|
236
|
+
*/
|
193
237
|
static VALUE
|
194
238
|
ptr_slice(VALUE self, VALUE rbOffset, VALUE rbLength)
|
195
239
|
{
|
196
240
|
return slice(self, NUM2LONG(rbOffset), NUM2LONG(rbLength));
|
197
241
|
}
|
198
242
|
|
243
|
+
/*
|
244
|
+
* call-seq: ptr.inspect
|
245
|
+
* @return [String]
|
246
|
+
* Inspect pointer object.
|
247
|
+
*/
|
199
248
|
static VALUE
|
200
249
|
ptr_inspect(VALUE self)
|
201
250
|
{
|
@@ -214,6 +263,12 @@ ptr_inspect(VALUE self)
|
|
214
263
|
return rb_str_new2(buf);
|
215
264
|
}
|
216
265
|
|
266
|
+
/*
|
267
|
+
* Document-method: null?
|
268
|
+
* call-seq: ptr.null?
|
269
|
+
* @return [Boolean]
|
270
|
+
* Return +true+ if +self+ is a {NULL} pointer.
|
271
|
+
*/
|
217
272
|
static VALUE
|
218
273
|
ptr_null_p(VALUE self)
|
219
274
|
{
|
@@ -224,6 +279,12 @@ ptr_null_p(VALUE self)
|
|
224
279
|
return ptr->memory.address == NULL ? Qtrue : Qfalse;
|
225
280
|
}
|
226
281
|
|
282
|
+
/*
|
283
|
+
* Document-method: ==
|
284
|
+
* call-seq: ptr == other
|
285
|
+
* @param [Pointer] other
|
286
|
+
* Check equality between +self+ and +other+. Equality is tested on {#address}.
|
287
|
+
*/
|
227
288
|
static VALUE
|
228
289
|
ptr_equals(VALUE self, VALUE other)
|
229
290
|
{
|
@@ -234,6 +295,11 @@ ptr_equals(VALUE self, VALUE other)
|
|
234
295
|
return ptr->memory.address == POINTER(other)->address ? Qtrue : Qfalse;
|
235
296
|
}
|
236
297
|
|
298
|
+
/*
|
299
|
+
* call-seq: ptr.address
|
300
|
+
* @return [Numeric] pointer's base address
|
301
|
+
* Return +self+'s base address (alias: #to_i).
|
302
|
+
*/
|
237
303
|
static VALUE
|
238
304
|
ptr_address(VALUE self)
|
239
305
|
{
|
@@ -250,6 +316,15 @@ ptr_address(VALUE self)
|
|
250
316
|
# define SWAPPED_ORDER LITTLE_ENDIAN
|
251
317
|
#endif
|
252
318
|
|
319
|
+
/*
|
320
|
+
* Get or set +self+'s endianness
|
321
|
+
* @overload ptr.order
|
322
|
+
* @return [:big, :little] endianness of +self+
|
323
|
+
* @overload ptr.order(order)
|
324
|
+
* @param [Symbol] order endianness to set (+:little+, +:big+ or +:network+). +:big+ and +:network+
|
325
|
+
* are synonymous.
|
326
|
+
* @return [self]
|
327
|
+
*/
|
253
328
|
static VALUE
|
254
329
|
ptr_order(int argc, VALUE* argv, VALUE self)
|
255
330
|
{
|
@@ -289,6 +364,11 @@ ptr_order(int argc, VALUE* argv, VALUE self)
|
|
289
364
|
}
|
290
365
|
|
291
366
|
|
367
|
+
/*
|
368
|
+
* call-seq: ptr.free
|
369
|
+
* @return [self]
|
370
|
+
* Free memory pointed by +self+.
|
371
|
+
*/
|
292
372
|
static VALUE
|
293
373
|
ptr_free(VALUE self)
|
294
374
|
{
|
@@ -307,6 +387,12 @@ ptr_free(VALUE self)
|
|
307
387
|
return self;
|
308
388
|
}
|
309
389
|
|
390
|
+
/*
|
391
|
+
* call-seq: ptr.autorelease = autorelease
|
392
|
+
* @param [Boolean] autorelease
|
393
|
+
* @return [Boolean] +autorelease+
|
394
|
+
* Set +autorelease+ attribute. See also Autorelease section.
|
395
|
+
*/
|
310
396
|
static VALUE
|
311
397
|
ptr_autorelease(VALUE self, VALUE autorelease)
|
312
398
|
{
|
@@ -318,6 +404,11 @@ ptr_autorelease(VALUE self, VALUE autorelease)
|
|
318
404
|
return autorelease;
|
319
405
|
}
|
320
406
|
|
407
|
+
/*
|
408
|
+
* call-seq: ptr.autorelease?
|
409
|
+
* @return [Boolean]
|
410
|
+
* Get +autorelease+ attribute. See also Autorelease section.
|
411
|
+
*/
|
321
412
|
static VALUE
|
322
413
|
ptr_autorelease_p(VALUE self)
|
323
414
|
{
|
@@ -350,7 +441,19 @@ rbffi_Pointer_Init(VALUE moduleFFI)
|
|
350
441
|
{
|
351
442
|
VALUE rbNullAddress = ULL2NUM(0);
|
352
443
|
|
444
|
+
/*
|
445
|
+
* Document-class: FFI::Pointer < FFI::AbstractMemory
|
446
|
+
* Pointer class is used to manage C pointers with ease. A {Pointer} object is defined by his
|
447
|
+
* {#address} (as a C pointer). It permits additions with an integer for pointer arithmetic.
|
448
|
+
*
|
449
|
+
* ==Autorelease
|
450
|
+
* A pointer object may autorelease his contents when freed (by default). This behaviour may be
|
451
|
+
* changed with {#autorelease=} method.
|
452
|
+
*/
|
353
453
|
rbffi_PointerClass = rb_define_class_under(moduleFFI, "Pointer", rbffi_AbstractMemoryClass);
|
454
|
+
/*
|
455
|
+
* Document-variable: Pointer
|
456
|
+
*/
|
354
457
|
rb_global_variable(&rbffi_PointerClass);
|
355
458
|
|
356
459
|
rb_define_alloc_func(rbffi_PointerClass, ptr_allocate);
|
@@ -370,6 +473,9 @@ rbffi_Pointer_Init(VALUE moduleFFI)
|
|
370
473
|
rb_define_method(rbffi_PointerClass, "free", ptr_free, 0);
|
371
474
|
|
372
475
|
rbffi_NullPointerSingleton = rb_class_new_instance(1, &rbNullAddress, rbffi_PointerClass);
|
476
|
+
/*
|
477
|
+
* NULL pointer
|
478
|
+
*/
|
373
479
|
rb_define_const(rbffi_PointerClass, "NULL", rbffi_NullPointerSingleton);
|
374
480
|
}
|
375
481
|
|