ffi 0.5.0 → 0.5.1
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 +2 -2
- data/ext/ffi_c/AbstractMemory.c +5 -0
- data/ext/ffi_c/Buffer.c +1 -0
- data/ext/ffi_c/MemoryPointer.c +1 -0
- data/ext/ffi_c/Variadic.c +7 -19
- data/ext/ffi_c/libffi/doc/libffi.info +19 -18
- data/spec/ffi/struct_spec.rb +13 -0
- metadata +3 -13
data/Rakefile
CHANGED
@@ -78,7 +78,7 @@ PROJ.name = 'ffi'
|
|
78
78
|
PROJ.authors = 'Wayne Meissner'
|
79
79
|
PROJ.email = 'wmeissner@gmail.com'
|
80
80
|
PROJ.url = 'http://wiki.github.com/ffi/ffi'
|
81
|
-
PROJ.version = '0.5.
|
81
|
+
PROJ.version = '0.5.1'
|
82
82
|
PROJ.rubyforge.name = 'ffi'
|
83
83
|
PROJ.readme_file = 'README.rdoc'
|
84
84
|
|
@@ -86,7 +86,7 @@ PROJ.readme_file = 'README.rdoc'
|
|
86
86
|
PROJ.ann.paragraphs << 'FEATURES' << 'SYNOPSIS' << 'REQUIREMENTS' << 'DOWNLOAD/INSTALL' << 'CREDITS' << 'LICENSE'
|
87
87
|
|
88
88
|
PROJ.ann.email[:from] = 'andrea.fazzi@alcacoop.it'
|
89
|
-
PROJ.ann.email[:to]
|
89
|
+
PROJ.ann.email[:to] = ['ruby-ffi@googlegroups.com']
|
90
90
|
PROJ.ann.email[:server] = 'smtp.gmail.com'
|
91
91
|
|
92
92
|
# Gem specifications
|
data/ext/ffi_c/AbstractMemory.c
CHANGED
@@ -156,6 +156,7 @@ get_pointer_value(VALUE value)
|
|
156
156
|
return MEMORY_PTR(rb_funcall2(value, id_to_ptr, 0, NULL));
|
157
157
|
} else {
|
158
158
|
rb_raise(rb_eArgError, "value is not a pointer");
|
159
|
+
return NULL;
|
159
160
|
}
|
160
161
|
}
|
161
162
|
|
@@ -253,6 +254,7 @@ memory_put_string(VALUE self, VALUE offset, VALUE str)
|
|
253
254
|
|
254
255
|
if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) {
|
255
256
|
rb_raise(rb_eSecurityError, "Writing unsafe string to memory");
|
257
|
+
return Qnil;
|
256
258
|
}
|
257
259
|
|
258
260
|
memcpy(ptr->address + off, RSTRING_PTR(str), len);
|
@@ -290,10 +292,12 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
|
|
290
292
|
idx = nargs > 2 ? NUM2LONG(rbIndex) : 0;
|
291
293
|
if (idx < 0) {
|
292
294
|
rb_raise(rb_eRangeError, "index canot be less than zero");
|
295
|
+
return Qnil;
|
293
296
|
}
|
294
297
|
len = nargs > 3 ? NUM2LONG(rbLength) : (RSTRING_LEN(str) - idx);
|
295
298
|
if ((idx + len) > RSTRING_LEN(str)) {
|
296
299
|
rb_raise(rb_eRangeError, "index+length is greater than size of string");
|
300
|
+
return Qnil;
|
297
301
|
}
|
298
302
|
|
299
303
|
checkWrite(ptr);
|
@@ -301,6 +305,7 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
|
|
301
305
|
|
302
306
|
if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) {
|
303
307
|
rb_raise(rb_eSecurityError, "Writing unsafe string to memory");
|
308
|
+
return Qnil;
|
304
309
|
}
|
305
310
|
memcpy(ptr->address + off, RSTRING_PTR(str) + idx, len);
|
306
311
|
|
data/ext/ffi_c/Buffer.c
CHANGED
@@ -87,6 +87,7 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
|
|
87
87
|
p->storage = xmalloc(p->memory.size + 7);
|
88
88
|
if (p->storage == NULL) {
|
89
89
|
rb_raise(rb_eNoMemError, "Failed to allocate memory size=%lu bytes", p->memory.size);
|
90
|
+
return Qnil;
|
90
91
|
}
|
91
92
|
|
92
93
|
/* ensure the memory is aligned on at least a 8 byte boundary */
|
data/ext/ffi_c/MemoryPointer.c
CHANGED
@@ -98,6 +98,7 @@ memptr_malloc(VALUE self, long size, long count, bool clear)
|
|
98
98
|
p->storage = xmalloc(msize + 7);
|
99
99
|
if (p->storage == NULL) {
|
100
100
|
rb_raise(rb_eNoMemError, "Failed to allocate memory size=%ld bytes", msize);
|
101
|
+
return Qnil;
|
101
102
|
}
|
102
103
|
p->autorelease = true;
|
103
104
|
p->memory.typeSize = size;
|
data/ext/ffi_c/Variadic.c
CHANGED
@@ -145,28 +145,12 @@ variadic_initialize(VALUE self, VALUE rbFunction, VALUE rbParameterTypes, VALUE
|
|
145
145
|
return retval;
|
146
146
|
}
|
147
147
|
|
148
|
-
|
149
|
-
static inline VALUE
|
150
|
-
ffi_invoke(ffi_cif* cif, void* function, Type* returnType, void** ffiValues,
|
151
|
-
VALUE rbReturnType, VALUE rbEnums)
|
152
|
-
{
|
153
|
-
FFIStorage retval;
|
154
|
-
|
155
|
-
#ifdef USE_RAW
|
156
|
-
ffi_raw_call(cif, function, &retval, (ffi_raw *) ffiValues[0]);
|
157
|
-
#else
|
158
|
-
ffi_call(cif, function, &retval, ffiValues);
|
159
|
-
#endif
|
160
|
-
rbffi_save_errno();
|
161
|
-
|
162
|
-
return rbffi_NativeValue_ToRuby(returnType, rbReturnType, &retval, rbEnums);
|
163
|
-
}
|
164
|
-
|
165
148
|
static VALUE
|
166
149
|
variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
|
167
150
|
{
|
168
151
|
VariadicInvoker* invoker;
|
169
152
|
FFIStorage* params;
|
153
|
+
void* retval;
|
170
154
|
ffi_cif cif;
|
171
155
|
void** ffiValues;
|
172
156
|
ffi_type** ffiParamTypes;
|
@@ -186,6 +170,7 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
|
|
186
170
|
params = ALLOCA_N(FFIStorage, paramCount);
|
187
171
|
ffiValues = ALLOCA_N(void*, paramCount);
|
188
172
|
argv = ALLOCA_N(VALUE, paramCount);
|
173
|
+
retval = alloca(MAX(invoker->returnType->ffiType->size, FFI_SIZEOF_ARG));
|
189
174
|
|
190
175
|
for (i = 0; i < paramCount; ++i) {
|
191
176
|
VALUE entry = rb_ary_entry(parameterTypes, i);
|
@@ -241,8 +226,11 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
|
|
241
226
|
rbffi_SetupCallParams(paramCount, argv, -1, paramTypes, params,
|
242
227
|
ffiValues, NULL, 0, invoker->rbEnums);
|
243
228
|
|
244
|
-
|
245
|
-
|
229
|
+
ffi_call(&cif, invoker->function, retval, ffiValues);
|
230
|
+
|
231
|
+
rbffi_save_errno();
|
232
|
+
|
233
|
+
return rbffi_NativeValue_ToRuby(invoker->returnType, invoker->rbReturnType, retval, invoker->rbEnums);
|
246
234
|
}
|
247
235
|
|
248
236
|
|
@@ -1,7 +1,8 @@
|
|
1
|
-
This is
|
2
|
-
|
1
|
+
This is /Users/wayne/src/ruby-ffi.git/ext/ffi_c/libffi/doc/libffi.info,
|
2
|
+
produced by makeinfo version 4.7 from
|
3
|
+
/Users/wayne/src/ruby-ffi.git/ext/ffi_c/libffi/doc/libffi.texi.
|
3
4
|
|
4
|
-
This manual is for Libffi, a portable foreign-function interface
|
5
|
+
This manual is for Libffi, a portable foreign-function interface
|
5
6
|
library.
|
6
7
|
|
7
8
|
Copyright (C) 2008 Red Hat, Inc.
|
@@ -111,10 +112,10 @@ To prepare a call interface object, use the function `ffi_prep_cif'.
|
|
111
112
|
This initializes CIF according to the given parameters.
|
112
113
|
|
113
114
|
ABI is the ABI to use; normally `FFI_DEFAULT_ABI' is what you
|
114
|
-
want. *
|
115
|
+
want. *Note Multiple ABIs:: for more information.
|
115
116
|
|
116
117
|
NARGS is the number of arguments that this function accepts.
|
117
|
-
`libffi' does not yet handle varargs functions; see *
|
118
|
+
`libffi' does not yet handle varargs functions; see *Note Missing
|
118
119
|
Features:: for more information.
|
119
120
|
|
120
121
|
RTYPE is a pointer to an `ffi_type' structure that describes the
|
@@ -516,18 +517,18 @@ Index
|
|
516
517
|
|
517
518
|
|
518
519
|
Tag Table:
|
519
|
-
Node: Top
|
520
|
-
Node: Introduction
|
521
|
-
Node: Using libffi
|
522
|
-
Node: The Basics
|
523
|
-
Node: Simple Example
|
524
|
-
Node: Types
|
525
|
-
Node: Primitive Types
|
526
|
-
Node: Structures
|
527
|
-
Node: Type Example
|
528
|
-
Node: Multiple ABIs
|
529
|
-
Node: The Closure API
|
530
|
-
Node: Missing Features
|
531
|
-
Node: Index
|
520
|
+
Node: Top764
|
521
|
+
Node: Introduction1500
|
522
|
+
Node: Using libffi3136
|
523
|
+
Node: The Basics3571
|
524
|
+
Node: Simple Example6178
|
525
|
+
Node: Types7205
|
526
|
+
Node: Primitive Types7488
|
527
|
+
Node: Structures9308
|
528
|
+
Node: Type Example10168
|
529
|
+
Node: Multiple ABIs11391
|
530
|
+
Node: The Closure API11762
|
531
|
+
Node: Missing Features14682
|
532
|
+
Node: Index15175
|
532
533
|
|
533
534
|
End Tag Table
|
data/spec/ffi/struct_spec.rb
CHANGED
@@ -387,12 +387,18 @@ describe FFI::Struct, ' by value' do
|
|
387
387
|
class S8S32 < FFI::Struct
|
388
388
|
layout :s8, :char, :s32, :int
|
389
389
|
end
|
390
|
+
|
391
|
+
class StructString < FFI::Struct
|
392
|
+
layout :bytes, :string, :len, :int
|
393
|
+
end
|
394
|
+
|
390
395
|
attach_function :struct_return_s8s32, [ ], S8S32.by_value
|
391
396
|
attach_function :struct_s8s32_set, [ :char, :int ], S8S32.by_value
|
392
397
|
attach_function :struct_s8s32_get_s8, [ S8S32.by_value ], :char
|
393
398
|
attach_function :struct_s8s32_get_s32, [ S8S32.by_value ], :int
|
394
399
|
attach_function :struct_s8s32_s32_ret_s32, [ S8S32.by_value, :int ], :int
|
395
400
|
attach_function :struct_s8s32_s64_ret_s64, [ S8S32.by_value, :long_long ], :long_long
|
401
|
+
attach_function :struct_varargs_ret_struct_string, [ :int, :varargs ], StructString.by_value
|
396
402
|
end
|
397
403
|
|
398
404
|
it 'return using pre-set values' do
|
@@ -430,6 +436,13 @@ describe FFI::Struct, ' by value' do
|
|
430
436
|
|
431
437
|
LibTest.struct_s8s32_s64_ret_s64(s, 0xdeadcafebabe).should == 0xdeadcafebabe
|
432
438
|
end
|
439
|
+
|
440
|
+
it 'varargs returning a struct' do
|
441
|
+
string = "test"
|
442
|
+
s = LibTest.struct_varargs_ret_struct_string(4, :string, string)
|
443
|
+
s[:len].should == string.length
|
444
|
+
s[:bytes].should == string
|
445
|
+
end
|
433
446
|
end
|
434
447
|
|
435
448
|
describe FFI::Struct, ' with an array field' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wayne Meissner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-19 00:00:00 +10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,16 +22,6 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 0.8.7
|
24
24
|
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: bones
|
27
|
-
type: :development
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 2.5.1
|
34
|
-
version:
|
35
25
|
description: |-
|
36
26
|
Ruby-FFI is a ruby extension for programmatically loading dynamic
|
37
27
|
libraries, binding functions within them, and calling those functions
|
@@ -400,7 +390,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
400
390
|
requirements: []
|
401
391
|
|
402
392
|
rubyforge_project: ffi
|
403
|
-
rubygems_version: 1.3.
|
393
|
+
rubygems_version: 1.3.4
|
404
394
|
signing_key:
|
405
395
|
specification_version: 3
|
406
396
|
summary: Ruby-FFI is a ruby extension for programmatically loading dynamic libraries, binding functions within them, and calling those functions from Ruby code
|