ffi 0.2.0 → 0.3.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/README.rdoc +19 -0
- data/Rakefile +65 -55
- data/ext/{AbstractMemory.c → ffi_c/AbstractMemory.c} +67 -40
- data/ext/{AbstractMemory.h → ffi_c/AbstractMemory.h} +10 -8
- data/ext/{AutoPointer.c → ffi_c/AutoPointer.c} +17 -8
- data/ext/{AutoPointer.h → ffi_c/AutoPointer.h} +0 -0
- data/ext/ffi_c/Buffer.c +136 -0
- data/ext/{Callback.c → ffi_c/Callback.c} +60 -35
- data/ext/{Callback.h → ffi_c/Callback.h} +1 -7
- data/ext/{Invoker.c → ffi_c/Invoker.c} +472 -102
- data/ext/ffi_c/MemoryPointer.c +146 -0
- data/ext/{MemoryPointer.h → ffi_c/MemoryPointer.h} +2 -7
- data/ext/ffi_c/NativeLibrary.c +149 -0
- data/ext/{NativeLibrary.h → ffi_c/NativeLibrary.h} +0 -0
- data/ext/ffi_c/NullPointer.c +104 -0
- data/ext/{Platform.c → ffi_c/Platform.c} +0 -0
- data/ext/{Platform.h → ffi_c/Platform.h} +0 -7
- data/ext/{Pointer.c → ffi_c/Pointer.c} +35 -15
- data/ext/{Pointer.h → ffi_c/Pointer.h} +4 -2
- data/ext/ffi_c/Struct.c +542 -0
- data/ext/ffi_c/Struct.h +26 -0
- data/ext/ffi_c/Types.c +76 -0
- data/ext/{Types.h → ffi_c/Types.h} +23 -28
- data/ext/{compat.h → ffi_c/compat.h} +2 -2
- data/ext/{extconf.rb → ffi_c/extconf.rb} +12 -7
- data/ext/ffi_c/ffi.c +99 -0
- data/ext/ffi_c/ffi.mk +23 -0
- data/ext/{libffi.darwin.mk → ffi_c/libffi.darwin.mk} +0 -0
- data/ext/ffi_c/libffi.mk +11 -0
- data/ext/{libffi → ffi_c/libffi}/ChangeLog +0 -0
- data/ext/{libffi → ffi_c/libffi}/ChangeLog.libffi +0 -0
- data/ext/{libffi → ffi_c/libffi}/ChangeLog.libgcj +0 -0
- data/ext/{libffi → ffi_c/libffi}/ChangeLog.v1 +0 -0
- data/ext/{libffi → ffi_c/libffi}/LICENSE +0 -0
- data/ext/{libffi → ffi_c/libffi}/Makefile.am +0 -0
- data/ext/{libffi → ffi_c/libffi}/Makefile.in +0 -0
- data/ext/{libffi → ffi_c/libffi}/README +0 -0
- data/ext/{libffi → ffi_c/libffi}/TODO +0 -0
- data/ext/{libffi → ffi_c/libffi}/acinclude.m4 +0 -0
- data/ext/{libffi → ffi_c/libffi}/aclocal.m4 +0 -0
- data/ext/{libffi → ffi_c/libffi}/compile +0 -0
- data/ext/{libffi → ffi_c/libffi}/config.guess +0 -0
- data/ext/{libffi → ffi_c/libffi}/config.sub +0 -0
- data/ext/{libffi → ffi_c/libffi}/configure +0 -0
- data/ext/{libffi → ffi_c/libffi}/configure.ac +0 -0
- data/ext/{libffi → ffi_c/libffi}/configure.host +0 -0
- data/ext/{libffi → ffi_c/libffi}/depcomp +0 -0
- data/ext/{libffi → ffi_c/libffi}/doc/libffi.info +0 -0
- data/ext/{libffi → ffi_c/libffi}/doc/libffi.texi +0 -0
- data/ext/{libffi → ffi_c/libffi}/doc/stamp-vti +0 -0
- data/ext/{libffi → ffi_c/libffi}/doc/version.texi +0 -0
- data/ext/{libffi → ffi_c/libffi}/fficonfig.h.in +0 -0
- data/ext/{libffi → ffi_c/libffi}/include/Makefile.am +0 -0
- data/ext/{libffi → ffi_c/libffi}/include/Makefile.in +0 -0
- data/ext/{libffi → ffi_c/libffi}/include/ffi.h.in +0 -0
- data/ext/{libffi → ffi_c/libffi}/include/ffi_common.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/install-sh +0 -0
- data/ext/{libffi → ffi_c/libffi}/libffi.pc.in +0 -0
- data/ext/{libffi → ffi_c/libffi}/libtool-version +0 -0
- data/ext/{libffi → ffi_c/libffi}/ltcf-c.sh +0 -0
- data/ext/{libffi → ffi_c/libffi}/ltcf-cxx.sh +0 -0
- data/ext/{libffi → ffi_c/libffi}/ltcf-gcj.sh +0 -0
- data/ext/{libffi → ffi_c/libffi}/ltconfig +0 -0
- data/ext/{libffi → ffi_c/libffi}/ltmain.sh +0 -0
- data/ext/{libffi → ffi_c/libffi}/man/Makefile.am +0 -0
- data/ext/{libffi → ffi_c/libffi}/man/Makefile.in +0 -0
- data/ext/{libffi → ffi_c/libffi}/man/ffi.3 +0 -0
- data/ext/{libffi → ffi_c/libffi}/man/ffi_call.3 +0 -0
- data/ext/{libffi → ffi_c/libffi}/man/ffi_prep_cif.3 +0 -0
- data/ext/{libffi → ffi_c/libffi}/mdate-sh +0 -0
- data/ext/{libffi → ffi_c/libffi}/missing +0 -0
- data/ext/{libffi → ffi_c/libffi}/mkinstalldirs +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/alpha/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/alpha/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/alpha/osf.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/arm/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/arm/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/arm/sysv.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/closures.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/cris/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/cris/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/cris/sysv.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/debug.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/dlmalloc.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/frv/eabi.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/frv/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/frv/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/ia64/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/ia64/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/ia64/ia64_flags.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/ia64/unix.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/java_raw_api.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/m32r/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/m32r/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/m32r/sysv.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/m68k/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/m68k/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/m68k/sysv.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/mips/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/mips/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/mips/n32.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/mips/o32.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/pa/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/pa/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/pa/hpux32.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/pa/linux.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/powerpc/aix.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/powerpc/aix_closure.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/powerpc/asm.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/powerpc/darwin.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/powerpc/darwin_closure.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/powerpc/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/powerpc/ffi_darwin.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/powerpc/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/powerpc/linux64.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/powerpc/linux64_closure.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/powerpc/ppc_closure.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/powerpc/sysv.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/prep_cif.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/raw_api.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/s390/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/s390/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/s390/sysv.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/sh/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/sh/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/sh/sysv.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/sh64/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/sh64/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/sh64/sysv.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/sparc/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/sparc/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/sparc/v8.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/sparc/v9.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/types.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/x86/darwin.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/x86/darwin64.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/x86/ffi.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/x86/ffi64.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/x86/ffitarget.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/x86/freebsd.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/x86/sysv.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/x86/unix64.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/src/x86/win32.S +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/Makefile.am +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/Makefile.in +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/config/default.exp +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/lib/libffi-dg.exp +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/lib/target-libpath.exp +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/lib/wrapper.exp +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/call.exp +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn0.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn1.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn2.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn3.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn4.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn5.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn6.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_stdcall.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_12byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_16byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_18byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_19byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_1_1byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_20byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_20byte1.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_24byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_2byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_3_1byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_3byte1.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_3byte2.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_4_1byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_4byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_5_1_byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_5byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_64byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_6_1_byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_6byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_7_1_byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_7byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_8byte.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_9byte1.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_9byte2.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_double.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_float.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_longdouble.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_pointer.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_sint16.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_sint32.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_sint64.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_uint16.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_uint32.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_uint64.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_double.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_float.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_multi_schar.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_multi_sshort.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_multi_sshortchar.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_multi_uchar.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_multi_ushort.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_multi_ushortchar.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_schar.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_sint.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_sshort.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_uchar.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_uint.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_ulonglong.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_ushort.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/ffitest.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/float.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/float1.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/float2.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/float3.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/float4.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/many.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/many_win32.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/negint.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct1.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct10.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct2.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct3.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct4.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct5.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct6.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct7.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct8.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct9.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/problem1.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/promotion.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/pyobjc-tc.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_dbl.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_dbl1.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_dbl2.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_fl.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_fl1.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_fl2.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_fl3.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_ldl.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_ll.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_ll1.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_sc.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_sl.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_uc.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_ul.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/strlen.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/strlen_win32.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct1.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct2.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct3.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct4.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct5.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct6.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct7.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct8.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct9.c +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.special/ffitestcxx.h +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.special/special.exp +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.special/unwindtest.cc +0 -0
- data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.special/unwindtest_ffi_call.cc +0 -0
- data/ext/{libffi → ffi_c/libffi}/texinfo.tex +0 -0
- data/ext/{rbffi.h → ffi_c/rbffi.h} +1 -8
- data/lib/ffi/autopointer.rb +7 -7
- data/lib/ffi/buffer.rb +0 -25
- data/lib/ffi/ffi.rb +1 -0
- data/lib/ffi/library.rb +103 -37
- data/lib/ffi/memorypointer.rb +25 -28
- data/lib/ffi/platform.rb +2 -2
- data/lib/ffi/pointer.rb +21 -7
- data/lib/ffi/struct.rb +161 -179
- data/lib/ffi/types.rb +3 -3
- data/lib/ffi/union.rb +17 -0
- data/nbproject/configurations.xml +98 -88
- data/samples/hello.rb +1 -2
- data/samples/sample_helper.rb +6 -0
- data/{specs → spec/ffi}/buffer_spec.rb +0 -0
- data/{specs → spec/ffi}/callback_spec.rb +114 -89
- data/{specs → spec/ffi}/errno_spec.rb +0 -0
- data/spec/ffi/library_spec.rb +144 -0
- data/{specs → spec/ffi}/managed_struct_spec.rb +12 -1
- data/{specs → spec/ffi}/number_spec.rb +34 -16
- data/{specs → spec/ffi}/pointer_spec.rb +46 -2
- data/{specs → spec/ffi}/rbx/attach_function_spec.rb +2 -1
- data/{specs → spec/ffi}/rbx/memory_pointer_spec.rb +19 -19
- data/{specs → spec/ffi}/rbx/spec_helper.rb +0 -0
- data/{specs → spec/ffi}/rbx/struct_spec.rb +0 -0
- data/spec/ffi/spec_helper.rb +13 -0
- data/{specs → spec/ffi}/string_spec.rb +8 -0
- data/spec/ffi/struct_spec.rb +453 -0
- data/{specs → spec/ffi}/typedef_spec.rb +3 -3
- data/spec/ffi/union_spec.rb +60 -0
- data/{specs → spec/ffi}/variadic_spec.rb +0 -0
- data/spec/spec.opts +4 -0
- metadata +356 -334
- data/README +0 -0
- data/ext/Buffer.c +0 -98
- data/ext/MemoryPointer.c +0 -99
- data/ext/NativeLibrary.c +0 -90
- data/ext/Types.c +0 -76
- data/ext/ffi.c +0 -64
- data/ext/ffi.mk +0 -24
- data/ext/libffi.mk +0 -10
- data/gen/Rakefile +0 -12
- data/specs/library_spec.rb +0 -55
- data/specs/spec_helper.rb +0 -9
- data/specs/struct_spec.rb +0 -223
@@ -9,9 +9,11 @@ extern "C" {
|
|
9
9
|
|
10
10
|
|
11
11
|
extern void rb_FFI_Pointer_Init(void);
|
12
|
-
extern
|
12
|
+
extern void rb_FFI_NullPointer_Init();
|
13
|
+
extern VALUE rb_FFI_Pointer_new(void* addr);
|
13
14
|
extern VALUE rb_FFI_Pointer_class;
|
14
|
-
|
15
|
+
extern VALUE rb_FFI_NullPointer_class;
|
16
|
+
extern VALUE rb_FFI_NullPointer_singleton;
|
15
17
|
|
16
18
|
#ifdef __cplusplus
|
17
19
|
}
|
data/ext/ffi_c/Struct.c
ADDED
@@ -0,0 +1,542 @@
|
|
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 "compat.h"
|
8
|
+
#include "AbstractMemory.h"
|
9
|
+
#include "Pointer.h"
|
10
|
+
#include "MemoryPointer.h"
|
11
|
+
#include "Types.h"
|
12
|
+
#include "Struct.h"
|
13
|
+
|
14
|
+
typedef struct StructField {
|
15
|
+
unsigned int type;
|
16
|
+
unsigned int offset;
|
17
|
+
unsigned int size;
|
18
|
+
unsigned int align;
|
19
|
+
} StructField;
|
20
|
+
|
21
|
+
typedef struct StructLayout {
|
22
|
+
VALUE rbFields;
|
23
|
+
unsigned int fieldCount;
|
24
|
+
int size;
|
25
|
+
int align;
|
26
|
+
} StructLayout;
|
27
|
+
|
28
|
+
typedef struct StructLayoutBuilder {
|
29
|
+
unsigned int offset;
|
30
|
+
} StructLayoutBuilder;
|
31
|
+
|
32
|
+
static void struct_field_mark(StructField *);
|
33
|
+
static void struct_field_free(StructField *);
|
34
|
+
static void struct_mark(Struct *);
|
35
|
+
static void struct_free(Struct *);
|
36
|
+
static void struct_layout_mark(StructLayout *);
|
37
|
+
static void struct_layout_free(StructLayout *);
|
38
|
+
|
39
|
+
VALUE rb_FFI_Struct_class = Qnil;
|
40
|
+
static VALUE classStruct = Qnil, classStructLayout = Qnil;
|
41
|
+
static VALUE classStructField = Qnil, classStructLayoutBuilder = Qnil;
|
42
|
+
static ID pointerID = 0, layoutID = 0, SIZE_ID, ALIGN_ID;
|
43
|
+
static ID getID = 0, putID = 0, to_ptr = 0;
|
44
|
+
|
45
|
+
#define FIELD_CAST(obj) ((StructField *)((TYPE(obj) == T_DATA && rb_obj_is_kind_of(obj, classStructField)) \
|
46
|
+
? DATA_PTR(obj) : (rb_raise(rb_eArgError, "StructField expected"), NULL)))
|
47
|
+
|
48
|
+
#define LAYOUT_CAST(obj) ((StructLayout *)((TYPE(obj) == T_DATA && rb_obj_is_kind_of(obj, classStructLayout)) \
|
49
|
+
? DATA_PTR(obj) : (rb_raise(rb_eArgError, "StructLayout expected"), NULL)))
|
50
|
+
|
51
|
+
static VALUE
|
52
|
+
struct_field_allocate(VALUE klass)
|
53
|
+
{
|
54
|
+
StructField* field;
|
55
|
+
return Data_Make_Struct(klass, StructField, struct_field_mark, struct_field_free, field);
|
56
|
+
}
|
57
|
+
|
58
|
+
static VALUE
|
59
|
+
struct_field_initialize(int argc, VALUE* argv, VALUE self)
|
60
|
+
{
|
61
|
+
VALUE offset = Qnil, info = Qnil;
|
62
|
+
StructField* field;
|
63
|
+
int nargs;
|
64
|
+
|
65
|
+
Data_Get_Struct(self, StructField, field);
|
66
|
+
|
67
|
+
nargs = rb_scan_args(argc, argv, "11", &offset, &info);
|
68
|
+
|
69
|
+
field->offset = NUM2UINT(offset);
|
70
|
+
if (rb_const_defined(CLASS_OF(self), rb_intern("TYPE"))) {
|
71
|
+
field->type = NUM2UINT(rb_const_get(CLASS_OF(self), rb_intern("TYPE")));
|
72
|
+
} else {
|
73
|
+
field->type = ~0;
|
74
|
+
}
|
75
|
+
#ifdef notyet
|
76
|
+
field->size = NUM2UINT(rb_const_get(klass, rb_intern("SIZE")));
|
77
|
+
field->align = NUM2UINT(rb_const_get(klass, rb_intern("ALIGN")));
|
78
|
+
#endif
|
79
|
+
rb_iv_set(self, "@off", offset);
|
80
|
+
rb_iv_set(self, "@info", info);
|
81
|
+
return self;
|
82
|
+
}
|
83
|
+
|
84
|
+
static VALUE
|
85
|
+
struct_field_offset(VALUE self)
|
86
|
+
{
|
87
|
+
StructField* field;
|
88
|
+
Data_Get_Struct(self, StructField, field);
|
89
|
+
return UINT2NUM(field->offset);
|
90
|
+
}
|
91
|
+
|
92
|
+
static void
|
93
|
+
struct_field_mark(StructField *f)
|
94
|
+
{
|
95
|
+
}
|
96
|
+
static void
|
97
|
+
struct_field_free(StructField *f)
|
98
|
+
{
|
99
|
+
if (f != NULL) {
|
100
|
+
xfree(f);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
static inline char*
|
105
|
+
memory_address(VALUE self)
|
106
|
+
{
|
107
|
+
return ((AbstractMemory *)DATA_PTR((self)))->address;
|
108
|
+
}
|
109
|
+
|
110
|
+
static inline char*
|
111
|
+
pointer_native(VALUE value)
|
112
|
+
{
|
113
|
+
const int type = TYPE(value);
|
114
|
+
|
115
|
+
if (rb_obj_is_kind_of(value, rb_FFI_Pointer_class) && type == T_DATA) {
|
116
|
+
return memory_address(value);
|
117
|
+
} else if (type == T_NIL) {
|
118
|
+
return NULL;
|
119
|
+
} else if (type == T_FIXNUM) {
|
120
|
+
return (char *)(uintptr_t) FIX2INT(value);
|
121
|
+
} else if (type == T_BIGNUM) {
|
122
|
+
return (char *)(uintptr_t) NUM2ULL(value);
|
123
|
+
} else if (rb_respond_to(value, to_ptr)) {
|
124
|
+
VALUE ptr = rb_funcall2(value, to_ptr, 0, NULL);
|
125
|
+
if (rb_obj_is_kind_of(ptr, rb_FFI_Pointer_class) && TYPE(ptr) == T_DATA) {
|
126
|
+
return memory_address(ptr);
|
127
|
+
} else {
|
128
|
+
rb_raise(rb_eArgError, "to_ptr returned an invalid pointer");
|
129
|
+
}
|
130
|
+
} else {
|
131
|
+
rb_raise(rb_eArgError, "value is not a pointer");
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
static inline VALUE
|
136
|
+
pointer_new(char* value)
|
137
|
+
{
|
138
|
+
return rb_FFI_Pointer_new(value);
|
139
|
+
}
|
140
|
+
|
141
|
+
static inline char*
|
142
|
+
string_to_native(VALUE value)
|
143
|
+
{
|
144
|
+
rb_raise(rb_eArgError, "Cannot set :string fields");
|
145
|
+
}
|
146
|
+
|
147
|
+
static inline VALUE
|
148
|
+
string_from_native(char* value)
|
149
|
+
{
|
150
|
+
return value != NULL ? rb_tainted_str_new2(value) : Qnil;
|
151
|
+
}
|
152
|
+
|
153
|
+
#define FIELD_OP(name, type, toNative, fromNative) \
|
154
|
+
static VALUE struct_field_put_##name(VALUE self, VALUE pointer, VALUE value); \
|
155
|
+
static inline void ptr_put_##name(AbstractMemory* ptr, StructField* field, VALUE value); \
|
156
|
+
static inline VALUE ptr_get_##name(AbstractMemory* ptr, StructField* field); \
|
157
|
+
static inline void \
|
158
|
+
ptr_put_##name(AbstractMemory* ptr, StructField* field, VALUE value) \
|
159
|
+
{ \
|
160
|
+
type tmp = toNative(value); \
|
161
|
+
memcpy(ptr->address + field->offset, &tmp, sizeof(tmp)); \
|
162
|
+
} \
|
163
|
+
static inline VALUE \
|
164
|
+
ptr_get_##name(AbstractMemory* ptr, StructField* field) \
|
165
|
+
{ \
|
166
|
+
type tmp; \
|
167
|
+
memcpy(&tmp, ptr->address + field->offset, sizeof(tmp)); \
|
168
|
+
return fromNative(tmp); \
|
169
|
+
} \
|
170
|
+
static VALUE \
|
171
|
+
struct_field_put_##name(VALUE self, VALUE pointer, VALUE value) \
|
172
|
+
{ \
|
173
|
+
StructField* f; Data_Get_Struct(self, StructField, f); \
|
174
|
+
ptr_put_##name(MEMORY(pointer), f, value); \
|
175
|
+
return self; \
|
176
|
+
} \
|
177
|
+
static VALUE struct_field_get_##name(VALUE self, VALUE pointer); \
|
178
|
+
static VALUE \
|
179
|
+
struct_field_get_##name(VALUE self, VALUE pointer) \
|
180
|
+
{ \
|
181
|
+
StructField* f; Data_Get_Struct(self, StructField, f); \
|
182
|
+
return ptr_get_##name(MEMORY(pointer), f); \
|
183
|
+
}
|
184
|
+
|
185
|
+
FIELD_OP(int8, int8_t, NUM2INT, INT2NUM);
|
186
|
+
FIELD_OP(uint8, uint8_t, NUM2UINT, UINT2NUM);
|
187
|
+
FIELD_OP(int16, int16_t, NUM2INT, INT2NUM);
|
188
|
+
FIELD_OP(uint16, uint16_t, NUM2UINT, UINT2NUM);
|
189
|
+
FIELD_OP(int32, int32_t, NUM2INT, INT2NUM);
|
190
|
+
FIELD_OP(uint32, uint32_t, NUM2UINT, UINT2NUM);
|
191
|
+
FIELD_OP(int64, int64_t, NUM2LL, LL2NUM);
|
192
|
+
FIELD_OP(uint64, uint64_t, NUM2ULL, ULL2NUM);
|
193
|
+
FIELD_OP(float32, float, NUM2DBL, rb_float_new);
|
194
|
+
FIELD_OP(float64, double, NUM2DBL, rb_float_new);
|
195
|
+
FIELD_OP(pointer, char*, pointer_native, pointer_new);
|
196
|
+
FIELD_OP(string, char*, string_to_native, string_from_native);
|
197
|
+
|
198
|
+
static VALUE
|
199
|
+
struct_allocate(VALUE klass)
|
200
|
+
{
|
201
|
+
Struct* s;
|
202
|
+
VALUE retval = Data_Make_Struct(klass, Struct, struct_mark, struct_free, s);
|
203
|
+
|
204
|
+
s->rbPointer = Qnil;
|
205
|
+
s->pointer = NULL;
|
206
|
+
s->rbLayout = Qnil;
|
207
|
+
s->layout = NULL;
|
208
|
+
|
209
|
+
if (rb_cvar_defined(klass, layoutID)) {
|
210
|
+
s->rbLayout = rb_cvar_get(klass, layoutID);
|
211
|
+
Data_Get_Struct(s->rbLayout, StructLayout, s->layout);
|
212
|
+
}
|
213
|
+
return retval;
|
214
|
+
}
|
215
|
+
|
216
|
+
static VALUE
|
217
|
+
struct_initialize(int argc, VALUE* argv, VALUE self)
|
218
|
+
{
|
219
|
+
Struct* s;
|
220
|
+
VALUE rbPointer = Qnil, rest = Qnil;
|
221
|
+
int nargs;
|
222
|
+
|
223
|
+
Data_Get_Struct(self, Struct, s);
|
224
|
+
|
225
|
+
nargs = rb_scan_args(argc, argv, "01*", &rbPointer, &rest);
|
226
|
+
|
227
|
+
/* Call up into ruby code to adjust the layout */
|
228
|
+
if (nargs > 1) {
|
229
|
+
s->rbLayout = rb_funcall2(CLASS_OF(self), rb_intern("layout"), RARRAY_LEN(rest), RARRAY_PTR(rest));
|
230
|
+
if (!rb_obj_is_kind_of(s->rbLayout, classStructLayout)) {
|
231
|
+
rb_raise(rb_eRuntimeError, "Invalid Struct layout");
|
232
|
+
}
|
233
|
+
|
234
|
+
Data_Get_Struct(s->rbLayout, StructLayout, s->layout);
|
235
|
+
}
|
236
|
+
|
237
|
+
if (rbPointer == Qnil) {
|
238
|
+
rbPointer = rb_FFI_MemoryPointer_new(s->layout->size, 1, true);
|
239
|
+
}
|
240
|
+
|
241
|
+
s->rbPointer = rbPointer;
|
242
|
+
s->pointer = MEMORY(rbPointer);
|
243
|
+
|
244
|
+
return self;
|
245
|
+
}
|
246
|
+
|
247
|
+
static void
|
248
|
+
struct_mark(Struct *s)
|
249
|
+
{
|
250
|
+
if (s->rbPointer != Qnil) {
|
251
|
+
rb_gc_mark(s->rbPointer);
|
252
|
+
}
|
253
|
+
if (s->rbLayout != Qnil) {
|
254
|
+
rb_gc_mark(s->rbLayout);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
static void struct_free(Struct *s)
|
259
|
+
{
|
260
|
+
xfree(s);
|
261
|
+
}
|
262
|
+
|
263
|
+
static VALUE
|
264
|
+
struct_field(Struct* s, VALUE fieldName)
|
265
|
+
{
|
266
|
+
StructLayout* layout = s->layout;
|
267
|
+
VALUE rbField;
|
268
|
+
if (layout == NULL) {
|
269
|
+
rb_raise(rb_eRuntimeError, "layout not set for Struct");
|
270
|
+
}
|
271
|
+
rbField = rb_hash_aref(layout->rbFields, fieldName);
|
272
|
+
if (rbField == Qnil) {
|
273
|
+
VALUE str = rb_funcall2(fieldName, rb_intern("to_s"), 0, NULL);
|
274
|
+
rb_raise(rb_eArgError, "No such field '%s'", StringValuePtr(str));
|
275
|
+
}
|
276
|
+
return rbField;
|
277
|
+
}
|
278
|
+
|
279
|
+
static VALUE
|
280
|
+
struct_get_field(VALUE self, VALUE fieldName)
|
281
|
+
{
|
282
|
+
Struct* s;
|
283
|
+
VALUE rbField;
|
284
|
+
StructField* f;
|
285
|
+
|
286
|
+
Data_Get_Struct(self, Struct, s);
|
287
|
+
rbField = struct_field(s, fieldName);
|
288
|
+
f = FIELD_CAST(rbField);
|
289
|
+
|
290
|
+
switch (f->type) {
|
291
|
+
case NATIVE_INT8:
|
292
|
+
return ptr_get_int8(s->pointer, f);
|
293
|
+
case NATIVE_UINT8:
|
294
|
+
return ptr_get_uint8(s->pointer, f);
|
295
|
+
case NATIVE_INT16:
|
296
|
+
return ptr_get_int16(s->pointer, f);
|
297
|
+
case NATIVE_UINT16:
|
298
|
+
return ptr_get_uint16(s->pointer, f);
|
299
|
+
case NATIVE_INT32:
|
300
|
+
return ptr_get_int32(s->pointer, f);
|
301
|
+
case NATIVE_UINT32:
|
302
|
+
return ptr_get_uint32(s->pointer, f);
|
303
|
+
case NATIVE_INT64:
|
304
|
+
return ptr_get_int64(s->pointer, f);
|
305
|
+
case NATIVE_UINT64:
|
306
|
+
return ptr_get_uint64(s->pointer, f);
|
307
|
+
case NATIVE_FLOAT32:
|
308
|
+
return ptr_get_float32(s->pointer, f);
|
309
|
+
case NATIVE_FLOAT64:
|
310
|
+
return ptr_get_float64(s->pointer, f);
|
311
|
+
case NATIVE_POINTER:
|
312
|
+
return ptr_get_pointer(s->pointer, f);
|
313
|
+
case NATIVE_STRING:
|
314
|
+
return ptr_get_string(s->pointer, f);
|
315
|
+
default:
|
316
|
+
/* call up to the ruby code to fetch the value */
|
317
|
+
return rb_funcall2(rbField, getID, 1, &s->rbPointer);
|
318
|
+
}
|
319
|
+
}
|
320
|
+
|
321
|
+
static VALUE
|
322
|
+
struct_put_field(VALUE self, VALUE fieldName, VALUE value)
|
323
|
+
{
|
324
|
+
Struct* s;
|
325
|
+
VALUE rbField;
|
326
|
+
StructField* f;
|
327
|
+
VALUE argv[2];
|
328
|
+
|
329
|
+
Data_Get_Struct(self, Struct, s);
|
330
|
+
rbField = struct_field(s, fieldName);
|
331
|
+
f = FIELD_CAST(rbField);
|
332
|
+
|
333
|
+
switch (f->type) {
|
334
|
+
case NATIVE_INT8:
|
335
|
+
ptr_put_int8(s->pointer, f, value);
|
336
|
+
break;
|
337
|
+
case NATIVE_UINT8:
|
338
|
+
ptr_put_uint8(s->pointer, f, value);
|
339
|
+
break;
|
340
|
+
case NATIVE_INT16:
|
341
|
+
ptr_put_int16(s->pointer, f, value);
|
342
|
+
break;
|
343
|
+
case NATIVE_UINT16:
|
344
|
+
ptr_put_uint16(s->pointer, f, value);
|
345
|
+
break;
|
346
|
+
case NATIVE_INT32:
|
347
|
+
ptr_put_int32(s->pointer, f, value);
|
348
|
+
break;
|
349
|
+
case NATIVE_UINT32:
|
350
|
+
ptr_put_uint32(s->pointer, f, value);
|
351
|
+
break;
|
352
|
+
case NATIVE_INT64:
|
353
|
+
ptr_put_int64(s->pointer, f, value);
|
354
|
+
break;
|
355
|
+
case NATIVE_UINT64:
|
356
|
+
ptr_put_uint64(s->pointer, f, value);
|
357
|
+
break;
|
358
|
+
case NATIVE_FLOAT32:
|
359
|
+
ptr_put_float32(s->pointer, f, value);
|
360
|
+
break;
|
361
|
+
case NATIVE_FLOAT64:
|
362
|
+
ptr_put_float64(s->pointer, f, value);
|
363
|
+
break;
|
364
|
+
case NATIVE_POINTER:
|
365
|
+
ptr_put_pointer(s->pointer, f, value);
|
366
|
+
break;
|
367
|
+
case NATIVE_STRING:
|
368
|
+
rb_raise(rb_eArgError, "Cannot set :string fields");
|
369
|
+
default:
|
370
|
+
/* call up to the ruby code to set the value */
|
371
|
+
argv[0] = s->rbPointer;
|
372
|
+
argv[1] = value;
|
373
|
+
rb_funcall2(rbField, putID, 2, argv);
|
374
|
+
break;
|
375
|
+
}
|
376
|
+
return self;
|
377
|
+
}
|
378
|
+
|
379
|
+
static VALUE
|
380
|
+
struct_set_pointer(VALUE self, VALUE pointer)
|
381
|
+
{
|
382
|
+
Struct* s;
|
383
|
+
|
384
|
+
if (!rb_obj_is_kind_of(pointer, rb_FFI_AbstractMemory_class)) {
|
385
|
+
rb_raise(rb_eArgError, "Invalid pointer");
|
386
|
+
}
|
387
|
+
|
388
|
+
Data_Get_Struct(self, Struct, s);
|
389
|
+
s->pointer = MEMORY(pointer);
|
390
|
+
s->rbPointer = pointer;
|
391
|
+
rb_ivar_set(self, pointerID, pointer);
|
392
|
+
return self;
|
393
|
+
}
|
394
|
+
|
395
|
+
static VALUE
|
396
|
+
struct_get_pointer(VALUE self)
|
397
|
+
{
|
398
|
+
Struct* s;
|
399
|
+
Data_Get_Struct(self, Struct, s);
|
400
|
+
return s->rbPointer;
|
401
|
+
}
|
402
|
+
|
403
|
+
static VALUE
|
404
|
+
struct_set_layout(VALUE self, VALUE layout)
|
405
|
+
{
|
406
|
+
Struct* s;
|
407
|
+
Data_Get_Struct(self, Struct, s);
|
408
|
+
|
409
|
+
if (!rb_obj_is_kind_of(layout, classStructLayout)) {
|
410
|
+
rb_raise(rb_eArgError, "Invalid Struct layout");
|
411
|
+
}
|
412
|
+
Data_Get_Struct(layout, StructLayout, s->layout);
|
413
|
+
rb_ivar_set(self, layoutID, layout);
|
414
|
+
return self;
|
415
|
+
}
|
416
|
+
|
417
|
+
static VALUE
|
418
|
+
struct_get_layout(VALUE self)
|
419
|
+
{
|
420
|
+
Struct* s;
|
421
|
+
Data_Get_Struct(self, Struct, s);
|
422
|
+
|
423
|
+
return s->rbLayout;
|
424
|
+
}
|
425
|
+
|
426
|
+
static VALUE
|
427
|
+
struct_layout_allocate(VALUE klass)
|
428
|
+
{
|
429
|
+
StructLayout* layout;
|
430
|
+
return Data_Make_Struct(klass, StructLayout, struct_layout_mark, struct_layout_free, layout);
|
431
|
+
}
|
432
|
+
|
433
|
+
static VALUE
|
434
|
+
struct_layout_initialize(VALUE self, VALUE field_names, VALUE fields, VALUE size, VALUE align)
|
435
|
+
{
|
436
|
+
StructLayout* layout;
|
437
|
+
|
438
|
+
Data_Get_Struct(self, StructLayout, layout);
|
439
|
+
layout->rbFields = fields;
|
440
|
+
layout->size = NUM2INT(size);
|
441
|
+
layout->align = NUM2INT(align);
|
442
|
+
|
443
|
+
rb_iv_set(self, "@field_names", field_names);
|
444
|
+
rb_iv_set(self, "@fields", fields);
|
445
|
+
rb_iv_set(self, "@size", size);
|
446
|
+
rb_iv_set(self, "@align", align);
|
447
|
+
|
448
|
+
return self;
|
449
|
+
}
|
450
|
+
|
451
|
+
static VALUE
|
452
|
+
struct_layout_aref(VALUE self, VALUE field)
|
453
|
+
{
|
454
|
+
StructLayout* layout;
|
455
|
+
|
456
|
+
Data_Get_Struct(self, StructLayout, layout);
|
457
|
+
return rb_hash_aref(layout->rbFields, field);
|
458
|
+
}
|
459
|
+
|
460
|
+
|
461
|
+
static void
|
462
|
+
struct_layout_mark(StructLayout *layout)
|
463
|
+
{
|
464
|
+
if (layout->rbFields != Qnil) {
|
465
|
+
rb_gc_mark(layout->rbFields);
|
466
|
+
}
|
467
|
+
}
|
468
|
+
|
469
|
+
static void
|
470
|
+
struct_layout_free(StructLayout *layout)
|
471
|
+
{
|
472
|
+
xfree(layout);
|
473
|
+
}
|
474
|
+
|
475
|
+
void
|
476
|
+
rb_FFI_Struct_Init()
|
477
|
+
{
|
478
|
+
VALUE moduleFFI = rb_define_module("FFI");
|
479
|
+
VALUE klass;
|
480
|
+
rb_FFI_Struct_class = classStruct = rb_define_class_under(moduleFFI, "Struct", rb_cObject);
|
481
|
+
classStructLayout = rb_define_class_under(moduleFFI, "StructLayout", rb_cObject);
|
482
|
+
classStructLayoutBuilder = rb_define_class_under(moduleFFI, "StructLayoutBuilder", rb_cObject);
|
483
|
+
classStructField = rb_define_class_under(classStructLayoutBuilder, "Field", rb_cObject);
|
484
|
+
|
485
|
+
rb_define_alloc_func(classStruct, struct_allocate);
|
486
|
+
rb_define_method(classStruct, "initialize", struct_initialize, -1);
|
487
|
+
|
488
|
+
rb_define_alias(rb_singleton_class(classStruct), "alloc_in", "new");
|
489
|
+
rb_define_alias(rb_singleton_class(classStruct), "alloc_out", "new");
|
490
|
+
rb_define_alias(rb_singleton_class(classStruct), "alloc_inout", "new");
|
491
|
+
rb_define_alias(rb_singleton_class(classStruct), "new_in", "new");
|
492
|
+
rb_define_alias(rb_singleton_class(classStruct), "new_out", "new");
|
493
|
+
rb_define_alias(rb_singleton_class(classStruct), "new_inout", "new");
|
494
|
+
|
495
|
+
rb_define_method(classStruct, "pointer", struct_get_pointer, 0);
|
496
|
+
rb_define_private_method(classStruct, "pointer=", struct_set_pointer, 1);
|
497
|
+
|
498
|
+
rb_define_method(classStruct, "layout", struct_get_layout, 0);
|
499
|
+
rb_define_private_method(classStruct, "layout=", struct_set_layout, 1);
|
500
|
+
|
501
|
+
rb_define_method(classStruct, "[]", struct_get_field, 1);
|
502
|
+
rb_define_method(classStruct, "[]=", struct_put_field, 2);
|
503
|
+
|
504
|
+
rb_define_alloc_func(classStructField, struct_field_allocate);
|
505
|
+
rb_define_method(classStructField, "initialize", struct_field_initialize, -1);
|
506
|
+
rb_define_method(classStructField, "offset", struct_field_offset, 0);
|
507
|
+
|
508
|
+
rb_define_alloc_func(classStructLayout, struct_layout_allocate);
|
509
|
+
rb_define_method(classStructLayout, "initialize", struct_layout_initialize, 4);
|
510
|
+
rb_define_method(classStructLayout, "[]", struct_layout_aref, 1);
|
511
|
+
|
512
|
+
pointerID = rb_intern("@pointer");
|
513
|
+
layoutID = rb_intern("@layout");
|
514
|
+
getID = rb_intern("get");
|
515
|
+
putID = rb_intern("put");
|
516
|
+
to_ptr = rb_intern("to_ptr");
|
517
|
+
SIZE_ID = rb_intern("SIZE");
|
518
|
+
ALIGN_ID = rb_intern("ALIGN");
|
519
|
+
#undef FIELD
|
520
|
+
#define FIELD(name, typeName, nativeType, T) do { \
|
521
|
+
typedef struct { char c; T v; } s; \
|
522
|
+
klass = rb_define_class_under(classStructLayoutBuilder, #name, classStructField); \
|
523
|
+
rb_define_method(klass, "put", struct_field_put_##typeName, 2); \
|
524
|
+
rb_define_method(klass, "get", struct_field_get_##typeName, 1); \
|
525
|
+
rb_define_const(klass, "ALIGN", INT2NUM((sizeof(s) - sizeof(T)) * 8)); \
|
526
|
+
rb_define_const(klass, "SIZE", INT2NUM(sizeof(T)* 8)); \
|
527
|
+
rb_define_const(klass, "TYPE", INT2NUM(nativeType)); \
|
528
|
+
} while(0)
|
529
|
+
|
530
|
+
FIELD(Signed8, int8, NATIVE_INT8, char);
|
531
|
+
FIELD(Unsigned8, uint8, NATIVE_UINT8, unsigned char);
|
532
|
+
FIELD(Signed16, int16, NATIVE_INT16, short);
|
533
|
+
FIELD(Unsigned16, uint16, NATIVE_UINT16, unsigned short);
|
534
|
+
FIELD(Signed32, int32, NATIVE_INT32, int);
|
535
|
+
FIELD(Unsigned32, uint32, NATIVE_UINT32, unsigned int);
|
536
|
+
FIELD(Signed64, int64, NATIVE_INT64, long long);
|
537
|
+
FIELD(Unsigned64, uint64, NATIVE_UINT64, unsigned long long);
|
538
|
+
FIELD(FloatField, float32, NATIVE_FLOAT32, float);
|
539
|
+
FIELD(DoubleField, float64, NATIVE_FLOAT64, double);
|
540
|
+
FIELD(PointerField, pointer, NATIVE_POINTER, char *);
|
541
|
+
FIELD(StringField, string, NATIVE_STRING, char *);
|
542
|
+
}
|