ffi 1.10.0 → 1.11.1
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/.gitignore +3 -0
- data/.gitmodules +2 -1
- data/.travis.yml +17 -18
- data/CHANGELOG.md +33 -0
- data/Gemfile +1 -1
- data/README.md +20 -17
- data/Rakefile +10 -83
- data/appveyor.yml +6 -1
- data/ext/ffi_c/Call.c +16 -33
- data/ext/ffi_c/Call.h +2 -5
- data/ext/ffi_c/Function.c +24 -108
- data/ext/ffi_c/Platform.c +0 -47
- data/ext/ffi_c/Thread.c +6 -222
- data/ext/ffi_c/Thread.h +2 -13
- data/ext/ffi_c/Type.c +0 -18
- data/ext/ffi_c/Type.h +0 -1
- data/ext/ffi_c/Variadic.c +9 -15
- data/ext/ffi_c/extconf.rb +34 -20
- data/ext/ffi_c/ffi.c +3 -8
- data/ext/ffi_c/libffi/configure.ac +5 -1
- data/ext/ffi_c/libffi/include/ffi_common.h +1 -1
- data/ext/ffi_c/libffi/src/aarch64/ffi.c +2 -2
- data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/metag/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/moxie/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/riscv/ffi.c +42 -6
- data/ext/ffi_c/libffi/src/riscv/ffitarget.h +1 -0
- data/ext/ffi_c/libffi/src/riscv/sysv.S +86 -7
- data/ext/ffi_c/libffi/src/x86/ffi.c +2 -1
- data/ext/ffi_c/libffi/src/x86/ffiw64.c +1 -1
- data/ext/ffi_c/libffi/src/x86/sysv.S +88 -2
- data/ext/ffi_c/libffi/src/x86/unix64.S +41 -0
- data/ext/ffi_c/rbffi.h +0 -2
- data/ffi.gemspec +11 -4
- data/lib/ffi/data_converter.rb +67 -0
- data/lib/ffi/ffi.rb +1 -0
- data/lib/ffi/platform.rb +2 -0
- data/lib/ffi/pointer.rb +1 -1
- data/lib/ffi/struct.rb +3 -63
- data/lib/ffi/struct_by_reference.rb +72 -0
- data/lib/ffi/struct_layout.rb +96 -0
- data/lib/ffi/tools/const_generator.rb +5 -4
- data/lib/ffi/tools/generator.rb +47 -2
- data/lib/ffi/tools/generator_task.rb +13 -17
- data/lib/ffi/tools/struct_generator.rb +4 -4
- data/lib/ffi/types.rb +1 -1
- data/lib/ffi/version.rb +1 -1
- metadata +18 -13
- data/ext/ffi_c/DataConverter.c +0 -91
- data/ext/ffi_c/StructByReference.c +0 -190
- data/ext/ffi_c/StructByReference.h +0 -50
@@ -1,190 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (c) 2010, Wayne Meissner
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
7
|
-
*
|
8
|
-
* * Redistributions of source code must retain the above copyright notice, this
|
9
|
-
* list of conditions and the following disclaimer.
|
10
|
-
* * Redistributions in binary form must reproduce the above copyright notice
|
11
|
-
* this list of conditions and the following disclaimer in the documentation
|
12
|
-
* and/or other materials provided with the distribution.
|
13
|
-
* * The name of the author or authors may not be used to endorse or promote
|
14
|
-
* products derived from this software without specific prior written permission.
|
15
|
-
*
|
16
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
20
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
-
*/
|
27
|
-
|
28
|
-
#ifndef _MSC_VER
|
29
|
-
# include <sys/param.h>
|
30
|
-
#endif
|
31
|
-
#include <sys/types.h>
|
32
|
-
#include <stdio.h>
|
33
|
-
#ifndef _MSC_VER
|
34
|
-
# include <stdint.h>
|
35
|
-
# include <stdbool.h>
|
36
|
-
#else
|
37
|
-
# include "win32/stdbool.h"
|
38
|
-
# include "win32/stdint.h"
|
39
|
-
#endif
|
40
|
-
#include <errno.h>
|
41
|
-
#include <ruby.h>
|
42
|
-
|
43
|
-
#include <ffi.h>
|
44
|
-
#include "rbffi.h"
|
45
|
-
#include "compat.h"
|
46
|
-
|
47
|
-
#include "Pointer.h"
|
48
|
-
#include "Struct.h"
|
49
|
-
#include "StructByReference.h"
|
50
|
-
|
51
|
-
|
52
|
-
#define FFI_ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1)
|
53
|
-
|
54
|
-
static VALUE sbr_allocate(VALUE);
|
55
|
-
static VALUE sbr_initialize(VALUE, VALUE);
|
56
|
-
static void sbr_mark(StructByReference *);
|
57
|
-
|
58
|
-
VALUE rbffi_StructByReferenceClass = Qnil;
|
59
|
-
|
60
|
-
static VALUE
|
61
|
-
sbr_allocate(VALUE klass)
|
62
|
-
{
|
63
|
-
StructByReference* sbr;
|
64
|
-
|
65
|
-
VALUE obj = Data_Make_Struct(klass, StructByReference, sbr_mark, -1, sbr);
|
66
|
-
|
67
|
-
sbr->rbStructClass = Qnil;
|
68
|
-
|
69
|
-
return obj;
|
70
|
-
}
|
71
|
-
|
72
|
-
/*
|
73
|
-
* call-seq: initialize(struc_class)
|
74
|
-
* @param [Struct] struct_calss
|
75
|
-
* @return [self]
|
76
|
-
* A new instance of StructByReference.
|
77
|
-
*/
|
78
|
-
static VALUE
|
79
|
-
sbr_initialize(VALUE self, VALUE rbStructClass)
|
80
|
-
{
|
81
|
-
StructByReference* sbr = NULL;
|
82
|
-
|
83
|
-
if (!rb_class_inherited_p(rbStructClass, rbffi_StructClass)) {
|
84
|
-
rb_raise(rb_eTypeError, "wrong type (expected subclass of FFI::Struct)");
|
85
|
-
}
|
86
|
-
|
87
|
-
Data_Get_Struct(self, StructByReference, sbr);
|
88
|
-
sbr->rbStructClass = rbStructClass;
|
89
|
-
|
90
|
-
return self;
|
91
|
-
}
|
92
|
-
|
93
|
-
static void
|
94
|
-
sbr_mark(StructByReference *sbr)
|
95
|
-
{
|
96
|
-
rb_gc_mark(sbr->rbStructClass);
|
97
|
-
}
|
98
|
-
|
99
|
-
|
100
|
-
/*
|
101
|
-
* call-seq: struct_class
|
102
|
-
* @return [Struct]
|
103
|
-
* Get +struct_class+.
|
104
|
-
*/
|
105
|
-
static VALUE
|
106
|
-
sbr_struct_class(VALUE self)
|
107
|
-
{
|
108
|
-
StructByReference* sbr;
|
109
|
-
|
110
|
-
Data_Get_Struct(self, StructByReference, sbr);
|
111
|
-
|
112
|
-
return sbr->rbStructClass;
|
113
|
-
}
|
114
|
-
|
115
|
-
/*
|
116
|
-
* call-seq: native_type
|
117
|
-
* @return [Class]
|
118
|
-
* Always get {FFI::Type}::POINTER.
|
119
|
-
*/
|
120
|
-
static VALUE
|
121
|
-
sbr_native_type(VALUE self)
|
122
|
-
{
|
123
|
-
return rb_const_get(rbffi_TypeClass, rb_intern("POINTER"));
|
124
|
-
}
|
125
|
-
|
126
|
-
/*
|
127
|
-
* call-seq: to_native(value, ctx)
|
128
|
-
* @param [nil, Struct] value
|
129
|
-
* @param [nil] ctx
|
130
|
-
* @return [AbstractMemory] Pointer on +value+.
|
131
|
-
*/
|
132
|
-
static VALUE
|
133
|
-
sbr_to_native(VALUE self, VALUE value, VALUE ctx)
|
134
|
-
{
|
135
|
-
StructByReference* sbr;
|
136
|
-
Struct* s;
|
137
|
-
|
138
|
-
if (unlikely(value == Qnil)) {
|
139
|
-
return rbffi_NullPointerSingleton;
|
140
|
-
}
|
141
|
-
|
142
|
-
Data_Get_Struct(self, StructByReference, sbr);
|
143
|
-
if (!rb_obj_is_kind_of(value, sbr->rbStructClass)) {
|
144
|
-
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
|
145
|
-
rb_obj_classname(value),
|
146
|
-
RSTRING_PTR(rb_class_name(sbr->rbStructClass)));
|
147
|
-
}
|
148
|
-
|
149
|
-
Data_Get_Struct(value, Struct, s);
|
150
|
-
|
151
|
-
return s->rbPointer;
|
152
|
-
}
|
153
|
-
|
154
|
-
/*
|
155
|
-
* call-seq: from_native(value, ctx)
|
156
|
-
* @param [AbstractMemory] value
|
157
|
-
* @param [nil] ctx
|
158
|
-
* @return [Struct]
|
159
|
-
* Create a struct from content of memory +value+.
|
160
|
-
*/
|
161
|
-
static VALUE
|
162
|
-
sbr_from_native(VALUE self, VALUE value, VALUE ctx)
|
163
|
-
{
|
164
|
-
StructByReference* sbr;
|
165
|
-
|
166
|
-
Data_Get_Struct(self, StructByReference, sbr);
|
167
|
-
|
168
|
-
return rb_class_new_instance(1, &value, sbr->rbStructClass);
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
void
|
173
|
-
rbffi_StructByReference_Init(VALUE moduleFFI)
|
174
|
-
{
|
175
|
-
/*
|
176
|
-
* Document-class: FFI::StructByReference
|
177
|
-
* This class includes {FFI::DataConverter} module.
|
178
|
-
*/
|
179
|
-
rbffi_StructByReferenceClass = rb_define_class_under(moduleFFI, "StructByReference", rb_cObject);
|
180
|
-
rb_global_variable(&rbffi_StructByReferenceClass);
|
181
|
-
rb_include_module(rbffi_StructByReferenceClass, rb_const_get(moduleFFI, rb_intern("DataConverter")));
|
182
|
-
|
183
|
-
rb_define_alloc_func(rbffi_StructByReferenceClass, sbr_allocate);
|
184
|
-
rb_define_method(rbffi_StructByReferenceClass, "initialize", sbr_initialize, 1);
|
185
|
-
rb_define_method(rbffi_StructByReferenceClass, "struct_class", sbr_struct_class, 0);
|
186
|
-
rb_define_method(rbffi_StructByReferenceClass, "native_type", sbr_native_type, 0);
|
187
|
-
rb_define_method(rbffi_StructByReferenceClass, "to_native", sbr_to_native, 2);
|
188
|
-
rb_define_method(rbffi_StructByReferenceClass, "from_native", sbr_from_native, 2);
|
189
|
-
}
|
190
|
-
|
@@ -1,50 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (c) 2009, Wayne Meissner
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
7
|
-
*
|
8
|
-
* * Redistributions of source code must retain the above copyright notice, this
|
9
|
-
* list of conditions and the following disclaimer.
|
10
|
-
* * Redistributions in binary form must reproduce the above copyright notice
|
11
|
-
* this list of conditions and the following disclaimer in the documentation
|
12
|
-
* and/or other materials provided with the distribution.
|
13
|
-
* * The name of the author or authors may not be used to endorse or promote
|
14
|
-
* products derived from this software without specific prior written permission.
|
15
|
-
*
|
16
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
20
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
-
*/
|
27
|
-
|
28
|
-
#ifndef RBFFI_STRUCTBYREFERENCE_H
|
29
|
-
#define RBFFI_STRUCTBYREFERENCE_H
|
30
|
-
|
31
|
-
#include <ruby.h>
|
32
|
-
|
33
|
-
#ifdef __cplusplus
|
34
|
-
extern "C" {
|
35
|
-
#endif
|
36
|
-
|
37
|
-
typedef struct StructByReference_ {
|
38
|
-
VALUE rbStructClass;
|
39
|
-
} StructByReference;
|
40
|
-
|
41
|
-
void rbffi_StructByReference_Init(VALUE moduleFFI);
|
42
|
-
|
43
|
-
extern VALUE rbffi_StructByReferenceClass;
|
44
|
-
|
45
|
-
#ifdef __cplusplus
|
46
|
-
}
|
47
|
-
#endif
|
48
|
-
|
49
|
-
#endif /* RBFFI_STRUCTBYREFERENCE_H */
|
50
|
-
|