ffi 0.1.0
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/LICENSE +51 -0
- data/README +0 -0
- data/Rakefile +90 -0
- data/ext/AbstractMemory.c +254 -0
- data/ext/AbstractMemory.h +36 -0
- data/ext/Buffer.c +94 -0
- data/ext/Callback.c +240 -0
- data/ext/Callback.h +47 -0
- data/ext/Invoker.c +269 -0
- data/ext/MemoryPointer.c +164 -0
- data/ext/MemoryPointer.h +25 -0
- data/ext/Platform.c +41 -0
- data/ext/Platform.h +23 -0
- data/ext/Types.c +65 -0
- data/ext/Types.h +51 -0
- data/ext/extconf.rb +13 -0
- data/ext/ffi.c +54 -0
- data/ext/ffi.mk +24 -0
- data/ext/libffi.darwin.mk +44 -0
- data/ext/libffi.mk +10 -0
- data/ext/libffi/ChangeLog +3243 -0
- data/ext/libffi/ChangeLog.libffi +347 -0
- data/ext/libffi/ChangeLog.libgcj +40 -0
- data/ext/libffi/ChangeLog.v1 +764 -0
- data/ext/libffi/LICENSE +21 -0
- data/ext/libffi/Makefile.am +177 -0
- data/ext/libffi/Makefile.in +1640 -0
- data/ext/libffi/README +328 -0
- data/ext/libffi/TODO +1 -0
- data/ext/libffi/acinclude.m4 +92 -0
- data/ext/libffi/aclocal.m4 +7516 -0
- data/ext/libffi/compile +142 -0
- data/ext/libffi/config.guess +1516 -0
- data/ext/libffi/config.sub +1626 -0
- data/ext/libffi/configure +24414 -0
- data/ext/libffi/configure.ac +365 -0
- data/ext/libffi/configure.host +11 -0
- data/ext/libffi/depcomp +584 -0
- data/ext/libffi/doc/libffi.info +533 -0
- data/ext/libffi/doc/libffi.texi +541 -0
- data/ext/libffi/doc/stamp-vti +4 -0
- data/ext/libffi/doc/version.texi +4 -0
- data/ext/libffi/fficonfig.h.in +160 -0
- data/ext/libffi/include/Makefile.am +9 -0
- data/ext/libffi/include/Makefile.in +422 -0
- data/ext/libffi/include/ffi.h.in +393 -0
- data/ext/libffi/include/ffi_common.h +98 -0
- data/ext/libffi/install-sh +323 -0
- data/ext/libffi/libffi.pc.in +10 -0
- data/ext/libffi/libtool-version +29 -0
- data/ext/libffi/ltcf-c.sh +861 -0
- data/ext/libffi/ltcf-cxx.sh +1069 -0
- data/ext/libffi/ltcf-gcj.sh +700 -0
- data/ext/libffi/ltconfig +2862 -0
- data/ext/libffi/ltmain.sh +6930 -0
- data/ext/libffi/man/Makefile.am +8 -0
- data/ext/libffi/man/Makefile.in +395 -0
- data/ext/libffi/man/ffi.3 +31 -0
- data/ext/libffi/man/ffi_call.3 +103 -0
- data/ext/libffi/man/ffi_prep_cif.3 +66 -0
- data/ext/libffi/mdate-sh +201 -0
- data/ext/libffi/missing +353 -0
- data/ext/libffi/mkinstalldirs +158 -0
- data/ext/libffi/src/alpha/ffi.c +284 -0
- data/ext/libffi/src/alpha/ffitarget.h +48 -0
- data/ext/libffi/src/alpha/osf.S +366 -0
- data/ext/libffi/src/arm/ffi.c +309 -0
- data/ext/libffi/src/arm/ffitarget.h +49 -0
- data/ext/libffi/src/arm/sysv.S +299 -0
- data/ext/libffi/src/closures.c +596 -0
- data/ext/libffi/src/cris/ffi.c +383 -0
- data/ext/libffi/src/cris/ffitarget.h +51 -0
- data/ext/libffi/src/cris/sysv.S +215 -0
- data/ext/libffi/src/debug.c +59 -0
- data/ext/libffi/src/dlmalloc.c +5099 -0
- data/ext/libffi/src/frv/eabi.S +128 -0
- data/ext/libffi/src/frv/ffi.c +292 -0
- data/ext/libffi/src/frv/ffitarget.h +61 -0
- data/ext/libffi/src/ia64/ffi.c +580 -0
- data/ext/libffi/src/ia64/ffitarget.h +50 -0
- data/ext/libffi/src/ia64/ia64_flags.h +40 -0
- data/ext/libffi/src/ia64/unix.S +560 -0
- data/ext/libffi/src/java_raw_api.c +359 -0
- data/ext/libffi/src/m32r/ffi.c +232 -0
- data/ext/libffi/src/m32r/ffitarget.h +48 -0
- data/ext/libffi/src/m32r/sysv.S +121 -0
- data/ext/libffi/src/m68k/ffi.c +278 -0
- data/ext/libffi/src/m68k/ffitarget.h +49 -0
- data/ext/libffi/src/m68k/sysv.S +234 -0
- data/ext/libffi/src/mips/ffi.c +926 -0
- data/ext/libffi/src/mips/ffitarget.h +202 -0
- data/ext/libffi/src/mips/n32.S +534 -0
- data/ext/libffi/src/mips/o32.S +381 -0
- data/ext/libffi/src/pa/ffi.c +709 -0
- data/ext/libffi/src/pa/ffitarget.h +77 -0
- data/ext/libffi/src/pa/hpux32.S +368 -0
- data/ext/libffi/src/pa/linux.S +357 -0
- data/ext/libffi/src/powerpc/aix.S +225 -0
- data/ext/libffi/src/powerpc/aix_closure.S +247 -0
- data/ext/libffi/src/powerpc/asm.h +125 -0
- data/ext/libffi/src/powerpc/darwin.S +245 -0
- data/ext/libffi/src/powerpc/darwin_closure.S +317 -0
- data/ext/libffi/src/powerpc/ffi.c +1429 -0
- data/ext/libffi/src/powerpc/ffi_darwin.c +800 -0
- data/ext/libffi/src/powerpc/ffitarget.h +118 -0
- data/ext/libffi/src/powerpc/linux64.S +187 -0
- data/ext/libffi/src/powerpc/linux64_closure.S +236 -0
- data/ext/libffi/src/powerpc/ppc_closure.S +327 -0
- data/ext/libffi/src/powerpc/sysv.S +230 -0
- data/ext/libffi/src/prep_cif.c +174 -0
- data/ext/libffi/src/raw_api.c +254 -0
- data/ext/libffi/src/s390/ffi.c +780 -0
- data/ext/libffi/src/s390/ffitarget.h +60 -0
- data/ext/libffi/src/s390/sysv.S +434 -0
- data/ext/libffi/src/sh/ffi.c +716 -0
- data/ext/libffi/src/sh/ffitarget.h +49 -0
- data/ext/libffi/src/sh/sysv.S +850 -0
- data/ext/libffi/src/sh64/ffi.c +453 -0
- data/ext/libffi/src/sh64/ffitarget.h +53 -0
- data/ext/libffi/src/sh64/sysv.S +530 -0
- data/ext/libffi/src/sparc/ffi.c +610 -0
- data/ext/libffi/src/sparc/ffitarget.h +66 -0
- data/ext/libffi/src/sparc/v8.S +272 -0
- data/ext/libffi/src/sparc/v9.S +307 -0
- data/ext/libffi/src/types.c +77 -0
- data/ext/libffi/src/x86/darwin.S +443 -0
- data/ext/libffi/src/x86/darwin64.S +416 -0
- data/ext/libffi/src/x86/ffi.c +475 -0
- data/ext/libffi/src/x86/ffi64.c +572 -0
- data/ext/libffi/src/x86/ffitarget.h +90 -0
- data/ext/libffi/src/x86/freebsd.S +458 -0
- data/ext/libffi/src/x86/sysv.S +437 -0
- data/ext/libffi/src/x86/unix64.S +418 -0
- data/ext/libffi/src/x86/win32.S +391 -0
- data/ext/libffi/testsuite/Makefile.am +71 -0
- data/ext/libffi/testsuite/Makefile.in +447 -0
- data/ext/libffi/testsuite/config/default.exp +1 -0
- data/ext/libffi/testsuite/lib/libffi-dg.exp +289 -0
- data/ext/libffi/testsuite/lib/target-libpath.exp +263 -0
- data/ext/libffi/testsuite/lib/wrapper.exp +45 -0
- data/ext/libffi/testsuite/libffi.call/call.exp +36 -0
- data/ext/libffi/testsuite/libffi.call/closure_fn0.c +97 -0
- data/ext/libffi/testsuite/libffi.call/closure_fn1.c +89 -0
- data/ext/libffi/testsuite/libffi.call/closure_fn2.c +89 -0
- data/ext/libffi/testsuite/libffi.call/closure_fn3.c +90 -0
- data/ext/libffi/testsuite/libffi.call/closure_fn4.c +97 -0
- data/ext/libffi/testsuite/libffi.call/closure_fn5.c +99 -0
- data/ext/libffi/testsuite/libffi.call/closure_fn6.c +98 -0
- data/ext/libffi/testsuite/libffi.call/closure_stdcall.c +72 -0
- data/ext/libffi/testsuite/libffi.call/cls_12byte.c +102 -0
- data/ext/libffi/testsuite/libffi.call/cls_16byte.c +103 -0
- data/ext/libffi/testsuite/libffi.call/cls_18byte.c +104 -0
- data/ext/libffi/testsuite/libffi.call/cls_19byte.c +110 -0
- data/ext/libffi/testsuite/libffi.call/cls_1_1byte.c +97 -0
- data/ext/libffi/testsuite/libffi.call/cls_20byte.c +99 -0
- data/ext/libffi/testsuite/libffi.call/cls_20byte1.c +101 -0
- data/ext/libffi/testsuite/libffi.call/cls_24byte.c +121 -0
- data/ext/libffi/testsuite/libffi.call/cls_2byte.c +98 -0
- data/ext/libffi/testsuite/libffi.call/cls_3_1byte.c +103 -0
- data/ext/libffi/testsuite/libffi.call/cls_3byte1.c +98 -0
- data/ext/libffi/testsuite/libffi.call/cls_3byte2.c +98 -0
- data/ext/libffi/testsuite/libffi.call/cls_4_1byte.c +106 -0
- data/ext/libffi/testsuite/libffi.call/cls_4byte.c +98 -0
- data/ext/libffi/testsuite/libffi.call/cls_5_1_byte.c +117 -0
- data/ext/libffi/testsuite/libffi.call/cls_5byte.c +106 -0
- data/ext/libffi/testsuite/libffi.call/cls_64byte.c +132 -0
- data/ext/libffi/testsuite/libffi.call/cls_6_1_byte.c +121 -0
- data/ext/libffi/testsuite/libffi.call/cls_6byte.c +107 -0
- data/ext/libffi/testsuite/libffi.call/cls_7_1_byte.c +125 -0
- data/ext/libffi/testsuite/libffi.call/cls_7byte.c +105 -0
- data/ext/libffi/testsuite/libffi.call/cls_8byte.c +96 -0
- data/ext/libffi/testsuite/libffi.call/cls_9byte1.c +98 -0
- data/ext/libffi/testsuite/libffi.call/cls_9byte2.c +99 -0
- data/ext/libffi/testsuite/libffi.call/cls_align_double.c +101 -0
- data/ext/libffi/testsuite/libffi.call/cls_align_float.c +99 -0
- data/ext/libffi/testsuite/libffi.call/cls_align_longdouble.c +100 -0
- data/ext/libffi/testsuite/libffi.call/cls_align_pointer.c +101 -0
- data/ext/libffi/testsuite/libffi.call/cls_align_sint16.c +99 -0
- data/ext/libffi/testsuite/libffi.call/cls_align_sint32.c +99 -0
- data/ext/libffi/testsuite/libffi.call/cls_align_sint64.c +99 -0
- data/ext/libffi/testsuite/libffi.call/cls_align_uint16.c +99 -0
- data/ext/libffi/testsuite/libffi.call/cls_align_uint32.c +99 -0
- data/ext/libffi/testsuite/libffi.call/cls_align_uint64.c +100 -0
- data/ext/libffi/testsuite/libffi.call/cls_double.c +51 -0
- data/ext/libffi/testsuite/libffi.call/cls_float.c +51 -0
- data/ext/libffi/testsuite/libffi.call/cls_multi_schar.c +82 -0
- data/ext/libffi/testsuite/libffi.call/cls_multi_sshort.c +82 -0
- data/ext/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +94 -0
- data/ext/libffi/testsuite/libffi.call/cls_multi_uchar.c +99 -0
- data/ext/libffi/testsuite/libffi.call/cls_multi_ushort.c +82 -0
- data/ext/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +94 -0
- data/ext/libffi/testsuite/libffi.call/cls_schar.c +52 -0
- data/ext/libffi/testsuite/libffi.call/cls_sint.c +50 -0
- data/ext/libffi/testsuite/libffi.call/cls_sshort.c +50 -0
- data/ext/libffi/testsuite/libffi.call/cls_uchar.c +50 -0
- data/ext/libffi/testsuite/libffi.call/cls_uint.c +51 -0
- data/ext/libffi/testsuite/libffi.call/cls_ulonglong.c +54 -0
- data/ext/libffi/testsuite/libffi.call/cls_ushort.c +51 -0
- data/ext/libffi/testsuite/libffi.call/ffitest.h +86 -0
- data/ext/libffi/testsuite/libffi.call/float.c +59 -0
- data/ext/libffi/testsuite/libffi.call/float1.c +58 -0
- data/ext/libffi/testsuite/libffi.call/float2.c +57 -0
- data/ext/libffi/testsuite/libffi.call/float3.c +72 -0
- data/ext/libffi/testsuite/libffi.call/float4.c +62 -0
- data/ext/libffi/testsuite/libffi.call/many.c +69 -0
- data/ext/libffi/testsuite/libffi.call/many_win32.c +63 -0
- data/ext/libffi/testsuite/libffi.call/negint.c +53 -0
- data/ext/libffi/testsuite/libffi.call/nested_struct.c +160 -0
- data/ext/libffi/testsuite/libffi.call/nested_struct1.c +169 -0
- data/ext/libffi/testsuite/libffi.call/nested_struct10.c +141 -0
- data/ext/libffi/testsuite/libffi.call/nested_struct2.c +118 -0
- data/ext/libffi/testsuite/libffi.call/nested_struct3.c +119 -0
- data/ext/libffi/testsuite/libffi.call/nested_struct4.c +119 -0
- data/ext/libffi/testsuite/libffi.call/nested_struct5.c +120 -0
- data/ext/libffi/testsuite/libffi.call/nested_struct6.c +139 -0
- data/ext/libffi/testsuite/libffi.call/nested_struct7.c +119 -0
- data/ext/libffi/testsuite/libffi.call/nested_struct8.c +139 -0
- data/ext/libffi/testsuite/libffi.call/nested_struct9.c +139 -0
- data/ext/libffi/testsuite/libffi.call/problem1.c +98 -0
- data/ext/libffi/testsuite/libffi.call/promotion.c +59 -0
- data/ext/libffi/testsuite/libffi.call/pyobjc-tc.c +114 -0
- data/ext/libffi/testsuite/libffi.call/return_dbl.c +35 -0
- data/ext/libffi/testsuite/libffi.call/return_dbl1.c +43 -0
- data/ext/libffi/testsuite/libffi.call/return_dbl2.c +42 -0
- data/ext/libffi/testsuite/libffi.call/return_fl.c +35 -0
- data/ext/libffi/testsuite/libffi.call/return_fl1.c +36 -0
- data/ext/libffi/testsuite/libffi.call/return_fl2.c +49 -0
- data/ext/libffi/testsuite/libffi.call/return_fl3.c +42 -0
- data/ext/libffi/testsuite/libffi.call/return_ldl.c +34 -0
- data/ext/libffi/testsuite/libffi.call/return_ll.c +41 -0
- data/ext/libffi/testsuite/libffi.call/return_ll1.c +42 -0
- data/ext/libffi/testsuite/libffi.call/return_sc.c +36 -0
- data/ext/libffi/testsuite/libffi.call/return_sl.c +38 -0
- data/ext/libffi/testsuite/libffi.call/return_uc.c +38 -0
- data/ext/libffi/testsuite/libffi.call/return_ul.c +38 -0
- data/ext/libffi/testsuite/libffi.call/strlen.c +44 -0
- data/ext/libffi/testsuite/libffi.call/strlen_win32.c +44 -0
- data/ext/libffi/testsuite/libffi.call/struct1.c +65 -0
- data/ext/libffi/testsuite/libffi.call/struct2.c +67 -0
- data/ext/libffi/testsuite/libffi.call/struct3.c +59 -0
- data/ext/libffi/testsuite/libffi.call/struct4.c +63 -0
- data/ext/libffi/testsuite/libffi.call/struct5.c +65 -0
- data/ext/libffi/testsuite/libffi.call/struct6.c +64 -0
- data/ext/libffi/testsuite/libffi.call/struct7.c +74 -0
- data/ext/libffi/testsuite/libffi.call/struct8.c +80 -0
- data/ext/libffi/testsuite/libffi.call/struct9.c +67 -0
- data/ext/libffi/testsuite/libffi.special/ffitestcxx.h +86 -0
- data/ext/libffi/testsuite/libffi.special/special.exp +38 -0
- data/ext/libffi/testsuite/libffi.special/unwindtest.cc +123 -0
- data/ext/libffi/testsuite/libffi.special/unwindtest_ffi_call.cc +53 -0
- data/ext/libffi/texinfo.tex +7482 -0
- data/ext/rbffi.h +32 -0
- data/lib/ffi.rb +2 -0
- data/lib/ffi/buffer.rb +25 -0
- data/lib/ffi/callback.rb +10 -0
- data/lib/ffi/ffi.rb +259 -0
- data/lib/ffi/memorypointer.rb +169 -0
- data/lib/ffi/platform.rb +75 -0
- data/lib/ffi/struct.rb +263 -0
- data/nbproject/Makefile-Default.mk +54 -0
- data/nbproject/Makefile-impl.mk +123 -0
- data/nbproject/configurations.xml +169 -0
- data/nbproject/private/configurations.xml +22 -0
- data/nbproject/private/private.xml +7 -0
- data/nbproject/project.properties +0 -0
- data/nbproject/project.xml +11 -0
- data/samples/getlogin.rb +7 -0
- data/samples/getpid.rb +7 -0
- data/samples/gettimeofday.rb +13 -0
- data/samples/hello.rb +7 -0
- data/samples/qsort.rb +20 -0
- data/specs/buffer_spec.rb +141 -0
- data/specs/callback_spec.rb +31 -0
- data/specs/rbx/attach_function_spec.rb +26 -0
- data/specs/rbx/memory_pointer_spec.rb +108 -0
- data/specs/rbx/spec_helper.rb +1 -0
- data/specs/rbx/struct_spec.rb +13 -0
- data/specs/spec_helper.rb +2 -0
- metadata +359 -0
data/LICENSE
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
Copyright (c) 2008, JRuby Project
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
* Neither the name of the JRuby Project nor the names of its contributors
|
13
|
+
may be used to endorse or promote products derived from this software
|
14
|
+
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
|
+
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/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rubygems/specification'
|
4
|
+
require "spec/rake/spectask"
|
5
|
+
require 'date'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
GEM = "ffi"
|
9
|
+
GEM_VERSION = "0.1.0"
|
10
|
+
AUTHOR = "Wayne Meissner"
|
11
|
+
EMAIL = "wmeissner@gmail.com"
|
12
|
+
HOMEPAGE = "http://kenai.com/projects/ruby-ffi"
|
13
|
+
SUMMARY = "A Ruby foreign function interface (compatible with Rubinius and JRuby FFI)"
|
14
|
+
|
15
|
+
spec = Gem::Specification.new do |s|
|
16
|
+
s.name = GEM
|
17
|
+
s.version = GEM_VERSION
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.extra_rdoc_files = ["README", "LICENSE"]
|
21
|
+
s.summary = SUMMARY
|
22
|
+
s.description = s.summary
|
23
|
+
s.author = AUTHOR
|
24
|
+
s.email = EMAIL
|
25
|
+
s.homepage = HOMEPAGE
|
26
|
+
s.rubyforge_project = 'ffi'
|
27
|
+
s.extensions = %w(ext/extconf.rb)
|
28
|
+
|
29
|
+
s.require_path = 'lib'
|
30
|
+
s.autorequire = GEM
|
31
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{ext,lib,nbproject,samples,specs}/**/*")
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Run all specs"
|
35
|
+
Spec::Rake::SpecTask.new("specs") do |t|
|
36
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
37
|
+
t.spec_files = Dir["spec/**/*_spec.rb"].sort
|
38
|
+
end
|
39
|
+
desc "Run rubinius specs"
|
40
|
+
Spec::Rake::SpecTask.new("rbxspecs") do |t|
|
41
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
42
|
+
t.spec_files = Dir["spec/rbx/*_spec.rb"].sort
|
43
|
+
end
|
44
|
+
|
45
|
+
if RUBY_PLATFORM == "java"
|
46
|
+
desc "Run specs"
|
47
|
+
task :specs do
|
48
|
+
sh %{#{Gem.ruby} -S spec #{Dir["specs/**/*_spec.rb"].join(" ")} -fs --color}
|
49
|
+
end
|
50
|
+
task :rbxspecs do
|
51
|
+
sh %{#{Gem.ruby} -S spec #{Dir["specs/rbx/**/*_spec.rb"].join(" ")} -fs --color}
|
52
|
+
end
|
53
|
+
else
|
54
|
+
desc "Run specs"
|
55
|
+
task :specs do
|
56
|
+
ENV["MRI_FFI"] = "1"
|
57
|
+
sh %{#{Gem.ruby} -S spec #{Dir["specs/**/*_spec.rb"].join(" ")} -fs --color}
|
58
|
+
end
|
59
|
+
task :rbxspecs do
|
60
|
+
ENV["MRI_FFI"] = "1"
|
61
|
+
sh %{#{Gem.ruby} -S spec #{Dir["specs/rbx/**/*_spec.rb"].join(" ")} -fs --color}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
66
|
+
pkg.gem_spec = spec
|
67
|
+
end
|
68
|
+
|
69
|
+
desc "install the gem locally"
|
70
|
+
task :install => [:package] do
|
71
|
+
sh %{sudo #{Gem.ruby} -S gem install pkg/#{GEM}-#{GEM_VERSION}}
|
72
|
+
end
|
73
|
+
|
74
|
+
desc "create a gemspec file"
|
75
|
+
task :make_spec do
|
76
|
+
File.open("#{GEM}.gemspec", "w") do |file|
|
77
|
+
file.puts spec.to_ruby
|
78
|
+
end
|
79
|
+
end
|
80
|
+
file "Makefile" do
|
81
|
+
sh %{#{Gem.ruby} ext/extconf.rb}
|
82
|
+
end
|
83
|
+
task :compile => "Makefile" do
|
84
|
+
sh %{make}
|
85
|
+
end
|
86
|
+
task :clean do
|
87
|
+
sh %{make clean} if File.exists?("Makefile")
|
88
|
+
FileUtils.rm_rf("build")
|
89
|
+
FileUtils.rm_f(Dir["pkg/*.gem", "Makefile"])
|
90
|
+
end
|
@@ -0,0 +1,254 @@
|
|
1
|
+
#include <sys/types.h>
|
2
|
+
#include <sys/param.h>
|
3
|
+
#include <stdint.h>
|
4
|
+
#include <stdbool.h>
|
5
|
+
#include <ruby.h>
|
6
|
+
#include "rbffi.h"
|
7
|
+
#include "AbstractMemory.h"
|
8
|
+
#include "MemoryPointer.h"
|
9
|
+
|
10
|
+
static VALUE memory_put_float32(VALUE self, VALUE offset, VALUE value);
|
11
|
+
static VALUE memory_get_float32(VALUE self, VALUE offset);
|
12
|
+
static VALUE memory_put_float64(VALUE self, VALUE offset, VALUE value);
|
13
|
+
static VALUE memory_get_float64(VALUE self, VALUE offset);
|
14
|
+
static VALUE memory_put_pointer(VALUE self, VALUE offset, VALUE value);
|
15
|
+
static VALUE memory_get_pointer(VALUE self, VALUE offset);
|
16
|
+
|
17
|
+
static inline caddr_t memory_address(VALUE self);
|
18
|
+
VALUE rb_FFI_AbstractMemory_class = Qnil;
|
19
|
+
static VALUE classMemory = Qnil;
|
20
|
+
|
21
|
+
#define ADDRESS(self, offset) (memory_address((self)) + NUM2ULONG(offset))
|
22
|
+
|
23
|
+
#define NUM_OP(name, type, toNative, fromNative) \
|
24
|
+
static VALUE memory_put_##name(VALUE self, VALUE offset, VALUE value); \
|
25
|
+
static VALUE \
|
26
|
+
memory_put_##name(VALUE self, VALUE offset, VALUE value) \
|
27
|
+
{ \
|
28
|
+
long off = NUM2LONG(offset); \
|
29
|
+
AbstractMemory* memory = (AbstractMemory *) DATA_PTR(self); \
|
30
|
+
type tmp = (type) toNative(value); \
|
31
|
+
checkBounds(memory, off, sizeof(type)); \
|
32
|
+
memcpy(memory->address + off, &tmp, sizeof(tmp)); \
|
33
|
+
return self; \
|
34
|
+
} \
|
35
|
+
static VALUE memory_get_##name(VALUE self, VALUE offset); \
|
36
|
+
static VALUE \
|
37
|
+
memory_get_##name(VALUE self, VALUE offset) \
|
38
|
+
{ \
|
39
|
+
long off = NUM2LONG(offset); \
|
40
|
+
AbstractMemory* memory = (AbstractMemory *) DATA_PTR(self); \
|
41
|
+
type tmp; \
|
42
|
+
checkBounds(memory, off, sizeof(type)); \
|
43
|
+
memcpy(&tmp, memory->address + off, sizeof(tmp)); \
|
44
|
+
return fromNative(tmp); \
|
45
|
+
} \
|
46
|
+
static VALUE memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary); \
|
47
|
+
static VALUE \
|
48
|
+
memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary) \
|
49
|
+
{ \
|
50
|
+
long count = RARRAY(ary)->len; \
|
51
|
+
long off = NUM2LONG(offset); \
|
52
|
+
AbstractMemory* memory = (AbstractMemory *) DATA_PTR(self); \
|
53
|
+
caddr_t address = memory->address; \
|
54
|
+
long i; \
|
55
|
+
checkBounds(memory, off, count * sizeof(type)); \
|
56
|
+
for (i = 0; i < count; i++) { \
|
57
|
+
type tmp = (type) toNative(rb_ary_entry(ary, i)); \
|
58
|
+
memcpy(address + off + (i * sizeof(type)), &tmp, sizeof(tmp)); \
|
59
|
+
} \
|
60
|
+
return self; \
|
61
|
+
} \
|
62
|
+
static VALUE memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length); \
|
63
|
+
static VALUE \
|
64
|
+
memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length) \
|
65
|
+
{ \
|
66
|
+
long count = NUM2LONG(length); \
|
67
|
+
long off = NUM2LONG(offset); \
|
68
|
+
AbstractMemory* memory = (AbstractMemory *) DATA_PTR(self); \
|
69
|
+
caddr_t address = memory->address; \
|
70
|
+
long last = off + count; \
|
71
|
+
long i; \
|
72
|
+
checkBounds(memory, off, count * sizeof(type)); \
|
73
|
+
VALUE retVal = rb_ary_new2(count); \
|
74
|
+
for (i = off; i < last; ++i) { \
|
75
|
+
type tmp; \
|
76
|
+
memcpy(&tmp, address + (i * sizeof(type)), sizeof(tmp)); \
|
77
|
+
rb_ary_push(retVal, fromNative(tmp)); \
|
78
|
+
} \
|
79
|
+
return retVal; \
|
80
|
+
}
|
81
|
+
|
82
|
+
NUM_OP(int8, int8_t, NUM2INT, INT2NUM);
|
83
|
+
NUM_OP(uint8, u_int8_t, NUM2UINT, UINT2NUM);
|
84
|
+
NUM_OP(int16, int16_t, NUM2INT, INT2NUM);
|
85
|
+
NUM_OP(uint16, u_int16_t, NUM2UINT, UINT2NUM);
|
86
|
+
NUM_OP(int32, int32_t, NUM2INT, INT2NUM);
|
87
|
+
NUM_OP(uint32, u_int32_t, NUM2UINT, UINT2NUM);
|
88
|
+
NUM_OP(int64, int64_t, NUM2LL, LL2NUM);
|
89
|
+
NUM_OP(uint64, u_int64_t, NUM2ULL, ULL2NUM);
|
90
|
+
NUM_OP(float32, float, NUM2DBL, rb_float_new);
|
91
|
+
NUM_OP(float64, double, NUM2DBL, rb_float_new);
|
92
|
+
|
93
|
+
static VALUE
|
94
|
+
memory_put_pointer(VALUE self, VALUE offset, VALUE value)
|
95
|
+
{
|
96
|
+
AbstractMemory* memory = (AbstractMemory *) DATA_PTR(self);
|
97
|
+
long off = NUM2LONG(offset);
|
98
|
+
checkBounds(memory, off, sizeof(void *));
|
99
|
+
if (rb_obj_is_kind_of(value, rb_FFI_MemoryPointer_class)) {
|
100
|
+
void* tmp = memory_address(value);
|
101
|
+
memcpy(memory->address + off, &tmp, sizeof(tmp));
|
102
|
+
} else if (TYPE(value) == T_NIL) {
|
103
|
+
void* tmp = NULL;
|
104
|
+
memcpy(memory->address + off, &tmp, sizeof(tmp));
|
105
|
+
} else if (TYPE(value) == T_FIXNUM) {
|
106
|
+
uintptr_t tmp = (uintptr_t) FIX2INT(value);
|
107
|
+
memcpy(memory->address + off, &tmp, sizeof(tmp));
|
108
|
+
} else if (TYPE(value) == T_BIGNUM) {
|
109
|
+
uintptr_t tmp = (uintptr_t) NUM2ULL(value);
|
110
|
+
memcpy(memory->address + off, &tmp, sizeof(tmp));
|
111
|
+
} else {
|
112
|
+
rb_raise(rb_eArgError, "value is not a pointer");
|
113
|
+
}
|
114
|
+
return self;
|
115
|
+
}
|
116
|
+
|
117
|
+
static VALUE
|
118
|
+
memory_get_pointer(VALUE self, VALUE offset)
|
119
|
+
{
|
120
|
+
AbstractMemory* memory = (AbstractMemory *) DATA_PTR(self);
|
121
|
+
long off = NUM2LONG(offset);
|
122
|
+
caddr_t tmp;
|
123
|
+
checkBounds(memory, off, sizeof(tmp));
|
124
|
+
memcpy(&tmp, memory->address + off, sizeof(tmp));
|
125
|
+
return rb_FFI_MemoryPointer_new(tmp);
|
126
|
+
}
|
127
|
+
|
128
|
+
static VALUE
|
129
|
+
memory_clear(VALUE self)
|
130
|
+
{
|
131
|
+
AbstractMemory* ptr = (AbstractMemory *) DATA_PTR(self);
|
132
|
+
memset(ptr->address, 0, ptr->size);
|
133
|
+
return self;
|
134
|
+
}
|
135
|
+
|
136
|
+
static VALUE
|
137
|
+
memory_size(VALUE self)
|
138
|
+
{
|
139
|
+
return LONG2FIX(((AbstractMemory *) DATA_PTR(self))->size);
|
140
|
+
}
|
141
|
+
|
142
|
+
static VALUE
|
143
|
+
memory_get_string(int argc, VALUE* argv, VALUE self)
|
144
|
+
{
|
145
|
+
VALUE length = Qnil, offset = Qnil;
|
146
|
+
AbstractMemory* ptr = (AbstractMemory *) DATA_PTR(self);
|
147
|
+
long off, len;
|
148
|
+
int nargs = rb_scan_args(argc, argv, "11", &offset, &length);
|
149
|
+
|
150
|
+
off = NUM2LONG(offset);
|
151
|
+
if (nargs > 1) {
|
152
|
+
len = NUM2LONG(length);
|
153
|
+
} else {
|
154
|
+
caddr_t end;
|
155
|
+
checkBounds(ptr, off, 1);
|
156
|
+
end = memchr(ptr->address + off, 0, ptr->size - off);
|
157
|
+
len = ((end != NULL) ? end - ptr->address: ptr->size) - off;
|
158
|
+
}
|
159
|
+
checkBounds(ptr, off, len);
|
160
|
+
return rb_str_new((char *) ptr->address + off, len);
|
161
|
+
}
|
162
|
+
|
163
|
+
static VALUE
|
164
|
+
memory_put_string(int argc, VALUE* argv, VALUE self)
|
165
|
+
{
|
166
|
+
AbstractMemory* ptr = (AbstractMemory *) DATA_PTR(self);
|
167
|
+
VALUE offset = Qnil, str = Qnil, length = Qnil;
|
168
|
+
bool nulTerminate = true;
|
169
|
+
long off, len;
|
170
|
+
int nargs = rb_scan_args(argc, argv, "21", &offset, &str, &length);
|
171
|
+
off = NUM2LONG(offset);
|
172
|
+
len = RSTRING_LEN(str);
|
173
|
+
if (nargs > 2 && length != Qnil) {
|
174
|
+
len = MIN(NUM2ULONG(length), len);
|
175
|
+
nulTerminate = false;
|
176
|
+
}
|
177
|
+
checkBounds(ptr, off, len);
|
178
|
+
memcpy(ptr->address + off, RSTRING_PTR(str), len);
|
179
|
+
|
180
|
+
if (nulTerminate) {
|
181
|
+
char nul = '\0';
|
182
|
+
memcpy(ptr->address + off + len, &nul, sizeof(nul));
|
183
|
+
}
|
184
|
+
return self;
|
185
|
+
}
|
186
|
+
static inline caddr_t
|
187
|
+
memory_address(VALUE self)
|
188
|
+
{
|
189
|
+
return ((AbstractMemory *)DATA_PTR((self)))->address;
|
190
|
+
}
|
191
|
+
|
192
|
+
void
|
193
|
+
rb_FFI_AbstractMemory_Init()
|
194
|
+
{
|
195
|
+
VALUE moduleFFI = rb_define_module("FFI");
|
196
|
+
rb_FFI_AbstractMemory_class = classMemory = rb_define_class_under(moduleFFI, "AbstractMemory", rb_cObject);
|
197
|
+
#undef INT
|
198
|
+
#define INT(type) \
|
199
|
+
rb_define_method(classMemory, "put_" #type, memory_put_##type, 2); \
|
200
|
+
rb_define_method(classMemory, "get_" #type, memory_get_##type, 1); \
|
201
|
+
rb_define_method(classMemory, "put_u" #type, memory_put_u##type, 2); \
|
202
|
+
rb_define_method(classMemory, "get_u" #type, memory_get_u##type, 1); \
|
203
|
+
rb_define_method(classMemory, "put_array_of_" #type, memory_put_array_of_##type, 2); \
|
204
|
+
rb_define_method(classMemory, "get_array_of_" #type, memory_get_array_of_##type, 2); \
|
205
|
+
rb_define_method(classMemory, "put_array_of_u" #type, memory_put_array_of_u##type, 2); \
|
206
|
+
rb_define_method(classMemory, "get_array_of_u" #type, memory_get_array_of_u##type, 2);
|
207
|
+
|
208
|
+
INT(int8);
|
209
|
+
INT(int16);
|
210
|
+
INT(int32);
|
211
|
+
INT(int64);
|
212
|
+
|
213
|
+
#define ALIAS(name, old) \
|
214
|
+
rb_define_alias(classMemory, "put_" #name, "put_" #old); \
|
215
|
+
rb_define_alias(classMemory, "get_" #name, "get_" #old); \
|
216
|
+
rb_define_alias(classMemory, "put_u" #name, "put_u" #old); \
|
217
|
+
rb_define_alias(classMemory, "get_u" #name, "get_u" #old); \
|
218
|
+
rb_define_alias(classMemory, "put_array_of_" #name, "put_array_of_" #old); \
|
219
|
+
rb_define_alias(classMemory, "get_array_of_" #name, "get_array_of_" #old); \
|
220
|
+
rb_define_alias(classMemory, "put_array_of_u" #name, "put_array_of_u" #old); \
|
221
|
+
rb_define_alias(classMemory, "get_array_of_u" #name, "get_array_of_u" #old);
|
222
|
+
|
223
|
+
ALIAS(char, int8);
|
224
|
+
ALIAS(short, int16);
|
225
|
+
ALIAS(int, int32);
|
226
|
+
ALIAS(long_long, int64);
|
227
|
+
|
228
|
+
if (sizeof(long) == 4) {
|
229
|
+
rb_define_alias(classMemory, "put_long", "put_int32");
|
230
|
+
rb_define_alias(classMemory, "put_ulong", "put_uint32");
|
231
|
+
rb_define_alias(classMemory, "get_long", "get_int32");
|
232
|
+
rb_define_alias(classMemory, "get_ulong", "get_uint32");
|
233
|
+
} else {
|
234
|
+
rb_define_alias(classMemory, "put_long", "put_int64");
|
235
|
+
rb_define_alias(classMemory, "put_ulong", "put_uint64");
|
236
|
+
rb_define_alias(classMemory, "get_long", "get_int64");
|
237
|
+
rb_define_alias(classMemory, "get_ulong", "get_uint64");
|
238
|
+
}
|
239
|
+
rb_define_method(classMemory, "put_float32", memory_put_float32, 2);
|
240
|
+
rb_define_method(classMemory, "get_float32", memory_get_float32, 1);
|
241
|
+
rb_define_method(classMemory, "put_array_of_float32", memory_put_array_of_float32, 2);
|
242
|
+
rb_define_method(classMemory, "get_array_of_float32", memory_get_array_of_float32, 2);
|
243
|
+
rb_define_method(classMemory, "put_float64", memory_put_float64, 2);
|
244
|
+
rb_define_method(classMemory, "get_float64", memory_get_float64, 1);
|
245
|
+
rb_define_method(classMemory, "put_array_of_float64", memory_put_array_of_float64, 2);
|
246
|
+
rb_define_method(classMemory, "get_array_of_float64", memory_get_array_of_float64, 2);
|
247
|
+
rb_define_method(classMemory, "put_pointer", memory_put_pointer, 2);
|
248
|
+
rb_define_method(classMemory, "get_pointer", memory_get_pointer, 1);
|
249
|
+
rb_define_method(classMemory, "get_string", memory_get_string, -1);
|
250
|
+
rb_define_method(classMemory, "put_string", memory_put_string, -1);
|
251
|
+
rb_define_method(classMemory, "clear", memory_clear, 0);
|
252
|
+
rb_define_method(classMemory, "total", memory_size, 0);
|
253
|
+
}
|
254
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/*
|
2
|
+
* File: AbstractMemory.h
|
3
|
+
* Author: wayne
|
4
|
+
*
|
5
|
+
* Created on August 28, 2008, 5:52 PM
|
6
|
+
*/
|
7
|
+
|
8
|
+
#ifndef _ABSTRACTMEMORY_H
|
9
|
+
#define _ABSTRACTMEMORY_H
|
10
|
+
|
11
|
+
#include <sys/types.h>
|
12
|
+
|
13
|
+
#ifdef __cplusplus
|
14
|
+
extern "C" {
|
15
|
+
#endif
|
16
|
+
|
17
|
+
typedef struct {
|
18
|
+
caddr_t address;
|
19
|
+
long size;
|
20
|
+
} AbstractMemory;
|
21
|
+
|
22
|
+
static inline void
|
23
|
+
checkBounds(AbstractMemory* mem, long off, long len)
|
24
|
+
{
|
25
|
+
if ((off | len | (off + len) | (mem->size - (off + len))) < 0) {
|
26
|
+
rb_raise(rb_eIndexError, "Memory access offset=%ld size=%ld is out of bounds",
|
27
|
+
off, len);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
}
|
33
|
+
#endif
|
34
|
+
|
35
|
+
#endif /* _ABSTRACTMEMORY_H */
|
36
|
+
|
data/ext/Buffer.c
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
#include <stdbool.h>
|
2
|
+
#include <stdint.h>
|
3
|
+
#include <limits.h>
|
4
|
+
#include <ruby.h>
|
5
|
+
#include "rbffi.h"
|
6
|
+
#include "AbstractMemory.h"
|
7
|
+
|
8
|
+
typedef struct Buffer {
|
9
|
+
AbstractMemory memory;
|
10
|
+
VALUE parent;
|
11
|
+
} Buffer;
|
12
|
+
|
13
|
+
static VALUE buffer_allocate(VALUE self, VALUE size, VALUE count, VALUE clear);
|
14
|
+
static void buffer_release(Buffer* ptr);
|
15
|
+
static void buffer_mark(Buffer* ptr);
|
16
|
+
|
17
|
+
static VALUE classBuffer = Qnil;
|
18
|
+
|
19
|
+
static VALUE
|
20
|
+
buffer_allocate(VALUE self, VALUE size, VALUE count, VALUE clear)
|
21
|
+
{
|
22
|
+
Buffer* p;
|
23
|
+
|
24
|
+
p = ALLOC(Buffer);
|
25
|
+
memset(p, 0, sizeof(*p));
|
26
|
+
p->memory.size = NUM2LONG(size) * (count == Qnil ? 1 : NUM2LONG(count));
|
27
|
+
p->memory.address = p->memory.size > 0 ? malloc(p->memory.size) : NULL;
|
28
|
+
p->parent = Qnil;
|
29
|
+
|
30
|
+
if (p->memory.address == NULL) {
|
31
|
+
int size = p->memory.size;
|
32
|
+
xfree(p);
|
33
|
+
rb_raise(rb_eNoMemError, "Failed to allocate memory size=%u bytes", size);
|
34
|
+
}
|
35
|
+
if (TYPE(clear) == T_TRUE) {
|
36
|
+
memset(p->memory.address, 0, p->memory.size);
|
37
|
+
}
|
38
|
+
return Data_Wrap_Struct(classBuffer, buffer_mark, buffer_release, p);
|
39
|
+
}
|
40
|
+
|
41
|
+
static VALUE
|
42
|
+
buffer_plus(VALUE self, VALUE offset)
|
43
|
+
{
|
44
|
+
Buffer* ptr = (Buffer *) DATA_PTR(self);
|
45
|
+
Buffer* p;
|
46
|
+
long off = NUM2LONG(offset);
|
47
|
+
|
48
|
+
checkBounds(&ptr->memory, off, 1);
|
49
|
+
p = ALLOC(Buffer);
|
50
|
+
memset(p, 0, sizeof(*p));
|
51
|
+
p->memory.address = ptr->memory.address + off;;
|
52
|
+
p->memory.size = ptr->memory.size - off;
|
53
|
+
p->parent = self;
|
54
|
+
return Data_Wrap_Struct(classBuffer, buffer_mark, buffer_release, p);
|
55
|
+
}
|
56
|
+
|
57
|
+
static VALUE
|
58
|
+
buffer_inspect(VALUE self)
|
59
|
+
{
|
60
|
+
Buffer* ptr = (Buffer *) DATA_PTR(self);
|
61
|
+
char tmp[100];
|
62
|
+
snprintf(tmp, sizeof(tmp), "#<Buffer size=%ld>", ptr->memory.size);
|
63
|
+
return rb_str_new2(tmp);
|
64
|
+
}
|
65
|
+
|
66
|
+
static void
|
67
|
+
buffer_release(Buffer* ptr)
|
68
|
+
{
|
69
|
+
if (ptr->parent != Qnil && ptr->memory.address != NULL) {
|
70
|
+
free(ptr->memory.address);
|
71
|
+
}
|
72
|
+
xfree(ptr);
|
73
|
+
|
74
|
+
}
|
75
|
+
static void
|
76
|
+
buffer_mark(Buffer* ptr)
|
77
|
+
{
|
78
|
+
if (ptr->parent != Qnil) {
|
79
|
+
rb_gc_mark(ptr->parent);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
void
|
84
|
+
rb_FFI_Buffer_Init()
|
85
|
+
{
|
86
|
+
VALUE moduleFFI = rb_define_module("FFI");
|
87
|
+
classBuffer = rb_define_class_under(moduleFFI, "Buffer", rb_FFI_AbstractMemory_class);
|
88
|
+
rb_define_singleton_method(classBuffer, "__alloc_inout", buffer_allocate, 3);
|
89
|
+
rb_define_singleton_method(classBuffer, "__alloc_out", buffer_allocate, 3);
|
90
|
+
rb_define_singleton_method(classBuffer, "__alloc_in", buffer_allocate, 3);
|
91
|
+
rb_define_method(classBuffer, "inspect", buffer_inspect, 0);
|
92
|
+
rb_define_method(classBuffer, "+", buffer_plus, 1);
|
93
|
+
}
|
94
|
+
|