ffi 1.9.3-x64-mingw32
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/COPYING +49 -0
- data/LICENSE +24 -0
- data/README.md +109 -0
- data/Rakefile +220 -0
- data/ext/ffi_c/AbstractMemory.c +1032 -0
- data/ext/ffi_c/AbstractMemory.h +175 -0
- data/ext/ffi_c/ArrayType.c +162 -0
- data/ext/ffi_c/ArrayType.h +59 -0
- data/ext/ffi_c/Buffer.c +365 -0
- data/ext/ffi_c/Call.c +465 -0
- data/ext/ffi_c/Call.h +93 -0
- data/ext/ffi_c/ClosurePool.c +283 -0
- data/ext/ffi_c/ClosurePool.h +57 -0
- data/ext/ffi_c/DataConverter.c +91 -0
- data/ext/ffi_c/DynamicLibrary.c +333 -0
- data/ext/ffi_c/DynamicLibrary.h +49 -0
- data/ext/ffi_c/Function.c +999 -0
- data/ext/ffi_c/Function.h +87 -0
- data/ext/ffi_c/FunctionInfo.c +271 -0
- data/ext/ffi_c/LastError.c +184 -0
- data/ext/ffi_c/LastError.h +47 -0
- data/ext/ffi_c/LongDouble.c +63 -0
- data/ext/ffi_c/LongDouble.h +51 -0
- data/ext/ffi_c/MappedType.c +168 -0
- data/ext/ffi_c/MappedType.h +59 -0
- data/ext/ffi_c/MemoryPointer.c +197 -0
- data/ext/ffi_c/MemoryPointer.h +53 -0
- data/ext/ffi_c/MethodHandle.c +360 -0
- data/ext/ffi_c/MethodHandle.h +55 -0
- data/ext/ffi_c/Platform.c +121 -0
- data/ext/ffi_c/Platform.h +45 -0
- data/ext/ffi_c/Pointer.c +508 -0
- data/ext/ffi_c/Pointer.h +63 -0
- data/ext/ffi_c/Struct.c +828 -0
- data/ext/ffi_c/Struct.h +106 -0
- data/ext/ffi_c/StructByReference.c +190 -0
- data/ext/ffi_c/StructByReference.h +50 -0
- data/ext/ffi_c/StructByValue.c +150 -0
- data/ext/ffi_c/StructByValue.h +55 -0
- data/ext/ffi_c/StructLayout.c +698 -0
- data/ext/ffi_c/Thread.c +352 -0
- data/ext/ffi_c/Thread.h +95 -0
- data/ext/ffi_c/Type.c +397 -0
- data/ext/ffi_c/Type.h +62 -0
- data/ext/ffi_c/Types.c +139 -0
- data/ext/ffi_c/Types.h +89 -0
- data/ext/ffi_c/Variadic.c +276 -0
- data/ext/ffi_c/compat.h +83 -0
- data/ext/ffi_c/extconf.rb +64 -0
- data/ext/ffi_c/ffi.c +98 -0
- data/ext/ffi_c/libffi.bsd.mk +34 -0
- data/ext/ffi_c/libffi.darwin.mk +95 -0
- data/ext/ffi_c/libffi.gnu.mk +31 -0
- data/ext/ffi_c/libffi.mk +13 -0
- data/ext/ffi_c/libffi.vc.mk +26 -0
- data/ext/ffi_c/libffi.vc64.mk +26 -0
- data/ext/ffi_c/libffi/ChangeLog +4600 -0
- data/ext/ffi_c/libffi/ChangeLog.libffi +584 -0
- data/ext/ffi_c/libffi/ChangeLog.libgcj +40 -0
- data/ext/ffi_c/libffi/ChangeLog.v1 +764 -0
- data/ext/ffi_c/libffi/LICENSE +21 -0
- data/ext/ffi_c/libffi/Makefile.am +196 -0
- data/ext/ffi_c/libffi/Makefile.in +1820 -0
- data/ext/ffi_c/libffi/Makefile.vc +141 -0
- data/ext/ffi_c/libffi/Makefile.vc64 +141 -0
- data/ext/ffi_c/libffi/README +342 -0
- data/ext/ffi_c/libffi/acinclude.m4 +92 -0
- data/ext/ffi_c/libffi/aclocal.m4 +1873 -0
- data/ext/ffi_c/libffi/build-ios.sh +67 -0
- data/ext/ffi_c/libffi/compile +143 -0
- data/ext/ffi_c/libffi/config.guess +1501 -0
- data/ext/ffi_c/libffi/config.sub +1705 -0
- data/ext/ffi_c/libffi/configure +17191 -0
- data/ext/ffi_c/libffi/configure.ac +496 -0
- data/ext/ffi_c/libffi/configure.host +11 -0
- data/ext/ffi_c/libffi/depcomp +630 -0
- data/ext/ffi_c/libffi/doc/libffi.info +593 -0
- data/ext/ffi_c/libffi/doc/libffi.texi +600 -0
- data/ext/ffi_c/libffi/doc/stamp-vti +4 -0
- data/ext/ffi_c/libffi/doc/version.texi +4 -0
- data/ext/ffi_c/libffi/fficonfig.h.in +199 -0
- data/ext/ffi_c/libffi/fficonfig.hw +57 -0
- data/ext/ffi_c/libffi/include/Makefile.am +9 -0
- data/ext/ffi_c/libffi/include/Makefile.in +487 -0
- data/ext/ffi_c/libffi/include/ffi.h.in +427 -0
- data/ext/ffi_c/libffi/include/ffi.h.vc +427 -0
- data/ext/ffi_c/libffi/include/ffi.h.vc64 +427 -0
- data/ext/ffi_c/libffi/include/ffi_common.h +126 -0
- data/ext/ffi_c/libffi/install-sh +520 -0
- data/ext/ffi_c/libffi/libffi.pc.in +10 -0
- data/ext/ffi_c/libffi/libtool-version +29 -0
- data/ext/ffi_c/libffi/ltmain.sh +9636 -0
- data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +176 -0
- data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +195 -0
- data/ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 +76 -0
- data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +63 -0
- data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
- data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +300 -0
- data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +215 -0
- data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +79 -0
- data/ext/ffi_c/libffi/m4/libtool.m4 +7831 -0
- data/ext/ffi_c/libffi/m4/ltoptions.m4 +369 -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 +98 -0
- data/ext/ffi_c/libffi/man/Makefile.am +8 -0
- data/ext/ffi_c/libffi/man/Makefile.in +466 -0
- data/ext/ffi_c/libffi/man/ffi.3 +31 -0
- data/ext/ffi_c/libffi/man/ffi_call.3 +103 -0
- data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +66 -0
- data/ext/ffi_c/libffi/mdate-sh +201 -0
- data/ext/ffi_c/libffi/missing +376 -0
- data/ext/ffi_c/libffi/msvcc.sh +197 -0
- data/ext/ffi_c/libffi/src/alpha/ffi.c +284 -0
- data/ext/ffi_c/libffi/src/alpha/ffitarget.h +48 -0
- data/ext/ffi_c/libffi/src/alpha/osf.S +387 -0
- data/ext/ffi_c/libffi/src/arm/ffi.c +728 -0
- data/ext/ffi_c/libffi/src/arm/ffitarget.h +65 -0
- data/ext/ffi_c/libffi/src/arm/gentramp.sh +118 -0
- data/ext/ffi_c/libffi/src/arm/sysv.S +497 -0
- data/ext/ffi_c/libffi/src/arm/trampoline.S +4450 -0
- data/ext/ffi_c/libffi/src/avr32/ffi.c +423 -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 +615 -0
- data/ext/ffi_c/libffi/src/cris/ffi.c +383 -0
- data/ext/ffi_c/libffi/src/cris/ffitarget.h +51 -0
- data/ext/ffi_c/libffi/src/cris/sysv.S +215 -0
- data/ext/ffi_c/libffi/src/debug.c +59 -0
- data/ext/ffi_c/libffi/src/dlmalloc.c +5161 -0
- data/ext/ffi_c/libffi/src/frv/eabi.S +128 -0
- data/ext/ffi_c/libffi/src/frv/ffi.c +292 -0
- data/ext/ffi_c/libffi/src/frv/ffitarget.h +57 -0
- data/ext/ffi_c/libffi/src/ia64/ffi.c +582 -0
- data/ext/ffi_c/libffi/src/ia64/ffitarget.h +50 -0
- data/ext/ffi_c/libffi/src/ia64/ia64_flags.h +40 -0
- data/ext/ffi_c/libffi/src/ia64/unix.S +560 -0
- data/ext/ffi_c/libffi/src/java_raw_api.c +356 -0
- data/ext/ffi_c/libffi/src/m32r/ffi.c +232 -0
- data/ext/ffi_c/libffi/src/m32r/ffitarget.h +48 -0
- data/ext/ffi_c/libffi/src/m32r/sysv.S +121 -0
- data/ext/ffi_c/libffi/src/m68k/ffi.c +288 -0
- data/ext/ffi_c/libffi/src/m68k/ffitarget.h +49 -0
- data/ext/ffi_c/libffi/src/m68k/sysv.S +270 -0
- data/ext/ffi_c/libffi/src/mips/ffi.c +1036 -0
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +242 -0
- data/ext/ffi_c/libffi/src/mips/n32.S +591 -0
- data/ext/ffi_c/libffi/src/mips/o32.S +381 -0
- data/ext/ffi_c/libffi/src/moxie/eabi.S +128 -0
- data/ext/ffi_c/libffi/src/moxie/ffi.c +276 -0
- data/ext/ffi_c/libffi/src/pa/ffi.c +719 -0
- data/ext/ffi_c/libffi/src/pa/ffitarget.h +78 -0
- data/ext/ffi_c/libffi/src/pa/hpux32.S +368 -0
- data/ext/ffi_c/libffi/src/pa/linux.S +357 -0
- data/ext/ffi_c/libffi/src/powerpc/aix.S +328 -0
- data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +445 -0
- data/ext/ffi_c/libffi/src/powerpc/asm.h +125 -0
- data/ext/ffi_c/libffi/src/powerpc/darwin.S +383 -0
- data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +575 -0
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +1448 -0
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +1359 -0
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +139 -0
- data/ext/ffi_c/libffi/src/powerpc/linux64.S +187 -0
- data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +236 -0
- data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +327 -0
- data/ext/ffi_c/libffi/src/powerpc/sysv.S +219 -0
- data/ext/ffi_c/libffi/src/prep_cif.c +177 -0
- data/ext/ffi_c/libffi/src/raw_api.c +254 -0
- data/ext/ffi_c/libffi/src/s390/ffi.c +780 -0
- data/ext/ffi_c/libffi/src/s390/ffitarget.h +62 -0
- data/ext/ffi_c/libffi/src/s390/sysv.S +434 -0
- data/ext/ffi_c/libffi/src/sh/ffi.c +716 -0
- data/ext/ffi_c/libffi/src/sh/ffitarget.h +49 -0
- data/ext/ffi_c/libffi/src/sh/sysv.S +850 -0
- data/ext/ffi_c/libffi/src/sh64/ffi.c +468 -0
- data/ext/ffi_c/libffi/src/sh64/ffitarget.h +53 -0
- data/ext/ffi_c/libffi/src/sh64/sysv.S +539 -0
- data/ext/ffi_c/libffi/src/sparc/ffi.c +669 -0
- data/ext/ffi_c/libffi/src/sparc/ffitarget.h +68 -0
- data/ext/ffi_c/libffi/src/sparc/v8.S +313 -0
- data/ext/ffi_c/libffi/src/sparc/v9.S +307 -0
- data/ext/ffi_c/libffi/src/types.c +77 -0
- data/ext/ffi_c/libffi/src/x86/darwin.S +444 -0
- data/ext/ffi_c/libffi/src/x86/darwin64.S +416 -0
- data/ext/ffi_c/libffi/src/x86/ffi.c +644 -0
- data/ext/ffi_c/libffi/src/x86/ffi64.c +635 -0
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +121 -0
- data/ext/ffi_c/libffi/src/x86/freebsd.S +458 -0
- data/ext/ffi_c/libffi/src/x86/sysv.S +468 -0
- data/ext/ffi_c/libffi/src/x86/unix64.S +426 -0
- data/ext/ffi_c/libffi/src/x86/win32.S +1065 -0
- data/ext/ffi_c/libffi/src/x86/win64.S +468 -0
- data/ext/ffi_c/libffi/testsuite/Makefile.am +80 -0
- data/ext/ffi_c/libffi/testsuite/Makefile.in +500 -0
- data/ext/ffi_c/libffi/testsuite/config/default.exp +1 -0
- data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +300 -0
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +350 -0
- data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +263 -0
- data/ext/ffi_c/libffi/testsuite/lib/wrapper.exp +45 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +32 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +89 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +81 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +81 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +82 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +89 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +92 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +90 -0
- 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 +64 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +94 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +95 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +96 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +102 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +89 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +93 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +113 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +95 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +98 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +109 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +98 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +124 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +113 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +117 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +97 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +88 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +93 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +92 -0
- 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 +95 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +92 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +93 -0
- 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 +43 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +60 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +42 -0
- 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 +60 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +74 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +74 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +86 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +74 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +86 -0
- 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 +44 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +42 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +42 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +42 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +43 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +47 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +43 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +36 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +26 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +153 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float.c +59 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +58 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +58 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +72 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float4.c +62 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +342 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +69 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/many_win32.c +63 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +53 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +152 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +161 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +133 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +110 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +111 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +111 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +112 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +131 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +111 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +131 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +131 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/promotion.c +59 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/pyobjc-tc.c +114 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +35 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl1.c +43 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl2.c +42 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl.c +35 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl1.c +36 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl2.c +49 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl3.c +42 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +34 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll.c +41 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +43 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +36 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +38 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +38 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +38 -0
- 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 +125 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +44 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen_win32.c +44 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +65 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +67 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +59 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +63 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +65 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +64 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +74 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +80 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +67 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +96 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +35 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest.cc +124 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest_ffi_call.cc +53 -0
- data/ext/ffi_c/libffi/texinfo.tex +7210 -0
- data/ext/ffi_c/rbffi.h +57 -0
- data/ext/ffi_c/rbffi_endian.h +59 -0
- data/ext/ffi_c/win32/stdbool.h +8 -0
- data/ext/ffi_c/win32/stdint.h +201 -0
- data/ffi.gemspec +22 -0
- data/gen/Rakefile +30 -0
- data/lib/ffi.rb +28 -0
- data/lib/ffi/autopointer.rb +194 -0
- data/lib/ffi/buffer.rb +4 -0
- data/lib/ffi/callback.rb +4 -0
- data/lib/ffi/enum.rb +173 -0
- data/lib/ffi/errno.rb +43 -0
- data/lib/ffi/ffi.rb +44 -0
- data/lib/ffi/io.rb +62 -0
- data/lib/ffi/library.rb +499 -0
- data/lib/ffi/managedstruct.rb +84 -0
- data/lib/ffi/memorypointer.rb +1 -0
- data/lib/ffi/platform.rb +148 -0
- data/lib/ffi/platform/arm-linux/types.conf +104 -0
- data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
- data/lib/ffi/platform/i386-darwin/types.conf +100 -0
- data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
- data/lib/ffi/platform/i386-gnu/types.conf +107 -0
- data/lib/ffi/platform/i386-linux/types.conf +103 -0
- data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
- data/lib/ffi/platform/i386-openbsd/types.conf +128 -0
- data/lib/ffi/platform/i386-solaris/types.conf +122 -0
- data/lib/ffi/platform/i386-windows/types.conf +105 -0
- data/lib/ffi/platform/ia64-linux/types.conf +104 -0
- data/lib/ffi/platform/mips-linux/types.conf +102 -0
- data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
- data/lib/ffi/platform/powerpc-aix/types.conf +180 -0
- data/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
- data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
- data/lib/ffi/platform/s390-linux/types.conf +102 -0
- data/lib/ffi/platform/s390x-linux/types.conf +102 -0
- data/lib/ffi/platform/sparc-linux/types.conf +102 -0
- data/lib/ffi/platform/sparc-solaris/types.conf +128 -0
- data/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
- data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
- data/lib/ffi/platform/x86_64-darwin/types.conf +100 -0
- data/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
- data/lib/ffi/platform/x86_64-linux/types.conf +102 -0
- data/lib/ffi/platform/x86_64-netbsd/types.conf +126 -0
- data/lib/ffi/platform/x86_64-openbsd/types.conf +128 -0
- data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
- data/lib/ffi/platform/x86_64-windows/types.conf +27 -0
- data/lib/ffi/pointer.rb +134 -0
- data/lib/ffi/struct.rb +367 -0
- data/lib/ffi/struct_layout_builder.rb +222 -0
- data/lib/ffi/tools/const_generator.rb +229 -0
- data/lib/ffi/tools/generator.rb +60 -0
- data/lib/ffi/tools/generator_task.rb +36 -0
- data/lib/ffi/tools/struct_generator.rb +194 -0
- data/lib/ffi/tools/types_generator.rb +135 -0
- data/lib/ffi/types.rb +190 -0
- data/lib/ffi/union.rb +43 -0
- data/lib/ffi/variadic.rb +78 -0
- data/lib/ffi/version.rb +4 -0
- data/lib/ffi_c.so +0 -0
- data/libtest/Benchmark.c +52 -0
- data/libtest/BoolTest.c +34 -0
- data/libtest/BufferTest.c +31 -0
- data/libtest/ClosureTest.c +190 -0
- data/libtest/EnumTest.c +34 -0
- data/libtest/FunctionTest.c +58 -0
- data/libtest/GNUmakefile +149 -0
- data/libtest/GlobalVariable.c +62 -0
- data/libtest/LastErrorTest.c +21 -0
- data/libtest/NumberTest.c +132 -0
- data/libtest/PointerTest.c +63 -0
- data/libtest/ReferenceTest.c +23 -0
- data/libtest/StringTest.c +34 -0
- data/libtest/StructTest.c +243 -0
- data/libtest/UnionTest.c +43 -0
- data/libtest/VariadicTest.c +62 -0
- data/spec/ffi/async_callback_spec.rb +35 -0
- data/spec/ffi/bool_spec.rb +29 -0
- data/spec/ffi/buffer_spec.rb +251 -0
- data/spec/ffi/callback_spec.rb +667 -0
- data/spec/ffi/custom_param_type.rb +36 -0
- data/spec/ffi/custom_type_spec.rb +74 -0
- data/spec/ffi/dup_spec.rb +54 -0
- data/spec/ffi/enum_spec.rb +220 -0
- data/spec/ffi/errno_spec.rb +18 -0
- data/spec/ffi/ffi_spec.rb +29 -0
- data/spec/ffi/function_spec.rb +76 -0
- data/spec/ffi/library_spec.rb +216 -0
- data/spec/ffi/long_double.rb +30 -0
- data/spec/ffi/managed_struct_spec.rb +57 -0
- data/spec/ffi/number_spec.rb +236 -0
- data/spec/ffi/pointer_spec.rb +265 -0
- data/spec/ffi/rbx/attach_function_spec.rb +28 -0
- data/spec/ffi/rbx/memory_pointer_spec.rb +123 -0
- data/spec/ffi/rbx/spec_helper.rb +1 -0
- data/spec/ffi/rbx/struct_spec.rb +13 -0
- data/spec/ffi/spec_helper.rb +33 -0
- data/spec/ffi/string_spec.rb +108 -0
- data/spec/ffi/strptr_spec.rb +50 -0
- data/spec/ffi/struct_by_ref_spec.rb +43 -0
- data/spec/ffi/struct_callback_spec.rb +69 -0
- data/spec/ffi/struct_initialize_spec.rb +35 -0
- data/spec/ffi/struct_packed_spec.rb +51 -0
- data/spec/ffi/struct_spec.rb +748 -0
- data/spec/ffi/typedef_spec.rb +78 -0
- data/spec/ffi/union_spec.rb +65 -0
- data/spec/ffi/variadic_spec.rb +92 -0
- data/spec/spec.opts +4 -0
- metadata +562 -0
data/ext/ffi_c/Pointer.h
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2008, 2009, Wayne Meissner
|
3
|
+
*
|
4
|
+
* Copyright (c) 2008-2013, Ruby FFI project contributors
|
5
|
+
* All rights reserved.
|
6
|
+
*
|
7
|
+
* Redistribution and use in source and binary forms, with or without
|
8
|
+
* modification, are permitted provided that the following conditions are met:
|
9
|
+
* * Redistributions of source code must retain the above copyright
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
11
|
+
* * Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in the
|
13
|
+
* documentation and/or other materials provided with the distribution.
|
14
|
+
* * Neither the name of the Ruby FFI project nor the
|
15
|
+
* names of its contributors may be used to endorse or promote products
|
16
|
+
* derived from this software without specific prior written permission.
|
17
|
+
*
|
18
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
19
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
20
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
22
|
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
23
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
24
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
25
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
27
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
*/
|
29
|
+
|
30
|
+
#ifndef RBFFI_POINTER_H
|
31
|
+
#define RBFFI_POINTER_H
|
32
|
+
|
33
|
+
#ifndef _MSC_VER
|
34
|
+
# include <stdbool.h>
|
35
|
+
#else
|
36
|
+
# include "win32/stdbool.h"
|
37
|
+
#endif
|
38
|
+
|
39
|
+
#ifdef __cplusplus
|
40
|
+
extern "C" {
|
41
|
+
#endif
|
42
|
+
|
43
|
+
#include "AbstractMemory.h"
|
44
|
+
|
45
|
+
extern void rbffi_Pointer_Init(VALUE moduleFFI);
|
46
|
+
extern VALUE rbffi_Pointer_NewInstance(void* addr);
|
47
|
+
extern VALUE rbffi_PointerClass;
|
48
|
+
extern VALUE rbffi_NullPointerSingleton;
|
49
|
+
|
50
|
+
typedef struct Pointer {
|
51
|
+
AbstractMemory memory;
|
52
|
+
VALUE rbParent;
|
53
|
+
char* storage; /* start of malloc area */
|
54
|
+
bool autorelease;
|
55
|
+
bool allocated;
|
56
|
+
} Pointer;
|
57
|
+
|
58
|
+
#ifdef __cplusplus
|
59
|
+
}
|
60
|
+
#endif
|
61
|
+
|
62
|
+
#endif /* RBFFI_POINTER_H */
|
63
|
+
|
data/ext/ffi_c/Struct.c
ADDED
@@ -0,0 +1,828 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2008, 2009, Wayne Meissner
|
3
|
+
* Copyright (C) 2009 Luc Heinrich <luc@honk-honk.com>
|
4
|
+
*
|
5
|
+
* Copyright (c) 2008-2013, Ruby FFI project contributors
|
6
|
+
* All rights reserved.
|
7
|
+
*
|
8
|
+
* Redistribution and use in source and binary forms, with or without
|
9
|
+
* modification, are permitted provided that the following conditions are met:
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above copyright
|
13
|
+
* notice, this list of conditions and the following disclaimer in the
|
14
|
+
* documentation and/or other materials provided with the distribution.
|
15
|
+
* * Neither the name of the Ruby FFI project nor the
|
16
|
+
* names of its contributors may be used to endorse or promote products
|
17
|
+
* derived from this software without specific prior written permission.
|
18
|
+
*
|
19
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
20
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
+
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
23
|
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
24
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
25
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
26
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
28
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
*/
|
30
|
+
|
31
|
+
#include <sys/types.h>
|
32
|
+
#ifndef _MSC_VER
|
33
|
+
# include <sys/param.h>
|
34
|
+
# include <stdint.h>
|
35
|
+
# include <stdbool.h>
|
36
|
+
#else
|
37
|
+
# include "win32/stdbool.h"
|
38
|
+
# include "win32/stdint.h"
|
39
|
+
#endif
|
40
|
+
#include <ruby.h>
|
41
|
+
#include "rbffi.h"
|
42
|
+
#include "compat.h"
|
43
|
+
#include "AbstractMemory.h"
|
44
|
+
#include "Pointer.h"
|
45
|
+
#include "MemoryPointer.h"
|
46
|
+
#include "Function.h"
|
47
|
+
#include "Types.h"
|
48
|
+
#include "Function.h"
|
49
|
+
#include "StructByValue.h"
|
50
|
+
#include "ArrayType.h"
|
51
|
+
#include "MappedType.h"
|
52
|
+
#include "Struct.h"
|
53
|
+
|
54
|
+
typedef struct InlineArray_ {
|
55
|
+
VALUE rbMemory;
|
56
|
+
VALUE rbField;
|
57
|
+
|
58
|
+
AbstractMemory* memory;
|
59
|
+
StructField* field;
|
60
|
+
MemoryOp *op;
|
61
|
+
Type* componentType;
|
62
|
+
ArrayType* arrayType;
|
63
|
+
int length;
|
64
|
+
} InlineArray;
|
65
|
+
|
66
|
+
|
67
|
+
static void struct_mark(Struct *);
|
68
|
+
static void struct_free(Struct *);
|
69
|
+
static VALUE struct_class_layout(VALUE klass);
|
70
|
+
static void struct_malloc(Struct* s);
|
71
|
+
static void inline_array_mark(InlineArray *);
|
72
|
+
static void store_reference_value(StructField* f, Struct* s, VALUE value);
|
73
|
+
|
74
|
+
VALUE rbffi_StructClass = Qnil;
|
75
|
+
|
76
|
+
VALUE rbffi_StructInlineArrayClass = Qnil;
|
77
|
+
VALUE rbffi_StructLayoutCharArrayClass = Qnil;
|
78
|
+
|
79
|
+
static ID id_pointer_ivar = 0, id_layout_ivar = 0;
|
80
|
+
static ID id_get = 0, id_put = 0, id_to_ptr = 0, id_to_s = 0, id_layout = 0;
|
81
|
+
|
82
|
+
static inline char*
|
83
|
+
memory_address(VALUE self)
|
84
|
+
{
|
85
|
+
return ((AbstractMemory *)DATA_PTR((self)))->address;
|
86
|
+
}
|
87
|
+
|
88
|
+
static VALUE
|
89
|
+
struct_allocate(VALUE klass)
|
90
|
+
{
|
91
|
+
Struct* s;
|
92
|
+
VALUE obj = Data_Make_Struct(klass, Struct, struct_mark, struct_free, s);
|
93
|
+
|
94
|
+
s->rbPointer = Qnil;
|
95
|
+
s->rbLayout = Qnil;
|
96
|
+
|
97
|
+
return obj;
|
98
|
+
}
|
99
|
+
|
100
|
+
/*
|
101
|
+
* call-seq: initialize
|
102
|
+
* @overload initialize(pointer, *args)
|
103
|
+
* @param [AbstractMemory] pointer
|
104
|
+
* @param [Array] args
|
105
|
+
* @return [self]
|
106
|
+
*/
|
107
|
+
static VALUE
|
108
|
+
struct_initialize(int argc, VALUE* argv, VALUE self)
|
109
|
+
{
|
110
|
+
Struct* s;
|
111
|
+
VALUE rbPointer = Qnil, rest = Qnil, klass = CLASS_OF(self);
|
112
|
+
int nargs;
|
113
|
+
|
114
|
+
Data_Get_Struct(self, Struct, s);
|
115
|
+
|
116
|
+
nargs = rb_scan_args(argc, argv, "01*", &rbPointer, &rest);
|
117
|
+
|
118
|
+
/* Call up into ruby code to adjust the layout */
|
119
|
+
if (nargs > 1) {
|
120
|
+
s->rbLayout = rb_funcall2(CLASS_OF(self), id_layout, (int) RARRAY_LEN(rest), RARRAY_PTR(rest));
|
121
|
+
} else {
|
122
|
+
s->rbLayout = struct_class_layout(klass);
|
123
|
+
}
|
124
|
+
|
125
|
+
if (!rb_obj_is_kind_of(s->rbLayout, rbffi_StructLayoutClass)) {
|
126
|
+
rb_raise(rb_eRuntimeError, "Invalid Struct layout");
|
127
|
+
}
|
128
|
+
|
129
|
+
Data_Get_Struct(s->rbLayout, StructLayout, s->layout);
|
130
|
+
|
131
|
+
if (rbPointer != Qnil) {
|
132
|
+
s->pointer = MEMORY(rbPointer);
|
133
|
+
s->rbPointer = rbPointer;
|
134
|
+
} else {
|
135
|
+
struct_malloc(s);
|
136
|
+
}
|
137
|
+
|
138
|
+
return self;
|
139
|
+
}
|
140
|
+
|
141
|
+
/*
|
142
|
+
* call-seq: initialize_copy(other)
|
143
|
+
* @return [nil]
|
144
|
+
* DO NOT CALL THIS METHOD
|
145
|
+
*/
|
146
|
+
static VALUE
|
147
|
+
struct_initialize_copy(VALUE self, VALUE other)
|
148
|
+
{
|
149
|
+
Struct* src;
|
150
|
+
Struct* dst;
|
151
|
+
|
152
|
+
Data_Get_Struct(self, Struct, dst);
|
153
|
+
Data_Get_Struct(other, Struct, src);
|
154
|
+
if (dst == src) {
|
155
|
+
return self;
|
156
|
+
}
|
157
|
+
|
158
|
+
dst->rbLayout = src->rbLayout;
|
159
|
+
dst->layout = src->layout;
|
160
|
+
|
161
|
+
/*
|
162
|
+
* A new MemoryPointer instance is allocated here instead of just calling
|
163
|
+
* #dup on rbPointer, since the Pointer may not know its length, or may
|
164
|
+
* be longer than just this struct.
|
165
|
+
*/
|
166
|
+
if (src->pointer->address != NULL) {
|
167
|
+
dst->rbPointer = rbffi_MemoryPointer_NewInstance(1, src->layout->size, false);
|
168
|
+
dst->pointer = MEMORY(dst->rbPointer);
|
169
|
+
memcpy(dst->pointer->address, src->pointer->address, src->layout->size);
|
170
|
+
} else {
|
171
|
+
dst->rbPointer = src->rbPointer;
|
172
|
+
dst->pointer = src->pointer;
|
173
|
+
}
|
174
|
+
|
175
|
+
if (src->layout->referenceFieldCount > 0) {
|
176
|
+
dst->rbReferences = ALLOC_N(VALUE, dst->layout->referenceFieldCount);
|
177
|
+
memcpy(dst->rbReferences, src->rbReferences, dst->layout->referenceFieldCount * sizeof(VALUE));
|
178
|
+
}
|
179
|
+
|
180
|
+
return self;
|
181
|
+
}
|
182
|
+
|
183
|
+
static VALUE
|
184
|
+
struct_class_layout(VALUE klass)
|
185
|
+
{
|
186
|
+
VALUE layout;
|
187
|
+
if (!rb_ivar_defined(klass, id_layout_ivar)) {
|
188
|
+
rb_raise(rb_eRuntimeError, "no Struct layout configured for %s", rb_class2name(klass));
|
189
|
+
}
|
190
|
+
|
191
|
+
layout = rb_ivar_get(klass, id_layout_ivar);
|
192
|
+
if (!rb_obj_is_kind_of(layout, rbffi_StructLayoutClass)) {
|
193
|
+
rb_raise(rb_eRuntimeError, "invalid Struct layout for %s", rb_class2name(klass));
|
194
|
+
}
|
195
|
+
|
196
|
+
return layout;
|
197
|
+
}
|
198
|
+
|
199
|
+
static StructLayout*
|
200
|
+
struct_layout(VALUE self)
|
201
|
+
{
|
202
|
+
Struct* s = (Struct *) DATA_PTR(self);
|
203
|
+
if (s->layout != NULL) {
|
204
|
+
return s->layout;
|
205
|
+
}
|
206
|
+
|
207
|
+
if (s->layout == NULL) {
|
208
|
+
s->rbLayout = struct_class_layout(CLASS_OF(self));
|
209
|
+
Data_Get_Struct(s->rbLayout, StructLayout, s->layout);
|
210
|
+
}
|
211
|
+
|
212
|
+
return s->layout;
|
213
|
+
}
|
214
|
+
|
215
|
+
static Struct*
|
216
|
+
struct_validate(VALUE self)
|
217
|
+
{
|
218
|
+
Struct* s;
|
219
|
+
Data_Get_Struct(self, Struct, s);
|
220
|
+
|
221
|
+
if (struct_layout(self) == NULL) {
|
222
|
+
rb_raise(rb_eRuntimeError, "struct layout == null");
|
223
|
+
}
|
224
|
+
|
225
|
+
if (s->pointer == NULL) {
|
226
|
+
struct_malloc(s);
|
227
|
+
}
|
228
|
+
|
229
|
+
return s;
|
230
|
+
}
|
231
|
+
|
232
|
+
static void
|
233
|
+
struct_malloc(Struct* s)
|
234
|
+
{
|
235
|
+
if (s->rbPointer == Qnil) {
|
236
|
+
s->rbPointer = rbffi_MemoryPointer_NewInstance(s->layout->size, 1, true);
|
237
|
+
|
238
|
+
} else if (!rb_obj_is_kind_of(s->rbPointer, rbffi_AbstractMemoryClass)) {
|
239
|
+
rb_raise(rb_eRuntimeError, "invalid pointer in struct");
|
240
|
+
}
|
241
|
+
|
242
|
+
s->pointer = (AbstractMemory *) DATA_PTR(s->rbPointer);
|
243
|
+
}
|
244
|
+
|
245
|
+
static void
|
246
|
+
struct_mark(Struct *s)
|
247
|
+
{
|
248
|
+
rb_gc_mark(s->rbPointer);
|
249
|
+
rb_gc_mark(s->rbLayout);
|
250
|
+
if (s->rbReferences != NULL) {
|
251
|
+
rb_gc_mark_locations(&s->rbReferences[0], &s->rbReferences[s->layout->referenceFieldCount]);
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
static void
|
256
|
+
struct_free(Struct* s)
|
257
|
+
{
|
258
|
+
xfree(s->rbReferences);
|
259
|
+
xfree(s);
|
260
|
+
}
|
261
|
+
|
262
|
+
|
263
|
+
static void
|
264
|
+
store_reference_value(StructField* f, Struct* s, VALUE value)
|
265
|
+
{
|
266
|
+
if (unlikely(f->referenceIndex == -1)) {
|
267
|
+
rb_raise(rb_eRuntimeError, "put_reference_value called for non-reference type");
|
268
|
+
return;
|
269
|
+
}
|
270
|
+
if (s->rbReferences == NULL) {
|
271
|
+
int i;
|
272
|
+
s->rbReferences = ALLOC_N(VALUE, s->layout->referenceFieldCount);
|
273
|
+
for (i = 0; i < s->layout->referenceFieldCount; ++i) {
|
274
|
+
s->rbReferences[i] = Qnil;
|
275
|
+
}
|
276
|
+
}
|
277
|
+
|
278
|
+
s->rbReferences[f->referenceIndex] = value;
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
static VALUE
|
283
|
+
struct_field(Struct* s, VALUE fieldName)
|
284
|
+
{
|
285
|
+
StructLayout* layout = s->layout;
|
286
|
+
VALUE rbField;
|
287
|
+
|
288
|
+
if (likely(SYMBOL_P(fieldName) && st_lookup(layout->fieldSymbolTable, fieldName, (st_data_t *) &rbField))) {
|
289
|
+
return rbField;
|
290
|
+
}
|
291
|
+
|
292
|
+
rbField = rb_hash_aref(layout->rbFieldMap, fieldName);
|
293
|
+
if (rbField == Qnil) {
|
294
|
+
VALUE str = rb_funcall2(fieldName, id_to_s, 0, NULL);
|
295
|
+
rb_raise(rb_eArgError, "No such field '%s'", StringValuePtr(str));
|
296
|
+
}
|
297
|
+
|
298
|
+
return rbField;
|
299
|
+
}
|
300
|
+
|
301
|
+
/*
|
302
|
+
* call-seq: struct[field_name]
|
303
|
+
* @param field_name field to access
|
304
|
+
* Acces to a Struct field.
|
305
|
+
*/
|
306
|
+
static VALUE
|
307
|
+
struct_aref(VALUE self, VALUE fieldName)
|
308
|
+
{
|
309
|
+
Struct* s;
|
310
|
+
VALUE rbField;
|
311
|
+
StructField* f;
|
312
|
+
|
313
|
+
s = struct_validate(self);
|
314
|
+
|
315
|
+
rbField = struct_field(s, fieldName);
|
316
|
+
f = (StructField *) DATA_PTR(rbField);
|
317
|
+
|
318
|
+
if (f->get != NULL) {
|
319
|
+
return (*f->get)(f, s);
|
320
|
+
|
321
|
+
} else if (f->memoryOp != NULL) {
|
322
|
+
return (*f->memoryOp->get)(s->pointer, f->offset);
|
323
|
+
|
324
|
+
} else {
|
325
|
+
|
326
|
+
/* call up to the ruby code to fetch the value */
|
327
|
+
return rb_funcall2(rbField, id_get, 1, &s->rbPointer);
|
328
|
+
}
|
329
|
+
}
|
330
|
+
|
331
|
+
/*
|
332
|
+
* call-seq: []=(field_name, value)
|
333
|
+
* @param field_name field to access
|
334
|
+
* @param value value to set to +field_name+
|
335
|
+
* @return [value]
|
336
|
+
* Set a field in Struct.
|
337
|
+
*/
|
338
|
+
static VALUE
|
339
|
+
struct_aset(VALUE self, VALUE fieldName, VALUE value)
|
340
|
+
{
|
341
|
+
Struct* s;
|
342
|
+
VALUE rbField;
|
343
|
+
StructField* f;
|
344
|
+
|
345
|
+
|
346
|
+
s = struct_validate(self);
|
347
|
+
|
348
|
+
rbField = struct_field(s, fieldName);
|
349
|
+
f = (StructField *) DATA_PTR(rbField);
|
350
|
+
if (f->put != NULL) {
|
351
|
+
(*f->put)(f, s, value);
|
352
|
+
|
353
|
+
} else if (f->memoryOp != NULL) {
|
354
|
+
|
355
|
+
(*f->memoryOp->put)(s->pointer, f->offset, value);
|
356
|
+
|
357
|
+
} else {
|
358
|
+
/* call up to the ruby code to set the value */
|
359
|
+
VALUE argv[2];
|
360
|
+
argv[0] = s->rbPointer;
|
361
|
+
argv[1] = value;
|
362
|
+
rb_funcall2(rbField, id_put, 2, argv);
|
363
|
+
}
|
364
|
+
|
365
|
+
if (f->referenceRequired) {
|
366
|
+
store_reference_value(f, s, value);
|
367
|
+
}
|
368
|
+
|
369
|
+
return value;
|
370
|
+
}
|
371
|
+
|
372
|
+
/*
|
373
|
+
* call-seq: pointer= pointer
|
374
|
+
* @param [AbstractMemory] pointer
|
375
|
+
* @return [self]
|
376
|
+
* Make Struct point to +pointer+.
|
377
|
+
*/
|
378
|
+
static VALUE
|
379
|
+
struct_set_pointer(VALUE self, VALUE pointer)
|
380
|
+
{
|
381
|
+
Struct* s;
|
382
|
+
StructLayout* layout;
|
383
|
+
AbstractMemory* memory;
|
384
|
+
|
385
|
+
if (!rb_obj_is_kind_of(pointer, rbffi_AbstractMemoryClass)) {
|
386
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected Pointer or Buffer)",
|
387
|
+
rb_obj_classname(pointer));
|
388
|
+
return Qnil;
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
Data_Get_Struct(self, Struct, s);
|
393
|
+
Data_Get_Struct(pointer, AbstractMemory, memory);
|
394
|
+
layout = struct_layout(self);
|
395
|
+
|
396
|
+
if ((int) layout->base.ffiType->size > memory->size) {
|
397
|
+
rb_raise(rb_eArgError, "memory of %ld bytes too small for struct %s (expected at least %ld)",
|
398
|
+
memory->size, rb_obj_classname(self), (long) layout->base.ffiType->size);
|
399
|
+
}
|
400
|
+
|
401
|
+
s->pointer = MEMORY(pointer);
|
402
|
+
s->rbPointer = pointer;
|
403
|
+
rb_ivar_set(self, id_pointer_ivar, pointer);
|
404
|
+
|
405
|
+
return self;
|
406
|
+
}
|
407
|
+
|
408
|
+
/*
|
409
|
+
* call-seq: pointer
|
410
|
+
* @return [AbstractMemory]
|
411
|
+
* Get pointer to Struct contents.
|
412
|
+
*/
|
413
|
+
static VALUE
|
414
|
+
struct_get_pointer(VALUE self)
|
415
|
+
{
|
416
|
+
Struct* s;
|
417
|
+
|
418
|
+
Data_Get_Struct(self, Struct, s);
|
419
|
+
|
420
|
+
return s->rbPointer;
|
421
|
+
}
|
422
|
+
|
423
|
+
/*
|
424
|
+
* call-seq: layout= layout
|
425
|
+
* @param [StructLayout] layout
|
426
|
+
* @return [self]
|
427
|
+
* Set the Struct's layout.
|
428
|
+
*/
|
429
|
+
static VALUE
|
430
|
+
struct_set_layout(VALUE self, VALUE layout)
|
431
|
+
{
|
432
|
+
Struct* s;
|
433
|
+
Data_Get_Struct(self, Struct, s);
|
434
|
+
|
435
|
+
if (!rb_obj_is_kind_of(layout, rbffi_StructLayoutClass)) {
|
436
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
|
437
|
+
rb_obj_classname(layout), rb_class2name(rbffi_StructLayoutClass));
|
438
|
+
return Qnil;
|
439
|
+
}
|
440
|
+
|
441
|
+
Data_Get_Struct(layout, StructLayout, s->layout);
|
442
|
+
rb_ivar_set(self, id_layout_ivar, layout);
|
443
|
+
|
444
|
+
return self;
|
445
|
+
}
|
446
|
+
|
447
|
+
/*
|
448
|
+
* call-seq: layout
|
449
|
+
* @return [StructLayout]
|
450
|
+
* Get the Struct's layout.
|
451
|
+
*/
|
452
|
+
static VALUE
|
453
|
+
struct_get_layout(VALUE self)
|
454
|
+
{
|
455
|
+
Struct* s;
|
456
|
+
|
457
|
+
Data_Get_Struct(self, Struct, s);
|
458
|
+
|
459
|
+
return s->rbLayout;
|
460
|
+
}
|
461
|
+
|
462
|
+
/*
|
463
|
+
* call-seq: null?
|
464
|
+
* @return [Boolean]
|
465
|
+
* Test if Struct's pointer is NULL
|
466
|
+
*/
|
467
|
+
static VALUE
|
468
|
+
struct_null_p(VALUE self)
|
469
|
+
{
|
470
|
+
Struct* s;
|
471
|
+
|
472
|
+
Data_Get_Struct(self, Struct, s);
|
473
|
+
|
474
|
+
return s->pointer->address == NULL ? Qtrue : Qfalse;
|
475
|
+
}
|
476
|
+
|
477
|
+
/*
|
478
|
+
* (see Pointer#order)
|
479
|
+
*/
|
480
|
+
static VALUE
|
481
|
+
struct_order(int argc, VALUE* argv, VALUE self)
|
482
|
+
{
|
483
|
+
Struct* s;
|
484
|
+
|
485
|
+
Data_Get_Struct(self, Struct, s);
|
486
|
+
if (argc == 0) {
|
487
|
+
return rb_funcall(s->rbPointer, rb_intern("order"), 0);
|
488
|
+
|
489
|
+
} else {
|
490
|
+
VALUE retval = rb_obj_dup(self);
|
491
|
+
VALUE rbPointer = rb_funcall2(s->rbPointer, rb_intern("order"), argc, argv);
|
492
|
+
struct_set_pointer(retval, rbPointer);
|
493
|
+
|
494
|
+
return retval;
|
495
|
+
}
|
496
|
+
}
|
497
|
+
|
498
|
+
static VALUE
|
499
|
+
inline_array_allocate(VALUE klass)
|
500
|
+
{
|
501
|
+
InlineArray* array;
|
502
|
+
VALUE obj;
|
503
|
+
|
504
|
+
obj = Data_Make_Struct(klass, InlineArray, inline_array_mark, -1, array);
|
505
|
+
array->rbField = Qnil;
|
506
|
+
array->rbMemory = Qnil;
|
507
|
+
|
508
|
+
return obj;
|
509
|
+
}
|
510
|
+
|
511
|
+
static void
|
512
|
+
inline_array_mark(InlineArray* array)
|
513
|
+
{
|
514
|
+
rb_gc_mark(array->rbField);
|
515
|
+
rb_gc_mark(array->rbMemory);
|
516
|
+
}
|
517
|
+
|
518
|
+
/*
|
519
|
+
* Document-method: FFI::Struct::InlineArray#initialize
|
520
|
+
* call-seq: initialize(memory, field)
|
521
|
+
* @param [AbstractMemory] memory
|
522
|
+
* @param [StructField] field
|
523
|
+
* @return [self]
|
524
|
+
*/
|
525
|
+
static VALUE
|
526
|
+
inline_array_initialize(VALUE self, VALUE rbMemory, VALUE rbField)
|
527
|
+
{
|
528
|
+
InlineArray* array;
|
529
|
+
|
530
|
+
Data_Get_Struct(self, InlineArray, array);
|
531
|
+
array->rbMemory = rbMemory;
|
532
|
+
array->rbField = rbField;
|
533
|
+
|
534
|
+
Data_Get_Struct(rbMemory, AbstractMemory, array->memory);
|
535
|
+
Data_Get_Struct(rbField, StructField, array->field);
|
536
|
+
Data_Get_Struct(array->field->rbType, ArrayType, array->arrayType);
|
537
|
+
Data_Get_Struct(array->arrayType->rbComponentType, Type, array->componentType);
|
538
|
+
|
539
|
+
array->op = get_memory_op(array->componentType);
|
540
|
+
if (array->op == NULL && array->componentType->nativeType == NATIVE_MAPPED) {
|
541
|
+
array->op = get_memory_op(((MappedType *) array->componentType)->type);
|
542
|
+
}
|
543
|
+
|
544
|
+
array->length = array->arrayType->length;
|
545
|
+
|
546
|
+
return self;
|
547
|
+
}
|
548
|
+
|
549
|
+
/*
|
550
|
+
* call-seq: size
|
551
|
+
* @return [Numeric]
|
552
|
+
* Get size
|
553
|
+
*/
|
554
|
+
static VALUE
|
555
|
+
inline_array_size(VALUE self)
|
556
|
+
{
|
557
|
+
InlineArray* array;
|
558
|
+
|
559
|
+
Data_Get_Struct(self, InlineArray, array);
|
560
|
+
|
561
|
+
return UINT2NUM(((ArrayType *) array->field->type)->length);
|
562
|
+
}
|
563
|
+
|
564
|
+
static int
|
565
|
+
inline_array_offset(InlineArray* array, int index)
|
566
|
+
{
|
567
|
+
if (index < 0 || (index >= array->length && array->length > 0)) {
|
568
|
+
rb_raise(rb_eIndexError, "index %d out of bounds", index);
|
569
|
+
}
|
570
|
+
|
571
|
+
return (int) array->field->offset + (index * (int) array->componentType->ffiType->size);
|
572
|
+
}
|
573
|
+
|
574
|
+
/*
|
575
|
+
* call-seq: [](index)
|
576
|
+
* @param [Numeric] index
|
577
|
+
* @return [Type, Struct]
|
578
|
+
*/
|
579
|
+
static VALUE
|
580
|
+
inline_array_aref(VALUE self, VALUE rbIndex)
|
581
|
+
{
|
582
|
+
InlineArray* array;
|
583
|
+
|
584
|
+
Data_Get_Struct(self, InlineArray, array);
|
585
|
+
|
586
|
+
if (array->op != NULL) {
|
587
|
+
VALUE rbNativeValue = array->op->get(array->memory,
|
588
|
+
inline_array_offset(array, NUM2INT(rbIndex)));
|
589
|
+
if (unlikely(array->componentType->nativeType == NATIVE_MAPPED)) {
|
590
|
+
return rb_funcall(((MappedType *) array->componentType)->rbConverter,
|
591
|
+
rb_intern("from_native"), 2, rbNativeValue, Qnil);
|
592
|
+
} else {
|
593
|
+
return rbNativeValue;
|
594
|
+
}
|
595
|
+
|
596
|
+
} else if (array->componentType->nativeType == NATIVE_STRUCT) {
|
597
|
+
VALUE rbOffset = INT2NUM(inline_array_offset(array, NUM2INT(rbIndex)));
|
598
|
+
VALUE rbLength = INT2NUM(array->componentType->ffiType->size);
|
599
|
+
VALUE rbPointer = rb_funcall(array->rbMemory, rb_intern("slice"), 2, rbOffset, rbLength);
|
600
|
+
|
601
|
+
return rb_class_new_instance(1, &rbPointer, ((StructByValue *) array->componentType)->rbStructClass);
|
602
|
+
} else {
|
603
|
+
|
604
|
+
rb_raise(rb_eArgError, "get not supported for %s", rb_obj_classname(array->arrayType->rbComponentType));
|
605
|
+
return Qnil;
|
606
|
+
}
|
607
|
+
}
|
608
|
+
|
609
|
+
/*
|
610
|
+
* call-seq: []=(index, value)
|
611
|
+
* @param [Numeric] index
|
612
|
+
* @param [Type, Struct]
|
613
|
+
* @return [value]
|
614
|
+
*/
|
615
|
+
static VALUE
|
616
|
+
inline_array_aset(VALUE self, VALUE rbIndex, VALUE rbValue)
|
617
|
+
{
|
618
|
+
InlineArray* array;
|
619
|
+
|
620
|
+
Data_Get_Struct(self, InlineArray, array);
|
621
|
+
|
622
|
+
if (array->op != NULL) {
|
623
|
+
if (unlikely(array->componentType->nativeType == NATIVE_MAPPED)) {
|
624
|
+
rbValue = rb_funcall(((MappedType *) array->componentType)->rbConverter,
|
625
|
+
rb_intern("to_native"), 2, rbValue, Qnil);
|
626
|
+
}
|
627
|
+
array->op->put(array->memory, inline_array_offset(array, NUM2INT(rbIndex)),
|
628
|
+
rbValue);
|
629
|
+
|
630
|
+
} else if (array->componentType->nativeType == NATIVE_STRUCT) {
|
631
|
+
int offset = inline_array_offset(array, NUM2INT(rbIndex));
|
632
|
+
Struct* s;
|
633
|
+
|
634
|
+
if (!rb_obj_is_kind_of(rbValue, rbffi_StructClass)) {
|
635
|
+
rb_raise(rb_eTypeError, "argument not an instance of struct");
|
636
|
+
return Qnil;
|
637
|
+
}
|
638
|
+
|
639
|
+
checkWrite(array->memory);
|
640
|
+
checkBounds(array->memory, offset, array->componentType->ffiType->size);
|
641
|
+
|
642
|
+
Data_Get_Struct(rbValue, Struct, s);
|
643
|
+
checkRead(s->pointer);
|
644
|
+
checkBounds(s->pointer, 0, array->componentType->ffiType->size);
|
645
|
+
|
646
|
+
memcpy(array->memory->address + offset, s->pointer->address, array->componentType->ffiType->size);
|
647
|
+
|
648
|
+
} else {
|
649
|
+
ArrayType* arrayType;
|
650
|
+
Data_Get_Struct(array->field->rbType, ArrayType, arrayType);
|
651
|
+
|
652
|
+
rb_raise(rb_eArgError, "set not supported for %s", rb_obj_classname(arrayType->rbComponentType));
|
653
|
+
return Qnil;
|
654
|
+
}
|
655
|
+
|
656
|
+
return rbValue;
|
657
|
+
}
|
658
|
+
|
659
|
+
/*
|
660
|
+
* call-seq: each
|
661
|
+
* Yield block for each element of +self+.
|
662
|
+
*/
|
663
|
+
static VALUE
|
664
|
+
inline_array_each(VALUE self)
|
665
|
+
{
|
666
|
+
InlineArray* array;
|
667
|
+
|
668
|
+
int i;
|
669
|
+
|
670
|
+
Data_Get_Struct(self, InlineArray, array);
|
671
|
+
|
672
|
+
for (i = 0; i < array->length; ++i) {
|
673
|
+
rb_yield(inline_array_aref(self, INT2FIX(i)));
|
674
|
+
}
|
675
|
+
|
676
|
+
return self;
|
677
|
+
}
|
678
|
+
|
679
|
+
/*
|
680
|
+
* call-seq: to_a
|
681
|
+
* @return [Array]
|
682
|
+
* Convert +self+ to an array.
|
683
|
+
*/
|
684
|
+
static VALUE
|
685
|
+
inline_array_to_a(VALUE self)
|
686
|
+
{
|
687
|
+
InlineArray* array;
|
688
|
+
VALUE obj;
|
689
|
+
int i;
|
690
|
+
|
691
|
+
Data_Get_Struct(self, InlineArray, array);
|
692
|
+
obj = rb_ary_new2(array->length);
|
693
|
+
|
694
|
+
|
695
|
+
for (i = 0; i < array->length; ++i) {
|
696
|
+
rb_ary_push(obj, inline_array_aref(self, INT2FIX(i)));
|
697
|
+
}
|
698
|
+
|
699
|
+
return obj;
|
700
|
+
}
|
701
|
+
|
702
|
+
/*
|
703
|
+
* Document-method: FFI::StructLayout::CharArray#to_s
|
704
|
+
* call-seq: to_s
|
705
|
+
* @return [String]
|
706
|
+
* Convert +self+ to a string.
|
707
|
+
*/
|
708
|
+
static VALUE
|
709
|
+
inline_array_to_s(VALUE self)
|
710
|
+
{
|
711
|
+
InlineArray* array;
|
712
|
+
VALUE argv[2];
|
713
|
+
|
714
|
+
Data_Get_Struct(self, InlineArray, array);
|
715
|
+
|
716
|
+
if (array->componentType->nativeType != NATIVE_INT8 && array->componentType->nativeType != NATIVE_UINT8) {
|
717
|
+
VALUE dummy = Qnil;
|
718
|
+
return rb_call_super(0, &dummy);
|
719
|
+
}
|
720
|
+
|
721
|
+
argv[0] = UINT2NUM(array->field->offset);
|
722
|
+
argv[1] = UINT2NUM(array->length);
|
723
|
+
|
724
|
+
return rb_funcall2(array->rbMemory, rb_intern("get_string"), 2, argv);
|
725
|
+
}
|
726
|
+
|
727
|
+
/*
|
728
|
+
* call-seq: to_ptr
|
729
|
+
* @return [AbstractMemory]
|
730
|
+
* Get pointer to +self+ content.
|
731
|
+
*/
|
732
|
+
static VALUE
|
733
|
+
inline_array_to_ptr(VALUE self)
|
734
|
+
{
|
735
|
+
InlineArray* array;
|
736
|
+
|
737
|
+
Data_Get_Struct(self, InlineArray, array);
|
738
|
+
|
739
|
+
return rb_funcall(array->rbMemory, rb_intern("slice"), 2,
|
740
|
+
UINT2NUM(array->field->offset), UINT2NUM(array->arrayType->base.ffiType->size));
|
741
|
+
}
|
742
|
+
|
743
|
+
|
744
|
+
void
|
745
|
+
rbffi_Struct_Init(VALUE moduleFFI)
|
746
|
+
{
|
747
|
+
VALUE StructClass;
|
748
|
+
|
749
|
+
rbffi_StructLayout_Init(moduleFFI);
|
750
|
+
|
751
|
+
/*
|
752
|
+
* Document-class: FFI::Struct
|
753
|
+
*
|
754
|
+
* A FFI::Struct means to mirror a C struct.
|
755
|
+
*
|
756
|
+
* A Struct is defined as:
|
757
|
+
* class MyStruct < FFI::Struct
|
758
|
+
* layout :value1, :int,
|
759
|
+
* :value2, :double
|
760
|
+
* end
|
761
|
+
* and is used as:
|
762
|
+
* my_struct = MyStruct.new
|
763
|
+
* my_struct[:value1] = 12
|
764
|
+
*
|
765
|
+
* For more information, see http://github.com/ffi/ffi/wiki/Structs
|
766
|
+
*/
|
767
|
+
rbffi_StructClass = rb_define_class_under(moduleFFI, "Struct", rb_cObject);
|
768
|
+
StructClass = rbffi_StructClass; // put on a line alone to help RDoc
|
769
|
+
rb_global_variable(&rbffi_StructClass);
|
770
|
+
|
771
|
+
/*
|
772
|
+
* Document-class: FFI::Struct::InlineArray
|
773
|
+
*/
|
774
|
+
rbffi_StructInlineArrayClass = rb_define_class_under(rbffi_StructClass, "InlineArray", rb_cObject);
|
775
|
+
rb_global_variable(&rbffi_StructInlineArrayClass);
|
776
|
+
|
777
|
+
/*
|
778
|
+
* Document-class: FFI::StructLayout::CharArray < FFI::Struct::InlineArray
|
779
|
+
*/
|
780
|
+
rbffi_StructLayoutCharArrayClass = rb_define_class_under(rbffi_StructLayoutClass, "CharArray",
|
781
|
+
rbffi_StructInlineArrayClass);
|
782
|
+
rb_global_variable(&rbffi_StructLayoutCharArrayClass);
|
783
|
+
|
784
|
+
|
785
|
+
rb_define_alloc_func(StructClass, struct_allocate);
|
786
|
+
rb_define_method(StructClass, "initialize", struct_initialize, -1);
|
787
|
+
rb_define_method(StructClass, "initialize_copy", struct_initialize_copy, 1);
|
788
|
+
rb_define_method(StructClass, "order", struct_order, -1);
|
789
|
+
|
790
|
+
rb_define_alias(rb_singleton_class(StructClass), "alloc_in", "new");
|
791
|
+
rb_define_alias(rb_singleton_class(StructClass), "alloc_out", "new");
|
792
|
+
rb_define_alias(rb_singleton_class(StructClass), "alloc_inout", "new");
|
793
|
+
rb_define_alias(rb_singleton_class(StructClass), "new_in", "new");
|
794
|
+
rb_define_alias(rb_singleton_class(StructClass), "new_out", "new");
|
795
|
+
rb_define_alias(rb_singleton_class(StructClass), "new_inout", "new");
|
796
|
+
|
797
|
+
rb_define_method(StructClass, "pointer", struct_get_pointer, 0);
|
798
|
+
rb_define_private_method(StructClass, "pointer=", struct_set_pointer, 1);
|
799
|
+
|
800
|
+
rb_define_method(StructClass, "layout", struct_get_layout, 0);
|
801
|
+
rb_define_private_method(StructClass, "layout=", struct_set_layout, 1);
|
802
|
+
|
803
|
+
rb_define_method(StructClass, "[]", struct_aref, 1);
|
804
|
+
rb_define_method(StructClass, "[]=", struct_aset, 2);
|
805
|
+
rb_define_method(StructClass, "null?", struct_null_p, 0);
|
806
|
+
|
807
|
+
rb_include_module(rbffi_StructInlineArrayClass, rb_mEnumerable);
|
808
|
+
rb_define_alloc_func(rbffi_StructInlineArrayClass, inline_array_allocate);
|
809
|
+
rb_define_method(rbffi_StructInlineArrayClass, "initialize", inline_array_initialize, 2);
|
810
|
+
rb_define_method(rbffi_StructInlineArrayClass, "[]", inline_array_aref, 1);
|
811
|
+
rb_define_method(rbffi_StructInlineArrayClass, "[]=", inline_array_aset, 2);
|
812
|
+
rb_define_method(rbffi_StructInlineArrayClass, "each", inline_array_each, 0);
|
813
|
+
rb_define_method(rbffi_StructInlineArrayClass, "size", inline_array_size, 0);
|
814
|
+
rb_define_method(rbffi_StructInlineArrayClass, "to_a", inline_array_to_a, 0);
|
815
|
+
rb_define_method(rbffi_StructInlineArrayClass, "to_ptr", inline_array_to_ptr, 0);
|
816
|
+
|
817
|
+
rb_define_method(rbffi_StructLayoutCharArrayClass, "to_s", inline_array_to_s, 0);
|
818
|
+
rb_define_alias(rbffi_StructLayoutCharArrayClass, "to_str", "to_s");
|
819
|
+
|
820
|
+
id_pointer_ivar = rb_intern("@pointer");
|
821
|
+
id_layout_ivar = rb_intern("@layout");
|
822
|
+
id_layout = rb_intern("layout");
|
823
|
+
id_get = rb_intern("get");
|
824
|
+
id_put = rb_intern("put");
|
825
|
+
id_to_ptr = rb_intern("to_ptr");
|
826
|
+
id_to_s = rb_intern("to_s");
|
827
|
+
}
|
828
|
+
|