ffi 0.4.0 → 0.5.0
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/README.rdoc +15 -15
- data/Rakefile +57 -8
- data/ext/ffi_c/AbstractMemory.c +101 -24
- data/ext/ffi_c/AbstractMemory.h +98 -6
- data/ext/ffi_c/ArrayType.c +129 -0
- data/ext/ffi_c/ArrayType.h +58 -0
- data/ext/ffi_c/AutoPointer.c +1 -0
- data/ext/ffi_c/Buffer.c +59 -43
- data/ext/ffi_c/Call.c +853 -0
- data/ext/ffi_c/Call.h +86 -0
- data/ext/ffi_c/ClosurePool.c +302 -0
- data/ext/ffi_c/ClosurePool.h +29 -0
- data/ext/ffi_c/DynamicLibrary.c +3 -0
- data/ext/ffi_c/Function.c +478 -0
- data/ext/ffi_c/Function.h +80 -0
- data/ext/ffi_c/FunctionInfo.c +221 -0
- data/ext/ffi_c/LastError.c +30 -6
- data/ext/ffi_c/MemoryPointer.c +50 -28
- data/ext/ffi_c/MethodHandle.c +346 -0
- data/ext/ffi_c/MethodHandle.h +53 -0
- data/ext/ffi_c/Pointer.c +73 -13
- data/ext/ffi_c/Pointer.h +31 -7
- data/ext/ffi_c/Struct.c +517 -224
- data/ext/ffi_c/Struct.h +60 -6
- data/ext/ffi_c/StructByValue.c +140 -0
- data/ext/ffi_c/StructByValue.h +53 -0
- data/ext/ffi_c/StructLayout.c +450 -0
- data/ext/ffi_c/Type.c +121 -22
- data/ext/ffi_c/Type.h +37 -8
- data/ext/ffi_c/Types.c +46 -61
- data/ext/ffi_c/Types.h +38 -7
- data/ext/ffi_c/Variadic.c +260 -0
- data/ext/ffi_c/compat.h +53 -3
- data/ext/ffi_c/extconf.rb +6 -7
- data/ext/ffi_c/ffi.c +45 -39
- data/ext/ffi_c/libffi.darwin.mk +2 -2
- data/ext/ffi_c/rbffi.h +3 -0
- data/lib/ffi/ffi.rb +7 -4
- data/lib/ffi/library.rb +34 -59
- data/lib/ffi/platform.rb +14 -4
- data/lib/ffi/struct.rb +110 -281
- data/lib/ffi/union.rb +4 -9
- data/lib/ffi/variadic.rb +1 -6
- data/spec/ffi/buffer_spec.rb +6 -0
- data/spec/ffi/callback_spec.rb +34 -3
- data/spec/ffi/function_spec.rb +73 -0
- data/spec/ffi/library_spec.rb +56 -52
- data/spec/ffi/pointer_spec.rb +3 -3
- data/spec/ffi/struct_callback_spec.rb +26 -3
- data/spec/ffi/struct_spec.rb +56 -3
- metadata +42 -11
- data/ext/ffi_c/Callback.c +0 -374
- data/ext/ffi_c/Callback.h +0 -47
- data/ext/ffi_c/Invoker.c +0 -962
- data/ext/ffi_c/NullPointer.c +0 -143
data/ext/ffi_c/NullPointer.c
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
#include <sys/types.h>
|
2
|
-
#include <stdbool.h>
|
3
|
-
#include <stdint.h>
|
4
|
-
#include <limits.h>
|
5
|
-
#include <ruby.h>
|
6
|
-
#include "rbffi.h"
|
7
|
-
#include "AbstractMemory.h"
|
8
|
-
#include "Pointer.h"
|
9
|
-
|
10
|
-
static VALUE NullPointerErrorClass;
|
11
|
-
|
12
|
-
VALUE rbffi_NullPointerClass;
|
13
|
-
VALUE rbffi_NullPointerSingleton;
|
14
|
-
|
15
|
-
static VALUE
|
16
|
-
nullptr_allocate(VALUE klass)
|
17
|
-
{
|
18
|
-
AbstractMemory* p;
|
19
|
-
VALUE retval;
|
20
|
-
|
21
|
-
retval = Data_Make_Struct(klass, AbstractMemory, NULL, -1, p);
|
22
|
-
p->address = 0;
|
23
|
-
p->size = 0;
|
24
|
-
p->ops = &rbffi_NullPointerOps;
|
25
|
-
|
26
|
-
return retval;
|
27
|
-
}
|
28
|
-
|
29
|
-
static VALUE
|
30
|
-
nullptr_op(int argc, VALUE* argv, VALUE self)
|
31
|
-
{
|
32
|
-
rb_raise(NullPointerErrorClass, "NULL Pointer access attempted");
|
33
|
-
return Qnil;
|
34
|
-
}
|
35
|
-
|
36
|
-
static VALUE
|
37
|
-
nullptr_op_get(AbstractMemory* ptr, long offset)
|
38
|
-
{
|
39
|
-
rb_raise(NullPointerErrorClass, "NULL Pointer access attempted");
|
40
|
-
return Qnil;
|
41
|
-
}
|
42
|
-
|
43
|
-
static void
|
44
|
-
nullptr_op_put(AbstractMemory* ptr, long offset, VALUE value)
|
45
|
-
{
|
46
|
-
rb_raise(NullPointerErrorClass, "NULL Pointer access attempted");
|
47
|
-
}
|
48
|
-
|
49
|
-
static VALUE
|
50
|
-
nullptr_inspect(VALUE self)
|
51
|
-
{
|
52
|
-
return rb_str_new2("#<NULL Pointer address=0x0>");
|
53
|
-
}
|
54
|
-
|
55
|
-
static VALUE
|
56
|
-
nullptr_null_p(VALUE self)
|
57
|
-
{
|
58
|
-
return Qtrue;
|
59
|
-
}
|
60
|
-
|
61
|
-
static VALUE
|
62
|
-
nullptr_equals(VALUE self, VALUE other)
|
63
|
-
{
|
64
|
-
AbstractMemory* p2;
|
65
|
-
|
66
|
-
if (!rb_obj_is_kind_of(other, rbffi_PointerClass)) {
|
67
|
-
rb_raise(rb_eArgError, "Comparing Pointer with non Pointer");
|
68
|
-
}
|
69
|
-
|
70
|
-
Data_Get_Struct(other, AbstractMemory, p2);
|
71
|
-
|
72
|
-
return p2->address == 0 ? Qtrue : Qfalse;
|
73
|
-
}
|
74
|
-
|
75
|
-
static VALUE
|
76
|
-
nullptr_address(VALUE self)
|
77
|
-
{
|
78
|
-
return INT2NUM(0);
|
79
|
-
}
|
80
|
-
|
81
|
-
static MemoryOp NullPointerMemoryOp = { nullptr_op_get, nullptr_op_put };
|
82
|
-
|
83
|
-
MemoryOps rbffi_NullPointerOps = {
|
84
|
-
.int8 = &NullPointerMemoryOp,
|
85
|
-
.uint8 = &NullPointerMemoryOp,
|
86
|
-
.int16 = &NullPointerMemoryOp,
|
87
|
-
.int16 = &NullPointerMemoryOp,
|
88
|
-
.int32 = &NullPointerMemoryOp,
|
89
|
-
.uint32 = &NullPointerMemoryOp,
|
90
|
-
.int64 = &NullPointerMemoryOp,
|
91
|
-
.uint64 = &NullPointerMemoryOp,
|
92
|
-
.float32 = &NullPointerMemoryOp,
|
93
|
-
.float64 = &NullPointerMemoryOp,
|
94
|
-
.pointer = &NullPointerMemoryOp,
|
95
|
-
.strptr = &NullPointerMemoryOp,
|
96
|
-
};
|
97
|
-
|
98
|
-
void
|
99
|
-
rbffi_NullPointer_Init(VALUE moduleFFI)
|
100
|
-
{
|
101
|
-
rbffi_NullPointerClass = rb_define_class_under(moduleFFI, "NullPointer", rbffi_PointerClass);
|
102
|
-
rb_global_variable(&rbffi_NullPointerClass);
|
103
|
-
|
104
|
-
NullPointerErrorClass = rb_define_class_under(moduleFFI, "NullPointerError", rb_eRuntimeError);
|
105
|
-
rb_global_variable(&NullPointerErrorClass);
|
106
|
-
|
107
|
-
rb_define_alloc_func(rbffi_NullPointerClass, nullptr_allocate);
|
108
|
-
rb_define_method(rbffi_NullPointerClass, "inspect", nullptr_inspect, 0);
|
109
|
-
rb_define_method(rbffi_NullPointerClass, "+", nullptr_op, -1);
|
110
|
-
rb_define_method(rbffi_NullPointerClass, "null?", nullptr_null_p, 0);
|
111
|
-
rb_define_method(rbffi_NullPointerClass, "address", nullptr_address, 0);
|
112
|
-
rb_define_method(rbffi_NullPointerClass, "==", nullptr_equals, 1);
|
113
|
-
|
114
|
-
#define NOP(name) \
|
115
|
-
rb_define_method(rbffi_NullPointerClass, "get_" #name, nullptr_op, -1); \
|
116
|
-
rb_define_method(rbffi_NullPointerClass, "put_" #name, nullptr_op, -1); \
|
117
|
-
rb_define_method(rbffi_NullPointerClass, "get_array_of_" #name, nullptr_op, -1); \
|
118
|
-
rb_define_method(rbffi_NullPointerClass, "put_array_of_" #name, nullptr_op, -1); \
|
119
|
-
|
120
|
-
|
121
|
-
NOP(int8); NOP(uint8); NOP(int16); NOP(uint16);
|
122
|
-
NOP(int32); NOP(uint32); NOP(int64); NOP(uint64); NOP(long); NOP(ulong);
|
123
|
-
NOP(float32); NOP(float64);
|
124
|
-
NOP(char); NOP(uchar); NOP(short); NOP(ushort);
|
125
|
-
NOP(int); NOP(uint); NOP(long_long); NOP(ulong_long);
|
126
|
-
NOP(float); NOP(double);
|
127
|
-
|
128
|
-
#undef NOP
|
129
|
-
#define NOP(name) \
|
130
|
-
rb_define_method(rbffi_NullPointerClass, "get_" #name, nullptr_op, -1); \
|
131
|
-
rb_define_method(rbffi_NullPointerClass, "put_" #name, nullptr_op, -1);
|
132
|
-
|
133
|
-
NOP(string); NOP(bytes); NOP(pointer); NOP(callback);
|
134
|
-
|
135
|
-
rb_define_method(rbffi_NullPointerClass, "clear", nullptr_op, -1); \
|
136
|
-
rb_define_method(rbffi_NullPointerClass, "total", nullptr_op, -1);
|
137
|
-
|
138
|
-
// Create a singleton instance of NullPointer that can be shared
|
139
|
-
rbffi_NullPointerSingleton = nullptr_allocate(rbffi_NullPointerClass);
|
140
|
-
rb_global_variable(&rbffi_NullPointerSingleton);
|
141
|
-
rb_define_const(rbffi_PointerClass, "NULL", rbffi_NullPointerSingleton);
|
142
|
-
}
|
143
|
-
|