ffi 1.12.2 → 1.14.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +82 -0
- data/Gemfile +4 -2
- data/README.md +10 -2
- data/Rakefile +31 -43
- data/ext/ffi_c/AbstractMemory.c +24 -25
- data/ext/ffi_c/Buffer.c +4 -9
- data/ext/ffi_c/Call.c +3 -14
- data/ext/ffi_c/ClosurePool.c +75 -25
- data/ext/ffi_c/ClosurePool.h +3 -1
- data/ext/ffi_c/DynamicLibrary.c +1 -6
- data/ext/ffi_c/Function.c +15 -35
- data/ext/ffi_c/FunctionInfo.c +3 -8
- data/ext/ffi_c/LastError.c +2 -6
- data/ext/ffi_c/LongDouble.c +5 -3
- data/ext/ffi_c/LongDouble.h +0 -4
- data/ext/ffi_c/MemoryPointer.c +3 -8
- data/ext/ffi_c/MethodHandle.c +21 -31
- data/ext/ffi_c/MethodHandle.h +3 -2
- data/ext/ffi_c/Platform.c +3 -7
- data/ext/ffi_c/Pointer.c +25 -26
- data/ext/ffi_c/Struct.c +3 -6
- data/ext/ffi_c/StructByValue.c +2 -7
- data/ext/ffi_c/StructLayout.c +9 -7
- data/ext/ffi_c/Thread.c +0 -8
- data/ext/ffi_c/Thread.h +1 -9
- data/ext/ffi_c/Type.c +1 -1
- data/ext/ffi_c/Variadic.c +2 -7
- data/ext/ffi_c/compat.h +4 -0
- data/ext/ffi_c/extconf.rb +33 -23
- data/ext/ffi_c/libffi/.travis.yml +4 -0
- data/ext/ffi_c/libffi/.travis/bfin-sim.exp +1 -1
- data/ext/ffi_c/libffi/.travis/build.sh +4 -0
- data/ext/ffi_c/libffi/.travis/m32r-sim.exp +1 -1
- data/ext/ffi_c/libffi/.travis/moxie-sim.exp +1 -1
- data/ext/ffi_c/libffi/.travis/or1k-sim.exp +1 -1
- data/ext/ffi_c/libffi/.travis/powerpc-eabisim.exp +1 -1
- data/ext/ffi_c/libffi/.travis/wine-sim.exp +1 -1
- data/ext/ffi_c/libffi/Makefile.am +49 -58
- data/ext/ffi_c/libffi/README.md +11 -1
- data/ext/ffi_c/libffi/config.guess +552 -331
- data/ext/ffi_c/libffi/config.sub +1321 -1306
- data/ext/ffi_c/libffi/configure.ac +31 -10
- data/ext/ffi_c/libffi/configure.host +32 -20
- data/ext/ffi_c/libffi/doc/Makefile.am +3 -0
- data/ext/ffi_c/libffi/doc/libffi.texi +997 -0
- data/ext/ffi_c/libffi/doc/version.texi +4 -0
- data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +1 -1
- data/ext/ffi_c/libffi/include/ffi.h.in +8 -0
- data/ext/ffi_c/libffi/libffi.map.in +8 -12
- data/ext/ffi_c/libffi/libtool-version +1 -1
- data/ext/ffi_c/libffi/msvcc.sh +11 -11
- data/ext/ffi_c/libffi/src/aarch64/ffi.c +51 -35
- data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +10 -5
- data/ext/ffi_c/libffi/src/aarch64/internal.h +1 -0
- data/ext/ffi_c/libffi/src/aarch64/sysv.S +14 -3
- data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +1 -1
- data/ext/ffi_c/libffi/src/arm/ffi.c +22 -0
- data/ext/ffi_c/libffi/src/arm/sysv.S +4 -4
- data/ext/ffi_c/libffi/src/closures.c +33 -10
- data/ext/ffi_c/libffi/src/csky/ffi.c +395 -0
- data/ext/ffi_c/libffi/src/csky/ffitarget.h +63 -0
- data/ext/ffi_c/libffi/src/csky/sysv.S +371 -0
- data/ext/ffi_c/libffi/src/dlmalloc.c +1 -1
- data/ext/ffi_c/libffi/src/kvx/asm.h +5 -0
- data/ext/ffi_c/libffi/src/kvx/ffi.c +273 -0
- data/ext/ffi_c/libffi/src/kvx/ffitarget.h +75 -0
- data/ext/ffi_c/libffi/src/kvx/sysv.S +127 -0
- data/ext/ffi_c/libffi/src/mips/ffi.c +5 -1
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +1 -1
- data/ext/ffi_c/libffi/src/pa/ffi.c +46 -91
- data/ext/ffi_c/libffi/src/pa/ffitarget.h +1 -6
- data/ext/ffi_c/libffi/src/pa/hpux32.S +4 -2
- data/ext/ffi_c/libffi/src/pa/linux.S +4 -2
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +13 -1
- data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +1 -1
- data/ext/ffi_c/libffi/src/powerpc/linux64.S +8 -0
- data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +13 -1
- data/ext/ffi_c/libffi/src/powerpc/sysv.S +5 -7
- data/ext/ffi_c/libffi/src/prep_cif.c +1 -1
- data/ext/ffi_c/libffi/src/x86/ffi.c +15 -6
- data/ext/ffi_c/libffi/src/x86/ffi64.c +17 -8
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -2
- data/ext/ffi_c/libffi/src/x86/ffiw64.c +15 -8
- data/ext/ffi_c/libffi/src/x86/sysv.S +15 -6
- data/ext/ffi_c/libffi/src/x86/unix64.S +59 -4
- data/ext/ffi_c/libffi/src/x86/win64.S +7 -3
- data/ext/ffi_c/libffi/src/x86/win64_intel.S +3 -2
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +22 -2
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.closures/huge_struct.c +2 -0
- data/ffi.gemspec +2 -2
- data/lib/ffi.rb +10 -2
- data/lib/ffi/abstract_memory.rb +44 -0
- data/lib/ffi/autopointer.rb +1 -1
- data/lib/ffi/ffi.rb +1 -0
- data/lib/ffi/io.rb +3 -3
- data/lib/ffi/library.rb +6 -2
- data/lib/ffi/managedstruct.rb +2 -2
- data/lib/ffi/platform.rb +21 -8
- data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
- data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
- data/lib/ffi/platform/arm-linux/types.conf +32 -4
- data/lib/ffi/platform/i386-windows/types.conf +26 -79
- data/lib/ffi/platform/powerpc-linux/types.conf +32 -2
- data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
- data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
- data/lib/ffi/platform/x86_64-darwin/types.conf +4 -0
- data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +4 -22
- data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
- data/lib/ffi/platform/x86_64-linux/types.conf +21 -0
- data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
- data/lib/ffi/platform/x86_64-windows/types.conf +10 -78
- data/lib/ffi/pointer.rb +21 -14
- data/lib/ffi/struct.rb +8 -2
- data/lib/ffi/tools/types_generator.rb +2 -0
- data/lib/ffi/variadic.rb +1 -1
- data/lib/ffi/version.rb +1 -1
- data/samples/getlogin.rb +1 -1
- data/samples/getpid.rb +1 -1
- data/samples/gettimeofday.rb +8 -8
- data/samples/hello.rb +2 -1
- data/samples/inotify.rb +1 -1
- data/samples/pty.rb +1 -2
- data/samples/qsort.rb +0 -1
- metadata +18 -12
- data/.appveyor.yml +0 -27
- data/.gitignore +0 -25
- data/.gitmodules +0 -4
- data/.travis.yml +0 -44
- data/.yardopts +0 -5
- data/ext/ffi_c/win32/stdbool.h +0 -8
- data/ext/ffi_c/win32/stdint.h +0 -201
- data/samples/sample_helper.rb +0 -6
data/ext/ffi_c/LastError.c
CHANGED
|
@@ -33,12 +33,8 @@
|
|
|
33
33
|
#endif
|
|
34
34
|
#include <sys/types.h>
|
|
35
35
|
#include <stdio.h>
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
# include <stdbool.h>
|
|
39
|
-
#else
|
|
40
|
-
# include "win32/stdbool.h"
|
|
41
|
-
#endif
|
|
36
|
+
#include <stdint.h>
|
|
37
|
+
#include <stdbool.h>
|
|
42
38
|
#include <errno.h>
|
|
43
39
|
#include <ruby.h>
|
|
44
40
|
|
data/ext/ffi_c/LongDouble.c
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
#include <stdarg.h>
|
|
4
4
|
#include <float.h>
|
|
5
5
|
|
|
6
|
-
#if defined (__CYGWIN__) || defined(__INTERIX)
|
|
6
|
+
#if defined (__CYGWIN__) || defined(__INTERIX) || defined(_MSC_VER)
|
|
7
7
|
# define strtold(str, endptr) ((long double) strtod((str), (endptr)))
|
|
8
8
|
#endif /* defined (__CYGWIN__) */
|
|
9
9
|
|
|
@@ -21,7 +21,7 @@ rbffi_longdouble_new(long double ld)
|
|
|
21
21
|
|
|
22
22
|
if (RTEST(rb_cBigDecimal) && rb_cBigDecimal != rb_cObject) {
|
|
23
23
|
char buf[128];
|
|
24
|
-
return rb_funcall(
|
|
24
|
+
return rb_funcall(rb_mKernel, rb_intern("BigDecimal"), 1, rb_str_new(buf, sprintf(buf, "%.35Le", ld)));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/* Fall through to handling as a float */
|
|
@@ -41,7 +41,9 @@ rbffi_num2longdouble(VALUE value)
|
|
|
41
41
|
|
|
42
42
|
if (RTEST(rb_cBigDecimal) && rb_cBigDecimal != rb_cObject && RTEST(rb_obj_is_kind_of(value, rb_cBigDecimal))) {
|
|
43
43
|
VALUE s = rb_funcall(value, rb_intern("to_s"), 1, rb_str_new2("E"));
|
|
44
|
-
|
|
44
|
+
long double ret = strtold(RSTRING_PTR(s), NULL);
|
|
45
|
+
RB_GC_GUARD(s);
|
|
46
|
+
return ret;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/* Fall through to handling as a float */
|
data/ext/ffi_c/LongDouble.h
CHANGED
data/ext/ffi_c/MemoryPointer.c
CHANGED
|
@@ -28,13 +28,8 @@
|
|
|
28
28
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
# include <stdint.h>
|
|
34
|
-
#else
|
|
35
|
-
# include "win32/stdbool.h"
|
|
36
|
-
# include "win32/stdint.h"
|
|
37
|
-
#endif
|
|
31
|
+
#include <stdbool.h>
|
|
32
|
+
#include <stdint.h>
|
|
38
33
|
#include <limits.h>
|
|
39
34
|
#include <ruby.h>
|
|
40
35
|
#include "rbffi.h"
|
|
@@ -112,7 +107,7 @@ memptr_malloc(VALUE self, long size, long count, bool clear)
|
|
|
112
107
|
p->memory.typeSize = (int) size;
|
|
113
108
|
p->memory.size = msize;
|
|
114
109
|
/* ensure the memory is aligned on at least a 8 byte boundary */
|
|
115
|
-
p->memory.address = (char *) (((uintptr_t) p->storage + 0x7) & (uintptr_t) ~
|
|
110
|
+
p->memory.address = (char *) (((uintptr_t) p->storage + 0x7) & (uintptr_t) ~0x7ULL);
|
|
116
111
|
p->allocated = true;
|
|
117
112
|
|
|
118
113
|
if (clear && p->memory.size > 0) {
|
data/ext/ffi_c/MethodHandle.c
CHANGED
|
@@ -34,13 +34,8 @@
|
|
|
34
34
|
# include <sys/mman.h>
|
|
35
35
|
#endif
|
|
36
36
|
#include <stdio.h>
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
# include <stdbool.h>
|
|
40
|
-
#else
|
|
41
|
-
# include "win32/stdint.h"
|
|
42
|
-
# include "win32/stdbool.h"
|
|
43
|
-
#endif
|
|
37
|
+
#include <stdint.h>
|
|
38
|
+
#include <stdbool.h>
|
|
44
39
|
#ifndef _WIN32
|
|
45
40
|
# include <unistd.h>
|
|
46
41
|
#endif
|
|
@@ -68,9 +63,6 @@
|
|
|
68
63
|
#ifndef roundup
|
|
69
64
|
# define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
|
|
70
65
|
#endif
|
|
71
|
-
#ifdef _WIN32
|
|
72
|
-
typedef char* caddr_t;
|
|
73
|
-
#endif
|
|
74
66
|
|
|
75
67
|
#ifdef USE_RAW
|
|
76
68
|
# define METHOD_CLOSURE ffi_raw_closure
|
|
@@ -120,23 +112,19 @@ rbffi_MethodHandle_Free(MethodHandle* handle)
|
|
|
120
112
|
{
|
|
121
113
|
if (handle != NULL) {
|
|
122
114
|
rbffi_Closure_Free(handle->closure);
|
|
115
|
+
xfree(handle);
|
|
123
116
|
}
|
|
124
117
|
}
|
|
125
118
|
|
|
126
|
-
|
|
127
|
-
rbffi_MethodHandle_CodeAddress(MethodHandle* handle)
|
|
119
|
+
rbffi_function_anyargs rbffi_MethodHandle_CodeAddress(MethodHandle* handle)
|
|
128
120
|
{
|
|
129
|
-
return handle->closure->code;
|
|
121
|
+
return (rbffi_function_anyargs) handle->closure->code;
|
|
130
122
|
}
|
|
131
123
|
|
|
132
124
|
#ifndef CUSTOM_TRAMPOLINE
|
|
133
125
|
static void attached_method_invoke(ffi_cif* cif, void* retval, METHOD_PARAMS parameters, void* user_data);
|
|
134
126
|
|
|
135
|
-
static ffi_type* methodHandleParamTypes[]
|
|
136
|
-
&ffi_type_sint,
|
|
137
|
-
&ffi_type_pointer,
|
|
138
|
-
&ffi_type_ulong,
|
|
139
|
-
};
|
|
127
|
+
static ffi_type* methodHandleParamTypes[3];
|
|
140
128
|
|
|
141
129
|
static ffi_cif mh_cif;
|
|
142
130
|
|
|
@@ -148,10 +136,10 @@ prep_trampoline(void* ctx, void* code, Closure* closure, char* errmsg, size_t er
|
|
|
148
136
|
#if defined(USE_RAW)
|
|
149
137
|
ffiStatus = ffi_prep_raw_closure(code, &mh_cif, attached_method_invoke, closure);
|
|
150
138
|
#else
|
|
151
|
-
ffiStatus =
|
|
139
|
+
ffiStatus = ffi_prep_closure_loc(closure->pcl, &mh_cif, attached_method_invoke, closure, code);
|
|
152
140
|
#endif
|
|
153
141
|
if (ffiStatus != FFI_OK) {
|
|
154
|
-
snprintf(errmsg, errmsgsize, "
|
|
142
|
+
snprintf(errmsg, errmsgsize, "ffi_prep_closure_loc failed. status=%#x", ffiStatus);
|
|
155
143
|
return false;
|
|
156
144
|
}
|
|
157
145
|
|
|
@@ -237,7 +225,7 @@ custom_trampoline(int argc, VALUE* argv, VALUE self, Closure* handle)
|
|
|
237
225
|
|
|
238
226
|
#elif defined(__i386__) && 0
|
|
239
227
|
|
|
240
|
-
static VALUE custom_trampoline(
|
|
228
|
+
static VALUE custom_trampoline(void *args, Closure*);
|
|
241
229
|
#define TRAMPOLINE_CTX_MAGIC (0xfee1dead)
|
|
242
230
|
#define TRAMPOLINE_FUN_MAGIC (0xbeefcafe)
|
|
243
231
|
|
|
@@ -269,7 +257,7 @@ __asm__(
|
|
|
269
257
|
);
|
|
270
258
|
|
|
271
259
|
static VALUE
|
|
272
|
-
custom_trampoline(
|
|
260
|
+
custom_trampoline(void *args, Closure* handle)
|
|
273
261
|
{
|
|
274
262
|
FunctionType* fnInfo = (FunctionType *) handle->info;
|
|
275
263
|
return (*fnInfo->invoke)(*(int *) args, *(VALUE **) (args + 4), handle->function, fnInfo);
|
|
@@ -286,10 +274,10 @@ static long trampoline_ctx_offset, trampoline_func_offset;
|
|
|
286
274
|
static long
|
|
287
275
|
trampoline_offset(int off, const long value)
|
|
288
276
|
{
|
|
289
|
-
|
|
290
|
-
for (ptr = (
|
|
277
|
+
char *ptr;
|
|
278
|
+
for (ptr = (char *) &ffi_trampoline + off; ptr < (char *) &ffi_trampoline_end; ++ptr) {
|
|
291
279
|
if (*(long *) ptr == value) {
|
|
292
|
-
return ptr - (
|
|
280
|
+
return ptr - (char *) &ffi_trampoline;
|
|
293
281
|
}
|
|
294
282
|
}
|
|
295
283
|
|
|
@@ -315,12 +303,10 @@ trampoline_offsets(long* ctxOffset, long* fnOffset)
|
|
|
315
303
|
static bool
|
|
316
304
|
prep_trampoline(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize)
|
|
317
305
|
{
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
memcpy(ptr, &ffi_trampoline, trampoline_size());
|
|
306
|
+
memcpy(code, (void*) &ffi_trampoline, trampoline_size());
|
|
321
307
|
/* Patch the context and function addresses into the stub code */
|
|
322
|
-
*(intptr_t *)(
|
|
323
|
-
*(intptr_t *)(
|
|
308
|
+
*(intptr_t *)((char*)code + trampoline_ctx_offset) = (intptr_t) closure;
|
|
309
|
+
*(intptr_t *)((char*)code + trampoline_func_offset) = (intptr_t) custom_trampoline;
|
|
324
310
|
|
|
325
311
|
return true;
|
|
326
312
|
}
|
|
@@ -328,7 +314,7 @@ prep_trampoline(void* ctx, void* code, Closure* closure, char* errmsg, size_t er
|
|
|
328
314
|
static long
|
|
329
315
|
trampoline_size(void)
|
|
330
316
|
{
|
|
331
|
-
return (
|
|
317
|
+
return (char *) &ffi_trampoline_end - (char *) &ffi_trampoline;
|
|
332
318
|
}
|
|
333
319
|
|
|
334
320
|
#endif /* CUSTOM_TRAMPOLINE */
|
|
@@ -348,6 +334,10 @@ rbffi_MethodHandle_Init(VALUE module)
|
|
|
348
334
|
rb_raise(rb_eFatal, "Could not locate offsets in trampoline code");
|
|
349
335
|
}
|
|
350
336
|
#else
|
|
337
|
+
methodHandleParamTypes[0] = &ffi_type_sint;
|
|
338
|
+
methodHandleParamTypes[1] = &ffi_type_pointer;
|
|
339
|
+
methodHandleParamTypes[2] = &ffi_type_ulong;
|
|
340
|
+
|
|
351
341
|
ffiStatus = ffi_prep_cif(&mh_cif, FFI_DEFAULT_ABI, 3, &ffi_type_ulong,
|
|
352
342
|
methodHandleParamTypes);
|
|
353
343
|
if (ffiStatus != FFI_OK) {
|
data/ext/ffi_c/MethodHandle.h
CHANGED
|
@@ -37,14 +37,15 @@ extern "C" {
|
|
|
37
37
|
#include <ruby.h>
|
|
38
38
|
#include "Function.h"
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
typedef struct MethodHandlePool MethodHandlePool;
|
|
42
42
|
typedef struct MethodHandle MethodHandle;
|
|
43
|
+
typedef VALUE (*rbffi_function_anyargs)(int argc, VALUE* argv, VALUE self);
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
MethodHandle* rbffi_MethodHandle_Alloc(FunctionType* fnInfo, void* function);
|
|
46
47
|
void rbffi_MethodHandle_Free(MethodHandle* handle);
|
|
47
|
-
|
|
48
|
+
rbffi_function_anyargs rbffi_MethodHandle_CodeAddress(MethodHandle* handle);
|
|
48
49
|
void rbffi_MethodHandle_Init(VALUE module);
|
|
49
50
|
|
|
50
51
|
#ifdef __cplusplus
|
data/ext/ffi_c/Platform.c
CHANGED
|
@@ -31,13 +31,8 @@
|
|
|
31
31
|
# include <sys/param.h>
|
|
32
32
|
#endif
|
|
33
33
|
# include <sys/types.h>
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
# include <stdbool.h>
|
|
37
|
-
#else
|
|
38
|
-
# include "win32/stdint.h"
|
|
39
|
-
# include "win32/stdbool.h"
|
|
40
|
-
#endif
|
|
34
|
+
#include <stdint.h>
|
|
35
|
+
#include <stdbool.h>
|
|
41
36
|
#include <ruby.h>
|
|
42
37
|
#include <ctype.h>
|
|
43
38
|
#include "rbffi_endian.h"
|
|
@@ -64,6 +59,7 @@ export_primitive_types(VALUE module)
|
|
|
64
59
|
S(LONG, long);
|
|
65
60
|
S(FLOAT, float);
|
|
66
61
|
S(DOUBLE, double);
|
|
62
|
+
S(LONG_DOUBLE, long double);
|
|
67
63
|
S(ADDRESS, void*);
|
|
68
64
|
#undef S
|
|
69
65
|
}
|
data/ext/ffi_c/Pointer.c
CHANGED
|
@@ -27,13 +27,8 @@
|
|
|
27
27
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
# include <stdbool.h>
|
|
33
|
-
#else
|
|
34
|
-
# include "win32/stdint.h"
|
|
35
|
-
# include "win32/stdbool.h"
|
|
36
|
-
#endif
|
|
30
|
+
#include <stdint.h>
|
|
31
|
+
#include <stdbool.h>
|
|
37
32
|
#include <limits.h>
|
|
38
33
|
#include <ruby.h>
|
|
39
34
|
#include "rbffi.h"
|
|
@@ -157,14 +152,14 @@ ptr_initialize_copy(VALUE self, VALUE other)
|
|
|
157
152
|
{
|
|
158
153
|
AbstractMemory* src;
|
|
159
154
|
Pointer* dst;
|
|
160
|
-
|
|
155
|
+
|
|
161
156
|
Data_Get_Struct(self, Pointer, dst);
|
|
162
157
|
src = POINTER(other);
|
|
163
158
|
if (src->size == LONG_MAX) {
|
|
164
159
|
rb_raise(rb_eRuntimeError, "cannot duplicate unbounded memory area");
|
|
165
160
|
return Qnil;
|
|
166
161
|
}
|
|
167
|
-
|
|
162
|
+
|
|
168
163
|
if ((dst->memory.flags & (MEM_RD | MEM_WR)) != (MEM_RD | MEM_WR)) {
|
|
169
164
|
rb_raise(rb_eRuntimeError, "cannot duplicate unreadable/unwritable memory area");
|
|
170
165
|
return Qnil;
|
|
@@ -180,13 +175,13 @@ ptr_initialize_copy(VALUE self, VALUE other)
|
|
|
180
175
|
rb_raise(rb_eNoMemError, "failed to allocate memory size=%lu bytes", src->size);
|
|
181
176
|
return Qnil;
|
|
182
177
|
}
|
|
183
|
-
|
|
178
|
+
|
|
184
179
|
dst->allocated = true;
|
|
185
180
|
dst->autorelease = true;
|
|
186
|
-
dst->memory.address = (void *) (((uintptr_t) dst->storage + 0x7) & (uintptr_t) ~
|
|
181
|
+
dst->memory.address = (void *) (((uintptr_t) dst->storage + 0x7) & (uintptr_t) ~0x7ULL);
|
|
187
182
|
dst->memory.size = src->size;
|
|
188
183
|
dst->memory.typeSize = src->typeSize;
|
|
189
|
-
|
|
184
|
+
|
|
190
185
|
/* finally, copy the actual memory contents */
|
|
191
186
|
memcpy(dst->memory.address, src->address, src->size);
|
|
192
187
|
|
|
@@ -199,7 +194,7 @@ slice(VALUE self, long offset, long size)
|
|
|
199
194
|
AbstractMemory* ptr;
|
|
200
195
|
Pointer* p;
|
|
201
196
|
VALUE retval;
|
|
202
|
-
|
|
197
|
+
|
|
203
198
|
Data_Get_Struct(self, AbstractMemory, ptr);
|
|
204
199
|
checkBounds(ptr, offset, size == LONG_MAX ? 1 : size);
|
|
205
200
|
|
|
@@ -214,7 +209,7 @@ slice(VALUE self, long offset, long size)
|
|
|
214
209
|
return retval;
|
|
215
210
|
}
|
|
216
211
|
|
|
217
|
-
/*
|
|
212
|
+
/*
|
|
218
213
|
* Document-method: +
|
|
219
214
|
* call-seq: ptr + offset
|
|
220
215
|
* @param [Numeric] offset
|
|
@@ -237,7 +232,7 @@ ptr_plus(VALUE self, VALUE offset)
|
|
|
237
232
|
* @param [Numeric] offset
|
|
238
233
|
* @param [Numeric] length
|
|
239
234
|
* @return [Pointer]
|
|
240
|
-
* Return a new {Pointer} from an existing one. This pointer points on same contents
|
|
235
|
+
* Return a new {Pointer} from an existing one. This pointer points on same contents
|
|
241
236
|
* from +offset+ for a length +length+.
|
|
242
237
|
*/
|
|
243
238
|
static VALUE
|
|
@@ -256,7 +251,7 @@ ptr_inspect(VALUE self)
|
|
|
256
251
|
{
|
|
257
252
|
char buf[100];
|
|
258
253
|
Pointer* ptr;
|
|
259
|
-
|
|
254
|
+
|
|
260
255
|
Data_Get_Struct(self, Pointer, ptr);
|
|
261
256
|
|
|
262
257
|
if (ptr->memory.size != LONG_MAX) {
|
|
@@ -295,7 +290,7 @@ static VALUE
|
|
|
295
290
|
ptr_equals(VALUE self, VALUE other)
|
|
296
291
|
{
|
|
297
292
|
Pointer* ptr;
|
|
298
|
-
|
|
293
|
+
|
|
299
294
|
Data_Get_Struct(self, Pointer, ptr);
|
|
300
295
|
|
|
301
296
|
if (NIL_P(other)) {
|
|
@@ -314,7 +309,7 @@ static VALUE
|
|
|
314
309
|
ptr_address(VALUE self)
|
|
315
310
|
{
|
|
316
311
|
Pointer* ptr;
|
|
317
|
-
|
|
312
|
+
|
|
318
313
|
Data_Get_Struct(self, Pointer, ptr);
|
|
319
314
|
|
|
320
315
|
return ULL2NUM((uintptr_t) ptr->memory.address);
|
|
@@ -331,9 +326,9 @@ ptr_address(VALUE self)
|
|
|
331
326
|
* @overload order
|
|
332
327
|
* @return [:big, :little] endianness of +self+
|
|
333
328
|
* @overload order(order)
|
|
334
|
-
* @param [Symbol] order endianness to set (+:little+, +:big+ or +:network+). +:big+ and +:network+
|
|
329
|
+
* @param [Symbol] order endianness to set (+:little+, +:big+ or +:network+). +:big+ and +:network+
|
|
335
330
|
* are synonymous.
|
|
336
|
-
* @return
|
|
331
|
+
* @return a new pointer with the new order
|
|
337
332
|
*/
|
|
338
333
|
static VALUE
|
|
339
334
|
ptr_order(int argc, VALUE* argv, VALUE self)
|
|
@@ -358,6 +353,8 @@ ptr_order(int argc, VALUE* argv, VALUE self)
|
|
|
358
353
|
|
|
359
354
|
} else if (id == rb_intern("big") || id == rb_intern("network")) {
|
|
360
355
|
order = BIG_ENDIAN;
|
|
356
|
+
} else {
|
|
357
|
+
rb_raise(rb_eArgError, "unknown byte order");
|
|
361
358
|
}
|
|
362
359
|
}
|
|
363
360
|
if (order != BYTE_ORDER) {
|
|
@@ -395,7 +392,7 @@ ptr_free(VALUE self)
|
|
|
395
392
|
|
|
396
393
|
} else {
|
|
397
394
|
VALUE caller = rb_funcall(rb_funcall(Qnil, rb_intern("caller"), 0), rb_intern("first"), 0);
|
|
398
|
-
|
|
395
|
+
|
|
399
396
|
rb_warn("calling free on non allocated pointer %s from %s", RSTRING_PTR(ptr_inspect(self)), RSTRING_PTR(rb_str_to_str(caller)));
|
|
400
397
|
}
|
|
401
398
|
|
|
@@ -408,7 +405,7 @@ ptr_type_size(VALUE self)
|
|
|
408
405
|
Pointer* ptr;
|
|
409
406
|
|
|
410
407
|
Data_Get_Struct(self, Pointer, ptr);
|
|
411
|
-
|
|
408
|
+
|
|
412
409
|
return INT2NUM(ptr->memory.typeSize);
|
|
413
410
|
}
|
|
414
411
|
|
|
@@ -440,7 +437,7 @@ ptr_autorelease_p(VALUE self)
|
|
|
440
437
|
Pointer* ptr;
|
|
441
438
|
|
|
442
439
|
Data_Get_Struct(self, Pointer, ptr);
|
|
443
|
-
|
|
440
|
+
|
|
444
441
|
return ptr->autorelease ? Qtrue : Qfalse;
|
|
445
442
|
}
|
|
446
443
|
|
|
@@ -472,9 +469,11 @@ rbffi_Pointer_Init(VALUE moduleFFI)
|
|
|
472
469
|
* Pointer class is used to manage C pointers with ease. A {Pointer} object is defined by his
|
|
473
470
|
* {#address} (as a C pointer). It permits additions with an integer for pointer arithmetic.
|
|
474
471
|
*
|
|
475
|
-
* ==Autorelease
|
|
476
|
-
*
|
|
477
|
-
*
|
|
472
|
+
* == Autorelease
|
|
473
|
+
* By default a pointer object frees its content when it's garbage collected.
|
|
474
|
+
* Therefore it's usually not necessary to call {#free} explicit.
|
|
475
|
+
* This behaviour may be changed with {#autorelease=} method.
|
|
476
|
+
* If it's set to +false+, the memory isn't freed by the garbage collector, but stays valid until +free()+ is called on C level or when the process terminates.
|
|
478
477
|
*/
|
|
479
478
|
rbffi_PointerClass = rb_define_class_under(moduleFFI, "Pointer", ffi_AbstractMemory);
|
|
480
479
|
/*
|
data/ext/ffi_c/Struct.c
CHANGED
|
@@ -31,12 +31,9 @@
|
|
|
31
31
|
#include <sys/types.h>
|
|
32
32
|
#ifndef _MSC_VER
|
|
33
33
|
# include <sys/param.h>
|
|
34
|
-
# include <stdint.h>
|
|
35
|
-
# include <stdbool.h>
|
|
36
|
-
#else
|
|
37
|
-
# include "win32/stdbool.h"
|
|
38
|
-
# include "win32/stdint.h"
|
|
39
34
|
#endif
|
|
35
|
+
#include <stdint.h>
|
|
36
|
+
#include <stdbool.h>
|
|
40
37
|
#include <ruby.h>
|
|
41
38
|
#include "rbffi.h"
|
|
42
39
|
#include "compat.h"
|
|
@@ -290,7 +287,7 @@ struct_field(Struct* s, VALUE fieldName)
|
|
|
290
287
|
VALUE rbField = rb_hash_aref(layout->rbFieldMap, fieldName);
|
|
291
288
|
if (unlikely(NIL_P(rbField))) {
|
|
292
289
|
VALUE str = rb_funcall2(fieldName, id_to_s, 0, NULL);
|
|
293
|
-
rb_raise(rb_eArgError, "No such field '%s'",
|
|
290
|
+
rb_raise(rb_eArgError, "No such field '%s'", StringValueCStr(str));
|
|
294
291
|
}
|
|
295
292
|
/* Write the retrieved coder to the cache */
|
|
296
293
|
p_ce->fieldName = fieldName;
|
data/ext/ffi_c/StructByValue.c
CHANGED
|
@@ -32,13 +32,8 @@
|
|
|
32
32
|
#endif
|
|
33
33
|
#include <sys/types.h>
|
|
34
34
|
#include <stdio.h>
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
# include <stdbool.h>
|
|
38
|
-
#else
|
|
39
|
-
# include "win32/stdbool.h"
|
|
40
|
-
# include "win32/stdint.h"
|
|
41
|
-
#endif
|
|
35
|
+
#include <stdint.h>
|
|
36
|
+
#include <stdbool.h>
|
|
42
37
|
#include <errno.h>
|
|
43
38
|
#include <ruby.h>
|
|
44
39
|
|