ffi 1.16.2 → 1.17.0.rc1
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
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +36 -0
- data/Gemfile +9 -2
- data/README.md +2 -2
- data/Rakefile +17 -5
- data/ext/ffi_c/AbstractMemory.c +42 -40
- data/ext/ffi_c/ArrayType.c +2 -2
- data/ext/ffi_c/Buffer.c +4 -4
- data/ext/ffi_c/Call.c +18 -9
- data/ext/ffi_c/Call.h +3 -2
- data/ext/ffi_c/DynamicLibrary.c +2 -2
- data/ext/ffi_c/Function.c +4 -2
- data/ext/ffi_c/FunctionInfo.c +4 -2
- data/ext/ffi_c/LastError.c +4 -4
- data/ext/ffi_c/MemoryPointer.c +2 -2
- data/ext/ffi_c/Pointer.c +14 -11
- data/ext/ffi_c/Struct.c +18 -7
- data/ext/ffi_c/StructLayout.c +6 -6
- data/ext/ffi_c/Type.c +17 -16
- data/ext/ffi_c/Types.c +7 -1
- data/ext/ffi_c/Types.h +0 -1
- data/ext/ffi_c/Variadic.c +5 -2
- data/ext/ffi_c/libffi/.allow-ai-service +0 -0
- data/ext/ffi_c/libffi/.github/workflows/build.yml +34 -15
- data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +2 -1
- data/ext/ffi_c/libffi/LICENSE +1 -1
- data/ext/ffi_c/libffi/README.md +10 -5
- data/ext/ffi_c/libffi/compile +9 -8
- data/ext/ffi_c/libffi/configure +15 -15
- data/ext/ffi_c/libffi/configure.ac +2 -2
- data/ext/ffi_c/libffi/configure.host +1 -1
- data/ext/ffi_c/libffi/doc/libffi.texi +1 -1
- data/ext/ffi_c/libffi/doc/version.texi +4 -4
- data/ext/ffi_c/libffi/include/ffi.h.in +2 -11
- data/ext/ffi_c/libffi/include/ffi_common.h +4 -2
- data/ext/ffi_c/libffi/libffi.map.in +5 -0
- data/ext/ffi_c/libffi/libtool-version +1 -1
- data/ext/ffi_c/libffi/ltmain.sh +8 -20
- data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +1 -1
- data/ext/ffi_c/libffi/src/aarch64/ffi.c +26 -13
- data/ext/ffi_c/libffi/src/aarch64/sysv.S +198 -46
- data/ext/ffi_c/libffi/src/closures.c +3 -3
- data/ext/ffi_c/libffi/src/debug.c +2 -2
- data/ext/ffi_c/libffi/src/dlmalloc.c +1 -1
- data/ext/ffi_c/libffi/src/loongarch64/ffi.c +3 -0
- data/ext/ffi_c/libffi/src/mips/ffi.c +12 -4
- data/ext/ffi_c/libffi/src/mips/n32.S +65 -14
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +36 -24
- data/ext/ffi_c/libffi/src/sparc/ffi64.c +7 -1
- data/ext/ffi_c/libffi/src/tramp.c +1 -1
- data/ext/ffi_c/libffi/src/types.c +4 -6
- data/ext/ffi_c/libffi/src/wasm32/ffi.c +13 -0
- data/ext/ffi_c/libffi/src/x86/ffiw64.c +1 -1
- data/ext/ffi_c/libffi/testsuite/Makefile.am +79 -127
- data/ext/ffi_c/libffi/testsuite/Makefile.in +79 -127
- data/ext/ffi_c/libffi/testsuite/emscripten/conftest.py +6 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/callback.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/callback2.c +108 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/callback3.c +114 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/callback4.c +119 -0
- data/ext/ffi_c/libffi.darwin.mk +2 -2
- data/lib/ffi/dynamic_library.rb +34 -5
- data/lib/ffi/enum.rb +0 -1
- data/lib/ffi/function.rb +1 -1
- data/lib/ffi/io.rb +2 -2
- data/lib/ffi/library.rb +23 -23
- data/lib/ffi/platform/aarch64-linux/types.conf +74 -3
- data/lib/ffi/pointer.rb +6 -6
- data/lib/ffi/struct.rb +4 -4
- data/lib/ffi/struct_layout.rb +2 -2
- data/lib/ffi/struct_layout_builder.rb +8 -8
- data/lib/ffi/types.rb +51 -48
- data/lib/ffi/version.rb +1 -1
- data/samples/hello_ractor.rb +11 -0
- data/samples/qsort_ractor.rb +28 -0
- data/sig/ffi/abstract_memory.rbs +164 -0
- data/sig/ffi/auto_pointer.rbs +27 -0
- data/sig/ffi/buffer.rbs +18 -0
- data/sig/ffi/data_converter.rbs +10 -0
- data/sig/ffi/dynamic_library.rbs +9 -0
- data/sig/ffi/enum.rbs +38 -0
- data/sig/ffi/function.rbs +39 -0
- data/sig/ffi/library.rbs +42 -0
- data/sig/ffi/native_type.rbs +86 -0
- data/sig/ffi/pointer.rbs +42 -0
- data/sig/ffi/struct.rbs +76 -0
- data/sig/ffi/struct_by_reference.rbs +11 -0
- data/sig/ffi/struct_by_value.rbs +7 -0
- data/sig/ffi/struct_layout.rbs +9 -0
- data/sig/ffi/struct_layout_builder.rbs +5 -0
- data/sig/ffi/type.rbs +39 -0
- data/sig/ffi.rbs +26 -0
- data.tar.gz.sig +0 -0
- metadata +39 -15
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5ea15fd47a8241bb9bab7086d46ac6bc6ac752c383dc748c616d298f742ed0d0
|
|
4
|
+
data.tar.gz: 5253f331c7fea5590f4499133cac83dbeba5d833825339f4fc45cb57f0c94bcd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e42a6fc177d1302b64a07b6b93a20bf9e0ad4e692a7ab2c16f1f5fbf65ce795fe044187befdcc5859ecb8f3870acac3ca3b687e5e96773f448d0b16e6a1d7710
|
|
7
|
+
data.tar.gz: 2efdb5b63defea13f90d5ec7a7f8c7fb85e3cab24fc84320c8e061017946687f0238a68a57375a4ce76aa67f041b6b65966170d4d98d5ed4cac4d1dbd3dc71df
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
1.17.0.rc1 / 2024-04-07
|
|
2
|
+
-------------------
|
|
3
|
+
|
|
4
|
+
Fixed:
|
|
5
|
+
* Fix type definitions on `aarch64-linux`. #1067, #1066
|
|
6
|
+
* Use RB_TEST for `Pointer.autorelease=` . #1065
|
|
7
|
+
So that `false` and `nil` are treated as falsey and anything else as truthy.
|
|
8
|
+
* Replace Fixnum by Integer. #1064
|
|
9
|
+
Fixnum is no longer present in the ruby language.
|
|
10
|
+
* Update `FFI::NativeType` doc. #1061
|
|
11
|
+
* Store FFI::Type::Mapped of FFI::StrPtrConverter in global instead of custom type map
|
|
12
|
+
* Various documentation fixes. #1042
|
|
13
|
+
* Update `FFI::Pointer#==` to return `false` if a pointer is compared to a non-pointer object, which is the expected behavior. #1083
|
|
14
|
+
* Avoid warning about undefined wariable `@ffi_functions` #1085
|
|
15
|
+
* Fix a very unlikely GC bug when using a callback block. # 1089
|
|
16
|
+
|
|
17
|
+
Added:
|
|
18
|
+
* Provide binary gems for many platforms. #990
|
|
19
|
+
* Add Windows fat binary gem for Ruby-3.3
|
|
20
|
+
* Add RBS type definitions for many user facing parts of the FFI API. #1042
|
|
21
|
+
* Improve fallback search path logic. #1088
|
|
22
|
+
Respect LD_LIBRARY_PATH and DYLD_LIBRARY_PATH on Macos.
|
|
23
|
+
* Update libffi to current git master branch.
|
|
24
|
+
|
|
25
|
+
Removed:
|
|
26
|
+
* Remove `enum CHAR_ARRAY` which is no longer used. #1063
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
1.16.3 / 2023-10-04
|
|
30
|
+
-------------------
|
|
31
|
+
|
|
32
|
+
Fixed:
|
|
33
|
+
* Fix gcc error when building on CentOS 7. #1052
|
|
34
|
+
* Avoid trying to store new DataConverter type in frozen TypeDefs hash. #1057
|
|
35
|
+
|
|
36
|
+
|
|
1
37
|
1.16.2 / 2023-09-25
|
|
2
38
|
-------------------
|
|
3
39
|
|
data/Gemfile
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
3
|
group :development do
|
|
4
|
+
gem 'bigdecimal' unless RUBY_VERSION =~ /^2\.[4567]|^3\.[012]\./ # necessary on ruby-3.3+
|
|
5
|
+
gem 'bundler', '>= 1.16', '< 3'
|
|
4
6
|
gem 'rake', '~> 13.0'
|
|
5
7
|
gem 'rake-compiler', '~> 1.1'
|
|
6
|
-
gem 'rake-compiler-dock', '~> 1.0'
|
|
8
|
+
gem 'rake-compiler-dock', '~> 1.0.pre'
|
|
7
9
|
gem 'rspec', '~> 3.0'
|
|
8
|
-
gem 'bundler', '>= 1.16', '< 3'
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
group :doc do
|
|
12
13
|
gem 'kramdown'
|
|
13
14
|
gem 'yard', '~> 0.9'
|
|
14
15
|
end
|
|
16
|
+
|
|
17
|
+
group :type_check do
|
|
18
|
+
if RUBY_VERSION >= "2.6" && %w[ ruby truffleruby ].include?(RUBY_ENGINE)
|
|
19
|
+
gem 'rbs', '~> 3.0'
|
|
20
|
+
end
|
|
21
|
+
end
|
data/README.md
CHANGED
|
@@ -15,7 +15,7 @@ using Ruby-FFI](https://github.com/ffi/ffi/wiki/why-use-ffi).
|
|
|
15
15
|
* C structs (also nested), enums and global variables
|
|
16
16
|
* Callbacks from C to Ruby
|
|
17
17
|
* Automatic garbage collection of native memory
|
|
18
|
-
* Usable in Ractor
|
|
18
|
+
* Usable in Ractor: [How-to-use-FFI-in-Ruby-Ractors](https://github.com/ffi/ffi/wiki/Ractors)
|
|
19
19
|
|
|
20
20
|
## Synopsis
|
|
21
21
|
|
|
@@ -114,7 +114,7 @@ The following people have submitted code, bug reports, or otherwise contributed
|
|
|
114
114
|
* Jurij Smakov <jurij@wooyd.org>
|
|
115
115
|
* KISHIMOTO, Makoto <ksmakoto@dd.iij4u.or.jp>
|
|
116
116
|
* Kim Burgestrand <kim@burgestrand.se>
|
|
117
|
-
* Lars Kanis <
|
|
117
|
+
* Lars Kanis <lars@greiz-reinsdorf.de>
|
|
118
118
|
* Luc Heinrich <luc@honk-honk.com>
|
|
119
119
|
* Luis Lavena <luislavena@gmail.com>
|
|
120
120
|
* Matijs van Zuijlen <matijs@matijs.net>
|
data/Rakefile
CHANGED
|
@@ -13,7 +13,7 @@ BUILD_EXT_DIR = File.join(BUILD_DIR, "#{RbConfig::CONFIG['arch']}", 'ffi_c', RUB
|
|
|
13
13
|
|
|
14
14
|
gem_spec = Bundler.load_gemspec('ffi.gemspec')
|
|
15
15
|
|
|
16
|
-
RSpec::Core::RakeTask.new(:spec
|
|
16
|
+
RSpec::Core::RakeTask.new(:spec) do |config|
|
|
17
17
|
config.rspec_opts = YAML.load_file 'spec/spec.opts'
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -84,10 +84,22 @@ end
|
|
|
84
84
|
task 'gem:java' => 'java:gem'
|
|
85
85
|
|
|
86
86
|
FfiGemHelper.install_tasks
|
|
87
|
-
# Register
|
|
88
|
-
Bundler::GemHelper.instance.cross_platforms = %w[
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
# Register binary gems to be pushed to rubygems.org
|
|
88
|
+
Bundler::GemHelper.instance.cross_platforms = %w[
|
|
89
|
+
x86-mingw32
|
|
90
|
+
x64-mingw-ucrt
|
|
91
|
+
x64-mingw32
|
|
92
|
+
x86-linux-gnu
|
|
93
|
+
x86-linux-musl
|
|
94
|
+
x86_64-linux-gnu
|
|
95
|
+
x86_64-linux-musl
|
|
96
|
+
arm-linux-gnu
|
|
97
|
+
arm-linux-musl
|
|
98
|
+
aarch64-linux-gnu
|
|
99
|
+
aarch64-linux-musl
|
|
100
|
+
x86_64-darwin
|
|
101
|
+
arm64-darwin
|
|
102
|
+
]
|
|
91
103
|
|
|
92
104
|
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
|
|
93
105
|
require 'rake/extensiontask'
|
data/ext/ffi_c/AbstractMemory.c
CHANGED
|
@@ -324,7 +324,7 @@ memory_clear(VALUE self)
|
|
|
324
324
|
/*
|
|
325
325
|
* call-seq: memory.size
|
|
326
326
|
* Return memory size in bytes (alias: #total)
|
|
327
|
-
* @return [
|
|
327
|
+
* @return [Integer]
|
|
328
328
|
*/
|
|
329
329
|
static VALUE
|
|
330
330
|
memory_size(VALUE self)
|
|
@@ -340,7 +340,7 @@ memory_size(VALUE self)
|
|
|
340
340
|
* call-seq: memory.get(type, offset)
|
|
341
341
|
* Return data of given type contained in memory.
|
|
342
342
|
* @param [Symbol, Type] type_name type of data to get
|
|
343
|
-
* @param [
|
|
343
|
+
* @param [Integer] offset point in buffer to start from
|
|
344
344
|
* @return [Object]
|
|
345
345
|
* @raise {ArgumentError} if type is not supported
|
|
346
346
|
*/
|
|
@@ -350,6 +350,7 @@ memory_get(VALUE self, VALUE type_name, VALUE offset)
|
|
|
350
350
|
AbstractMemory* ptr;
|
|
351
351
|
VALUE nType;
|
|
352
352
|
Type *type;
|
|
353
|
+
MemoryOp *op;
|
|
353
354
|
|
|
354
355
|
nType = rbffi_Type_Lookup(type_name);
|
|
355
356
|
if(NIL_P(nType)) goto undefined_type;
|
|
@@ -357,7 +358,7 @@ memory_get(VALUE self, VALUE type_name, VALUE offset)
|
|
|
357
358
|
TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
|
|
358
359
|
TypedData_Get_Struct(nType, Type, &rbffi_type_data_type, type);
|
|
359
360
|
|
|
360
|
-
|
|
361
|
+
op = get_memory_op(type);
|
|
361
362
|
if(op == NULL) goto undefined_type;
|
|
362
363
|
|
|
363
364
|
return op->get(ptr, NUM2LONG(offset));
|
|
@@ -372,7 +373,7 @@ undefined_type: {
|
|
|
372
373
|
/*
|
|
373
374
|
* call-seq: memory.put(type, offset, value)
|
|
374
375
|
* @param [Symbol, Type] type_name type of data to put
|
|
375
|
-
* @param [
|
|
376
|
+
* @param [Integer] offset point in buffer to start from
|
|
376
377
|
* @return [nil]
|
|
377
378
|
* @raise {ArgumentError} if type is not supported
|
|
378
379
|
*/
|
|
@@ -382,6 +383,7 @@ memory_put(VALUE self, VALUE type_name, VALUE offset, VALUE value)
|
|
|
382
383
|
AbstractMemory* ptr;
|
|
383
384
|
VALUE nType;
|
|
384
385
|
Type *type;
|
|
386
|
+
MemoryOp *op;
|
|
385
387
|
|
|
386
388
|
nType = rbffi_Type_Lookup(type_name);
|
|
387
389
|
if(NIL_P(nType)) goto undefined_type;
|
|
@@ -389,7 +391,7 @@ memory_put(VALUE self, VALUE type_name, VALUE offset, VALUE value)
|
|
|
389
391
|
TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
|
|
390
392
|
TypedData_Get_Struct(nType, Type, &rbffi_type_data_type, type);
|
|
391
393
|
|
|
392
|
-
|
|
394
|
+
op = get_memory_op(type);
|
|
393
395
|
if(op == NULL) goto undefined_type;
|
|
394
396
|
|
|
395
397
|
op->put(ptr, NUM2LONG(offset), value);
|
|
@@ -405,8 +407,8 @@ undefined_type: {
|
|
|
405
407
|
/*
|
|
406
408
|
* call-seq: memory.get_string(offset, length=nil)
|
|
407
409
|
* Return string contained in memory.
|
|
408
|
-
* @param [
|
|
409
|
-
* @param [
|
|
410
|
+
* @param [Integer] offset point in buffer to start from
|
|
411
|
+
* @param [Integer] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
|
|
410
412
|
* @return [String]
|
|
411
413
|
* @raise {IndexError} if +length+ is too great
|
|
412
414
|
* @raise {NullPointerError} if memory not initialized
|
|
@@ -433,8 +435,8 @@ memory_get_string(int argc, VALUE* argv, VALUE self)
|
|
|
433
435
|
/*
|
|
434
436
|
* call-seq: memory.get_array_of_string(offset, count=nil)
|
|
435
437
|
* Return an array of strings contained in memory.
|
|
436
|
-
* @param [
|
|
437
|
-
* @param [
|
|
438
|
+
* @param [Integer] offset point in memory to start from
|
|
439
|
+
* @param [Integer] count number of strings to get. If nil, return all strings
|
|
438
440
|
* @return [Array<String>]
|
|
439
441
|
* @raise {IndexError} if +offset+ is too great
|
|
440
442
|
* @raise {NullPointerError} if memory not initialized
|
|
@@ -483,7 +485,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
|
|
|
483
485
|
* call-seq: memory.read_array_of_string(count=nil)
|
|
484
486
|
* Return an array of strings contained in memory. Same as:
|
|
485
487
|
* memory.get_array_of_string(0, count)
|
|
486
|
-
* @param [
|
|
488
|
+
* @param [Integer] count number of strings to get. If nil, return all strings
|
|
487
489
|
* @return [Array<String>]
|
|
488
490
|
*/
|
|
489
491
|
static VALUE
|
|
@@ -503,7 +505,7 @@ memory_read_array_of_string(int argc, VALUE* argv, VALUE self)
|
|
|
503
505
|
|
|
504
506
|
/*
|
|
505
507
|
* call-seq: memory.put_string(offset, str)
|
|
506
|
-
* @param [
|
|
508
|
+
* @param [Integer] offset
|
|
507
509
|
* @param [String] str
|
|
508
510
|
* @return [self]
|
|
509
511
|
* @raise {SecurityError} when writing unsafe string to memory
|
|
@@ -533,8 +535,8 @@ memory_put_string(VALUE self, VALUE offset, VALUE str)
|
|
|
533
535
|
/*
|
|
534
536
|
* call-seq: memory.get_bytes(offset, length)
|
|
535
537
|
* Return string contained in memory.
|
|
536
|
-
* @param [
|
|
537
|
-
* @param [
|
|
538
|
+
* @param [Integer] offset point in buffer to start from
|
|
539
|
+
* @param [Integer] length string's length in bytes.
|
|
538
540
|
* @return [String]
|
|
539
541
|
* @raise {IndexError} if +length+ is too great
|
|
540
542
|
* @raise {NullPointerError} if memory not initialized
|
|
@@ -557,10 +559,10 @@ memory_get_bytes(VALUE self, VALUE offset, VALUE length)
|
|
|
557
559
|
/*
|
|
558
560
|
* call-seq: memory.put_bytes(offset, str, index=0, length=nil)
|
|
559
561
|
* Put a string in memory.
|
|
560
|
-
* @param [
|
|
562
|
+
* @param [Integer] offset point in buffer to start from
|
|
561
563
|
* @param [String] str string to put to memory
|
|
562
|
-
* @param [
|
|
563
|
-
* @param [
|
|
564
|
+
* @param [Integer] index
|
|
565
|
+
* @param [Integer] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
|
|
564
566
|
* @return [self]
|
|
565
567
|
* @raise {IndexError} if +length+ is too great
|
|
566
568
|
* @raise {NullPointerError} if memory not initialized
|
|
@@ -599,7 +601,7 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
|
|
|
599
601
|
|
|
600
602
|
/*
|
|
601
603
|
* call-seq: memory.read_bytes(length)
|
|
602
|
-
* @param [
|
|
604
|
+
* @param [Integer] length of string to return
|
|
603
605
|
* @return [String]
|
|
604
606
|
* equivalent to :
|
|
605
607
|
* memory.get_bytes(0, length)
|
|
@@ -613,8 +615,8 @@ memory_read_bytes(VALUE self, VALUE length)
|
|
|
613
615
|
/*
|
|
614
616
|
* call-seq: memory.write_bytes(str, index=0, length=nil)
|
|
615
617
|
* @param [String] str string to put to memory
|
|
616
|
-
* @param [
|
|
617
|
-
* @param [
|
|
618
|
+
* @param [Integer] index
|
|
619
|
+
* @param [Integer] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
|
|
618
620
|
* @return [self]
|
|
619
621
|
* equivalent to :
|
|
620
622
|
* memory.put_bytes(0, str, index, length)
|
|
@@ -635,7 +637,7 @@ memory_write_bytes(int argc, VALUE* argv, VALUE self)
|
|
|
635
637
|
|
|
636
638
|
/*
|
|
637
639
|
* call-seq: memory.type_size
|
|
638
|
-
* @return [
|
|
640
|
+
* @return [Integer] type size in bytes
|
|
639
641
|
* Get the memory's type size.
|
|
640
642
|
*/
|
|
641
643
|
static VALUE
|
|
@@ -651,7 +653,7 @@ memory_type_size(VALUE self)
|
|
|
651
653
|
/*
|
|
652
654
|
* Document-method: []
|
|
653
655
|
* call-seq: memory[idx]
|
|
654
|
-
* @param [
|
|
656
|
+
* @param [Integer] idx index to access in memory
|
|
655
657
|
* @return
|
|
656
658
|
* Memory read accessor.
|
|
657
659
|
*/
|
|
@@ -859,8 +861,8 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
859
861
|
|
|
860
862
|
/*
|
|
861
863
|
* Document-method: put_float32
|
|
862
|
-
* call-seq: memory.
|
|
863
|
-
* @param [
|
|
864
|
+
* call-seq: memory.put_float32(offset, value)
|
|
865
|
+
* @param [Integer] offset
|
|
864
866
|
* @param [Numeric] value
|
|
865
867
|
* @return [self]
|
|
866
868
|
* Put +value+ as a 32-bit float in memory at offset +offset+ (alias: #put_float).
|
|
@@ -869,7 +871,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
869
871
|
/*
|
|
870
872
|
* Document-method: get_float32
|
|
871
873
|
* call-seq: memory.get_float32(offset)
|
|
872
|
-
* @param [
|
|
874
|
+
* @param [Integer] offset
|
|
873
875
|
* @return [Float]
|
|
874
876
|
* Get a 32-bit float from memory at offset +offset+ (alias: #get_float).
|
|
875
877
|
*/
|
|
@@ -900,7 +902,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
900
902
|
/*
|
|
901
903
|
* Document-method: put_array_of_float32
|
|
902
904
|
* call-seq: memory.put_array_of_float32(offset, ary)
|
|
903
|
-
* @param [
|
|
905
|
+
* @param [Integer] offset
|
|
904
906
|
* @param [Array<Numeric>] ary
|
|
905
907
|
* @return [self]
|
|
906
908
|
* Put values from +ary+ as 32-bit floats in memory from offset +offset+ (alias: #put_array_of_float).
|
|
@@ -909,8 +911,8 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
909
911
|
/*
|
|
910
912
|
* Document-method: get_array_of_float32
|
|
911
913
|
* call-seq: memory.get_array_of_float32(offset, length)
|
|
912
|
-
* @param [
|
|
913
|
-
* @param [
|
|
914
|
+
* @param [Integer] offset
|
|
915
|
+
* @param [Integer] length number of Float to get
|
|
914
916
|
* @return [Array<Float>]
|
|
915
917
|
* Get 32-bit floats in memory from offset +offset+ (alias: #get_array_of_float).
|
|
916
918
|
*/
|
|
@@ -929,7 +931,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
929
931
|
/*
|
|
930
932
|
* Document-method: read_array_of_float
|
|
931
933
|
* call-seq: memory.read_array_of_float(length)
|
|
932
|
-
* @param [
|
|
934
|
+
* @param [Integer] length number of Float to read
|
|
933
935
|
* @return [Array<Float>]
|
|
934
936
|
* Read 32-bit floats from memory.
|
|
935
937
|
*
|
|
@@ -942,7 +944,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
942
944
|
/*
|
|
943
945
|
* Document-method: put_float64
|
|
944
946
|
* call-seq: memory.put_float64(offset, value)
|
|
945
|
-
* @param [
|
|
947
|
+
* @param [Integer] offset
|
|
946
948
|
* @param [Numeric] value
|
|
947
949
|
* @return [self]
|
|
948
950
|
* Put +value+ as a 64-bit float (double) in memory at offset +offset+ (alias: #put_double).
|
|
@@ -951,7 +953,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
951
953
|
/*
|
|
952
954
|
* Document-method: get_float64
|
|
953
955
|
* call-seq: memory.get_float64(offset)
|
|
954
|
-
* @param [
|
|
956
|
+
* @param [Integer] offset
|
|
955
957
|
* @return [Float]
|
|
956
958
|
* Get a 64-bit float (double) from memory at offset +offset+ (alias: #get_double).
|
|
957
959
|
*/
|
|
@@ -982,7 +984,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
982
984
|
/*
|
|
983
985
|
* Document-method: put_array_of_float64
|
|
984
986
|
* call-seq: memory.put_array_of_float64(offset, ary)
|
|
985
|
-
* @param [
|
|
987
|
+
* @param [Integer] offset
|
|
986
988
|
* @param [Array<Numeric>] ary
|
|
987
989
|
* @return [self]
|
|
988
990
|
* Put values from +ary+ as 64-bit floats (doubles) in memory from offset +offset+ (alias: #put_array_of_double).
|
|
@@ -991,8 +993,8 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
991
993
|
/*
|
|
992
994
|
* Document-method: get_array_of_float64
|
|
993
995
|
* call-seq: memory.get_array_of_float64(offset, length)
|
|
994
|
-
* @param [
|
|
995
|
-
* @param [
|
|
996
|
+
* @param [Integer] offset
|
|
997
|
+
* @param [Integer] length number of Float to get
|
|
996
998
|
* @return [Array<Float>]
|
|
997
999
|
* Get 64-bit floats (doubles) in memory from offset +offset+ (alias: #get_array_of_double).
|
|
998
1000
|
*/
|
|
@@ -1011,7 +1013,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
1011
1013
|
/*
|
|
1012
1014
|
* Document-method: read_array_of_double
|
|
1013
1015
|
* call-seq: memory.read_array_of_double(length)
|
|
1014
|
-
* @param [
|
|
1016
|
+
* @param [Integer] length number of Float to read
|
|
1015
1017
|
* @return [Array<Float>]
|
|
1016
1018
|
* Read 64-bit floats (doubles) from memory.
|
|
1017
1019
|
*
|
|
@@ -1024,7 +1026,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
1024
1026
|
/*
|
|
1025
1027
|
* Document-method: put_pointer
|
|
1026
1028
|
* call-seq: memory.put_pointer(offset, value)
|
|
1027
|
-
* @param [
|
|
1029
|
+
* @param [Integer] offset
|
|
1028
1030
|
* @param [nil,Pointer, Integer, #to_ptr] value
|
|
1029
1031
|
* @return [self]
|
|
1030
1032
|
* Put +value+ in memory from +offset+..
|
|
@@ -1033,7 +1035,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
1033
1035
|
/*
|
|
1034
1036
|
* Document-method: get_pointer
|
|
1035
1037
|
* call-seq: memory.get_pointer(offset)
|
|
1036
|
-
* @param [
|
|
1038
|
+
* @param [Integer] offset
|
|
1037
1039
|
* @return [Pointer]
|
|
1038
1040
|
* Get a {Pointer} to the memory from +offset+.
|
|
1039
1041
|
*/
|
|
@@ -1062,7 +1064,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
1062
1064
|
/*
|
|
1063
1065
|
* Document-method: put_array_of_pointer
|
|
1064
1066
|
* call-seq: memory.put_array_of_pointer(offset, ary)
|
|
1065
|
-
* @param [
|
|
1067
|
+
* @param [Integer] offset
|
|
1066
1068
|
* @param [Array<#to_ptr>] ary
|
|
1067
1069
|
* @return [self]
|
|
1068
1070
|
* Put an array of {Pointer} into memory from +offset+.
|
|
@@ -1071,8 +1073,8 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
1071
1073
|
/*
|
|
1072
1074
|
* Document-method: get_array_of_pointer
|
|
1073
1075
|
* call-seq: memory.get_array_of_pointer(offset, length)
|
|
1074
|
-
* @param [
|
|
1075
|
-
* @param [
|
|
1076
|
+
* @param [Integer] offset
|
|
1077
|
+
* @param [Integer] length
|
|
1076
1078
|
* @return [Array<Pointer>]
|
|
1077
1079
|
* Get an array of {Pointer} of length +length+ from +offset+.
|
|
1078
1080
|
*/
|
|
@@ -1091,7 +1093,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
1091
1093
|
/*
|
|
1092
1094
|
* Document-method: read_array_of_pointer
|
|
1093
1095
|
* call-seq: memory.read_array_of_pointer(length)
|
|
1094
|
-
* @param [
|
|
1096
|
+
* @param [Integer] length
|
|
1095
1097
|
* @return [Array<Pointer>]
|
|
1096
1098
|
* Read an array of {Pointer} of length +length+.
|
|
1097
1099
|
*
|
data/ext/ffi_c/ArrayType.c
CHANGED
|
@@ -110,7 +110,7 @@ array_type_memsize(const void *data)
|
|
|
110
110
|
/*
|
|
111
111
|
* call-seq: initialize(component_type, length)
|
|
112
112
|
* @param [Type] component_type
|
|
113
|
-
* @param [
|
|
113
|
+
* @param [Integer] length
|
|
114
114
|
* @return [self]
|
|
115
115
|
* A new instance of ArrayType.
|
|
116
116
|
*/
|
|
@@ -140,7 +140,7 @@ array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength)
|
|
|
140
140
|
|
|
141
141
|
/*
|
|
142
142
|
* call-seq: length
|
|
143
|
-
* @return [
|
|
143
|
+
* @return [Integer]
|
|
144
144
|
* Get array's length
|
|
145
145
|
*/
|
|
146
146
|
static VALUE
|
data/ext/ffi_c/Buffer.c
CHANGED
|
@@ -114,7 +114,7 @@ buffer_release(void *data)
|
|
|
114
114
|
/*
|
|
115
115
|
* call-seq: initialize(size, count=1, clear=false)
|
|
116
116
|
* @param [Integer, Symbol, #size] Type or size in bytes of a buffer cell
|
|
117
|
-
* @param [
|
|
117
|
+
* @param [Integer] count number of cell in the Buffer
|
|
118
118
|
* @param [Boolean] clear if true, set the buffer to all-zero
|
|
119
119
|
* @return [self]
|
|
120
120
|
* @raise {NoMemoryError} if failed to allocate memory for Buffer
|
|
@@ -219,7 +219,7 @@ slice(VALUE self, long offset, long len)
|
|
|
219
219
|
|
|
220
220
|
/*
|
|
221
221
|
* call-seq: + offset
|
|
222
|
-
* @param [
|
|
222
|
+
* @param [Integer] offset
|
|
223
223
|
* @return [Buffer] a new instance of Buffer pointing from offset until end of previous buffer.
|
|
224
224
|
* Add a Buffer with an offset
|
|
225
225
|
*/
|
|
@@ -236,8 +236,8 @@ buffer_plus(VALUE self, VALUE rbOffset)
|
|
|
236
236
|
|
|
237
237
|
/*
|
|
238
238
|
* call-seq: slice(offset, length)
|
|
239
|
-
* @param [
|
|
240
|
-
* @param [
|
|
239
|
+
* @param [Integer] offset
|
|
240
|
+
* @param [Integer] length
|
|
241
241
|
* @return [Buffer] a new instance of Buffer
|
|
242
242
|
* Slice an existing Buffer.
|
|
243
243
|
*/
|
data/ext/ffi_c/Call.c
CHANGED
|
@@ -86,10 +86,11 @@ static inline void* getPointer(VALUE value, int type);
|
|
|
86
86
|
|
|
87
87
|
static ID id_to_ptr, id_map_symbol, id_to_native;
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
VALUE
|
|
90
90
|
rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
|
91
91
|
FFIStorage* paramStorage, void** ffiValues,
|
|
92
|
-
VALUE* callbackParameters, int callbackCount,
|
|
92
|
+
VALUE* callbackParameters, int callbackCount,
|
|
93
|
+
VALUE enums)
|
|
93
94
|
{
|
|
94
95
|
VALUE callbackProc = Qnil;
|
|
95
96
|
FFIStorage* param = ¶mStorage[0];
|
|
@@ -327,6 +328,7 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
|
|
327
328
|
rb_raise(rb_eArgError, "Invalid parameter type: %d", paramType->nativeType);
|
|
328
329
|
}
|
|
329
330
|
}
|
|
331
|
+
return callbackProc;
|
|
330
332
|
}
|
|
331
333
|
|
|
332
334
|
static void *
|
|
@@ -362,6 +364,7 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
|
362
364
|
FFIStorage* params;
|
|
363
365
|
VALUE rbReturnValue;
|
|
364
366
|
rbffi_frame_t frame = { 0 };
|
|
367
|
+
VALUE callbackProc;
|
|
365
368
|
|
|
366
369
|
retval = alloca(MAX(fnInfo->ffi_cif.rtype->size, FFI_SIZEOF_ARG));
|
|
367
370
|
|
|
@@ -379,9 +382,10 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
|
379
382
|
bc->params = params;
|
|
380
383
|
bc->frame = &frame;
|
|
381
384
|
|
|
382
|
-
rbffi_SetupCallParams(argc, argv,
|
|
385
|
+
callbackProc = rbffi_SetupCallParams(argc, argv,
|
|
383
386
|
fnInfo->parameterCount, fnInfo->parameterTypes, params, ffiValues,
|
|
384
|
-
fnInfo->callbackParameters, fnInfo->callbackCount,
|
|
387
|
+
fnInfo->callbackParameters, fnInfo->callbackCount,
|
|
388
|
+
fnInfo->rbEnums);
|
|
385
389
|
|
|
386
390
|
rbffi_frame_push(&frame);
|
|
387
391
|
rb_rescue2(rbffi_do_blocking_call, (VALUE) bc, rbffi_save_frame_exception, (VALUE) &frame, rb_eException, (VALUE) 0);
|
|
@@ -392,14 +396,16 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
|
392
396
|
ffiValues = ALLOCA_N(void *, fnInfo->parameterCount);
|
|
393
397
|
params = ALLOCA_N(FFIStorage, fnInfo->parameterCount);
|
|
394
398
|
|
|
395
|
-
rbffi_SetupCallParams(argc, argv,
|
|
399
|
+
callbackProc = rbffi_SetupCallParams(argc, argv,
|
|
396
400
|
fnInfo->parameterCount, fnInfo->parameterTypes, params, ffiValues,
|
|
397
|
-
fnInfo->callbackParameters, fnInfo->callbackCount,
|
|
401
|
+
fnInfo->callbackParameters, fnInfo->callbackCount,
|
|
402
|
+
fnInfo->rbEnums);
|
|
398
403
|
|
|
399
404
|
rbffi_frame_push(&frame);
|
|
400
405
|
ffi_call(&fnInfo->ffi_cif, FFI_FN(function), retval, ffiValues);
|
|
401
406
|
rbffi_frame_pop(&frame);
|
|
402
407
|
}
|
|
408
|
+
RB_GC_GUARD(callbackProc);
|
|
403
409
|
|
|
404
410
|
if (unlikely(!fnInfo->ignoreErrno)) {
|
|
405
411
|
rbffi_save_errno();
|
|
@@ -427,8 +433,10 @@ getPointer(VALUE value, int type)
|
|
|
427
433
|
} else if (type == T_DATA && rb_obj_is_kind_of(value, rbffi_StructClass)) {
|
|
428
434
|
|
|
429
435
|
Struct* s;
|
|
436
|
+
AbstractMemory* memory;
|
|
437
|
+
|
|
430
438
|
TypedData_Get_Struct(value, Struct, &rbffi_struct_data_type, s);
|
|
431
|
-
|
|
439
|
+
memory = s->pointer;
|
|
432
440
|
return memory != NULL ? memory->address : NULL;
|
|
433
441
|
|
|
434
442
|
} else if (type == T_STRING) {
|
|
@@ -464,7 +472,9 @@ rbffi_GetInvoker(FunctionType *fnInfo)
|
|
|
464
472
|
static void*
|
|
465
473
|
callback_param(VALUE proc, VALUE cbInfo)
|
|
466
474
|
{
|
|
467
|
-
VALUE callback
|
|
475
|
+
VALUE callback;
|
|
476
|
+
AbstractMemory *mem;
|
|
477
|
+
|
|
468
478
|
if (unlikely(proc == Qnil)) {
|
|
469
479
|
return NULL ;
|
|
470
480
|
}
|
|
@@ -479,7 +489,6 @@ callback_param(VALUE proc, VALUE cbInfo)
|
|
|
479
489
|
callback = rbffi_Function_ForProc(cbInfo, proc);
|
|
480
490
|
RB_GC_GUARD(callback);
|
|
481
491
|
|
|
482
|
-
AbstractMemory *mem;
|
|
483
492
|
TypedData_Get_Struct(callback, AbstractMemory, &rbffi_abstract_memory_data_type, mem);
|
|
484
493
|
return mem->address;
|
|
485
494
|
}
|
data/ext/ffi_c/Call.h
CHANGED
|
@@ -73,9 +73,10 @@ typedef union {
|
|
|
73
73
|
|
|
74
74
|
extern void rbffi_Call_Init(VALUE moduleFFI);
|
|
75
75
|
|
|
76
|
-
extern
|
|
76
|
+
extern VALUE rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
|
77
77
|
FFIStorage* paramStorage, void** ffiValues,
|
|
78
|
-
VALUE* callbackParameters, int callbackCount,
|
|
78
|
+
VALUE* callbackParameters, int callbackCount,
|
|
79
|
+
VALUE enums);
|
|
79
80
|
|
|
80
81
|
struct FunctionType_;
|
|
81
82
|
extern VALUE rbffi_CallFunction(int argc, VALUE* argv, void* function, struct FunctionType_* fnInfo);
|
data/ext/ffi_c/DynamicLibrary.c
CHANGED
|
@@ -128,7 +128,7 @@ library_open(VALUE klass, VALUE libname, VALUE libflags)
|
|
|
128
128
|
/*
|
|
129
129
|
* call-seq: initialize(libname, libflags)
|
|
130
130
|
* @param [String] libname name of library to open
|
|
131
|
-
* @param [
|
|
131
|
+
* @param [Integer] libflags flags for library to open
|
|
132
132
|
* @return [FFI::DynamicLibrary]
|
|
133
133
|
* @raise {LoadError} if +libname+ cannot be opened
|
|
134
134
|
* A new DynamicLibrary instance.
|
|
@@ -232,7 +232,7 @@ dl_error(char* buf, int size)
|
|
|
232
232
|
|
|
233
233
|
// Get the associated message
|
|
234
234
|
LPSTR message = NULL;
|
|
235
|
-
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
|
235
|
+
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
|
236
236
|
NULL, error, 0, (LPSTR)&message, 0, NULL);
|
|
237
237
|
|
|
238
238
|
// Update the passed in buffer
|
data/ext/ffi_c/Function.c
CHANGED
|
@@ -953,10 +953,10 @@ invoke_callback(VALUE data)
|
|
|
953
953
|
|
|
954
954
|
} else if (rb_obj_is_kind_of(rbReturnValue, rb_cProc) || rb_respond_to(rbReturnValue, id_call)) {
|
|
955
955
|
VALUE function;
|
|
956
|
+
AbstractMemory* memory;
|
|
956
957
|
|
|
957
958
|
function = rbffi_Function_ForProc(rbReturnType, rbReturnValue);
|
|
958
959
|
|
|
959
|
-
AbstractMemory* memory;
|
|
960
960
|
TypedData_Get_Struct(function, AbstractMemory, &rbffi_abstract_memory_data_type, memory);
|
|
961
961
|
|
|
962
962
|
*((void **) retval) = memory->address;
|
|
@@ -968,8 +968,10 @@ invoke_callback(VALUE data)
|
|
|
968
968
|
case NATIVE_STRUCT:
|
|
969
969
|
if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_StructClass)) {
|
|
970
970
|
Struct* s;
|
|
971
|
+
AbstractMemory* memory;
|
|
972
|
+
|
|
971
973
|
TypedData_Get_Struct(rbReturnValue, Struct, &rbffi_struct_data_type, s);
|
|
972
|
-
|
|
974
|
+
memory = s->pointer;
|
|
973
975
|
|
|
974
976
|
if (memory->address != NULL) {
|
|
975
977
|
memcpy(retval, memory->address, returnType->ffiType->size);
|
data/ext/ffi_c/FunctionInfo.c
CHANGED
|
@@ -97,7 +97,8 @@ fntype_mark(void *data)
|
|
|
97
97
|
rb_gc_mark_movable(fnInfo->rbParameterTypes);
|
|
98
98
|
rb_gc_mark_movable(fnInfo->rbEnums);
|
|
99
99
|
if (fnInfo->callbackCount > 0 && fnInfo->callbackParameters != NULL) {
|
|
100
|
-
|
|
100
|
+
size_t index;
|
|
101
|
+
for (index = 0; index < fnInfo->callbackCount; index++) {
|
|
101
102
|
rb_gc_mark_movable(fnInfo->callbackParameters[index]);
|
|
102
103
|
}
|
|
103
104
|
}
|
|
@@ -111,7 +112,8 @@ fntype_compact(void *data)
|
|
|
111
112
|
ffi_gc_location(fnInfo->rbParameterTypes);
|
|
112
113
|
ffi_gc_location(fnInfo->rbEnums);
|
|
113
114
|
if (fnInfo->callbackCount > 0 && fnInfo->callbackParameters != NULL) {
|
|
114
|
-
|
|
115
|
+
size_t index;
|
|
116
|
+
for (index = 0; index < fnInfo->callbackCount; index++) {
|
|
115
117
|
ffi_gc_location(fnInfo->callbackParameters[index]);
|
|
116
118
|
}
|
|
117
119
|
}
|