ffi 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +51 -1
- data/Rakefile +47 -28
- data/ext/ffi_c/AbstractMemory.c +149 -65
- data/ext/ffi_c/AbstractMemory.h +34 -4
- data/ext/ffi_c/AutoPointer.c +15 -18
- data/ext/ffi_c/AutoPointer.h +2 -2
- data/ext/ffi_c/Buffer.c +79 -44
- data/ext/ffi_c/Callback.c +133 -62
- data/ext/ffi_c/Callback.h +11 -5
- data/ext/ffi_c/{NativeLibrary.c → DynamicLibrary.c} +88 -24
- data/ext/ffi_c/{NativeLibrary.h → DynamicLibrary.h} +1 -1
- data/ext/ffi_c/Invoker.c +154 -190
- data/ext/ffi_c/LastError.c +135 -0
- data/ext/ffi_c/LastError.h +18 -0
- data/ext/ffi_c/MemoryPointer.c +30 -20
- data/ext/ffi_c/MemoryPointer.h +3 -3
- data/ext/ffi_c/NullPointer.c +67 -28
- data/ext/ffi_c/Platform.c +9 -10
- data/ext/ffi_c/Platform.h +1 -1
- data/ext/ffi_c/Pointer.c +67 -30
- data/ext/ffi_c/Pointer.h +8 -6
- data/ext/ffi_c/Struct.c +202 -267
- data/ext/ffi_c/Struct.h +2 -2
- data/ext/ffi_c/Type.c +230 -0
- data/ext/ffi_c/Type.h +28 -0
- data/ext/ffi_c/Types.c +48 -6
- data/ext/ffi_c/Types.h +8 -2
- data/ext/ffi_c/endian.h +40 -0
- data/ext/ffi_c/extconf.rb +6 -5
- data/ext/ffi_c/ffi.c +21 -44
- data/ext/ffi_c/libffi.bsd.mk +34 -0
- data/ext/ffi_c/libffi.darwin.mk +30 -10
- data/ext/ffi_c/libffi.gnu.mk +29 -0
- data/ext/ffi_c/libffi.mk +4 -2
- data/ext/ffi_c/rbffi.h +6 -8
- data/gen/Rakefile +12 -0
- data/lib/ffi/autopointer.rb +1 -1
- data/lib/ffi/enum.rb +78 -0
- data/lib/ffi/ffi.rb +5 -6
- data/lib/ffi/io.rb +15 -1
- data/lib/ffi/library.rb +79 -18
- data/lib/ffi/pointer.rb +2 -2
- data/lib/ffi/struct.rb +68 -14
- data/lib/ffi/types.rb +6 -3
- data/lib/ffi/variadic.rb +2 -2
- data/lib/ffi.rb +10 -1
- data/spec/ffi/bool_spec.rb +24 -0
- data/spec/ffi/callback_spec.rb +217 -17
- data/spec/ffi/enum_spec.rb +164 -0
- data/spec/ffi/managed_struct_spec.rb +6 -1
- data/spec/ffi/number_spec.rb +30 -0
- data/spec/ffi/pointer_spec.rb +33 -8
- data/spec/ffi/rbx/memory_pointer_spec.rb +0 -6
- data/spec/ffi/spec_helper.rb +5 -1
- data/spec/ffi/string_spec.rb +65 -4
- data/spec/ffi/struct_callback_spec.rb +41 -0
- data/spec/ffi/struct_initialize_spec.rb +30 -0
- data/spec/ffi/struct_spec.rb +44 -21
- metadata +31 -69
- data/ext/ffi_c/ffi.mk +0 -23
- data/nbproject/Makefile-Default.mk +0 -57
- data/nbproject/Makefile-impl.mk +0 -123
- data/nbproject/Package-Default.bash +0 -72
- data/nbproject/configurations.xml +0 -293
- data/nbproject/private/configurations.xml +0 -22
- data/nbproject/private/private.xml +0 -7
- data/nbproject/project.properties +0 -0
- data/nbproject/project.xml +0 -15
- data/samples/getlogin.rb +0 -7
- data/samples/getpid.rb +0 -7
- data/samples/gettimeofday.rb +0 -17
- data/samples/hello.rb +0 -6
- data/samples/inotify.rb +0 -59
- data/samples/pty.rb +0 -75
- data/samples/qsort.rb +0 -20
- data/samples/sample_helper.rb +0 -6
|
@@ -12,12 +12,25 @@
|
|
|
12
12
|
|
|
13
13
|
#include "rbffi.h"
|
|
14
14
|
#include "compat.h"
|
|
15
|
+
#include "AbstractMemory.h"
|
|
15
16
|
#include "Pointer.h"
|
|
16
|
-
#include "
|
|
17
|
+
#include "DynamicLibrary.h"
|
|
18
|
+
|
|
19
|
+
typedef struct LibrarySymbol_ {
|
|
20
|
+
AbstractMemory memory;
|
|
21
|
+
VALUE library;
|
|
22
|
+
VALUE name;
|
|
23
|
+
} LibrarySymbol;
|
|
17
24
|
|
|
18
25
|
static VALUE library_initialize(VALUE self, VALUE libname, VALUE libflags);
|
|
19
26
|
static void library_free(Library* lib);
|
|
20
|
-
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
static VALUE symbol_allocate(VALUE klass);
|
|
30
|
+
static VALUE symbol_new(VALUE library, void* address, VALUE name);
|
|
31
|
+
static void symbol_mark(LibrarySymbol* sym);
|
|
32
|
+
|
|
33
|
+
static VALUE LibraryClass = Qnil, SymbolClass = Qnil;
|
|
21
34
|
|
|
22
35
|
#if defined(_WIN32) || defined(__WIN32__)
|
|
23
36
|
static void* dl_open(const char* name, int flags);
|
|
@@ -80,7 +93,8 @@ library_dlsym(VALUE self, VALUE name)
|
|
|
80
93
|
|
|
81
94
|
Data_Get_Struct(self, Library, library);
|
|
82
95
|
address = dl_sym(library->handle, StringValueCStr(name));
|
|
83
|
-
|
|
96
|
+
|
|
97
|
+
return address != NULL ? symbol_new(self, address, name) : Qnil;
|
|
84
98
|
}
|
|
85
99
|
|
|
86
100
|
static VALUE
|
|
@@ -94,16 +108,13 @@ library_dlerror(VALUE self)
|
|
|
94
108
|
static void
|
|
95
109
|
library_free(Library* library)
|
|
96
110
|
{
|
|
97
|
-
|
|
98
|
-
// dlclose() on MacOS tends to segfault - avoid it
|
|
111
|
+
// dlclose() on MacOS tends to segfault - avoid it
|
|
99
112
|
#ifndef __APPLE__
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
#endif
|
|
104
|
-
library->handle = NULL;
|
|
105
|
-
xfree(library);
|
|
113
|
+
if (library->handle != NULL) {
|
|
114
|
+
dl_close(library->handle);
|
|
106
115
|
}
|
|
116
|
+
#endif
|
|
117
|
+
xfree(library);
|
|
107
118
|
}
|
|
108
119
|
|
|
109
120
|
#if defined(_WIN32) || defined(__WIN32__)
|
|
@@ -125,21 +136,74 @@ dl_error(char* buf, int size)
|
|
|
125
136
|
}
|
|
126
137
|
#endif
|
|
127
138
|
|
|
139
|
+
static VALUE
|
|
140
|
+
symbol_allocate(VALUE klass)
|
|
141
|
+
{
|
|
142
|
+
LibrarySymbol* sym;
|
|
143
|
+
VALUE obj = Data_Make_Struct(klass, LibrarySymbol, NULL, -1, sym);
|
|
144
|
+
sym->name = Qnil;
|
|
145
|
+
sym->library = Qnil;
|
|
146
|
+
|
|
147
|
+
return obj;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static VALUE
|
|
151
|
+
symbol_new(VALUE library, void* address, VALUE name)
|
|
152
|
+
{
|
|
153
|
+
LibrarySymbol* sym;
|
|
154
|
+
VALUE obj = Data_Make_Struct(SymbolClass, LibrarySymbol, symbol_mark, -1, sym);
|
|
155
|
+
|
|
156
|
+
sym->memory.address = address;
|
|
157
|
+
sym->memory.size = LONG_MAX;
|
|
158
|
+
sym->library = library;
|
|
159
|
+
sym->name = name;
|
|
160
|
+
|
|
161
|
+
return obj;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
static void
|
|
165
|
+
symbol_mark(LibrarySymbol* sym)
|
|
166
|
+
{
|
|
167
|
+
rb_gc_mark(sym->library);
|
|
168
|
+
rb_gc_mark(sym->name);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
static VALUE
|
|
172
|
+
symbol_inspect(VALUE self)
|
|
173
|
+
{
|
|
174
|
+
LibrarySymbol* sym;
|
|
175
|
+
char buf[256];
|
|
176
|
+
|
|
177
|
+
Data_Get_Struct(self, LibrarySymbol, sym);
|
|
178
|
+
snprintf(buf, sizeof(buf), "#<FFI::Library::Symbol name=%s address=%p>",
|
|
179
|
+
StringValueCStr(sym->name), sym->memory.address);
|
|
180
|
+
return rb_str_new2(buf);
|
|
181
|
+
}
|
|
182
|
+
|
|
128
183
|
void
|
|
129
|
-
|
|
184
|
+
rbffi_DynamicLibrary_Init(VALUE moduleFFI)
|
|
130
185
|
{
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
186
|
+
LibraryClass = rb_define_class_under(moduleFFI, "DynamicLibrary", rb_cObject);
|
|
187
|
+
rb_global_variable(&LibraryClass);
|
|
188
|
+
SymbolClass = rb_define_class_under(LibraryClass, "Symbol", rbffi_PointerClass);
|
|
189
|
+
rb_global_variable(&SymbolClass);
|
|
190
|
+
|
|
191
|
+
rb_define_const(moduleFFI, "NativeLibrary", LibraryClass); // backwards compat library
|
|
192
|
+
rb_define_alloc_func(LibraryClass, library_allocate);
|
|
193
|
+
rb_define_singleton_method(LibraryClass, "open", library_open, 2);
|
|
194
|
+
rb_define_singleton_method(LibraryClass, "last_error", library_dlerror, 0);
|
|
195
|
+
rb_define_method(LibraryClass, "initialize", library_initialize, 2);
|
|
196
|
+
rb_define_method(LibraryClass, "find_symbol", library_dlsym, 1);
|
|
197
|
+
rb_define_method(LibraryClass, "find_function", library_dlsym, 1);
|
|
198
|
+
rb_define_method(LibraryClass, "find_variable", library_dlsym, 1);
|
|
199
|
+
rb_define_method(LibraryClass, "last_error", library_dlerror, 0);
|
|
200
|
+
rb_define_attr(LibraryClass, "name", 1, 0);
|
|
201
|
+
|
|
202
|
+
rb_define_alloc_func(SymbolClass, symbol_allocate);
|
|
203
|
+
rb_undef_method(SymbolClass, "new");
|
|
204
|
+
rb_define_method(SymbolClass, "inspect", symbol_inspect, 0);
|
|
205
|
+
|
|
206
|
+
#define DEF(x) rb_define_const(LibraryClass, "RTLD_" #x, UINT2NUM(RTLD_##x))
|
|
143
207
|
DEF(LAZY);
|
|
144
208
|
DEF(NOW);
|
|
145
209
|
DEF(GLOBAL);
|