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/AbstractMemory.h
CHANGED
@@ -21,9 +21,13 @@
|
|
21
21
|
#ifndef RBFFI_ABSTRACTMEMORY_H
|
22
22
|
#define RBFFI_ABSTRACTMEMORY_H
|
23
23
|
|
24
|
+
#ifndef _MSC_VER
|
24
25
|
#include <sys/param.h>
|
26
|
+
#endif
|
25
27
|
#include <sys/types.h>
|
28
|
+
#ifndef _MSC_VER
|
26
29
|
#include <stdint.h>
|
30
|
+
#endif
|
27
31
|
|
28
32
|
#include "compat.h"
|
29
33
|
#include "Types.h"
|
@@ -37,6 +41,7 @@ extern "C" {
|
|
37
41
|
#define MEM_WR 0x02
|
38
42
|
#define MEM_CODE 0x04
|
39
43
|
#define MEM_SWAP 0x08
|
44
|
+
#define MEM_EMBED 0x10
|
40
45
|
|
41
46
|
typedef struct AbstractMemory_ AbstractMemory;
|
42
47
|
|
@@ -60,6 +65,7 @@ typedef struct {
|
|
60
65
|
MemoryOp* float64;
|
61
66
|
MemoryOp* pointer;
|
62
67
|
MemoryOp* strptr;
|
68
|
+
MemoryOp* boolOp;
|
63
69
|
} MemoryOps;
|
64
70
|
|
65
71
|
struct AbstractMemory_ {
|
@@ -136,6 +142,8 @@ get_memory_op(Type* type)
|
|
136
142
|
return rbffi_AbstractMemoryOps.pointer;
|
137
143
|
case NATIVE_STRING:
|
138
144
|
return rbffi_AbstractMemoryOps.strptr;
|
145
|
+
case NATIVE_BOOL:
|
146
|
+
return rbffi_AbstractMemoryOps.boolOp;
|
139
147
|
default:
|
140
148
|
return NULL;
|
141
149
|
}
|
data/ext/ffi_c/ArrayType.c
CHANGED
@@ -62,6 +62,13 @@ array_type_free(ArrayType *array)
|
|
62
62
|
}
|
63
63
|
|
64
64
|
|
65
|
+
/*
|
66
|
+
* call-seq: initialize(component_type, length)
|
67
|
+
* @param [Type] component_type
|
68
|
+
* @param [Numeric] length
|
69
|
+
* @return [self]
|
70
|
+
* A new instance of ArrayType.
|
71
|
+
*/
|
65
72
|
static VALUE
|
66
73
|
array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength)
|
67
74
|
{
|
@@ -86,6 +93,11 @@ array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength)
|
|
86
93
|
return self;
|
87
94
|
}
|
88
95
|
|
96
|
+
/*
|
97
|
+
* call-seq: length
|
98
|
+
* @return [Numeric]
|
99
|
+
* Get array's length
|
100
|
+
*/
|
89
101
|
static VALUE
|
90
102
|
array_type_length(VALUE self)
|
91
103
|
{
|
@@ -96,6 +108,11 @@ array_type_length(VALUE self)
|
|
96
108
|
return UINT2NUM(array->length);
|
97
109
|
}
|
98
110
|
|
111
|
+
/*
|
112
|
+
* call-seq: element_type
|
113
|
+
* @return [Type]
|
114
|
+
* Get element type.
|
115
|
+
*/
|
99
116
|
static VALUE
|
100
117
|
array_type_element_type(VALUE self)
|
101
118
|
{
|
@@ -109,8 +126,19 @@ array_type_element_type(VALUE self)
|
|
109
126
|
void
|
110
127
|
rbffi_ArrayType_Init(VALUE moduleFFI)
|
111
128
|
{
|
129
|
+
/*
|
130
|
+
* Document-class: FFI::ArrayType < FFI::Type
|
131
|
+
*
|
132
|
+
* This is a typed array. The type is a {NativeType native type}.
|
133
|
+
*/
|
112
134
|
rbffi_ArrayTypeClass = rb_define_class_under(moduleFFI, "ArrayType", rbffi_TypeClass);
|
135
|
+
/*
|
136
|
+
* Document-variable: FFI::ArrayType
|
137
|
+
*/
|
113
138
|
rb_global_variable(&rbffi_ArrayTypeClass);
|
139
|
+
/*
|
140
|
+
* Document-constant: FFI::Type::Array
|
141
|
+
*/
|
114
142
|
rb_define_const(rbffi_TypeClass, "Array", rbffi_ArrayTypeClass);
|
115
143
|
|
116
144
|
rb_define_alloc_func(rbffi_ArrayTypeClass, array_type_s_allocate);
|
data/ext/ffi_c/Buffer.c
CHANGED
@@ -18,18 +18,31 @@
|
|
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"
|
26
34
|
#include "endian.h"
|
27
35
|
#include "AbstractMemory.h"
|
28
36
|
|
37
|
+
#define BUFFER_EMBED_MAXLEN (8)
|
29
38
|
typedef struct Buffer {
|
30
39
|
AbstractMemory memory;
|
31
|
-
|
32
|
-
|
40
|
+
|
41
|
+
union {
|
42
|
+
VALUE rbParent; /* link to parent buffer */
|
43
|
+
char* storage; /* start of malloc area */
|
44
|
+
long embed[BUFFER_EMBED_MAXLEN / sizeof(long)]; // storage for tiny allocations
|
45
|
+
} data;
|
33
46
|
} Buffer;
|
34
47
|
|
35
48
|
static VALUE buffer_allocate(VALUE klass);
|
@@ -47,7 +60,7 @@ buffer_allocate(VALUE klass)
|
|
47
60
|
VALUE obj;
|
48
61
|
|
49
62
|
obj = Data_Make_Struct(klass, Buffer, NULL, buffer_release, buffer);
|
50
|
-
buffer->rbParent = Qnil;
|
63
|
+
buffer->data.rbParent = Qnil;
|
51
64
|
buffer->memory.flags = MEM_RD | MEM_WR;
|
52
65
|
|
53
66
|
return obj;
|
@@ -56,14 +69,23 @@ buffer_allocate(VALUE klass)
|
|
56
69
|
static void
|
57
70
|
buffer_release(Buffer* ptr)
|
58
71
|
{
|
59
|
-
if (ptr->storage != NULL) {
|
60
|
-
xfree(ptr->storage);
|
61
|
-
ptr->storage = NULL;
|
72
|
+
if ((ptr->memory.flags & MEM_EMBED) == 0 && ptr->data.storage != NULL) {
|
73
|
+
xfree(ptr->data.storage);
|
74
|
+
ptr->data.storage = NULL;
|
62
75
|
}
|
63
76
|
|
64
77
|
xfree(ptr);
|
65
78
|
}
|
66
79
|
|
80
|
+
/*
|
81
|
+
* call-seq: initialize(size, count=1, clear=false)
|
82
|
+
* @param [Integer, Symbol, #size] Type or size in bytes of a buffer cell
|
83
|
+
* @param [Fixnum] count number of cell in the Buffer
|
84
|
+
* @param [Boolean] clear if true, set the buffer to all-zero
|
85
|
+
* @return [self]
|
86
|
+
* @raise {NoMemoryError} if failed to allocate memory for Buffer
|
87
|
+
* A new instance of Buffer.
|
88
|
+
*/
|
67
89
|
static VALUE
|
68
90
|
buffer_initialize(int argc, VALUE* argv, VALUE self)
|
69
91
|
{
|
@@ -77,17 +99,23 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
|
|
77
99
|
p->memory.typeSize = rbffi_type_size(rbSize);
|
78
100
|
p->memory.size = p->memory.typeSize * (nargs > 1 ? NUM2LONG(rbCount) : 1);
|
79
101
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
102
|
+
if (p->memory.size > BUFFER_EMBED_MAXLEN) {
|
103
|
+
p->data.storage = xmalloc(p->memory.size + 7);
|
104
|
+
if (p->data.storage == NULL) {
|
105
|
+
rb_raise(rb_eNoMemError, "Failed to allocate memory size=%lu bytes", p->memory.size);
|
106
|
+
return Qnil;
|
107
|
+
}
|
85
108
|
|
86
|
-
|
87
|
-
|
109
|
+
/* ensure the memory is aligned on at least a 8 byte boundary */
|
110
|
+
p->memory.address = (void *) (((uintptr_t) p->data.storage + 0x7) & (uintptr_t) ~0x7UL);
|
111
|
+
|
112
|
+
if (p->memory.size > 0 && (nargs < 3 || RTEST(rbClear))) {
|
113
|
+
memset(p->memory.address, 0, p->memory.size);
|
114
|
+
}
|
88
115
|
|
89
|
-
|
90
|
-
|
116
|
+
} else {
|
117
|
+
p->memory.flags |= MEM_EMBED;
|
118
|
+
p->memory.address = (void *) &p->data.embed[0];
|
91
119
|
}
|
92
120
|
|
93
121
|
if (rb_block_given_p()) {
|
@@ -97,6 +125,11 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
|
|
97
125
|
return self;
|
98
126
|
}
|
99
127
|
|
128
|
+
/*
|
129
|
+
* call-seq: initialize_copy(other)
|
130
|
+
* @return [self]
|
131
|
+
* DO NOT CALL THIS METHOD.
|
132
|
+
*/
|
100
133
|
static VALUE
|
101
134
|
buffer_initialize_copy(VALUE self, VALUE other)
|
102
135
|
{
|
@@ -105,16 +138,16 @@ buffer_initialize_copy(VALUE self, VALUE other)
|
|
105
138
|
|
106
139
|
Data_Get_Struct(self, Buffer, dst);
|
107
140
|
src = rbffi_AbstractMemory_Cast(other, BufferClass);
|
108
|
-
if (dst->storage != NULL) {
|
109
|
-
xfree(dst->storage);
|
141
|
+
if ((dst->memory.flags & MEM_EMBED) == 0 && dst->data.storage != NULL) {
|
142
|
+
xfree(dst->data.storage);
|
110
143
|
}
|
111
|
-
dst->storage = xmalloc(src->size + 7);
|
112
|
-
if (dst->storage == NULL) {
|
144
|
+
dst->data.storage = xmalloc(src->size + 7);
|
145
|
+
if (dst->data.storage == NULL) {
|
113
146
|
rb_raise(rb_eNoMemError, "failed to allocate memory size=%lu bytes", src->size);
|
114
147
|
return Qnil;
|
115
148
|
}
|
116
149
|
|
117
|
-
dst->memory.address = (void *) (((uintptr_t) dst->storage + 0x7) & (uintptr_t) ~0x7UL);
|
150
|
+
dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~0x7UL);
|
118
151
|
dst->memory.size = src->size;
|
119
152
|
dst->memory.typeSize = src->typeSize;
|
120
153
|
|
@@ -145,11 +178,17 @@ slice(VALUE self, long offset, long len)
|
|
145
178
|
result->memory.size = len;
|
146
179
|
result->memory.flags = ptr->memory.flags;
|
147
180
|
result->memory.typeSize = ptr->memory.typeSize;
|
148
|
-
result->rbParent = self;
|
181
|
+
result->data.rbParent = self;
|
149
182
|
|
150
183
|
return obj;
|
151
184
|
}
|
152
185
|
|
186
|
+
/*
|
187
|
+
* call-seq: + offset
|
188
|
+
* @param [Numeric] offset
|
189
|
+
* @return [Buffer] a new instance of Buffer pointing from offset until end of previous buffer.
|
190
|
+
* Add a Buffer with an offset
|
191
|
+
*/
|
153
192
|
static VALUE
|
154
193
|
buffer_plus(VALUE self, VALUE rbOffset)
|
155
194
|
{
|
@@ -161,12 +200,24 @@ buffer_plus(VALUE self, VALUE rbOffset)
|
|
161
200
|
return slice(self, offset, ptr->memory.size - offset);
|
162
201
|
}
|
163
202
|
|
203
|
+
/*
|
204
|
+
* call-seq: slice(offset, length)
|
205
|
+
* @param [Numeric] offset
|
206
|
+
* @param [Numeric] length
|
207
|
+
* @return [Buffer] a new instance of Buffer
|
208
|
+
* Slice an existing Buffer.
|
209
|
+
*/
|
164
210
|
static VALUE
|
165
211
|
buffer_slice(VALUE self, VALUE rbOffset, VALUE rbLength)
|
166
212
|
{
|
167
213
|
return slice(self, NUM2LONG(rbOffset), NUM2LONG(rbLength));
|
168
214
|
}
|
169
215
|
|
216
|
+
/*
|
217
|
+
* call-seq: inspect
|
218
|
+
* @return [String]
|
219
|
+
* Inspect a Buffer.
|
220
|
+
*/
|
170
221
|
static VALUE
|
171
222
|
buffer_inspect(VALUE self)
|
172
223
|
{
|
@@ -187,6 +238,16 @@ buffer_inspect(VALUE self)
|
|
187
238
|
# define SWAPPED_ORDER LITTLE_ENDIAN
|
188
239
|
#endif
|
189
240
|
|
241
|
+
/*
|
242
|
+
* Set or get endianness of Buffer.
|
243
|
+
* @overload order
|
244
|
+
* @return [:big, :little]
|
245
|
+
* Get endianness of Buffer.
|
246
|
+
* @overload order(order)
|
247
|
+
* @param [:big, :little, :network] order
|
248
|
+
* @return [self]
|
249
|
+
* Set endinaness of Buffer (+:network+ is an alias for +:big+).
|
250
|
+
*/
|
190
251
|
static VALUE
|
191
252
|
buffer_order(int argc, VALUE* argv, VALUE self)
|
192
253
|
{
|
@@ -232,9 +293,9 @@ buffer_free(VALUE self)
|
|
232
293
|
Buffer* ptr;
|
233
294
|
|
234
295
|
Data_Get_Struct(self, Buffer, ptr);
|
235
|
-
if (ptr->storage != NULL) {
|
236
|
-
xfree(ptr->storage);
|
237
|
-
ptr->storage = NULL;
|
296
|
+
if ((ptr->memory.flags & MEM_EMBED) == 0 && ptr->data.storage != NULL) {
|
297
|
+
xfree(ptr->data.storage);
|
298
|
+
ptr->data.storage = NULL;
|
238
299
|
}
|
239
300
|
|
240
301
|
return self;
|
@@ -243,19 +304,42 @@ buffer_free(VALUE self)
|
|
243
304
|
static void
|
244
305
|
buffer_mark(Buffer* ptr)
|
245
306
|
{
|
246
|
-
rb_gc_mark(ptr->rbParent);
|
307
|
+
rb_gc_mark(ptr->data.rbParent);
|
247
308
|
}
|
248
309
|
|
249
310
|
void
|
250
311
|
rbffi_Buffer_Init(VALUE moduleFFI)
|
251
312
|
{
|
313
|
+
/*
|
314
|
+
* Document-class: FFI::Buffer < FFI::AbstractMemory
|
315
|
+
*
|
316
|
+
* A Buffer is a function argument type. It should be use with functions playing with C arrays.
|
317
|
+
*/
|
252
318
|
BufferClass = rb_define_class_under(moduleFFI, "Buffer", rbffi_AbstractMemoryClass);
|
253
319
|
|
320
|
+
/*
|
321
|
+
* Document-variable: FFI::Buffer
|
322
|
+
*/
|
254
323
|
rb_global_variable(&BufferClass);
|
255
324
|
rb_define_alloc_func(BufferClass, buffer_allocate);
|
256
325
|
|
326
|
+
/*
|
327
|
+
* Document-method: alloc_inout
|
328
|
+
* call-seq: alloc_inout(*args)
|
329
|
+
* Create a new Buffer for in and out arguments (alias : <i>new_inout</i>).
|
330
|
+
*/
|
257
331
|
rb_define_singleton_method(BufferClass, "alloc_inout", buffer_alloc_inout, -1);
|
332
|
+
/*
|
333
|
+
* Document-method: alloc_out
|
334
|
+
* call-seq: alloc_out(*args)
|
335
|
+
* Create a new Buffer for out arguments (alias : <i>new_out</i>).
|
336
|
+
*/
|
258
337
|
rb_define_singleton_method(BufferClass, "alloc_out", buffer_alloc_inout, -1);
|
338
|
+
/*
|
339
|
+
* Document-method: alloc_in
|
340
|
+
* call-seq: alloc_in(*args)
|
341
|
+
* Create a new Buffer for in arguments (alias : <i>new_in</i>).
|
342
|
+
*/
|
259
343
|
rb_define_singleton_method(BufferClass, "alloc_in", buffer_alloc_inout, -1);
|
260
344
|
rb_define_alias(rb_singleton_class(BufferClass), "new_in", "alloc_in");
|
261
345
|
rb_define_alias(rb_singleton_class(BufferClass), "new_out", "alloc_out");
|
data/ext/ffi_c/Call.c
CHANGED
@@ -20,11 +20,19 @@
|
|
20
20
|
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
21
21
|
*/
|
22
22
|
|
23
|
+
#ifndef _MSC_VER
|
23
24
|
#include <sys/param.h>
|
25
|
+
#endif
|
24
26
|
#include <sys/types.h>
|
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
|
#include <errno.h>
|
29
37
|
#include <ruby.h>
|
30
38
|
#if defined(HAVE_NATIVETHREAD) && defined(HAVE_RB_THREAD_BLOCKING_REGION) && !defined(_WIN32)
|
@@ -288,7 +296,7 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
288
296
|
void** ffiValues;
|
289
297
|
FFIStorage* params;
|
290
298
|
VALUE rbReturnValue;
|
291
|
-
|
299
|
+
|
292
300
|
#if !defined(HAVE_RUBY_THREAD_HAS_GVL_P)
|
293
301
|
rbffi_thread_t oldThread;
|
294
302
|
#endif
|
@@ -329,7 +337,6 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
329
337
|
oldThread = rbffi_active_thread;
|
330
338
|
rbffi_active_thread = rbffi_thread_self();
|
331
339
|
#endif
|
332
|
-
retval = alloca(MAX(fnInfo->ffi_cif.rtype->size, FFI_SIZEOF_ARG));
|
333
340
|
ffi_call(&fnInfo->ffi_cif, FFI_FN(function), retval, ffiValues);
|
334
341
|
|
335
342
|
#if !defined(HAVE_RUBY_THREAD_HAS_GVL_P)
|
@@ -339,9 +346,12 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
339
346
|
|
340
347
|
if (unlikely(!fnInfo->ignoreErrno)) {
|
341
348
|
rbffi_save_errno();
|
342
|
-
}
|
343
|
-
|
344
|
-
|
349
|
+
}
|
350
|
+
|
351
|
+
RB_GC_GUARD(rbReturnValue) = rbffi_NativeValue_ToRuby(fnInfo->returnType, fnInfo->rbReturnType, retval);
|
352
|
+
RB_GC_GUARD(fnInfo->rbReturnType);
|
353
|
+
|
354
|
+
return rbReturnValue;
|
345
355
|
}
|
346
356
|
|
347
357
|
static inline void*
|
@@ -423,6 +433,7 @@ callback_param(VALUE proc, VALUE cbInfo)
|
|
423
433
|
|
424
434
|
//callback = rbffi_NativeCallback_ForProc(proc, cbInfo);
|
425
435
|
callback = rbffi_Function_ForProc(cbInfo, proc);
|
436
|
+
RB_GC_GUARD(callback);
|
426
437
|
|
427
438
|
return ((AbstractMemory *) DATA_PTR(callback))->address;
|
428
439
|
}
|
data/ext/ffi_c/ClosurePool.c
CHANGED
@@ -17,22 +17,35 @@
|
|
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
|
#else
|
39
|
+
# include <winsock2.h>
|
40
|
+
# define _WINSOCKAPI_
|
31
41
|
# include <windows.h>
|
32
42
|
#endif
|
33
43
|
#include <errno.h>
|
34
44
|
#include <ruby.h>
|
35
45
|
|
46
|
+
#if defined(_MSC_VER) && !defined(INT8_MIN)
|
47
|
+
# include "win32/stdint.h"
|
48
|
+
#endif
|
36
49
|
#include <ffi.h>
|
37
50
|
#include "rbffi.h"
|
38
51
|
#include "compat.h"
|
@@ -68,7 +81,7 @@ struct ClosurePool_ {
|
|
68
81
|
long refcnt;
|
69
82
|
};
|
70
83
|
|
71
|
-
static
|
84
|
+
static long pageSize;
|
72
85
|
|
73
86
|
static void* allocatePage(void);
|
74
87
|
static bool freePage(void *);
|
@@ -102,15 +115,14 @@ cleanup_closure_pool(ClosurePool* pool)
|
|
102
115
|
free(memory);
|
103
116
|
memory = next;
|
104
117
|
}
|
105
|
-
|
118
|
+
xfree(pool);
|
106
119
|
}
|
107
120
|
|
108
121
|
void
|
109
122
|
rbffi_ClosurePool_Free(ClosurePool* pool)
|
110
123
|
{
|
111
124
|
if (pool != NULL) {
|
112
|
-
|
113
|
-
refcnt = --(pool->refcnt);
|
125
|
+
long refcnt = --(pool->refcnt);
|
114
126
|
if (refcnt == 0) {
|
115
127
|
cleanup_closure_pool(pool);
|
116
128
|
}
|
@@ -124,7 +136,8 @@ rbffi_Closure_Alloc(ClosurePool* pool)
|
|
124
136
|
Memory* block = NULL;
|
125
137
|
caddr_t code = NULL;
|
126
138
|
char errmsg[256];
|
127
|
-
int nclosures
|
139
|
+
int nclosures;
|
140
|
+
long trampolineSize;
|
128
141
|
int i;
|
129
142
|
|
130
143
|
if (pool->list != NULL) {
|
@@ -136,7 +149,7 @@ rbffi_Closure_Alloc(ClosurePool* pool)
|
|
136
149
|
}
|
137
150
|
|
138
151
|
trampolineSize = roundup(pool->closureSize, 8);
|
139
|
-
nclosures = pageSize / trampolineSize;
|
152
|
+
nclosures = (int) (pageSize / trampolineSize);
|
140
153
|
block = calloc(1, sizeof(*block));
|
141
154
|
list = calloc(nclosures, sizeof(*list));
|
142
155
|
code = allocatePage();
|
@@ -192,7 +205,7 @@ rbffi_Closure_Free(Closure* closure)
|
|
192
205
|
{
|
193
206
|
if (closure != NULL) {
|
194
207
|
ClosurePool* pool = closure->pool;
|
195
|
-
|
208
|
+
long refcnt;
|
196
209
|
// Just push it on the front of the free list
|
197
210
|
closure->next = pool->list;
|
198
211
|
pool->list = closure;
|
@@ -210,7 +223,7 @@ rbffi_Closure_CodeAddress(Closure* handle)
|
|
210
223
|
}
|
211
224
|
|
212
225
|
|
213
|
-
static
|
226
|
+
static long
|
214
227
|
getPageSize()
|
215
228
|
{
|
216
229
|
#if defined(_WIN32) || defined(__WIN32__)
|