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/DataConverter.c
CHANGED
@@ -11,6 +11,15 @@
|
|
11
11
|
VALUE rbffi_DataConverterClass = Qnil;
|
12
12
|
static ID id_native_type_ivar;
|
13
13
|
|
14
|
+
/*
|
15
|
+
* Get native type.
|
16
|
+
* @overload native_type(type)
|
17
|
+
* @param [String, Symbol, Type] type
|
18
|
+
* @return [Type]
|
19
|
+
* Get native type from +type+.
|
20
|
+
* @overload native_type
|
21
|
+
* @raise {NotImplementedError} This method must be overriden.
|
22
|
+
*/
|
14
23
|
static VALUE
|
15
24
|
conv_native_type(int argc, VALUE* argv, VALUE self)
|
16
25
|
{
|
@@ -33,12 +42,26 @@ conv_native_type(int argc, VALUE* argv, VALUE self)
|
|
33
42
|
}
|
34
43
|
}
|
35
44
|
|
45
|
+
/*
|
46
|
+
* call-seq: to_native(value, ctx)
|
47
|
+
* @param value
|
48
|
+
* @param ctx
|
49
|
+
* @return [value]
|
50
|
+
* Convert to a native type.
|
51
|
+
*/
|
36
52
|
static VALUE
|
37
53
|
conv_to_native(VALUE self, VALUE value, VALUE ctx)
|
38
54
|
{
|
39
55
|
return value;
|
40
56
|
}
|
41
57
|
|
58
|
+
/*
|
59
|
+
* call-seq: from_native(value, ctx)
|
60
|
+
* @param value
|
61
|
+
* @param ctx
|
62
|
+
* @return [value]
|
63
|
+
* Convert from a native type.
|
64
|
+
*/
|
42
65
|
static VALUE
|
43
66
|
conv_from_native(VALUE self, VALUE value, VALUE ctx)
|
44
67
|
{
|
@@ -50,6 +73,12 @@ conv_from_native(VALUE self, VALUE value, VALUE ctx)
|
|
50
73
|
void
|
51
74
|
rbffi_DataConverter_Init(VALUE moduleFFI)
|
52
75
|
{
|
76
|
+
/*
|
77
|
+
* Document-module: FFI::DataConverter
|
78
|
+
* This module is used to extend somes classes and give then a common API.
|
79
|
+
*
|
80
|
+
* Most of methods defined here must be overriden.
|
81
|
+
*/
|
53
82
|
rbffi_DataConverterClass = rb_define_module_under(moduleFFI, "DataConverter");
|
54
83
|
|
55
84
|
rb_define_method(rbffi_DataConverterClass, "native_type", conv_native_type, -1);
|
data/ext/ffi_c/DynamicLibrary.c
CHANGED
@@ -20,13 +20,20 @@
|
|
20
20
|
|
21
21
|
#include <sys/types.h>
|
22
22
|
#include <stdio.h>
|
23
|
-
#
|
23
|
+
#ifndef _MSC_VER
|
24
|
+
# include <stdint.h>
|
25
|
+
#endif
|
24
26
|
#if defined(_WIN32) || defined(__WIN32__)
|
27
|
+
# include <winsock2.h>
|
28
|
+
# define _WINSOCKAPI_
|
25
29
|
# include <windows.h>
|
26
30
|
#else
|
27
31
|
# include <dlfcn.h>
|
28
32
|
#endif
|
29
33
|
#include <ruby.h>
|
34
|
+
#if defined(_MSC_VER) && !defined(INT8_MIN)
|
35
|
+
# include "win32/stdint.h"
|
36
|
+
#endif
|
30
37
|
|
31
38
|
#include <ffi.h>
|
32
39
|
|
@@ -75,12 +82,28 @@ library_allocate(VALUE klass)
|
|
75
82
|
return Data_Make_Struct(klass, Library, NULL, library_free, library);
|
76
83
|
}
|
77
84
|
|
85
|
+
/*
|
86
|
+
* call-seq: DynamicLibrary.open(libname, libflags)
|
87
|
+
* @param libname (see #initialize)
|
88
|
+
* @param libflags (see #initialize)
|
89
|
+
* @return [FFI::DynamicLibrary]
|
90
|
+
* @raise {LoadError} if +libname+ cannot be opened
|
91
|
+
* Open a library.
|
92
|
+
*/
|
78
93
|
static VALUE
|
79
94
|
library_open(VALUE klass, VALUE libname, VALUE libflags)
|
80
95
|
{
|
81
96
|
return library_initialize(library_allocate(klass), libname, libflags);
|
82
97
|
}
|
83
98
|
|
99
|
+
/*
|
100
|
+
* call-seq: initialize(libname, libflags)
|
101
|
+
* @param [String] libname name of library to open
|
102
|
+
* @param [Fixnum] libflags flags for library to open
|
103
|
+
* @return [FFI::DynamicLibrary]
|
104
|
+
* @raise {LoadError} if +libname+ cannot be opened
|
105
|
+
* A new DynamicLibrary instance.
|
106
|
+
*/
|
84
107
|
static VALUE
|
85
108
|
library_initialize(VALUE self, VALUE libname, VALUE libflags)
|
86
109
|
{
|
@@ -117,6 +140,10 @@ library_dlsym(VALUE self, VALUE name)
|
|
117
140
|
return address != NULL ? symbol_new(self, address, name) : Qnil;
|
118
141
|
}
|
119
142
|
|
143
|
+
/*
|
144
|
+
* call-seq: last_error
|
145
|
+
* @return [String] library's last error string
|
146
|
+
*/
|
120
147
|
static VALUE
|
121
148
|
library_dlerror(VALUE self)
|
122
149
|
{
|
@@ -144,7 +171,7 @@ dl_open(const char* name, int flags)
|
|
144
171
|
if (name == NULL) {
|
145
172
|
return GetModuleHandle(NULL);
|
146
173
|
} else {
|
147
|
-
return
|
174
|
+
return LoadLibraryExA(name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
|
148
175
|
}
|
149
176
|
}
|
150
177
|
|
@@ -169,6 +196,12 @@ symbol_allocate(VALUE klass)
|
|
169
196
|
}
|
170
197
|
|
171
198
|
|
199
|
+
/*
|
200
|
+
* call-seq: initialize_copy(other)
|
201
|
+
* @param [Object] other
|
202
|
+
* @return [nil]
|
203
|
+
* DO NOT CALL THIS METHOD
|
204
|
+
*/
|
172
205
|
static VALUE
|
173
206
|
symbol_initialize_copy(VALUE self, VALUE other)
|
174
207
|
{
|
@@ -199,6 +232,11 @@ symbol_mark(LibrarySymbol* sym)
|
|
199
232
|
rb_gc_mark(sym->name);
|
200
233
|
}
|
201
234
|
|
235
|
+
/*
|
236
|
+
* call-seq: inspect
|
237
|
+
* @return [String]
|
238
|
+
* Inspect.
|
239
|
+
*/
|
202
240
|
static VALUE
|
203
241
|
symbol_inspect(VALUE self)
|
204
242
|
{
|
@@ -214,18 +252,49 @@ symbol_inspect(VALUE self)
|
|
214
252
|
void
|
215
253
|
rbffi_DynamicLibrary_Init(VALUE moduleFFI)
|
216
254
|
{
|
255
|
+
/*
|
256
|
+
* Document-class: FFI::DynamicLibrary
|
257
|
+
*/
|
217
258
|
LibraryClass = rb_define_class_under(moduleFFI, "DynamicLibrary", rb_cObject);
|
218
259
|
rb_global_variable(&LibraryClass);
|
260
|
+
/*
|
261
|
+
* Document-class: FFI::DynamicLibrary::Symbol < FFI::Pointer
|
262
|
+
*
|
263
|
+
* An instance of this class represents a library symbol. It may be a {Pointer pointer} to
|
264
|
+
* a function or to a variable.
|
265
|
+
*/
|
219
266
|
SymbolClass = rb_define_class_under(LibraryClass, "Symbol", rbffi_PointerClass);
|
220
267
|
rb_global_variable(&SymbolClass);
|
221
268
|
|
269
|
+
/*
|
270
|
+
* Document-const: FFI::NativeLibrary
|
271
|
+
* Backward compatibility for FFI::DynamicLibrary
|
272
|
+
*/
|
222
273
|
rb_define_const(moduleFFI, "NativeLibrary", LibraryClass); // backwards compat library
|
223
274
|
rb_define_alloc_func(LibraryClass, library_allocate);
|
224
275
|
rb_define_singleton_method(LibraryClass, "open", library_open, 2);
|
225
276
|
rb_define_singleton_method(LibraryClass, "last_error", library_dlerror, 0);
|
226
277
|
rb_define_method(LibraryClass, "initialize", library_initialize, 2);
|
278
|
+
/*
|
279
|
+
* Document-method: find_symbol
|
280
|
+
* call-seq: find_symbol(name)
|
281
|
+
* @param [String] name library symbol's name
|
282
|
+
* @return [FFI::DynamicLibrary::Symbol] library symbol
|
283
|
+
*/
|
227
284
|
rb_define_method(LibraryClass, "find_symbol", library_dlsym, 1);
|
285
|
+
/*
|
286
|
+
* Document-method: find_function
|
287
|
+
* call-seq: find_function(name)
|
288
|
+
* @param [String] name library function's name
|
289
|
+
* @return [FFI::DynamicLibrary::Symbol] library function symbol
|
290
|
+
*/
|
228
291
|
rb_define_method(LibraryClass, "find_function", library_dlsym, 1);
|
292
|
+
/*
|
293
|
+
* Document-method: find_variable
|
294
|
+
* call-seq: find_variable(name)
|
295
|
+
* @param [String] name library variable's name
|
296
|
+
* @return [FFI::DynamicLibrary::Symbol] library variable symbol
|
297
|
+
*/
|
229
298
|
rb_define_method(LibraryClass, "find_variable", library_dlsym, 1);
|
230
299
|
rb_define_method(LibraryClass, "last_error", library_dlerror, 0);
|
231
300
|
rb_define_attr(LibraryClass, "name", 1, 0);
|
data/ext/ffi_c/Function.c
CHANGED
@@ -20,16 +20,26 @@
|
|
20
20
|
|
21
21
|
#include "MethodHandle.h"
|
22
22
|
|
23
|
-
|
23
|
+
#ifndef _MSC_VER
|
24
24
|
#include <sys/param.h>
|
25
|
+
#endif
|
25
26
|
#include <sys/types.h>
|
26
27
|
#ifndef _WIN32
|
27
28
|
# include <sys/mman.h>
|
28
29
|
#endif
|
29
30
|
#include <stdio.h>
|
31
|
+
#ifndef _MSC_VER
|
30
32
|
#include <stdint.h>
|
31
33
|
#include <stdbool.h>
|
34
|
+
#else
|
35
|
+
typedef int bool;
|
36
|
+
#define true 1
|
37
|
+
#define false 0
|
38
|
+
#endif
|
32
39
|
#include <ruby.h>
|
40
|
+
#if defined(_MSC_VER) && !defined(INT8_MIN)
|
41
|
+
# include "win32/stdint.h"
|
42
|
+
#endif
|
33
43
|
|
34
44
|
#include <ffi.h>
|
35
45
|
#if defined(HAVE_NATIVETHREAD) && !defined(_WIN32)
|
@@ -69,9 +79,7 @@ static void callback_invoke(ffi_cif* cif, void* retval, void** parameters, void*
|
|
69
79
|
static bool callback_prep(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize);
|
70
80
|
static void* callback_with_gvl(void* data);
|
71
81
|
|
72
|
-
#
|
73
|
-
# define DEFER_ASYNC_CALLBACK 1
|
74
|
-
#endif
|
82
|
+
#define DEFER_ASYNC_CALLBACK 1
|
75
83
|
|
76
84
|
|
77
85
|
#if defined(DEFER_ASYNC_CALLBACK)
|
@@ -117,8 +125,11 @@ static struct gvl_callback* async_cb_list = NULL;
|
|
117
125
|
static int async_cb_pipe[2];
|
118
126
|
# endif
|
119
127
|
# else
|
120
|
-
static HANDLE async_cb_cond;
|
121
|
-
static CRITICAL_SECTION async_cb_lock;
|
128
|
+
static HANDLE async_cb_cond;
|
129
|
+
static CRITICAL_SECTION async_cb_lock;
|
130
|
+
# if !defined(HAVE_RB_THREAD_BLOCKING_REGION)
|
131
|
+
static int async_cb_pipe[2];
|
132
|
+
# endif
|
122
133
|
# endif
|
123
134
|
#endif
|
124
135
|
|
@@ -162,6 +173,20 @@ function_free(Function *fn)
|
|
162
173
|
xfree(fn);
|
163
174
|
}
|
164
175
|
|
176
|
+
/*
|
177
|
+
* @param [Type, Symbol] return_type return type for the function
|
178
|
+
* @param [Array<Type, Symbol>] param_types array of parameters types
|
179
|
+
* @param [Hash] options see {FFI::FunctionType} for available options
|
180
|
+
* @return [self]
|
181
|
+
* A new Function instance.
|
182
|
+
*
|
183
|
+
* Define a function from a Proc or a block.
|
184
|
+
*
|
185
|
+
* @overload initialize(return_type, param_types, options = {}) { |i| ... }
|
186
|
+
* @yieldparam i parameters for the function
|
187
|
+
* @overload initialize(return_type, param_types, proc, options = {})
|
188
|
+
* @param [Proc] proc
|
189
|
+
*/
|
165
190
|
static VALUE
|
166
191
|
function_initialize(int argc, VALUE* argv, VALUE self)
|
167
192
|
{
|
@@ -202,6 +227,11 @@ function_initialize(int argc, VALUE* argv, VALUE self)
|
|
202
227
|
return self;
|
203
228
|
}
|
204
229
|
|
230
|
+
/*
|
231
|
+
* call-seq: initialize_copy(other)
|
232
|
+
* @return [nil]
|
233
|
+
* DO NOT CALL THIS METHOD
|
234
|
+
*/
|
205
235
|
static VALUE
|
206
236
|
function_initialize_copy(VALUE self, VALUE other)
|
207
237
|
{
|
@@ -277,7 +307,9 @@ function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
|
|
277
307
|
|
278
308
|
#if defined(DEFER_ASYNC_CALLBACK)
|
279
309
|
if (async_cb_thread == Qnil) {
|
280
|
-
#if !defined(HAVE_RB_THREAD_BLOCKING_REGION)
|
310
|
+
#if !defined(HAVE_RB_THREAD_BLOCKING_REGION) && defined(_WIN32)
|
311
|
+
_pipe(async_cb_pipe, 1024, O_BINARY);
|
312
|
+
#elif !defined(HAVE_RB_THREAD_BLOCKING_REGION)
|
281
313
|
pipe(async_cb_pipe);
|
282
314
|
fcntl(async_cb_pipe[0], F_SETFL, fcntl(async_cb_pipe[0], F_GETFL) | O_NONBLOCK);
|
283
315
|
fcntl(async_cb_pipe[1], F_SETFL, fcntl(async_cb_pipe[1], F_GETFL) | O_NONBLOCK);
|
@@ -303,6 +335,12 @@ function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc)
|
|
303
335
|
return self;
|
304
336
|
}
|
305
337
|
|
338
|
+
/*
|
339
|
+
* call-seq: call(*args)
|
340
|
+
* @param [Array] args function arguments
|
341
|
+
* @return [FFI::Type]
|
342
|
+
* Call the function
|
343
|
+
*/
|
306
344
|
static VALUE
|
307
345
|
function_call(int argc, VALUE* argv, VALUE self)
|
308
346
|
{
|
@@ -313,6 +351,13 @@ function_call(int argc, VALUE* argv, VALUE self)
|
|
313
351
|
return (*fn->info->invoke)(argc, argv, fn->base.memory.address, fn->info);
|
314
352
|
}
|
315
353
|
|
354
|
+
/*
|
355
|
+
* call-seq: attach(m, name)
|
356
|
+
* @param [Module] m
|
357
|
+
* @param [String] name
|
358
|
+
* @return [self]
|
359
|
+
* Attach a Function to the Module +m+ as +name+.
|
360
|
+
*/
|
316
361
|
static VALUE
|
317
362
|
function_attach(VALUE self, VALUE module, VALUE name)
|
318
363
|
{
|
@@ -351,6 +396,12 @@ function_attach(VALUE self, VALUE module, VALUE name)
|
|
351
396
|
return self;
|
352
397
|
}
|
353
398
|
|
399
|
+
/*
|
400
|
+
* call-seq: autorelease = autorelease
|
401
|
+
* @param [Boolean] autorelease
|
402
|
+
* @return [self]
|
403
|
+
* Set +autorelease+ attribute (See {Pointer}).
|
404
|
+
*/
|
354
405
|
static VALUE
|
355
406
|
function_set_autorelease(VALUE self, VALUE autorelease)
|
356
407
|
{
|
@@ -373,6 +424,11 @@ function_autorelease_p(VALUE self)
|
|
373
424
|
return fn->autorelease ? Qtrue : Qfalse;
|
374
425
|
}
|
375
426
|
|
427
|
+
/*
|
428
|
+
* call-seq: free
|
429
|
+
* @return [self]
|
430
|
+
* Free memory allocated by Function.
|
431
|
+
*/
|
376
432
|
static VALUE
|
377
433
|
function_release(VALUE self)
|
378
434
|
{
|
@@ -441,16 +497,27 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
441
497
|
|
442
498
|
#elif defined(DEFER_ASYNC_CALLBACK) && defined(_WIN32)
|
443
499
|
} else {
|
500
|
+
bool empty = false;
|
501
|
+
|
444
502
|
cb.async_event = CreateEvent(NULL, FALSE, FALSE, NULL);
|
445
|
-
|
503
|
+
|
446
504
|
// Now signal the async callback thread
|
447
505
|
EnterCriticalSection(&async_cb_lock);
|
506
|
+
empty = async_cb_list == NULL;
|
448
507
|
cb.next = async_cb_list;
|
449
508
|
async_cb_list = &cb;
|
450
509
|
LeaveCriticalSection(&async_cb_lock);
|
451
510
|
|
511
|
+
#if !defined(HAVE_RB_THREAD_BLOCKING_REGION)
|
512
|
+
// Only signal if the list was empty
|
513
|
+
if (empty) {
|
514
|
+
char c;
|
515
|
+
write(async_cb_pipe[1], &c, 1);
|
516
|
+
}
|
517
|
+
#else
|
452
518
|
SetEvent(async_cb_cond);
|
453
|
-
|
519
|
+
#endif
|
520
|
+
|
454
521
|
// Wait for the thread executing the ruby callback to signal it is done
|
455
522
|
WaitForSingleObject(cb.async_event, INFINITE);
|
456
523
|
CloseHandle(cb.async_event);
|
@@ -481,10 +548,39 @@ async_cb_event(void* unused)
|
|
481
548
|
rb_thread_create(async_cb_call, w.cb);
|
482
549
|
}
|
483
550
|
}
|
484
|
-
|
551
|
+
|
485
552
|
return Qnil;
|
486
553
|
}
|
487
554
|
|
555
|
+
#elif defined(_WIN32)
|
556
|
+
static VALUE
|
557
|
+
async_cb_event(void* unused)
|
558
|
+
{
|
559
|
+
while (true) {
|
560
|
+
struct gvl_callback* cb;
|
561
|
+
char buf[64];
|
562
|
+
fd_set rfds;
|
563
|
+
|
564
|
+
FD_ZERO(&rfds);
|
565
|
+
FD_SET(async_cb_pipe[0], &rfds);
|
566
|
+
rb_thread_select(async_cb_pipe[0] + 1, &rfds, NULL, NULL, NULL);
|
567
|
+
read(async_cb_pipe[0], buf, sizeof(buf));
|
568
|
+
|
569
|
+
EnterCriticalSection(&async_cb_lock);
|
570
|
+
cb = async_cb_list;
|
571
|
+
async_cb_list = NULL;
|
572
|
+
LeaveCriticalSection(&async_cb_lock);
|
573
|
+
|
574
|
+
while (cb != NULL) {
|
575
|
+
struct gvl_callback* next = cb->next;
|
576
|
+
// Start up a new ruby thread to run the ruby callback
|
577
|
+
rb_thread_create(async_cb_call, cb);
|
578
|
+
cb = next;
|
579
|
+
}
|
580
|
+
}
|
581
|
+
|
582
|
+
return Qnil;
|
583
|
+
}
|
488
584
|
#else
|
489
585
|
static VALUE
|
490
586
|
async_cb_event(void* unused)
|
@@ -709,6 +805,7 @@ callback_with_gvl(void* data)
|
|
709
805
|
}
|
710
806
|
|
711
807
|
rbReturnValue = rb_funcall2(fn->rbProc, id_call, cbInfo->parameterCount, rbParams);
|
808
|
+
RB_GC_GUARD_PTR(rbParams);
|
712
809
|
|
713
810
|
if (unlikely(returnType->nativeType == NATIVE_MAPPED)) {
|
714
811
|
VALUE values[] = { rbReturnValue, Qnil };
|
@@ -822,6 +919,9 @@ void
|
|
822
919
|
rbffi_Function_Init(VALUE moduleFFI)
|
823
920
|
{
|
824
921
|
rbffi_FunctionInfo_Init(moduleFFI);
|
922
|
+
/*
|
923
|
+
* Document-class: FFI::Function < FFI::Pointer
|
924
|
+
*/
|
825
925
|
rbffi_FunctionClass = rb_define_class_under(moduleFFI, "Function", rbffi_PointerClass);
|
826
926
|
|
827
927
|
rb_global_variable(&rbffi_FunctionClass);
|
@@ -833,7 +933,18 @@ rbffi_Function_Init(VALUE moduleFFI)
|
|
833
933
|
rb_define_method(rbffi_FunctionClass, "attach", function_attach, 2);
|
834
934
|
rb_define_method(rbffi_FunctionClass, "free", function_release, 0);
|
835
935
|
rb_define_method(rbffi_FunctionClass, "autorelease=", function_set_autorelease, 1);
|
936
|
+
/*
|
937
|
+
* call-seq: autorelease
|
938
|
+
* @return [Boolean]
|
939
|
+
* Get +autorelease+ attribute.
|
940
|
+
* Synonymous for {#autorelease?}.
|
941
|
+
*/
|
836
942
|
rb_define_method(rbffi_FunctionClass, "autorelease", function_autorelease_p, 0);
|
943
|
+
/*
|
944
|
+
* call-seq: autorelease?
|
945
|
+
* @return [Boolean] +autorelease+ attribute
|
946
|
+
* Get +autorelease+ attribute.
|
947
|
+
*/
|
837
948
|
rb_define_method(rbffi_FunctionClass, "autorelease?", function_autorelease_p, 0);
|
838
949
|
|
839
950
|
id_call = rb_intern("call");
|
@@ -841,7 +952,7 @@ rbffi_Function_Init(VALUE moduleFFI)
|
|
841
952
|
id_cb_ref = rb_intern("@__ffi_callback__");
|
842
953
|
id_to_native = rb_intern("to_native");
|
843
954
|
id_from_native = rb_intern("from_native");
|
844
|
-
#if defined(_WIN32)
|
955
|
+
#if defined(_WIN32)
|
845
956
|
InitializeCriticalSection(&async_cb_lock);
|
846
957
|
async_cb_cond = CreateEvent(NULL, FALSE, FALSE, NULL);
|
847
958
|
#endif
|