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
@@ -0,0 +1,146 @@
|
|
1
|
+
#include <stdbool.h>
|
2
|
+
#include <stdint.h>
|
3
|
+
#include <limits.h>
|
4
|
+
#include <ruby.h>
|
5
|
+
#include "rbffi.h"
|
6
|
+
#include "AbstractMemory.h"
|
7
|
+
#include "Pointer.h"
|
8
|
+
#include "MemoryPointer.h"
|
9
|
+
|
10
|
+
typedef struct MemoryPointer {
|
11
|
+
AbstractMemory memory;
|
12
|
+
char* storage; /* start of malloc area */
|
13
|
+
int type_size;
|
14
|
+
bool autorelease;
|
15
|
+
bool allocated;
|
16
|
+
} MemoryPointer;
|
17
|
+
|
18
|
+
static VALUE memptr_allocate(VALUE klass);
|
19
|
+
static void memptr_release(MemoryPointer* ptr);
|
20
|
+
static VALUE memptr_malloc(VALUE self, long size, long count, bool clear);
|
21
|
+
static VALUE memptr_free(VALUE self);
|
22
|
+
|
23
|
+
VALUE rb_FFI_MemoryPointer_class;
|
24
|
+
static VALUE classMemoryPointer = Qnil;
|
25
|
+
#define MEMPTR(obj) ((MemoryPointer *) rb_FFI_AbstractMemory_cast(obj, rb_FFI_MemoryPointer_class))
|
26
|
+
|
27
|
+
VALUE
|
28
|
+
rb_FFI_MemoryPointer_new(long size, long count, bool clear)
|
29
|
+
{
|
30
|
+
return memptr_malloc(memptr_allocate(classMemoryPointer), size, count, clear);
|
31
|
+
}
|
32
|
+
|
33
|
+
static VALUE
|
34
|
+
memptr_allocate(VALUE klass)
|
35
|
+
{
|
36
|
+
MemoryPointer* p;
|
37
|
+
return Data_Make_Struct(klass, MemoryPointer, NULL, memptr_release, p);
|
38
|
+
}
|
39
|
+
|
40
|
+
static VALUE
|
41
|
+
memptr_initialize(int argc, VALUE* argv, VALUE self)
|
42
|
+
{
|
43
|
+
VALUE size = Qnil, count = Qnil, clear = Qnil;
|
44
|
+
int nargs = rb_scan_args(argc, argv, "12", &size, &count, &clear);
|
45
|
+
memptr_malloc(self, rb_FFI_type_size(size), nargs > 1 ? NUM2LONG(count) : 1,
|
46
|
+
nargs > 2 && RTEST(clear));
|
47
|
+
|
48
|
+
if (rb_block_given_p()) {
|
49
|
+
return rb_rescue(rb_yield, self, memptr_free, self);
|
50
|
+
}
|
51
|
+
return self;
|
52
|
+
}
|
53
|
+
|
54
|
+
static VALUE
|
55
|
+
memptr_malloc(VALUE self, long size, long count, bool clear)
|
56
|
+
{
|
57
|
+
MemoryPointer* p;
|
58
|
+
unsigned long msize;
|
59
|
+
|
60
|
+
Data_Get_Struct(self, MemoryPointer, p);
|
61
|
+
p->type_size = size;
|
62
|
+
|
63
|
+
msize = size * count;
|
64
|
+
|
65
|
+
p->storage = malloc(msize + 7);
|
66
|
+
if (p->storage == NULL) {
|
67
|
+
rb_raise(rb_eNoMemError, "Failed to allocate memory size=%ld bytes", msize);
|
68
|
+
}
|
69
|
+
p->autorelease = true;
|
70
|
+
p->memory.size = msize;
|
71
|
+
/* ensure the memory is aligned on at least a 8 byte boundary */
|
72
|
+
p->memory.address = (char *) (((uintptr_t) p->storage + 0x7) & (uintptr_t) ~0x7UL);;
|
73
|
+
p->allocated = true;
|
74
|
+
if (clear && p->memory.size > 0) {
|
75
|
+
memset(p->memory.address, 0, p->memory.size);
|
76
|
+
}
|
77
|
+
return self;
|
78
|
+
}
|
79
|
+
|
80
|
+
static VALUE
|
81
|
+
memptr_inspect(VALUE self)
|
82
|
+
{
|
83
|
+
MemoryPointer* ptr = MEMPTR(self);
|
84
|
+
char tmp[100];
|
85
|
+
snprintf(tmp, sizeof(tmp), "#<MemoryPointer address=%p size=%lu>", ptr->memory.address, ptr->memory.size);
|
86
|
+
return rb_str_new2(tmp);
|
87
|
+
}
|
88
|
+
|
89
|
+
static VALUE
|
90
|
+
memptr_type_size(VALUE self)
|
91
|
+
{
|
92
|
+
return INT2FIX(MEMPTR(self)->type_size);
|
93
|
+
}
|
94
|
+
|
95
|
+
static VALUE
|
96
|
+
memptr_aref(VALUE self, VALUE which)
|
97
|
+
{
|
98
|
+
MemoryPointer* ptr = MEMPTR(self);
|
99
|
+
VALUE offset = INT2NUM(ptr->type_size * NUM2INT(which));
|
100
|
+
return rb_funcall2(self, rb_intern("+"), 1, &offset);
|
101
|
+
}
|
102
|
+
|
103
|
+
static VALUE
|
104
|
+
memptr_free(VALUE self)
|
105
|
+
{
|
106
|
+
MemoryPointer* ptr = MEMPTR(self);
|
107
|
+
if (ptr->allocated) {
|
108
|
+
if (ptr->storage != NULL) {
|
109
|
+
free(ptr->storage);
|
110
|
+
ptr->storage = NULL;
|
111
|
+
}
|
112
|
+
ptr->allocated = false;
|
113
|
+
}
|
114
|
+
return self;
|
115
|
+
}
|
116
|
+
|
117
|
+
static VALUE
|
118
|
+
memptr_autorelease(VALUE self, VALUE autorelease)
|
119
|
+
{
|
120
|
+
MEMPTR(self)->autorelease = autorelease == Qtrue;
|
121
|
+
return self;
|
122
|
+
}
|
123
|
+
|
124
|
+
static void
|
125
|
+
memptr_release(MemoryPointer* ptr)
|
126
|
+
{
|
127
|
+
if (ptr->autorelease && ptr->allocated && ptr->storage != NULL) {
|
128
|
+
free(ptr->storage);
|
129
|
+
ptr->storage = NULL;
|
130
|
+
}
|
131
|
+
xfree(ptr);
|
132
|
+
}
|
133
|
+
|
134
|
+
void
|
135
|
+
rb_FFI_MemoryPointer_Init()
|
136
|
+
{
|
137
|
+
VALUE moduleFFI = rb_define_module("FFI");
|
138
|
+
rb_FFI_MemoryPointer_class = classMemoryPointer = rb_define_class_under(moduleFFI, "MemoryPointer", rb_FFI_Pointer_class);
|
139
|
+
rb_define_alloc_func(classMemoryPointer, memptr_allocate);
|
140
|
+
rb_define_method(classMemoryPointer, "initialize", memptr_initialize, -1);
|
141
|
+
rb_define_method(classMemoryPointer, "inspect", memptr_inspect, 0);
|
142
|
+
rb_define_method(classMemoryPointer, "autorelease=", memptr_autorelease, 1);
|
143
|
+
rb_define_method(classMemoryPointer, "free", memptr_free, 0);
|
144
|
+
rb_define_method(classMemoryPointer, "type_size", memptr_type_size, 0);
|
145
|
+
rb_define_method(classMemoryPointer, "[]", memptr_aref, 1);
|
146
|
+
}
|
@@ -1,13 +1,8 @@
|
|
1
|
-
/*
|
2
|
-
* File: MemoryPointer.h
|
3
|
-
* Author: wayne
|
4
|
-
*
|
5
|
-
* Created on August 28, 2008, 5:24 PM
|
6
|
-
*/
|
7
1
|
|
8
2
|
#ifndef _MEMORYPOINTER_H
|
9
3
|
#define _MEMORYPOINTER_H
|
10
4
|
|
5
|
+
#include <stdbool.h>
|
11
6
|
#include <ruby.h>
|
12
7
|
|
13
8
|
#ifdef __cplusplus
|
@@ -15,8 +10,8 @@ extern "C" {
|
|
15
10
|
#endif
|
16
11
|
|
17
12
|
extern void rb_FFI_MemoryPointer_Init();
|
18
|
-
extern VALUE rb_FFI_MemoryPointer_new(caddr_t addr);
|
19
13
|
extern VALUE rb_FFI_MemoryPointer_class;
|
14
|
+
extern VALUE rb_FFI_MemoryPointer_new(long size, long count, bool clear);
|
20
15
|
#ifdef __cplusplus
|
21
16
|
}
|
22
17
|
#endif
|
@@ -0,0 +1,149 @@
|
|
1
|
+
#include <sys/types.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <stdint.h>
|
4
|
+
#if defined(_WIN32) || defined(__WIN32__)
|
5
|
+
# include <windows.h>
|
6
|
+
#else
|
7
|
+
# include <dlfcn.h>
|
8
|
+
#endif
|
9
|
+
#include <ruby.h>
|
10
|
+
|
11
|
+
#include <ffi.h>
|
12
|
+
|
13
|
+
#include "rbffi.h"
|
14
|
+
#include "compat.h"
|
15
|
+
#include "Pointer.h"
|
16
|
+
#include "NativeLibrary.h"
|
17
|
+
|
18
|
+
static VALUE library_initialize(VALUE self, VALUE libname, VALUE libflags);
|
19
|
+
static void library_free(Library* lib);
|
20
|
+
static VALUE classLibrary;
|
21
|
+
|
22
|
+
#if defined(_WIN32) || defined(__WIN32__)
|
23
|
+
static void* dl_open(const char* name, int flags);
|
24
|
+
static void dl_error(char* buf, int size);
|
25
|
+
#define dl_sym(handle, name) GetProcAddress(handle, name)
|
26
|
+
#define dl_close(handle) FreeLibrary(handle)
|
27
|
+
enum { RTLD_LAZY=1, RTLD_NOW, RTLD_GLOBAL, RTLD_LOCAL };
|
28
|
+
#else
|
29
|
+
# define dl_open(name, flags) dlopen(name, flags != 0 ? flags : RTLD_LAZY)
|
30
|
+
# define dl_error(buf, size) do { snprintf(buf, size, "%s", dlerror()); } while(0)
|
31
|
+
# define dl_sym(handle, name) dlsym(handle, name)
|
32
|
+
# define dl_close(handle) dlclose(handle)
|
33
|
+
#ifndef RTLD_LOCAL
|
34
|
+
# define RTLD_LOCAL 8
|
35
|
+
#endif
|
36
|
+
#endif
|
37
|
+
|
38
|
+
static VALUE
|
39
|
+
library_allocate(VALUE klass)
|
40
|
+
{
|
41
|
+
Library* library;
|
42
|
+
return Data_Make_Struct(klass, Library, NULL, library_free, library);
|
43
|
+
}
|
44
|
+
|
45
|
+
static VALUE
|
46
|
+
library_open(VALUE klass, VALUE libname, VALUE libflags)
|
47
|
+
{
|
48
|
+
return library_initialize(library_allocate(klass), libname, libflags);
|
49
|
+
}
|
50
|
+
|
51
|
+
static VALUE
|
52
|
+
library_initialize(VALUE self, VALUE libname, VALUE libflags)
|
53
|
+
{
|
54
|
+
Library* library;
|
55
|
+
int flags;
|
56
|
+
|
57
|
+
Check_Type(libflags, T_FIXNUM);
|
58
|
+
|
59
|
+
Data_Get_Struct(self, Library, library);
|
60
|
+
flags = libflags != Qnil ? NUM2UINT(libflags) : 0;
|
61
|
+
|
62
|
+
library->handle = dl_open(libname != Qnil ? StringValueCStr(libname) : NULL, flags);
|
63
|
+
if (library->handle == NULL) {
|
64
|
+
char errmsg[1024];
|
65
|
+
dl_error(errmsg, sizeof(errmsg));
|
66
|
+
rb_raise(rb_eLoadError, "Could not open library '%s': %s",
|
67
|
+
libname != Qnil ? StringValueCStr(libname) : "[current process]",
|
68
|
+
errmsg);
|
69
|
+
}
|
70
|
+
rb_iv_set(self, "@name", libname != Qnil ? libname : rb_str_new2("[current process]"));
|
71
|
+
return self;
|
72
|
+
}
|
73
|
+
|
74
|
+
static VALUE
|
75
|
+
library_dlsym(VALUE self, VALUE name)
|
76
|
+
{
|
77
|
+
Library* library;
|
78
|
+
void* address = NULL;
|
79
|
+
Check_Type(name, T_STRING);
|
80
|
+
|
81
|
+
Data_Get_Struct(self, Library, library);
|
82
|
+
address = dl_sym(library->handle, StringValueCStr(name));
|
83
|
+
return address != NULL ? rb_FFI_Pointer_new(address) : Qnil;
|
84
|
+
}
|
85
|
+
|
86
|
+
static VALUE
|
87
|
+
library_dlerror(VALUE self)
|
88
|
+
{
|
89
|
+
char errmsg[1024];
|
90
|
+
dl_error(errmsg, sizeof(errmsg));
|
91
|
+
return rb_tainted_str_new2(errmsg);
|
92
|
+
}
|
93
|
+
|
94
|
+
static void
|
95
|
+
library_free(Library* library)
|
96
|
+
{
|
97
|
+
if (library != NULL) {
|
98
|
+
// dlclose() on MacOS tends to segfault - avoid it
|
99
|
+
#ifndef __APPLE__
|
100
|
+
if (library->handle != NULL) {
|
101
|
+
dl_close(library->handle);
|
102
|
+
}
|
103
|
+
#endif
|
104
|
+
library->handle = NULL;
|
105
|
+
xfree(library);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
#if defined(_WIN32) || defined(__WIN32__)
|
110
|
+
static void*
|
111
|
+
dl_open(const char* name, int flags)
|
112
|
+
{
|
113
|
+
if (name == NULL) {
|
114
|
+
return GetModuleHandle(NULL);
|
115
|
+
} else {
|
116
|
+
return LoadLibraryEx(name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
static void
|
121
|
+
dl_error(char* buf, int size)
|
122
|
+
{
|
123
|
+
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
|
124
|
+
0, buf, size, NULL);
|
125
|
+
}
|
126
|
+
#endif
|
127
|
+
|
128
|
+
void
|
129
|
+
rb_FFI_NativeLibrary_Init()
|
130
|
+
{
|
131
|
+
VALUE moduleFFI = rb_define_module("FFI");
|
132
|
+
classLibrary = rb_define_class_under(moduleFFI, "DynamicLibrary", rb_cObject);
|
133
|
+
rb_define_const(moduleFFI, "NativeLibrary", classLibrary); // backwards compat library
|
134
|
+
rb_define_alloc_func(classLibrary, library_allocate);
|
135
|
+
rb_define_singleton_method(classLibrary, "open", library_open, 2);
|
136
|
+
rb_define_singleton_method(classLibrary, "last_error", library_dlerror, 0);
|
137
|
+
rb_define_method(classLibrary, "initialize", library_initialize, 2);
|
138
|
+
rb_define_method(classLibrary, "find_symbol", library_dlsym, 1);
|
139
|
+
rb_define_method(classLibrary, "last_error", library_dlerror, 0);
|
140
|
+
rb_define_attr(classLibrary, "name", 1, 0);
|
141
|
+
|
142
|
+
#define DEF(x) rb_define_const(classLibrary, "RTLD_" #x, UINT2NUM(RTLD_##x))
|
143
|
+
DEF(LAZY);
|
144
|
+
DEF(NOW);
|
145
|
+
DEF(GLOBAL);
|
146
|
+
DEF(LOCAL);
|
147
|
+
|
148
|
+
}
|
149
|
+
|
File without changes
|
@@ -0,0 +1,104 @@
|
|
1
|
+
#include <sys/types.h>
|
2
|
+
#include <stdbool.h>
|
3
|
+
#include <stdint.h>
|
4
|
+
#include <limits.h>
|
5
|
+
#include <ruby.h>
|
6
|
+
#include "rbffi.h"
|
7
|
+
#include "AbstractMemory.h"
|
8
|
+
#include "Pointer.h"
|
9
|
+
|
10
|
+
static VALUE NullPointerError;
|
11
|
+
static VALUE classNullPointer;
|
12
|
+
VALUE rb_FFI_NullPointer_class;
|
13
|
+
VALUE rb_FFI_NullPointer_singleton;
|
14
|
+
|
15
|
+
VALUE
|
16
|
+
rb_FFI_NullPointer_allocate(VALUE klass)
|
17
|
+
{
|
18
|
+
AbstractMemory* p;
|
19
|
+
VALUE retval;
|
20
|
+
|
21
|
+
retval = Data_Make_Struct(klass, AbstractMemory, NULL, -1, p);
|
22
|
+
p->address = 0;
|
23
|
+
p->size = 0;
|
24
|
+
return retval;
|
25
|
+
}
|
26
|
+
|
27
|
+
static VALUE
|
28
|
+
nullptr_op(int argc, VALUE* argv, VALUE self)
|
29
|
+
{
|
30
|
+
rb_raise(NullPointerError, "NULL Pointer access attempted");
|
31
|
+
}
|
32
|
+
|
33
|
+
static VALUE
|
34
|
+
nullptr_inspect(VALUE self)
|
35
|
+
{
|
36
|
+
return rb_str_new2("#<NULL Pointer address=0x0>");
|
37
|
+
}
|
38
|
+
|
39
|
+
static VALUE
|
40
|
+
nullptr_null_p(VALUE self)
|
41
|
+
{
|
42
|
+
return Qtrue;
|
43
|
+
}
|
44
|
+
|
45
|
+
static VALUE
|
46
|
+
nullptr_equals(VALUE self, VALUE other)
|
47
|
+
{
|
48
|
+
AbstractMemory* p2;
|
49
|
+
if (!rb_obj_is_kind_of(other, rb_FFI_Pointer_class)) {
|
50
|
+
rb_raise(rb_eArgError, "Comparing Pointer with non Pointer");
|
51
|
+
}
|
52
|
+
Data_Get_Struct(other, AbstractMemory, p2);
|
53
|
+
return p2->address == 0 ? Qtrue : Qfalse;
|
54
|
+
}
|
55
|
+
|
56
|
+
static VALUE
|
57
|
+
nullptr_address(VALUE self)
|
58
|
+
{
|
59
|
+
return INT2NUM(0);
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
void
|
64
|
+
rb_FFI_NullPointer_Init()
|
65
|
+
{
|
66
|
+
VALUE moduleFFI = rb_define_module("FFI");
|
67
|
+
rb_FFI_NullPointer_class = classNullPointer = rb_define_class_under(moduleFFI, "NullPointer", rb_FFI_Pointer_class);
|
68
|
+
NullPointerError = rb_define_class_under(moduleFFI, "NullPointerError", rb_eRuntimeError);
|
69
|
+
rb_define_alloc_func(classNullPointer, rb_FFI_NullPointer_allocate);
|
70
|
+
rb_define_method(classNullPointer, "inspect", nullptr_inspect, 0);
|
71
|
+
rb_define_method(classNullPointer, "+", nullptr_op, -1);
|
72
|
+
rb_define_method(classNullPointer, "null?", nullptr_null_p, 0);
|
73
|
+
rb_define_method(classNullPointer, "address", nullptr_address, 0);
|
74
|
+
rb_define_method(classNullPointer, "==", nullptr_equals, 1);
|
75
|
+
|
76
|
+
#define NOP(name) \
|
77
|
+
rb_define_method(classNullPointer, "get_" #name, nullptr_op, -1); \
|
78
|
+
rb_define_method(classNullPointer, "put_" #name, nullptr_op, -1); \
|
79
|
+
rb_define_method(classNullPointer, "get_array_of_" #name, nullptr_op, -1); \
|
80
|
+
rb_define_method(classNullPointer, "put_array_of_" #name, nullptr_op, -1); \
|
81
|
+
|
82
|
+
|
83
|
+
NOP(int8); NOP(uint8); NOP(int16); NOP(uint16);
|
84
|
+
NOP(int32); NOP(uint32); NOP(int64); NOP(uint64); NOP(long); NOP(ulong);
|
85
|
+
NOP(float32); NOP(float64);
|
86
|
+
NOP(char); NOP(uchar); NOP(short); NOP(ushort);
|
87
|
+
NOP(int); NOP(uint); NOP(long_long); NOP(ulong_long);
|
88
|
+
NOP(float); NOP(double);
|
89
|
+
|
90
|
+
#undef NOP
|
91
|
+
#define NOP(name) \
|
92
|
+
rb_define_method(classNullPointer, "get_" #name, nullptr_op, -1); \
|
93
|
+
rb_define_method(classNullPointer, "put_" #name, nullptr_op, -1);
|
94
|
+
|
95
|
+
NOP(string); NOP(bytes); NOP(pointer); NOP(callback);
|
96
|
+
|
97
|
+
rb_define_method(classNullPointer, "clear", nullptr_op, -1); \
|
98
|
+
rb_define_method(classNullPointer, "total", nullptr_op, -1);
|
99
|
+
|
100
|
+
// Create a singleton instance of NullPointer that can be shared
|
101
|
+
rb_FFI_NullPointer_singleton = rb_FFI_NullPointer_allocate(classNullPointer);
|
102
|
+
rb_gc_register_address(&rb_FFI_NullPointer_singleton);
|
103
|
+
}
|
104
|
+
|
File without changes
|
@@ -11,16 +11,21 @@ typedef struct Pointer {
|
|
11
11
|
VALUE parent;
|
12
12
|
} Pointer;
|
13
13
|
|
14
|
+
#define POINTER(obj) rb_FFI_AbstractMemory_cast((obj), rb_FFI_Pointer_class)
|
15
|
+
|
14
16
|
VALUE rb_FFI_Pointer_class;
|
15
17
|
static VALUE classPointer = Qnil;
|
16
18
|
static void ptr_mark(Pointer* ptr);
|
17
19
|
static void ptr_free(Pointer* ptr);
|
18
20
|
|
19
21
|
VALUE
|
20
|
-
rb_FFI_Pointer_new(
|
22
|
+
rb_FFI_Pointer_new(void* addr)
|
21
23
|
{
|
22
24
|
Pointer* p;
|
23
25
|
VALUE retval;
|
26
|
+
if (addr == NULL) {
|
27
|
+
return rb_FFI_NullPointer_singleton;
|
28
|
+
}
|
24
29
|
retval = Data_Make_Struct(classPointer, Pointer, NULL, ptr_free, p);
|
25
30
|
p->memory.address = addr;
|
26
31
|
p->memory.size = LONG_MAX;
|
@@ -28,56 +33,69 @@ rb_FFI_Pointer_new(caddr_t addr)
|
|
28
33
|
return retval;
|
29
34
|
}
|
30
35
|
|
36
|
+
static VALUE
|
37
|
+
ptr_allocate(VALUE klass)
|
38
|
+
{
|
39
|
+
Pointer* p;
|
40
|
+
return Data_Make_Struct(classPointer, Pointer, NULL, ptr_free, p);
|
41
|
+
}
|
42
|
+
|
31
43
|
static VALUE
|
32
44
|
ptr_plus(VALUE self, VALUE offset)
|
33
45
|
{
|
34
|
-
AbstractMemory* ptr
|
46
|
+
AbstractMemory* ptr;
|
35
47
|
Pointer* p;
|
36
48
|
VALUE retval;
|
37
49
|
long off = NUM2LONG(offset);
|
38
50
|
|
51
|
+
Data_Get_Struct(self, AbstractMemory, ptr);
|
39
52
|
checkBounds(ptr, off, 1);
|
53
|
+
|
40
54
|
retval = Data_Make_Struct(classPointer, Pointer, ptr_mark, ptr_free, p);
|
55
|
+
|
41
56
|
p->memory.address = ptr->address + off;
|
42
57
|
p->memory.size = ptr->size == LONG_MAX ? LONG_MAX : ptr->size - off;
|
43
58
|
p->parent = self;
|
59
|
+
|
44
60
|
return retval;
|
45
61
|
}
|
46
62
|
|
47
63
|
static VALUE
|
48
64
|
ptr_inspect(VALUE self)
|
49
65
|
{
|
50
|
-
|
66
|
+
Pointer* ptr;
|
51
67
|
char tmp[100];
|
52
|
-
|
68
|
+
|
69
|
+
Data_Get_Struct(self, Pointer, ptr);
|
70
|
+
snprintf(tmp, sizeof(tmp), "#<Native Pointer address=%p>", ptr->memory.address);
|
71
|
+
|
53
72
|
return rb_str_new2(tmp);
|
54
73
|
}
|
55
74
|
|
56
75
|
static VALUE
|
57
76
|
ptr_null_p(VALUE self)
|
58
77
|
{
|
59
|
-
|
60
|
-
|
78
|
+
Pointer* ptr;
|
79
|
+
Data_Get_Struct(self, Pointer, ptr);
|
80
|
+
return ptr->memory.address == NULL ? Qtrue : Qfalse;
|
61
81
|
}
|
62
82
|
|
63
83
|
static VALUE
|
64
84
|
ptr_equals(VALUE self, VALUE other)
|
65
85
|
{
|
66
|
-
|
67
|
-
|
86
|
+
Pointer* ptr;
|
87
|
+
Data_Get_Struct(self, Pointer, ptr);
|
68
88
|
|
69
|
-
|
70
|
-
rb_raise(rb_eArgError, "Comparing Pointer with non Pointer");
|
71
|
-
}
|
72
|
-
p2 = (AbstractMemory *) DATA_PTR(other);
|
73
|
-
return p1->address == p2->address ? Qtrue : Qfalse;
|
89
|
+
return ptr->memory.address == POINTER(other)->address ? Qtrue : Qfalse;
|
74
90
|
}
|
75
91
|
|
76
92
|
static VALUE
|
77
93
|
ptr_address(VALUE self)
|
78
94
|
{
|
79
|
-
|
80
|
-
|
95
|
+
Pointer* ptr;
|
96
|
+
Data_Get_Struct(self, Pointer, ptr);
|
97
|
+
|
98
|
+
return ULL2NUM((uintptr_t) ptr->memory.address);
|
81
99
|
}
|
82
100
|
|
83
101
|
static void
|
@@ -99,6 +117,8 @@ rb_FFI_Pointer_Init()
|
|
99
117
|
{
|
100
118
|
VALUE moduleFFI = rb_define_module("FFI");
|
101
119
|
rb_FFI_Pointer_class = classPointer = rb_define_class_under(moduleFFI, "Pointer", rb_FFI_AbstractMemory_class);
|
120
|
+
|
121
|
+
rb_define_alloc_func(classPointer, ptr_allocate);
|
102
122
|
rb_define_method(classPointer, "inspect", ptr_inspect, 0);
|
103
123
|
rb_define_method(classPointer, "+", ptr_plus, 1);
|
104
124
|
rb_define_method(classPointer, "null?", ptr_null_p, 0);
|