ffi 0.5.0 → 0.6.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/LICENSE +1 -27
- data/Rakefile +9 -12
- data/ext/ffi_c/AbstractMemory.c +11 -8
- data/ext/ffi_c/AbstractMemory.h +23 -21
- data/ext/ffi_c/AutoPointer.c +0 -1
- data/ext/ffi_c/Buffer.c +24 -8
- data/ext/ffi_c/Call.c +28 -0
- data/ext/ffi_c/Call.h +8 -4
- data/ext/ffi_c/ClosurePool.c +7 -5
- data/ext/ffi_c/DynamicLibrary.c +0 -1
- data/ext/ffi_c/Function.c +19 -2
- data/ext/ffi_c/MemoryPointer.c +3 -3
- data/ext/ffi_c/MethodHandle.c +1 -1
- data/ext/ffi_c/Pointer.c +23 -9
- data/ext/ffi_c/Struct.c +142 -69
- data/ext/ffi_c/Struct.h +16 -7
- data/ext/ffi_c/StructLayout.c +92 -55
- data/ext/ffi_c/Type.c +5 -22
- data/ext/ffi_c/Type.h +1 -1
- data/ext/ffi_c/Types.c +8 -2
- data/ext/ffi_c/Types.h +2 -0
- data/ext/ffi_c/Variadic.c +7 -19
- data/ext/ffi_c/endian.h +1 -1
- data/ext/ffi_c/extconf.rb +20 -11
- data/ext/ffi_c/libffi/ChangeLog +900 -84
- data/ext/ffi_c/libffi/ChangeLog.libffi +311 -0
- data/ext/ffi_c/libffi/LICENSE +1 -1
- data/ext/ffi_c/libffi/Makefile.am +14 -4
- data/ext/ffi_c/libffi/Makefile.in +362 -211
- data/ext/ffi_c/libffi/README +70 -92
- data/ext/ffi_c/libffi/aclocal.m4 +6068 -4586
- data/ext/ffi_c/libffi/config.guess +125 -143
- data/ext/ffi_c/libffi/config.sub +103 -27
- data/ext/ffi_c/libffi/configure +11364 -18497
- data/ext/ffi_c/libffi/configure.ac +43 -4
- data/ext/ffi_c/libffi/doc/libffi.info +15 -15
- data/ext/ffi_c/libffi/doc/libffi.texi +1 -1
- data/ext/ffi_c/libffi/doc/stamp-vti +4 -4
- data/ext/ffi_c/libffi/doc/version.texi +4 -4
- data/ext/ffi_c/libffi/fficonfig.h.in +24 -3
- data/ext/ffi_c/libffi/include/Makefile.am +1 -1
- data/ext/ffi_c/libffi/include/Makefile.in +97 -50
- data/ext/ffi_c/libffi/include/ffi.h.in +8 -2
- data/ext/ffi_c/libffi/include/ffi_common.h +24 -0
- data/ext/ffi_c/libffi/libtool-version +1 -1
- data/ext/ffi_c/libffi/ltmain.sh +7346 -5870
- data/ext/ffi_c/libffi/m4/libtool.m4 +7360 -0
- data/ext/ffi_c/libffi/m4/ltoptions.m4 +368 -0
- data/ext/ffi_c/libffi/m4/ltsugar.m4 +123 -0
- data/ext/ffi_c/libffi/m4/ltversion.m4 +23 -0
- data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +92 -0
- data/ext/ffi_c/libffi/man/Makefile.in +115 -62
- data/ext/ffi_c/libffi/man/ffi_call.3 +3 -3
- data/ext/ffi_c/libffi/missing +15 -8
- data/ext/ffi_c/libffi/src/arm/sysv.S +15 -8
- data/ext/ffi_c/libffi/src/avr32/ffi.c +421 -0
- data/ext/ffi_c/libffi/src/avr32/ffitarget.h +50 -0
- data/ext/ffi_c/libffi/src/avr32/sysv.S +208 -0
- data/ext/ffi_c/libffi/src/closures.c +47 -10
- data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/java_raw_api.c +0 -3
- data/ext/ffi_c/libffi/src/mips/ffi.c +135 -32
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +37 -4
- data/ext/ffi_c/libffi/src/mips/n32.S +67 -10
- data/ext/ffi_c/libffi/src/mips/o32.S +8 -8
- data/ext/ffi_c/libffi/src/pa/ffi.c +7 -0
- data/ext/ffi_c/libffi/src/powerpc/aix.S +163 -64
- data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +308 -112
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +20 -7
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +208 -80
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +11 -3
- data/ext/ffi_c/libffi/src/powerpc/sysv.S +12 -23
- data/ext/ffi_c/libffi/src/s390/sysv.S +1 -1
- data/ext/ffi_c/libffi/src/sh/sysv.S +9 -9
- data/ext/ffi_c/libffi/src/sh64/ffi.c +37 -22
- data/ext/ffi_c/libffi/src/sh64/sysv.S +23 -14
- data/ext/ffi_c/libffi/src/sparc/ffi.c +21 -6
- data/ext/ffi_c/libffi/src/sparc/v8.S +55 -14
- data/ext/ffi_c/libffi/src/x86/darwin.S +10 -9
- data/ext/ffi_c/libffi/src/x86/ffi.c +293 -86
- data/ext/ffi_c/libffi/src/x86/ffi64.c +73 -19
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +30 -0
- data/ext/ffi_c/libffi/src/x86/sysv.S +21 -4
- data/ext/ffi_c/libffi/src/x86/unix64.S +8 -4
- data/ext/ffi_c/libffi/src/x86/win32.S +633 -147
- data/ext/ffi_c/libffi/src/x86/win64.S +460 -0
- data/ext/ffi_c/libffi/testsuite/Makefile.am +63 -54
- data/ext/ffi_c/libffi/testsuite/Makefile.in +112 -77
- data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +12 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +7 -14
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c +95 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_stdcall.c +6 -14
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +134 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +117 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +11 -17
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +66 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +57 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +4 -13
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +105 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +57 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +74 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +140 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +8 -16
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +37 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +25 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +31 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +2 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +342 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +145 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +148 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +124 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +124 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +4 -5
- data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest.cc +17 -16
- data/ext/ffi_c/libffi/texinfo.tex +155 -427
- data/ext/ffi_c/libffi.bsd.mk +1 -1
- data/lib/ffi/autopointer.rb +79 -20
- data/lib/ffi/buffer.rb +4 -0
- data/lib/ffi/callback.rb +4 -10
- data/lib/ffi/enum.rb +28 -0
- data/lib/ffi/ffi.rb +0 -1
- data/lib/ffi/io.rb +28 -0
- data/lib/ffi/library.rb +237 -182
- data/lib/ffi/memorypointer.rb +28 -62
- data/lib/ffi/platform.rb +27 -0
- data/lib/ffi/pointer.rb +28 -0
- data/lib/ffi/struct.rb +55 -1
- data/lib/ffi/types.rb +29 -0
- data/lib/ffi/variadic.rb +29 -0
- data/spec/ffi/library_spec.rb +31 -5
- data/spec/ffi/managed_struct_spec.rb +1 -1
- data/spec/ffi/pointer_spec.rb +1 -1
- data/spec/ffi/rbx/attach_function_spec.rb +2 -1
- data/spec/ffi/rbx/memory_pointer_spec.rb +2 -1
- data/spec/ffi/spec_helper.rb +5 -1
- data/spec/ffi/struct_spec.rb +77 -0
- metadata +28 -18
- data/ext/ffi_c/libffi/TODO +0 -1
- data/ext/ffi_c/libffi/ltcf-c.sh +0 -861
- data/ext/ffi_c/libffi/ltcf-cxx.sh +0 -1069
- data/ext/ffi_c/libffi/ltcf-gcj.sh +0 -700
- data/ext/ffi_c/libffi/ltconfig +0 -2862
- data/ext/ffi_c/libffi/mkinstalldirs +0 -158
data/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2008,
|
|
1
|
+
Copyright (c) 2008, 2009 Ruby FFI contributors
|
|
2
2
|
All rights reserved.
|
|
3
3
|
|
|
4
4
|
Redistribution and use in source and binary forms, with or without
|
|
@@ -23,29 +23,3 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
23
23
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
24
24
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
25
25
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
-
|
|
27
|
-
Copyright (c) 2007, Evan Phoenix
|
|
28
|
-
All rights reserved.
|
|
29
|
-
|
|
30
|
-
Redistribution and use in source and binary forms, with or without
|
|
31
|
-
modification, are permitted provided that the following conditions are met:
|
|
32
|
-
|
|
33
|
-
* Redistributions of source code must retain the above copyright notice, this
|
|
34
|
-
list of conditions and the following disclaimer.
|
|
35
|
-
* Redistributions in binary form must reproduce the above copyright notice
|
|
36
|
-
this list of conditions and the following disclaimer in the documentation
|
|
37
|
-
and/or other materials provided with the distribution.
|
|
38
|
-
* Neither the name of the Evan Phoenix nor the names of its contributors
|
|
39
|
-
may be used to endorse or promote products derived from this software
|
|
40
|
-
without specific prior written permission.
|
|
41
|
-
|
|
42
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
43
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
44
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
45
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
46
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
47
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
48
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
49
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
50
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
51
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/Rakefile
CHANGED
|
@@ -12,16 +12,7 @@ require 'date'
|
|
|
12
12
|
require 'fileutils'
|
|
13
13
|
require 'rbconfig'
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
require 'bones'
|
|
17
|
-
Bones.setup
|
|
18
|
-
rescue LoadError
|
|
19
|
-
begin
|
|
20
|
-
load 'tasks/setup.rb'
|
|
21
|
-
rescue LoadError
|
|
22
|
-
raise RuntimeError, '### please install the "bones" gem ###'
|
|
23
|
-
end
|
|
24
|
-
end
|
|
15
|
+
load 'tasks/setup.rb'
|
|
25
16
|
|
|
26
17
|
LIBEXT = case Config::CONFIG['host_os'].downcase
|
|
27
18
|
when /darwin/
|
|
@@ -40,10 +31,16 @@ CPU = case Config::CONFIG['host_cpu'].downcase
|
|
|
40
31
|
else
|
|
41
32
|
"i386"
|
|
42
33
|
end
|
|
34
|
+
|
|
43
35
|
when /amd64|x86_64/
|
|
44
36
|
"x86_64"
|
|
37
|
+
|
|
38
|
+
when /ppc64|powerpc64/
|
|
39
|
+
"powerpc64"
|
|
40
|
+
|
|
45
41
|
when /ppc|powerpc/
|
|
46
42
|
"powerpc"
|
|
43
|
+
|
|
47
44
|
else
|
|
48
45
|
Config::CONFIG['host_cpu']
|
|
49
46
|
end
|
|
@@ -78,7 +75,7 @@ PROJ.name = 'ffi'
|
|
|
78
75
|
PROJ.authors = 'Wayne Meissner'
|
|
79
76
|
PROJ.email = 'wmeissner@gmail.com'
|
|
80
77
|
PROJ.url = 'http://wiki.github.com/ffi/ffi'
|
|
81
|
-
PROJ.version = '0.
|
|
78
|
+
PROJ.version = '0.6.0'
|
|
82
79
|
PROJ.rubyforge.name = 'ffi'
|
|
83
80
|
PROJ.readme_file = 'README.rdoc'
|
|
84
81
|
|
|
@@ -86,7 +83,7 @@ PROJ.readme_file = 'README.rdoc'
|
|
|
86
83
|
PROJ.ann.paragraphs << 'FEATURES' << 'SYNOPSIS' << 'REQUIREMENTS' << 'DOWNLOAD/INSTALL' << 'CREDITS' << 'LICENSE'
|
|
87
84
|
|
|
88
85
|
PROJ.ann.email[:from] = 'andrea.fazzi@alcacoop.it'
|
|
89
|
-
PROJ.ann.email[:to]
|
|
86
|
+
PROJ.ann.email[:to] = ['ruby-ffi@googlegroups.com']
|
|
90
87
|
PROJ.ann.email[:server] = 'smtp.gmail.com'
|
|
91
88
|
|
|
92
89
|
# Gem specifications
|
data/ext/ffi_c/AbstractMemory.c
CHANGED
|
@@ -49,7 +49,6 @@ memory_allocate(VALUE klass)
|
|
|
49
49
|
AbstractMemory* memory;
|
|
50
50
|
VALUE obj;
|
|
51
51
|
obj = Data_Make_Struct(klass, AbstractMemory, NULL, -1, memory);
|
|
52
|
-
memory->ops = &rbffi_AbstractMemoryOps;
|
|
53
52
|
memory->access = MEM_RD | MEM_WR;
|
|
54
53
|
|
|
55
54
|
return obj;
|
|
@@ -137,6 +136,8 @@ NUM_OP(int32, int32_t, NUM2INT, INT2NUM);
|
|
|
137
136
|
NUM_OP(uint32, uint32_t, NUM2UINT, UINT2NUM);
|
|
138
137
|
NUM_OP(int64, int64_t, NUM2LL, LL2NUM);
|
|
139
138
|
NUM_OP(uint64, uint64_t, NUM2ULL, ULL2NUM);
|
|
139
|
+
NUM_OP(long, long, NUM2LONG, LONG2NUM);
|
|
140
|
+
NUM_OP(ulong, unsigned long, NUM2ULONG, ULONG2NUM);
|
|
140
141
|
NUM_OP(float32, float, NUM2DBL, rb_float_new);
|
|
141
142
|
NUM_OP(float64, double, NUM2DBL, rb_float_new);
|
|
142
143
|
|
|
@@ -156,6 +157,7 @@ get_pointer_value(VALUE value)
|
|
|
156
157
|
return MEMORY_PTR(rb_funcall2(value, id_to_ptr, 0, NULL));
|
|
157
158
|
} else {
|
|
158
159
|
rb_raise(rb_eArgError, "value is not a pointer");
|
|
160
|
+
return NULL;
|
|
159
161
|
}
|
|
160
162
|
}
|
|
161
163
|
|
|
@@ -226,7 +228,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
|
|
|
226
228
|
|
|
227
229
|
} else {
|
|
228
230
|
checkBounds(ptr, off, sizeof (char*));
|
|
229
|
-
for ( ; off < ptr->size - sizeof (void *); off += sizeof (void *)) {
|
|
231
|
+
for ( ; off < ptr->size - (long) sizeof (void *); off += (long) sizeof (void *)) {
|
|
230
232
|
const char* strptr = *(const char**) (ptr->address + off);
|
|
231
233
|
if (strptr == NULL) {
|
|
232
234
|
break;
|
|
@@ -253,6 +255,7 @@ memory_put_string(VALUE self, VALUE offset, VALUE str)
|
|
|
253
255
|
|
|
254
256
|
if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) {
|
|
255
257
|
rb_raise(rb_eSecurityError, "Writing unsafe string to memory");
|
|
258
|
+
return Qnil;
|
|
256
259
|
}
|
|
257
260
|
|
|
258
261
|
memcpy(ptr->address + off, RSTRING_PTR(str), len);
|
|
@@ -290,10 +293,12 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
|
|
|
290
293
|
idx = nargs > 2 ? NUM2LONG(rbIndex) : 0;
|
|
291
294
|
if (idx < 0) {
|
|
292
295
|
rb_raise(rb_eRangeError, "index canot be less than zero");
|
|
296
|
+
return Qnil;
|
|
293
297
|
}
|
|
294
298
|
len = nargs > 3 ? NUM2LONG(rbLength) : (RSTRING_LEN(str) - idx);
|
|
295
299
|
if ((idx + len) > RSTRING_LEN(str)) {
|
|
296
300
|
rb_raise(rb_eRangeError, "index+length is greater than size of string");
|
|
301
|
+
return Qnil;
|
|
297
302
|
}
|
|
298
303
|
|
|
299
304
|
checkWrite(ptr);
|
|
@@ -301,6 +306,7 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
|
|
|
301
306
|
|
|
302
307
|
if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) {
|
|
303
308
|
rb_raise(rb_eSecurityError, "Writing unsafe string to memory");
|
|
309
|
+
return Qnil;
|
|
304
310
|
}
|
|
305
311
|
memcpy(ptr->address + off, RSTRING_PTR(str) + idx, len);
|
|
306
312
|
|
|
@@ -395,6 +401,8 @@ MemoryOps rbffi_AbstractMemoryOps = {
|
|
|
395
401
|
.uint32 = &memory_op_uint32,
|
|
396
402
|
.int64 = &memory_op_int64,
|
|
397
403
|
.uint64 = &memory_op_uint64,
|
|
404
|
+
.slong = &memory_op_long,
|
|
405
|
+
.ulong = &memory_op_ulong,
|
|
398
406
|
.float32 = &memory_op_float32,
|
|
399
407
|
.float64 = &memory_op_float64,
|
|
400
408
|
.pointer = &memory_op_pointer,
|
|
@@ -428,6 +436,7 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
428
436
|
INT(int16);
|
|
429
437
|
INT(int32);
|
|
430
438
|
INT(int64);
|
|
439
|
+
INT(long);
|
|
431
440
|
|
|
432
441
|
#define ALIAS(name, old) \
|
|
433
442
|
rb_define_alias(classMemory, "put_" #name, "put_" #old); \
|
|
@@ -444,12 +453,6 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
|
|
|
444
453
|
ALIAS(int, int32);
|
|
445
454
|
ALIAS(long_long, int64);
|
|
446
455
|
|
|
447
|
-
if (sizeof(long) == 4) {
|
|
448
|
-
ALIAS(long, int32);
|
|
449
|
-
} else {
|
|
450
|
-
ALIAS(long, int64);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
456
|
rb_define_method(classMemory, "put_float32", memory_put_float32, 2);
|
|
454
457
|
rb_define_method(classMemory, "get_float32", memory_get_float32, 1);
|
|
455
458
|
rb_define_alias(classMemory, "put_float", "put_float32");
|
data/ext/ffi_c/AbstractMemory.h
CHANGED
|
@@ -61,6 +61,8 @@ typedef struct {
|
|
|
61
61
|
MemoryOp* uint32;
|
|
62
62
|
MemoryOp* int64;
|
|
63
63
|
MemoryOp* uint64;
|
|
64
|
+
MemoryOp* slong;
|
|
65
|
+
MemoryOp* ulong;
|
|
64
66
|
MemoryOp* float32;
|
|
65
67
|
MemoryOp* float64;
|
|
66
68
|
MemoryOp* pointer;
|
|
@@ -72,9 +74,12 @@ struct AbstractMemory_ {
|
|
|
72
74
|
long size;
|
|
73
75
|
int access;
|
|
74
76
|
int typeSize;
|
|
75
|
-
MemoryOps* ops;
|
|
76
77
|
};
|
|
77
78
|
|
|
79
|
+
|
|
80
|
+
extern VALUE rbffi_AbstractMemoryClass;
|
|
81
|
+
extern MemoryOps rbffi_AbstractMemoryOps;
|
|
82
|
+
|
|
78
83
|
extern void rbffi_AbstractMemory_Init(VALUE ffiModule);
|
|
79
84
|
|
|
80
85
|
extern AbstractMemory* rbffi_AbstractMemory_Cast(VALUE obj, VALUE klass);
|
|
@@ -107,36 +112,37 @@ checkWrite(AbstractMemory* mem)
|
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
static inline MemoryOp*
|
|
110
|
-
|
|
115
|
+
get_memory_op(Type* type)
|
|
111
116
|
{
|
|
112
|
-
if (ptr == NULL || ptr->ops == NULL || type == NULL) {
|
|
113
|
-
return NULL;
|
|
114
|
-
}
|
|
115
117
|
switch (type->nativeType) {
|
|
116
118
|
case NATIVE_INT8:
|
|
117
|
-
return
|
|
119
|
+
return rbffi_AbstractMemoryOps.int8;
|
|
118
120
|
case NATIVE_UINT8:
|
|
119
|
-
return
|
|
121
|
+
return rbffi_AbstractMemoryOps.uint8;
|
|
120
122
|
case NATIVE_INT16:
|
|
121
|
-
return
|
|
123
|
+
return rbffi_AbstractMemoryOps.int16;
|
|
122
124
|
case NATIVE_UINT16:
|
|
123
|
-
return
|
|
125
|
+
return rbffi_AbstractMemoryOps.uint16;
|
|
124
126
|
case NATIVE_INT32:
|
|
125
|
-
return
|
|
127
|
+
return rbffi_AbstractMemoryOps.int32;
|
|
126
128
|
case NATIVE_UINT32:
|
|
127
|
-
return
|
|
129
|
+
return rbffi_AbstractMemoryOps.uint32;
|
|
128
130
|
case NATIVE_INT64:
|
|
129
|
-
return
|
|
131
|
+
return rbffi_AbstractMemoryOps.int64;
|
|
130
132
|
case NATIVE_UINT64:
|
|
131
|
-
return
|
|
133
|
+
return rbffi_AbstractMemoryOps.uint64;
|
|
134
|
+
case NATIVE_LONG:
|
|
135
|
+
return rbffi_AbstractMemoryOps.slong;
|
|
136
|
+
case NATIVE_ULONG:
|
|
137
|
+
return rbffi_AbstractMemoryOps.ulong;
|
|
132
138
|
case NATIVE_FLOAT32:
|
|
133
|
-
return
|
|
139
|
+
return rbffi_AbstractMemoryOps.float32;
|
|
134
140
|
case NATIVE_FLOAT64:
|
|
135
|
-
return
|
|
141
|
+
return rbffi_AbstractMemoryOps.float64;
|
|
136
142
|
case NATIVE_POINTER:
|
|
137
|
-
return
|
|
143
|
+
return rbffi_AbstractMemoryOps.pointer;
|
|
138
144
|
case NATIVE_STRING:
|
|
139
|
-
return
|
|
145
|
+
return rbffi_AbstractMemoryOps.strptr;
|
|
140
146
|
default:
|
|
141
147
|
return NULL;
|
|
142
148
|
}
|
|
@@ -148,10 +154,6 @@ memory_get_op(AbstractMemory* ptr, Type* type)
|
|
|
148
154
|
|
|
149
155
|
|
|
150
156
|
|
|
151
|
-
extern VALUE rbffi_AbstractMemoryClass;
|
|
152
|
-
extern MemoryOps rbffi_AbstractMemoryOps;
|
|
153
|
-
|
|
154
|
-
|
|
155
157
|
#ifdef __cplusplus
|
|
156
158
|
}
|
|
157
159
|
#endif
|
data/ext/ffi_c/AutoPointer.c
CHANGED
data/ext/ffi_c/Buffer.c
CHANGED
|
@@ -54,7 +54,6 @@ buffer_allocate(VALUE klass)
|
|
|
54
54
|
|
|
55
55
|
obj = Data_Make_Struct(klass, Buffer, NULL, buffer_release, buffer);
|
|
56
56
|
buffer->rbParent = Qnil;
|
|
57
|
-
buffer->memory.ops = &rbffi_AbstractMemoryOps;
|
|
58
57
|
buffer->memory.access = MEM_RD | MEM_WR;
|
|
59
58
|
|
|
60
59
|
return obj;
|
|
@@ -87,6 +86,7 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
|
|
|
87
86
|
p->storage = xmalloc(p->memory.size + 7);
|
|
88
87
|
if (p->storage == NULL) {
|
|
89
88
|
rb_raise(rb_eNoMemError, "Failed to allocate memory size=%lu bytes", p->memory.size);
|
|
89
|
+
return Qnil;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/* ensure the memory is aligned on at least a 8 byte boundary */
|
|
@@ -110,20 +110,18 @@ buffer_alloc_inout(int argc, VALUE* argv, VALUE klass)
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
static VALUE
|
|
113
|
-
|
|
113
|
+
slice(VALUE self, long offset, long len)
|
|
114
114
|
{
|
|
115
115
|
Buffer* ptr;
|
|
116
116
|
Buffer* result;
|
|
117
117
|
VALUE obj = Qnil;
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
|
|
120
119
|
Data_Get_Struct(self, Buffer, ptr);
|
|
121
|
-
checkBounds(&ptr->memory, offset,
|
|
120
|
+
checkBounds(&ptr->memory, offset, len);
|
|
122
121
|
|
|
123
122
|
obj = Data_Make_Struct(BufferClass, Buffer, buffer_mark, -1, result);
|
|
124
123
|
result->memory.address = ptr->memory.address + offset;
|
|
125
|
-
result->memory.size =
|
|
126
|
-
result->memory.ops = ptr->memory.ops;
|
|
124
|
+
result->memory.size = len;
|
|
127
125
|
result->memory.access = ptr->memory.access;
|
|
128
126
|
result->memory.typeSize = ptr->memory.typeSize;
|
|
129
127
|
result->rbParent = self;
|
|
@@ -131,6 +129,23 @@ buffer_plus(VALUE self, VALUE rbOffset)
|
|
|
131
129
|
return obj;
|
|
132
130
|
}
|
|
133
131
|
|
|
132
|
+
static VALUE
|
|
133
|
+
buffer_plus(VALUE self, VALUE rbOffset)
|
|
134
|
+
{
|
|
135
|
+
Buffer* ptr;
|
|
136
|
+
long offset = NUM2LONG(rbOffset);
|
|
137
|
+
|
|
138
|
+
Data_Get_Struct(self, Buffer, ptr);
|
|
139
|
+
|
|
140
|
+
return slice(self, offset, ptr->memory.size - offset);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static VALUE
|
|
144
|
+
buffer_slice(VALUE self, VALUE rbOffset, VALUE rbLength)
|
|
145
|
+
{
|
|
146
|
+
return slice(self, NUM2LONG(rbOffset), NUM2LONG(rbLength));
|
|
147
|
+
}
|
|
148
|
+
|
|
134
149
|
static VALUE
|
|
135
150
|
buffer_inspect(VALUE self)
|
|
136
151
|
{
|
|
@@ -152,7 +167,7 @@ buffer_free(VALUE self)
|
|
|
152
167
|
|
|
153
168
|
Data_Get_Struct(self, Buffer, ptr);
|
|
154
169
|
if (ptr->storage != NULL) {
|
|
155
|
-
|
|
170
|
+
xfree(ptr->storage);
|
|
156
171
|
ptr->storage = NULL;
|
|
157
172
|
}
|
|
158
173
|
|
|
@@ -184,4 +199,5 @@ rbffi_Buffer_Init(VALUE moduleFFI)
|
|
|
184
199
|
rb_define_method(BufferClass, "inspect", buffer_inspect, 0);
|
|
185
200
|
rb_define_alias(BufferClass, "length", "total");
|
|
186
201
|
rb_define_method(BufferClass, "+", buffer_plus, 1);
|
|
202
|
+
rb_define_method(BufferClass, "slice", buffer_slice, 2);
|
|
187
203
|
}
|
data/ext/ffi_c/Call.c
CHANGED
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
#define INT16_ADJ (4)
|
|
61
61
|
#define INT32_ADJ (4)
|
|
62
62
|
#define INT64_ADJ (8)
|
|
63
|
+
#define LONG_ADJ (sizeof(long))
|
|
63
64
|
#define FLOAT32_ADJ (4)
|
|
64
65
|
#define FLOAT64_ADJ (8)
|
|
65
66
|
#define ADDRESS_ADJ (sizeof(void *))
|
|
@@ -186,6 +187,17 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, NativeType* paramTy
|
|
|
186
187
|
++argidx;
|
|
187
188
|
break;
|
|
188
189
|
|
|
190
|
+
case NATIVE_LONG:
|
|
191
|
+
*(ffi_sarg *) param = NUM2LONG(argv[argidx]);
|
|
192
|
+
ADJ(param, LONG);
|
|
193
|
+
++argidx;
|
|
194
|
+
break;
|
|
195
|
+
|
|
196
|
+
case NATIVE_ULONG:
|
|
197
|
+
*(ffi_arg *) param = NUM2ULONG(argv[argidx]);
|
|
198
|
+
ADJ(param, LONG);
|
|
199
|
+
++argidx;
|
|
200
|
+
break;
|
|
189
201
|
|
|
190
202
|
case NATIVE_FLOAT32:
|
|
191
203
|
if (type != T_FLOAT && type != T_FIXNUM) {
|
|
@@ -431,6 +443,8 @@ rbffi_GetInvoker(FunctionType *fnInfo)
|
|
|
431
443
|
case NATIVE_UINT16:
|
|
432
444
|
case NATIVE_INT32:
|
|
433
445
|
case NATIVE_UINT32:
|
|
446
|
+
case NATIVE_LONG:
|
|
447
|
+
case NATIVE_ULONG:
|
|
434
448
|
#ifdef __x86_64__
|
|
435
449
|
case NATIVE_INT64:
|
|
436
450
|
case NATIVE_UINT64:
|
|
@@ -452,6 +466,8 @@ rbffi_GetInvoker(FunctionType *fnInfo)
|
|
|
452
466
|
case NATIVE_UINT16:
|
|
453
467
|
case NATIVE_INT32:
|
|
454
468
|
case NATIVE_UINT32:
|
|
469
|
+
case NATIVE_LONG:
|
|
470
|
+
case NATIVE_ULONG:
|
|
455
471
|
#ifdef __x86_64__
|
|
456
472
|
case NATIVE_INT64:
|
|
457
473
|
case NATIVE_UINT64:
|
|
@@ -536,6 +552,12 @@ rbffi_GetLongValue(int idx, VALUE* argv, FunctionType* fnInfo)
|
|
|
536
552
|
/* Special handling/checking for unsigned 32 bit integers */
|
|
537
553
|
return getUnsignedInt32(value, type);
|
|
538
554
|
|
|
555
|
+
case NATIVE_LONG:
|
|
556
|
+
return NUM2LONG(value);
|
|
557
|
+
|
|
558
|
+
case NATIVE_ULONG:
|
|
559
|
+
return NUM2ULONG(value);
|
|
560
|
+
|
|
539
561
|
#ifdef __x86_64__
|
|
540
562
|
case NATIVE_INT64:
|
|
541
563
|
if (type != T_FIXNUM && type != T_BIGNUM) {
|
|
@@ -609,6 +631,9 @@ returnL(FunctionType* fnInfo, L* result)
|
|
|
609
631
|
case NATIVE_INT32:
|
|
610
632
|
return INT2NUM(*(signed int *) result);
|
|
611
633
|
|
|
634
|
+
case NATIVE_LONG:
|
|
635
|
+
return LONG2NUM(*(signed long *) result);
|
|
636
|
+
|
|
612
637
|
case NATIVE_UINT8:
|
|
613
638
|
return UINT2NUM(*(unsigned char *) result);
|
|
614
639
|
|
|
@@ -618,6 +643,9 @@ returnL(FunctionType* fnInfo, L* result)
|
|
|
618
643
|
case NATIVE_UINT32:
|
|
619
644
|
return UINT2NUM(*(unsigned int *) result);
|
|
620
645
|
|
|
646
|
+
case NATIVE_ULONG:
|
|
647
|
+
return ULONG2NUM(*(unsigned long *) result);
|
|
648
|
+
|
|
621
649
|
#ifdef __x86_64__
|
|
622
650
|
case NATIVE_INT64:
|
|
623
651
|
return LL2NUM(*(signed long long *) result);
|
data/ext/ffi_c/Call.h
CHANGED
|
@@ -28,14 +28,16 @@
|
|
|
28
28
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
#ifndef
|
|
32
|
-
#define
|
|
31
|
+
#ifndef RBFFI_INVOKE_H
|
|
32
|
+
#define RBFFI_INVOKE_H
|
|
33
33
|
|
|
34
34
|
#ifdef __cplusplus
|
|
35
35
|
extern "C" {
|
|
36
36
|
#endif
|
|
37
37
|
|
|
38
|
-
#if defined(__i386__) &&
|
|
38
|
+
#if defined(__i386__) && \
|
|
39
|
+
(defined(HAVE_RAW_API) || defined(USE_INTERNAL_LIBFFI)) && \
|
|
40
|
+
!defined(_WIN32) && !defined(__WIN32__)
|
|
39
41
|
# define USE_RAW
|
|
40
42
|
#endif
|
|
41
43
|
|
|
@@ -57,6 +59,8 @@ typedef union {
|
|
|
57
59
|
#endif
|
|
58
60
|
signed long long i64;
|
|
59
61
|
unsigned long long u64;
|
|
62
|
+
signed long sl;
|
|
63
|
+
unsigned long ul;
|
|
60
64
|
void* ptr;
|
|
61
65
|
float f32;
|
|
62
66
|
double f64;
|
|
@@ -82,5 +86,5 @@ extern int rbffi_GetSignedIntValue(VALUE value, int type, int minValue, int maxV
|
|
|
82
86
|
}
|
|
83
87
|
#endif
|
|
84
88
|
|
|
85
|
-
#endif /*
|
|
89
|
+
#endif /* RBFFI_INVOKE_H */
|
|
86
90
|
|
data/ext/ffi_c/ClosurePool.c
CHANGED
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
#include <stdbool.h>
|
|
36
36
|
#ifndef _WIN32
|
|
37
37
|
# include <unistd.h>
|
|
38
|
+
#else
|
|
39
|
+
# include <windows.h>
|
|
38
40
|
#endif
|
|
39
41
|
#include <errno.h>
|
|
40
42
|
#include <ruby.h>
|
|
@@ -111,7 +113,7 @@ rbffi_ClosurePool_New(int closureSize,
|
|
|
111
113
|
pool->prep = prep;
|
|
112
114
|
pool->refcnt = 1;
|
|
113
115
|
|
|
114
|
-
#if defined(HAVE_NATIVETHREAD) && !defined(_WIN32)
|
|
116
|
+
#if defined(HAVE_NATIVETHREAD) && !defined(_WIN32)
|
|
115
117
|
pthread_mutex_init(&pool->mutex, NULL);
|
|
116
118
|
#endif
|
|
117
119
|
|
|
@@ -253,7 +255,7 @@ rbffi_Closure_CodeAddress(Closure* handle)
|
|
|
253
255
|
static int
|
|
254
256
|
getPageSize()
|
|
255
257
|
{
|
|
256
|
-
#
|
|
258
|
+
#if defined(_WIN32) || defined(__WIN32__)
|
|
257
259
|
SYSTEM_INFO si;
|
|
258
260
|
GetSystemInfo(&si);
|
|
259
261
|
return si.dwPageSize;
|
|
@@ -265,7 +267,7 @@ getPageSize()
|
|
|
265
267
|
static void*
|
|
266
268
|
allocatePage(void)
|
|
267
269
|
{
|
|
268
|
-
#
|
|
270
|
+
#if defined(_WIN32) || defined(__WIN32__)
|
|
269
271
|
return VirtualAlloc(NULL, pageSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
|
270
272
|
#else
|
|
271
273
|
caddr_t page = mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
|
@@ -276,7 +278,7 @@ allocatePage(void)
|
|
|
276
278
|
static bool
|
|
277
279
|
freePage(void *addr)
|
|
278
280
|
{
|
|
279
|
-
#
|
|
281
|
+
#if defined(_WIN32) || defined(__WIN32__)
|
|
280
282
|
return VirtualFree(addr, 0, MEM_RELEASE);
|
|
281
283
|
#else
|
|
282
284
|
return munmap(addr, pageSize) == 0;
|
|
@@ -286,7 +288,7 @@ freePage(void *addr)
|
|
|
286
288
|
static bool
|
|
287
289
|
protectPage(void* page)
|
|
288
290
|
{
|
|
289
|
-
#
|
|
291
|
+
#if defined(_WIN32) || defined(__WIN32__)
|
|
290
292
|
DWORD oldProtect;
|
|
291
293
|
return VirtualProtect(page, pageSize, PAGE_EXECUTE_READ, &oldProtect);
|
|
292
294
|
#else
|
data/ext/ffi_c/DynamicLibrary.c
CHANGED
|
@@ -157,7 +157,6 @@ symbol_new(VALUE library, void* address, VALUE name)
|
|
|
157
157
|
sym->memory.size = LONG_MAX;
|
|
158
158
|
sym->memory.typeSize = 1;
|
|
159
159
|
sym->memory.access = MEM_RD | MEM_WR;
|
|
160
|
-
sym->memory.ops = &rbffi_AbstractMemoryOps;
|
|
161
160
|
sym->library = library;
|
|
162
161
|
sym->name = name;
|
|
163
162
|
|
data/ext/ffi_c/Function.c
CHANGED
|
@@ -81,7 +81,6 @@ function_allocate(VALUE klass)
|
|
|
81
81
|
obj = Data_Make_Struct(klass, Function, function_mark, function_free, fn);
|
|
82
82
|
|
|
83
83
|
fn->memory.access = MEM_RD;
|
|
84
|
-
fn->memory.ops = &rbffi_AbstractMemoryOps;
|
|
85
84
|
|
|
86
85
|
fn->rbProc = Qnil;
|
|
87
86
|
fn->rbFunctionInfo = Qnil;
|
|
@@ -250,7 +249,13 @@ function_attach(VALUE self, VALUE module, VALUE name)
|
|
|
250
249
|
Data_Get_Struct(self, Function, fn);
|
|
251
250
|
|
|
252
251
|
if (fn->info->parameterCount == -1) {
|
|
253
|
-
rb_raise(rb_eRuntimeError, "
|
|
252
|
+
rb_raise(rb_eRuntimeError, "cannot attach variadic functions");
|
|
253
|
+
return Qnil;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (!rb_obj_is_kind_of(module, rb_cModule)) {
|
|
257
|
+
rb_raise(rb_eRuntimeError, "trying to attach function to non-module");
|
|
258
|
+
return Qnil;
|
|
254
259
|
}
|
|
255
260
|
|
|
256
261
|
if (fn->methodHandle == NULL) {
|
|
@@ -350,6 +355,12 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
|
350
355
|
case NATIVE_UINT64:
|
|
351
356
|
param = ULL2NUM(*(uint64_t *) parameters[i]);
|
|
352
357
|
break;
|
|
358
|
+
case NATIVE_LONG:
|
|
359
|
+
param = LONG2NUM(*(long *) parameters[i]);
|
|
360
|
+
break;
|
|
361
|
+
case NATIVE_ULONG:
|
|
362
|
+
param = ULONG2NUM(*(unsigned long *) parameters[i]);
|
|
363
|
+
break;
|
|
353
364
|
case NATIVE_FLOAT32:
|
|
354
365
|
param = rb_float_new(*(float *) parameters[i]);
|
|
355
366
|
break;
|
|
@@ -397,6 +408,12 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
|
|
|
397
408
|
case NATIVE_UINT64:
|
|
398
409
|
*((uint64_t *) retval) = NUM2ULL(rbReturnValue);
|
|
399
410
|
break;
|
|
411
|
+
case NATIVE_LONG:
|
|
412
|
+
*((ffi_sarg *) retval) = NUM2LONG(rbReturnValue);
|
|
413
|
+
break;
|
|
414
|
+
case NATIVE_ULONG:
|
|
415
|
+
*((ffi_arg *) retval) = NUM2ULONG(rbReturnValue);
|
|
416
|
+
break;
|
|
400
417
|
case NATIVE_FLOAT32:
|
|
401
418
|
*((float *) retval) = (float) NUM2DBL(rbReturnValue);
|
|
402
419
|
break;
|
data/ext/ffi_c/MemoryPointer.c
CHANGED
|
@@ -63,7 +63,6 @@ memptr_allocate(VALUE klass)
|
|
|
63
63
|
{
|
|
64
64
|
MemoryPointer* p;
|
|
65
65
|
VALUE obj = Data_Make_Struct(klass, MemoryPointer, NULL, memptr_release, p);
|
|
66
|
-
p->memory.ops = &rbffi_AbstractMemoryOps;
|
|
67
66
|
p->memory.access = MEM_RD | MEM_WR;
|
|
68
67
|
|
|
69
68
|
return obj;
|
|
@@ -98,6 +97,7 @@ memptr_malloc(VALUE self, long size, long count, bool clear)
|
|
|
98
97
|
p->storage = xmalloc(msize + 7);
|
|
99
98
|
if (p->storage == NULL) {
|
|
100
99
|
rb_raise(rb_eNoMemError, "Failed to allocate memory size=%ld bytes", msize);
|
|
100
|
+
return Qnil;
|
|
101
101
|
}
|
|
102
102
|
p->autorelease = true;
|
|
103
103
|
p->memory.typeSize = size;
|
|
@@ -105,7 +105,7 @@ memptr_malloc(VALUE self, long size, long count, bool clear)
|
|
|
105
105
|
/* ensure the memory is aligned on at least a 8 byte boundary */
|
|
106
106
|
p->memory.address = (char *) (((uintptr_t) p->storage + 0x7) & (uintptr_t) ~0x7UL);;
|
|
107
107
|
p->allocated = true;
|
|
108
|
-
|
|
108
|
+
|
|
109
109
|
if (clear && p->memory.size > 0) {
|
|
110
110
|
memset(p->memory.address, 0, p->memory.size);
|
|
111
111
|
}
|
|
@@ -134,7 +134,7 @@ memptr_free(VALUE self)
|
|
|
134
134
|
|
|
135
135
|
if (ptr->allocated) {
|
|
136
136
|
if (ptr->storage != NULL) {
|
|
137
|
-
|
|
137
|
+
xfree(ptr->storage);
|
|
138
138
|
ptr->storage = NULL;
|
|
139
139
|
}
|
|
140
140
|
ptr->allocated = false;
|
data/ext/ffi_c/MethodHandle.c
CHANGED
|
@@ -175,7 +175,7 @@ attached_method_invoke(ffi_cif* cif, void* mretval, METHOD_PARAMS parameters, vo
|
|
|
175
175
|
int argc = parameters[0].sint;
|
|
176
176
|
VALUE* argv = *(VALUE **) ¶meters[1];
|
|
177
177
|
#else
|
|
178
|
-
int argc = *(
|
|
178
|
+
int argc = *(int *) parameters[0];
|
|
179
179
|
VALUE* argv = *(VALUE **) parameters[1];
|
|
180
180
|
#endif
|
|
181
181
|
|