ruby-ffi-1.9.3debian.orig/0000755000175000017500000000000012261216360015562 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/LICENSE0000644000175000017500000000276312261216357016605 0ustar terceiroterceiroCopyright (c) 2008-2013, Ruby FFI project contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Ruby FFI project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ruby-ffi-1.9.3debian.orig/README.md0000644000175000017500000000660012261216357017051 0ustar terceiroterceiro# ruby-ffi https://wiki.github.com/ffi/ffi [![Build Status](https://travis-ci.org/ffi/ffi.png?branch=master)](https://travis-ci.org/ffi/ffi) ## Description Ruby-FFI is a ruby extension for programmatically loading dynamic libraries, binding functions within them, and calling those functions from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby and JRuby. [Discover why you should write your next extension using Ruby-FFI](https://wiki.github.com/ffi/ffi/why-use-ffi). ## Features/problems * Intuitive DSL * Supports all C native types * C structs (also nested), enums and global variables * Callbacks from C to ruby * Automatic garbage collection of native memory ## Synopsis ```ruby require 'ffi' module MyLib extend FFI::Library ffi_lib 'c' attach_function :puts, [ :string ], :int end MyLib.puts 'Hello, World using libc!' ``` For less minimalistic and more sane examples you may look at: * the samples/ folder * the examples on the [wiki](https://wiki.github.com/ffi/ffi) * the projects using FFI listed on this page (https://wiki.github.com/ffi/ffi/projects-using-ffi) ## Requirements You need a sane building environment in order to compile the extension. At a minimum, you will need: * A C compiler (e.g. Xcode on OSX, gcc on everything else) * libffi development library - this is commonly in the libffi-dev or libffi-devel ## Installation From rubygems: [sudo] gem install ffi or from the git repository on github: git clone git://github.com/ffi/ffi.git cd ffi rake gem:install ## License The ffi library is covered by the BSD license, also see the LICENSE file. The specs are shared with Rubyspec and are licensed by the same license as Rubyspec, see the LICENSE.SPECS file. ## Credits The following people have submitted code, bug reports, or otherwide contributed to the success of this project: * Alban Peignier * Aman Gupta * Andrea Fazzi * Andreas Niederl * Andrew Cholakian * Antonio Terceiro * Brian Candler * Brian D. Burns * Bryan Kearney * Charlie Savage * Chikanaga Tomoyuki * Hongli Lai * Ian MacLeod * Jake Douglas * Jean-Dominique Morani * Jeremy Hinegardner * Jesús García Sáez * Joe Khoobyar * Jurij Smakov * KISHIMOTO, Makoto * Kim Burgestrand * Lars Kanis * Luc Heinrich * Luis Lavena * Matijs van Zuijlen * Matthew King * Mike Dalessio * NARUSE, Yui * Park Heesob * Shin Yee * Stephen Bannasch * Suraj N. Kurapati * Sylvain Daubert * Victor Costan * beoran@gmail.com * ctide * emboss * hobophobe * meh * postmodern * wycats@gmail.com * Wayne Meissner ruby-ffi-1.9.3debian.orig/COPYING0000644000175000017500000000524312261216357016627 0ustar terceiroterceiroCopyright (c) 2008-2013, Ruby FFI project contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Ruby FFI project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. libffi, used by this project, is licensed under the MIT license: libffi - Copyright (c) 1996-2011 Anthony Green, Red Hat, Inc and others. See source files for details. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ``Software''), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ruby-ffi-1.9.3debian.orig/libtest/0000755000175000017500000000000012261216360017230 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/libtest/EnumTest.c0000644000175000017500000000134412261216360021142 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ int test_untagged_enum(int val) { return val; } int test_untagged_typedef_enum(int val) { return val; } typedef enum {c1, c2, c3, c4} enum_type1; enum_type1 test_tagged_typedef_enum1(enum_type1 val) { return val; } typedef enum {c5 = 42, c6, c7, c8} enum_type2; enum_type2 test_tagged_typedef_enum2(enum_type2 val) { return val; } typedef enum {c9 = 42, c10, c11 = 4242, c12} enum_type3; enum_type3 test_tagged_typedef_enum3(enum_type3 val) { return val; } typedef enum {c13 = 42, c14 = 4242, c15 = 424242, c16 = 42424242} enum_type4; enum_type4 test_tagged_typedef_enum4(enum_type4 val) { return val; } ruby-ffi-1.9.3debian.orig/libtest/UnionTest.c0000644000175000017500000000144212261216360021325 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #include #include #include #include #include typedef char s8; typedef short s16; typedef int s32; typedef long long s64; typedef float f32; typedef double f64; typedef union union_test { char b; short s; int i; long long j; long l; float f; double d; s8 a[10]; } union_test_t; #define T(x, type) \ type union_align_##type(union_test_t* u) { return u->x; } \ union_test_t* union_make_union_with_##type(type value) { static union_test_t u; u.x = value; return &u; } T(b, s8); T(s, s16); T(i, s32); T(j, s64); T(f, f32); T(d, f64); T(l, long); unsigned int union_size() { return sizeof(union_test_t); } ruby-ffi-1.9.3debian.orig/libtest/ReferenceTest.c0000644000175000017500000000124412261216360022133 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #include #define REF(T) void ref_##T(T arg, T* result) { *result = arg; } #define ADD(T) void ref_add_##T(T arg1, T arg2, T* result) { *result = arg1 + arg2; } #define SUB(T) void ref_sub_##T(T arg1, T arg2, T* result) { *result = arg1 - arg2; } #define MUL(T) void ref_mul_##T(T arg1, T arg2, T* result) { *result = arg1 * arg2; } #define DIV(T) void ref_div_##T(T arg1, T arg2, T* result) { *result = arg1 / arg2; } #define TEST(T) ADD(T) SUB(T) MUL(T) DIV(T) REF(T) TEST(int8_t); TEST(int16_t); TEST(int32_t); TEST(int64_t); TEST(float); TEST(double); ruby-ffi-1.9.3debian.orig/libtest/BufferTest.c0000644000175000017500000000140112261216360021441 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #define MEMSET(buf, value, size) do { \ int i; for (i = 0; i < size; ++i) buf[i] = value; \ } while(0) #define MEMCPY(dst, src, size) do { \ int i; for (i = 0; i < size; ++i) dst[i] = src[i]; \ } while(0) #define FILL(JTYPE, CTYPE) \ void fill##JTYPE##Buffer(CTYPE* buf, CTYPE value, int size) { MEMSET(buf, value, size); } #define COPY(JTYPE, CTYPE) \ void copy##JTYPE##Buffer(CTYPE* dst, CTYPE* src, int size) { MEMCPY(dst, src, size); } #define FUNC(JTYPE, CTYPE) \ FILL(JTYPE, CTYPE); \ COPY(JTYPE, CTYPE) FUNC(Byte, char); FUNC(Short, short); FUNC(Int, int); FUNC(Long, long long); FUNC(Float, float); FUNC(Double, double); ruby-ffi-1.9.3debian.orig/libtest/Benchmark.c0000644000175000017500000000234512261216360021272 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #include #include void returnVoid() { } void returnVoidI(int arg) { } int returnInt() { return 0; } int returnIntI(int arg) { return arg; } typedef int8_t s8; typedef uint8_t u8; typedef int16_t s16; typedef uint16_t u16; typedef int32_t s32; typedef uint32_t u32; typedef int64_t s64; typedef uint64_t u64; typedef float f32; typedef double f64; typedef void v; typedef char* S; typedef void* P; #define B6(R, T1, T2, T3, T4, T5, T6) R bench_##T1##T2##T3##T4##T5##T6##_##R(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) {} #define B5(R, T1, T2, T3, T4, T5) R bench_##T1##T2##T3##T4##T5##_##R(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {} #define B4(R, T1, T2, T3, T4) R bench_##T1##T2##T3##T4##_##R(T1 a1, T2 a2, T3 a3, T4 a4) {} #define B3(R, T1, T2, T3) R bench_##T1##T2##T3##_##R(T1 a1, T2 a2, T3 a3) {} #define B2(R, T1, T2) R bench_##T1##T2##_##R(T1 a1, T2 a2) {} #define B1(R, T1) R bench_##T1##_##R(T1 a1) {} #define BrV(T) B1(v, T); B2(v, T, T); B3(v, T, T, T); B4(v, T, T, T, T); B5(v, T, T, T, T, T); B6(v, T, T, T, T, T, T); BrV(u32); BrV(s32); BrV(s64); BrV(u64); BrV(f32); BrV(f64); BrV(S); BrV(P); ruby-ffi-1.9.3debian.orig/libtest/ClosureTest.c0000644000175000017500000000723112261216360021653 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #include #include #ifndef _WIN32 # include #else # include # include #endif #define R(T, rtype) rtype testClosureVr##T(rtype (*closure)(void)) { \ return closure != NULL ? (*closure)() : (rtype) 0; \ } #define P(T, ptype) void testClosure##T##rV(void (*closure)(ptype), ptype a1) { \ if (closure != NULL) (*closure)(a1); \ } void testClosureVrV(void (*closure)(void)) { (*closure)(); } R(Z, bool); R(B, char); R(S, short); R(I, int); R(L, long); R(J, long long); R(LL, long long); R(F, float); R(D, double); R(P, const void*); P(Z, bool); P(B, char); P(S, short); P(I, int); P(L, long); P(J, long long); P(LL, long long); P(F, float); P(D, double); P(P, const void*); P(UL, unsigned long); void testOptionalClosureBrV(void (*closure)(char), char a1) { if (closure) { (*closure)(a1); } } struct ThreadVrV { void (*closure)(void); int count; }; static void * threadVrV(void *arg) { struct ThreadVrV* t = (struct ThreadVrV *) arg; int i; for (i = 0; i < t->count; i++) { (*t->closure)(); } return NULL; } void testThreadedClosureVrV(void (*closure)(void), int n) { struct ThreadVrV arg = {closure, n}; #ifndef _WIN32 pthread_t t; pthread_create(&t, NULL, threadVrV, &arg); pthread_join(t, NULL); #else HANDLE hThread = (HANDLE) _beginthread((void (*)(void *))threadVrV, 0, &arg); WaitForSingleObject(hThread, INFINITE); #endif } struct s8f32s32 { char s8; float f32; int s32; }; // Takes a struct argument void testClosureTrV(void (*closure)(struct s8f32s32 s), struct s8f32s32* s) { (*closure)(*s); } // Returns a struct value struct s8f32s32 testClosureVrT(struct s8f32s32 (*closure)()) { return (*closure)(); } typedef int (*returnTypeClosure_t)(int) ; typedef returnTypeClosure_t (*lookupClosure_t)(); int testReturnsClosure(lookupClosure_t lookup, int val) { returnTypeClosure_t func = lookup ? (*lookup)() : NULL; return func ? (*func)(val) : 0; } static int multiplyByTwo(int value) { return value * 2; } returnTypeClosure_t testReturnsFunctionPointer() { return multiplyByTwo; } typedef int (*argumentClosure_t)(int); typedef int (*withArgumentClosure_t)(argumentClosure_t, int); int testArgumentClosure(withArgumentClosure_t closure_with, argumentClosure_t closure_arg, int val) { return (*closure_with)(closure_arg, val); } // // These macros produce functions of the form: // testClosureBIrV(void (*closure)(char, int), char a1, int a2) {} // #define C2_(J1, J2, N1, N2) \ void testClosure##J1##J2##rV(void (*closure)(N1, N2), N1 a1, N2 a2) \ { \ if (closure != NULL) (*closure)(a1, a2); \ } #define C2(J, N) \ C2_(B, J, char, N) \ C2_(S, J, short, N) \ C2_(I, J, int, N) \ C2_(LL, J, long long, N) \ C2_(F, J, float, N) \ C2_(D, J, double, N) \ C2(B, char); C2(S, short); C2(I, int); C2(LL, long long); C2(F, float); C2(D, double); #define C3_(J1, J2, J3, N1, N2, N3) \ void testClosure##J1##J2##J3##rV(void (*closure)(N1, N2, N3), N1 a1, N2 a2, N3 a3) \ { \ (*closure)(a1, a2, a3); \ } #define C3(J, N) \ C3_(B, J, B, char, N, char) \ C3_(S, J, S, short, N, short) \ C3_(I, J, I, int, N, int) \ C3_(LL, J, LL, long long, N, long long) \ C3_(F, J, F, float, N, float) \ C3_(D, J, D, double, N, double) \ C3(B, char); C3(S, short); C3(I, int); C3(LL, long long); C3(F, float); C3(D, double); C3_(B, S, I, char, short, int); C3_(B, S, LL, char, short, long long); C3_(LL, S, B, long long, short, char); C3_(LL, B, S, long long, char, short); ruby-ffi-1.9.3debian.orig/libtest/VariadicTest.c0000644000175000017500000000250512261216360021760 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #include #include #include #include #include typedef int8_t s8; typedef uint8_t u8; typedef int16_t s16; typedef uint16_t u16; typedef int32_t s32; typedef uint32_t u32; typedef int64_t s64; typedef uint64_t u64; typedef signed long sL; typedef unsigned long uL; typedef float F; typedef double D; void pack_varargs(s64* buf, const char* fmt, ...) { va_list ap; int c; double d; va_start(ap, fmt); while ((c = *fmt++)) { switch (c) { case 'c': case 's': case 'i': *buf++ = va_arg(ap, s32); break; case 'l': *buf++ = va_arg(ap, long); break; case 'j': *buf++ = va_arg(ap, s64); break; case 'f': case 'd': d = va_arg(ap, double); memcpy(buf++, &d, sizeof(d)); break; case 'C': case 'S': case 'I': *buf++ = va_arg(ap, u32); break; case 'L': *buf++ = va_arg(ap, unsigned long); break; } } va_end(ap); } ruby-ffi-1.9.3debian.orig/libtest/NumberTest.c0000644000175000017500000000766712261216360021504 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #include #include #include #include #if defined(__sparc) && defined(__sun__) #define fix_mem_access __asm("ta 6") #else #define fix_mem_access #endif typedef int8_t s8; typedef uint8_t u8; typedef int16_t s16; typedef uint16_t u16; typedef int32_t s32; typedef uint32_t u32; typedef int64_t s64; typedef uint64_t u64; typedef signed long sL; typedef unsigned long uL; typedef float f32; typedef double f64; typedef long double f128; #if !defined(__OpenBSD__) typedef unsigned long ulong; #endif #define ADD(T) T add_##T(T arg1, T arg2) { return arg1 + arg2; } #define SUB(T) T sub_##T(T arg1, T arg2) { return arg1 - arg2; } #define MUL(T) T mul_##T(T arg1, T arg2) { return arg1 * arg2; } #define DIV(T) T div_##T(T arg1, T arg2) { return arg1 / arg2; } #define RET(T) T ret_##T(T arg1) { return arg1; } #define SET(T) static T T##_;void set_##T(T arg1) { T##_ = arg1; } #define GET(T) T get_##T() { return T##_; } typedef char* ptr; #define TEST(T) ADD(T) SUB(T) MUL(T) DIV(T) RET(T) SET(T) GET(T) TEST(s8); TEST(u8); TEST(s16); TEST(u16); TEST(s32); TEST(u32); TEST(s64); TEST(u64); TEST(float); TEST(double); TEST(long); TEST(ulong); TEST(f128); #define ADD2(R, T1, T2) R add_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 + arg2; } #define SUB2(R, T1, T2) R sub_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 - arg2; } #define MUL2(R, T1, T2) R mul_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 * arg2; } #define DIV2(R, T1, T2) R div_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 / arg2; } #define T2__(R, T1, T2) ADD2(R, T1, T2) SUB2(R, T1, T2) MUL2(R, T1, T2) DIV2(R, T1, T2) #define T2_(R, T1) \ T2__(R, T1, s8) T2__(R, T1, u8) \ T2__(R, T1, s16) T2__(R, T1, u16) \ T2__(R, T1, s32) T2__(R, T1, u32) \ T2__(R, T1, sL) T2__(R, T1, uL) \ T2__(R, T1, s64) T2__(R, T1, u64) \ #define TEST2(R) \ T2_(R, s8) T2_(R, u8) T2_(R, s16) T2_(R, u16) T2_(R, s32) T2_(R, u32) \ T2_(R, sL) T2_(R, uL) T2_(R, s64) T2_(R, u64) #ifdef notyet TEST2(s32) TEST2(u32) TEST2(s64) TEST2(u64) #endif #define ADD3(R, T1, T2, T3) R add_##T1##T2##T3##_##R(T1 arg1, T2 arg2, T3 arg3) { return arg1 + arg2 + arg3; } #define pack_f32(buf, v) do { float f = v; memcpy((buf), &f, sizeof(f)); } while(0) #define pack_f64(buf, v) do { double f = v; memcpy((buf), &f, sizeof(f)); } while(0) #define pack_int(buf, v) do { *(buf) = v; } while(0) #define pack_s8 pack_int #define pack_u8 pack_int #define pack_s16 pack_int #define pack_u16 pack_int #define pack_s32 pack_int #define pack_u32 pack_int #define pack_s64 pack_int #define pack_u64 pack_int #define pack_sL pack_int #define pack_uL pack_int #define PACK3(R, T1, T2, T3) void pack_##T1##T2##T3##_##R(T1 arg1, T2 arg2, T3 arg3, R* r) { \ fix_mem_access; \ pack_##T1(&r[0], arg1); \ pack_##T2(&r[1], arg2); \ pack_##T3(&r[2], arg3); \ } #define T3___(R, T1, T2, T3) PACK3(R, T1, T2, T3) /* SUB2(R, T1, T2) MUL2(R, T1, T2) DIV2(R, T1, T2) */ #define T3__(R, T1, T2) \ T3___(R, T1, T2, s8) T3___(R, T1, T2, u8) \ T3___(R, T1, T2, s16) T3___(R, T1, T2, u16) \ T3___(R, T1, T2, s32) T3___(R, T1, T2, u32) \ T3___(R, T1, T2, sL) T3___(R, T1, T2, uL) \ T3___(R, T1, T2, s64) T3___(R, T1, T2, u64) \ T3___(R, T1, T2, f32) T3___(R, T1, T2, f64) \ #define T3_(R, T1) \ T3__(R, T1, s8) T3__(R, T1, u8) \ T3__(R, T1, s16) T3__(R, T1, u16) \ T3__(R, T1, s32) T3__(R, T1, u32) \ T3__(R, T1, sL) T3__(R, T1, uL) \ T3__(R, T1, s64) T3__(R, T1, u64) \ T3__(R, T1, f32) T3__(R, T1, f64) \ #define TEST3(R) \ T3_(R, s8) T3_(R, u8) T3_(R, s16) T3_(R, u16) T3_(R, s32) T3_(R, u32) \ T3_(R, sL) T3_(R, uL) T3_(R, s64) T3_(R, u64) T3_(R, f32) T3_(R, f64) TEST3(s64) void foo6(intptr_t i1, intptr_t i2, intptr_t i3, intptr_t i4, intptr_t i5, intptr_t i6) { } void foo5(intptr_t i1, intptr_t i2, intptr_t i3, intptr_t i4, intptr_t i5) { } ruby-ffi-1.9.3debian.orig/libtest/GlobalVariable.c0000644000175000017500000000200212261216360022234 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #include #include typedef int8_t s8; typedef uint8_t u8; typedef int16_t s16; typedef uint16_t u16; typedef int32_t s32; typedef uint32_t u32; typedef int64_t s64; typedef uint64_t u64; typedef signed long sL; typedef unsigned long uL; typedef float f32; typedef double f64; #if !defined(__OpenBSD__) typedef unsigned long ulong; #endif typedef void* pointer; typedef void* P; #define GVAR(T) \ extern T gvar_##T; \ T gvar_##T = (T) -1; \ T gvar_##T##_get() { return gvar_##T; }; \ void gvar_##T##_set(T v) { gvar_##T = v; } GVAR(s8); GVAR(u8); GVAR(s16); GVAR(u16); GVAR(s32); GVAR(u32); GVAR(s64); GVAR(u64); GVAR(long); GVAR(ulong); GVAR(pointer); struct gstruct { long data; }; struct gstruct gvar_gstruct = { -1 }; struct gstruct* gvar_gstruct_get(void) { return &gvar_gstruct; } void gvar_gstruct_set(const struct gstruct* val) { gvar_gstruct = *val; } ruby-ffi-1.9.3debian.orig/libtest/GNUmakefile0000644000175000017500000000615712261216360021313 0ustar terceiroterceiro# -*- makefile -*- ifeq ($(OS),) BUILD_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]') OS := $(BUILD_OS) endif ifeq ($(CPU),) CPU := $(shell uname -m | sed -e 's/i[345678]86/i386/') endif PLATFORM = $(CPU)-$(OS) ifeq ($(OS), sunos) OS = solaris endif SRC_DIR = libtest BUILD_DIR ?= build TEST_BUILD_DIR = $(BUILD_DIR)/libtest # Set defaults to unix (linux/solaris/bsd) PREFIX = lib LIBEXT ?= so LIBNAME = $(PREFIX)test.$(LIBEXT) export MACOSX_DEPLOYMENT_TARGET=10.4 CCACHE := $(strip $(realpath $(shell which ccache 2> /dev/null))) TEST_SRCS = $(wildcard $(SRC_DIR)/*.c) TEST_OBJS := $(patsubst $(SRC_DIR)/%.c, $(TEST_BUILD_DIR)/%.o, $(TEST_SRCS)) # # Compiler/linker flags from: # http://weblogs.java.net/blog/kellyohair/archive/2006/01/compilation_of_1.html JFLAGS = -fno-omit-frame-pointer -fno-strict-aliasing OFLAGS = -O2 $(JFLAGS) WFLAGS = -W -Wall -Wno-unused -Wno-parentheses PICFLAGS = -fPIC SOFLAGS = -shared LDFLAGS += $(SOFLAGS) IFLAGS = -I"$(BUILD_DIR)" CFLAGS = $(OFLAGS) $(WFLAGS) $(IFLAGS) $(PICFLAGS) -D_REENTRANT ifneq ($(strip $(findstring $(OS), win32, mingw, cygwin)),) # For cygwin => win32-native builds, strip out cygwin deps ifneq ($(findstring cygwin, $(BUILD_OS)),) CC += -mno-cygwin -mwin32 LDFLAGS += -mno-cygwin -Wl,--add-stdcall-alias endif PICFLAGS= LIBEXT=dll CC = gcc endif ifeq ($(OS), darwin) ifneq ($(findstring $(CPU),ppc),) ARCHFLAGS += -arch ppc endif ifneq ($(findstring $(CPU),i386 x86_64),) ARCHFLAGS += -arch i386 -arch x86_64 endif CFLAGS += $(ARCHFLAGS) -DTARGET_RT_MAC_CFM=0 CFLAGS += -fno-common LDFLAGS = $(ARCHFLAGS) -dynamiclib # link against the universal libraries on ppc machines LDFLAGS += -L$(MACSDK)/usr/lib LIBEXT = dylib FFI_CFLAGS += -isysroot $(MACSDK) PICFLAGS = SOFLAGS = endif ifeq ($(OS), linux) SOFLAGS += -Wl,-soname,$(LIBNAME) endif ifeq ($(OS), solaris) CC = /usr/sfw/bin/gcc -std=c99 LD = /usr/ccs/bin/ld SOFLAGS = -shared -static-libgcc endif ifeq ($(OS), aix) LIBEXT = a SOFLAGS = -shared -static-libgcc PICFLAGS += -pthread endif ifneq ($(findstring bsd, $(OS)),) SOFLAGS = -shared -static-libgcc CFLAGS += -pthread LDFLAGS += -pthread endif ifeq ($(CPU), i386) MODEL = 32 endif ifeq ($(CPU), sparcv9) MODEL = 64 endif ifeq ($(CPU), amd64) MODEL = 64 endif ifeq ($(CPU), x86_64) MODEL = 64 endif ifeq ($(CPU), ppc64) MODEL = 64 endif ifeq ($(CPU), powerpc64) MODEL = 64 endif MODELFLAG = ifneq ($(MODEL),) MODELFLAG = -m$(MODEL) endif # On platforms (linux, solaris) that support both 32bit and 64bit, force building for one or the other ifneq ($(or $(findstring linux, $(OS)), $(findstring solaris, $(OS))),) # Change the CC/LD instead of CFLAGS/LDFLAGS, incase other things in the flags # makes the libffi build choke CC += $(MODELFLAG) LD += $(MODELFLAG) endif LIBTEST = $(BUILD_DIR)/$(LIBNAME) all: $(LIBTEST) $(TEST_BUILD_DIR)/%.o : $(SRC_DIR)/%.c @mkdir -p $(@D) $(CCACHE) $(CC) $(CFLAGS) -c $< -o $@ $(LIBTEST): $(TEST_OBJS) $(CC) -o $@ $(LDFLAGS) $(TEST_OBJS) -lm clean:: # nothing to do - ant will delete the build dir debug:: @echo "SRCS=$(TEST_SRCS)" ruby-ffi-1.9.3debian.orig/libtest/PointerTest.c0000644000175000017500000000213212261216360021652 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #include #include #include #include #include #include typedef void* ptr; typedef void* pointer; #ifdef _WIN32 typedef char* caddr_t; #endif #define RET(T) T ptr_ret_##T(void* arg1, int offset) { \ T tmp; memcpy(&tmp, (caddr_t) arg1 + offset, sizeof(tmp)); return tmp; \ } #define SET(T) void ptr_set_##T(void* arg1, int offset, T value) { \ memcpy((caddr_t) arg1 + offset, &value, sizeof(value)); \ } #define TEST(T) SET(T) RET(T) TEST(int8_t); TEST(int16_t); TEST(int32_t); TEST(int64_t); TEST(float); TEST(double); TEST(pointer); void* ptr_return_array_element(void **ptrArray, int arrayIndex) { return ptrArray[arrayIndex]; } void ptr_set_array_element(void **ptrArray, int arrayIndex, void *value) { ptrArray[arrayIndex] = value; } void* ptr_malloc(int size) { return calloc(1, size); } void ptr_free(void* ptr) { free(ptr); } void* ptr_from_address(uintptr_t addr) { return (void *) addr; } ruby-ffi-1.9.3debian.orig/libtest/StructTest.c0000644000175000017500000000770212261216360021526 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. * Copyright (c) 2009 Andrea Fazzi . * * All rights reserved. * * For licensing, see LICENSE.SPECS */ #include #include #include #include #include #include typedef char s8; typedef short s16; typedef int s32; typedef long long s64; typedef float f32; typedef double f64; typedef struct bugged_struct { unsigned char visible; unsigned int x; unsigned int y; short rx; short ry; unsigned char order; unsigned char size; } bugged_struct_t; unsigned int bugged_struct_size() { return sizeof(bugged_struct_t); } struct test1 { char b; short s; int i; long long j; long l; float f; double d; char string[32]; }; struct struct_with_array { char c; int a[5]; }; struct nested { int i; }; struct container { char first; struct nested s; }; int struct_align_nested_struct(struct container* a) { return a->s.i; } void* struct_field_array(struct struct_with_array* s) { return &s->a; } struct container* struct_make_container_struct(int i) { static struct container cs; memset(&cs, 0, sizeof(cs)); cs.first = 1; cs.s.i = i; return &cs; } #define T(x, type) \ type struct_field_##type(struct test1* t) { return t->x; } \ struct type##_align { char first; type value; }; \ type struct_align_##type(struct type##_align* a) { return a->value; } T(b, s8); T(s, s16); T(i, s32); T(j, s64); T(f, f32); T(d, f64); T(l, long); void struct_set_string(struct test1* t, char* s) { strcpy(t->string, s); } struct test1* struct_make_struct(char b, short s, int i, long long ll, float f, double d) { static struct test1 t; memset(&t, 0, sizeof(t)); t.b = b; t.s = s; t.i = i; t.j = ll; t.f = f; t.d = d; return &t; } typedef int (*add_cb)(int a1, int a2); typedef int (*sub_cb)(int a1, int a2); struct test2 { add_cb add_callback; sub_cb sub_callback; }; int struct_call_add_cb(struct test2* t, int a1, int a2) { return t->add_callback(a1, a2); } int struct_call_sub_cb(struct test2* t, int a1, int a2) { return t->sub_callback(a1, a2); } struct struct_with_array* struct_make_struct_with_array(int a_0, int a_1, int a_2, int a_3, int a_4) { static struct struct_with_array s; memset(&s, 0, sizeof(s)); s.a[0] = a_0; s.a[1] = a_1; s.a[2] = a_2; s.a[3] = a_3; s.a[4] = a_4; return &s; } struct s8s32 { char s8; int s32; }; struct s8s32 struct_return_s8s32() { struct s8s32 s; s.s8 = 0x7f; s.s32 = 0x12345678; return s; } struct s8s32 struct_s8s32_set(char s8, int s32) { struct s8s32 s; s.s8 = s8; s.s32 = s32; return s; } int struct_s8s32_get_s8(struct s8s32 s) { return s.s8; } int struct_s8s32_get_s32(struct s8s32 s) { return s.s32; } struct s8s32 struct_s8s32_ret_s8s32(struct s8s32 s) { return s; } // Pass a struct and an int arg, ensure the int arg is passed correctly int struct_s8s32_s32_ret_s32(struct s8s32 s, int s32) { return s32; } // Pass a struct and a long long arg, ensure the long long arg is passed correctly long long struct_s8s32_s64_ret_s64(struct s8s32 s, long long s64) { return s64; } // Pass a struct and a long long arg, ensure the long long arg is passed correctly int struct_s32_ptr_s32_s8s32_ret_s32(int s32a, void *ptr, int s32b, struct s8s32 s) { if (ptr != NULL) *(struct s8s32 *) ptr = s; return s.s32; } // Pass a char *, copy into buffer length struct struct struct_string { char *bytes; int len; }; struct struct_string struct_varargs_ret_struct_string(int len, ...) { struct struct_string ss; va_list vl; char* cp = NULL; va_start(vl, len); ss.len = len; ss.bytes = va_arg(vl, char *); if (ss.bytes != NULL) { cp = malloc(strlen(ss.bytes) + 1); strcpy(cp, ss.bytes); ss.bytes = cp; } va_end(vl); return ss; } ruby-ffi-1.9.3debian.orig/libtest/StringTest.c0000644000175000017500000000067212261216360021507 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #include int string_equals(const char* s1, const char* s2) { return strcmp(s1, s2) == 0; } void string_set(char* s1, const char* s2) { strcpy(s1, s2); } void string_concat(char* dst, const char* src) { strcat(dst, src); } void string_dummy(char* dummy) { } const char* string_null(void) { return NULL; } ruby-ffi-1.9.3debian.orig/libtest/LastErrorTest.c0000644000175000017500000000053712261216360022156 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #if defined(_WIN32) || defined(__WIN32__) # include #else # include #endif int setLastError(int error) { #if defined(_WIN32) || defined(__WIN32__) SetLastError(error); #else errno = error; #endif return -1; } ruby-ffi-1.9.3debian.orig/libtest/BoolTest.c0000644000175000017500000000060512261216360021130 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. * Copyright (c) 2009 Aman Gupta. * * All rights reserved. * * For licensing, see LICENSE.SPECS */ #include bool bool_return_true() { return true; } bool bool_return_false() { return false; } bool bool_return_val(bool value) { return value; } bool bool_reverse_val(bool value) { return value ? false : true; } ruby-ffi-1.9.3debian.orig/libtest/FunctionTest.c0000644000175000017500000000164712261216360022031 0ustar terceiroterceiro/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #ifdef _WIN32 #include #define sleep(x) Sleep(x) #endif #ifndef _WIN32 #include #include #endif int testAdd(int a, int b) { return a + b; }; int testFunctionAdd(int a, int b, int (*f)(int, int)) { return f(a, b); }; void testBlocking(int seconds) { sleep(seconds); }; struct async_data { void (*fn)(int); int value; }; static void* asyncThreadCall(void *data) { struct async_data* d = (struct async_data *) data; if (d != NULL && d->fn != NULL) { (*d->fn)(d->value); } return NULL; } void testAsyncCallback(void (*fn)(int), int value) { #ifndef _WIN32 pthread_t t; struct async_data d; d.fn = fn; d.value = value; pthread_create(&t, NULL, asyncThreadCall, &d); pthread_join(t, NULL); #else (*fn)(value); #endif } ruby-ffi-1.9.3debian.orig/spec/0000755000175000017500000000000012261216360016514 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/spec/ffi/0000755000175000017500000000000012261216360017260 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/spec/ffi/typedef_spec.rb0000644000175000017500000000450112261216360022257 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "Custom type definitions" do it "attach_function with custom typedef" do module CustomTypedef extend FFI::Library ffi_lib TestLibrary::PATH typedef :uint, :fubar_t attach_function :ret_u32, [ :fubar_t ], :fubar_t end CustomTypedef.ret_u32(0x12345678).should == 0x12345678 end it "variadic invoker with custom typedef" do module VariadicCustomTypedef extend FFI::Library ffi_lib TestLibrary::PATH typedef :uint, :fubar_t attach_function :pack_varargs, [ :buffer_out, :string, :varargs ], :void end buf = FFI::Buffer.new :uint, 10 VariadicCustomTypedef.pack_varargs(buf, "i", :fubar_t, 0x12345678) buf.get_int64(0).should == 0x12345678 end it "Callback with custom typedef parameter" do module CallbackCustomTypedef extend FFI::Library ffi_lib TestLibrary::PATH typedef :uint, :fubar3_t callback :cbIrV, [ :fubar3_t ], :void attach_function :testCallbackU32rV, :testClosureIrV, [ :cbIrV, :fubar3_t ], :void end i = 0 CallbackCustomTypedef.testCallbackU32rV(0xdeadbeef) { |v| i = v } i.should == 0xdeadbeef end module StructCustomTypedef extend FFI::Library ffi_lib TestLibrary::PATH typedef :uint, :fubar3_t class S < FFI::Struct layout :a, :fubar3_t end end it "Struct with custom typedef field" do s = StructCustomTypedef::S.new s[:a] = 0x12345678 s.pointer.get_uint(0).should == 0x12345678 end it "attach_function after a typedef should not reject normal types" do lambda do Module.new do extend FFI::Library # enum() will insert a custom typedef called :foo for the enum enum :foo, [ :a, :b ] typedef :int, :bar ffi_lib TestLibrary::PATH attach_function :ptr_ret_int32_t, [ :string, :foo ], :bar end end.should_not raise_error end it "detects the correct type for size_t" do lambda do Module.new do extend FFI::Library ffi_lib "c" # read(2) is a standard UNIX function attach_function :read, [:int, :pointer, :size_t], :ssize_t end end.should_not raise_error end end ruby-ffi-1.9.3debian.orig/spec/ffi/pointer_spec.rb0000644000175000017500000002067612261216360022312 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) require 'delegate' require 'java' if RUBY_PLATFORM =~ /java/ module PointerTestLib extend FFI::Library ffi_lib TestLibrary::PATH attach_function :ptr_ret_int32_t, [ :pointer, :int ], :int attach_function :ptr_from_address, [ FFI::Platform::ADDRESS_SIZE == 32 ? :uint : :ulong_long ], :pointer attach_function :ptr_set_pointer, [ :pointer, :int, :pointer ], :void attach_function :ptr_ret_pointer, [ :pointer, :int ], :pointer end describe "Pointer" do include FFI class ToPtrTest def initialize(ptr) @ptr = ptr end def to_ptr @ptr end end it "Any object implementing #to_ptr can be passed as a :pointer parameter" do memory = FFI::MemoryPointer.new :long_long magic = 0x12345678 memory.put_int32(0, magic) tp = ToPtrTest.new(memory) PointerTestLib.ptr_ret_int32_t(tp, 0).should == magic end class PointerDelegate < DelegateClass(FFI::Pointer) def initialize(ptr) @ptr = ptr end def to_ptr @ptr end end it "A DelegateClass(Pointer) can be passed as a :pointer parameter" do memory = FFI::MemoryPointer.new :long_long magic = 0x12345678 memory.put_int32(0, magic) ptr = PointerDelegate.new(memory) PointerTestLib.ptr_ret_int32_t(ptr, 0).should == magic end it "Fixnum cannot be used as a Pointer argument" do lambda { PointerTestLib.ptr_ret_int32(0, 0) }.should raise_error end it "Bignum cannot be used as a Pointer argument" do lambda { PointerTestLib.ptr_ret_int32(0xfee1deadbeefcafebabe, 0) }.should raise_error end describe "pointer type methods" do it "#read_pointer" do memory = FFI::MemoryPointer.new :pointer PointerTestLib.ptr_set_pointer(memory, 0, PointerTestLib.ptr_from_address(0xdeadbeef)) memory.read_pointer.address.should == 0xdeadbeef end it "#write_pointer" do memory = FFI::MemoryPointer.new :pointer memory.write_pointer(PointerTestLib.ptr_from_address(0xdeadbeef)) PointerTestLib.ptr_ret_pointer(memory, 0).address.should == 0xdeadbeef end it "#read_array_of_pointer" do values = [0x12345678, 0xfeedf00d, 0xdeadbeef] memory = FFI::MemoryPointer.new :pointer, values.size values.each_with_index do |address, j| PointerTestLib.ptr_set_pointer(memory, j * FFI.type_size(:pointer), PointerTestLib.ptr_from_address(address)) end array = memory.read_array_of_pointer(values.size) values.each_with_index do |address, j| array[j].address.should == address end end end describe 'NULL' do it 'should be obtained using Pointer::NULL constant' do null_ptr = FFI::Pointer::NULL null_ptr.null?.should be_true end it 'should be obtained passing address 0 to constructor' do FFI::Pointer.new(0).null?.should be_true end it 'should raise an error when attempting read/write operations on it' do null_ptr = FFI::Pointer::NULL lambda { null_ptr.read_int }.should raise_error(FFI::NullPointerError) lambda { null_ptr.write_int(0xff1) }.should raise_error(FFI::NullPointerError) end it 'returns true when compared with nil' do (FFI::Pointer::NULL == nil).should be_true end end it "Pointer.size returns sizeof pointer on platform" do FFI::Pointer.size.should == (FFI::Platform::ADDRESS_SIZE / 8) end describe "#slice" do before(:each) do @mptr = FFI::MemoryPointer.new(:char, 12) @mptr.put_uint(0, 0x12345678) @mptr.put_uint(4, 0xdeadbeef) end it "contents of sliced pointer matches original pointer at offset" do @mptr.slice(4, 4).get_uint(0).should == 0xdeadbeef end it "modifying sliced pointer is reflected in original pointer" do @mptr.slice(4, 4).put_uint(0, 0xfee1dead) @mptr.get_uint(4).should == 0xfee1dead end it "access beyond bounds should raise IndexError" do lambda { @mptr.slice(4, 4).get_int(4) }.should raise_error(IndexError) end end describe "#type_size" do it "should be same as FFI.type_size(type)" do FFI::MemoryPointer.new(:int, 1).type_size.should == FFI.type_size(:int) end end end describe "AutoPointer" do loop_count = 30 wiggle_room = 5 # GC rarely cleans up all objects. we can get most of them, and that's enough to determine if the basic functionality is working. magic = 0x12345678 class AutoPointerTestHelper @@count = 0 def self.release @@count += 1 if @@count > 0 end def self.reset @@count = 0 end def self.gc_everything(count) loop = 5 while @@count < count && loop > 0 loop -= 1 TestLibrary.force_gc sleep 0.05 unless @@count == count end @@count = 0 end def self.finalizer self.method(:release).to_proc end end class AutoPointerSubclass < FFI::AutoPointer def self.release(ptr); end end it "cleanup via default release method" do AutoPointerSubclass.should_receive(:release).at_least(loop_count-wiggle_room).times AutoPointerTestHelper.reset loop_count.times do # note that if we called # AutoPointerTestHelper.method(:release).to_proc inline, we'd # have a reference to the pointer and it would never get GC'd. AutoPointerSubclass.new(PointerTestLib.ptr_from_address(magic)) end AutoPointerTestHelper.gc_everything loop_count end it "cleanup when passed a proc" do # NOTE: passing a proc is touchy, because it's so easy to create a memory leak. # # specifically, if we made an inline call to # # AutoPointerTestHelper.method(:release).to_proc # # we'd have a reference to the pointer and it would # never get GC'd. AutoPointerTestHelper.should_receive(:release).at_least(loop_count-wiggle_room).times AutoPointerTestHelper.reset loop_count.times do FFI::AutoPointer.new(PointerTestLib.ptr_from_address(magic), AutoPointerTestHelper.finalizer) end AutoPointerTestHelper.gc_everything loop_count end it "cleanup when passed a method" do AutoPointerTestHelper.should_receive(:release).at_least(loop_count-wiggle_room).times AutoPointerTestHelper.reset loop_count.times do FFI::AutoPointer.new(PointerTestLib.ptr_from_address(magic), AutoPointerTestHelper.method(:release)) end AutoPointerTestHelper.gc_everything loop_count end it "can be used as the return type of a function" do lambda do Module.new do extend FFI::Library ffi_lib TestLibrary::PATH class CustomAutoPointer < FFI::AutoPointer def self.release(ptr); end end attach_function :ptr_from_address, [ FFI::Platform::ADDRESS_SIZE == 32 ? :uint : :ulong_long ], CustomAutoPointer end end.should_not raise_error end describe "#new" do it "MemoryPointer argument raises TypeError" do lambda { FFI::AutoPointer.new(FFI::MemoryPointer.new(:int))}.should raise_error(::TypeError) end it "AutoPointer argument raises TypeError" do lambda { AutoPointerSubclass.new(AutoPointerSubclass.new(PointerTestLib.ptr_from_address(0))) }.should raise_error(::TypeError) end it "Buffer argument raises TypeError" do lambda { FFI::AutoPointer.new(FFI::Buffer.new(:int))}.should raise_error(::TypeError) end end describe "#autorelease?" do ptr_class = Class.new(FFI::AutoPointer) do def self.release(ptr); end end it "should be true by default" do ptr_class.new(FFI::Pointer.new(0xdeadbeef)).autorelease?.should be_true end it "should return false when autorelease=(false)" do ptr = ptr_class.new(FFI::Pointer.new(0xdeadbeef)) ptr.autorelease = false ptr.autorelease?.should be_false end end describe "#type_size" do ptr_class = Class.new(FFI::AutoPointer) do def self.release(ptr); end end it "type_size of AutoPointer should match wrapped Pointer" do aptr = ptr_class.new(FFI::Pointer.new(:int, 0xdeadbeef)) aptr.type_size.should == FFI.type_size(:int) end it "[] offset should match wrapped Pointer" do mptr = FFI::MemoryPointer.new(:int, 1024) aptr = ptr_class.new(FFI::Pointer.new(:int, mptr)) aptr[0].write_uint(0xfee1dead) aptr[1].write_uint(0xcafebabe) mptr[0].read_uint.should == 0xfee1dead mptr[1].read_uint.should == 0xcafebabe end end end ruby-ffi-1.9.3debian.orig/spec/ffi/dup_spec.rb0000644000175000017500000000226412261216360021413 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "Pointer#dup" do it "clone should be independent" do p1 = FFI::MemoryPointer.new(:char, 1024) p1.put_string(0, "test123"); p2 = p1.dup p1.put_string(0, "deadbeef") p2.get_string(0).should == "test123" end it "sliced pointer can be cloned" do p1 = FFI::MemoryPointer.new(:char, 1024) p1.put_string(0, "test123"); p2 = p1[1].dup # first char will be excised p2.get_string(0).should == "est123" p1.get_string(0).should == "test123" end it "sliced pointer when cloned is independent" do p1 = FFI::MemoryPointer.new(:char, 1024) p1.put_string(0, "test123"); p2 = p1[1].dup p1.put_string(0, "deadbeef") # first char will be excised p2.get_string(0).should == "est123" end end describe "Struct#dup" do it "clone should be independent" do s = Class.new(FFI::Struct) do layout :i, :int end s1 = s.new s1[:i] = 0x12345 s2 = s1.dup s1[:i] = 0x98765 s2[:i].should == 0x12345 s1[:i].should == 0x98765 end end ruby-ffi-1.9.3debian.orig/spec/ffi/errno_spec.rb0000644000175000017500000000072012261216360021743 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "FFI.errno" do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH attach_function :setLastError, [ :int ], :void end it "FFI.errno contains errno from last function" do LibTest.setLastError(0) LibTest.setLastError(0x12345678) FFI.errno.should == 0x12345678 end end ruby-ffi-1.9.3debian.orig/spec/ffi/string_spec.rb0000644000175000017500000000717512261216360022137 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "String tests" do include FFI module StrLibTest extend FFI::Library ffi_lib TestLibrary::PATH attach_function :ptr_ret_pointer, [ :pointer, :int], :string attach_function :string_equals, [ :string, :string ], :int attach_function :string_dummy, [ :string ], :void attach_function :string_null, [ ], :string end it "MemoryPointer#get_string returns a tainted string" do mp = FFI::MemoryPointer.new 1024 mp.put_string(0, "test\0") str = mp.get_string(0) str.tainted?.should == true end it "String returned by a method is tainted" do mp = FFI::MemoryPointer.new :pointer sp = FFI::MemoryPointer.new 1024 sp.put_string(0, "test") mp.put_pointer(0, sp) str = StrLibTest.ptr_ret_pointer(mp, 0) str.should == "test" str.tainted?.should == true end it "Poison null byte raises error" do s = "123\0abc" lambda { StrLibTest.string_equals(s, s) }.should raise_error end it "Tainted String parameter should throw a SecurityError" do $SAFE = 1 str = "test" str.taint begin LibTest.string_equals(str, str).should == false rescue SecurityError end end if false it "casts nil as NULL pointer" do StrLibTest.string_dummy(nil) end it "return nil for NULL char*" do StrLibTest.string_null.should == nil end it "reads an array of strings until encountering a NULL pointer" do strings = ["foo", "bar", "baz", "testing", "ffi"] ptrary = FFI::MemoryPointer.new(:pointer, 6) ary = strings.inject([]) do |a, str| f = FFI::MemoryPointer.new(1024) f.put_string(0, str) a << f end ary.insert(3, nil) ptrary.write_array_of_pointer(ary) ptrary.get_array_of_string(0).should == ["foo", "bar", "baz"] end it "reads an array of strings of the size specified, substituting nil when a pointer is NULL" do strings = ["foo", "bar", "baz", "testing", "ffi"] ptrary = FFI::MemoryPointer.new(:pointer, 6) ary = strings.inject([]) do |a, str| f = FFI::MemoryPointer.new(1024) f.put_string(0, str) a << f end ary.insert(2, nil) ptrary.write_array_of_pointer(ary) ptrary.get_array_of_string(0, 4).should == ["foo", "bar", nil, "baz"] end it "reads an array of strings, taking a memory offset parameter" do strings = ["foo", "bar", "baz", "testing", "ffi"] ptrary = FFI::MemoryPointer.new(:pointer, 5) ary = strings.inject([]) do |a, str| f = FFI::MemoryPointer.new(1024) f.put_string(0, str) a << f end ptrary.write_array_of_pointer(ary) ptrary.get_array_of_string(2 * FFI.type_size(:pointer), 3).should == ["baz", "testing", "ffi"] end it "raises an IndexError when trying to read an array of strings out of bounds" do strings = ["foo", "bar", "baz", "testing", "ffi"] ptrary = FFI::MemoryPointer.new(:pointer, 5) ary = strings.inject([]) do |a, str| f = FFI::MemoryPointer.new(1024) f.put_string(0, str) a << f end ptrary.write_array_of_pointer(ary) lambda { ptrary.get_array_of_string(0, 6) }.should raise_error end it "raises an IndexError when trying to read an array of strings using a negative offset" do strings = ["foo", "bar", "baz", "testing", "ffi"] ptrary = FFI::MemoryPointer.new(:pointer, 5) ary = strings.inject([]) do |a, str| f = FFI::MemoryPointer.new(1024) f.put_string(0, str) a << f end ptrary.write_array_of_pointer(ary) lambda { ptrary.get_array_of_string(-1) }.should raise_error end end ruby-ffi-1.9.3debian.orig/spec/ffi/ffi_spec.rb0000644000175000017500000000145012261216360021363 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "FFI" do describe ".map_library_name" do let(:prefix) { FFI::Platform::LIBPREFIX } let(:suffix) { FFI::Platform::LIBSUFFIX } it "should add platform library extension if not present" do FFI.map_library_name("#{prefix}dummy").should == "#{prefix}dummy.#{suffix}" end it "should add platform library extension even if lib suffix is present in name" do FFI.map_library_name("#{prefix}dummy_with_#{suffix}").should == "#{prefix}dummy_with_#{suffix}.#{suffix}" end it "should return Platform::LIBC when called with 'c'" do FFI.map_library_name('c').should == FFI::Library::LIBC end end end ruby-ffi-1.9.3debian.orig/spec/ffi/rbx/0000755000175000017500000000000012261216360020053 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/spec/ffi/rbx/attach_function_spec.rb0000644000175000017500000000131212261216360024560 0ustar terceiroterceirorequire File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) class Timeval < FFI::Struct layout :tv_sec, :ulong, 0, :tv_usec, :ulong, 4 end module LibC extend FFI::Library ffi_lib FFI::Library::LIBC attach_function :gettimeofday, [:pointer, :pointer], :int end describe FFI::Library, "#attach_function" do it "correctly returns a value for gettimeofday" do t = Timeval.new time = LibC.gettimeofday(t.pointer, nil) time.should be_kind_of(Integer) end it "correctly populates a struct for gettimeofday" do t = Timeval.new time = LibC.gettimeofday(t.pointer, nil) t[:tv_sec].should be_kind_of(Numeric) t[:tv_usec].should be_kind_of(Numeric) end end ruby-ffi-1.9.3debian.orig/spec/ffi/rbx/memory_pointer_spec.rb0000644000175000017500000000702112261216360024462 0ustar terceiroterceiro# coding: utf-8 require "rubygems" require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) module CTest extend FFI::Library ffi_lib FFI::Library::LIBC attach_function :strcat, [:pointer, :pointer], :pointer end describe "MemoryPointer" do it "makes a pointer from a string" do m = FFI::MemoryPointer.from_string("FFI is Awesome") m.total.should == 15 m.type_size.should == 1 end it "does not make a pointer from non-strings" do expect { FFI::MemoryPointer.from_string(nil) }.to raise_error(TypeError) end it "makes a pointer from a string with multibyte characters" do m = FFI::MemoryPointer.from_string("ぱんだ") m.total.should == 10 m.type_size.should == 1 end it "reads back a string" do m = FFI::MemoryPointer.from_string("FFI is Awesome") m.read_string.should == "FFI is Awesome" end it "makes a pointer for a certain number of bytes" do m = FFI::MemoryPointer.new(8) m.write_array_of_int([1,2]) m.read_array_of_int(2).should == [1,2] end it "allows access to an element of the pointer (as an array)" do m = FFI::MemoryPointer.new(:int, 2) m.write_array_of_int([1,2]) m[0].read_int.should == 1 m[1].read_int.should == 2 end it "allows writing as an int" do m = FFI::MemoryPointer.new(:int) m.write_int(1) m.read_int.should == 1 end it "allows writing as a long" do m = FFI::MemoryPointer.new(:long) m.write_long(10) m.read_long.should == 10 end it "raises an error if you try putting a long into a pointer of size 1" do m = FFI::MemoryPointer.new(1) lambda { m.write_long(10) }.should raise_error end it "raises an error if you try putting an int into a pointer of size 1" do m = FFI::MemoryPointer.new(1) lambda { m.write_int(10) }.should raise_error end # it "does not raise IndexError for opaque pointers" do # m = FFI::MemoryPointer.new(8) # p2 = FFI::MemoryPointer.new(1024) # m.write_long(p2.address) # p = m.read_pointer # lambda { p.write_int(10) }.should_not raise_error # end it "makes a pointer for a certain type" do m = FFI::MemoryPointer.new(:int) m.write_int(10) m.read_int.should == 10 end it "makes a memory pointer for a number of a certain type" do m = FFI::MemoryPointer.new(:int, 2) m.write_array_of_int([1,2]) m.read_array_of_int(2).should == [1,2] end it "makes a pointer for an object responding to #size" do m = FFI::MemoryPointer.new(Struct.new(:size).new(8)) m.write_array_of_int([1,2]) m.read_array_of_int(2).should == [1,2] end it "makes a pointer for a number of an object responding to #size" do m = FFI::MemoryPointer.new(Struct.new(:size).new(4), 2) m.write_array_of_int([1,2]) m.read_array_of_int(2).should == [1,2] end it "MemoryPointer#address returns correct value" do m = FFI::MemoryPointer.new(:long_long) magic = 0x12345678 m.write_long(magic) m.read_pointer.address.should == magic end it "MemoryPointer#null? returns true for zero value" do m = FFI::MemoryPointer.new(:long_long) m.write_long(0) m.read_pointer.null?.should == true end it "MemoryPointer#null? returns false for non-zero value" do m = FFI::MemoryPointer.new(:long_long) m.write_long(0x12345678) m.read_pointer.null?.should == false end it "initialize with block should execute block" do block_executed = false FFI::MemoryPointer.new(:pointer) do |ptr| block_executed = true end block_executed.should be_true end end ruby-ffi-1.9.3debian.orig/spec/ffi/rbx/spec_helper.rb0000644000175000017500000000012112261216360022663 0ustar terceiroterceirorequire File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) ruby-ffi-1.9.3debian.orig/spec/ffi/rbx/struct_spec.rb0000644000175000017500000000044512261216360022741 0ustar terceiroterceirorequire File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) class Timeval < FFI::Struct layout :tv_sec, :ulong, 0, :tv_usec, :ulong, 4 end describe FFI::Struct do it "allows setting fields" do t = Timeval.new t[:tv_sec] = 12 t[:tv_sec].should == 12 end endruby-ffi-1.9.3debian.orig/spec/ffi/union_spec.rb0000644000175000017500000000362112261216360021751 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) module LibTest Types = { 's8' => [:char, :c, 1], 's16' => [:short, :s, 0xff0], 's32' => [:int, :i, 0xff00], 's64' => [:long_long, :j, 0xffff00], 'long' => [:long, :l, 0xffff], 'f32' => [:float, :f, 1.0001], 'f64' => [:double, :d, 1.000000001] } class TestUnion < FFI::Union layout( :a, [:char, 10], :i, :int, :f, :float, :d, :double, :s, :short, :l, :long, :j, :long_long, :c, :char ) end Types.keys.each do |k| attach_function "union_align_#{k}", [ :pointer ], Types[k][0] attach_function "union_make_union_with_#{k}", [ Types[k][0] ], :pointer end attach_function :union_size, [], :uint end describe 'Union' do before do @u = LibTest::TestUnion.new end it 'should place all the fields at offset 0' do LibTest::TestUnion.members.all? { |m| LibTest::TestUnion.offset_of(m) == 0 }.should be_true end LibTest::Types.each do |k, type| it "should correctly align/write a #{type[0]} value" do @u[type[1]] = type[2] if k == 'f32' or k == 'f64' (@u[type[1]] - LibTest.send("union_align_#{k}", @u.to_ptr)).abs.should < 0.00001 else @u[type[1]].should == LibTest.send("union_align_#{k}", @u.to_ptr) end end end LibTest::Types.each do |k, type| it "should read a #{type[0]} value from memory" do @u = LibTest::TestUnion.new(LibTest.send("union_make_union_with_#{k}", type[2])) if k == 'f32' or k == 'f64' (@u[type[1]] - type[2]).abs.should < 0.00001 else @u[type[1]].should == type[2] end end end it 'should return a size equals to the size of the biggest field' do LibTest::TestUnion.size.should == LibTest.union_size end end ruby-ffi-1.9.3debian.orig/spec/ffi/function_spec.rb0000644000175000017500000000541712261216360022453 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe FFI::Function do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH attach_function :testFunctionAdd, [:int, :int, :pointer], :int end before do @libtest = FFI::DynamicLibrary.open(TestLibrary::PATH, FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_GLOBAL) end it 'is initialized with a signature and a block' do FFI::Function.new(:int, []) { } end it 'raises an error when passing a wrong signature' do lambda { FFI::Function.new([], :int).new { } }.should raise_error TypeError end it 'returns a native pointer' do FFI::Function.new(:int, []) { }.kind_of? FFI::Pointer end it 'can be used as callback from C passing to it a block' do function_add = FFI::Function.new(:int, [:int, :int]) { |a, b| a + b } LibTest.testFunctionAdd(10, 10, function_add).should == 20 end it 'can be used as callback from C passing to it a Proc object' do function_add = FFI::Function.new(:int, [:int, :int], Proc.new { |a, b| a + b }) LibTest.testFunctionAdd(10, 10, function_add).should == 20 end it 'can be used to wrap an existing function pointer' do FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd')).call(10, 10).should == 20 end it 'can be attached to a module' do module Foo; end fp = FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd')) fp.attach(Foo, 'add') Foo.add(10, 10).should == 20 end it 'can be used to extend an object' do fp = FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd')) foo = Object.new class << foo def singleton_class class << self; self; end end end fp.attach(foo.singleton_class, 'add') foo.add(10, 10).should == 20 end it 'can wrap a blocking function' do fp = FFI::Function.new(:void, [ :int ], @libtest.find_function('testBlocking'), :blocking => true) time = Time.now threads = [] threads << Thread.new { fp.call(2) } threads << Thread.new(time) { (Time.now - time).should < 1 } threads.each { |t| t.join } end it 'autorelease flag is set to true by default' do fp = FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd')) fp.autorelease?.should be_true end it 'can explicity free itself' do fp = FFI::Function.new(:int, []) { } fp.free lambda { fp.free }.should raise_error RuntimeError end it 'can\'t explicity free itself if not previously allocated' do fp = FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd')) lambda { fp.free }.should raise_error RuntimeError end end ruby-ffi-1.9.3debian.orig/spec/ffi/struct_by_ref_spec.rb0000644000175000017500000000214112261216360023467 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe FFI::Struct, ' by_ref' do before :all do @struct_class = struct_class = Class.new(FFI::Struct) do layout :a, :pointer end @api = Module.new do extend FFI::Library ffi_lib TestLibrary::PATH fn = FFI::Type::POINTER.size == FFI::Type::LONG.size ? :ret_ulong : ret_uint64_t attach_function :struct_test, fn, [ struct_class.by_ref ], :pointer end end it "should accept instances of exact struct class" do s = @struct_class.new @api.struct_test(s).should == s.pointer end it "should accept nil" do @api.struct_test(nil).should == nil end it "should reject other types" do lambda { @api.struct_test('test').should == nil }.should raise_error(TypeError) end it "should reject instances of other struct classes" do other_class = Class.new(FFI::Struct) do layout :a, :pointer end lambda { @api.struct_test(other_class.new) }.should raise_error(TypeError) end end ruby-ffi-1.9.3debian.orig/spec/ffi/spec_helper.rb0000644000175000017500000000150312261216360022075 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require 'rubygems' require 'rbconfig' if RUBY_PLATFORM =~/java/ libdir = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib")) $:.reject! { |p| p == libdir } else $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib"), File.join(File.dirname(__FILE__), "..", "..", "build", "#{RbConfig::CONFIG['host_cpu''arch']}", "ffi_c", RUBY_VERSION) end # puts "loadpath=#{$:.join(':')}" require "ffi" module TestLibrary PATH = "build/libtest.#{FFI::Platform::LIBSUFFIX}" def self.force_gc if RUBY_PLATFORM =~ /java/ java.lang.System.gc elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx' GC.run(true) else GC.start end end end module LibTest extend FFI::Library ffi_lib TestLibrary::PATH end ruby-ffi-1.9.3debian.orig/spec/ffi/struct_initialize_spec.rb0000644000175000017500000000166612261216360024375 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe FFI::Struct, ' with an initialize function' do it "should call the initialize function" do class StructWithInitialize < FFI::Struct layout :string, :string attr_accessor :magic def initialize super self.magic = 42 end end StructWithInitialize.new.magic.should == 42 end end describe FFI::ManagedStruct, ' with an initialize function' do it "should call the initialize function" do class ManagedStructWithInitialize < FFI::ManagedStruct layout :string, :string attr_accessor :magic def initialize super FFI::MemoryPointer.new(:pointer).put_int(0, 0x1234).get_pointer(0) self.magic = 42 end def self.release;end end ManagedStructWithInitialize.new.magic.should == 42 end end ruby-ffi-1.9.3debian.orig/spec/ffi/number_spec.rb0000644000175000017500000001531512261216360022114 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "Function with primitive integer arguments" do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH attach_function :ret_s8, [ :char ], :char attach_function :ret_u8, [ :uchar ], :uchar attach_function :ret_s16, [ :short ], :short attach_function :ret_u16, [ :ushort ], :ushort attach_function :ret_s32, [ :int ], :int attach_function :ret_u32, [ :uint ], :uint attach_function :ret_s64, [ :long_long ], :long_long attach_function :ret_u64, [ :ulong_long ], :ulong_long attach_function :ret_long, [ :long ], :long attach_function :ret_ulong, [ :ulong ], :ulong attach_function :set_s8, [ :char ], :void attach_function :get_s8, [ ], :char attach_function :set_float, [ :float ], :void attach_function :get_float, [ ], :float attach_function :set_double, [ :double ], :void attach_function :get_double, [ ], :double end it "int8.size" do FFI::TYPE_INT8.size.should == 1 end it "uint8.size" do FFI::TYPE_UINT8.size.should == 1 end it "int16.size" do FFI::TYPE_INT16.size.should == 2 end it "uint16.size" do FFI::TYPE_UINT16.size.should == 2 end it "int32.size" do FFI::TYPE_INT32.size.should == 4 end it "uint32.size" do FFI::TYPE_UINT32.size.should == 4 end it "int64.size" do FFI::TYPE_INT64.size.should == 8 end it "uint64.size" do FFI::TYPE_UINT64.size.should == 8 end it "float.size" do FFI::TYPE_FLOAT32.size.should == 4 end it "double.size" do FFI::TYPE_FLOAT64.size.should == 8 end [ 0, 127, -128, -1 ].each do |i| it ":char call(:char (#{i}))" do LibTest.ret_s8(i).should == i end end [ 0, 0x7f, 0x80, 0xff ].each do |i| it ":uchar call(:uchar (#{i}))" do LibTest.ret_u8(i).should == i end end [ 0, 0x7fff, -0x8000, -1 ].each do |i| it ":short call(:short (#{i}))" do LibTest.ret_s16(i).should == i end end [ 0, 0x7fff, 0x8000, 0xffff ].each do |i| it ":ushort call(:ushort (#{i}))" do LibTest.ret_u16(i).should == i end end [ 0, 0x7fffffff, -0x80000000, -1 ].each do |i| it ":int call(:int (#{i}))" do LibTest.ret_s32(i).should == i end end [ 0, 0x7fffffff, 0x80000000, 0xffffffff ].each do |i| it ":uint call(:uint (#{i}))" do LibTest.ret_u32(i).should == i end end [ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ].each do |i| it ":long_long call(:long_long (#{i}))" do LibTest.ret_s64(i).should == i end end [ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ].each do |i| it ":ulong_long call(:ulong_long (#{i}))" do LibTest.ret_u64(i).should == i end end if FFI::Platform::LONG_SIZE == 32 [ 0, 0x7fffffff, -0x80000000, -1 ].each do |i| it ":long call(:long (#{i}))" do LibTest.ret_long(i).should == i end end [ 0, 0x7fffffff, 0x80000000, 0xffffffff ].each do |i| it ":ulong call(:ulong (#{i}))" do LibTest.ret_ulong(i).should == i end end else [ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ].each do |i| it ":long call(:long (#{i}))" do LibTest.ret_long(i).should == i end end [ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ].each do |i| it ":ulong call(:ulong (#{i}))" do LibTest.ret_ulong(i).should == i end end [ 0.0, 0.1, 1.1, 1.23 ].each do |f| it ":float call(:double (#{f}))" do LibTest.set_float(f) (LibTest.get_float - f).abs.should < 0.001 end end [ 0.0, 0.1, 1.1, 1.23 ].each do |f| it ":double call(:double (#{f}))" do LibTest.set_double(f) (LibTest.get_double - f).abs.should < 0.001 end end end end describe "Integer parameter range checking" do [ 128, -129 ].each do |i| it ":char call(:char (#{i}))" do lambda { LibTest.ret_int8_t(i).should == i }.should raise_error end end [ -1, 256 ].each do |i| it ":uchar call(:uchar (#{i}))" do lambda { LibTest.ret_u_int8_t(i).should == i }.should raise_error end end [ 0x8000, -0x8001 ].each do |i| it ":short call(:short (#{i}))" do lambda { LibTest.ret_int16_t(i).should == i }.should raise_error end end [ -1, 0x10000 ].each do |i| it ":ushort call(:ushort (#{i}))" do lambda { LibTest.ret_u_int16_t(i).should == i }.should raise_error end end [ 0x80000000, -0x80000001 ].each do |i| it ":int call(:int (#{i}))" do lambda { LibTest.ret_int32_t(i).should == i }.should raise_error end end [ -1, 0x100000000 ].each do |i| it ":ushort call(:ushort (#{i}))" do lambda { LibTest.ret_u_int32_t(i).should == i }.should raise_error end end end describe "Three different size Integer arguments" do TYPE_MAP = { 's8' => :char, 'u8' => :uchar, 's16' => :short, 'u16' => :ushort, 's32' => :int, 'u32' => :uint, 's64' => :long_long, 'u64' => :ulong_long, 'sL' => :long, 'uL' => :ulong, 'f32' => :float, 'f64' => :double } TYPES = TYPE_MAP.keys module LibTest extend FFI::Library ffi_lib TestLibrary::PATH [ 's32', 'u32', 's64', 'u64' ].each do |rt| TYPES.each do |t1| TYPES.each do |t2| TYPES.each do |t3| begin attach_function "pack_#{t1}#{t2}#{t3}_#{rt}", [ TYPE_MAP[t1], TYPE_MAP[t2], TYPE_MAP[t3], :buffer_out ], :void rescue FFI::NotFoundError end end end end end end PACK_VALUES = { 's8' => [ 0x12 ], 'u8' => [ 0x34 ], 's16' => [ 0x5678 ], 'u16' => [ 0x9abc ], 's32' => [ 0x7654321f ], 'u32' => [ 0xfee1babe ], 'sL' => [ 0x1f2e3d4c ], 'uL' => [ 0xf7e8d9ca ], 's64' => [ 0x1eafdeadbeefa1b2 ], # 'f32' => [ 1.234567 ], 'f64' => [ 9.87654321 ] } def verify(p, off, t, v) if t == 'f32' p.get_float32(off).should == v elsif t == 'f64' p.get_float64(off).should == v else p.get_int64(off).should == v end end PACK_VALUES.keys.each do |t1| PACK_VALUES.keys.each do |t2| PACK_VALUES.keys.each do |t3| PACK_VALUES[t1].each do |v1| PACK_VALUES[t2].each do |v2| PACK_VALUES[t3].each do |v3| it "call(#{TYPE_MAP[t1]} (#{v1}), #{TYPE_MAP[t2]} (#{v2}), #{TYPE_MAP[t3]} (#{v3}))" do p = FFI::Buffer.new :long_long, 3 LibTest.send("pack_#{t1}#{t2}#{t3}_s64", v1, v2, v3, p) verify(p, 0, t1, v1) verify(p, 8, t2, v2) verify(p, 16, t3, v3) end end end end end end end end ruby-ffi-1.9.3debian.orig/spec/ffi/custom_type_spec.rb0000644000175000017500000000345112261216360023175 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "functions with custom types" do class Custom_enum extend FFI::DataConverter ToNativeMap= { :a => 1, :b => 2, :c => 3 } FromNativeMap = { 1 => :a, 2 => :b, 3 => :c } def self.native_type @native_type_called = true FFI::Type::INT32 end def self.to_native(val, ctx) @to_native_called = true ToNativeMap[val] end def self.from_native(val, ctx) @from_native_called = true FromNativeMap[val] end def self.native_type_called?; @native_type_called; end def self.from_native_called?; @from_native_called; end def self.to_native_called?; @to_native_called; end end it "can attach with custom return type" do lambda do Module.new do extend FFI::Library ffi_lib TestLibrary::PATH attach_function :ret_s32, [ :int ], Custom_enum end end.should_not raise_error end it "should return object of correct type" do m = Module.new do extend FFI::Library ffi_lib TestLibrary::PATH attach_function :ret_s32, [ :int ], Custom_enum end m.ret_s32(1).is_a?(Symbol).should be_true end it "from_native should be called for result" do m = Module.new do extend FFI::Library ffi_lib TestLibrary::PATH attach_function :ret_s32, [ :int ], Custom_enum end m.ret_s32(1) Custom_enum.from_native_called?.should be_true end it "to_native should be called for parameter" do m = Module.new do extend FFI::Library ffi_lib TestLibrary::PATH attach_function :ret_s32, [ Custom_enum ], :int end m.ret_s32(:a) Custom_enum.to_native_called?.should be_true end end ruby-ffi-1.9.3debian.orig/spec/ffi/buffer_spec.rb0000644000175000017500000001702112261216360022071 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "Buffer#total" do [1,2,3].each do |i| { :char => 1, :uchar => 1, :short => 2, :ushort => 2, :int => 4, :uint => 4, :long => FFI::Type::LONG.size, :ulong => FFI::Type::ULONG.size, :long_long => 8, :ulong_long => 8, :float => 4, :double => 8 }.each_pair do |t, s| it "Buffer.alloc_in(#{t}, #{i}).total == #{i * s}" do FFI::Buffer.alloc_in(t, i).total.should == i * s end it "Buffer.alloc_out(#{t}, #{i}).total == #{i * s}" do FFI::Buffer.alloc_out(t, i).total.should == i * s end it "Buffer.alloc_inout(#{t}, #{i}).total == #{i * s}" do FFI::Buffer.alloc_inout(t, i).total.should == i * s end end end end describe "Buffer#put_char" do bufsize = 4 (0..127).each do |i| (0..bufsize-1).each do |offset| it "put_char(#{offset}, #{i}).get_char(#{offset}) == #{i}" do FFI::Buffer.alloc_in(bufsize).put_char(offset, i).get_char(offset).should == i end end end end describe "Buffer#put_uchar" do bufsize = 4 (0..255).each do |i| (0..bufsize-1).each do |offset| it "Buffer.put_uchar(#{offset}, #{i}).get_uchar(#{offset}) == #{i}" do FFI::Buffer.alloc_in(bufsize).put_uchar(offset, i).get_uchar(offset).should == i end end end end describe "Buffer#put_short" do bufsize = 4 [0, 1, 128, 32767].each do |i| (0..bufsize-2).each do |offset| it "put_short(#{offset}, #{i}).get_short(#{offset}) == #{i}" do FFI::Buffer.alloc_in(bufsize).put_short(offset, i).get_short(offset).should == i end end end end describe "Buffer#put_ushort" do bufsize = 4 [ 0, 1, 128, 32767, 65535, 0xfee1, 0xdead, 0xbeef, 0xcafe ].each do |i| (0..bufsize-2).each do |offset| it "put_ushort(#{offset}, #{i}).get_ushort(#{offset}) == #{i}" do FFI::Buffer.alloc_in(bufsize).put_ushort(offset, i).get_ushort(offset).should == i end end end end describe "Buffer#put_int" do bufsize = 8 [0, 1, 128, 32767, 0x7ffffff ].each do |i| (0..bufsize-4).each do |offset| it "put_int(#{offset}, #{i}).get_int(#{offset}) == #{i}" do FFI::Buffer.alloc_in(bufsize).put_int(offset, i).get_int(offset).should == i end end end end describe "Buffer#put_uint" do bufsize = 8 [ 0, 1, 128, 32767, 65535, 0xfee1dead, 0xcafebabe, 0xffffffff ].each do |i| (0..bufsize-4).each do |offset| it "put_uint(#{offset}, #{i}).get_uint(#{offset}) == #{i}" do FFI::Buffer.alloc_in(bufsize).put_uint(offset, i).get_uint(offset).should == i end end end end describe "Buffer#put_long" do bufsize = 16 [0, 1, 128, 32767, 0x7ffffff ].each do |i| (0..bufsize-FFI::Type::LONG.size).each do |offset| it "put_long(#{offset}, #{i}).get_long(#{offset}) == #{i}" do FFI::Buffer.alloc_in(bufsize).put_long(offset, i).get_long(offset).should == i end end end end describe "Buffer#put_ulong" do bufsize = 16 [ 0, 1, 128, 32767, 65535, 0xfee1dead, 0xcafebabe, 0xffffffff ].each do |i| (0..bufsize-FFI::Type::LONG.size).each do |offset| it "put_ulong(#{offset}, #{i}).get_ulong(#{offset}) == #{i}" do FFI::Buffer.alloc_in(bufsize).put_ulong(offset, i).get_ulong(offset).should == i end end end end describe "Buffer#put_long_long" do bufsize = 16 [0, 1, 128, 32767, 0x7ffffffffffffff ].each do |i| (0..bufsize-8).each do |offset| it "put_long_long(#{offset}, #{i}).get_long_long(#{offset}) == #{i}" do FFI::Buffer.alloc_in(bufsize).put_long_long(offset, i).get_long_long(offset).should == i end end end end describe "Buffer#put_ulong_long" do bufsize = 16 [ 0, 1, 128, 32767, 65535, 0xdeadcafebabe, 0x7fffffffffffffff ].each do |i| (0..bufsize-8).each do |offset| it "put_ulong_long(#{offset}, #{i}).get_ulong_long(#{offset}) == #{i}" do FFI::Buffer.alloc_in(bufsize).put_ulong_long(offset, i).get_ulong_long(offset).should == i end end end end describe "Reading/Writing binary strings" do it "Buffer#put_bytes" do str = "hello\0world" buf = FFI::Buffer.new 1024 buf.put_bytes(0, str); s2 = buf.get_bytes(0, 11); s2.should == str end it "Buffer#put_bytes with index and length" do str = "hello\0world" buf = FFI::Buffer.new 1024 buf.put_bytes(0, str, 5, 6); s2 = buf.get_bytes(0, 6); s2.should == str[5..-1] end it "Buffer#put_bytes with only index" do str = "hello\0world" buf = FFI::Buffer.new 1024 buf.put_bytes(0, str, 5); s2 = buf.get_bytes(0, 6); s2.should == str[5..-1] end it "Buffer#put_bytes with index > str.length" do str = "hello\0world" buf = FFI::Buffer.new 1024 lambda { buf.put_bytes(0, str, 12); }.should raise_error end it "Buffer#put_bytes with length > str.length" do str = "hello\0world" buf = FFI::Buffer.new 1024 lambda { buf.put_bytes(0, str, 0, 12); }.should raise_error end it "Buffer#put_bytes with negative index" do str = "hello\0world" buf = FFI::Buffer.new 1024 lambda { buf.put_bytes(0, str, -1, 12); }.should raise_error end it "Buffer#write_bytes" do str = "hello\0world" buf = FFI::Buffer.new 1024 buf.write_bytes(str) s2 = buf.get_bytes(0, 11) s2.should == str end it "Buffer#write_bytes with index and length" do str = "hello\0world" buf = FFI::Buffer.new 1024 buf.write_bytes(str, 5, 6) s2 = buf.get_bytes(0, 6) s2.should == str[5..-1] end it "Buffer#write_bytes with only index" do str = "hello\0world" buf = FFI::Buffer.new 1024 buf.write_bytes(str, 5) s2 = buf.get_bytes(0, 6) s2.should == str[5..-1] end it "Buffer#write_bytes with index > str.length" do str = "hello\0world" buf = FFI::Buffer.new 1024 lambda { buf.write_bytes(str, 12) }.should raise_error end it "Buffer#put_bytes with length > str.length" do str = "hello\0world" buf = FFI::Buffer.new 1024 lambda { buf.put_bytes(0, str, 0, 12) }.should raise_error end it "Buffer#write_bytes with negative index" do str = "hello\0world" buf = FFI::Buffer.new 1024 lambda { buf.write_bytes(str, -1, 12) }.should raise_error end end describe "Reading/Writing ascii strings" do it "Buffer#put_string with string containing zero byte" do str = "hello\0world" buf = FFI::Buffer.new 1024 buf.put_string(0, str); s2 = buf.get_bytes(0, 11); s2.should == str end it "Buffer#get_string with string containing zero byte" do str = "hello\0world" buf = FFI::Buffer.new 1024 buf.put_bytes(0, str); s2 = buf.get_string(0, 11); s2.should == "hello" end it "Buffer#put_string without length should NUL terminate" do str = "hello" buf = FFI::Buffer.new 1024 buf.put_string(0, str); s2 = buf.get_bytes(0, 6); s2.should == "hello\0" end end describe "Buffer#put_pointer" do it "put_pointer(0, p).get_pointer(0) == p" do p = FFI::MemoryPointer.new :ulong_long p.put_uint(0, 0xdeadbeef) buf = FFI::Buffer.alloc_inout 8 p2 = buf.put_pointer(0, p).get_pointer(0) p2.should_not be_nil p2.should == p p2.get_uint(0).should == 0xdeadbeef end end describe "Buffer#size" do it "should return size" do buf = FFI::Buffer.new 14 buf.size.should == 14 end end describe "Buffer#initialize" do it "with block should execute block" do block_executed = false FFI::Buffer.new(:pointer) do |ptr| block_executed = true end block_executed.should be_true end end ruby-ffi-1.9.3debian.orig/spec/ffi/async_callback_spec.rb0000644000175000017500000000152712261216360023555 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "async callback" do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH AsyncIntCallback = callback [ :int ], :void @blocking = true attach_function :testAsyncCallback, [ AsyncIntCallback, :int ], :void end it ":int (0x7fffffff) argument" do v = 0xdeadbeef called = false cb = Proc.new {|i| v = i; called = true } LibTest.testAsyncCallback(cb, 0x7fffffff) called.should be_true v.should == 0x7fffffff end it "called a second time" do v = 0xdeadbeef called = false cb = Proc.new {|i| v = i; called = true } LibTest.testAsyncCallback(cb, 0x7fffffff) called.should be_true v.should == 0x7fffffff end end ruby-ffi-1.9.3debian.orig/spec/ffi/struct_packed_spec.rb0000644000175000017500000000233012261216360023450 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe FFI::Struct do it "packed :char followed by :int should have size of 5" do Class.new(FFI::Struct) do packed layout :c, :char, :i, :int end.size.should == 5 end it "packed :char followed by :int should have alignment of 1" do Class.new(FFI::Struct) do packed layout :c, :char, :i, :int end.alignment.should == 1 end it "packed(2) :char followed by :int should have size of 6" do Class.new(FFI::Struct) do packed 2 layout :c, :char, :i, :int end.size.should == 6 end it "packed(2) :char followed by :int should have alignment of 2" do Class.new(FFI::Struct) do packed 2 layout :c, :char, :i, :int end.alignment.should == 2 end it "packed :short followed by int should have size of 6" do Class.new(FFI::Struct) do packed layout :s, :short, :i, :int end.size.should == 6 end it "packed :short followed by int should have alignment of 1" do Class.new(FFI::Struct) do packed layout :s, :short, :i, :int end.alignment.should == 1 end end ruby-ffi-1.9.3debian.orig/spec/ffi/enum_spec.rb0000644000175000017500000001773112261216360021574 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) module TestEnum0 extend FFI::Library end module TestEnum1 extend FFI::Library ffi_lib TestLibrary::PATH enum [:c1, :c2, :c3, :c4] enum [:c5, 42, :c6, :c7, :c8] enum [:c9, 42, :c10, :c11, 4242, :c12] enum [:c13, 42, :c14, 4242, :c15, 424242, :c16, 42424242] attach_function :test_untagged_enum, [:int], :int end module TestEnum3 extend FFI::Library ffi_lib TestLibrary::PATH enum :enum_type1, [:c1, :c2, :c3, :c4] enum :enum_type2, [:c5, 42, :c6, :c7, :c8] enum :enum_type3, [:c9, 42, :c10, :c11, 4242, :c12] enum :enum_type4, [:c13, 42, :c14, 4242, :c15, 424242, :c16, 42424242] attach_function :test_tagged_typedef_enum1, [:enum_type1], :enum_type1 attach_function :test_tagged_typedef_enum2, [:enum_type2], :enum_type2 attach_function :test_tagged_typedef_enum3, [:enum_type3], :enum_type3 attach_function :test_tagged_typedef_enum4, [:enum_type4], :enum_type4 end describe "A library with no enum defined" do it "returns nil when asked for an enum" do TestEnum0.enum_type(:foo).should == nil end end describe "An untagged enum" do it "constants can be used as function parameters and return value" do TestEnum1.test_untagged_enum(:c1).should == 0 TestEnum1.test_untagged_enum(:c2).should == 1 TestEnum1.test_untagged_enum(:c3).should == 2 TestEnum1.test_untagged_enum(:c4).should == 3 TestEnum1.test_untagged_enum(:c5).should == 42 TestEnum1.test_untagged_enum(:c6).should == 43 TestEnum1.test_untagged_enum(:c7).should == 44 TestEnum1.test_untagged_enum(:c8).should == 45 TestEnum1.test_untagged_enum(:c9).should == 42 TestEnum1.test_untagged_enum(:c10).should == 43 TestEnum1.test_untagged_enum(:c11).should == 4242 TestEnum1.test_untagged_enum(:c12).should == 4243 TestEnum1.test_untagged_enum(:c13).should == 42 TestEnum1.test_untagged_enum(:c14).should == 4242 TestEnum1.test_untagged_enum(:c15).should == 424242 TestEnum1.test_untagged_enum(:c16).should == 42424242 end end describe "A tagged typedef enum" do it "is accessible through its tag" do TestEnum3.enum_type(:enum_type1).should_not == nil TestEnum3.enum_type(:enum_type2).should_not == nil TestEnum3.enum_type(:enum_type3).should_not == nil TestEnum3.enum_type(:enum_type4).should_not == nil end it "contains enum constants" do TestEnum3.enum_type(:enum_type1).symbols.length.should == 4 TestEnum3.enum_type(:enum_type2).symbols.length.should == 4 TestEnum3.enum_type(:enum_type3).symbols.length.should == 4 TestEnum3.enum_type(:enum_type4).symbols.length.should == 4 end it "constants can be used as function parameters and return value" do TestEnum3.test_tagged_typedef_enum1(:c1).should == :c1 TestEnum3.test_tagged_typedef_enum1(:c2).should == :c2 TestEnum3.test_tagged_typedef_enum1(:c3).should == :c3 TestEnum3.test_tagged_typedef_enum1(:c4).should == :c4 TestEnum3.test_tagged_typedef_enum2(:c5).should == :c5 TestEnum3.test_tagged_typedef_enum2(:c6).should == :c6 TestEnum3.test_tagged_typedef_enum2(:c7).should == :c7 TestEnum3.test_tagged_typedef_enum2(:c8).should == :c8 TestEnum3.test_tagged_typedef_enum3(:c9).should == :c9 TestEnum3.test_tagged_typedef_enum3(:c10).should == :c10 TestEnum3.test_tagged_typedef_enum3(:c11).should == :c11 TestEnum3.test_tagged_typedef_enum3(:c12).should == :c12 TestEnum3.test_tagged_typedef_enum4(:c13).should == :c13 TestEnum3.test_tagged_typedef_enum4(:c14).should == :c14 TestEnum3.test_tagged_typedef_enum4(:c15).should == :c15 TestEnum3.test_tagged_typedef_enum4(:c16).should == :c16 end it "integers can be used instead of constants" do TestEnum3.test_tagged_typedef_enum1(0).should == :c1 TestEnum3.test_tagged_typedef_enum1(1).should == :c2 TestEnum3.test_tagged_typedef_enum1(2).should == :c3 TestEnum3.test_tagged_typedef_enum1(3).should == :c4 TestEnum3.test_tagged_typedef_enum2(42).should == :c5 TestEnum3.test_tagged_typedef_enum2(43).should == :c6 TestEnum3.test_tagged_typedef_enum2(44).should == :c7 TestEnum3.test_tagged_typedef_enum2(45).should == :c8 TestEnum3.test_tagged_typedef_enum3(42).should == :c9 TestEnum3.test_tagged_typedef_enum3(43).should == :c10 TestEnum3.test_tagged_typedef_enum3(4242).should == :c11 TestEnum3.test_tagged_typedef_enum3(4243).should == :c12 TestEnum3.test_tagged_typedef_enum4(42).should == :c13 TestEnum3.test_tagged_typedef_enum4(4242).should == :c14 TestEnum3.test_tagged_typedef_enum4(424242).should == :c15 TestEnum3.test_tagged_typedef_enum4(42424242).should == :c16 end end describe "All enums" do it "have autonumbered constants when defined with names only" do TestEnum1.enum_value(:c1).should == 0 TestEnum1.enum_value(:c2).should == 1 TestEnum1.enum_value(:c3).should == 2 TestEnum1.enum_value(:c4).should == 3 TestEnum3.enum_value(:c1).should == 0 TestEnum3.enum_value(:c2).should == 1 TestEnum3.enum_value(:c3).should == 2 TestEnum3.enum_value(:c4).should == 3 end it "can have an explicit first constant and autonumbered subsequent constants" do TestEnum1.enum_value(:c5).should == 42 TestEnum1.enum_value(:c6).should == 43 TestEnum1.enum_value(:c7).should == 44 TestEnum1.enum_value(:c8).should == 45 TestEnum3.enum_value(:c5).should == 42 TestEnum3.enum_value(:c6).should == 43 TestEnum3.enum_value(:c7).should == 44 TestEnum3.enum_value(:c8).should == 45 end it "can have a mix of explicit and autonumbered constants" do TestEnum1.enum_value(:c9).should == 42 TestEnum1.enum_value(:c10).should == 43 TestEnum1.enum_value(:c11).should == 4242 TestEnum1.enum_value(:c12).should == 4243 TestEnum3.enum_value(:c9).should == 42 TestEnum3.enum_value(:c10).should == 43 TestEnum3.enum_value(:c11).should == 4242 TestEnum3.enum_value(:c12).should == 4243 end it "can have all its constants explicitely valued" do TestEnum1.enum_value(:c13).should == 42 TestEnum1.enum_value(:c14).should == 4242 TestEnum1.enum_value(:c15).should == 424242 TestEnum1.enum_value(:c16).should == 42424242 TestEnum3.enum_value(:c13).should == 42 TestEnum3.enum_value(:c14).should == 4242 TestEnum3.enum_value(:c15).should == 424242 TestEnum3.enum_value(:c16).should == 42424242 end it "return the constant corresponding to a specific value" do enum = TestEnum3.enum_type(:enum_type1) enum[0].should == :c1 enum[1].should == :c2 enum[2].should == :c3 enum[3].should == :c4 enum = TestEnum3.enum_type(:enum_type2) enum[42].should == :c5 enum[43].should == :c6 enum[44].should == :c7 enum[45].should == :c8 enum = TestEnum3.enum_type(:enum_type3) enum[42].should == :c9 enum[43].should == :c10 enum[4242].should == :c11 enum[4243].should == :c12 enum = TestEnum3.enum_type(:enum_type4) enum[42].should == :c13 enum[4242].should == :c14 enum[424242].should == :c15 enum[42424242].should == :c16 end it "return nil for values that don't have a symbol" do enum = TestEnum3.enum_type(:enum_type1) enum[-1].should == nil enum[4].should == nil enum = TestEnum3.enum_type(:enum_type2) enum[0].should == nil enum[41].should == nil enum[46].should == nil enum = TestEnum3.enum_type(:enum_type3) enum[0].should == nil enum[41].should == nil enum[44].should == nil enum[4241].should == nil enum[4244].should == nil enum = TestEnum3.enum_type(:enum_type4) enum[0].should == nil enum[41].should == nil enum[43].should == nil enum[4241].should == nil enum[4243].should == nil enum[424241].should == nil enum[424243].should == nil enum[42424241].should == nil enum[42424243].should == nil end it "duplicate enum keys rejected" do lambda { enum [ :a, 0xfee1dead, :b, 0xdeadbeef, :a, 0 ] }.should raise_error end end ruby-ffi-1.9.3debian.orig/spec/ffi/callback_spec.rb0000644000175000017500000005122412261216360022357 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "Callback" do # module LibC # extend FFI::Library # callback :qsort_cmp, [ :pointer, :pointer ], :int # attach_function :qsort, [ :pointer, :int, :int, :qsort_cmp ], :int # end # it "arguments get passed correctly" do # p = MemoryPointer.new(:int, 2) # p.put_array_of_int32(0, [ 1 , 2 ]) # args = [] # cmp = proc do |p1, p2| args.push(p1.get_int(0)); args.push(p2.get_int(0)); 0; end # # this is a bit dodgey, as it relies on qsort passing the args in order # LibC.qsort(p, 2, 4, cmp) # args.should == [ 1, 2 ] # end # # it "Block can be substituted for Callback as last argument" do # p = MemoryPointer.new(:int, 2) # p.put_array_of_int32(0, [ 1 , 2 ]) # args = [] # # this is a bit dodgey, as it relies on qsort passing the args in order # LibC.qsort(p, 2, 4) do |p1, p2| # args.push(p1.get_int(0)) # args.push(p2.get_int(0)) # 0 # end # args.should == [ 1, 2 ] # end module LibTest extend FFI::Library ffi_lib TestLibrary::PATH class S8F32S32 < FFI::Struct layout :s8, :char, :f32, :float, :s32, :int end callback :cbVrS8, [ ], :char callback :cbVrU8, [ ], :uchar callback :cbVrS16, [ ], :short callback :cbVrU16, [ ], :ushort callback :cbVrS32, [ ], :int callback :cbVrU32, [ ], :uint callback :cbVrL, [ ], :long callback :cbVrUL, [ ], :ulong callback :cbVrS64, [ ], :long_long callback :cbVrU64, [ ], :ulong_long callback :cbVrP, [], :pointer callback :cbVrZ, [], :bool callback :cbCrV, [ :char ], :void callback :cbSrV, [ :short ], :void callback :cbIrV, [ :int ], :void callback :cbLrV, [ :long ], :void callback :cbULrV, [ :ulong ], :void callback :cbLrV, [ :long_long ], :void callback :cbVrT, [ ], S8F32S32.by_value callback :cbTrV, [ S8F32S32.by_value ], :void callback :cbYrV, [ S8F32S32.ptr ], :void callback :cbVrY, [ ], S8F32S32.ptr attach_function :testCallbackVrS8, :testClosureVrB, [ :cbVrS8 ], :char attach_function :testCallbackVrU8, :testClosureVrB, [ :cbVrU8 ], :uchar attach_function :testCallbackVrS16, :testClosureVrS, [ :cbVrS16 ], :short attach_function :testCallbackVrU16, :testClosureVrS, [ :cbVrU16 ], :ushort attach_function :testCallbackVrS32, :testClosureVrI, [ :cbVrS32 ], :int attach_function :testCallbackVrU32, :testClosureVrI, [ :cbVrU32 ], :uint attach_function :testCallbackVrL, :testClosureVrL, [ :cbVrL ], :long attach_function :testCallbackVrZ, :testClosureVrZ, [ :cbVrZ ], :bool attach_function :testCallbackVrUL, :testClosureVrL, [ :cbVrUL ], :ulong attach_function :testCallbackVrS64, :testClosureVrLL, [ :cbVrS64 ], :long_long attach_function :testCallbackVrU64, :testClosureVrLL, [ :cbVrU64 ], :ulong_long attach_function :testCallbackVrP, :testClosureVrP, [ :cbVrP ], :pointer attach_function :testCallbackVrY, :testClosureVrP, [ :cbVrY ], S8F32S32.ptr attach_function :testCallbackVrT, :testClosureVrT, [ :cbVrT ], S8F32S32.by_value attach_function :testCallbackTrV, :testClosureTrV, [ :cbTrV, S8F32S32.ptr ], :void attach_variable :cbVrS8, :gvar_pointer, :cbVrS8 attach_variable :pVrS8, :gvar_pointer, :pointer attach_function :testGVarCallbackVrS8, :testClosureVrB, [ :pointer ], :char attach_function :testOptionalCallbackCrV, :testOptionalClosureBrV, [ :cbCrV, :char ], :void end it "returning :char (0)" do LibTest.testCallbackVrS8 { 0 }.should == 0 end it "returning :char (127)" do LibTest.testCallbackVrS8 { 127 }.should == 127 end it "returning :char (-128)" do LibTest.testCallbackVrS8 { -128 }.should == -128 end # test wrap around it "returning :char (128)" do LibTest.testCallbackVrS8 { 128 }.should == -128 end it "returning :char (255)" do LibTest.testCallbackVrS8 { 0xff }.should == -1 end it "returning :uchar (0)" do LibTest.testCallbackVrU8 { 0 }.should == 0 end it "returning :uchar (0xff)" do LibTest.testCallbackVrU8 { 0xff }.should == 0xff end it "returning :uchar (-1)" do LibTest.testCallbackVrU8 { -1 }.should == 0xff end it "returning :uchar (128)" do LibTest.testCallbackVrU8 { 128 }.should == 128 end it "returning :uchar (-128)" do LibTest.testCallbackVrU8 { -128 }.should == 128 end it "returning :short (0)" do LibTest.testCallbackVrS16 { 0 }.should == 0 end it "returning :short (0x7fff)" do LibTest.testCallbackVrS16 { 0x7fff }.should == 0x7fff end # test wrap around it "returning :short (0x8000)" do LibTest.testCallbackVrS16 { 0x8000 }.should == -0x8000 end it "returning :short (0xffff)" do LibTest.testCallbackVrS16 { 0xffff }.should == -1 end it "returning :ushort (0)" do LibTest.testCallbackVrU16 { 0 }.should == 0 end it "returning :ushort (0x7fff)" do LibTest.testCallbackVrU16 { 0x7fff }.should == 0x7fff end it "returning :ushort (0x8000)" do LibTest.testCallbackVrU16 { 0x8000 }.should == 0x8000 end it "returning :ushort (0xffff)" do LibTest.testCallbackVrU16 { 0xffff }.should == 0xffff end it "returning :ushort (-1)" do LibTest.testCallbackVrU16 { -1 }.should == 0xffff end it "returning :int (0)" do LibTest.testCallbackVrS32 { 0 }.should == 0 end it "returning :int (0x7fffffff)" do LibTest.testCallbackVrS32 { 0x7fffffff }.should == 0x7fffffff end # test wrap around it "returning :int (-0x80000000)" do LibTest.testCallbackVrS32 { -0x80000000 }.should == -0x80000000 end it "returning :int (-1)" do LibTest.testCallbackVrS32 { -1 }.should == -1 end it "returning :uint (0)" do LibTest.testCallbackVrU32 { 0 }.should == 0 end it "returning :uint (0x7fffffff)" do LibTest.testCallbackVrU32 { 0x7fffffff }.should == 0x7fffffff end # test wrap around it "returning :uint (0x80000000)" do LibTest.testCallbackVrU32 { 0x80000000 }.should == 0x80000000 end it "returning :uint (0xffffffff)" do LibTest.testCallbackVrU32 { 0xffffffff }.should == 0xffffffff end it "returning :uint (-1)" do LibTest.testCallbackVrU32 { -1 }.should == 0xffffffff end it "returning :long (0)" do LibTest.testCallbackVrL { 0 }.should == 0 end it "returning :long (0x7fffffff)" do LibTest.testCallbackVrL { 0x7fffffff }.should == 0x7fffffff end # test wrap around it "returning :long (-0x80000000)" do LibTest.testCallbackVrL { -0x80000000 }.should == -0x80000000 end it "returning :long (-1)" do LibTest.testCallbackVrL { -1 }.should == -1 end it "returning :ulong (0)" do LibTest.testCallbackVrUL { 0 }.should == 0 end it "returning :ulong (0x7fffffff)" do LibTest.testCallbackVrUL { 0x7fffffff }.should == 0x7fffffff end # test wrap around it "returning :ulong (0x80000000)" do LibTest.testCallbackVrUL { 0x80000000 }.should == 0x80000000 end it "returning :ulong (0xffffffff)" do LibTest.testCallbackVrUL { 0xffffffff }.should == 0xffffffff end it "Callback returning :ulong (-1)" do if FFI::Platform::LONG_SIZE == 32 LibTest.testCallbackVrUL { -1 }.should == 0xffffffff else LibTest.testCallbackVrUL { -1 }.should == 0xffffffffffffffff end end it "returning :long_long (0)" do LibTest.testCallbackVrS64 { 0 }.should == 0 end it "returning :long_long (0x7fffffffffffffff)" do LibTest.testCallbackVrS64 { 0x7fffffffffffffff }.should == 0x7fffffffffffffff end # test wrap around it "returning :long_long (-0x8000000000000000)" do LibTest.testCallbackVrS64 { -0x8000000000000000 }.should == -0x8000000000000000 end it "returning :long_long (-1)" do LibTest.testCallbackVrS64 { -1 }.should == -1 end it "returning bool" do LibTest.testCallbackVrZ { true }.should be_true end it "returning :pointer (nil)" do LibTest.testCallbackVrP { nil }.null?.should be_true end it "returning :pointer (MemoryPointer)" do p = FFI::MemoryPointer.new :long LibTest.testCallbackVrP { p }.should == p end it "returning struct by value" do s = LibTest::S8F32S32.new s[:s8] = 0x12 s[:s32] = 0x1eefbeef s[:f32] = 1.234567 ret = LibTest.testCallbackVrT { s } ret[:s8].should == s[:s8] ret[:f32].should == s[:f32] ret[:s32].should == s[:s32] end it "struct by value parameter" do s = LibTest::S8F32S32.new s[:s8] = 0x12 s[:s32] = 0x1eefbeef s[:f32] = 1.234567 s2 = LibTest::S8F32S32.new LibTest.testCallbackTrV(s) do |struct| s2[:s8] = struct[:s8] s2[:f32] = struct[:f32] s2[:s32] = struct[:s32] end end it "global variable" do proc = Proc.new { 0x1e } LibTest.cbVrS8 = proc LibTest.testGVarCallbackVrS8(LibTest.pVrS8).should == 0x1e end describe "When the callback is considered optional by the underlying library" do it "should handle receiving 'nil' in place of the closure" do LibTest.testOptionalCallbackCrV(nil, 13) end end describe 'when inlined' do it 'could be anonymous' do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH attach_function :testAnonymousCallbackVrS8, :testClosureVrB, [ callback([ ], :char) ], :char end LibTest.testAnonymousCallbackVrS8 { 0 }.should == 0 end end describe "as return value" do it "should not blow up when a callback is defined that returns a callback" do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH callback :cb_return_type_1, [ :short ], :short callback :cb_lookup_1, [ :short ], :cb_return_type_1 attach_function :testReturnsCallback_1, :testReturnsClosure, [ :cb_lookup_1, :short ], :cb_return_type_1 end end it "should return a callback" do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH callback :cb_return_type, [ :int ], :int callback :cb_lookup, [ ], :cb_return_type attach_function :testReturnsCallback, :testReturnsClosure, [ :cb_lookup, :int ], :int end lookup_proc_called = false return_proc_called = false return_proc = Proc.new do |a| return_proc_called = true a * 2 end lookup_proc = Proc.new do lookup_proc_called = true return_proc end val = LibTest.testReturnsCallback(lookup_proc, 0x1234) val.should == 0x1234 * 2 lookup_proc_called.should be_true return_proc_called.should be_true end it "should return a method callback" do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH callback :cb_return_type, [ :int ], :int callback :cb_lookup, [ ], :cb_return_type attach_function :testReturnsCallback_2, :testReturnsClosure, [ :cb_lookup, :int ], :int end module MethodCallback def self.lookup method(:perform) end def self.perform num num * 2 end end LibTest.testReturnsCallback_2(MethodCallback.method(:lookup), 0x1234).should == 0x2468 end it 'should not blow up when a callback takes a callback as argument' do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH callback :cb_argument, [ :int ], :int callback :cb_with_cb_argument, [ :cb_argument, :int ], :int attach_function :testCallbackAsArgument_2, :testArgumentClosure, [ :cb_with_cb_argument, :int ], :int end end it 'should be able to use the callback argument' do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH callback :cb_argument, [ :int ], :int callback :cb_with_cb_argument, [ :cb_argument, :int ], :int attach_function :testCallbackAsArgument, :testArgumentClosure, [ :cb_with_cb_argument, :cb_argument, :int ], :int end callback_arg_called = false callback_with_callback_arg_called = false callback_arg = Proc.new do |val| callback_arg_called = true val * 2 end callback_with_callback_arg = Proc.new do |cb, val| callback_with_callback_arg_called = true cb.call(val) end val = LibTest.testCallbackAsArgument(callback_with_callback_arg, callback_arg, 0xff1) val.should == 0xff1 * 2 callback_arg_called.should be_true callback_with_callback_arg_called.should be_true end it 'function returns callable object' do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH callback :funcptr, [ :int ], :int attach_function :testReturnsFunctionPointer, [ ], :funcptr end f = LibTest.testReturnsFunctionPointer f.call(3).should == 6 end end end describe "Callback with " do # # Test callbacks that take an argument, returning void # module LibTest extend FFI::Library ffi_lib TestLibrary::PATH class S8F32S32 < FFI::Struct layout :s8, :char, :f32, :float, :s32, :int end callback :cbS8rV, [ :char ], :void callback :cbU8rV, [ :uchar ], :void callback :cbS16rV, [ :short ], :void callback :cbU16rV, [ :ushort ], :void callback :cbZrV, [ :bool ], :void callback :cbS32rV, [ :int ], :void callback :cbU32rV, [ :uint ], :void callback :cbLrV, [ :long ], :void callback :cbULrV, [ :ulong ], :void callback :cbArV, [ :string ], :void callback :cbPrV, [ :pointer], :void callback :cbYrV, [ S8F32S32.ptr ], :void callback :cbS64rV, [ :long_long ], :void attach_function :testCallbackCrV, :testClosureBrV, [ :cbS8rV, :char ], :void attach_function :testCallbackU8rV, :testClosureBrV, [ :cbU8rV, :uchar ], :void attach_function :testCallbackSrV, :testClosureSrV, [ :cbS16rV, :short ], :void attach_function :testCallbackU16rV, :testClosureSrV, [ :cbU16rV, :ushort ], :void attach_function :testCallbackZrV, :testClosureZrV, [ :cbZrV, :bool ], :void attach_function :testCallbackIrV, :testClosureIrV, [ :cbS32rV, :int ], :void attach_function :testCallbackU32rV, :testClosureIrV, [ :cbU32rV, :uint ], :void attach_function :testCallbackLrV, :testClosureLrV, [ :cbLrV, :long ], :void attach_function :testCallbackULrV, :testClosureULrV, [ :cbULrV, :ulong ], :void attach_function :testCallbackLLrV, :testClosureLLrV, [ :cbS64rV, :long_long ], :void attach_function :testCallbackArV, :testClosurePrV, [ :cbArV, :string ], :void attach_function :testCallbackPrV, :testClosurePrV, [ :cbPrV, :pointer], :void attach_function :testCallbackYrV, :testClosurePrV, [ :cbYrV, S8F32S32.in ], :void end it "function with Callback plus another arg should raise error if no arg given" do lambda { LibTest.testCallbackCrV { |*a| }}.should raise_error end it ":char (0) argument" do v = 0xdeadbeef LibTest.testCallbackCrV(0) { |i| v = i } v.should == 0 end it ":char (127) argument" do v = 0xdeadbeef LibTest.testCallbackCrV(127) { |i| v = i } v.should == 127 end it ":char (-128) argument" do v = 0xdeadbeef LibTest.testCallbackCrV(-128) { |i| v = i } v.should == -128 end it ":char (-1) argument" do v = 0xdeadbeef LibTest.testCallbackCrV(-1) { |i| v = i } v.should == -1 end it ":uchar (0) argument" do v = 0xdeadbeef LibTest.testCallbackU8rV(0) { |i| v = i } v.should == 0 end it ":uchar (127) argument" do v = 0xdeadbeef LibTest.testCallbackU8rV(127) { |i| v = i } v.should == 127 end it ":uchar (128) argument" do v = 0xdeadbeef LibTest.testCallbackU8rV(128) { |i| v = i } v.should == 128 end it ":uchar (255) argument" do v = 0xdeadbeef LibTest.testCallbackU8rV(255) { |i| v = i } v.should == 255 end it ":short (0) argument" do v = 0xdeadbeef LibTest.testCallbackSrV(0) { |i| v = i } v.should == 0 end it ":short (0x7fff) argument" do v = 0xdeadbeef LibTest.testCallbackSrV(0x7fff) { |i| v = i } v.should == 0x7fff end it ":short (-0x8000) argument" do v = 0xdeadbeef LibTest.testCallbackSrV(-0x8000) { |i| v = i } v.should == -0x8000 end it ":short (-1) argument" do v = 0xdeadbeef LibTest.testCallbackSrV(-1) { |i| v = i } v.should == -1 end it ":ushort (0) argument" do v = 0xdeadbeef LibTest.testCallbackU16rV(0) { |i| v = i } v.should == 0 end it ":ushort (0x7fff) argument" do v = 0xdeadbeef LibTest.testCallbackU16rV(0x7fff) { |i| v = i } v.should == 0x7fff end it ":ushort (0x8000) argument" do v = 0xdeadbeef LibTest.testCallbackU16rV(0x8000) { |i| v = i } v.should == 0x8000 end it ":ushort (0xffff) argument" do v = 0xdeadbeef LibTest.testCallbackU16rV(0xffff) { |i| v = i } v.should == 0xffff end it ":bool (true) argument" do v = false LibTest.testCallbackZrV(true) { |i| v = i } v.should be_true end it ":int (0) argument" do v = 0xdeadbeef LibTest.testCallbackIrV(0) { |i| v = i } v.should == 0 end it ":int (0x7fffffff) argument" do v = 0xdeadbeef LibTest.testCallbackIrV(0x7fffffff) { |i| v = i } v.should == 0x7fffffff end it ":int (-0x80000000) argument" do v = 0xdeadbeef LibTest.testCallbackIrV(-0x80000000) { |i| v = i } v.should == -0x80000000 end it ":int (-1) argument" do v = 0xdeadbeef LibTest.testCallbackIrV(-1) { |i| v = i } v.should == -1 end it ":uint (0) argument" do v = 0xdeadbeef LibTest.testCallbackU32rV(0) { |i| v = i } v.should == 0 end it ":uint (0x7fffffff) argument" do v = 0xdeadbeef LibTest.testCallbackU32rV(0x7fffffff) { |i| v = i } v.should == 0x7fffffff end it ":uint (0x80000000) argument" do v = 0xdeadbeef LibTest.testCallbackU32rV(0x80000000) { |i| v = i } v.should == 0x80000000 end it ":uint (0xffffffff) argument" do v = 0xdeadbeef LibTest.testCallbackU32rV(0xffffffff) { |i| v = i } v.should == 0xffffffff end it ":long (0) argument" do v = 0xdeadbeef LibTest.testCallbackLrV(0) { |i| v = i } v.should == 0 end it ":long (0x7fffffff) argument" do v = 0xdeadbeef LibTest.testCallbackLrV(0x7fffffff) { |i| v = i } v.should == 0x7fffffff end it ":long (-0x80000000) argument" do v = 0xdeadbeef LibTest.testCallbackLrV(-0x80000000) { |i| v = i } v.should == -0x80000000 end it ":long (-1) argument" do v = 0xdeadbeef LibTest.testCallbackLrV(-1) { |i| v = i } v.should == -1 end it ":ulong (0) argument" do v = 0xdeadbeef LibTest.testCallbackULrV(0) { |i| v = i } v.should == 0 end it ":ulong (0x7fffffff) argument" do v = 0xdeadbeef LibTest.testCallbackULrV(0x7fffffff) { |i| v = i } v.should == 0x7fffffff end it ":ulong (0x80000000) argument" do v = 0xdeadbeef LibTest.testCallbackULrV(0x80000000) { |i| v = i } v.should == 0x80000000 end it ":ulong (0xffffffff) argument" do v = 0xdeadbeef LibTest.testCallbackULrV(0xffffffff) { |i| v = i } v.should == 0xffffffff end it ":long_long (0) argument" do v = 0xdeadbeef LibTest.testCallbackLLrV(0) { |i| v = i } v.should == 0 end it ":long_long (0x7fffffffffffffff) argument" do v = 0xdeadbeef LibTest.testCallbackLLrV(0x7fffffffffffffff) { |i| v = i } v.should == 0x7fffffffffffffff end it ":long_long (-0x8000000000000000) argument" do v = 0xdeadbeef LibTest.testCallbackLLrV(-0x8000000000000000) { |i| v = i } v.should == -0x8000000000000000 end it ":long_long (-1) argument" do v = 0xdeadbeef LibTest.testCallbackLLrV(-1) { |i| v = i } v.should == -1 end it ":string argument" do v = nil LibTest.testCallbackArV("Hello, World") { |i| v = i } v.should == "Hello, World" end it ":string (nil) argument" do v = "Hello, World" LibTest.testCallbackArV(nil) { |i| v = i } v.should be_nil end it ":pointer argument" do v = nil magic = FFI::Pointer.new(0xdeadbeef) LibTest.testCallbackPrV(magic) { |i| v = i } v.should == magic end it ":pointer (nil) argument" do v = "Hello, World" LibTest.testCallbackPrV(nil) { |i| v = i } v.should == FFI::Pointer::NULL end it "struct by reference argument" do v = nil magic = LibTest::S8F32S32.new LibTest.testCallbackYrV(magic) { |i| v = i } v.class.should == magic.class v.pointer == magic.pointer end it "struct by reference argument with nil value" do v = LibTest::S8F32S32.new LibTest.testCallbackYrV(nil) { |i| v = i } v.is_a?(FFI::Struct).should be_true v.pointer.should == FFI::Pointer::NULL end it "varargs parameters are rejected" do lambda { Module.new do extend FFI::Library ffi_lib TestLibrary::PATH callback :cbVrL, [ :varargs ], :long end }.should raise_error(ArgumentError) end end ruby-ffi-1.9.3debian.orig/spec/ffi/strptr_spec.rb0000644000175000017500000000236312261216360022161 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "functions returning :strptr" do it "can attach function with :strptr return type" do lambda do Module.new do extend FFI::Library ffi_lib FFI::Library::LIBC if !FFI::Platform.windows? attach_function :strdup, [ :string ], :strptr else attach_function :_strdup, [ :string ], :strptr end end end.should_not raise_error end module StrPtr extend FFI::Library ffi_lib FFI::Library::LIBC attach_function :free, [ :pointer ], :void if !FFI::Platform.windows? attach_function :strdup, [ :string ], :strptr else attach_function :strdup, :_strdup, [ :string ], :strptr end end it "should return [ String, Pointer ]" do result = StrPtr.strdup("test") result[0].is_a?(String).should be_true result[1].is_a?(FFI::Pointer).should be_true end it "should return the correct value" do result = StrPtr.strdup("test") result[0].should == "test" end it "should return non-NULL pointer" do result = StrPtr.strdup("test") result[1].null?.should be_false end end ruby-ffi-1.9.3debian.orig/spec/ffi/struct_spec.rb0000644000175000017500000005552612261216360022160 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "Struct tests" do StructTypes = { 's8' => :char, 's16' => :short, 's32' => :int, 's64' => :long_long, 'long' => :long, 'f32' => :float, 'f64' => :double } module LibTest extend FFI::Library ffi_lib TestLibrary::PATH attach_function :ptr_ret_pointer, [ :pointer, :int], :string attach_function :ptr_ret_int32_t, [ :pointer, :int ], :int attach_function :ptr_from_address, [ :ulong ], :pointer attach_function :string_equals, [ :string, :string ], :int [ 's8', 's16', 's32', 's64', 'f32', 'f64', 'long' ].each do |t| attach_function "struct_align_#{t}", [ :pointer ], StructTypes[t] end end class PointerMember < FFI::Struct layout :pointer, :pointer end class StringMember < FFI::Struct layout :string, :string end it "Struct#[:pointer]" do magic = 0x12345678 mp = FFI::MemoryPointer.new :long mp.put_long(0, magic) smp = FFI::MemoryPointer.new :pointer smp.put_pointer(0, mp) s = PointerMember.new smp s[:pointer].should == mp end it "Struct#[:pointer].nil? for NULL value" do magic = 0x12345678 mp = FFI::MemoryPointer.new :long mp.put_long(0, magic) smp = FFI::MemoryPointer.new :pointer smp.put_pointer(0, nil) s = PointerMember.new smp s[:pointer].null?.should == true end it "Struct#[:pointer]=" do magic = 0x12345678 mp = FFI::MemoryPointer.new :long mp.put_long(0, magic) smp = FFI::MemoryPointer.new :pointer s = PointerMember.new smp s[:pointer] = mp smp.get_pointer(0).should == mp end it "Struct#[:pointer]=struct" do smp = FFI::MemoryPointer.new :pointer s = PointerMember.new smp lambda { s[:pointer] = s }.should_not raise_error end it "Struct#[:pointer]=nil" do smp = FFI::MemoryPointer.new :pointer s = PointerMember.new smp s[:pointer] = nil smp.get_pointer(0).null?.should == true end it "Struct#[:string]" do magic = "test" mp = FFI::MemoryPointer.new 1024 mp.put_string(0, magic) smp = FFI::MemoryPointer.new :pointer smp.put_pointer(0, mp) s = StringMember.new smp s[:string].should == magic end it "Struct#[:string].nil? for NULL value" do smp = FFI::MemoryPointer.new :pointer smp.put_pointer(0, nil) s = StringMember.new smp s[:string].nil?.should == true end it "Struct#layout works with :name, :type pairs" do class PairLayout < FFI::Struct layout :a, :int, :b, :long_long end ll_off = (FFI::TYPE_UINT64.alignment == 4 ? 4 : 8) PairLayout.size.should == (ll_off + 8) mp = FFI::MemoryPointer.new(PairLayout.size) s = PairLayout.new mp s[:a] = 0x12345678 mp.get_int(0).should == 0x12345678 s[:b] = 0xfee1deadbeef mp.get_int64(ll_off).should == 0xfee1deadbeef end it "Struct#layout works with :name, :type, offset tuples" do class PairLayout < FFI::Struct layout :a, :int, 0, :b, :long_long, 4 end PairLayout.size.should == (FFI::TYPE_UINT64.alignment == 4 ? 12 : 16) mp = FFI::MemoryPointer.new(PairLayout.size) s = PairLayout.new mp s[:a] = 0x12345678 mp.get_int(0).should == 0x12345678 s[:b] = 0xfee1deadbeef mp.get_int64(4).should == 0xfee1deadbeef end it "Struct#layout works with mixed :name,:type and :name,:type,offset" do class MixedLayout < FFI::Struct layout :a, :int, :b, :long_long, 4 end MixedLayout.size.should == (FFI::TYPE_UINT64.alignment == 4 ? 12 : 16) mp = FFI::MemoryPointer.new(MixedLayout.size) s = MixedLayout.new mp s[:a] = 0x12345678 mp.get_int(0).should == 0x12345678 s[:b] = 0xfee1deadbeef mp.get_int64(4).should == 0xfee1deadbeef end rb_maj, rb_min = RUBY_VERSION.split('.') if rb_maj.to_i >= 1 && rb_min.to_i >= 9 || RUBY_PLATFORM =~ /java/ it "Struct#layout withs with a hash of :name => type" do class HashLayout < FFI::Struct layout :a => :int, :b => :long_long end ll_off = (FFI::TYPE_UINT64.alignment == 4? 4 : 8) HashLayout.size.should == (ll_off + 8) mp = FFI::MemoryPointer.new(HashLayout.size) s = HashLayout.new mp s[:a] = 0x12345678 mp.get_int(0).should == 0x12345678 s[:b] = 0xfee1deadbeef mp.get_int64(ll_off).should == 0xfee1deadbeef end end it "subclass overrides initialize without calling super" do class InitializeWithoutSuper < FFI::Struct layout :a, :int, :b, :long_long, :d, [:double, 2] def initialize(a, b) self[:a] = a self[:b] = b self[:d][0] = 1.2 self[:d][1] = 3.4 end end s = InitializeWithoutSuper.new(0x1eefbeef, 0xdeadcafebabe) s[:a].should == 0x1eefbeef s[:b].should == 0xdeadcafebabe end it "Can use Struct subclass as parameter type" do module StructParam extend FFI::Library ffi_lib TestLibrary::PATH class TestStruct < FFI::Struct layout :c, :char end attach_function :struct_field_s8, [ TestStruct.in ], :char end end it "Can use Struct subclass as IN parameter type" do module StructParam2 extend FFI::Library ffi_lib TestLibrary::PATH class TestStruct < FFI::Struct layout :c, :char end attach_function :struct_field_s8, [ TestStruct.in ], :char end end it "Can use Struct subclass as OUT parameter type" do module StructParam3 extend FFI::Library ffi_lib TestLibrary::PATH class TestStruct < FFI::Struct layout :c, :char end attach_function :struct_field_s8, [ TestStruct.out ], :char end end it "can be passed directly as a :pointer parameter" do class TestStruct < FFI::Struct layout :i, :int end s = TestStruct.new s[:i] = 0x12 LibTest.ptr_ret_int32_t(s, 0).should == 0x12 end it ":char member aligned correctly" do class AlignChar < FFI::Struct layout :c, :char, :v, :char end s = AlignChar.new s[:v] = 0x12 LibTest.struct_align_s8(s.pointer).should == 0x12 end it ":short member aligned correctly" do class AlignShort < FFI::Struct layout :c, :char, :v, :short end s = AlignShort.alloc_in s[:v] = 0x1234 LibTest.struct_align_s16(s.pointer).should == 0x1234 end it ":int member aligned correctly" do class AlignInt < FFI::Struct layout :c, :char, :v, :int end s = AlignInt.alloc_in s[:v] = 0x12345678 LibTest.struct_align_s32(s.pointer).should == 0x12345678 end it ":long_long member aligned correctly" do class AlignLongLong < FFI::Struct layout :c, :char, :v, :long_long end s = AlignLongLong.alloc_in s[:v] = 0x123456789abcdef0 LibTest.struct_align_s64(s.pointer).should == 0x123456789abcdef0 end it ":long member aligned correctly" do class AlignLong < FFI::Struct layout :c, :char, :v, :long end s = AlignLong.alloc_in s[:v] = 0x12345678 LibTest.struct_align_long(s.pointer).should == 0x12345678 end it ":float member aligned correctly" do class AlignFloat < FFI::Struct layout :c, :char, :v, :float end s = AlignFloat.alloc_in s[:v] = 1.23456 (LibTest.struct_align_f32(s.pointer) - 1.23456).abs.should < 0.00001 end it ":double member aligned correctly" do class AlignDouble < FFI::Struct layout :c, :char, :v, :double end s = AlignDouble.alloc_in s[:v] = 1.23456789 (LibTest.struct_align_f64(s.pointer) - 1.23456789).abs.should < 0.00000001 end it ":ulong, :pointer struct" do class ULPStruct < FFI::Struct layout :ul, :ulong, :p, :pointer end s = ULPStruct.alloc_in s[:ul] = 0xdeadbeef s[:p] = LibTest.ptr_from_address(0x12345678) s.pointer.get_ulong(0).should == 0xdeadbeef end def test_num_field(type, v) klass = Class.new(FFI::Struct) klass.layout :v, type, :dummy, :long s = klass.new s[:v] = v s.pointer.send("get_#{type.to_s}", 0).should == v s.pointer.send("put_#{type.to_s}", 0, 0) s[:v].should == 0 end def self.int_field_test(type, values) values.each do |v| it "#{type} field r/w (#{v.to_s(16)})" do test_num_field(type, v) end end end int_field_test(:char, [ 0, 127, -128, -1 ]) int_field_test(:uchar, [ 0, 0x7f, 0x80, 0xff ]) int_field_test(:short, [ 0, 0x7fff, -0x8000, -1 ]) int_field_test(:ushort, [ 0, 0x7fff, 0x8000, 0xffff ]) int_field_test(:int, [ 0, 0x7fffffff, -0x80000000, -1 ]) int_field_test(:uint, [ 0, 0x7fffffff, 0x80000000, 0xffffffff ]) int_field_test(:long_long, [ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ]) int_field_test(:ulong_long, [ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ]) if FFI::Platform::LONG_SIZE == 32 int_field_test(:long, [ 0, 0x7fffffff, -0x80000000, -1 ]) int_field_test(:ulong, [ 0, 0x7fffffff, 0x80000000, 0xffffffff ]) else int_field_test(:long, [ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ]) int_field_test(:ulong, [ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ]) end it ":float field r/w" do klass = Class.new(FFI::Struct) klass.layout :v, :float, :dummy, :long s = klass.new value = 1.23456 s[:v] = value (s.pointer.get_float(0) - value).abs.should < 0.0001 end it ":double field r/w" do klass = Class.new(FFI::Struct) klass.layout :v, :double, :dummy, :long s = klass.new value = 1.23456 s[:v] = value (s.pointer.get_double(0) - value).abs.should < 0.0001 end module EnumFields extend FFI::Library TestEnum = enum :test_enum, [:c1, 10, :c2, 20, :c3, 30, :c4, 40] class TestStruct < FFI::Struct layout :a, :int, :c, :test_enum, :d, [ TestEnum, TestEnum.symbols.length ] end end it ":enum field r/w" do s = EnumFields::TestStruct.new s[:c] = :c3 s.pointer.get_uint(FFI::Type::INT32.size).should == 30 s[:c].should == :c3 end it "array of :enum field" do s = EnumFields::TestStruct.new EnumFields::TestEnum.symbols.each_with_index do |val, i| s[:d][i] = val end EnumFields::TestEnum.symbols.each_with_index do |val, i| s.pointer.get_uint(FFI::Type::INT32.size * (2 + i)).should == EnumFields::TestEnum[val] end s[:d].each_with_index do |val, i| val.should == EnumFields::TestEnum.symbols[i] end end module CallbackMember extend FFI::Library ffi_lib TestLibrary::PATH callback :add, [ :int, :int ], :int callback :sub, [ :int, :int ], :int class TestStruct < FFI::Struct layout :add, :add, :sub, :sub end attach_function :struct_call_add_cb, [TestStruct.in, :int, :int], :int attach_function :struct_call_sub_cb, [TestStruct.in, :int, :int], :int end it "Can have CallbackInfo struct field" do s = CallbackMember::TestStruct.new add_proc = lambda { |a, b| a+b } sub_proc = lambda { |a, b| a-b } s[:add] = add_proc s[:sub] = sub_proc CallbackMember.struct_call_add_cb(s, 40, 2).should == 42 CallbackMember.struct_call_sub_cb(s, 44, 2).should == 42 end it "Can return its members as a list" do class TestStruct < FFI::Struct layout :a, :int, :b, :int, :c, :int end TestStruct.members.should include(:a, :b, :c) end it "Can return its instance members and values as lists" do class TestStruct < FFI::Struct layout :a, :int, :b, :int, :c, :int end s = TestStruct.new s.members.should include(:a, :b, :c) s[:a] = 1 s[:b] = 2 s[:c] = 3 s.values.should include(1, 2, 3) end it 'should return an ordered field/offset pairs array' do class TestStruct < FFI::Struct layout :a, :int, :b, :int, :c, :int end s = TestStruct.new s.offsets.should == [[:a, 0], [:b, 4], [:c, 8]] TestStruct.offsets.should == [[:a, 0], [:b, 4], [:c, 8]] end it "Struct#offset_of returns offset of field within struct" do class TestStruct < FFI::Struct layout :a, :int, :b, :int, :c, :int end TestStruct.offset_of(:a).should == 0 TestStruct.offset_of(:b).should == 4 TestStruct.offset_of(:c).should == 8 end end describe FFI::Struct, ' with a nested struct field' do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH class NestedStruct < FFI::Struct layout :i, :int end class ContainerStruct < FFI::Struct layout :first, :char, :ns, NestedStruct end attach_function :struct_align_nested_struct, [ :pointer ], :int attach_function :struct_make_container_struct, [ :int ], :pointer end before do @cs = LibTest::ContainerStruct.new end it 'should align correctly nested struct field' do @cs[:ns][:i] = 123 LibTest.struct_align_nested_struct(@cs.to_ptr).should == 123 end it 'should correctly calculate Container size (in bytes)' do LibTest::ContainerStruct.size.should == 8 end it 'should return a Struct object when the field is accessed' do @cs[:ns].is_a?(FFI::Struct).should be_true end it 'should read a value from memory' do @cs = LibTest::ContainerStruct.new(LibTest.struct_make_container_struct(123)) @cs[:ns][:i].should == 123 end it 'should write a value to memory' do @cs = LibTest::ContainerStruct.new(LibTest.struct_make_container_struct(123)) @cs[:ns][:i] = 456 LibTest.struct_align_nested_struct(@cs.to_ptr).should == 456 end it 'should be able to assign struct instance to nested field' do cs = LibTest::ContainerStruct.new(LibTest.struct_make_container_struct(123)) ns = LibTest::NestedStruct.new ns[:i] = 567 cs[:ns] = ns cs[:ns][:i].should == 567 LibTest.struct_align_nested_struct(cs.to_ptr).should == 567 end end describe FFI::Struct, ' with a nested array of structs' do module InlineArrayOfStructs extend FFI::Library ffi_lib TestLibrary::PATH class NestedStruct < FFI::Struct layout :i, :int end class ContainerStruct < FFI::Struct layout :first, :char, :ns, [ NestedStruct, 1 ] end attach_function :struct_align_nested_struct, [ :pointer ], :int attach_function :struct_make_container_struct, [ :int ], :pointer end before do @cs = InlineArrayOfStructs::ContainerStruct.new end it 'should align correctly nested struct field' do @cs[:ns][0][:i] = 123 InlineArrayOfStructs.struct_align_nested_struct(@cs.to_ptr).should == 123 end it 'should correctly calculate Container size (in bytes)' do InlineArrayOfStructs::ContainerStruct.size.should == 8 end it 'should return a Struct object when the field is accessed' do @cs[:ns][0].is_a?(FFI::Struct).should be_true end it 'should read a value from memory' do @cs = InlineArrayOfStructs::ContainerStruct.new(InlineArrayOfStructs.struct_make_container_struct(123)) @cs[:ns][0][:i].should == 123 end it 'should write a value to memory' do @cs = InlineArrayOfStructs::ContainerStruct.new(InlineArrayOfStructs.struct_make_container_struct(123)) @cs[:ns][0][:i] = 456 InlineArrayOfStructs.struct_align_nested_struct(@cs.to_ptr).should == 456 end it 'should support Enumerable#each' do @cs = InlineArrayOfStructs::ContainerStruct.new(InlineArrayOfStructs.struct_make_container_struct(123)) ints = [] @cs[:ns].each { |s| ints << s[:i] } ints[0].should == 123 end end describe FFI::Struct, ' by value' do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH class S8S32 < FFI::Struct layout :s8, :char, :s32, :int end class StructString < FFI::Struct layout :bytes, :string, :len, :int end attach_function :struct_return_s8s32, [ ], S8S32.by_value attach_function :struct_s8s32_set, [ :char, :int ], S8S32.by_value attach_function :struct_s8s32_get_s8, [ S8S32.by_value ], :char attach_function :struct_s8s32_get_s32, [ S8S32.by_value ], :int attach_function :struct_s8s32_s32_ret_s32, [ S8S32.by_value, :int ], :int attach_function :struct_s8s32_s64_ret_s64, [ S8S32.by_value, :long_long ], :long_long attach_function :struct_s8s32_ret_s8s32, [ S8S32.by_value ], S8S32.by_value attach_function :struct_s32_ptr_s32_s8s32_ret_s32, [ :int, :pointer, :int, S8S32.by_value ], :int attach_function :struct_varargs_ret_struct_string, [ :int, :varargs ], StructString.by_value end it 'return using pre-set values' do s = LibTest.struct_return_s8s32 s[:s8].should == 0x7f s[:s32].should == 0x12345678 end it 'return using passed in values' do s = LibTest.struct_s8s32_set(123, 456789) s[:s8].should == 123 s[:s32].should == 456789 end it 'parameter' do s = LibTest::S8S32.new s[:s8] = 0x12 s[:s32] = 0x34567890 LibTest.struct_s8s32_get_s8(s).should == 0x12 LibTest.struct_s8s32_get_s32(s).should == 0x34567890 end it 'parameter with following s32' do s = LibTest::S8S32.new s[:s8] = 0x12 s[:s32] = 0x34567890 LibTest.struct_s8s32_s32_ret_s32(s, 0x1eefdead).should == 0x1eefdead end it 'parameter with following s64' do s = LibTest::S8S32.new s[:s8] = 0x12 s[:s32] = 0x34567890 end it 'parameter with preceding s32,ptr,s32' do s = LibTest::S8S32.new s[:s8] = 0x12 s[:s32] = 0x34567890 out = LibTest::S8S32.new LibTest.struct_s32_ptr_s32_s8s32_ret_s32(0x1000000, out, 0x1eafbeef, s).should == 0x34567890 out[:s8].should == s[:s8] out[:s32].should == s[:s32] end it 'parameter with preceding s32,string,s32' do s = LibTest::S8S32.new s[:s8] = 0x12 s[:s32] = 0x34567890 out = 0.chr * 32 LibTest.struct_s32_ptr_s32_s8s32_ret_s32(0x1000000, out, 0x1eafbeef, s).should == 0x34567890 end it 'parameter, returning struct by value' do s = LibTest::S8S32.new s[:s8] = 0x12 s[:s32] = 0x34567890 ret = LibTest.struct_s8s32_ret_s8s32(s) ret[:s8].should == s[:s8] ret[:s32].should == s[:s32] end it 'varargs returning a struct' do string = "test" s = LibTest.struct_varargs_ret_struct_string(4, :string, string) s[:len].should == string.length s[:bytes].should == string end end describe FFI::Struct, ' with an array field' do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH class StructWithArray < FFI::Struct layout :first, :char, :a, [:int, 5] end attach_function :struct_make_struct_with_array, [:int, :int, :int, :int, :int], :pointer attach_function :struct_field_array, [:pointer], :pointer end before do @s = LibTest::StructWithArray.new end it 'should correctly calculate StructWithArray size (in bytes)' do LibTest::StructWithArray.size.should == 24 end it 'should read values from memory' do @s = LibTest::StructWithArray.new(LibTest.struct_make_struct_with_array(0, 1, 2, 3, 4)) @s[:a].to_a.should == [0, 1, 2, 3, 4] end # it 'should cache array object for successive calls' do # @s[:a].object_id.should == @s[:a].object_id # end it 'should return the number of elements in the array field' do @s = LibTest::StructWithArray.new(LibTest.struct_make_struct_with_array(0, 1, 2, 3, 4)) @s[:a].size.should == 5 end it 'should allow iteration through the array elements' do @s = LibTest::StructWithArray.new(LibTest.struct_make_struct_with_array(0, 1, 2, 3, 4)) @s[:a].each_with_index { |elem, i| elem.should == i } end it 'should return the pointer to the array' do @s = LibTest::StructWithArray.new(LibTest.struct_make_struct_with_array(0, 1, 2, 3, 4)) @s[:a].to_ptr.should == LibTest::struct_field_array(@s.to_ptr) end end describe 'BuggedStruct' do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH class BuggedStruct < FFI::Struct layout :visible, :uchar, :x, :uint, :y, :uint, :rx, :short, :ry, :short, :order, :uchar, :size, :uchar end attach_function :bugged_struct_size, [], :uint end it 'should return its correct size' do LibTest::BuggedStruct.size.should == LibTest.bugged_struct_size end it "offsets within struct should be correct" do LibTest::BuggedStruct.offset_of(:visible).should == 0 LibTest::BuggedStruct.offset_of(:x).should == 4 LibTest::BuggedStruct.offset_of(:y).should == 8 LibTest::BuggedStruct.offset_of(:rx).should == 12 LibTest::BuggedStruct.offset_of(:ry).should == 14 LibTest::BuggedStruct.offset_of(:order).should == 16 LibTest::BuggedStruct.offset_of(:size).should == 17 end it 'should return correct field/offset pairs' do LibTest::BuggedStruct.offsets.sort do |a, b| a[1] <=> b[1] end.should == [[:visible, 0], [:x, 4], [:y, 8], [:rx, 12], [:ry, 14], [:order, 16], [:size, 17]] end end describe "Struct allocation" do it "MemoryPointer.new(Struct, 2)" do class S < FFI::Struct layout :i, :uint end p = FFI::MemoryPointer.new(S, 2) p.total.should == 8 p.type_size.should == 4 p.put_uint(4, 0xdeadbeef) S.new(p[1])[:i].should == 0xdeadbeef p[1].address.should == (p[0].address + 4) end it "Buffer.new(Struct, 2)" do class S < FFI::Struct layout :i, :uint end p = FFI::Buffer.new(S, 2) p.total.should == 8 p.type_size.should == 4 p.put_uint(4, 0xdeadbeef) S.new(p[1])[:i].should == 0xdeadbeef end it "null? should be true when initialized with NULL pointer" do class S < FFI::Struct layout :i, :uint end S.new(FFI::Pointer::NULL).null?.should be_true end it "null? should be false when initialized with non-NULL pointer" do class S < FFI::Struct layout :i, :uint end S.new(FFI::MemoryPointer.new(S)).null?.should be_false end it "supports :bool as a struct member" do lambda do c = Class.new(FFI::Struct) do layout :b, :bool end struct = c.new struct[:b] = ! struct[:b] end.should_not raise_error end end describe "variable-length arrays" do it "zero length array should be accepted as last field" do lambda { Class.new(FFI::Struct) do layout :count, :int, :data, [ :char, 0 ] end }.should_not raise_error end it "zero length array before last element should raise error" do lambda { Class.new(FFI::Struct) do layout :data, [ :char, 0 ], :count, :int end }.should raise_error end it "can access elements of array" do struct_class = Class.new(FFI::Struct) do layout :count, :int, :data, [ :long, 0 ] end s = struct_class.new(FFI::MemoryPointer.new(1024)) s[:data][0] = 0x1eadbeef s[:data][1] = 0x12345678 s[:data][0].should == 0x1eadbeef s[:data][1].should == 0x12345678 end it "non-variable length array is bounds checked" do struct_class = Class.new(FFI::Struct) do layout :count, :int, :data, [ :long, 1 ] end s = struct_class.new(FFI::MemoryPointer.new(1024)) s[:data][0] = 0x1eadbeef lambda { s[:data][1] = 0x12345678 }.should raise_error s[:data][0].should == 0x1eadbeef lambda { s[:data][1].should == 0x12345678 }.should raise_error end end ruby-ffi-1.9.3debian.orig/spec/ffi/bool_spec.rb0000644000175000017500000000167012261216360021556 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "Function with primitive boolean arguments and return values" do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH attach_function :bool_return_true, [ ], :bool attach_function :bool_return_false, [ ], :bool attach_function :bool_return_val, [ :bool ], :bool attach_function :bool_reverse_val, [ :bool ], :bool end it "bools" do LibTest.bool_return_true.should == true LibTest.bool_return_false.should == false LibTest.bool_return_val(true).should == true LibTest.bool_return_val(false).should == false LibTest.bool_reverse_val(true).should == false LibTest.bool_reverse_val(false).should == true end it "raise error on invalid types" do lambda { LibTest.bool_return_val(nil) }.should raise_error(::TypeError) end end ruby-ffi-1.9.3debian.orig/spec/ffi/library_spec.rb0000644000175000017500000001360012261216360022263 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "Library" do describe "#ffi_convention" do it "defaults to :default" do m = Module.new do extend FFI::Library end m.ffi_convention.should == :default end it "should be settable" do m = Module.new do extend FFI::Library end m.ffi_convention.should == :default m.ffi_convention :stdcall m.ffi_convention.should == :stdcall end end describe "ffi_lib" do it "empty name list should raise error" do lambda { Module.new do |m| m.extend FFI::Library ffi_lib end }.should raise_error(LoadError) end end unless RbConfig::CONFIG['target_os'] =~ /mswin|mingw/ it "attach_function with no library specified" do lambda { Module.new do |m| m.extend FFI::Library attach_function :getpid, [ ], :uint end }.should raise_error end it "attach_function :getpid from this process" do lambda { Module.new do |m| m.extend FFI::Library ffi_lib FFI::Library::CURRENT_PROCESS attach_function :getpid, [ ], :uint end.getpid.should == Process.pid }.should_not raise_error end it "attach_function :getpid from [ 'c', 'libc.so.6'] " do lambda { Module.new do |m| m.extend FFI::Library ffi_lib [ 'c', 'libc.so.6' ] attach_function :getpid, [ ], :uint end.getpid.should == Process.pid }.should_not raise_error end it "attach_function :getpid from [ 'libc.so.6', 'c' ] " do lambda { Module.new do |m| m.extend FFI::Library ffi_lib [ 'libc.so.6', 'c' ] attach_function :getpid, [ ], :uint end.getpid.should == Process.pid }.should_not raise_error end it "attach_function :getpid from [ 'libfubar.so.0xdeadbeef', nil, 'c' ] " do lambda { Module.new do |m| m.extend FFI::Library ffi_lib [ 'libfubar.so.0xdeadbeef', nil, 'c' ] attach_function :getpid, [ ], :uint end.getpid.should == Process.pid }.should_not raise_error end it "attach_function :getpid from [ 'libfubar.so.0xdeadbeef' ] " do lambda { Module.new do |m| m.extend FFI::Library ffi_lib 'libfubar.so.0xdeadbeef' attach_function :getpid, [ ], :uint end.getpid.should == Process.pid }.should raise_error(LoadError) end it "attach_function :bool_return_true from [ File.expand_path(#{TestLibrary::PATH.inspect}) ]" do Module.new do |m| m.extend FFI::Library ffi_lib File.expand_path(TestLibrary::PATH) attach_function :bool_return_true, [ ], :bool m.bool_return_true.should == true end end end def gvar_lib(name, type) Module.new do |m| m.extend FFI::Library ffi_lib TestLibrary::PATH attach_variable :gvar, "gvar_#{name}", type attach_function :get, "gvar_#{name}_get", [], type attach_function :set, "gvar_#{name}_set", [ type ], :void end end def gvar_test(name, type, val) lib = gvar_lib(name, type) lib.set(val) lib.gvar.should == val lib.set(0) lib.gvar = val lib.get.should == val end [ 0, 127, -128, -1 ].each do |i| it ":char variable" do gvar_test("s8", :char, i) end end [ 0, 0x7f, 0x80, 0xff ].each do |i| it ":uchar variable" do gvar_test("u8", :uchar, i) end end [ 0, 0x7fff, -0x8000, -1 ].each do |i| it ":short variable" do gvar_test("s16", :short, i) end end [ 0, 0x7fff, 0x8000, 0xffff ].each do |i| it ":ushort variable" do gvar_test("u16", :ushort, i) end end [ 0, 0x7fffffff, -0x80000000, -1 ].each do |i| it ":int variable" do gvar_test("s32", :int, i) end end [ 0, 0x7fffffff, 0x80000000, 0xffffffff ].each do |i| it ":uint variable" do gvar_test("u32", :uint, i) end end [ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ].each do |i| it ":long_long variable" do gvar_test("s64", :long_long, i) end end [ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ].each do |i| it ":ulong_long variable" do gvar_test("u64", :ulong_long, i) end end if FFI::Platform::LONG_SIZE == 32 [ 0, 0x7fffffff, -0x80000000, -1 ].each do |i| it ":long variable" do gvar_test("long", :long, i) end end [ 0, 0x7fffffff, 0x80000000, 0xffffffff ].each do |i| it ":ulong variable" do gvar_test("ulong", :ulong, i) end end else [ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ].each do |i| it ":long variable" do gvar_test("long", :long, i) end end [ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ].each do |i| it ":ulong variable" do gvar_test("ulong", :ulong, i) end end end it "Pointer variable" do lib = gvar_lib("pointer", :pointer) val = FFI::MemoryPointer.new :long lib.set(val) lib.gvar.should == val lib.set(nil) lib.gvar = val lib.get.should == val end [ 0, 0x7fffffff, -0x80000000, -1 ].each do |i| it "structure" do class GlobalStruct < FFI::Struct layout :data, :long end lib = Module.new do |m| m.extend FFI::Library ffi_lib TestLibrary::PATH attach_variable :gvar, "gvar_gstruct", GlobalStruct attach_function :get, "gvar_gstruct_get", [], GlobalStruct attach_function :set, "gvar_gstruct_set", [ GlobalStruct ], :void end val = GlobalStruct.new val[:data] = i lib.set(val) lib.gvar[:data].should == i val[:data] = 0 lib.gvar[:data] = i val = GlobalStruct.new(lib.get) val[:data].should == i end end end ruby-ffi-1.9.3debian.orig/spec/ffi/managed_struct_spec.rb0000644000175000017500000000311212261216360023614 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) require 'java' if RUBY_PLATFORM =~ /java/ describe "Managed Struct" do include FFI module ManagedStructTestLib extend FFI::Library ffi_lib TestLibrary::PATH attach_function :ptr_from_address, [ FFI::Platform::ADDRESS_SIZE == 32 ? :uint : :ulong_long ], :pointer end it "should raise an error if release() is not defined" do class NoRelease < FFI::ManagedStruct ; layout :i, :int; end lambda { NoRelease.new(ManagedStructTestLib.ptr_from_address(0x12345678)) }.should raise_error(NoMethodError) end it "should be the right class" do class WhatClassAmI < FFI::ManagedStruct layout :i, :int def self.release end end WhatClassAmI.new(ManagedStructTestLib.ptr_from_address(0x12345678)).class.should == WhatClassAmI end it "should release memory properly" do class PleaseReleaseMe < FFI::ManagedStruct layout :i, :int @@count = 0 def self.release @@count += 1 end def self.wait_gc(count) loop = 5 while loop > 0 && @@count < count loop -= 1 TestLibrary.force_gc sleep 0.05 if @@count < count end end end loop_count = 30 wiggle_room = 5 PleaseReleaseMe.should_receive(:release).at_least(loop_count-wiggle_room).times loop_count.times do PleaseReleaseMe.new(ManagedStructTestLib.ptr_from_address(0x12345678)) end PleaseReleaseMe.wait_gc loop_count end end ruby-ffi-1.9.3debian.orig/spec/ffi/long_double.rb0000644000175000017500000000156112261216360022101 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) require 'bigdecimal' describe ":long_double arguments and return values" do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH attach_function :add_f128, [ :long_double, :long_double ], :long_double attach_function :ret_f128, [ :long_double ], :long_double end it "returns first parameter" do LibTest.ret_f128(0.1).should be_within(0.01).of(0.1) end it "returns first parameter with high precision" do ld = BigDecimal.new("1.234567890123456789") tolerance = BigDecimal.new("0.0000000000000000001") LibTest.ret_f128(ld).should be_within(tolerance).of(ld) end it "add two long double numbers" do LibTest.add_f128(0.1, 0.2).should be_within(0.01).of(0.3) end end ruby-ffi-1.9.3debian.orig/spec/ffi/struct_callback_spec.rb0000644000175000017500000000407512261216360023765 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe FFI::Struct, ' with inline callback functions' do it 'should be able to define inline callback field' do module CallbackMember1 extend FFI::Library ffi_lib TestLibrary::PATH DUMMY_CB = callback :dummy_cb, [ :int ], :int class TestStruct < FFI::Struct layout \ :add, callback([ :int, :int ], :int), :sub, callback([ :int, :int ], :int), :cb_with_cb_parameter, callback([ DUMMY_CB, :int ], :int) end attach_function :struct_call_add_cb, [TestStruct, :int, :int], :int attach_function :struct_call_sub_cb, [TestStruct, :int, :int], :int end end it 'should take methods as callbacks' do module CallbackMember2 extend FFI::Library ffi_lib TestLibrary::PATH class TestStruct < FFI::Struct layout \ :add, callback([ :int, :int ], :int), :sub, callback([ :int, :int ], :int) end attach_function :struct_call_add_cb, [TestStruct, :int, :int], :int attach_function :struct_call_sub_cb, [TestStruct, :int, :int], :int end module StructCallbacks def self.add a, b a+b end end ts = CallbackMember2::TestStruct.new ts[:add] = StructCallbacks.method(:add) CallbackMember2.struct_call_add_cb(ts, 1, 2).should == 3 end it 'should return callable object from []' do module CallbackMember3 extend FFI::Library ffi_lib TestLibrary::PATH class TestStruct < FFI::Struct layout \ :add, callback([ :int, :int ], :int), :sub, callback([ :int, :int ], :int) end attach_function :struct_call_add_cb, [TestStruct, :int, :int], :int attach_function :struct_call_sub_cb, [TestStruct, :int, :int], :int end s = CallbackMember3::TestStruct.new add = Proc.new { |a,b| a+b} s[:add] = add fn = s[:add] fn.respond_to?(:call).should be_true fn.call(1, 2).should == 3 end end ruby-ffi-1.9.3debian.orig/spec/ffi/custom_param_type.rb0000644000175000017500000000155412261216360023345 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "functions with custom parameter types" do before :each do Custom_enum = Class.new do extend FFI::DataConverter ToNativeMap= { :a => 1, :b => 2 } FromNativeMap = { 1 => :a, 2 => :b } def self.native_type @native_type_called = true FFI::Type::INT32 end def self.to_native(val, ctx) @to_native_called = true ToNativeMap[val] end def self.from_native(val, ctx) @from_native_called = true FromNativeMap[val] end def self.native_type_called?; @native_type_called; end def self.from_native_called?; @from_native_called; end def self.to_native_called?; @to_native_called; end end end end ruby-ffi-1.9.3debian.orig/spec/ffi/variadic_spec.rb0000644000175000017500000000535212261216360022406 0ustar terceiroterceiro# # This file is part of ruby-ffi. # For licensing, see LICENSE.SPECS # require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "Function with variadic arguments" do module LibTest extend FFI::Library ffi_lib TestLibrary::PATH attach_function :pack_varargs, [ :buffer_out, :string, :varargs ], :void end [ 0, 127, -128, -1 ].each do |i| it "call variadic with (:char (#{i})) argument" do buf = FFI::Buffer.new :long_long LibTest.pack_varargs(buf, "c", :char, i) buf.get_int64(0).should == i end end [ 0, 0x7f, 0x80, 0xff ].each do |i| it "call variadic with (:uchar (#{i})) argument" do buf = FFI::Buffer.new :long_long LibTest.pack_varargs(buf, "C", :uchar, i) buf.get_int64(0).should == i end end [ 0, 1.234567, 9.87654321 ].each do |v| it "call variadic with (:float (#{v})) argument" do buf = FFI::Buffer.new :long_long LibTest.pack_varargs(buf, "f", :float, v.to_f) buf.get_float64(0).should == v end end [ 0, 1.234567, 9.87654321 ].each do |v| it "call variadic with (:double (#{v})) argument" do buf = FFI::Buffer.new :long_long LibTest.pack_varargs(buf, "f", :double, v.to_f) buf.get_float64(0).should == v end end module Varargs PACK_VALUES = { 'c' => [ 0x12 ], 'C' => [ 0x34 ], 's' => [ 0x5678 ], 'S' => [ 0x9abc ], 'i' => [ 0x7654321f ], 'I' => [ 0xfee1babe ], 'l' => [ 0x1f2e3d4c ], 'L' => [ 0xf7e8d9ca ], 'j' => [ 0x1eafdeadbeefa1b2 ], 'f' => [ 1.23456789 ], 'd' => [ 9.87654321 ] } TYPE_MAP = { 'c' => :char, 'C' => :uchar, 's' => :short, 'S' => :ushort, 'i' => :int, 'I' => :uint, 'j' => :long_long, 'J' => :ulong_long, 'l' => :long, 'L' => :ulong, 'f' => :float, 'd' => :double } end def verify(p, off, v) if v.kind_of?(Float) p.get_float64(off).should == v else p.get_int64(off).should == v end end Varargs::PACK_VALUES.keys.each do |t1| Varargs::PACK_VALUES.keys.each do |t2| Varargs::PACK_VALUES.keys.each do |t3| Varargs::PACK_VALUES[t1].each do |v1| Varargs::PACK_VALUES[t2].each do |v2| Varargs::PACK_VALUES[t3].each do |v3| fmt = "#{t1}#{t2}#{t3}" params = [ Varargs::TYPE_MAP[t1], v1, Varargs::TYPE_MAP[t2], v2, Varargs::TYPE_MAP[t3], v3 ] it "call(#{fmt}, #{params.join(',')})" do buf = FFI::Buffer.new :long_long, 3 LibTest.pack_varargs(buf, fmt, *params) verify(buf, 0, v1) verify(buf, 8, v2) verify(buf, 16, v3) end end end end end end end end ruby-ffi-1.9.3debian.orig/spec/spec.opts0000644000175000017500000000003212261216360020350 0ustar terceiroterceiro--color --format specdoc ruby-ffi-1.9.3debian.orig/ext/0000755000175000017500000000000012261216357016370 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/ext/ffi_c/0000755000175000017500000000000012263242362017433 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/ext/ffi_c/Types.h0000644000175000017500000000542212261216360020710 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * Copyright (c) 2009, Luc Heinrich * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_TYPES_H #define RBFFI_TYPES_H #ifdef __cplusplus extern "C" { #endif typedef enum { NATIVE_VOID, NATIVE_INT8, NATIVE_UINT8, NATIVE_INT16, NATIVE_UINT16, NATIVE_INT32, NATIVE_UINT32, NATIVE_INT64, NATIVE_UINT64, NATIVE_LONG, NATIVE_ULONG, NATIVE_FLOAT32, NATIVE_FLOAT64, NATIVE_LONGDOUBLE, NATIVE_POINTER, NATIVE_CALLBACK, NATIVE_FUNCTION, NATIVE_BUFFER_IN, NATIVE_BUFFER_OUT, NATIVE_BUFFER_INOUT, NATIVE_CHAR_ARRAY, NATIVE_BOOL, /** An immutable string. Nul terminated, but only copies in to the native function */ NATIVE_STRING, /** The function takes a variable number of arguments */ NATIVE_VARARGS, /** Struct-by-value param or result */ NATIVE_STRUCT, /** An array type definition */ NATIVE_ARRAY, /** Custom native type */ NATIVE_MAPPED, } NativeType; #include #include "Type.h" VALUE rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr); void rbffi_Types_Init(VALUE moduleFFI); #ifdef __cplusplus } #endif #endif /* RBFFI_TYPES_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/ClosurePool.h0000644000175000017500000000472312261216357022063 0ustar terceiroterceiro/* * Copyright (c) 2009, 2010 Wayne Meissner * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RUBYFFI_CLOSUREPOOL_H #define RUBYFFI_CLOSUREPOOL_H typedef struct ClosurePool_ ClosurePool; typedef struct Closure_ Closure; struct Closure_ { void* info; /* opaque handle for storing closure-instance specific data */ void* function; /* closure-instance specific function, called by custom trampoline */ void* code; /* The native trampoline code location */ struct ClosurePool_* pool; Closure* next; }; void rbffi_ClosurePool_Init(VALUE module); ClosurePool* rbffi_ClosurePool_New(int closureSize, bool (*prep)(void* ctx, void *code, Closure* closure, char* errbuf, size_t errbufsize), void* ctx); void rbffi_ClosurePool_Free(ClosurePool *); Closure* rbffi_Closure_Alloc(ClosurePool *); void rbffi_Closure_Free(Closure *); void* rbffi_Closure_GetCodeAddress(Closure *); #endif /* RUBYFFI_CLOSUREPOOL_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/MappedType.h0000644000175000017500000000375112261216360021657 0ustar terceiroterceiro/* * Copyright (c) 2010, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_MAPPEDTYPE_H #define RBFFI_MAPPEDTYPE_H #include #ifdef __cplusplus extern "C" { #endif typedef struct MappedType_ { Type base; Type* type; VALUE rbConverter; VALUE rbType; } MappedType; void rbffi_MappedType_Init(VALUE moduleFFI); extern VALUE rbffi_MappedTypeClass; #ifdef __cplusplus } #endif #endif /* RBFFI_MAPPEDTYPE_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/Thread.h0000644000175000017500000000533512261216360021016 0ustar terceiroterceiro/* * Copyright (c) 2010 Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_THREAD_H #define RBFFI_THREAD_H #ifndef _MSC_VER # include #else # include "win32/stdbool.h" # include "win32/stdint.h" #endif #include #include "extconf.h" #ifdef __cplusplus extern "C" { #endif #ifdef _WIN32 # include #else # include #endif typedef struct { #ifdef _WIN32 DWORD id; #else pthread_t id; #endif bool valid; bool has_gvl; VALUE exc; } rbffi_thread_t; typedef struct rbffi_frame { #ifndef _WIN32 struct thread_data* td; #endif struct rbffi_frame* prev; bool has_gvl; VALUE exc; } rbffi_frame_t; rbffi_frame_t* rbffi_frame_current(void); void rbffi_frame_push(rbffi_frame_t* frame); void rbffi_frame_pop(rbffi_frame_t* frame); #ifdef HAVE_RB_THREAD_CALL_WITHOUT_GVL # define rbffi_thread_blocking_region rb_thread_call_without_gvl #elif defined(HAVE_RB_THREAD_BLOCKING_REGION) # define rbffi_thread_blocking_region rb_thread_blocking_region #else VALUE rbffi_thread_blocking_region(VALUE (*func)(void *), void *data1, void (*ubf)(void *), void *data2); #endif #ifdef __cplusplus } #endif #endif /* RBFFI_THREAD_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/Type.c0000644000175000017500000002532512261216360020524 0ustar terceiroterceiro/* * Copyright (c) 2009, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER #include #endif #include #include #include #include "rbffi.h" #include "compat.h" #include "Types.h" #include "Type.h" typedef struct BuiltinType_ { Type type; char* name; } BuiltinType; static void builtin_type_free(BuiltinType *); VALUE rbffi_TypeClass = Qnil; static VALUE classBuiltinType = Qnil; static VALUE moduleNativeType = Qnil; static VALUE typeMap = Qnil, sizeMap = Qnil; static ID id_find_type = 0, id_type_size = 0, id_size = 0; static VALUE type_allocate(VALUE klass) { Type* type; VALUE obj = Data_Make_Struct(klass, Type, NULL, -1, type); type->nativeType = -1; type->ffiType = &ffi_type_void; return obj; } /* * Document-method: initialize * call-seq: initialize(value) * @param [Fixnum,Type] value * @return [self] */ static VALUE type_initialize(VALUE self, VALUE value) { Type* type; Type* other; Data_Get_Struct(self, Type, type); if (FIXNUM_P(value)) { type->nativeType = FIX2INT(value); } else if (rb_obj_is_kind_of(value, rbffi_TypeClass)) { Data_Get_Struct(value, Type, other); type->nativeType = other->nativeType; type->ffiType = other->ffiType; } else { rb_raise(rb_eArgError, "wrong type"); } return self; } /* * call-seq: type.size * @return [Fixnum] * Return type's size, in bytes. */ static VALUE type_size(VALUE self) { Type *type; Data_Get_Struct(self, Type, type); return INT2FIX(type->ffiType->size); } /* * call-seq: type.alignment * @return [Fixnum] * Get Type alignment. */ static VALUE type_alignment(VALUE self) { Type *type; Data_Get_Struct(self, Type, type); return INT2FIX(type->ffiType->alignment); } /* * call-seq: type.inspect * @return [String] * Inspect {Type} object. */ static VALUE type_inspect(VALUE self) { char buf[100]; Type *type; Data_Get_Struct(self, Type, type); snprintf(buf, sizeof(buf), "#<%s:%p size=%d alignment=%d>", rb_obj_classname(self), type, (int) type->ffiType->size, (int) type->ffiType->alignment); return rb_str_new2(buf); } static VALUE builtin_type_new(VALUE klass, int nativeType, ffi_type* ffiType, const char* name) { BuiltinType* type; VALUE obj = Qnil; obj = Data_Make_Struct(klass, BuiltinType, NULL, builtin_type_free, type); type->name = strdup(name); type->type.nativeType = nativeType; type->type.ffiType = ffiType; return obj; } static void builtin_type_free(BuiltinType *type) { free(type->name); xfree(type); } /* * call-seq: type.inspect * @return [String] * Inspect {Type::Builtin} object. */ static VALUE builtin_type_inspect(VALUE self) { char buf[100]; BuiltinType *type; Data_Get_Struct(self, BuiltinType, type); snprintf(buf, sizeof(buf), "#<%s:%s size=%d alignment=%d>", rb_obj_classname(self), type->name, (int) type->type.ffiType->size, type->type.ffiType->alignment); return rb_str_new2(buf); } int rbffi_type_size(VALUE type) { int t = TYPE(type); if (t == T_FIXNUM || t == T_BIGNUM) { return NUM2INT(type); } else if (t == T_SYMBOL) { /* * Try looking up directly in the type and size maps */ VALUE nType; if ((nType = rb_hash_lookup(typeMap, type)) != Qnil) { if (rb_obj_is_kind_of(nType, rbffi_TypeClass)) { Type* type; Data_Get_Struct(nType, Type, type); return (int) type->ffiType->size; } else if (rb_respond_to(nType, id_size)) { return NUM2INT(rb_funcall2(nType, id_size, 0, NULL)); } } /* Not found - call up to the ruby version to resolve */ return NUM2INT(rb_funcall2(rbffi_FFIModule, id_type_size, 1, &type)); } else { return NUM2INT(rb_funcall2(type, id_size, 0, NULL)); } } VALUE rbffi_Type_Lookup(VALUE name) { int t = TYPE(name); if (t == T_SYMBOL || t == T_STRING) { /* * Try looking up directly in the type Map */ VALUE nType; if ((nType = rb_hash_lookup(typeMap, name)) != Qnil && rb_obj_is_kind_of(nType, rbffi_TypeClass)) { return nType; } } else if (rb_obj_is_kind_of(name, rbffi_TypeClass)) { return name; } /* Nothing found - let caller handle raising exceptions */ return Qnil; } /** * rbffi_Type_Find() is like rbffi_Type_Lookup, but an error is raised if the * type is not found. */ VALUE rbffi_Type_Find(VALUE name) { VALUE rbType = rbffi_Type_Lookup(name); if (!RTEST(rbType)) { VALUE s = rb_inspect(name); rb_raise(rb_eTypeError, "invalid type, %s", RSTRING_PTR(s)); RB_GC_GUARD(s); } return rbType; } void rbffi_Type_Init(VALUE moduleFFI) { /* * Document-class: FFI::Type * This class manages C types. * * It embbed {FFI::Type::Builtin} objects as constants (for names, * see {FFI::NativeType}). */ rbffi_TypeClass = rb_define_class_under(moduleFFI, "Type", rb_cObject); /* * Document-constant: FFI::TypeDefs */ rb_define_const(moduleFFI, "TypeDefs", typeMap = rb_hash_new()); rb_define_const(moduleFFI, "SizeTypes", sizeMap = rb_hash_new()); rb_global_variable(&typeMap); rb_global_variable(&sizeMap); id_find_type = rb_intern("find_type"); id_type_size = rb_intern("type_size"); id_size = rb_intern("size"); /* * Document-class: FFI::Type::Builtin * Class for Built-in types. */ classBuiltinType = rb_define_class_under(rbffi_TypeClass, "Builtin", rbffi_TypeClass); /* * Document-module: FFI::NativeType * This module defines constants for native (C) types. * * ==Native type constants * Native types are defined by constants : * * INT8, SCHAR, CHAR * * UINT8, UCHAR * * INT16, SHORT, SSHORT * * UINT16, USHORT * * INT32,, INT, SINT * * UINT32, UINT * * INT64, LONG_LONG, SLONG_LONG * * UINT64, ULONG_LONG * * LONG, SLONG * * ULONG * * FLOAT32, FLOAT * * FLOAT64, DOUBLE * * POINTER * * CALLBACK * * FUNCTION * * CHAR_ARRAY * * BOOL * * STRING (immutable string, nul terminated) * * STRUCT (struct-b-value param or result) * * ARRAY (array type definition) * * MAPPED (custom native type) * For function return type only : * * VOID * For function argument type only : * * BUFFER_IN * * BUFFER_OUT * * VARARGS (function takes a variable number of arguments) * * All these constants are exported to {FFI} module prefixed with "TYPE_". * They are objets from {FFI::Type::Builtin} class. */ moduleNativeType = rb_define_module_under(moduleFFI, "NativeType"); /* * Document-global: FFI::Type */ rb_global_variable(&rbffi_TypeClass); rb_global_variable(&classBuiltinType); rb_global_variable(&moduleNativeType); rb_define_alloc_func(rbffi_TypeClass, type_allocate); rb_define_method(rbffi_TypeClass, "initialize", type_initialize, 1); rb_define_method(rbffi_TypeClass, "size", type_size, 0); rb_define_method(rbffi_TypeClass, "alignment", type_alignment, 0); rb_define_method(rbffi_TypeClass, "inspect", type_inspect, 0); /* Make Type::Builtin non-allocatable */ rb_undef_method(CLASS_OF(classBuiltinType), "new"); rb_define_method(classBuiltinType, "inspect", builtin_type_inspect, 0); rb_global_variable(&rbffi_TypeClass); rb_global_variable(&classBuiltinType); /* Define all the builtin types */ #define T(x, ffiType) do { \ VALUE t = Qnil; \ rb_define_const(rbffi_TypeClass, #x, t = builtin_type_new(classBuiltinType, NATIVE_##x, ffiType, #x)); \ rb_define_const(moduleNativeType, #x, t); \ rb_define_const(moduleFFI, "TYPE_" #x, t); \ } while(0) #define A(old_type, new_type) do { \ VALUE t = rb_const_get(rbffi_TypeClass, rb_intern(#old_type)); \ rb_const_set(rbffi_TypeClass, rb_intern(#new_type), t); \ } while(0) /* * Document-constant: FFI::Type::Builtin::VOID */ T(VOID, &ffi_type_void); T(INT8, &ffi_type_sint8); A(INT8, SCHAR); A(INT8, CHAR); T(UINT8, &ffi_type_uint8); A(UINT8, UCHAR); T(INT16, &ffi_type_sint16); A(INT16, SHORT); A(INT16, SSHORT); T(UINT16, &ffi_type_uint16); A(UINT16, USHORT); T(INT32, &ffi_type_sint32); A(INT32, INT); A(INT32, SINT); T(UINT32, &ffi_type_uint32); A(UINT32, UINT); T(INT64, &ffi_type_sint64); A(INT64, LONG_LONG); A(INT64, SLONG_LONG); T(UINT64, &ffi_type_uint64); A(UINT64, ULONG_LONG); T(LONG, &ffi_type_slong); A(LONG, SLONG); T(ULONG, &ffi_type_ulong); T(FLOAT32, &ffi_type_float); A(FLOAT32, FLOAT); T(FLOAT64, &ffi_type_double); A(FLOAT64, DOUBLE); T(LONGDOUBLE, &ffi_type_longdouble); T(POINTER, &ffi_type_pointer); T(STRING, &ffi_type_pointer); T(BUFFER_IN, &ffi_type_pointer); T(BUFFER_OUT, &ffi_type_pointer); T(BUFFER_INOUT, &ffi_type_pointer); T(BOOL, &ffi_type_uchar); T(VARARGS, &ffi_type_void); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/AbstractMemory.h0000644000175000017500000001223312261216357022544 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_ABSTRACTMEMORY_H #define RBFFI_ABSTRACTMEMORY_H #ifndef _MSC_VER #include #endif #include #ifndef _MSC_VER #include #endif #include "compat.h" #include "Types.h" #ifdef __cplusplus extern "C" { #endif #define MEM_RD 0x01 #define MEM_WR 0x02 #define MEM_CODE 0x04 #define MEM_SWAP 0x08 #define MEM_EMBED 0x10 typedef struct AbstractMemory_ AbstractMemory; typedef struct { VALUE (*get)(AbstractMemory* ptr, long offset); void (*put)(AbstractMemory* ptr, long offset, VALUE value); } MemoryOp; typedef struct { MemoryOp* int8; MemoryOp* uint8; MemoryOp* int16; MemoryOp* uint16; MemoryOp* int32; MemoryOp* uint32; MemoryOp* int64; MemoryOp* uint64; MemoryOp* slong; MemoryOp* uslong; MemoryOp* float32; MemoryOp* float64; MemoryOp* longdouble; MemoryOp* pointer; MemoryOp* strptr; MemoryOp* boolOp; } MemoryOps; struct AbstractMemory_ { char* address; /* Use char* instead of void* to ensure adding to it works correctly */ long size; int flags; int typeSize; }; extern VALUE rbffi_AbstractMemoryClass; extern MemoryOps rbffi_AbstractMemoryOps; extern void rbffi_AbstractMemory_Init(VALUE ffiModule); extern AbstractMemory* rbffi_AbstractMemory_Cast(VALUE obj, VALUE klass); extern void rbffi_AbstractMemory_Error(AbstractMemory *, int op); static inline void checkBounds(AbstractMemory* mem, long off, long len) { if (unlikely((off | len | (off + len) | (mem->size - (off + len))) < 0)) { rb_raise(rb_eIndexError, "Memory access offset=%ld size=%ld is out of bounds", off, len); } } static inline void checkRead(AbstractMemory* mem) { if (unlikely((mem->flags & MEM_RD) == 0)) { rbffi_AbstractMemory_Error(mem, MEM_RD); } } static inline void checkWrite(AbstractMemory* mem) { if (unlikely((mem->flags & MEM_WR) == 0)) { rbffi_AbstractMemory_Error(mem, MEM_WR); } } static inline MemoryOp* get_memory_op(Type* type) { switch (type->nativeType) { case NATIVE_INT8: return rbffi_AbstractMemoryOps.int8; case NATIVE_UINT8: return rbffi_AbstractMemoryOps.uint8; case NATIVE_INT16: return rbffi_AbstractMemoryOps.int16; case NATIVE_UINT16: return rbffi_AbstractMemoryOps.uint16; case NATIVE_INT32: return rbffi_AbstractMemoryOps.int32; case NATIVE_UINT32: return rbffi_AbstractMemoryOps.uint32; case NATIVE_INT64: return rbffi_AbstractMemoryOps.int64; case NATIVE_UINT64: return rbffi_AbstractMemoryOps.uint64; case NATIVE_LONG: return rbffi_AbstractMemoryOps.slong; case NATIVE_ULONG: return rbffi_AbstractMemoryOps.uslong; case NATIVE_FLOAT32: return rbffi_AbstractMemoryOps.float32; case NATIVE_FLOAT64: return rbffi_AbstractMemoryOps.float64; case NATIVE_LONGDOUBLE: return rbffi_AbstractMemoryOps.longdouble; case NATIVE_POINTER: return rbffi_AbstractMemoryOps.pointer; case NATIVE_STRING: return rbffi_AbstractMemoryOps.strptr; case NATIVE_BOOL: return rbffi_AbstractMemoryOps.boolOp; default: return NULL; } } #define MEMORY(obj) rbffi_AbstractMemory_Cast((obj), rbffi_AbstractMemoryClass) #define MEMORY_PTR(obj) MEMORY((obj))->address #define MEMORY_LEN(obj) MEMORY((obj))->size #ifdef __cplusplus } #endif #endif /* RBFFI_ABSTRACTMEMORY_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/libffi.bsd.mk0000644000175000017500000000153412261216360021766 0ustar terceiroterceiro# -*- makefile -*- # # Makefile for BSD systems # INCFLAGS += -I${LIBFFI_BUILD_DIR}/include LOCAL_LIBS += ${LIBFFI} -lpthread LIBFFI_CFLAGS = ${FFI_MMAP_EXEC} -pthread LIBFFI_BUILD_DIR = ${.CURDIR}/libffi-${arch} .if ${srcdir} == "." LIBFFI_SRC_DIR := ${.CURDIR}/libffi .else LIBFFI_SRC_DIR := ${srcdir}/libffi .endif LIBFFI = ${LIBFFI_BUILD_DIR}/.libs/libffi_convenience.a LIBFFI_CONFIGURE = ${LIBFFI_SRC_DIR}/configure --disable-static \ --with-pic=yes --disable-dependency-tracking $(OBJS): ${LIBFFI} $(LIBFFI): @mkdir -p ${LIBFFI_BUILD_DIR} @if [ ! -f ${LIBFFI_BUILD_DIR}/Makefile ]; then \ echo "Configuring libffi"; \ cd ${LIBFFI_BUILD_DIR} && \ /usr/bin/env CC="${CC}" LD="${LD}" CFLAGS="${LIBFFI_CFLAGS}" GREP_OPTIONS="" \ /bin/sh ${LIBFFI_CONFIGURE} ${LIBFFI_HOST} > /dev/null; \ fi @cd ${LIBFFI_BUILD_DIR} && ${MAKE} ruby-ffi-1.9.3debian.orig/ext/ffi_c/StructByValue.h0000644000175000017500000000400212261216360022351 0ustar terceiroterceiro/* * Copyright (c) 2009, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_STRUCTBYVALUE_H #define RBFFI_STRUCTBYVALUE_H #include #include "Type.h" #ifdef __cplusplus extern "C" { #endif typedef struct StructByValue_ { Type base; VALUE rbStructClass; VALUE rbStructLayout; } StructByValue; void rbffi_StructByValue_Init(VALUE moduleFFI); extern VALUE rbffi_StructByValueClass; #ifdef __cplusplus } #endif #endif /* RBFFI_STRUCTBYVALUE_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/MethodHandle.h0000644000175000017500000000420412261216360022135 0ustar terceiroterceiro/* * Copyright (c) 2009, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_METHODHANDLE_H #define RBFFI_METHODHANDLE_H #ifdef __cplusplus extern "C" { #endif #include #include "Function.h" typedef struct MethodHandlePool MethodHandlePool; typedef struct MethodHandle MethodHandle; MethodHandle* rbffi_MethodHandle_Alloc(FunctionType* fnInfo, void* function); void rbffi_MethodHandle_Free(MethodHandle* handle); void* rbffi_MethodHandle_CodeAddress(MethodHandle* handle); void rbffi_MethodHandle_Init(VALUE module); #ifdef __cplusplus } #endif #endif /* RBFFI_METHODHANDLE_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/Types.c0000644000175000017500000001204112261216360020676 0ustar terceiroterceiro/* * Copyright (c) 2009, Wayne Meissner * Copyright (c) 2009, Luc Heinrich * Copyright (c) 2009, Aman Gupta. * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "Pointer.h" #include "rbffi.h" #include "Function.h" #include "StructByValue.h" #include "Types.h" #include "Struct.h" #include "MappedType.h" #include "MemoryPointer.h" #include "LongDouble.h" static ID id_from_native = 0; VALUE rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr) { switch (type->nativeType) { case NATIVE_VOID: return Qnil; case NATIVE_INT8: return INT2NUM((signed char) *(ffi_sarg *) ptr); case NATIVE_INT16: return INT2NUM((signed short) *(ffi_sarg *) ptr); case NATIVE_INT32: return INT2NUM((signed int) *(ffi_sarg *) ptr); case NATIVE_LONG: return LONG2NUM((signed long) *(ffi_sarg *) ptr); case NATIVE_INT64: return LL2NUM(*(signed long long *) ptr); case NATIVE_UINT8: return UINT2NUM((unsigned char) *(ffi_arg *) ptr); case NATIVE_UINT16: return UINT2NUM((unsigned short) *(ffi_arg *) ptr); case NATIVE_UINT32: return UINT2NUM((unsigned int) *(ffi_arg *) ptr); case NATIVE_ULONG: return ULONG2NUM((unsigned long) *(ffi_arg *) ptr); case NATIVE_UINT64: return ULL2NUM(*(unsigned long long *) ptr); case NATIVE_FLOAT32: return rb_float_new(*(float *) ptr); case NATIVE_FLOAT64: return rb_float_new(*(double *) ptr); case NATIVE_LONGDOUBLE: return rbffi_longdouble_new(*(long double *) ptr); case NATIVE_STRING: return (*(void **) ptr != NULL) ? rb_tainted_str_new2(*(char **) ptr) : Qnil; case NATIVE_POINTER: return rbffi_Pointer_NewInstance(*(void **) ptr); case NATIVE_BOOL: return ((unsigned char) *(ffi_arg *) ptr) ? Qtrue : Qfalse; case NATIVE_FUNCTION: case NATIVE_CALLBACK: { return *(void **) ptr != NULL ? rbffi_Function_NewInstance(rbType, rbffi_Pointer_NewInstance(*(void **) ptr)) : Qnil; } case NATIVE_STRUCT: { StructByValue* sbv = (StructByValue *)type; AbstractMemory* mem; VALUE rbMemory = rbffi_MemoryPointer_NewInstance(1, sbv->base.ffiType->size, false); Data_Get_Struct(rbMemory, AbstractMemory, mem); memcpy(mem->address, ptr, sbv->base.ffiType->size); RB_GC_GUARD(rbMemory); RB_GC_GUARD(rbType); return rb_class_new_instance(1, &rbMemory, sbv->rbStructClass); } case NATIVE_MAPPED: { /* * For mapped types, first convert to the real native type, then upcall to * ruby to convert to the expected return type */ MappedType* m = (MappedType *) type; VALUE values[2], rbReturnValue; values[0] = rbffi_NativeValue_ToRuby(m->type, m->rbType, ptr); values[1] = Qnil; rbReturnValue = rb_funcall2(m->rbConverter, id_from_native, 2, values); RB_GC_GUARD(values[0]); RB_GC_GUARD(rbType); return rbReturnValue; } default: rb_raise(rb_eRuntimeError, "Unknown type: %d", type->nativeType); return Qnil; } } void rbffi_Types_Init(VALUE moduleFFI) { id_from_native = rb_intern("from_native"); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/DynamicLibrary.c0000644000175000017500000002354612261216357022525 0ustar terceiroterceiro/* * Copyright (c) 2008-2010 Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifndef _MSC_VER # include #endif #if (defined(_WIN32) || defined(__WIN32__)) && !defined(__CYGWIN__) # include # define _WINSOCKAPI_ # include #else # include #endif #include #if defined(_MSC_VER) && !defined(INT8_MIN) # include "win32/stdint.h" #endif #include #include "rbffi.h" #include "compat.h" #include "AbstractMemory.h" #include "Pointer.h" #include "DynamicLibrary.h" typedef struct LibrarySymbol_ { Pointer base; VALUE library; VALUE name; } LibrarySymbol; static VALUE library_initialize(VALUE self, VALUE libname, VALUE libflags); static void library_free(Library* lib); static VALUE symbol_allocate(VALUE klass); static VALUE symbol_new(VALUE library, void* address, VALUE name); static void symbol_mark(LibrarySymbol* sym); static VALUE LibraryClass = Qnil, SymbolClass = Qnil; #if (defined(_WIN32) || defined(__WIN32__)) && !defined(__CYGWIN__) static void* dl_open(const char* name, int flags); static void dl_error(char* buf, int size); #define dl_sym(handle, name) GetProcAddress(handle, name) #define dl_close(handle) FreeLibrary(handle) enum { RTLD_LAZY=1, RTLD_NOW, RTLD_GLOBAL, RTLD_LOCAL }; #else # define dl_open(name, flags) dlopen(name, flags != 0 ? flags : RTLD_LAZY) # define dl_error(buf, size) do { snprintf(buf, size, "%s", dlerror()); } while(0) # define dl_sym(handle, name) dlsym(handle, name) # define dl_close(handle) dlclose(handle) #ifndef RTLD_LOCAL # define RTLD_LOCAL 8 #endif #endif static VALUE library_allocate(VALUE klass) { Library* library; return Data_Make_Struct(klass, Library, NULL, library_free, library); } /* * call-seq: DynamicLibrary.open(libname, libflags) * @param libname (see #initialize) * @param libflags (see #initialize) * @return [FFI::DynamicLibrary] * @raise {LoadError} if +libname+ cannot be opened * Open a library. */ static VALUE library_open(VALUE klass, VALUE libname, VALUE libflags) { return library_initialize(library_allocate(klass), libname, libflags); } /* * call-seq: initialize(libname, libflags) * @param [String] libname name of library to open * @param [Fixnum] libflags flags for library to open * @return [FFI::DynamicLibrary] * @raise {LoadError} if +libname+ cannot be opened * A new DynamicLibrary instance. */ static VALUE library_initialize(VALUE self, VALUE libname, VALUE libflags) { Library* library; int flags; Check_Type(libflags, T_FIXNUM); Data_Get_Struct(self, Library, library); flags = libflags != Qnil ? NUM2UINT(libflags) : 0; library->handle = dl_open(libname != Qnil ? StringValueCStr(libname) : NULL, flags); if (library->handle == NULL) { char errmsg[1024]; dl_error(errmsg, sizeof(errmsg)); rb_raise(rb_eLoadError, "Could not open library '%s': %s", libname != Qnil ? StringValueCStr(libname) : "[current process]", errmsg); } #ifdef __CYGWIN__ // On Cygwin 1.7.17 "dlsym(dlopen(0,0), 'getpid')" fails. (dlerror: "No such process") // As a workaround we can use "dlsym(RTLD_DEFAULT, 'getpid')" instead. // Since 0 == RTLD_DEFAULT we won't call dl_close later. if (libname == Qnil) { dl_close(library->handle); library->handle = RTLD_DEFAULT; } #endif rb_iv_set(self, "@name", libname != Qnil ? libname : rb_str_new2("[current process]")); return self; } static VALUE library_dlsym(VALUE self, VALUE name) { Library* library; void* address = NULL; Check_Type(name, T_STRING); Data_Get_Struct(self, Library, library); address = dl_sym(library->handle, StringValueCStr(name)); return address != NULL ? symbol_new(self, address, name) : Qnil; } /* * call-seq: last_error * @return [String] library's last error string */ static VALUE library_dlerror(VALUE self) { char errmsg[1024]; dl_error(errmsg, sizeof(errmsg)); return rb_tainted_str_new2(errmsg); } static void library_free(Library* library) { /* dlclose() on MacOS tends to segfault - avoid it */ #ifndef __APPLE__ if (library->handle != NULL) { dl_close(library->handle); } #endif xfree(library); } #if (defined(_WIN32) || defined(__WIN32__)) && !defined(__CYGWIN__) static void* dl_open(const char* name, int flags) { if (name == NULL) { return GetModuleHandle(NULL); } else { return LoadLibraryExA(name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); } } static void dl_error(char* buf, int size) { FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, buf, size, NULL); } #endif static VALUE symbol_allocate(VALUE klass) { LibrarySymbol* sym; VALUE obj = Data_Make_Struct(klass, LibrarySymbol, NULL, -1, sym); sym->name = Qnil; sym->library = Qnil; sym->base.rbParent = Qnil; return obj; } /* * call-seq: initialize_copy(other) * @param [Object] other * @return [nil] * DO NOT CALL THIS METHOD */ static VALUE symbol_initialize_copy(VALUE self, VALUE other) { rb_raise(rb_eRuntimeError, "cannot duplicate symbol"); return Qnil; } static VALUE symbol_new(VALUE library, void* address, VALUE name) { LibrarySymbol* sym; VALUE obj = Data_Make_Struct(SymbolClass, LibrarySymbol, symbol_mark, -1, sym); sym->base.memory.address = address; sym->base.memory.size = LONG_MAX; sym->base.memory.typeSize = 1; sym->base.memory.flags = MEM_RD | MEM_WR; sym->library = library; sym->name = name; return obj; } static void symbol_mark(LibrarySymbol* sym) { rb_gc_mark(sym->library); rb_gc_mark(sym->name); } /* * call-seq: inspect * @return [String] * Inspect. */ static VALUE symbol_inspect(VALUE self) { LibrarySymbol* sym; char buf[256]; Data_Get_Struct(self, LibrarySymbol, sym); snprintf(buf, sizeof(buf), "#", StringValueCStr(sym->name), sym->base.memory.address); return rb_str_new2(buf); } void rbffi_DynamicLibrary_Init(VALUE moduleFFI) { /* * Document-class: FFI::DynamicLibrary */ LibraryClass = rb_define_class_under(moduleFFI, "DynamicLibrary", rb_cObject); rb_global_variable(&LibraryClass); /* * Document-class: FFI::DynamicLibrary::Symbol < FFI::Pointer * * An instance of this class represents a library symbol. It may be a {Pointer pointer} to * a function or to a variable. */ SymbolClass = rb_define_class_under(LibraryClass, "Symbol", rbffi_PointerClass); rb_global_variable(&SymbolClass); /* * Document-const: FFI::NativeLibrary * Backward compatibility for FFI::DynamicLibrary */ rb_define_const(moduleFFI, "NativeLibrary", LibraryClass); /* backwards compat library */ rb_define_alloc_func(LibraryClass, library_allocate); rb_define_singleton_method(LibraryClass, "open", library_open, 2); rb_define_singleton_method(LibraryClass, "last_error", library_dlerror, 0); rb_define_method(LibraryClass, "initialize", library_initialize, 2); /* * Document-method: find_symbol * call-seq: find_symbol(name) * @param [String] name library symbol's name * @return [FFI::DynamicLibrary::Symbol] library symbol */ rb_define_method(LibraryClass, "find_symbol", library_dlsym, 1); /* * Document-method: find_function * call-seq: find_function(name) * @param [String] name library function's name * @return [FFI::DynamicLibrary::Symbol] library function symbol */ rb_define_method(LibraryClass, "find_function", library_dlsym, 1); /* * Document-method: find_variable * call-seq: find_variable(name) * @param [String] name library variable's name * @return [FFI::DynamicLibrary::Symbol] library variable symbol */ rb_define_method(LibraryClass, "find_variable", library_dlsym, 1); rb_define_method(LibraryClass, "last_error", library_dlerror, 0); rb_define_attr(LibraryClass, "name", 1, 0); rb_define_alloc_func(SymbolClass, symbol_allocate); rb_undef_method(SymbolClass, "new"); rb_define_method(SymbolClass, "inspect", symbol_inspect, 0); rb_define_method(SymbolClass, "initialize_copy", symbol_initialize_copy, 1); #define DEF(x) rb_define_const(LibraryClass, "RTLD_" #x, UINT2NUM(RTLD_##x)) DEF(LAZY); DEF(NOW); DEF(GLOBAL); DEF(LOCAL); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/Variadic.c0000644000175000017500000002174512261216360021327 0ustar terceiroterceiro/* * Copyright (c) 2008-2010 Wayne Meissner * Copyright (C) 2009 Andrea Fazzi * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER #include #endif #include #include #ifndef _MSC_VER # include # include #else # include "win32/stdbool.h" # include "win32/stdint.h" #endif #include #include #include "rbffi.h" #include "compat.h" #include "AbstractMemory.h" #include "Pointer.h" #include "Types.h" #include "Type.h" #include "LastError.h" #include "MethodHandle.h" #include "Call.h" #include "Thread.h" typedef struct VariadicInvoker_ { VALUE rbAddress; VALUE rbReturnType; VALUE rbEnums; Type* returnType; ffi_abi abi; void* function; int paramCount; } VariadicInvoker; static VALUE variadic_allocate(VALUE klass); static VALUE variadic_initialize(VALUE self, VALUE rbFunction, VALUE rbParameterTypes, VALUE rbReturnType, VALUE options); static void variadic_mark(VariadicInvoker *); static VALUE classVariadicInvoker = Qnil; static VALUE variadic_allocate(VALUE klass) { VariadicInvoker *invoker; VALUE obj = Data_Make_Struct(klass, VariadicInvoker, variadic_mark, -1, invoker); invoker->rbAddress = Qnil; invoker->rbEnums = Qnil; invoker->rbReturnType = Qnil; return obj; } static void variadic_mark(VariadicInvoker *invoker) { rb_gc_mark(invoker->rbEnums); rb_gc_mark(invoker->rbAddress); rb_gc_mark(invoker->rbReturnType); } static VALUE variadic_initialize(VALUE self, VALUE rbFunction, VALUE rbParameterTypes, VALUE rbReturnType, VALUE options) { VariadicInvoker* invoker = NULL; VALUE retval = Qnil; VALUE convention = Qnil; VALUE fixed = Qnil; #if defined(_WIN32) || defined(__WIN32__) VALUE rbConventionStr; #endif int i; Check_Type(options, T_HASH); convention = rb_hash_aref(options, ID2SYM(rb_intern("convention"))); Data_Get_Struct(self, VariadicInvoker, invoker); invoker->rbEnums = rb_hash_aref(options, ID2SYM(rb_intern("enums"))); invoker->rbAddress = rbFunction; invoker->function = rbffi_AbstractMemory_Cast(rbFunction, rbffi_PointerClass)->address; #if (defined(_WIN32) || defined(__WIN32__)) && defined(FFI_STDCALL) rbConventionStr = rb_funcall2(convention, rb_intern("to_s"), 0, NULL); invoker->abi = (RTEST(convention) && strcmp(StringValueCStr(rbConventionStr), "stdcall") == 0) ? FFI_STDCALL : FFI_DEFAULT_ABI; #else invoker->abi = FFI_DEFAULT_ABI; #endif invoker->rbReturnType = rbffi_Type_Lookup(rbReturnType); if (!RTEST(invoker->rbReturnType)) { VALUE typeName = rb_funcall2(rbReturnType, rb_intern("inspect"), 0, NULL); rb_raise(rb_eTypeError, "Invalid return type (%s)", RSTRING_PTR(typeName)); } Data_Get_Struct(rbReturnType, Type, invoker->returnType); invoker->paramCount = -1; fixed = rb_ary_new2(RARRAY_LEN(rbParameterTypes) - 1); for (i = 0; i < RARRAY_LEN(rbParameterTypes); ++i) { VALUE entry = rb_ary_entry(rbParameterTypes, i); VALUE rbType = rbffi_Type_Lookup(entry); Type* type; if (!RTEST(rbType)) { VALUE typeName = rb_funcall2(entry, rb_intern("inspect"), 0, NULL); rb_raise(rb_eTypeError, "Invalid parameter type (%s)", RSTRING_PTR(typeName)); } Data_Get_Struct(rbType, Type, type); if (type->nativeType != NATIVE_VARARGS) { rb_ary_push(fixed, entry); } } /* * @fixed and @type_map are used by the parameter mangling ruby code */ rb_iv_set(self, "@fixed", fixed); rb_iv_set(self, "@type_map", rb_hash_aref(options, ID2SYM(rb_intern("type_map")))); return retval; } static VALUE variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues) { VariadicInvoker* invoker; FFIStorage* params; void* retval; ffi_cif cif; void** ffiValues; ffi_type** ffiParamTypes; ffi_type* ffiReturnType; Type** paramTypes; VALUE* argv; int paramCount = 0, i; ffi_status ffiStatus; rbffi_frame_t frame = { 0 }; Check_Type(parameterTypes, T_ARRAY); Check_Type(parameterValues, T_ARRAY); Data_Get_Struct(self, VariadicInvoker, invoker); paramCount = (int) RARRAY_LEN(parameterTypes); paramTypes = ALLOCA_N(Type *, paramCount); ffiParamTypes = ALLOCA_N(ffi_type *, paramCount); params = ALLOCA_N(FFIStorage, paramCount); ffiValues = ALLOCA_N(void*, paramCount); argv = ALLOCA_N(VALUE, paramCount); retval = alloca(MAX(invoker->returnType->ffiType->size, FFI_SIZEOF_ARG)); for (i = 0; i < paramCount; ++i) { VALUE rbType = rb_ary_entry(parameterTypes, i); if (!rb_obj_is_kind_of(rbType, rbffi_TypeClass)) { rb_raise(rb_eTypeError, "wrong type. Expected (FFI::Type)"); } Data_Get_Struct(rbType, Type, paramTypes[i]); switch (paramTypes[i]->nativeType) { case NATIVE_INT8: case NATIVE_INT16: case NATIVE_INT32: rbType = rb_const_get(rbffi_TypeClass, rb_intern("INT32")); Data_Get_Struct(rbType, Type, paramTypes[i]); break; case NATIVE_UINT8: case NATIVE_UINT16: case NATIVE_UINT32: rbType = rb_const_get(rbffi_TypeClass, rb_intern("UINT32")); Data_Get_Struct(rbType, Type, paramTypes[i]); break; case NATIVE_FLOAT32: rbType = rb_const_get(rbffi_TypeClass, rb_intern("DOUBLE")); Data_Get_Struct(rbType, Type, paramTypes[i]); break; default: break; } ffiParamTypes[i] = paramTypes[i]->ffiType; if (ffiParamTypes[i] == NULL) { rb_raise(rb_eArgError, "Invalid parameter type #%x", paramTypes[i]->nativeType); } argv[i] = rb_ary_entry(parameterValues, i); } ffiReturnType = invoker->returnType->ffiType; if (ffiReturnType == NULL) { rb_raise(rb_eArgError, "Invalid return type"); } #ifdef HAVE_FFI_PREP_CIF_VAR ffiStatus = ffi_prep_cif_var(&cif, invoker->abi, paramCount, paramCount, ffiReturnType, ffiParamTypes); #else ffiStatus = ffi_prep_cif(&cif, invoker->abi, paramCount, ffiReturnType, ffiParamTypes); #endif switch (ffiStatus) { case FFI_BAD_ABI: rb_raise(rb_eArgError, "Invalid ABI specified"); case FFI_BAD_TYPEDEF: rb_raise(rb_eArgError, "Invalid argument type specified"); case FFI_OK: break; default: rb_raise(rb_eArgError, "Unknown FFI error"); } rbffi_SetupCallParams(paramCount, argv, -1, paramTypes, params, ffiValues, NULL, 0, invoker->rbEnums); rbffi_frame_push(&frame); ffi_call(&cif, FFI_FN(invoker->function), retval, ffiValues); rbffi_frame_pop(&frame); rbffi_save_errno(); if (RTEST(frame.exc) && frame.exc != Qnil) { rb_exc_raise(frame.exc); } return rbffi_NativeValue_ToRuby(invoker->returnType, invoker->rbReturnType, retval); } void rbffi_Variadic_Init(VALUE moduleFFI) { classVariadicInvoker = rb_define_class_under(moduleFFI, "VariadicInvoker", rb_cObject); rb_global_variable(&classVariadicInvoker); rb_define_alloc_func(classVariadicInvoker, variadic_allocate); rb_define_method(classVariadicInvoker, "initialize", variadic_initialize, 4); rb_define_method(classVariadicInvoker, "invoke", variadic_invoke, 2); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/LongDouble.h0000644000175000017500000000366312261216360021643 0ustar terceiroterceiro/* * Copyright (c) 2012, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_LONGDOUBLE_H #define RBFFI_LONGDOUBLE_H #include #ifdef __cplusplus extern "C" { #endif #ifdef _MSC_VER #define strtold strtod #endif extern VALUE rbffi_longdouble_new(long double ld); extern long double rbffi_num2longdouble(VALUE value); #ifdef __cplusplus } #endif #endif /* RBFFI_LONGDOUBLE_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/Struct.h0000644000175000017500000000655212261216360021075 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * Copyright (c) 2009, Luc Heinrich * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_STRUCT_H #define RBFFI_STRUCT_H #include "extconf.h" #include "AbstractMemory.h" #include "Type.h" #ifdef RUBY_1_9 #include #else #include #endif #ifdef __cplusplus extern "C" { #endif extern void rbffi_Struct_Init(VALUE ffiModule); extern void rbffi_StructLayout_Init(VALUE ffiModule); typedef struct StructField_ StructField; typedef struct StructLayout_ StructLayout; typedef struct Struct_ Struct; struct StructField_ { Type* type; unsigned int offset; int referenceIndex; bool referenceRequired; VALUE rbType; VALUE rbName; VALUE (*get)(StructField* field, Struct* s); void (*put)(StructField* field, Struct* s, VALUE value); MemoryOp* memoryOp; }; struct StructLayout_ { Type base; StructField** fields; int fieldCount; int size; int align; ffi_type** ffiTypes; struct st_table* fieldSymbolTable; /** The number of reference tracking fields in this struct */ int referenceFieldCount; VALUE rbFieldNames; VALUE rbFieldMap; VALUE rbFields; }; struct Struct_ { StructLayout* layout; AbstractMemory* pointer; VALUE* rbReferences; VALUE rbLayout; VALUE rbPointer; }; extern VALUE rbffi_StructClass, rbffi_StructLayoutClass; extern VALUE rbffi_StructLayoutFieldClass, rbffi_StructLayoutFunctionFieldClass; extern VALUE rbffi_StructLayoutArrayFieldClass; extern VALUE rbffi_StructInlineArrayClass; extern VALUE rbffi_StructLayoutCharArrayClass; #ifdef __cplusplus } #endif #endif /* RBFFI_STRUCT_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/StructLayout.c0000644000175000017500000005144012261216360022262 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * Copyright (c) 2009, Luc Heinrich * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #ifndef _MSC_VER # include # include # include #else # include "win32/stdbool.h" # include "win32/stdint.h" #endif #include #include "rbffi.h" #include "compat.h" #include "AbstractMemory.h" #include "Pointer.h" #include "MemoryPointer.h" #include "Function.h" #include "Types.h" #include "StructByValue.h" #include "ArrayType.h" #include "Function.h" #include "MappedType.h" #include "Struct.h" #define FFI_ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1) static void struct_layout_mark(StructLayout *); static void struct_layout_free(StructLayout *); static void struct_field_mark(StructField* ); VALUE rbffi_StructLayoutFieldClass = Qnil; VALUE rbffi_StructLayoutNumberFieldClass = Qnil, rbffi_StructLayoutPointerFieldClass = Qnil; VALUE rbffi_StructLayoutStringFieldClass = Qnil; VALUE rbffi_StructLayoutFunctionFieldClass = Qnil, rbffi_StructLayoutArrayFieldClass = Qnil; VALUE rbffi_StructLayoutClass = Qnil; static VALUE struct_field_allocate(VALUE klass) { StructField* field; VALUE obj; obj = Data_Make_Struct(klass, StructField, struct_field_mark, -1, field); field->rbType = Qnil; field->rbName = Qnil; return obj; } static void struct_field_mark(StructField* f) { rb_gc_mark(f->rbType); rb_gc_mark(f->rbName); } /* * call-seq: initialize(name, offset, type) * @param [String,Symbol] name * @param [Fixnum] offset * @param [FFI::Type] type * @return [self] * A new FFI::StructLayout::Field instance. */ static VALUE struct_field_initialize(int argc, VALUE* argv, VALUE self) { VALUE rbOffset = Qnil, rbName = Qnil, rbType = Qnil; StructField* field; int nargs; Data_Get_Struct(self, StructField, field); nargs = rb_scan_args(argc, argv, "3", &rbName, &rbOffset, &rbType); if (TYPE(rbName) != T_SYMBOL && TYPE(rbName) != T_STRING) { rb_raise(rb_eTypeError, "wrong argument type %s (expected Symbol/String)", rb_obj_classname(rbName)); } Check_Type(rbOffset, T_FIXNUM); if (!rb_obj_is_kind_of(rbType, rbffi_TypeClass)) { rb_raise(rb_eTypeError, "wrong argument type %s (expected FFI::Type)", rb_obj_classname(rbType)); } field->offset = NUM2UINT(rbOffset); field->rbName = (TYPE(rbName) == T_SYMBOL) ? rbName : rb_str_intern(rbName); field->rbType = rbType; Data_Get_Struct(field->rbType, Type, field->type); field->memoryOp = get_memory_op(field->type); field->referenceIndex = -1; switch (field->type->nativeType == NATIVE_MAPPED ? ((MappedType *) field->type)->type->nativeType : field->type->nativeType) { case NATIVE_FUNCTION: case NATIVE_CALLBACK: case NATIVE_POINTER: field->referenceRequired = true; break; default: field->referenceRequired = (rb_respond_to(self, rb_intern("reference_required?")) && RTEST(rb_funcall2(self, rb_intern("reference_required?"), 0, NULL))) || (rb_respond_to(rbType, rb_intern("reference_required?")) && RTEST(rb_funcall2(rbType, rb_intern("reference_required?"), 0, NULL))); break; } return self; } /* * call-seq: offset * @return [Numeric] * Get the field offset. */ static VALUE struct_field_offset(VALUE self) { StructField* field; Data_Get_Struct(self, StructField, field); return UINT2NUM(field->offset); } /* * call-seq: size * @return [Numeric] * Get the field size. */ static VALUE struct_field_size(VALUE self) { StructField* field; Data_Get_Struct(self, StructField, field); return UINT2NUM(field->type->ffiType->size); } /* * call-seq: alignment * @return [Numeric] * Get the field alignment. */ static VALUE struct_field_alignment(VALUE self) { StructField* field; Data_Get_Struct(self, StructField, field); return UINT2NUM(field->type->ffiType->alignment); } /* * call-seq: type * @return [Type] * Get the field type. */ static VALUE struct_field_type(VALUE self) { StructField* field; Data_Get_Struct(self, StructField, field); return field->rbType; } /* * call-seq: name * @return [Symbol] * Get the field name. */ static VALUE struct_field_name(VALUE self) { StructField* field; Data_Get_Struct(self, StructField, field); return field->rbName; } /* * call-seq: get(pointer) * @param [AbstractMemory] pointer pointer on a {Struct} * @return [Object] * Get an object of type {#type} from memory pointed by +pointer+. */ static VALUE struct_field_get(VALUE self, VALUE pointer) { StructField* f; Data_Get_Struct(self, StructField, f); if (f->memoryOp == NULL) { rb_raise(rb_eArgError, "get not supported for %s", rb_obj_classname(f->rbType)); return Qnil; } return (*f->memoryOp->get)(MEMORY(pointer), f->offset); } /* * call-seq: put(pointer, value) * @param [AbstractMemory] pointer pointer on a {Struct} * @param [Object] value this object must be a kind of {#type} * @return [self] * Put an object to memory pointed by +pointer+. */ static VALUE struct_field_put(VALUE self, VALUE pointer, VALUE value) { StructField* f; Data_Get_Struct(self, StructField, f); if (f->memoryOp == NULL) { rb_raise(rb_eArgError, "put not supported for %s", rb_obj_classname(f->rbType)); return self; } (*f->memoryOp->put)(MEMORY(pointer), f->offset, value); return self; } /* * call-seq: get(pointer) * @param [AbstractMemory] pointer pointer on a {Struct} * @return [Function] * Get a {Function} from memory pointed by +pointer+. */ static VALUE function_field_get(VALUE self, VALUE pointer) { StructField* f; Data_Get_Struct(self, StructField, f); return rbffi_Function_NewInstance(f->rbType, (*rbffi_AbstractMemoryOps.pointer->get)(MEMORY(pointer), f->offset)); } /* * call-seq: put(pointer, proc) * @param [AbstractMemory] pointer pointer to a {Struct} * @param [Function, Proc] proc * @return [Function] * Set a {Function} to memory pointed by +pointer+ as a function. * * If a Proc is submitted as +proc+, it is automatically transformed to a {Function}. */ static VALUE function_field_put(VALUE self, VALUE pointer, VALUE proc) { StructField* f; VALUE value = Qnil; Data_Get_Struct(self, StructField, f); if (NIL_P(proc) || rb_obj_is_kind_of(proc, rbffi_FunctionClass)) { value = proc; } else if (rb_obj_is_kind_of(proc, rb_cProc) || rb_respond_to(proc, rb_intern("call"))) { value = rbffi_Function_ForProc(f->rbType, proc); } else { rb_raise(rb_eTypeError, "wrong type (expected Proc or Function)"); } (*rbffi_AbstractMemoryOps.pointer->put)(MEMORY(pointer), f->offset, value); return self; } static inline bool isCharArray(ArrayType* arrayType) { return arrayType->componentType->nativeType == NATIVE_INT8 || arrayType->componentType->nativeType == NATIVE_UINT8; } /* * call-seq: get(pointer) * @param [AbstractMemory] pointer pointer on a {Struct} * @return [FFI::StructLayout::CharArray, FFI::Struct::InlineArray] * Get an array from a {Struct}. */ static VALUE array_field_get(VALUE self, VALUE pointer) { StructField* f; ArrayType* array; VALUE argv[2]; Data_Get_Struct(self, StructField, f); Data_Get_Struct(f->rbType, ArrayType, array); argv[0] = pointer; argv[1] = self; return rb_class_new_instance(2, argv, isCharArray(array) ? rbffi_StructLayoutCharArrayClass : rbffi_StructInlineArrayClass); } /* * call-seq: put(pointer, value) * @param [AbstractMemory] pointer pointer on a {Struct} * @param [String, Array] value +value+ may be a String only if array's type is a kind of +int8+ * @return [value] * Set an array in a {Struct}. */ static VALUE array_field_put(VALUE self, VALUE pointer, VALUE value) { StructField* f; ArrayType* array; Data_Get_Struct(self, StructField, f); Data_Get_Struct(f->rbType, ArrayType, array); if (isCharArray(array) && rb_obj_is_instance_of(value, rb_cString)) { VALUE argv[2]; argv[0] = INT2FIX(f->offset); argv[1] = value; rb_funcall2(pointer, rb_intern("put_string"), 2, argv); } else { #ifdef notyet MemoryOp* op; int count = RARRAY_LEN(value); int i; AbstractMemory* memory = MEMORY(pointer); if (count > array->length) { rb_raise(rb_eIndexError, "array too large"); } /* clear the contents in case of a short write */ checkWrite(memory); checkBounds(memory, f->offset, f->type->ffiType->size); if (count < array->length) { memset(memory->address + f->offset + (count * array->componentType->ffiType->size), 0, (array->length - count) * array->componentType->ffiType->size); } /* now copy each element in */ if ((op = get_memory_op(array->componentType)) != NULL) { for (i = 0; i < count; ++i) { (*op->put)(memory, f->offset + (i * array->componentType->ffiType->size), rb_ary_entry(value, i)); } } else if (array->componentType->nativeType == NATIVE_STRUCT) { for (i = 0; i < count; ++i) { VALUE entry = rb_ary_entry(value, i); Struct* s; if (!rb_obj_is_kind_of(entry, rbffi_StructClass)) { rb_raise(rb_eTypeError, "array element not an instance of FFI::Struct"); break; } Data_Get_Struct(entry, Struct, s); checkRead(s->pointer); checkBounds(s->pointer, 0, array->componentType->ffiType->size); memcpy(memory->address + f->offset + (i * array->componentType->ffiType->size), s->pointer->address, array->componentType->ffiType->size); } } else { rb_raise(rb_eNotImpError, "put not supported for arrays of type %s", rb_obj_classname(array->rbComponentType)); } #else rb_raise(rb_eNotImpError, "cannot set array field"); #endif } return value; } static VALUE struct_layout_allocate(VALUE klass) { StructLayout* layout; VALUE obj; obj = Data_Make_Struct(klass, StructLayout, struct_layout_mark, struct_layout_free, layout); layout->rbFieldMap = Qnil; layout->rbFieldNames = Qnil; layout->rbFields = Qnil; layout->fieldSymbolTable = st_init_numtable(); layout->base.ffiType = xcalloc(1, sizeof(*layout->base.ffiType)); layout->base.ffiType->size = 0; layout->base.ffiType->alignment = 0; layout->base.ffiType->type = FFI_TYPE_STRUCT; return obj; } /* * call-seq: initialize(fields, size, align) * @param [Array] fields * @param [Numeric] size * @param [Numeric] align * @return [self] * A new StructLayout instance. */ static VALUE struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align) { StructLayout* layout; ffi_type* ltype; int i; Data_Get_Struct(self, StructLayout, layout); layout->fieldCount = (int) RARRAY_LEN(fields); layout->rbFieldMap = rb_hash_new(); layout->rbFieldNames = rb_ary_new2(layout->fieldCount); layout->size = (int) FFI_ALIGN(NUM2INT(size), NUM2INT(align)); layout->align = NUM2INT(align); layout->fields = xcalloc(layout->fieldCount, sizeof(StructField *)); layout->ffiTypes = xcalloc(layout->fieldCount + 1, sizeof(ffi_type *)); layout->rbFields = rb_ary_new2(layout->fieldCount); layout->referenceFieldCount = 0; layout->base.ffiType->elements = layout->ffiTypes; layout->base.ffiType->size = layout->size; layout->base.ffiType->alignment = layout->align; ltype = layout->base.ffiType; for (i = 0; i < (int) layout->fieldCount; ++i) { VALUE rbField = rb_ary_entry(fields, i); VALUE rbName; StructField* field; ffi_type* ftype; if (!rb_obj_is_kind_of(rbField, rbffi_StructLayoutFieldClass)) { rb_raise(rb_eTypeError, "wrong type for field %d.", i); } rbName = rb_funcall2(rbField, rb_intern("name"), 0, NULL); Data_Get_Struct(rbField, StructField, field); layout->fields[i] = field; if (field->type == NULL || field->type->ffiType == NULL) { rb_raise(rb_eRuntimeError, "type of field %d not supported", i); } ftype = field->type->ffiType; if (ftype->size == 0 && i < ((int) layout->fieldCount - 1)) { rb_raise(rb_eTypeError, "type of field %d has zero size", i); } if (field->referenceRequired) { field->referenceIndex = layout->referenceFieldCount++; } layout->ffiTypes[i] = ftype->size > 0 ? ftype : NULL; st_insert(layout->fieldSymbolTable, rbName, rbField); rb_hash_aset(layout->rbFieldMap, rbName, rbField); rb_ary_push(layout->rbFields, rbField); rb_ary_push(layout->rbFieldNames, rbName); } if (ltype->size == 0) { rb_raise(rb_eRuntimeError, "Struct size is zero"); } return self; } /* * call-seq: [](field) * @param [Symbol] field * @return [StructLayout::Field] * Get a field from the layout. */ static VALUE struct_layout_union_bang(VALUE self) { static const ffi_type *alignment_types[] = { &ffi_type_sint8, &ffi_type_sint16, &ffi_type_sint32, &ffi_type_sint64, &ffi_type_float, &ffi_type_double, &ffi_type_longdouble, NULL }; StructLayout* layout; ffi_type *t = NULL; int count, i; Data_Get_Struct(self, StructLayout, layout); for (i = 0; alignment_types[i] != NULL; ++i) { if (alignment_types[i]->alignment == layout->align) { t = (ffi_type *) alignment_types[i]; break; } } if (t == NULL) { rb_raise(rb_eRuntimeError, "cannot create libffi union representation for alignment %d", layout->align); return Qnil; } count = (int) layout->size / (int) t->size; xfree(layout->ffiTypes); layout->ffiTypes = xcalloc(count + 1, sizeof(ffi_type *)); layout->base.ffiType->elements = layout->ffiTypes; for (i = 0; i < count; ++i) { layout->ffiTypes[i] = t; } return self; } static VALUE struct_layout_aref(VALUE self, VALUE field) { StructLayout* layout; Data_Get_Struct(self, StructLayout, layout); return rb_hash_aref(layout->rbFieldMap, field); } /* * call-seq: fields * @return [Array] * Get fields list. */ static VALUE struct_layout_fields(VALUE self) { StructLayout* layout; Data_Get_Struct(self, StructLayout, layout); return rb_ary_dup(layout->rbFields); } /* * call-seq: members * @return [Array] * Get list of field names. */ static VALUE struct_layout_members(VALUE self) { StructLayout* layout; Data_Get_Struct(self, StructLayout, layout); return rb_ary_dup(layout->rbFieldNames); } /* * call-seq: to_a * @return [Array] * Get an array of fields. */ static VALUE struct_layout_to_a(VALUE self) { StructLayout* layout; Data_Get_Struct(self, StructLayout, layout); return rb_ary_dup(layout->rbFields); } static void struct_layout_mark(StructLayout *layout) { rb_gc_mark(layout->rbFieldMap); rb_gc_mark(layout->rbFieldNames); rb_gc_mark(layout->rbFields); } static void struct_layout_free(StructLayout *layout) { xfree(layout->ffiTypes); xfree(layout->base.ffiType); xfree(layout->fields); st_free_table(layout->fieldSymbolTable); xfree(layout); } void rbffi_StructLayout_Init(VALUE moduleFFI) { VALUE ffi_Type = rbffi_TypeClass; /* * Document-class: FFI::StructLayout < FFI::Type * * This class aims at defining a struct layout. */ rbffi_StructLayoutClass = rb_define_class_under(moduleFFI, "StructLayout", ffi_Type); rb_global_variable(&rbffi_StructLayoutClass); /* * Document-class: FFI::StructLayout::Field * A field in a {StructLayout}. */ rbffi_StructLayoutFieldClass = rb_define_class_under(rbffi_StructLayoutClass, "Field", rb_cObject); rb_global_variable(&rbffi_StructLayoutFieldClass); /* * Document-class: FFI::StructLayout::Number * A numeric {Field} in a {StructLayout}. */ rbffi_StructLayoutNumberFieldClass = rb_define_class_under(rbffi_StructLayoutClass, "Number", rbffi_StructLayoutFieldClass); rb_global_variable(&rbffi_StructLayoutNumberFieldClass); /* * Document-class: FFI::StructLayout::String * A string {Field} in a {StructLayout}. */ rbffi_StructLayoutStringFieldClass = rb_define_class_under(rbffi_StructLayoutClass, "String", rbffi_StructLayoutFieldClass); rb_global_variable(&rbffi_StructLayoutStringFieldClass); /* * Document-class: FFI::StructLayout::Pointer * A pointer {Field} in a {StructLayout}. */ rbffi_StructLayoutPointerFieldClass = rb_define_class_under(rbffi_StructLayoutClass, "Pointer", rbffi_StructLayoutFieldClass); rb_global_variable(&rbffi_StructLayoutPointerFieldClass); /* * Document-class: FFI::StructLayout::Function * A function pointer {Field} in a {StructLayout}. */ rbffi_StructLayoutFunctionFieldClass = rb_define_class_under(rbffi_StructLayoutClass, "Function", rbffi_StructLayoutFieldClass); rb_global_variable(&rbffi_StructLayoutFunctionFieldClass); /* * Document-class: FFI::StructLayout::Array * An array {Field} in a {StructLayout}. */ rbffi_StructLayoutArrayFieldClass = rb_define_class_under(rbffi_StructLayoutClass, "Array", rbffi_StructLayoutFieldClass); rb_global_variable(&rbffi_StructLayoutArrayFieldClass); rb_define_alloc_func(rbffi_StructLayoutFieldClass, struct_field_allocate); rb_define_method(rbffi_StructLayoutFieldClass, "initialize", struct_field_initialize, -1); rb_define_method(rbffi_StructLayoutFieldClass, "offset", struct_field_offset, 0); rb_define_method(rbffi_StructLayoutFieldClass, "size", struct_field_size, 0); rb_define_method(rbffi_StructLayoutFieldClass, "alignment", struct_field_alignment, 0); rb_define_method(rbffi_StructLayoutFieldClass, "name", struct_field_name, 0); rb_define_method(rbffi_StructLayoutFieldClass, "type", struct_field_type, 0); rb_define_method(rbffi_StructLayoutFieldClass, "put", struct_field_put, 2); rb_define_method(rbffi_StructLayoutFieldClass, "get", struct_field_get, 1); rb_define_method(rbffi_StructLayoutFunctionFieldClass, "put", function_field_put, 2); rb_define_method(rbffi_StructLayoutFunctionFieldClass, "get", function_field_get, 1); rb_define_method(rbffi_StructLayoutArrayFieldClass, "get", array_field_get, 1); rb_define_method(rbffi_StructLayoutArrayFieldClass, "put", array_field_put, 2); rb_define_alloc_func(rbffi_StructLayoutClass, struct_layout_allocate); rb_define_method(rbffi_StructLayoutClass, "initialize", struct_layout_initialize, 3); rb_define_method(rbffi_StructLayoutClass, "[]", struct_layout_aref, 1); rb_define_method(rbffi_StructLayoutClass, "fields", struct_layout_fields, 0); rb_define_method(rbffi_StructLayoutClass, "members", struct_layout_members, 0); rb_define_method(rbffi_StructLayoutClass, "to_a", struct_layout_to_a, 0); rb_define_method(rbffi_StructLayoutClass, "__union!", struct_layout_union_bang, 0); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/libffi.darwin.mk0000644000175000017500000000554112261216360022504 0ustar terceiroterceiro# -*- makefile -*- include ${srcdir}/libffi.gnu.mk CCACHE := $(shell type -p ccache) BUILD_DIR := $(shell pwd) INCFLAGS += -I"$(BUILD_DIR)" # Work out which arches we need to compile the lib for ARCHES := ARCHFLAGS ?= $(filter -arch %, $(CFLAGS)) ifneq ($(findstring -arch ppc,$(ARCHFLAGS)),) ARCHES += ppc endif ifneq ($(findstring -arch i386,$(ARCHFLAGS)),) ARCHES += i386 endif ifneq ($(findstring -arch x86_64,$(ARCHFLAGS)),) ARCHES += x86_64 endif ifeq ($(strip $(ARCHES)),) LIBFFI_BUILD_DIR = $(BUILD_DIR)/libffi-$(arch) # Just build the one (default) architecture $(LIBFFI): @mkdir -p "$(LIBFFI_BUILD_DIR)" "$(@D)" @if [ ! -f "$(LIBFFI_BUILD_DIR)"/Makefile ]; then \ echo "Configuring libffi"; \ cd "$(LIBFFI_BUILD_DIR)" && \ /usr/bin/env CC="$(CC)" LD="$(LD)" CFLAGS="$(LIBFFI_CFLAGS)" GREP_OPTIONS="" \ /bin/sh $(LIBFFI_CONFIGURE) $(LIBFFI_HOST) > /dev/null; \ fi cd "$(LIBFFI_BUILD_DIR)" && $(MAKE) else LIBTARGETS = $(foreach arch,$(ARCHES),"$(BUILD_DIR)"/libffi-$(arch)/.libs/libffi_convenience.a) # Build a fat binary and assemble build_ffi = \ mkdir -p "$(BUILD_DIR)"/libffi-$(1); \ (if [ ! -f "$(BUILD_DIR)"/libffi-$(1)/Makefile ]; then \ echo "Configuring libffi for $(1)"; \ cd "$(BUILD_DIR)"/libffi-$(1) && \ env CC="$(CCACHE) $(CC)" CFLAGS="-arch $(1) $(LIBFFI_CFLAGS)" LDFLAGS="-arch $(1)" \ $(LIBFFI_CONFIGURE) --host=$(1)-apple-darwin > /dev/null; \ fi); \ env MACOSX_DEPLOYMENT_TARGET=10.4 $(MAKE) -C "$(BUILD_DIR)"/libffi-$(1) target_ffi = "$(BUILD_DIR)"/libffi-$(1)/.libs/libffi_convenience.a:; $(call build_ffi,$(1)) # Work out which arches we need to compile the lib for ifneq ($(findstring ppc,$(ARCHES)),) $(call target_ffi,ppc) endif ifneq ($(findstring i386,$(ARCHES)),) $(call target_ffi,i386) endif ifneq ($(findstring x86_64,$(ARCHES)),) $(call target_ffi,x86_64) endif $(LIBFFI): $(LIBTARGETS) # Assemble into a FAT (x86_64, i386, ppc) library @mkdir -p "$(@D)" /usr/bin/libtool -static -o $@ \ $(foreach arch, $(ARCHES),"$(BUILD_DIR)"/libffi-$(arch)/.libs/libffi_convenience.a) @mkdir -p "$(LIBFFI_BUILD_DIR)"/include $(RM) "$(LIBFFI_BUILD_DIR)"/include/ffi.h @( \ printf "#if defined(__i386__)\n"; \ printf "#include \"libffi-i386/include/ffi.h\"\n"; \ printf "#elif defined(__x86_64__)\n"; \ printf "#include \"libffi-x86_64/include/ffi.h\"\n";\ printf "#elif defined(__ppc__)\n"; \ printf "#include \"libffi-ppc/include/ffi.h\"\n";\ printf "#endif\n";\ ) > "$(LIBFFI_BUILD_DIR)"/include/ffi.h @( \ printf "#if defined(__i386__)\n"; \ printf "#include \"libffi-i386/include/ffitarget.h\"\n"; \ printf "#elif defined(__x86_64__)\n"; \ printf "#include \"libffi-x86_64/include/ffitarget.h\"\n";\ printf "#elif defined(__ppc__)\n"; \ printf "#include \"libffi-ppc/include/ffitarget.h\"\n";\ printf "#endif\n";\ ) > "$(LIBFFI_BUILD_DIR)"/include/ffitarget.h endif ruby-ffi-1.9.3debian.orig/ext/ffi_c/ArrayType.h0000644000175000017500000000405112261216357021527 0ustar terceiroterceiro/* * Copyright (c) 2009, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_ARRAYTYPE_H #define RBFFI_ARRAYTYPE_H #include #include #include "Type.h" #ifdef __cplusplus extern "C" { #endif typedef struct ArrayType_ { Type base; int length; ffi_type** ffiTypes; Type* componentType; VALUE rbComponentType; } ArrayType; extern void rbffi_ArrayType_Init(VALUE moduleFFI); extern VALUE rbffi_ArrayTypeClass; #ifdef __cplusplus } #endif #endif /* RBFFI_ARRAYTYPE_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/Platform.h0000644000175000017500000000347512261216360021376 0ustar terceiroterceiro/* * Copyright (c) 2008-2010 Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_PLATFORM_H #define RBFFI_PLATFORM_H #ifdef __cplusplus extern "C" { #endif extern void rbffi_Platform_Init(VALUE moduleFFI); #ifdef __cplusplus } #endif #endif /* RBFFI_PLATFORM_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/DataConverter.c0000644000175000017500000000373612261216357022354 0ustar terceiroterceiro #include #include #include "rbffi.h" #include "Type.h" #include "MappedType.h" VALUE rbffi_DataConverterClass = Qnil; static ID id_native_type_ivar; /* * Get native type. * @overload native_type(type) * @param [String, Symbol, Type] type * @return [Type] * Get native type from +type+. * @overload native_type * @raise {NotImplementedError} This method must be overriden. */ static VALUE conv_native_type(int argc, VALUE* argv, VALUE self) { if (argc == 0) { if (!rb_ivar_defined(self, id_native_type_ivar)) { rb_raise(rb_eNotImpError, "native_type method not overridden and no native_type set"); } return rb_ivar_get(self, id_native_type_ivar); } else if (argc == 1) { VALUE type = rbffi_Type_Find(argv[0]); rb_ivar_set(self, id_native_type_ivar, type); return type; } else { rb_raise(rb_eArgError, "incorrect arguments"); } } /* * call-seq: to_native(value, ctx) * @param value * @param ctx * @return [value] * Convert to a native type. */ static VALUE conv_to_native(VALUE self, VALUE value, VALUE ctx) { return value; } /* * call-seq: from_native(value, ctx) * @param value * @param ctx * @return [value] * Convert from a native type. */ static VALUE conv_from_native(VALUE self, VALUE value, VALUE ctx) { return value; } void rbffi_DataConverter_Init(VALUE moduleFFI) { /* * Document-module: FFI::DataConverter * This module is used to extend somes classes and give then a common API. * * Most of methods defined here must be overriden. */ rbffi_DataConverterClass = rb_define_module_under(moduleFFI, "DataConverter"); rb_define_method(rbffi_DataConverterClass, "native_type", conv_native_type, -1); rb_define_method(rbffi_DataConverterClass, "to_native", conv_to_native, 2); rb_define_method(rbffi_DataConverterClass, "from_native", conv_from_native, 2); id_native_type_ivar = rb_intern("@native_type"); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/ClosurePool.c0000644000175000017500000001601012261216357022046 0ustar terceiroterceiro/* * Copyright (c) 2009, 2010 Wayne Meissner * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER #include #endif #include #if defined(__CYGWIN__) || !defined(_WIN32) # include #endif #include #ifndef _MSC_VER # include # include #else # include "win32/stdbool.h" # include "win32/stdint.h" #endif #if defined(__CYGWIN__) || !defined(_WIN32) # include #else # include # define _WINSOCKAPI_ # include #endif #include #include #if defined(_MSC_VER) && !defined(INT8_MIN) # include "win32/stdint.h" #endif #include #include "rbffi.h" #include "compat.h" #include "Function.h" #include "Types.h" #include "Type.h" #include "LastError.h" #include "Call.h" #include "ClosurePool.h" #ifndef roundup # define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) #endif #ifdef _WIN32 typedef char* caddr_t; #endif typedef struct Memory { void* code; void* data; struct Memory* next; } Memory; struct ClosurePool_ { void* ctx; int closureSize; bool (*prep)(void* ctx, void *code, Closure* closure, char* errbuf, size_t errbufsize); struct Memory* blocks; /* Keeps track of all the allocated memory for this pool */ Closure* list; long refcnt; }; static long pageSize; static void* allocatePage(void); static bool freePage(void *); static bool protectPage(void *); ClosurePool* rbffi_ClosurePool_New(int closureSize, bool (*prep)(void* ctx, void *code, Closure* closure, char* errbuf, size_t errbufsize), void* ctx) { ClosurePool* pool; pool = xcalloc(1, sizeof(*pool)); pool->closureSize = closureSize; pool->ctx = ctx; pool->prep = prep; pool->refcnt = 1; return pool; } void cleanup_closure_pool(ClosurePool* pool) { Memory* memory; for (memory = pool->blocks; memory != NULL; ) { Memory* next = memory->next; freePage(memory->code); free(memory->data); free(memory); memory = next; } xfree(pool); } void rbffi_ClosurePool_Free(ClosurePool* pool) { if (pool != NULL) { long refcnt = --(pool->refcnt); if (refcnt == 0) { cleanup_closure_pool(pool); } } } Closure* rbffi_Closure_Alloc(ClosurePool* pool) { Closure *list = NULL; Memory* block = NULL; caddr_t code = NULL; char errmsg[256]; int nclosures; long trampolineSize; int i; if (pool->list != NULL) { Closure* closure = pool->list; pool->list = pool->list->next; pool->refcnt++; return closure; } trampolineSize = roundup(pool->closureSize, 8); nclosures = (int) (pageSize / trampolineSize); block = calloc(1, sizeof(*block)); list = calloc(nclosures, sizeof(*list)); code = allocatePage(); if (block == NULL || list == NULL || code == NULL) { snprintf(errmsg, sizeof(errmsg), "failed to allocate a page. errno=%d (%s)", errno, strerror(errno)); goto error; } for (i = 0; i < nclosures; ++i) { Closure* closure = &list[i]; closure->next = &list[i + 1]; closure->pool = pool; closure->code = (code + (i * trampolineSize)); if (!(*pool->prep)(pool->ctx, closure->code, closure, errmsg, sizeof(errmsg))) { goto error; } } if (!protectPage(code)) { goto error; } /* Track the allocated page + Closure memory area */ block->data = list; block->code = code; block->next = pool->blocks; pool->blocks = block; /* Thread the new block onto the free list, apart from the first one. */ list[nclosures - 1].next = pool->list; pool->list = list->next; pool->refcnt++; /* Use the first one as the new handle */ return list; error: free(block); free(list); if (code != NULL) { freePage(code); } rb_raise(rb_eRuntimeError, "%s", errmsg); return NULL; } void rbffi_Closure_Free(Closure* closure) { if (closure != NULL) { ClosurePool* pool = closure->pool; long refcnt; /* Just push it on the front of the free list */ closure->next = pool->list; pool->list = closure; refcnt = --(pool->refcnt); if (refcnt == 0) { cleanup_closure_pool(pool); } } } void* rbffi_Closure_CodeAddress(Closure* handle) { return handle->code; } static long getPageSize() { #if !defined(__CYGWIN__) && (defined(_WIN32) || defined(__WIN32__)) SYSTEM_INFO si; GetSystemInfo(&si); return si.dwPageSize; #else return sysconf(_SC_PAGESIZE); #endif } static void* allocatePage(void) { #if !defined(__CYGWIN__) && (defined(_WIN32) || defined(__WIN32__)) return VirtualAlloc(NULL, pageSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); #else caddr_t page = mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); return (page != (caddr_t) -1) ? page : NULL; #endif } static bool freePage(void *addr) { #if !defined(__CYGWIN__) && (defined(_WIN32) || defined(__WIN32__)) return VirtualFree(addr, 0, MEM_RELEASE); #else return munmap(addr, pageSize) == 0; #endif } static bool protectPage(void* page) { #if !defined(__CYGWIN__) && (defined(_WIN32) || defined(__WIN32__)) DWORD oldProtect; return VirtualProtect(page, pageSize, PAGE_EXECUTE_READ, &oldProtect); #else return mprotect(page, pageSize, PROT_READ | PROT_EXEC) == 0; #endif } void rbffi_ClosurePool_Init(VALUE module) { pageSize = getPageSize(); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/Platform.c0000644000175000017500000001003412261216360021356 0ustar terceiroterceiro/* * Copyright (c) 2008-2010 Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER # include #endif # include #ifndef _MSC_VER # include # include #else # include "win32/stdint.h" # include "win32/stdbool.h" #endif #include #include #include "rbffi_endian.h" #include "Platform.h" #if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) # include #endif static VALUE PlatformModule = Qnil; /* * Determine the cpu type at compile time - useful for MacOSX where the the * system installed ruby incorrectly reports 'host_cpu' as 'powerpc' when running * on intel. */ #if defined(__x86_64__) || defined(__x86_64) || defined(__amd64) || defined(_M_X64) || defined(_M_AMD64) # define CPU "x86_64" #elif defined(__i386__) || defined(__i386) || defined(_M_IX86) # define CPU "i386" #elif defined(__ppc64__) || defined(__powerpc64__) || defined(_M_PPC) # define CPU "ppc64" #elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc) # define CPU "ppc" /* Need to check for __sparcv9 first, because __sparc will be defined either way. */ #elif defined(__sparcv9__) || defined(__sparcv9) # define CPU "sparcv9" #elif defined(__sparc__) || defined(__sparc) # define CPU "sparc" #elif defined(__arm__) || defined(__arm) # define CPU "arm" #elif defined(__mips__) || defined(__mips) # define CPU "mips" #elif defined(__s390__) # define CPU "s390" #else # define CPU "unknown" #endif static void export_primitive_types(VALUE module) { #define S(name, T) do { \ typedef struct { char c; T v; } s; \ rb_define_const(module, #name "_ALIGN", INT2NUM((sizeof(s) - sizeof(T)) * 8)); \ rb_define_const(module, #name "_SIZE", INT2NUM(sizeof(T)* 8)); \ } while(0) S(INT8, char); S(INT16, short); S(INT32, int); S(INT64, long long); S(LONG, long); S(FLOAT, float); S(DOUBLE, double); S(ADDRESS, void*); #undef S } void rbffi_Platform_Init(VALUE moduleFFI) { PlatformModule = rb_define_module_under(moduleFFI, "Platform"); rb_define_const(PlatformModule, "BYTE_ORDER", INT2FIX(BYTE_ORDER)); rb_define_const(PlatformModule, "LITTLE_ENDIAN", INT2FIX(LITTLE_ENDIAN)); rb_define_const(PlatformModule, "BIG_ENDIAN", INT2FIX(BIG_ENDIAN)); rb_define_const(PlatformModule, "CPU", rb_str_new2(CPU)); #if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) rb_define_const(PlatformModule, "GNU_LIBC", rb_str_new2(LIBC_SO)); #endif export_primitive_types(PlatformModule); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/LastError.c0000644000175000017500000001047112261216357021522 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * Copyright (C) 2009 Aman Gupta * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER # include #endif #include #include #ifndef _MSC_VER # include # include #else # include "win32/stdbool.h" #endif #include #include #include "LastError.h" #if defined(HAVE_NATIVETHREAD) && !defined(_WIN32) && !defined(__WIN32__) # include # define USE_PTHREAD_LOCAL #endif typedef struct ThreadData { int td_errno; } ThreadData; #if defined(USE_PTHREAD_LOCAL) static pthread_key_t threadDataKey; #endif static inline ThreadData* thread_data_get(void); #if defined(USE_PTHREAD_LOCAL) static ThreadData* thread_data_init(void) { ThreadData* td = xcalloc(1, sizeof(ThreadData)); pthread_setspecific(threadDataKey, td); return td; } static inline ThreadData* thread_data_get(void) { ThreadData* td = pthread_getspecific(threadDataKey); return td != NULL ? td : thread_data_init(); } static void thread_data_free(void *ptr) { xfree(ptr); } #else static ID id_thread_data; static ThreadData* thread_data_init(void) { ThreadData* td; VALUE obj; obj = Data_Make_Struct(rb_cObject, ThreadData, NULL, -1, td); rb_thread_local_aset(rb_thread_current(), id_thread_data, obj); return td; } static inline ThreadData* thread_data_get() { VALUE obj = rb_thread_local_aref(rb_thread_current(), id_thread_data); if (obj != Qnil && TYPE(obj) == T_DATA) { return (ThreadData *) DATA_PTR(obj); } return thread_data_init(); } #endif /* * call-seq: error * @return [Numeric] * Get +errno+ value. */ static VALUE get_last_error(VALUE self) { return INT2NUM(thread_data_get()->td_errno); } /* * call-seq: error(error) * @param [Numeric] error * @return [nil] * Set +errno+ value. */ static VALUE set_last_error(VALUE self, VALUE error) { #ifdef _WIN32 SetLastError(NUM2INT(error)); #else errno = NUM2INT(error); #endif return Qnil; } void rbffi_save_errno(void) { int error = 0; #ifdef _WIN32 error = GetLastError(); #else error = errno; #endif thread_data_get()->td_errno = error; } void rbffi_LastError_Init(VALUE moduleFFI) { /* * Document-module: FFI::LastError * This module defines a couple of method to set and get +errno+ * for current thread. */ VALUE moduleError = rb_define_module_under(moduleFFI, "LastError"); rb_define_module_function(moduleError, "error", get_last_error, 0); rb_define_module_function(moduleError, "error=", set_last_error, 1); #if defined(USE_PTHREAD_LOCAL) pthread_key_create(&threadDataKey, thread_data_free); #else id_thread_data = rb_intern("ffi_thread_local_data"); #endif /* USE_PTHREAD_LOCAL */ } ruby-ffi-1.9.3debian.orig/ext/ffi_c/rbffi_endian.h0000644000175000017500000000254612261216360022216 0ustar terceiroterceiro#ifndef JFFI_ENDIAN_H #define JFFI_ENDIAN_H #ifndef _MSC_VER #include #endif #include #if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__) || defined(__GLIBC__) # include # if !defined(LITTLE_ENDIAN) && defined(__LITTLE_ENDIAN) # define LITTLE_ENDIAN __LITTLE_ENDIAN # endif # if !defined(BIG_ENDIAN) && defined(__BIG_ENDIAN) # define BIG_ENDIAN __BIG_ENDIAN # endif # if !defined(BYTE_ORDER) && defined(__BYTE_ORDER) # define BYTE_ORDER __BYTE_ORDER # endif #endif #ifdef __sun # include # define LITTLE_ENDIAN 1234 # define BIG_ENDIAN 4321 # if defined(_BIG_ENDIAN) # define BYTE_ORDER BIG_ENDIAN # elif defined(_LITTLE_ENDIAN) # define BYTE_ORDER LITTLE_ENDIAN # else # error "Cannot determine endian-ness" # endif #endif #if defined(_AIX) && !defined(BYTE_ORDER) # define LITTLE_ENDIAN 1234 # define BIG_ENDIAN 4321 # if defined(__BIG_ENDIAN__) # define BYTE_ORDER BIG_ENDIAN # elif defined(__LITTLE_ENDIAN__) # define BYTE_ORDER LITTLE_ENDIAN # else # error "Cannot determine endian-ness" # endif #endif #if defined(_WIN32) # define LITTLE_ENDIAN 1234 # define BIG_ENDIAN 4321 # define BYTE_ORDER LITTLE_ENDIAN #endif #if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN) # error "Cannot determine the endian-ness of this platform" #endif #endif /* JFFI_ENDIAN_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/ffi.c0000644000175000017500000000647312261216357020360 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * Copyright (C) 2009 Luc Heinrich * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include "rbffi.h" #include "AbstractMemory.h" #include "Pointer.h" #include "MemoryPointer.h" #include "Struct.h" #include "StructByValue.h" #include "StructByReference.h" #include "DynamicLibrary.h" #include "Platform.h" #include "Types.h" #include "LastError.h" #include "Function.h" #include "ClosurePool.h" #include "MethodHandle.h" #include "Call.h" #include "ArrayType.h" #include "MappedType.h" void Init_ffi_c(void); VALUE rbffi_FFIModule = Qnil; static VALUE moduleFFI = Qnil; void Init_ffi_c(void) { /* * Document-module: FFI * * This module embbed type constants from {FFI::NativeType}. */ rbffi_FFIModule = moduleFFI = rb_define_module("FFI"); rb_global_variable(&rbffi_FFIModule); rbffi_Thread_Init(rbffi_FFIModule); /* FFI::Type needs to be initialized before most other classes */ rbffi_Type_Init(moduleFFI); rbffi_DataConverter_Init(moduleFFI); rbffi_ArrayType_Init(moduleFFI); rbffi_LastError_Init(moduleFFI); rbffi_Call_Init(moduleFFI); rbffi_ClosurePool_Init(moduleFFI); rbffi_MethodHandle_Init(moduleFFI); rbffi_Platform_Init(moduleFFI); rbffi_AbstractMemory_Init(moduleFFI); rbffi_Pointer_Init(moduleFFI); rbffi_Function_Init(moduleFFI); rbffi_MemoryPointer_Init(moduleFFI); rbffi_Buffer_Init(moduleFFI); rbffi_StructByValue_Init(moduleFFI); rbffi_StructByReference_Init(moduleFFI); rbffi_Struct_Init(moduleFFI); rbffi_DynamicLibrary_Init(moduleFFI); rbffi_Variadic_Init(moduleFFI); rbffi_Types_Init(moduleFFI); rbffi_MappedType_Init(moduleFFI); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/LastError.h0000644000175000017500000000352612261216357021532 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_LASTERROR_H #define RBFFI_LASTERROR_H #ifdef __cplusplus extern "C" { #endif void rbffi_LastError_Init(VALUE moduleFFI); void rbffi_save_errno(void); #ifdef __cplusplus } #endif #endif /* RBFFI_LASTERROR_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/Pointer.h0000644000175000017500000000431612261216360021225 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_POINTER_H #define RBFFI_POINTER_H #ifndef _MSC_VER # include #else # include "win32/stdbool.h" #endif #ifdef __cplusplus extern "C" { #endif #include "AbstractMemory.h" extern void rbffi_Pointer_Init(VALUE moduleFFI); extern VALUE rbffi_Pointer_NewInstance(void* addr); extern VALUE rbffi_PointerClass; extern VALUE rbffi_NullPointerSingleton; typedef struct Pointer { AbstractMemory memory; VALUE rbParent; char* storage; /* start of malloc area */ bool autorelease; bool allocated; } Pointer; #ifdef __cplusplus } #endif #endif /* RBFFI_POINTER_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/Pointer.c0000644000175000017500000003350512261216360021222 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER # include # include #else # include "win32/stdint.h" # include "win32/stdbool.h" #endif #include #include #include "rbffi.h" #include "rbffi_endian.h" #include "AbstractMemory.h" #include "Pointer.h" #define POINTER(obj) rbffi_AbstractMemory_Cast((obj), rbffi_PointerClass) VALUE rbffi_PointerClass = Qnil; VALUE rbffi_NullPointerSingleton = Qnil; static void ptr_release(Pointer* ptr); static void ptr_mark(Pointer* ptr); VALUE rbffi_Pointer_NewInstance(void* addr) { Pointer* p; VALUE obj; if (addr == NULL) { return rbffi_NullPointerSingleton; } obj = Data_Make_Struct(rbffi_PointerClass, Pointer, NULL, -1, p); p->memory.address = addr; p->memory.size = LONG_MAX; p->memory.flags = (addr == NULL) ? 0 : (MEM_RD | MEM_WR); p->memory.typeSize = 1; p->rbParent = Qnil; return obj; } static VALUE ptr_allocate(VALUE klass) { Pointer* p; VALUE obj; obj = Data_Make_Struct(klass, Pointer, ptr_mark, ptr_release, p); p->rbParent = Qnil; p->memory.flags = MEM_RD | MEM_WR; return obj; } /* * @overload initialize(pointer) * @param [Pointer] pointer another pointer to initialize from * Create a new pointer from another {Pointer}. * @overload initialize(type, address) * @param [Type] type type for pointer * @param [Integer] address base address for pointer * Create a new pointer from a {Type} and a base adresse * @return [self] * A new instance of Pointer. */ static VALUE ptr_initialize(int argc, VALUE* argv, VALUE self) { Pointer* p; VALUE rbType = Qnil, rbAddress = Qnil; int typeSize = 1; Data_Get_Struct(self, Pointer, p); switch (rb_scan_args(argc, argv, "11", &rbType, &rbAddress)) { case 1: rbAddress = rbType; typeSize = 1; break; case 2: typeSize = rbffi_type_size(rbType); break; default: rb_raise(rb_eArgError, "Invalid arguments"); } switch (TYPE(rbAddress)) { case T_FIXNUM: case T_BIGNUM: p->memory.address = (void*) (uintptr_t) NUM2LL(rbAddress); p->memory.size = LONG_MAX; if (p->memory.address == NULL) { p->memory.flags = 0; } break; default: if (rb_obj_is_kind_of(rbAddress, rbffi_PointerClass)) { Pointer* orig; p->rbParent = rbAddress; Data_Get_Struct(rbAddress, Pointer, orig); p->memory = orig->memory; } else { rb_raise(rb_eTypeError, "wrong argument type, expected Integer or FFI::Pointer"); } break; } p->memory.typeSize = typeSize; return self; } /* * call-seq: ptr.initialize_copy(other) * @param [Pointer] other source for cloning or dupping * @return [self] * @raise {RuntimeError} if +other+ is an unbounded memory area, or is unreable/unwritable * @raise {NoMemError} if failed to allocate memory for new object * DO NOT CALL THIS METHOD. * * This method is internally used by #dup and #clone. Memory contents is copied from +other+. */ static VALUE ptr_initialize_copy(VALUE self, VALUE other) { AbstractMemory* src; Pointer* dst; Data_Get_Struct(self, Pointer, dst); src = POINTER(other); if (src->size == LONG_MAX) { rb_raise(rb_eRuntimeError, "cannot duplicate unbounded memory area"); return Qnil; } if ((dst->memory.flags & (MEM_RD | MEM_WR)) != (MEM_RD | MEM_WR)) { rb_raise(rb_eRuntimeError, "cannot duplicate unreadable/unwritable memory area"); return Qnil; } if (dst->storage != NULL) { xfree(dst->storage); dst->storage = NULL; } dst->storage = xmalloc(src->size + 7); if (dst->storage == NULL) { rb_raise(rb_eNoMemError, "failed to allocate memory size=%lu bytes", src->size); return Qnil; } dst->allocated = true; dst->autorelease = true; dst->memory.address = (void *) (((uintptr_t) dst->storage + 0x7) & (uintptr_t) ~0x7UL); dst->memory.size = src->size; dst->memory.typeSize = src->typeSize; /* finally, copy the actual memory contents */ memcpy(dst->memory.address, src->address, src->size); return self; } static VALUE slice(VALUE self, long offset, long size) { AbstractMemory* ptr; Pointer* p; VALUE retval; Data_Get_Struct(self, AbstractMemory, ptr); checkBounds(ptr, offset, size == LONG_MAX ? 1 : size); retval = Data_Make_Struct(rbffi_PointerClass, Pointer, ptr_mark, -1, p); p->memory.address = ptr->address + offset; p->memory.size = size; p->memory.flags = ptr->flags; p->memory.typeSize = ptr->typeSize; p->rbParent = self; return retval; } /* * Document-method: + * call-seq: ptr + offset * @param [Numeric] offset * @return [Pointer] * Return a new {Pointer} from an existing pointer and an +offset+. */ static VALUE ptr_plus(VALUE self, VALUE offset) { AbstractMemory* ptr; long off = NUM2LONG(offset); Data_Get_Struct(self, AbstractMemory, ptr); return slice(self, off, ptr->size == LONG_MAX ? LONG_MAX : ptr->size - off); } /* * call-seq: ptr.slice(offset, length) * @param [Numeric] offset * @param [Numeric] length * @return [Pointer] * Return a new {Pointer} from an existing one. This pointer points on same contents * from +offset+ for a length +length+. */ static VALUE ptr_slice(VALUE self, VALUE rbOffset, VALUE rbLength) { return slice(self, NUM2LONG(rbOffset), NUM2LONG(rbLength)); } /* * call-seq: ptr.inspect * @return [String] * Inspect pointer object. */ static VALUE ptr_inspect(VALUE self) { char buf[100]; Pointer* ptr; Data_Get_Struct(self, Pointer, ptr); if (ptr->memory.size != LONG_MAX) { snprintf(buf, sizeof(buf), "#<%s address=%p size=%lu>", rb_obj_classname(self), ptr->memory.address, ptr->memory.size); } else { snprintf(buf, sizeof(buf), "#<%s address=%p>", rb_obj_classname(self), ptr->memory.address); } return rb_str_new2(buf); } /* * Document-method: null? * call-seq: ptr.null? * @return [Boolean] * Return +true+ if +self+ is a {NULL} pointer. */ static VALUE ptr_null_p(VALUE self) { Pointer* ptr; Data_Get_Struct(self, Pointer, ptr); return ptr->memory.address == NULL ? Qtrue : Qfalse; } /* * Document-method: == * call-seq: ptr == other * @param [Pointer] other * Check equality between +self+ and +other+. Equality is tested on {#address}. */ static VALUE ptr_equals(VALUE self, VALUE other) { Pointer* ptr; Data_Get_Struct(self, Pointer, ptr); if (NIL_P(other)) { return ptr->memory.address == NULL ? Qtrue : Qfalse; } return ptr->memory.address == POINTER(other)->address ? Qtrue : Qfalse; } /* * call-seq: ptr.address * @return [Numeric] pointer's base address * Return +self+'s base address (alias: #to_i). */ static VALUE ptr_address(VALUE self) { Pointer* ptr; Data_Get_Struct(self, Pointer, ptr); return ULL2NUM((uintptr_t) ptr->memory.address); } #if BYTE_ORDER == LITTLE_ENDIAN # define SWAPPED_ORDER BIG_ENDIAN #else # define SWAPPED_ORDER LITTLE_ENDIAN #endif /* * Get or set +self+'s endianness * @overload order * @return [:big, :little] endianness of +self+ * @overload order(order) * @param [Symbol] order endianness to set (+:little+, +:big+ or +:network+). +:big+ and +:network+ * are synonymous. * @return [self] */ static VALUE ptr_order(int argc, VALUE* argv, VALUE self) { Pointer* ptr; Data_Get_Struct(self, Pointer, ptr); if (argc == 0) { int order = (ptr->memory.flags & MEM_SWAP) == 0 ? BYTE_ORDER : SWAPPED_ORDER; return order == BIG_ENDIAN ? ID2SYM(rb_intern("big")) : ID2SYM(rb_intern("little")); } else { VALUE rbOrder = Qnil; int order = BYTE_ORDER; if (rb_scan_args(argc, argv, "1", &rbOrder) < 1) { rb_raise(rb_eArgError, "need byte order"); } if (SYMBOL_P(rbOrder)) { ID id = SYM2ID(rbOrder); if (id == rb_intern("little")) { order = LITTLE_ENDIAN; } else if (id == rb_intern("big") || id == rb_intern("network")) { order = BIG_ENDIAN; } } if (order != BYTE_ORDER) { Pointer* p2; VALUE retval = slice(self, 0, ptr->memory.size); Data_Get_Struct(retval, Pointer, p2); p2->memory.flags |= MEM_SWAP; return retval; } return self; } } /* * call-seq: ptr.free * @return [self] * Free memory pointed by +self+. */ static VALUE ptr_free(VALUE self) { Pointer* ptr; Data_Get_Struct(self, Pointer, ptr); if (ptr->allocated) { if (ptr->storage != NULL) { xfree(ptr->storage); ptr->storage = NULL; } ptr->allocated = false; } else { VALUE caller = rb_funcall(rb_funcall(Qnil, rb_intern("caller"), 0), rb_intern("first"), 0); rb_warn("calling free on non allocated pointer %s from %s", RSTRING_PTR(ptr_inspect(self)), RSTRING_PTR(rb_str_to_str(caller))); } return self; } static VALUE ptr_type_size(VALUE self) { Pointer* ptr; Data_Get_Struct(self, Pointer, ptr); return INT2NUM(ptr->memory.typeSize); } /* * call-seq: ptr.autorelease = autorelease * @param [Boolean] autorelease * @return [Boolean] +autorelease+ * Set +autorelease+ attribute. See also Autorelease section. */ static VALUE ptr_autorelease(VALUE self, VALUE autorelease) { Pointer* ptr; Data_Get_Struct(self, Pointer, ptr); ptr->autorelease = autorelease == Qtrue; return autorelease; } /* * call-seq: ptr.autorelease? * @return [Boolean] * Get +autorelease+ attribute. See also Autorelease section. */ static VALUE ptr_autorelease_p(VALUE self) { Pointer* ptr; Data_Get_Struct(self, Pointer, ptr); return ptr->autorelease ? Qtrue : Qfalse; } static void ptr_release(Pointer* ptr) { if (ptr->autorelease && ptr->allocated && ptr->storage != NULL) { xfree(ptr->storage); ptr->storage = NULL; } xfree(ptr); } static void ptr_mark(Pointer* ptr) { rb_gc_mark(ptr->rbParent); } void rbffi_Pointer_Init(VALUE moduleFFI) { VALUE rbNullAddress = ULL2NUM(0); VALUE ffi_AbstractMemory = rbffi_AbstractMemoryClass; /* * Document-class: FFI::Pointer < FFI::AbstractMemory * Pointer class is used to manage C pointers with ease. A {Pointer} object is defined by his * {#address} (as a C pointer). It permits additions with an integer for pointer arithmetic. * * ==Autorelease * A pointer object may autorelease his contents when freed (by default). This behaviour may be * changed with {#autorelease=} method. */ rbffi_PointerClass = rb_define_class_under(moduleFFI, "Pointer", ffi_AbstractMemory); /* * Document-variable: Pointer */ rb_global_variable(&rbffi_PointerClass); rb_define_alloc_func(rbffi_PointerClass, ptr_allocate); rb_define_method(rbffi_PointerClass, "initialize", ptr_initialize, -1); rb_define_method(rbffi_PointerClass, "initialize_copy", ptr_initialize_copy, 1); rb_define_method(rbffi_PointerClass, "inspect", ptr_inspect, 0); rb_define_method(rbffi_PointerClass, "to_s", ptr_inspect, 0); rb_define_method(rbffi_PointerClass, "+", ptr_plus, 1); rb_define_method(rbffi_PointerClass, "slice", ptr_slice, 2); rb_define_method(rbffi_PointerClass, "null?", ptr_null_p, 0); rb_define_method(rbffi_PointerClass, "address", ptr_address, 0); rb_define_alias(rbffi_PointerClass, "to_i", "address"); rb_define_method(rbffi_PointerClass, "==", ptr_equals, 1); rb_define_method(rbffi_PointerClass, "order", ptr_order, -1); rb_define_method(rbffi_PointerClass, "autorelease=", ptr_autorelease, 1); rb_define_method(rbffi_PointerClass, "autorelease?", ptr_autorelease_p, 0); rb_define_method(rbffi_PointerClass, "free", ptr_free, 0); rb_define_method(rbffi_PointerClass, "type_size", ptr_type_size, 0); rbffi_NullPointerSingleton = rb_class_new_instance(1, &rbNullAddress, rbffi_PointerClass); /* * NULL pointer */ rb_define_const(rbffi_PointerClass, "NULL", rbffi_NullPointerSingleton); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/Buffer.c0000644000175000017500000002544512261216357021025 0ustar terceiroterceiro/* * Copyright (c) 2008-2010 Wayne Meissner * Copyright (C) 2009 Aman Gupta * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER # include # include #else # include "win32/stdbool.h" # include "win32/stdint.h" #endif #include #include #include "rbffi.h" #include "rbffi_endian.h" #include "AbstractMemory.h" #define BUFFER_EMBED_MAXLEN (8) typedef struct Buffer { AbstractMemory memory; union { VALUE rbParent; /* link to parent buffer */ char* storage; /* start of malloc area */ long embed[BUFFER_EMBED_MAXLEN / sizeof(long)]; /* storage for tiny allocations */ } data; } Buffer; static VALUE buffer_allocate(VALUE klass); static VALUE buffer_initialize(int argc, VALUE* argv, VALUE self); static void buffer_release(Buffer* ptr); static void buffer_mark(Buffer* ptr); static VALUE buffer_free(VALUE self); static VALUE BufferClass = Qnil; static VALUE buffer_allocate(VALUE klass) { Buffer* buffer; VALUE obj; obj = Data_Make_Struct(klass, Buffer, NULL, buffer_release, buffer); buffer->data.rbParent = Qnil; buffer->memory.flags = MEM_RD | MEM_WR; return obj; } static void buffer_release(Buffer* ptr) { if ((ptr->memory.flags & MEM_EMBED) == 0 && ptr->data.storage != NULL) { xfree(ptr->data.storage); ptr->data.storage = NULL; } xfree(ptr); } /* * call-seq: initialize(size, count=1, clear=false) * @param [Integer, Symbol, #size] Type or size in bytes of a buffer cell * @param [Fixnum] count number of cell in the Buffer * @param [Boolean] clear if true, set the buffer to all-zero * @return [self] * @raise {NoMemoryError} if failed to allocate memory for Buffer * A new instance of Buffer. */ static VALUE buffer_initialize(int argc, VALUE* argv, VALUE self) { VALUE rbSize = Qnil, rbCount = Qnil, rbClear = Qnil; Buffer* p; int nargs; Data_Get_Struct(self, Buffer, p); nargs = rb_scan_args(argc, argv, "12", &rbSize, &rbCount, &rbClear); p->memory.typeSize = rbffi_type_size(rbSize); p->memory.size = p->memory.typeSize * (nargs > 1 ? NUM2LONG(rbCount) : 1); if (p->memory.size > BUFFER_EMBED_MAXLEN) { p->data.storage = xmalloc(p->memory.size + 7); if (p->data.storage == NULL) { rb_raise(rb_eNoMemError, "Failed to allocate memory size=%lu bytes", p->memory.size); return Qnil; } /* ensure the memory is aligned on at least a 8 byte boundary */ p->memory.address = (void *) (((uintptr_t) p->data.storage + 0x7) & (uintptr_t) ~0x7UL); if (p->memory.size > 0 && (nargs < 3 || RTEST(rbClear))) { memset(p->memory.address, 0, p->memory.size); } } else { p->memory.flags |= MEM_EMBED; p->memory.address = (void *) &p->data.embed[0]; } if (rb_block_given_p()) { return rb_ensure(rb_yield, self, buffer_free, self); } return self; } /* * call-seq: initialize_copy(other) * @return [self] * DO NOT CALL THIS METHOD. */ static VALUE buffer_initialize_copy(VALUE self, VALUE other) { AbstractMemory* src; Buffer* dst; Data_Get_Struct(self, Buffer, dst); src = rbffi_AbstractMemory_Cast(other, BufferClass); if ((dst->memory.flags & MEM_EMBED) == 0 && dst->data.storage != NULL) { xfree(dst->data.storage); } dst->data.storage = xmalloc(src->size + 7); if (dst->data.storage == NULL) { rb_raise(rb_eNoMemError, "failed to allocate memory size=%lu bytes", src->size); return Qnil; } dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~0x7UL); dst->memory.size = src->size; dst->memory.typeSize = src->typeSize; /* finally, copy the actual buffer contents */ memcpy(dst->memory.address, src->address, src->size); return self; } static VALUE buffer_alloc_inout(int argc, VALUE* argv, VALUE klass) { return buffer_initialize(argc, argv, buffer_allocate(klass)); } static VALUE slice(VALUE self, long offset, long len) { Buffer* ptr; Buffer* result; VALUE obj = Qnil; Data_Get_Struct(self, Buffer, ptr); checkBounds(&ptr->memory, offset, len); obj = Data_Make_Struct(BufferClass, Buffer, buffer_mark, -1, result); result->memory.address = ptr->memory.address + offset; result->memory.size = len; result->memory.flags = ptr->memory.flags; result->memory.typeSize = ptr->memory.typeSize; result->data.rbParent = self; return obj; } /* * call-seq: + offset * @param [Numeric] offset * @return [Buffer] a new instance of Buffer pointing from offset until end of previous buffer. * Add a Buffer with an offset */ static VALUE buffer_plus(VALUE self, VALUE rbOffset) { Buffer* ptr; long offset = NUM2LONG(rbOffset); Data_Get_Struct(self, Buffer, ptr); return slice(self, offset, ptr->memory.size - offset); } /* * call-seq: slice(offset, length) * @param [Numeric] offset * @param [Numeric] length * @return [Buffer] a new instance of Buffer * Slice an existing Buffer. */ static VALUE buffer_slice(VALUE self, VALUE rbOffset, VALUE rbLength) { return slice(self, NUM2LONG(rbOffset), NUM2LONG(rbLength)); } /* * call-seq: inspect * @return [String] * Inspect a Buffer. */ static VALUE buffer_inspect(VALUE self) { char tmp[100]; Buffer* ptr; Data_Get_Struct(self, Buffer, ptr); snprintf(tmp, sizeof(tmp), "#", ptr, ptr->memory.address, ptr->memory.size); return rb_str_new2(tmp); } #if BYTE_ORDER == LITTLE_ENDIAN # define SWAPPED_ORDER BIG_ENDIAN #else # define SWAPPED_ORDER LITTLE_ENDIAN #endif /* * Set or get endianness of Buffer. * @overload order * @return [:big, :little] * Get endianness of Buffer. * @overload order(order) * @param [:big, :little, :network] order * @return [self] * Set endinaness of Buffer (+:network+ is an alias for +:big+). */ static VALUE buffer_order(int argc, VALUE* argv, VALUE self) { Buffer* ptr; Data_Get_Struct(self, Buffer, ptr); if (argc == 0) { int order = (ptr->memory.flags & MEM_SWAP) == 0 ? BYTE_ORDER : SWAPPED_ORDER; return order == BIG_ENDIAN ? ID2SYM(rb_intern("big")) : ID2SYM(rb_intern("little")); } else { VALUE rbOrder = Qnil; int order = BYTE_ORDER; if (rb_scan_args(argc, argv, "1", &rbOrder) < 1) { rb_raise(rb_eArgError, "need byte order"); } if (SYMBOL_P(rbOrder)) { ID id = SYM2ID(rbOrder); if (id == rb_intern("little")) { order = LITTLE_ENDIAN; } else if (id == rb_intern("big") || id == rb_intern("network")) { order = BIG_ENDIAN; } } if (order != BYTE_ORDER) { Buffer* p2; VALUE retval = slice(self, 0, ptr->memory.size); Data_Get_Struct(retval, Buffer, p2); p2->memory.flags |= MEM_SWAP; return retval; } return self; } } /* Only used to free the buffer if the yield in the initializer throws an exception */ static VALUE buffer_free(VALUE self) { Buffer* ptr; Data_Get_Struct(self, Buffer, ptr); if ((ptr->memory.flags & MEM_EMBED) == 0 && ptr->data.storage != NULL) { xfree(ptr->data.storage); ptr->data.storage = NULL; } return self; } static void buffer_mark(Buffer* ptr) { rb_gc_mark(ptr->data.rbParent); } void rbffi_Buffer_Init(VALUE moduleFFI) { VALUE ffi_AbstractMemory = rbffi_AbstractMemoryClass; /* * Document-class: FFI::Buffer < FFI::AbstractMemory * * A Buffer is a function argument type. It should be use with functions playing with C arrays. */ BufferClass = rb_define_class_under(moduleFFI, "Buffer", ffi_AbstractMemory); /* * Document-variable: FFI::Buffer */ rb_global_variable(&BufferClass); rb_define_alloc_func(BufferClass, buffer_allocate); /* * Document-method: alloc_inout * call-seq: alloc_inout(*args) * Create a new Buffer for in and out arguments (alias : new_inout). */ rb_define_singleton_method(BufferClass, "alloc_inout", buffer_alloc_inout, -1); /* * Document-method: alloc_out * call-seq: alloc_out(*args) * Create a new Buffer for out arguments (alias : new_out). */ rb_define_singleton_method(BufferClass, "alloc_out", buffer_alloc_inout, -1); /* * Document-method: alloc_in * call-seq: alloc_in(*args) * Create a new Buffer for in arguments (alias : new_in). */ rb_define_singleton_method(BufferClass, "alloc_in", buffer_alloc_inout, -1); rb_define_alias(rb_singleton_class(BufferClass), "new_in", "alloc_in"); rb_define_alias(rb_singleton_class(BufferClass), "new_out", "alloc_out"); rb_define_alias(rb_singleton_class(BufferClass), "new_inout", "alloc_inout"); rb_define_method(BufferClass, "initialize", buffer_initialize, -1); rb_define_method(BufferClass, "initialize_copy", buffer_initialize_copy, 1); rb_define_method(BufferClass, "order", buffer_order, -1); rb_define_method(BufferClass, "inspect", buffer_inspect, 0); rb_define_alias(BufferClass, "length", "total"); rb_define_method(BufferClass, "+", buffer_plus, 1); rb_define_method(BufferClass, "slice", buffer_slice, 2); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/libffi.mk0000644000175000017500000000060212261216360021212 0ustar terceiroterceiro# -*- makefile -*- include ${srcdir}/libffi.gnu.mk $(LIBFFI): @mkdir -p "$(LIBFFI_BUILD_DIR)" "$@(D)" @if [ ! -f "$(LIBFFI_BUILD_DIR)"/Makefile ]; then \ echo "Configuring libffi"; \ cd "$(LIBFFI_BUILD_DIR)" && \ /usr/bin/env CFLAGS="$(LIBFFI_CFLAGS)" GREP_OPTIONS="" \ /bin/sh $(LIBFFI_CONFIGURE) $(LIBFFI_HOST) > /dev/null; \ fi $(MAKE) -C "$(LIBFFI_BUILD_DIR)" ruby-ffi-1.9.3debian.orig/ext/ffi_c/LongDouble.c0000644000175000017500000000333112261216360021626 0ustar terceiroterceiro#include "LongDouble.h" #include #include #include #if defined (__CYGWIN__) || defined(__INTERIX) # define strtold(str, endptr) ((long double) strtod((str), (endptr))) #endif /* defined (__CYGWIN__) */ static VALUE rb_cBigDecimal = Qnil; static VALUE bigdecimal_load(VALUE unused); static VALUE bigdecimal_failed(VALUE value); VALUE rbffi_longdouble_new(long double ld) { if (!RTEST(rb_cBigDecimal)) { /* allow fallback if the bigdecimal library is unavailable in future ruby versions */ rb_cBigDecimal = rb_rescue(bigdecimal_load, Qnil, bigdecimal_failed, rb_cObject); } if (RTEST(rb_cBigDecimal) && rb_cBigDecimal != rb_cObject) { char buf[128]; return rb_funcall(rb_cBigDecimal, rb_intern("new"), 1, rb_str_new(buf, sprintf(buf, "%.35Le", ld))); } /* Fall through to handling as a float */ return rb_float_new(ld); } long double rbffi_num2longdouble(VALUE value) { if (TYPE(value) == T_FLOAT) { return rb_num2dbl(value); } if (!RTEST(rb_cBigDecimal) && rb_const_defined(rb_cObject, rb_intern("BigDecimal"))) { rb_cBigDecimal = rb_const_get(rb_cObject, rb_intern("BigDecimal")); } if (RTEST(rb_cBigDecimal) && rb_cBigDecimal != rb_cObject && RTEST(rb_obj_is_kind_of(value, rb_cBigDecimal))) { VALUE s = rb_funcall(value, rb_intern("to_s"), 1, rb_str_new2("E")); return strtold(RSTRING_PTR(s), NULL); } /* Fall through to handling as a float */ return rb_num2dbl(value); } static VALUE bigdecimal_load(VALUE unused) { rb_require("bigdecimal"); return rb_const_get(rb_cObject, rb_intern("BigDecimal")); } static VALUE bigdecimal_failed(VALUE value) { return value; } ruby-ffi-1.9.3debian.orig/ext/ffi_c/StructByValue.c0000644000175000017500000001065512261216360022357 0ustar terceiroterceiro/* * Copyright (c) 2009, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER #include #endif #include #include #ifndef _MSC_VER # include # include #else # include "win32/stdbool.h" # include "win32/stdint.h" #endif #include #include #include #include "rbffi.h" #include "compat.h" #include "Type.h" #include "StructByValue.h" #include "Struct.h" #define FFI_ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1) static VALUE sbv_allocate(VALUE); static VALUE sbv_initialize(VALUE, VALUE); static void sbv_mark(StructByValue *); static void sbv_free(StructByValue *); VALUE rbffi_StructByValueClass = Qnil; static VALUE sbv_allocate(VALUE klass) { StructByValue* sbv; VALUE obj = Data_Make_Struct(klass, StructByValue, sbv_mark, sbv_free, sbv); sbv->rbStructClass = Qnil; sbv->rbStructLayout = Qnil; sbv->base.nativeType = NATIVE_STRUCT; sbv->base.ffiType = xcalloc(1, sizeof(*sbv->base.ffiType)); sbv->base.ffiType->size = 0; sbv->base.ffiType->alignment = 1; sbv->base.ffiType->type = FFI_TYPE_STRUCT; return obj; } static VALUE sbv_initialize(VALUE self, VALUE rbStructClass) { StructByValue* sbv = NULL; StructLayout* layout = NULL; VALUE rbLayout = Qnil; rbLayout = rb_ivar_get(rbStructClass, rb_intern("@layout")); if (!rb_obj_is_instance_of(rbLayout, rbffi_StructLayoutClass)) { rb_raise(rb_eTypeError, "wrong type in @layout ivar (expected FFI::StructLayout)"); } Data_Get_Struct(rbLayout, StructLayout, layout); Data_Get_Struct(self, StructByValue, sbv); sbv->rbStructClass = rbStructClass; sbv->rbStructLayout = rbLayout; /* We can just use everything from the ffi_type directly */ *sbv->base.ffiType = *layout->base.ffiType; return self; } static void sbv_mark(StructByValue *sbv) { rb_gc_mark(sbv->rbStructClass); rb_gc_mark(sbv->rbStructLayout); } static void sbv_free(StructByValue *sbv) { xfree(sbv->base.ffiType); xfree(sbv); } static VALUE sbv_layout(VALUE self) { StructByValue* sbv; Data_Get_Struct(self, StructByValue, sbv); return sbv->rbStructLayout; } static VALUE sbv_struct_class(VALUE self) { StructByValue* sbv; Data_Get_Struct(self, StructByValue, sbv); return sbv->rbStructClass; } void rbffi_StructByValue_Init(VALUE moduleFFI) { rbffi_StructByValueClass = rb_define_class_under(moduleFFI, "StructByValue", rbffi_TypeClass); rb_global_variable(&rbffi_StructByValueClass); rb_define_const(rbffi_TypeClass, "Struct", rbffi_StructByValueClass); rb_define_alloc_func(rbffi_StructByValueClass, sbv_allocate); rb_define_method(rbffi_StructByValueClass, "initialize", sbv_initialize, 1); rb_define_method(rbffi_StructByValueClass, "layout", sbv_layout, 0); rb_define_method(rbffi_StructByValueClass, "struct_class", sbv_struct_class, 0); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/Thread.c0000644000175000017500000002014712261216360021007 0ustar terceiroterceiro/* * Copyright (c) 2010 Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER #include #else # include "win32/stdbool.h" # include "win32/stdint.h" #endif #if defined(__CYGWIN__) || !defined(_WIN32) # include # include # include # include #else # include # define _WINSOCKAPI_ # include #endif #include #include "Thread.h" #ifdef _WIN32 static volatile DWORD frame_thread_key = TLS_OUT_OF_INDEXES; #else static pthread_key_t thread_data_key; struct thread_data { rbffi_frame_t* frame; }; static inline struct thread_data* thread_data_get(void); #endif rbffi_frame_t* rbffi_frame_current(void) { #ifdef _WIN32 return (rbffi_frame_t *) TlsGetValue(frame_thread_key); #else struct thread_data* td = (struct thread_data *) pthread_getspecific(thread_data_key); return td != NULL ? td->frame : NULL; #endif } void rbffi_frame_push(rbffi_frame_t* frame) { memset(frame, 0, sizeof(*frame)); frame->has_gvl = true; frame->exc = Qnil; #ifdef _WIN32 frame->prev = TlsGetValue(frame_thread_key); TlsSetValue(frame_thread_key, frame); #else frame->td = thread_data_get(); frame->prev = frame->td->frame; frame->td->frame = frame; #endif } void rbffi_frame_pop(rbffi_frame_t* frame) { #ifdef _WIN32 TlsSetValue(frame_thread_key, frame->prev); #else frame->td->frame = frame->prev; #endif } #if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) #if !defined(_WIN32) struct BlockingThread { pthread_t tid; VALUE (*fn)(void *); void *data; void (*ubf)(void *); void *data2; VALUE retval; int wrfd; int rdfd; }; static void* rbffi_blocking_thread(void* args) { struct BlockingThread* thr = (struct BlockingThread *) args; char c = 1; VALUE retval; retval = (*thr->fn)(thr->data); pthread_testcancel(); thr->retval = retval; write(thr->wrfd, &c, sizeof(c)); return NULL; } static VALUE wait_for_thread(void *data) { struct BlockingThread* thr = (struct BlockingThread *) data; char c; if (read(thr->rdfd, &c, 1) < 1) { rb_thread_wait_fd(thr->rdfd); while (read(thr->rdfd, &c, 1) < 1 && rb_io_wait_readable(thr->rdfd) == Qtrue) { ; } } return Qnil; } static VALUE cleanup_blocking_thread(void *data, VALUE exc) { struct BlockingThread* thr = (struct BlockingThread *) data; if (thr->ubf != (void (*)(void *)) -1) { (*thr->ubf)(thr->data2); } else { pthread_kill(thr->tid, SIGVTALRM); } return exc; } VALUE rbffi_thread_blocking_region(VALUE (*func)(void *), void *data1, void (*ubf)(void *), void *data2) { struct BlockingThread* thr; int fd[2]; VALUE exc; if (pipe(fd) < 0) { rb_raise(rb_eSystemCallError, "pipe(2) failed"); return Qnil; } fcntl(fd[0], F_SETFL, fcntl(fd[0], F_GETFL) | O_NONBLOCK); thr = ALLOC_N(struct BlockingThread, 1); thr->rdfd = fd[0]; thr->wrfd = fd[1]; thr->fn = func; thr->data = data1; thr->ubf = ubf; thr->data2 = data2; thr->retval = Qnil; if (pthread_create(&thr->tid, NULL, rbffi_blocking_thread, thr) != 0) { close(fd[0]); close(fd[1]); xfree(thr); rb_raise(rb_eSystemCallError, "pipe(2) failed"); return Qnil; } exc = rb_rescue2(wait_for_thread, (VALUE) thr, cleanup_blocking_thread, (VALUE) thr, rb_eException); pthread_join(thr->tid, NULL); close(fd[1]); close(fd[0]); xfree(thr); if (exc != Qnil) { rb_exc_raise(exc); } return thr->retval; } #else /* win32 implementation */ struct BlockingThread { HANDLE tid; VALUE (*fn)(void *); void *data; void (*ubf)(void *); void *data2; VALUE retval; int wrfd; int rdfd; }; static DWORD __stdcall rbffi_blocking_thread(LPVOID args) { struct BlockingThread* thr = (struct BlockingThread *) args; char c = 1; VALUE retval; retval = (*thr->fn)(thr->data); thr->retval = retval; write(thr->wrfd, &c, sizeof(c)); return 0; } static VALUE wait_for_thread(void *data) { struct BlockingThread* thr = (struct BlockingThread *) data; char c, res; fd_set rfds; FD_ZERO(&rfds); FD_SET(thr->rdfd, &rfds); rb_thread_select(thr->rdfd + 1, &rfds, NULL, NULL, NULL); read(thr->rdfd, &c, 1); return Qnil; } static VALUE cleanup_blocking_thread(void *data, VALUE exc) { struct BlockingThread* thr = (struct BlockingThread *) data; if (thr->ubf != (void (*)(void *)) -1) { (*thr->ubf)(thr->data2); } else { TerminateThread(thr->tid, 0); } return exc; } VALUE rbffi_thread_blocking_region(VALUE (*func)(void *), void *data1, void (*ubf)(void *), void *data2) { struct BlockingThread* thr; int fd[2]; VALUE exc; DWORD state; DWORD res; if (_pipe(fd, 1024, O_BINARY) == -1) { rb_raise(rb_eSystemCallError, "_pipe() failed"); return Qnil; } thr = ALLOC_N(struct BlockingThread, 1); thr->rdfd = fd[0]; thr->wrfd = fd[1]; thr->fn = func; thr->data = data1; thr->ubf = ubf; thr->data2 = data2; thr->retval = Qnil; thr->tid = CreateThread(NULL, 0, rbffi_blocking_thread, thr, 0, NULL); if (!thr->tid) { close(fd[0]); close(fd[1]); xfree(thr); rb_raise(rb_eSystemCallError, "CreateThread() failed"); return Qnil; } exc = rb_rescue2(wait_for_thread, (VALUE) thr, cleanup_blocking_thread, (VALUE) thr, rb_eException); /* The thread should be finished, already. */ WaitForSingleObject(thr->tid, INFINITE); CloseHandle(thr->tid); close(fd[1]); close(fd[0]); xfree(thr); if (exc != Qnil) { rb_exc_raise(exc); } return thr->retval; } #endif /* !_WIN32 */ #endif /* HAVE_RB_THREAD_BLOCKING_REGION */ #ifndef _WIN32 static struct thread_data* thread_data_init(void); static inline struct thread_data* thread_data_get(void) { struct thread_data* td = (struct thread_data *) pthread_getspecific(thread_data_key); return td != NULL ? td : thread_data_init(); } static struct thread_data* thread_data_init(void) { struct thread_data* td = calloc(1, sizeof(struct thread_data)); pthread_setspecific(thread_data_key, td); return td; } static void thread_data_free(void *ptr) { free(ptr); } #endif void rbffi_Thread_Init(VALUE moduleFFI) { #ifdef _WIN32 frame_thread_key = TlsAlloc(); #else pthread_key_create(&thread_data_key, thread_data_free); #endif } ruby-ffi-1.9.3debian.orig/ext/ffi_c/libffi.vc64.mk0000644000175000017500000000107212261216360021775 0ustar terceiroterceiro# -*- makefile -*- # # Makefile for msvc # # Tack the extra deps onto the autogenerated variables INCFLAGS = $(INCFLAGS) -I$(LIBFFI_BUILD_DIR)/include -I$(LIBFFI_BUILD_DIR)/src/x86 LOCAL_LIBS = $(LOCAL_LIBS) $(LIBFFI) BUILD_DIR = $(MAKEDIR) LIBFFI_BUILD_DIR = $(BUILD_DIR)/libffi !IF "$(srcdir)" == "." LIBFFI_SRC_DIR = $(MAKEDIR)/libffi !ELSE LIBFFI_SRC_DIR = $(srcdir)/libffi !ENDIF LIBFFI = $(LIBFFI_BUILD_DIR)/.libs/libffi_convenience.lib $(OBJS): $(LIBFFI) $(LIBFFI): @$(MAKEDIRS) $(LIBFFI_BUILD_DIR) @cd $(LIBFFI_BUILD_DIR) && $(MAKE) -f Makefile.vc64 ruby-ffi-1.9.3debian.orig/ext/ffi_c/libffi.vc.mk0000644000175000017500000000107012261216360021621 0ustar terceiroterceiro# -*- makefile -*- # # Makefile for msvc # # Tack the extra deps onto the autogenerated variables INCFLAGS = $(INCFLAGS) -I$(LIBFFI_BUILD_DIR)/include -I$(LIBFFI_BUILD_DIR)/src/x86 LOCAL_LIBS = $(LOCAL_LIBS) $(LIBFFI) BUILD_DIR = $(MAKEDIR) LIBFFI_BUILD_DIR = $(BUILD_DIR)/libffi !IF "$(srcdir)" == "." LIBFFI_SRC_DIR = $(MAKEDIR)/libffi !ELSE LIBFFI_SRC_DIR = $(srcdir)/libffi !ENDIF LIBFFI = $(LIBFFI_BUILD_DIR)/.libs/libffi_convenience.lib $(OBJS): $(LIBFFI) $(LIBFFI): @$(MAKEDIRS) $(LIBFFI_BUILD_DIR) @cd $(LIBFFI_BUILD_DIR) && $(MAKE) -f Makefile.vc ruby-ffi-1.9.3debian.orig/ext/ffi_c/MemoryPointer.c0000644000175000017500000001414212261216360022407 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * Copyright (C) 2009 Luc Heinrich * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER # include # include #else # include "win32/stdbool.h" # include "win32/stdint.h" #endif #include #include #include "rbffi.h" #include "AbstractMemory.h" #include "Pointer.h" #include "MemoryPointer.h" static VALUE memptr_allocate(VALUE klass); static void memptr_release(Pointer* ptr); static VALUE memptr_malloc(VALUE self, long size, long count, bool clear); static VALUE memptr_free(VALUE self); VALUE rbffi_MemoryPointerClass; #define MEMPTR(obj) ((MemoryPointer *) rbffi_AbstractMemory_Cast(obj, rbffi_MemoryPointerClass)) VALUE rbffi_MemoryPointer_NewInstance(long size, long count, bool clear) { return memptr_malloc(memptr_allocate(rbffi_MemoryPointerClass), size, count, clear); } static VALUE memptr_allocate(VALUE klass) { Pointer* p; VALUE obj = Data_Make_Struct(klass, Pointer, NULL, memptr_release, p); p->rbParent = Qnil; p->memory.flags = MEM_RD | MEM_WR; return obj; } /* * call-seq: initialize(size, count=1, clear=true) * @param [Fixnum, Bignum, Symbol, FFI::Type] size size of a memory cell (in bytes, or type whom size will be used) * @param [Numeric] count number of cells in memory * @param [Boolean] clear set memory to all-zero if +true+ * @return [self] * A new instance of FFI::MeoryPointer. */ static VALUE memptr_initialize(int argc, VALUE* argv, VALUE self) { VALUE size = Qnil, count = Qnil, clear = Qnil; int nargs = rb_scan_args(argc, argv, "12", &size, &count, &clear); memptr_malloc(self, rbffi_type_size(size), nargs > 1 ? NUM2LONG(count) : 1, RTEST(clear) || clear == Qnil); if (rb_block_given_p()) { return rb_ensure(rb_yield, self, memptr_free, self); } return self; } static VALUE memptr_malloc(VALUE self, long size, long count, bool clear) { Pointer* p; unsigned long msize; Data_Get_Struct(self, Pointer, p); msize = size * count; p->storage = xmalloc(msize + 7); if (p->storage == NULL) { rb_raise(rb_eNoMemError, "Failed to allocate memory size=%ld bytes", msize); return Qnil; } p->autorelease = true; p->memory.typeSize = (int) size; p->memory.size = msize; /* ensure the memory is aligned on at least a 8 byte boundary */ p->memory.address = (char *) (((uintptr_t) p->storage + 0x7) & (uintptr_t) ~0x7UL);; p->allocated = true; if (clear && p->memory.size > 0) { memset(p->memory.address, 0, p->memory.size); } return self; } static VALUE memptr_free(VALUE self) { Pointer* ptr; Data_Get_Struct(self, Pointer, ptr); if (ptr->allocated) { if (ptr->storage != NULL) { xfree(ptr->storage); ptr->storage = NULL; } ptr->allocated = false; } return self; } static void memptr_release(Pointer* ptr) { if (ptr->autorelease && ptr->allocated && ptr->storage != NULL) { xfree(ptr->storage); ptr->storage = NULL; } xfree(ptr); } /* * call-seq: from_string(s) * @param [String] s string * @return [MemoryPointer] * Create a {MemoryPointer} with +s+ inside. */ static VALUE memptr_s_from_string(VALUE klass, VALUE to_str) { VALUE s = StringValue(to_str); VALUE args[] = { INT2FIX(1), LONG2NUM(RSTRING_LEN(s) + 1), Qfalse }; VALUE obj = rb_class_new_instance(3, args, klass); rb_funcall(obj, rb_intern("put_string"), 2, INT2FIX(0), s); return obj; } void rbffi_MemoryPointer_Init(VALUE moduleFFI) { VALUE ffi_Pointer; ffi_Pointer = rbffi_PointerClass; /* * Document-class: FFI::MemoryPointer < FFI::Pointer * A MemoryPointer is a specific {Pointer}. It points to a memory composed of cells. All cells have the * same size. * * @example Create a new MemoryPointer * mp = FFI::MemoryPointer.new(:long, 16) # Create a pointer on a memory of 16 long ints. * @example Create a new MemoryPointer from a String * mp1 = FFI::MemoryPointer.from_string("this is a string") * # same as: * mp2 = FFI::MemoryPointer.new(:char,16) * mp2.put_string("this is a string") */ rbffi_MemoryPointerClass = rb_define_class_under(moduleFFI, "MemoryPointer", ffi_Pointer); rb_global_variable(&rbffi_MemoryPointerClass); rb_define_alloc_func(rbffi_MemoryPointerClass, memptr_allocate); rb_define_method(rbffi_MemoryPointerClass, "initialize", memptr_initialize, -1); rb_define_singleton_method(rbffi_MemoryPointerClass, "from_string", memptr_s_from_string, 1); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/Call.h0000644000175000017500000000642712261216357020473 0ustar terceiroterceiro/* * Copyright (c) 2009, Wayne Meissner * Copyright (c) 2009, Luc Heinrich * Copyright (c) 2009, Mike Dalessio * Copyright (c) 2009, Aman Gupta. * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_CALL_H #define RBFFI_CALL_H #ifdef __cplusplus extern "C" { #endif #if defined(__i386__) && \ (defined(HAVE_RAW_API) || defined(USE_INTERNAL_LIBFFI)) && \ !defined(_WIN32) && !defined(__WIN32__) # define USE_RAW #endif #if (defined(__i386__) || defined(__x86_64__)) && !(defined(_WIN32) || defined(__WIN32__)) # define BYPASS_FFI 1 #endif typedef union { #ifdef USE_RAW signed int s8, s16, s32; unsigned int u8, u16, u32; #else signed char s8; unsigned char u8; signed short s16; unsigned short u16; signed int s32; unsigned int u32; #endif signed long long i64; unsigned long long u64; signed long sl; unsigned long ul; void* ptr; float f32; double f64; long double ld; } FFIStorage; extern void rbffi_Call_Init(VALUE moduleFFI); extern void rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes, FFIStorage* paramStorage, void** ffiValues, VALUE* callbackParameters, int callbackCount, VALUE enums); struct FunctionType_; extern VALUE rbffi_CallFunction(int argc, VALUE* argv, void* function, struct FunctionType_* fnInfo); typedef VALUE (*Invoker)(int argc, VALUE* argv, void* function, struct FunctionType_* fnInfo); Invoker rbffi_GetInvoker(struct FunctionType_* fnInfo); extern VALUE rbffi_GetEnumValue(VALUE enums, VALUE value); extern int rbffi_GetSignedIntValue(VALUE value, int type, int minValue, int maxValue, const char* typeName, VALUE enums); #ifdef __cplusplus } #endif #endif /* RBFFI_CALL_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/libffi.gnu.mk0000644000175000017500000000140712261216360022006 0ustar terceiroterceiro# -*- makefile -*- # # Common definitions for all systems that use GNU make # # Tack the extra deps onto the autogenerated variables INCFLAGS += -I"$(LIBFFI_BUILD_DIR)"/include LOCAL_LIBS += $(LIBFFI) BUILD_DIR = $(shell pwd) LIBFFI_CFLAGS = $(FFI_MMAP_EXEC) LIBFFI_BUILD_DIR = $(BUILD_DIR)/libffi-$(arch) ifeq ($(srcdir),.) LIBFFI_SRC_DIR := $(shell pwd)/libffi else ifeq ($(srcdir),..) LIBFFI_SRC_DIR := $(shell pwd)/../libffi else LIBFFI_SRC_DIR := $(realpath $(srcdir)/libffi) endif LIBFFI = "$(LIBFFI_BUILD_DIR)"/.libs/libffi_convenience.a LIBFFI_CONFIGURE = "$(LIBFFI_SRC_DIR)"/configure --disable-static \ --with-pic=yes --disable-dependency-tracking $(OBJS): $(LIBFFI) # # libffi.mk or libffi.darwin.mk contains rules for building the actual library # ruby-ffi-1.9.3debian.orig/ext/ffi_c/Type.h0000644000175000017500000000403312261216360020522 0ustar terceiroterceiro/* * Copyright (c) 2009, Wayne Meissner * Copyright (C) 2009 Luc Heinrich * * This file is part of ruby-ffi. * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the Evan Phoenix nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #ifndef RBFFI_TYPE_H #define RBFFI_TYPE_H #include #include #ifdef __cplusplus extern "C" { #endif typedef struct Type_ Type; #include "Types.h" struct Type_ { NativeType nativeType; ffi_type* ffiType; }; extern VALUE rbffi_TypeClass; extern VALUE rbffi_Type_Lookup(VALUE type); extern VALUE rbffi_Type_Find(VALUE type); #ifdef __cplusplus } #endif #endif /* RBFFI_TYPE_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/win32/0000755000175000017500000000000012261216360020372 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/ext/ffi_c/win32/stdbool.h0000644000175000017500000000017112261216360022210 0ustar terceiroterceiro#ifndef FFI_STDBOOL_H #define FFI_STDBOOL_H typedef int bool; #define true 1 #define false 0 #endif /* FFI_STDBOOL_H */ruby-ffi-1.9.3debian.orig/ext/ffi_c/win32/stdint.h0000644000175000017500000001211012261216360022043 0ustar terceiroterceiro/* stdint.h standard header */ #if !defined(_MSC_VER) && !defined(INT8_MIN) #pragma once #ifndef _STDINT #define _STDINT #ifndef RC_INVOKED #include /* NB: assumes byte has 8 bits long is 32 bits pointer can convert to and from long long long long is longest type */ _C_STD_BEGIN /* TYPE DEFINITIONS */ typedef signed char int8_t; typedef short int16_t; typedef int int32_t; typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; typedef signed char int_least8_t; typedef short int_least16_t; typedef int int_least32_t; typedef unsigned char uint_least8_t; typedef unsigned short uint_least16_t; typedef unsigned int uint_least32_t; typedef char int_fast8_t; typedef int int_fast16_t; typedef int int_fast32_t; typedef unsigned char uint_fast8_t; typedef unsigned int uint_fast16_t; typedef unsigned int uint_fast32_t; #ifndef _INTPTR_T_DEFINED #define _INTPTR_T_DEFINED #ifdef _WIN64 typedef __int64 intptr_t; #else /* _WIN64 */ typedef _W64 int intptr_t; #endif /* _WIN64 */ #endif /* _INTPTR_T_DEFINED */ #ifndef _UINTPTR_T_DEFINED #define _UINTPTR_T_DEFINED #ifdef _WIN64 typedef unsigned __int64 uintptr_t; #else /* _WIN64 */ typedef _W64 unsigned int uintptr_t; #endif /* _WIN64 */ #endif /* _UINTPTR_T_DEFINED */ typedef _Longlong int64_t; typedef _ULonglong uint64_t; typedef _Longlong int_least64_t; typedef _ULonglong uint_least64_t; typedef _Longlong int_fast64_t; typedef _ULonglong uint_fast64_t; typedef _Longlong intmax_t; typedef _ULonglong uintmax_t; /* LIMIT MACROS */ #define INT8_MIN (-0x7f - _C2) #define INT16_MIN (-0x7fff - _C2) #define INT32_MIN (-0x7fffffff - _C2) #define INT8_MAX 0x7f #define INT16_MAX 0x7fff #define INT32_MAX 0x7fffffff #define UINT8_MAX 0xff #define UINT16_MAX 0xffff #define UINT32_MAX 0xffffffff #define INT_LEAST8_MIN (-0x7f - _C2) #define INT_LEAST16_MIN (-0x7fff - _C2) #define INT_LEAST32_MIN (-0x7fffffff - _C2) #define INT_LEAST8_MAX 0x7f #define INT_LEAST16_MAX 0x7fff #define INT_LEAST32_MAX 0x7fffffff #define UINT_LEAST8_MAX 0xff #define UINT_LEAST16_MAX 0xffff #define UINT_LEAST32_MAX 0xffffffff #define INT_FAST8_MIN (-0x7f - _C2) #define INT_FAST16_MIN (-0x7fff - _C2) #define INT_FAST32_MIN (-0x7fffffff - _C2) #define INT_FAST8_MAX 0x7f #define INT_FAST16_MAX 0x7fff #define INT_FAST32_MAX 0x7fffffff #define UINT_FAST8_MAX 0xff #define UINT_FAST16_MAX 0xffff #define UINT_FAST32_MAX 0xffffffff #if _INTPTR == 0 || _INTPTR == 1 #define INTPTR_MAX 0x7fffffff #define INTPTR_MIN (-INTPTR_MAX - _C2) #define UINTPTR_MAX 0xffffffff #else /* _INTPTR == 2 */ #define INTPTR_MIN (-_LLONG_MAX - _C2) #define INTPTR_MAX _LLONG_MAX #define UINTPTR_MAX _ULLONG_MAX #endif /* _INTPTR */ #define INT8_C(x) (x) #define INT16_C(x) (x) #define INT32_C(x) ((x) + (INT32_MAX - INT32_MAX)) #define UINT8_C(x) (x) #define UINT16_C(x) (x) #define UINT32_C(x) ((x) + (UINT32_MAX - UINT32_MAX)) #ifdef _WIN64 #define PTRDIFF_MIN INT64_MIN #define PTRDIFF_MAX INT64_MAX #else /* _WIN64 */ #define PTRDIFF_MIN INT32_MIN #define PTRDIFF_MAX INT32_MAX #endif /* _WIN64 */ #define SIG_ATOMIC_MIN INT32_MIN #define SIG_ATOMIC_MAX INT32_MAX #ifndef SIZE_MAX #ifdef _WIN64 #define SIZE_MAX UINT64_MAX #else /* _WIN64 */ #define SIZE_MAX UINT32_MAX #endif /* _WIN64 */ #endif /* SIZE_MAX */ #define WCHAR_MIN 0x0000 #define WCHAR_MAX 0xffff #define WINT_MIN 0x0000 #define WINT_MAX 0xffff #define INT64_MIN (-0x7fffffffffffffff - _C2) #define INT64_MAX 0x7fffffffffffffff #define UINT64_MAX 0xffffffffffffffffU #define INT_LEAST64_MIN (-0x7fffffffffffffff - _C2) #define INT_LEAST64_MAX 0x7fffffffffffffff #define UINT_LEAST64_MAX 0xffffffffffffffffU #define INT_FAST64_MIN (-0x7fffffffffffffff - _C2) #define INT_FAST64_MAX 0x7fffffffffffffff #define UINT_FAST64_MAX 0xffffffffffffffffU #define INTMAX_MIN (-0x7fffffffffffffff - _C2) #define INTMAX_MAX 0x7fffffffffffffff #define UINTMAX_MAX 0xffffffffffffffffU #define INT64_C(x) ((x) + (INT64_MAX - INT64_MAX)) #define UINT64_C(x) ((x) + (UINT64_MAX - UINT64_MAX)) #define INTMAX_C(x) INT64_C(x) #define UINTMAX_C(x) UINT64_C(x) _C_STD_END #endif /* RC_INVOKED */ #endif /* _STDINT */ #if defined(_STD_USING) using _CSTD int8_t; using _CSTD int16_t; using _CSTD int32_t; using _CSTD int64_t; using _CSTD uint8_t; using _CSTD uint16_t; using _CSTD uint32_t; using _CSTD uint64_t; using _CSTD int_least8_t; using _CSTD int_least16_t; using _CSTD int_least32_t; using _CSTD int_least64_t; using _CSTD uint_least8_t; using _CSTD uint_least16_t; using _CSTD uint_least32_t; using _CSTD uint_least64_t; using _CSTD intmax_t; using _CSTD uintmax_t; using _CSTD uintptr_t; using _CSTD intptr_t; using _CSTD int_fast8_t; using _CSTD int_fast16_t; using _CSTD int_fast32_t; using _CSTD int_fast64_t; using _CSTD uint_fast8_t; using _CSTD uint_fast16_t; using _CSTD uint_fast32_t; using _CSTD uint_fast64_t; #endif /* defined(_STD_USING) */ /* * Copyright (c) 1992-2009 by P.J. Plauger. ALL RIGHTS RESERVED. * Consult your license regarding permissions and restrictions. V5.20:0009 */ #endif /* !defined(_MSC_VER) && !defined(INT8_MIN) */ruby-ffi-1.9.3debian.orig/ext/ffi_c/MemoryPointer.h0000644000175000017500000000415412261216360022416 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * Copyright (c) 2008, Luc Heinrich * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_MEMORYPOINTER_H #define RBFFI_MEMORYPOINTER_H #ifndef _MSC_VER # include #else # include "win32/stdbool.h" #endif #include #ifdef __cplusplus extern "C" { #endif extern void rbffi_MemoryPointer_Init(VALUE moduleFFI); extern VALUE rbffi_MemoryPointerClass; extern VALUE rbffi_MemoryPointer_NewInstance(long size, long count, bool clear); #ifdef __cplusplus } #endif #endif /* RBFFI_MEMORYPOINTER_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/MappedType.c0000644000175000017500000001216512261216360021651 0ustar terceiroterceiro/* * Copyright (c) 2010, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "rbffi.h" #include "Type.h" #include "MappedType.h" static VALUE mapped_allocate(VALUE); static VALUE mapped_initialize(VALUE, VALUE); static void mapped_mark(MappedType *); static ID id_native_type, id_to_native, id_from_native; VALUE rbffi_MappedTypeClass = Qnil; static VALUE mapped_allocate(VALUE klass) { MappedType* m; VALUE obj = Data_Make_Struct(klass, MappedType, mapped_mark, -1, m); m->rbConverter = Qnil; m->rbType = Qnil; m->type = NULL; m->base.nativeType = NATIVE_MAPPED; m->base.ffiType = &ffi_type_void; return obj; } /* * call-seq: initialize(converter) * @param [#native_type, #to_native, #from_native] converter +converter+ must respond to * all these methods * @return [self] */ static VALUE mapped_initialize(VALUE self, VALUE rbConverter) { MappedType* m = NULL; if (!rb_respond_to(rbConverter, id_native_type)) { rb_raise(rb_eNoMethodError, "native_type method not implemented"); } if (!rb_respond_to(rbConverter, id_to_native)) { rb_raise(rb_eNoMethodError, "to_native method not implemented"); } if (!rb_respond_to(rbConverter, id_from_native)) { rb_raise(rb_eNoMethodError, "from_native method not implemented"); } Data_Get_Struct(self, MappedType, m); m->rbType = rb_funcall2(rbConverter, id_native_type, 0, NULL); if (!(rb_obj_is_kind_of(m->rbType, rbffi_TypeClass))) { rb_raise(rb_eTypeError, "native_type did not return instance of FFI::Type"); } m->rbConverter = rbConverter; Data_Get_Struct(m->rbType, Type, m->type); m->base.ffiType = m->type->ffiType; return self; } static void mapped_mark(MappedType* m) { rb_gc_mark(m->rbType); rb_gc_mark(m->rbConverter); } /* * call-seq: mapped_type.native_type * @return [Type] * Get native type of mapped type. */ static VALUE mapped_native_type(VALUE self) { MappedType*m = NULL; Data_Get_Struct(self, MappedType, m); return m->rbType; } /* * call-seq: mapped_type.to_native(*args) * @param args depends on {FFI::DataConverter} used to initialize +self+ */ static VALUE mapped_to_native(int argc, VALUE* argv, VALUE self) { MappedType*m = NULL; Data_Get_Struct(self, MappedType, m); return rb_funcall2(m->rbConverter, id_to_native, argc, argv); } /* * call-seq: mapped_type.from_native(*args) * @param args depends on {FFI::DataConverter} used to initialize +self+ */ static VALUE mapped_from_native(int argc, VALUE* argv, VALUE self) { MappedType*m = NULL; Data_Get_Struct(self, MappedType, m); return rb_funcall2(m->rbConverter, id_from_native, argc, argv); } void rbffi_MappedType_Init(VALUE moduleFFI) { /* * Document-class: FFI::Type::Mapped < FFI::Type */ rbffi_MappedTypeClass = rb_define_class_under(rbffi_TypeClass, "Mapped", rbffi_TypeClass); rb_global_variable(&rbffi_MappedTypeClass); id_native_type = rb_intern("native_type"); id_to_native = rb_intern("to_native"); id_from_native = rb_intern("from_native"); rb_define_alloc_func(rbffi_MappedTypeClass, mapped_allocate); rb_define_method(rbffi_MappedTypeClass, "initialize", mapped_initialize, 1); rb_define_method(rbffi_MappedTypeClass, "type", mapped_native_type, 0); rb_define_method(rbffi_MappedTypeClass, "native_type", mapped_native_type, 0); rb_define_method(rbffi_MappedTypeClass, "to_native", mapped_to_native, -1); rb_define_method(rbffi_MappedTypeClass, "from_native", mapped_from_native, -1); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/Struct.c0000644000175000017500000005421312261216360021065 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * Copyright (C) 2009 Luc Heinrich * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #ifndef _MSC_VER # include # include # include #else # include "win32/stdbool.h" # include "win32/stdint.h" #endif #include #include "rbffi.h" #include "compat.h" #include "AbstractMemory.h" #include "Pointer.h" #include "MemoryPointer.h" #include "Function.h" #include "Types.h" #include "Function.h" #include "StructByValue.h" #include "ArrayType.h" #include "MappedType.h" #include "Struct.h" typedef struct InlineArray_ { VALUE rbMemory; VALUE rbField; AbstractMemory* memory; StructField* field; MemoryOp *op; Type* componentType; ArrayType* arrayType; int length; } InlineArray; static void struct_mark(Struct *); static void struct_free(Struct *); static VALUE struct_class_layout(VALUE klass); static void struct_malloc(Struct* s); static void inline_array_mark(InlineArray *); static void store_reference_value(StructField* f, Struct* s, VALUE value); VALUE rbffi_StructClass = Qnil; VALUE rbffi_StructInlineArrayClass = Qnil; VALUE rbffi_StructLayoutCharArrayClass = Qnil; static ID id_pointer_ivar = 0, id_layout_ivar = 0; static ID id_get = 0, id_put = 0, id_to_ptr = 0, id_to_s = 0, id_layout = 0; static inline char* memory_address(VALUE self) { return ((AbstractMemory *)DATA_PTR((self)))->address; } static VALUE struct_allocate(VALUE klass) { Struct* s; VALUE obj = Data_Make_Struct(klass, Struct, struct_mark, struct_free, s); s->rbPointer = Qnil; s->rbLayout = Qnil; return obj; } /* * call-seq: initialize * @overload initialize(pointer, *args) * @param [AbstractMemory] pointer * @param [Array] args * @return [self] */ static VALUE struct_initialize(int argc, VALUE* argv, VALUE self) { Struct* s; VALUE rbPointer = Qnil, rest = Qnil, klass = CLASS_OF(self); int nargs; Data_Get_Struct(self, Struct, s); nargs = rb_scan_args(argc, argv, "01*", &rbPointer, &rest); /* Call up into ruby code to adjust the layout */ if (nargs > 1) { s->rbLayout = rb_funcall2(CLASS_OF(self), id_layout, (int) RARRAY_LEN(rest), RARRAY_PTR(rest)); } else { s->rbLayout = struct_class_layout(klass); } if (!rb_obj_is_kind_of(s->rbLayout, rbffi_StructLayoutClass)) { rb_raise(rb_eRuntimeError, "Invalid Struct layout"); } Data_Get_Struct(s->rbLayout, StructLayout, s->layout); if (rbPointer != Qnil) { s->pointer = MEMORY(rbPointer); s->rbPointer = rbPointer; } else { struct_malloc(s); } return self; } /* * call-seq: initialize_copy(other) * @return [nil] * DO NOT CALL THIS METHOD */ static VALUE struct_initialize_copy(VALUE self, VALUE other) { Struct* src; Struct* dst; Data_Get_Struct(self, Struct, dst); Data_Get_Struct(other, Struct, src); if (dst == src) { return self; } dst->rbLayout = src->rbLayout; dst->layout = src->layout; /* * A new MemoryPointer instance is allocated here instead of just calling * #dup on rbPointer, since the Pointer may not know its length, or may * be longer than just this struct. */ if (src->pointer->address != NULL) { dst->rbPointer = rbffi_MemoryPointer_NewInstance(1, src->layout->size, false); dst->pointer = MEMORY(dst->rbPointer); memcpy(dst->pointer->address, src->pointer->address, src->layout->size); } else { dst->rbPointer = src->rbPointer; dst->pointer = src->pointer; } if (src->layout->referenceFieldCount > 0) { dst->rbReferences = ALLOC_N(VALUE, dst->layout->referenceFieldCount); memcpy(dst->rbReferences, src->rbReferences, dst->layout->referenceFieldCount * sizeof(VALUE)); } return self; } static VALUE struct_class_layout(VALUE klass) { VALUE layout; if (!rb_ivar_defined(klass, id_layout_ivar)) { rb_raise(rb_eRuntimeError, "no Struct layout configured for %s", rb_class2name(klass)); } layout = rb_ivar_get(klass, id_layout_ivar); if (!rb_obj_is_kind_of(layout, rbffi_StructLayoutClass)) { rb_raise(rb_eRuntimeError, "invalid Struct layout for %s", rb_class2name(klass)); } return layout; } static StructLayout* struct_layout(VALUE self) { Struct* s = (Struct *) DATA_PTR(self); if (s->layout != NULL) { return s->layout; } if (s->layout == NULL) { s->rbLayout = struct_class_layout(CLASS_OF(self)); Data_Get_Struct(s->rbLayout, StructLayout, s->layout); } return s->layout; } static Struct* struct_validate(VALUE self) { Struct* s; Data_Get_Struct(self, Struct, s); if (struct_layout(self) == NULL) { rb_raise(rb_eRuntimeError, "struct layout == null"); } if (s->pointer == NULL) { struct_malloc(s); } return s; } static void struct_malloc(Struct* s) { if (s->rbPointer == Qnil) { s->rbPointer = rbffi_MemoryPointer_NewInstance(s->layout->size, 1, true); } else if (!rb_obj_is_kind_of(s->rbPointer, rbffi_AbstractMemoryClass)) { rb_raise(rb_eRuntimeError, "invalid pointer in struct"); } s->pointer = (AbstractMemory *) DATA_PTR(s->rbPointer); } static void struct_mark(Struct *s) { rb_gc_mark(s->rbPointer); rb_gc_mark(s->rbLayout); if (s->rbReferences != NULL) { rb_gc_mark_locations(&s->rbReferences[0], &s->rbReferences[s->layout->referenceFieldCount]); } } static void struct_free(Struct* s) { xfree(s->rbReferences); xfree(s); } static void store_reference_value(StructField* f, Struct* s, VALUE value) { if (unlikely(f->referenceIndex == -1)) { rb_raise(rb_eRuntimeError, "put_reference_value called for non-reference type"); return; } if (s->rbReferences == NULL) { int i; s->rbReferences = ALLOC_N(VALUE, s->layout->referenceFieldCount); for (i = 0; i < s->layout->referenceFieldCount; ++i) { s->rbReferences[i] = Qnil; } } s->rbReferences[f->referenceIndex] = value; } static VALUE struct_field(Struct* s, VALUE fieldName) { StructLayout* layout = s->layout; VALUE rbField; if (likely(SYMBOL_P(fieldName) && st_lookup(layout->fieldSymbolTable, fieldName, (st_data_t *) &rbField))) { return rbField; } rbField = rb_hash_aref(layout->rbFieldMap, fieldName); if (rbField == Qnil) { VALUE str = rb_funcall2(fieldName, id_to_s, 0, NULL); rb_raise(rb_eArgError, "No such field '%s'", StringValuePtr(str)); } return rbField; } /* * call-seq: struct[field_name] * @param field_name field to access * Acces to a Struct field. */ static VALUE struct_aref(VALUE self, VALUE fieldName) { Struct* s; VALUE rbField; StructField* f; s = struct_validate(self); rbField = struct_field(s, fieldName); f = (StructField *) DATA_PTR(rbField); if (f->get != NULL) { return (*f->get)(f, s); } else if (f->memoryOp != NULL) { return (*f->memoryOp->get)(s->pointer, f->offset); } else { /* call up to the ruby code to fetch the value */ return rb_funcall2(rbField, id_get, 1, &s->rbPointer); } } /* * call-seq: []=(field_name, value) * @param field_name field to access * @param value value to set to +field_name+ * @return [value] * Set a field in Struct. */ static VALUE struct_aset(VALUE self, VALUE fieldName, VALUE value) { Struct* s; VALUE rbField; StructField* f; s = struct_validate(self); rbField = struct_field(s, fieldName); f = (StructField *) DATA_PTR(rbField); if (f->put != NULL) { (*f->put)(f, s, value); } else if (f->memoryOp != NULL) { (*f->memoryOp->put)(s->pointer, f->offset, value); } else { /* call up to the ruby code to set the value */ VALUE argv[2]; argv[0] = s->rbPointer; argv[1] = value; rb_funcall2(rbField, id_put, 2, argv); } if (f->referenceRequired) { store_reference_value(f, s, value); } return value; } /* * call-seq: pointer= pointer * @param [AbstractMemory] pointer * @return [self] * Make Struct point to +pointer+. */ static VALUE struct_set_pointer(VALUE self, VALUE pointer) { Struct* s; StructLayout* layout; AbstractMemory* memory; if (!rb_obj_is_kind_of(pointer, rbffi_AbstractMemoryClass)) { rb_raise(rb_eTypeError, "wrong argument type %s (expected Pointer or Buffer)", rb_obj_classname(pointer)); return Qnil; } Data_Get_Struct(self, Struct, s); Data_Get_Struct(pointer, AbstractMemory, memory); layout = struct_layout(self); if ((int) layout->base.ffiType->size > memory->size) { rb_raise(rb_eArgError, "memory of %ld bytes too small for struct %s (expected at least %ld)", memory->size, rb_obj_classname(self), (long) layout->base.ffiType->size); } s->pointer = MEMORY(pointer); s->rbPointer = pointer; rb_ivar_set(self, id_pointer_ivar, pointer); return self; } /* * call-seq: pointer * @return [AbstractMemory] * Get pointer to Struct contents. */ static VALUE struct_get_pointer(VALUE self) { Struct* s; Data_Get_Struct(self, Struct, s); return s->rbPointer; } /* * call-seq: layout= layout * @param [StructLayout] layout * @return [self] * Set the Struct's layout. */ static VALUE struct_set_layout(VALUE self, VALUE layout) { Struct* s; Data_Get_Struct(self, Struct, s); if (!rb_obj_is_kind_of(layout, rbffi_StructLayoutClass)) { rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", rb_obj_classname(layout), rb_class2name(rbffi_StructLayoutClass)); return Qnil; } Data_Get_Struct(layout, StructLayout, s->layout); rb_ivar_set(self, id_layout_ivar, layout); return self; } /* * call-seq: layout * @return [StructLayout] * Get the Struct's layout. */ static VALUE struct_get_layout(VALUE self) { Struct* s; Data_Get_Struct(self, Struct, s); return s->rbLayout; } /* * call-seq: null? * @return [Boolean] * Test if Struct's pointer is NULL */ static VALUE struct_null_p(VALUE self) { Struct* s; Data_Get_Struct(self, Struct, s); return s->pointer->address == NULL ? Qtrue : Qfalse; } /* * (see Pointer#order) */ static VALUE struct_order(int argc, VALUE* argv, VALUE self) { Struct* s; Data_Get_Struct(self, Struct, s); if (argc == 0) { return rb_funcall(s->rbPointer, rb_intern("order"), 0); } else { VALUE retval = rb_obj_dup(self); VALUE rbPointer = rb_funcall2(s->rbPointer, rb_intern("order"), argc, argv); struct_set_pointer(retval, rbPointer); return retval; } } static VALUE inline_array_allocate(VALUE klass) { InlineArray* array; VALUE obj; obj = Data_Make_Struct(klass, InlineArray, inline_array_mark, -1, array); array->rbField = Qnil; array->rbMemory = Qnil; return obj; } static void inline_array_mark(InlineArray* array) { rb_gc_mark(array->rbField); rb_gc_mark(array->rbMemory); } /* * Document-method: FFI::Struct::InlineArray#initialize * call-seq: initialize(memory, field) * @param [AbstractMemory] memory * @param [StructField] field * @return [self] */ static VALUE inline_array_initialize(VALUE self, VALUE rbMemory, VALUE rbField) { InlineArray* array; Data_Get_Struct(self, InlineArray, array); array->rbMemory = rbMemory; array->rbField = rbField; Data_Get_Struct(rbMemory, AbstractMemory, array->memory); Data_Get_Struct(rbField, StructField, array->field); Data_Get_Struct(array->field->rbType, ArrayType, array->arrayType); Data_Get_Struct(array->arrayType->rbComponentType, Type, array->componentType); array->op = get_memory_op(array->componentType); if (array->op == NULL && array->componentType->nativeType == NATIVE_MAPPED) { array->op = get_memory_op(((MappedType *) array->componentType)->type); } array->length = array->arrayType->length; return self; } /* * call-seq: size * @return [Numeric] * Get size */ static VALUE inline_array_size(VALUE self) { InlineArray* array; Data_Get_Struct(self, InlineArray, array); return UINT2NUM(((ArrayType *) array->field->type)->length); } static int inline_array_offset(InlineArray* array, int index) { if (index < 0 || (index >= array->length && array->length > 0)) { rb_raise(rb_eIndexError, "index %d out of bounds", index); } return (int) array->field->offset + (index * (int) array->componentType->ffiType->size); } /* * call-seq: [](index) * @param [Numeric] index * @return [Type, Struct] */ static VALUE inline_array_aref(VALUE self, VALUE rbIndex) { InlineArray* array; Data_Get_Struct(self, InlineArray, array); if (array->op != NULL) { VALUE rbNativeValue = array->op->get(array->memory, inline_array_offset(array, NUM2INT(rbIndex))); if (unlikely(array->componentType->nativeType == NATIVE_MAPPED)) { return rb_funcall(((MappedType *) array->componentType)->rbConverter, rb_intern("from_native"), 2, rbNativeValue, Qnil); } else { return rbNativeValue; } } else if (array->componentType->nativeType == NATIVE_STRUCT) { VALUE rbOffset = INT2NUM(inline_array_offset(array, NUM2INT(rbIndex))); VALUE rbLength = INT2NUM(array->componentType->ffiType->size); VALUE rbPointer = rb_funcall(array->rbMemory, rb_intern("slice"), 2, rbOffset, rbLength); return rb_class_new_instance(1, &rbPointer, ((StructByValue *) array->componentType)->rbStructClass); } else { rb_raise(rb_eArgError, "get not supported for %s", rb_obj_classname(array->arrayType->rbComponentType)); return Qnil; } } /* * call-seq: []=(index, value) * @param [Numeric] index * @param [Type, Struct] * @return [value] */ static VALUE inline_array_aset(VALUE self, VALUE rbIndex, VALUE rbValue) { InlineArray* array; Data_Get_Struct(self, InlineArray, array); if (array->op != NULL) { if (unlikely(array->componentType->nativeType == NATIVE_MAPPED)) { rbValue = rb_funcall(((MappedType *) array->componentType)->rbConverter, rb_intern("to_native"), 2, rbValue, Qnil); } array->op->put(array->memory, inline_array_offset(array, NUM2INT(rbIndex)), rbValue); } else if (array->componentType->nativeType == NATIVE_STRUCT) { int offset = inline_array_offset(array, NUM2INT(rbIndex)); Struct* s; if (!rb_obj_is_kind_of(rbValue, rbffi_StructClass)) { rb_raise(rb_eTypeError, "argument not an instance of struct"); return Qnil; } checkWrite(array->memory); checkBounds(array->memory, offset, array->componentType->ffiType->size); Data_Get_Struct(rbValue, Struct, s); checkRead(s->pointer); checkBounds(s->pointer, 0, array->componentType->ffiType->size); memcpy(array->memory->address + offset, s->pointer->address, array->componentType->ffiType->size); } else { ArrayType* arrayType; Data_Get_Struct(array->field->rbType, ArrayType, arrayType); rb_raise(rb_eArgError, "set not supported for %s", rb_obj_classname(arrayType->rbComponentType)); return Qnil; } return rbValue; } /* * call-seq: each * Yield block for each element of +self+. */ static VALUE inline_array_each(VALUE self) { InlineArray* array; int i; Data_Get_Struct(self, InlineArray, array); for (i = 0; i < array->length; ++i) { rb_yield(inline_array_aref(self, INT2FIX(i))); } return self; } /* * call-seq: to_a * @return [Array] * Convert +self+ to an array. */ static VALUE inline_array_to_a(VALUE self) { InlineArray* array; VALUE obj; int i; Data_Get_Struct(self, InlineArray, array); obj = rb_ary_new2(array->length); for (i = 0; i < array->length; ++i) { rb_ary_push(obj, inline_array_aref(self, INT2FIX(i))); } return obj; } /* * Document-method: FFI::StructLayout::CharArray#to_s * call-seq: to_s * @return [String] * Convert +self+ to a string. */ static VALUE inline_array_to_s(VALUE self) { InlineArray* array; VALUE argv[2]; Data_Get_Struct(self, InlineArray, array); if (array->componentType->nativeType != NATIVE_INT8 && array->componentType->nativeType != NATIVE_UINT8) { VALUE dummy = Qnil; return rb_call_super(0, &dummy); } argv[0] = UINT2NUM(array->field->offset); argv[1] = UINT2NUM(array->length); return rb_funcall2(array->rbMemory, rb_intern("get_string"), 2, argv); } /* * call-seq: to_ptr * @return [AbstractMemory] * Get pointer to +self+ content. */ static VALUE inline_array_to_ptr(VALUE self) { InlineArray* array; Data_Get_Struct(self, InlineArray, array); return rb_funcall(array->rbMemory, rb_intern("slice"), 2, UINT2NUM(array->field->offset), UINT2NUM(array->arrayType->base.ffiType->size)); } void rbffi_Struct_Init(VALUE moduleFFI) { VALUE StructClass; rbffi_StructLayout_Init(moduleFFI); /* * Document-class: FFI::Struct * * A FFI::Struct means to mirror a C struct. * * A Struct is defined as: * class MyStruct < FFI::Struct * layout :value1, :int, * :value2, :double * end * and is used as: * my_struct = MyStruct.new * my_struct[:value1] = 12 * * For more information, see http://github.com/ffi/ffi/wiki/Structs */ rbffi_StructClass = rb_define_class_under(moduleFFI, "Struct", rb_cObject); StructClass = rbffi_StructClass; // put on a line alone to help RDoc rb_global_variable(&rbffi_StructClass); /* * Document-class: FFI::Struct::InlineArray */ rbffi_StructInlineArrayClass = rb_define_class_under(rbffi_StructClass, "InlineArray", rb_cObject); rb_global_variable(&rbffi_StructInlineArrayClass); /* * Document-class: FFI::StructLayout::CharArray < FFI::Struct::InlineArray */ rbffi_StructLayoutCharArrayClass = rb_define_class_under(rbffi_StructLayoutClass, "CharArray", rbffi_StructInlineArrayClass); rb_global_variable(&rbffi_StructLayoutCharArrayClass); rb_define_alloc_func(StructClass, struct_allocate); rb_define_method(StructClass, "initialize", struct_initialize, -1); rb_define_method(StructClass, "initialize_copy", struct_initialize_copy, 1); rb_define_method(StructClass, "order", struct_order, -1); rb_define_alias(rb_singleton_class(StructClass), "alloc_in", "new"); rb_define_alias(rb_singleton_class(StructClass), "alloc_out", "new"); rb_define_alias(rb_singleton_class(StructClass), "alloc_inout", "new"); rb_define_alias(rb_singleton_class(StructClass), "new_in", "new"); rb_define_alias(rb_singleton_class(StructClass), "new_out", "new"); rb_define_alias(rb_singleton_class(StructClass), "new_inout", "new"); rb_define_method(StructClass, "pointer", struct_get_pointer, 0); rb_define_private_method(StructClass, "pointer=", struct_set_pointer, 1); rb_define_method(StructClass, "layout", struct_get_layout, 0); rb_define_private_method(StructClass, "layout=", struct_set_layout, 1); rb_define_method(StructClass, "[]", struct_aref, 1); rb_define_method(StructClass, "[]=", struct_aset, 2); rb_define_method(StructClass, "null?", struct_null_p, 0); rb_include_module(rbffi_StructInlineArrayClass, rb_mEnumerable); rb_define_alloc_func(rbffi_StructInlineArrayClass, inline_array_allocate); rb_define_method(rbffi_StructInlineArrayClass, "initialize", inline_array_initialize, 2); rb_define_method(rbffi_StructInlineArrayClass, "[]", inline_array_aref, 1); rb_define_method(rbffi_StructInlineArrayClass, "[]=", inline_array_aset, 2); rb_define_method(rbffi_StructInlineArrayClass, "each", inline_array_each, 0); rb_define_method(rbffi_StructInlineArrayClass, "size", inline_array_size, 0); rb_define_method(rbffi_StructInlineArrayClass, "to_a", inline_array_to_a, 0); rb_define_method(rbffi_StructInlineArrayClass, "to_ptr", inline_array_to_ptr, 0); rb_define_method(rbffi_StructLayoutCharArrayClass, "to_s", inline_array_to_s, 0); rb_define_alias(rbffi_StructLayoutCharArrayClass, "to_str", "to_s"); id_pointer_ivar = rb_intern("@pointer"); id_layout_ivar = rb_intern("@layout"); id_layout = rb_intern("layout"); id_get = rb_intern("get"); id_put = rb_intern("put"); id_to_ptr = rb_intern("to_ptr"); id_to_s = rb_intern("to_s"); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/FunctionInfo.c0000644000175000017500000002210312261216357022201 0ustar terceiroterceiro/* * Copyright (c) 2009, Wayne Meissner * Copyright (C) 2009 Andrea Fazzi * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER # include #endif #include #include #ifndef _MSC_VER # include # include #else # include "win32/stdbool.h" #endif #include #include #include #include "rbffi.h" #include "compat.h" #include "AbstractMemory.h" #include "Types.h" #include "Type.h" #include "StructByValue.h" #include "Function.h" static VALUE fntype_allocate(VALUE klass); static VALUE fntype_initialize(int argc, VALUE* argv, VALUE self); static void fntype_mark(FunctionType*); static void fntype_free(FunctionType *); VALUE rbffi_FunctionTypeClass = Qnil; static VALUE fntype_allocate(VALUE klass) { FunctionType* fnInfo; VALUE obj = Data_Make_Struct(klass, FunctionType, fntype_mark, fntype_free, fnInfo); fnInfo->type.ffiType = &ffi_type_pointer; fnInfo->type.nativeType = NATIVE_FUNCTION; fnInfo->rbReturnType = Qnil; fnInfo->rbParameterTypes = Qnil; fnInfo->rbEnums = Qnil; fnInfo->invoke = rbffi_CallFunction; fnInfo->closurePool = NULL; return obj; } static void fntype_mark(FunctionType* fnInfo) { rb_gc_mark(fnInfo->rbReturnType); rb_gc_mark(fnInfo->rbParameterTypes); rb_gc_mark(fnInfo->rbEnums); if (fnInfo->callbackCount > 0 && fnInfo->callbackParameters != NULL) { rb_gc_mark_locations(&fnInfo->callbackParameters[0], &fnInfo->callbackParameters[fnInfo->callbackCount]); } } static void fntype_free(FunctionType* fnInfo) { xfree(fnInfo->parameterTypes); xfree(fnInfo->ffiParameterTypes); xfree(fnInfo->nativeParameterTypes); xfree(fnInfo->callbackParameters); if (fnInfo->closurePool != NULL) { rbffi_ClosurePool_Free(fnInfo->closurePool); } xfree(fnInfo); } /* * call-seq: initialize(return_type, param_types, options={}) * @param [Type, Symbol] return_type return type for the function * @param [Array] param_types array of parameters types * @param [Hash] options * @option options [Boolean] :blocking set to true if the C function is a blocking call * @option options [Symbol] :convention calling convention see {FFI::Library#calling_convention} * @option options [FFI::Enums] :enums * @return [self] * A new FunctionType instance. */ static VALUE fntype_initialize(int argc, VALUE* argv, VALUE self) { FunctionType *fnInfo; ffi_status status; VALUE rbReturnType = Qnil, rbParamTypes = Qnil, rbOptions = Qnil; VALUE rbEnums = Qnil, rbConvention = Qnil, rbBlocking = Qnil; #if defined(_WIN32) || defined(__WIN32__) VALUE rbConventionStr; #endif int i, nargs; nargs = rb_scan_args(argc, argv, "21", &rbReturnType, &rbParamTypes, &rbOptions); if (nargs >= 3 && rbOptions != Qnil) { rbConvention = rb_hash_aref(rbOptions, ID2SYM(rb_intern("convention"))); rbEnums = rb_hash_aref(rbOptions, ID2SYM(rb_intern("enums"))); rbBlocking = rb_hash_aref(rbOptions, ID2SYM(rb_intern("blocking"))); } Check_Type(rbParamTypes, T_ARRAY); Data_Get_Struct(self, FunctionType, fnInfo); fnInfo->parameterCount = (int) RARRAY_LEN(rbParamTypes); fnInfo->parameterTypes = xcalloc(fnInfo->parameterCount, sizeof(*fnInfo->parameterTypes)); fnInfo->ffiParameterTypes = xcalloc(fnInfo->parameterCount, sizeof(ffi_type *)); fnInfo->nativeParameterTypes = xcalloc(fnInfo->parameterCount, sizeof(*fnInfo->nativeParameterTypes)); fnInfo->rbParameterTypes = rb_ary_new2(fnInfo->parameterCount); fnInfo->rbEnums = rbEnums; fnInfo->blocking = RTEST(rbBlocking); fnInfo->hasStruct = false; for (i = 0; i < fnInfo->parameterCount; ++i) { VALUE entry = rb_ary_entry(rbParamTypes, i); VALUE type = rbffi_Type_Lookup(entry); if (!RTEST(type)) { VALUE typeName = rb_funcall2(entry, rb_intern("inspect"), 0, NULL); rb_raise(rb_eTypeError, "Invalid parameter type (%s)", RSTRING_PTR(typeName)); } if (rb_obj_is_kind_of(type, rbffi_FunctionTypeClass)) { REALLOC_N(fnInfo->callbackParameters, VALUE, fnInfo->callbackCount + 1); fnInfo->callbackParameters[fnInfo->callbackCount++] = type; } if (rb_obj_is_kind_of(type, rbffi_StructByValueClass)) { fnInfo->hasStruct = true; } rb_ary_push(fnInfo->rbParameterTypes, type); Data_Get_Struct(type, Type, fnInfo->parameterTypes[i]); fnInfo->ffiParameterTypes[i] = fnInfo->parameterTypes[i]->ffiType; fnInfo->nativeParameterTypes[i] = fnInfo->parameterTypes[i]->nativeType; } fnInfo->rbReturnType = rbffi_Type_Lookup(rbReturnType); if (!RTEST(fnInfo->rbReturnType)) { VALUE typeName = rb_funcall2(rbReturnType, rb_intern("inspect"), 0, NULL); rb_raise(rb_eTypeError, "Invalid return type (%s)", RSTRING_PTR(typeName)); } if (rb_obj_is_kind_of(fnInfo->rbReturnType, rbffi_StructByValueClass)) { fnInfo->hasStruct = true; } Data_Get_Struct(fnInfo->rbReturnType, Type, fnInfo->returnType); fnInfo->ffiReturnType = fnInfo->returnType->ffiType; #if (defined(_WIN32) || defined(__WIN32__)) && defined(FFI_STDCALL) rbConventionStr = (rbConvention != Qnil) ? rb_funcall2(rbConvention, rb_intern("to_s"), 0, NULL) : Qnil; fnInfo->abi = (rbConventionStr != Qnil && strcmp(StringValueCStr(rbConventionStr), "stdcall") == 0) ? FFI_STDCALL : FFI_DEFAULT_ABI; #else fnInfo->abi = FFI_DEFAULT_ABI; #endif status = ffi_prep_cif(&fnInfo->ffi_cif, fnInfo->abi, fnInfo->parameterCount, fnInfo->ffiReturnType, fnInfo->ffiParameterTypes); switch (status) { case FFI_BAD_ABI: rb_raise(rb_eArgError, "Invalid ABI specified"); case FFI_BAD_TYPEDEF: rb_raise(rb_eArgError, "Invalid argument type specified"); case FFI_OK: break; default: rb_raise(rb_eArgError, "Unknown FFI error"); } fnInfo->invoke = rbffi_GetInvoker(fnInfo); return self; } /* * call-seq: result_type * @return [Type] * Get the return type of the function type */ static VALUE fntype_result_type(VALUE self) { FunctionType* ft; Data_Get_Struct(self, FunctionType, ft); return ft->rbReturnType; } /* * call-seq: param_types * @return [Array] * Get parameters types. */ static VALUE fntype_param_types(VALUE self) { FunctionType* ft; Data_Get_Struct(self, FunctionType, ft); return rb_ary_dup(ft->rbParameterTypes); } void rbffi_FunctionInfo_Init(VALUE moduleFFI) { VALUE ffi_Type; ffi_Type = rbffi_TypeClass; /* * Document-class: FFI::FunctionType < FFI::Type */ rbffi_FunctionTypeClass = rb_define_class_under(moduleFFI, "FunctionType",ffi_Type); rb_global_variable(&rbffi_FunctionTypeClass); /* * Document-const: FFI::CallbackInfo = FFI::FunctionType */ rb_define_const(moduleFFI, "CallbackInfo", rbffi_FunctionTypeClass); /* * Document-const: FFI::FunctionInfo = FFI::FunctionType */ rb_define_const(moduleFFI, "FunctionInfo", rbffi_FunctionTypeClass); /* * Document-const: FFI::Type::Function = FFI::FunctionType */ rb_define_const(ffi_Type, "Function", rbffi_FunctionTypeClass); rb_define_alloc_func(rbffi_FunctionTypeClass, fntype_allocate); rb_define_method(rbffi_FunctionTypeClass, "initialize", fntype_initialize, -1); rb_define_method(rbffi_FunctionTypeClass, "result_type", fntype_result_type, 0); rb_define_method(rbffi_FunctionTypeClass, "param_types", fntype_param_types, 0); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/StructByReference.h0000644000175000017500000000355712261216360023211 0ustar terceiroterceiro/* * Copyright (c) 2009, Wayne Meissner * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * The name of the author or authors may not be used to endorse or promote * products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_STRUCTBYREFERENCE_H #define RBFFI_STRUCTBYREFERENCE_H #include #ifdef __cplusplus extern "C" { #endif typedef struct StructByReference_ { VALUE rbStructClass; } StructByReference; void rbffi_StructByReference_Init(VALUE moduleFFI); extern VALUE rbffi_StructByReferenceClass; #ifdef __cplusplus } #endif #endif /* RBFFI_STRUCTBYREFERENCE_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/AbstractMemory.c0000644000175000017500000010331312261216357022537 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * Copyright (C) 2009 Jake Douglas * Copyright (C) 2008 Luc Heinrich * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #ifndef _MSC_VER # include # include # include #else # include "win32/stdbool.h" # include "win32/stdint.h" #endif #include #include #include "rbffi.h" #include "compat.h" #include "AbstractMemory.h" #include "Pointer.h" #include "Function.h" #include "LongDouble.h" static inline char* memory_address(VALUE self); VALUE rbffi_AbstractMemoryClass = Qnil; static VALUE NullPointerErrorClass = Qnil; static ID id_to_ptr = 0, id_plus = 0, id_call = 0; static VALUE memory_allocate(VALUE klass) { AbstractMemory* memory; VALUE obj; obj = Data_Make_Struct(klass, AbstractMemory, NULL, -1, memory); memory->flags = MEM_RD | MEM_WR; return obj; } #define VAL(x, swap) (unlikely(((memory->flags & MEM_SWAP) != 0)) ? swap((x)) : (x)) #define NUM_OP(name, type, toNative, fromNative, swap) \ static void memory_op_put_##name(AbstractMemory* memory, long off, VALUE value); \ static void \ memory_op_put_##name(AbstractMemory* memory, long off, VALUE value) \ { \ type tmp = (type) VAL(toNative(value), swap); \ checkWrite(memory); \ checkBounds(memory, off, sizeof(type)); \ memcpy(memory->address + off, &tmp, sizeof(tmp)); \ } \ static VALUE memory_put_##name(VALUE self, VALUE offset, VALUE value); \ static VALUE \ memory_put_##name(VALUE self, VALUE offset, VALUE value) \ { \ AbstractMemory* memory; \ Data_Get_Struct(self, AbstractMemory, memory); \ memory_op_put_##name(memory, NUM2LONG(offset), value); \ return self; \ } \ static VALUE memory_write_##name(VALUE self, VALUE value); \ static VALUE \ memory_write_##name(VALUE self, VALUE value) \ { \ AbstractMemory* memory; \ Data_Get_Struct(self, AbstractMemory, memory); \ memory_op_put_##name(memory, 0, value); \ return self; \ } \ static VALUE memory_op_get_##name(AbstractMemory* memory, long off); \ static VALUE \ memory_op_get_##name(AbstractMemory* memory, long off) \ { \ type tmp; \ checkRead(memory); \ checkBounds(memory, off, sizeof(type)); \ memcpy(&tmp, memory->address + off, sizeof(tmp)); \ return fromNative(VAL(tmp, swap)); \ } \ static VALUE memory_get_##name(VALUE self, VALUE offset); \ static VALUE \ memory_get_##name(VALUE self, VALUE offset) \ { \ AbstractMemory* memory; \ Data_Get_Struct(self, AbstractMemory, memory); \ return memory_op_get_##name(memory, NUM2LONG(offset)); \ } \ static VALUE memory_read_##name(VALUE self); \ static VALUE \ memory_read_##name(VALUE self) \ { \ AbstractMemory* memory; \ Data_Get_Struct(self, AbstractMemory, memory); \ return memory_op_get_##name(memory, 0); \ } \ static MemoryOp memory_op_##name = { memory_op_get_##name, memory_op_put_##name }; \ \ static VALUE memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary); \ static VALUE \ memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary) \ { \ long count = RARRAY_LEN(ary); \ long off = NUM2LONG(offset); \ AbstractMemory* memory = MEMORY(self); \ long i; \ checkWrite(memory); \ checkBounds(memory, off, count * sizeof(type)); \ for (i = 0; i < count; i++) { \ type tmp = (type) VAL(toNative(RARRAY_PTR(ary)[i]), swap); \ memcpy(memory->address + off + (i * sizeof(type)), &tmp, sizeof(tmp)); \ } \ return self; \ } \ static VALUE memory_write_array_of_##name(VALUE self, VALUE ary); \ static VALUE \ memory_write_array_of_##name(VALUE self, VALUE ary) \ { \ return memory_put_array_of_##name(self, INT2FIX(0), ary); \ } \ static VALUE memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length); \ static VALUE \ memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length) \ { \ long count = NUM2LONG(length); \ long off = NUM2LONG(offset); \ AbstractMemory* memory = MEMORY(self); \ VALUE retVal = rb_ary_new2(count); \ long i; \ checkRead(memory); \ checkBounds(memory, off, count * sizeof(type)); \ for (i = 0; i < count; ++i) { \ type tmp; \ memcpy(&tmp, memory->address + off + (i * sizeof(type)), sizeof(tmp)); \ rb_ary_push(retVal, fromNative(VAL(tmp, swap))); \ } \ return retVal; \ } \ static VALUE memory_read_array_of_##name(VALUE self, VALUE length); \ static VALUE \ memory_read_array_of_##name(VALUE self, VALUE length) \ { \ return memory_get_array_of_##name(self, INT2FIX(0), length); \ } #define NOSWAP(x) (x) #define bswap16(x) (((x) >> 8) & 0xff) | (((x) << 8) & 0xff00); static inline int16_t SWAPS16(int16_t x) { return bswap16(x); } static inline uint16_t SWAPU16(uint16_t x) { return bswap16(x); } #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) #define bswap32(x) \ (((x << 24) & 0xff000000) | \ ((x << 8) & 0x00ff0000) | \ ((x >> 8) & 0x0000ff00) | \ ((x >> 24) & 0x000000ff)) #define bswap64(x) \ (((x << 56) & 0xff00000000000000ULL) | \ ((x << 40) & 0x00ff000000000000ULL) | \ ((x << 24) & 0x0000ff0000000000ULL) | \ ((x << 8) & 0x000000ff00000000ULL) | \ ((x >> 8) & 0x00000000ff000000ULL) | \ ((x >> 24) & 0x0000000000ff0000ULL) | \ ((x >> 40) & 0x000000000000ff00ULL) | \ ((x >> 56) & 0x00000000000000ffULL)) static inline int32_t SWAPS32(int32_t x) { return bswap32(x); } static inline uint32_t SWAPU32(uint32_t x) { return bswap32(x); } static inline int64_t SWAPS64(int64_t x) { return bswap64(x); } static inline uint64_t SWAPU64(uint64_t x) { return bswap64(x); } #else # define SWAPS32(x) ((int32_t) __builtin_bswap32(x)) # define SWAPU32(x) ((uint32_t) __builtin_bswap32(x)) # define SWAPS64(x) ((int64_t) __builtin_bswap64(x)) # define SWAPU64(x) ((uint64_t) __builtin_bswap64(x)) #endif #if LONG_MAX > INT_MAX # define SWAPSLONG SWAPS64 # define SWAPULONG SWAPU64 #else # define SWAPSLONG SWAPS32 # define SWAPULONG SWAPU32 #endif NUM_OP(int8, int8_t, NUM2INT, INT2NUM, NOSWAP); NUM_OP(uint8, uint8_t, NUM2UINT, UINT2NUM, NOSWAP); NUM_OP(int16, int16_t, NUM2INT, INT2NUM, SWAPS16); NUM_OP(uint16, uint16_t, NUM2UINT, UINT2NUM, SWAPU16); NUM_OP(int32, int32_t, NUM2INT, INT2NUM, SWAPS32); NUM_OP(uint32, uint32_t, NUM2UINT, UINT2NUM, SWAPU32); NUM_OP(int64, int64_t, NUM2LL, LL2NUM, SWAPS64); NUM_OP(uint64, uint64_t, NUM2ULL, ULL2NUM, SWAPU64); NUM_OP(long, long, NUM2LONG, LONG2NUM, SWAPSLONG); NUM_OP(ulong, unsigned long, NUM2ULONG, ULONG2NUM, SWAPULONG); NUM_OP(float32, float, NUM2DBL, rb_float_new, NOSWAP); NUM_OP(float64, double, NUM2DBL, rb_float_new, NOSWAP); NUM_OP(longdouble, long double, rbffi_num2longdouble, rbffi_longdouble_new, NOSWAP); static inline void* get_pointer_value(VALUE value) { const int type = TYPE(value); if (type == T_DATA && rb_obj_is_kind_of(value, rbffi_PointerClass)) { return memory_address(value); } else if (type == T_NIL) { return NULL; } else if (type == T_FIXNUM) { return (void *) (uintptr_t) FIX2ULONG(value); } else if (type == T_BIGNUM) { return (void *) (uintptr_t) NUM2ULL(value); } else if (rb_respond_to(value, id_to_ptr)) { return MEMORY_PTR(rb_funcall2(value, id_to_ptr, 0, NULL)); } else { rb_raise(rb_eArgError, "value is not a pointer"); return NULL; } } NUM_OP(pointer, void *, get_pointer_value, rbffi_Pointer_NewInstance, NOSWAP); static inline uint8_t rbffi_bool_value(VALUE value) { return RTEST(value); } static inline VALUE rbffi_bool_new(uint8_t value) { return (value & 1) != 0 ? Qtrue : Qfalse; } NUM_OP(bool, unsigned char, rbffi_bool_value, rbffi_bool_new, NOSWAP); /* * call-seq: memory.clear * Set the memory to all-zero. * @return [self] */ static VALUE memory_clear(VALUE self) { AbstractMemory* ptr = MEMORY(self); memset(ptr->address, 0, ptr->size); return self; } /* * call-seq: memory.size * Return memory size in bytes (alias: #total) * @return [Numeric] */ static VALUE memory_size(VALUE self) { AbstractMemory* ptr; Data_Get_Struct(self, AbstractMemory, ptr); return LONG2NUM(ptr->size); } /* * call-seq: memory.get_string(offset, length=nil) * Return string contained in memory. * @param [Numeric] offset point in buffer to start from * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned). * @return [String] * @raise {IndexError} if +length+ is too great * @raise {NullPointerError} if memory not initialized */ static VALUE memory_get_string(int argc, VALUE* argv, VALUE self) { VALUE length = Qnil, offset = Qnil; AbstractMemory* ptr = MEMORY(self); long off, len; char* end; int nargs = rb_scan_args(argc, argv, "11", &offset, &length); off = NUM2LONG(offset); len = nargs > 1 && length != Qnil ? NUM2LONG(length) : (ptr->size - off); checkRead(ptr); checkBounds(ptr, off, len); end = memchr(ptr->address + off, 0, len); return rb_tainted_str_new((char *) ptr->address + off, (end != NULL ? end - ptr->address - off : len)); } /* * call-seq: memory.get_array_of_string(offset, count=nil) * Return an array of strings contained in memory. * @param [Numeric] offset point in memory to start from * @param [Numeric] count number of strings to get. If nil, return all strings * @return [Array] * @raise {IndexError} if +offset+ is too great * @raise {NullPointerError} if memory not initialized */ static VALUE memory_get_array_of_string(int argc, VALUE* argv, VALUE self) { VALUE offset = Qnil, countnum = Qnil, retVal = Qnil; AbstractMemory* ptr; long off; int count; rb_scan_args(argc, argv, "11", &offset, &countnum); off = NUM2LONG(offset); count = (countnum == Qnil ? 0 : NUM2INT(countnum)); retVal = rb_ary_new2(count); Data_Get_Struct(self, AbstractMemory, ptr); checkRead(ptr); if (countnum != Qnil) { int i; checkBounds(ptr, off, count * sizeof (char*)); for (i = 0; i < count; ++i) { const char* strptr = *((const char**) (ptr->address + off) + i); rb_ary_push(retVal, (strptr == NULL ? Qnil : rb_tainted_str_new2(strptr))); } } else { checkBounds(ptr, off, sizeof (char*)); for ( ; off < ptr->size - (long) sizeof (void *); off += (long) sizeof (void *)) { const char* strptr = *(const char**) (ptr->address + off); if (strptr == NULL) { break; } rb_ary_push(retVal, rb_tainted_str_new2(strptr)); } } return retVal; } /* * call-seq: memory.read_array_of_string(count=nil) * Return an array of strings contained in memory. Same as: * memory.get_array_of_string(0, count) * @param [Numeric] count number of strings to get. If nil, return all strings * @return [Array] */ static VALUE memory_read_array_of_string(int argc, VALUE* argv, VALUE self) { VALUE* rargv = ALLOCA_N(VALUE, argc + 1); int i; rargv[0] = INT2FIX(0); for (i = 0; i < argc; i++) { rargv[i + 1] = argv[i]; } return memory_get_array_of_string(argc + 1, rargv, self); } /* * call-seq: memory.put_string(offset, str) * @param [Numeric] offset * @param [String] str * @return [self] * @raise {SecurityError} when writing unsafe string to memory * @raise {IndexError} if +offset+ is too great * @raise {NullPointerError} if memory not initialized * Put a string in memory. */ static VALUE memory_put_string(VALUE self, VALUE offset, VALUE str) { AbstractMemory* ptr = MEMORY(self); long off, len; Check_Type(str, T_STRING); off = NUM2LONG(offset); len = RSTRING_LEN(str); checkWrite(ptr); checkBounds(ptr, off, len + 1); memcpy(ptr->address + off, RSTRING_PTR(str), len); *((char *) ptr->address + off + len) = '\0'; return self; } /* * call-seq: memory.get_bytes(offset, length) * Return string contained in memory. * @param [Numeric] offset point in buffer to start from * @param [Numeric] length string's length in bytes. * @return [String] * @raise {IndexError} if +length+ is too great * @raise {NullPointerError} if memory not initialized */ static VALUE memory_get_bytes(VALUE self, VALUE offset, VALUE length) { AbstractMemory* ptr = MEMORY(self); long off, len; off = NUM2LONG(offset); len = NUM2LONG(length); checkRead(ptr); checkBounds(ptr, off, len); return rb_tainted_str_new((char *) ptr->address + off, len); } /* * call-seq: memory.put_bytes(offset, str, index=0, length=nil) * Put a string in memory. * @param [Numeric] offset point in buffer to start from * @param [String] str string to put to memory * @param [Numeric] index * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned). * @return [self] * @raise {IndexError} if +length+ is too great * @raise {NullPointerError} if memory not initialized * @raise {RangeError} if +index+ is negative, or if index+length is greater than size of string * @raise {SecurityError} when writing unsafe string to memory */ static VALUE memory_put_bytes(int argc, VALUE* argv, VALUE self) { AbstractMemory* ptr = MEMORY(self); VALUE offset = Qnil, str = Qnil, rbIndex = Qnil, rbLength = Qnil; long off, len, idx; int nargs = rb_scan_args(argc, argv, "22", &offset, &str, &rbIndex, &rbLength); Check_Type(str, T_STRING); off = NUM2LONG(offset); idx = nargs > 2 ? NUM2LONG(rbIndex) : 0; if (idx < 0) { rb_raise(rb_eRangeError, "index canot be less than zero"); return Qnil; } len = nargs > 3 ? NUM2LONG(rbLength) : (RSTRING_LEN(str) - idx); if ((idx + len) > RSTRING_LEN(str)) { rb_raise(rb_eRangeError, "index+length is greater than size of string"); return Qnil; } checkWrite(ptr); checkBounds(ptr, off, len); if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) { rb_raise(rb_eSecurityError, "Writing unsafe string to memory"); return Qnil; } memcpy(ptr->address + off, RSTRING_PTR(str) + idx, len); return self; } /* * call-seq: memory.read_bytes(length) * @param [Numeric] length of string to return * @return [String] * equivalent to : * memory.get_bytes(0, length) */ static VALUE memory_read_bytes(VALUE self, VALUE length) { return memory_get_bytes(self, INT2FIX(0), length); } /* * call-seq: memory.write_bytes(str, index=0, length=nil) * @param [String] str string to put to memory * @param [Numeric] index * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned). * @return [self] * equivalent to : * memory.put_bytes(0, str, index, length) */ static VALUE memory_write_bytes(int argc, VALUE* argv, VALUE self) { VALUE* wargv = ALLOCA_N(VALUE, argc + 1); int i; wargv[0] = INT2FIX(0); for (i = 0; i < argc; i++) { wargv[i + 1] = argv[i]; } return memory_put_bytes(argc + 1, wargv, self); } /* * call-seq: memory.type_size * @return [Numeric] type size in bytes * Get the memory's type size. */ static VALUE memory_type_size(VALUE self) { AbstractMemory* ptr; Data_Get_Struct(self, AbstractMemory, ptr); return INT2NUM(ptr->typeSize); } /* * Document-method: [] * call-seq: memory[idx] * @param [Numeric] idx index to access in memory * @return * Memory read accessor. */ static VALUE memory_aref(VALUE self, VALUE idx) { AbstractMemory* ptr; VALUE rbOffset = Qnil; Data_Get_Struct(self, AbstractMemory, ptr); rbOffset = ULONG2NUM(NUM2ULONG(idx) * ptr->typeSize); return rb_funcall2(self, id_plus, 1, &rbOffset); } static inline char* memory_address(VALUE obj) { return ((AbstractMemory *) DATA_PTR(obj))->address; } static VALUE memory_copy_from(VALUE self, VALUE rbsrc, VALUE rblen) { AbstractMemory* dst; Data_Get_Struct(self, AbstractMemory, dst); memcpy(dst->address, rbffi_AbstractMemory_Cast(rbsrc, rbffi_AbstractMemoryClass)->address, NUM2INT(rblen)); return self; } AbstractMemory* rbffi_AbstractMemory_Cast(VALUE obj, VALUE klass) { if (rb_obj_is_kind_of(obj, klass)) { AbstractMemory* memory; Data_Get_Struct(obj, AbstractMemory, memory); return memory; } rb_raise(rb_eArgError, "Invalid Memory object"); return NULL; } void rbffi_AbstractMemory_Error(AbstractMemory *mem, int op) { VALUE rbErrorClass = mem->address == NULL ? NullPointerErrorClass : rb_eRuntimeError; if (op == MEM_RD) { rb_raise(rbErrorClass, "invalid memory read at address=%p", mem->address); } else if (op == MEM_WR) { rb_raise(rbErrorClass, "invalid memory write at address=%p", mem->address); } else { rb_raise(rbErrorClass, "invalid memory access at address=%p", mem->address); } } static VALUE memory_op_get_strptr(AbstractMemory* ptr, long offset) { void* tmp = NULL; if (ptr != NULL && ptr->address != NULL) { checkRead(ptr); checkBounds(ptr, offset, sizeof(tmp)); memcpy(&tmp, ptr->address + offset, sizeof(tmp)); } return tmp != NULL ? rb_tainted_str_new2(tmp) : Qnil; } static void memory_op_put_strptr(AbstractMemory* ptr, long offset, VALUE value) { rb_raise(rb_eArgError, "Cannot set :string fields"); } static MemoryOp memory_op_strptr = { memory_op_get_strptr, memory_op_put_strptr }; MemoryOps rbffi_AbstractMemoryOps = { &memory_op_int8, /*.int8 */ &memory_op_uint8, /* .uint8 */ &memory_op_int16, /* .int16 */ &memory_op_uint16, /* .uint16 */ &memory_op_int32, /* .int32 */ &memory_op_uint32, /* .uint32 */ &memory_op_int64, /* .int64 */ &memory_op_uint64, /* .uint64 */ &memory_op_long, /* .slong */ &memory_op_ulong, /* .uslong */ &memory_op_float32, /* .float32 */ &memory_op_float64, /* .float64 */ &memory_op_longdouble, /* .longdouble */ &memory_op_pointer, /* .pointer */ &memory_op_strptr, /* .strptr */ &memory_op_bool /* .boolOp */ }; void rbffi_AbstractMemory_Init(VALUE moduleFFI) { /* * Document-class: FFI::AbstractMemory * * {AbstractMemory} is the base class for many memory management classes such as {Buffer}. * * This class has a lot of methods to work with integers : * * put_intsize(offset, value) * * get_intsize(offset) * * put_uintsize(offset, value) * * get_uintsize(offset) * * writeuintsize(value) * * read_intsize * * write_uintsize(value) * * read_uintsize * * put_array_of_intsize(offset, ary) * * get_array_of_intsize(offset, length) * * put_array_of_uintsize(offset, ary) * * get_array_of_uintsize(offset, length) * * write_array_of_intsize(ary) * * read_array_of_intsize(length) * * write_array_of_uintsize(ary) * * read_array_of_uintsize(length) * where _size_ is 8, 16, 32 or 64. Same methods exist for long type. * * Aliases exist : _char_ for _int8_, _short_ for _int16_, _int_ for _int32_ and long_long for _int64_. * * Others methods are listed below. */ VALUE classMemory = rb_define_class_under(moduleFFI, "AbstractMemory", rb_cObject); rbffi_AbstractMemoryClass = classMemory; /* * Document-variable: FFI::AbstractMemory */ rb_global_variable(&rbffi_AbstractMemoryClass); rb_define_alloc_func(classMemory, memory_allocate); NullPointerErrorClass = rb_define_class_under(moduleFFI, "NullPointerError", rb_eRuntimeError); /* Document-variable: NullPointerError */ rb_global_variable(&NullPointerErrorClass); #undef INT #define INT(type) \ rb_define_method(classMemory, "put_" #type, memory_put_##type, 2); \ rb_define_method(classMemory, "get_" #type, memory_get_##type, 1); \ rb_define_method(classMemory, "put_u" #type, memory_put_u##type, 2); \ rb_define_method(classMemory, "get_u" #type, memory_get_u##type, 1); \ rb_define_method(classMemory, "write_" #type, memory_write_##type, 1); \ rb_define_method(classMemory, "read_" #type, memory_read_##type, 0); \ rb_define_method(classMemory, "write_u" #type, memory_write_u##type, 1); \ rb_define_method(classMemory, "read_u" #type, memory_read_u##type, 0); \ rb_define_method(classMemory, "put_array_of_" #type, memory_put_array_of_##type, 2); \ rb_define_method(classMemory, "get_array_of_" #type, memory_get_array_of_##type, 2); \ rb_define_method(classMemory, "put_array_of_u" #type, memory_put_array_of_u##type, 2); \ rb_define_method(classMemory, "get_array_of_u" #type, memory_get_array_of_u##type, 2); \ rb_define_method(classMemory, "write_array_of_" #type, memory_write_array_of_##type, 1); \ rb_define_method(classMemory, "read_array_of_" #type, memory_read_array_of_##type, 1); \ rb_define_method(classMemory, "write_array_of_u" #type, memory_write_array_of_u##type, 1); \ rb_define_method(classMemory, "read_array_of_u" #type, memory_read_array_of_u##type, 1); INT(int8); INT(int16); INT(int32); INT(int64); INT(long); #define ALIAS(name, old) \ rb_define_alias(classMemory, "put_" #name, "put_" #old); \ rb_define_alias(classMemory, "get_" #name, "get_" #old); \ rb_define_alias(classMemory, "put_u" #name, "put_u" #old); \ rb_define_alias(classMemory, "get_u" #name, "get_u" #old); \ rb_define_alias(classMemory, "write_" #name, "write_" #old); \ rb_define_alias(classMemory, "read_" #name, "read_" #old); \ rb_define_alias(classMemory, "write_u" #name, "write_u" #old); \ rb_define_alias(classMemory, "read_u" #name, "read_u" #old); \ rb_define_alias(classMemory, "put_array_of_" #name, "put_array_of_" #old); \ rb_define_alias(classMemory, "get_array_of_" #name, "get_array_of_" #old); \ rb_define_alias(classMemory, "put_array_of_u" #name, "put_array_of_u" #old); \ rb_define_alias(classMemory, "get_array_of_u" #name, "get_array_of_u" #old); \ rb_define_alias(classMemory, "write_array_of_" #name, "write_array_of_" #old); \ rb_define_alias(classMemory, "read_array_of_" #name, "read_array_of_" #old); \ rb_define_alias(classMemory, "write_array_of_u" #name, "write_array_of_u" #old); \ rb_define_alias(classMemory, "read_array_of_u" #name, "read_array_of_u" #old); ALIAS(char, int8); ALIAS(short, int16); ALIAS(int, int32); ALIAS(long_long, int64); /* * Document-method: put_float32 * call-seq: memory.put_float32offset, value) * @param [Numeric] offset * @param [Numeric] value * @return [self] * Put +value+ as a 32-bit float in memory at offset +offset+ (alias: #put_float). */ rb_define_method(classMemory, "put_float32", memory_put_float32, 2); /* * Document-method: get_float32 * call-seq: memory.get_float32(offset) * @param [Numeric] offset * @return [Float] * Get a 32-bit float from memory at offset +offset+ (alias: #get_float). */ rb_define_method(classMemory, "get_float32", memory_get_float32, 1); rb_define_alias(classMemory, "put_float", "put_float32"); rb_define_alias(classMemory, "get_float", "get_float32"); /* * Document-method: write_float * call-seq: memory.write_float(value) * @param [Numeric] value * @return [self] * Write +value+ as a 32-bit float in memory. * * Same as: * memory.put_float(0, value) */ rb_define_method(classMemory, "write_float", memory_write_float32, 1); /* * Document-method: read_float * call-seq: memory.read_float * @return [Float] * Read a 32-bit float from memory. * * Same as: * memory.get_float(0) */ rb_define_method(classMemory, "read_float", memory_read_float32, 0); /* * Document-method: put_array_of_float32 * call-seq: memory.put_array_of_float32(offset, ary) * @param [Numeric] offset * @param [Array] ary * @return [self] * Put values from +ary+ as 32-bit floats in memory from offset +offset+ (alias: #put_array_of_float). */ rb_define_method(classMemory, "put_array_of_float32", memory_put_array_of_float32, 2); /* * Document-method: get_array_of_float32 * call-seq: memory.get_array_of_float32(offset, length) * @param [Numeric] offset * @param [Numeric] length number of Float to get * @return [Array] * Get 32-bit floats in memory from offset +offset+ (alias: #get_array_of_float). */ rb_define_method(classMemory, "get_array_of_float32", memory_get_array_of_float32, 2); /* * Document-method: write_array_of_float * call-seq: memory.write_array_of_float(ary) * @param [Array] ary * @return [self] * Write values from +ary+ as 32-bit floats in memory. * * Same as: * memory.put_array_of_float(0, ary) */ rb_define_method(classMemory, "write_array_of_float", memory_write_array_of_float32, 1); /* * Document-method: read_array_of_float * call-seq: memory.read_array_of_float(length) * @param [Numeric] length number of Float to read * @return [Array] * Read 32-bit floats from memory. * * Same as: * memory.get_array_of_float(0, ary) */ rb_define_method(classMemory, "read_array_of_float", memory_read_array_of_float32, 1); rb_define_alias(classMemory, "put_array_of_float", "put_array_of_float32"); rb_define_alias(classMemory, "get_array_of_float", "get_array_of_float32"); /* * Document-method: put_float64 * call-seq: memory.put_float64(offset, value) * @param [Numeric] offset * @param [Numeric] value * @return [self] * Put +value+ as a 64-bit float (double) in memory at offset +offset+ (alias: #put_double). */ rb_define_method(classMemory, "put_float64", memory_put_float64, 2); /* * Document-method: get_float64 * call-seq: memory.get_float64(offset) * @param [Numeric] offset * @return [Float] * Get a 64-bit float (double) from memory at offset +offset+ (alias: #get_double). */ rb_define_method(classMemory, "get_float64", memory_get_float64, 1); rb_define_alias(classMemory, "put_double", "put_float64"); rb_define_alias(classMemory, "get_double", "get_float64"); /* * Document-method: write_double * call-seq: memory.write_double(value) * @param [Numeric] value * @return [self] * Write +value+ as a 64-bit float (double) in memory. * * Same as: * memory.put_double(0, value) */ rb_define_method(classMemory, "write_double", memory_write_float64, 1); /* * Document-method: read_double * call-seq: memory.read_double * @return [Float] * Read a 64-bit float (double) from memory. * * Same as: * memory.get_double(0) */ rb_define_method(classMemory, "read_double", memory_read_float64, 0); /* * Document-method: put_array_of_float64 * call-seq: memory.put_array_of_float64(offset, ary) * @param [Numeric] offset * @param [Array] ary * @return [self] * Put values from +ary+ as 64-bit floats (doubles) in memory from offset +offset+ (alias: #put_array_of_double). */ rb_define_method(classMemory, "put_array_of_float64", memory_put_array_of_float64, 2); /* * Document-method: get_array_of_float64 * call-seq: memory.get_array_of_float64(offset, length) * @param [Numeric] offset * @param [Numeric] length number of Float to get * @return [Array] * Get 64-bit floats (doubles) in memory from offset +offset+ (alias: #get_array_of_double). */ rb_define_method(classMemory, "get_array_of_float64", memory_get_array_of_float64, 2); /* * Document-method: write_array_of_double * call-seq: memory.write_array_of_double(ary) * @param [Array] ary * @return [self] * Write values from +ary+ as 64-bit floats (doubles) in memory. * * Same as: * memory.put_array_of_double(0, ary) */ rb_define_method(classMemory, "write_array_of_double", memory_write_array_of_float64, 1); /* * Document-method: read_array_of_double * call-seq: memory.read_array_of_double(length) * @param [Numeric] length number of Float to read * @return [Array] * Read 64-bit floats (doubles) from memory. * * Same as: * memory.get_array_of_double(0, ary) */ rb_define_method(classMemory, "read_array_of_double", memory_read_array_of_float64, 1); rb_define_alias(classMemory, "put_array_of_double", "put_array_of_float64"); rb_define_alias(classMemory, "get_array_of_double", "get_array_of_float64"); /* * Document-method: put_pointer * call-seq: memory.put_pointer(offset, value) * @param [Numeric] offset * @param [nil,Pointer, Integer, #to_ptr] value * @return [self] * Put +value+ in memory from +offset+.. */ rb_define_method(classMemory, "put_pointer", memory_put_pointer, 2); /* * Document-method: get_pointer * call-seq: memory.get_pointer(offset) * @param [Numeric] offset * @return [Pointer] * Get a {Pointer} to the memory from +offset+. */ rb_define_method(classMemory, "get_pointer", memory_get_pointer, 1); /* * Document-method: write_pointer * call-seq: memory.write_pointer(value) * @param [nil,Pointer, Integer, #to_ptr] value * @return [self] * Write +value+ in memory. * * Equivalent to: * memory.put_pointer(0, value) */ rb_define_method(classMemory, "write_pointer", memory_write_pointer, 1); /* * Document-method: read_pointer * call-seq: memory.read_pointer * @return [Pointer] * Get a {Pointer} to the memory from base address. * * Equivalent to: * memory.get_pointer(0) */ rb_define_method(classMemory, "read_pointer", memory_read_pointer, 0); /* * Document-method: put_array_of_pointer * call-seq: memory.put_array_of_pointer(offset, ary) * @param [Numeric] offset * @param [Array<#to_ptr>] ary * @return [self] * Put an array of {Pointer} into memory from +offset+. */ rb_define_method(classMemory, "put_array_of_pointer", memory_put_array_of_pointer, 2); /* * Document-method: get_array_of_pointer * call-seq: memory.get_array_of_pointer(offset, length) * @param [Numeric] offset * @param [Numeric] length * @return [Array] * Get an array of {Pointer} of length +length+ from +offset+. */ rb_define_method(classMemory, "get_array_of_pointer", memory_get_array_of_pointer, 2); /* * Document-method: write_array_of_pointer * call-seq: memory.write_array_of_pointer(ary) * @param [Array<#to_ptr>] ary * @return [self] * Write an array of {Pointer} into memory from +offset+. * * Same as : * memory.put_array_of_pointer(0, ary) */ rb_define_method(classMemory, "write_array_of_pointer", memory_write_array_of_pointer, 1); /* * Document-method: read_array_of_pointer * call-seq: memory.read_array_of_pointer(length) * @param [Numeric] length * @return [Array] * Read an array of {Pointer} of length +length+. * * Same as: * memory.get_array_of_pointer(0, length) */ rb_define_method(classMemory, "read_array_of_pointer", memory_read_array_of_pointer, 1); rb_define_method(classMemory, "get_string", memory_get_string, -1); rb_define_method(classMemory, "put_string", memory_put_string, 2); rb_define_method(classMemory, "get_bytes", memory_get_bytes, 2); rb_define_method(classMemory, "put_bytes", memory_put_bytes, -1); rb_define_method(classMemory, "read_bytes", memory_read_bytes, 1); rb_define_method(classMemory, "write_bytes", memory_write_bytes, -1); rb_define_method(classMemory, "get_array_of_string", memory_get_array_of_string, -1); rb_define_method(classMemory, "clear", memory_clear, 0); rb_define_method(classMemory, "total", memory_size, 0); rb_define_alias(classMemory, "size", "total"); rb_define_method(classMemory, "type_size", memory_type_size, 0); rb_define_method(classMemory, "[]", memory_aref, 1); rb_define_method(classMemory, "__copy_from__", memory_copy_from, 2); id_to_ptr = rb_intern("to_ptr"); id_call = rb_intern("call"); id_plus = rb_intern("+"); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/rbffi.h0000644000175000017500000000433612261216360020677 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_RBFFI_H #define RBFFI_RBFFI_H #include #ifdef __cplusplus extern "C" { #endif #define MAX_PARAMETERS (32) extern VALUE rbffi_FFIModule; extern void rbffi_Type_Init(VALUE ffiModule); extern void rbffi_Buffer_Init(VALUE ffiModule); extern void rbffi_Invoker_Init(VALUE ffiModule); extern void rbffi_Variadic_Init(VALUE ffiModule); extern void rbffi_DataConverter_Init(VALUE ffiModule); extern VALUE rbffi_AbstractMemoryClass, rbffi_InvokerClass; extern int rbffi_type_size(VALUE type); extern void rbffi_Thread_Init(VALUE moduleFFI); #ifdef __cplusplus } #endif #endif /* RBFFI_RBFFI_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/ArrayType.c0000644000175000017500000001141612261216357021525 0ustar terceiroterceiro/* * Copyright (c) 2009, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "ArrayType.h" static VALUE array_type_s_allocate(VALUE klass); static VALUE array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength); static void array_type_mark(ArrayType *); static void array_type_free(ArrayType *); VALUE rbffi_ArrayTypeClass = Qnil; static VALUE array_type_s_allocate(VALUE klass) { ArrayType* array; VALUE obj; obj = Data_Make_Struct(klass, ArrayType, array_type_mark, array_type_free, array); array->base.nativeType = NATIVE_ARRAY; array->base.ffiType = xcalloc(1, sizeof(*array->base.ffiType)); array->base.ffiType->type = FFI_TYPE_STRUCT; array->base.ffiType->size = 0; array->base.ffiType->alignment = 0; array->rbComponentType = Qnil; return obj; } static void array_type_mark(ArrayType *array) { rb_gc_mark(array->rbComponentType); } static void array_type_free(ArrayType *array) { xfree(array->base.ffiType); xfree(array->ffiTypes); xfree(array); } /* * call-seq: initialize(component_type, length) * @param [Type] component_type * @param [Numeric] length * @return [self] * A new instance of ArrayType. */ static VALUE array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength) { ArrayType* array; int i; Data_Get_Struct(self, ArrayType, array); array->length = NUM2UINT(rbLength); array->rbComponentType = rbComponentType; Data_Get_Struct(rbComponentType, Type, array->componentType); array->ffiTypes = xcalloc(array->length + 1, sizeof(*array->ffiTypes)); array->base.ffiType->elements = array->ffiTypes; array->base.ffiType->size = array->componentType->ffiType->size * array->length; array->base.ffiType->alignment = array->componentType->ffiType->alignment; for (i = 0; i < array->length; ++i) { array->ffiTypes[i] = array->componentType->ffiType; } return self; } /* * call-seq: length * @return [Numeric] * Get array's length */ static VALUE array_type_length(VALUE self) { ArrayType* array; Data_Get_Struct(self, ArrayType, array); return UINT2NUM(array->length); } /* * call-seq: element_type * @return [Type] * Get element type. */ static VALUE array_type_element_type(VALUE self) { ArrayType* array; Data_Get_Struct(self, ArrayType, array); return array->rbComponentType; } void rbffi_ArrayType_Init(VALUE moduleFFI) { VALUE ffi_Type; ffi_Type = rbffi_TypeClass; /* * Document-class: FFI::ArrayType < FFI::Type * * This is a typed array. The type is a {NativeType native type}. */ rbffi_ArrayTypeClass = rb_define_class_under(moduleFFI, "ArrayType", ffi_Type); /* * Document-variable: FFI::ArrayType */ rb_global_variable(&rbffi_ArrayTypeClass); /* * Document-constant: FFI::Type::Array */ rb_define_const(ffi_Type, "Array", rbffi_ArrayTypeClass); rb_define_alloc_func(rbffi_ArrayTypeClass, array_type_s_allocate); rb_define_method(rbffi_ArrayTypeClass, "initialize", array_type_initialize, 2); rb_define_method(rbffi_ArrayTypeClass, "length", array_type_length, 0); rb_define_method(rbffi_ArrayTypeClass, "elem_type", array_type_element_type, 0); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/Call.c0000644000175000017500000003342612261216357020465 0ustar terceiroterceiro/* * Copyright (c) 2009, Wayne Meissner * Copyright (c) 2009, Luc Heinrich * Copyright (c) 2009, Mike Dalessio * Copyright (c) 2009, Aman Gupta. * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER #include #endif #include #include #ifndef _MSC_VER # include # include #else # include "win32/stdbool.h" # include "win32/stdint.h" #endif #include #include #if defined(HAVE_NATIVETHREAD) && (defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) && !defined(_WIN32) # include # include #endif #include #include "extconf.h" #include "rbffi.h" #include "compat.h" #include "AbstractMemory.h" #include "Pointer.h" #include "Struct.h" #include "Function.h" #include "Type.h" #include "LastError.h" #include "Call.h" #include "MappedType.h" #include "Thread.h" #include "LongDouble.h" #ifdef USE_RAW # ifndef __i386__ # error "RAW argument packing only supported on i386" # endif #define INT8_ADJ (4) #define INT16_ADJ (4) #define INT32_ADJ (4) #define INT64_ADJ (8) #define LONG_ADJ (sizeof(long)) #define FLOAT32_ADJ (4) #define FLOAT64_ADJ (8) #define ADDRESS_ADJ (sizeof(void *)) #define LONGDOUBLE_ADJ (ffi_type_longdouble.alignment) #endif /* USE_RAW */ #ifdef USE_RAW # define ADJ(p, a) ((p) = (FFIStorage*) (((char *) p) + a##_ADJ)) #else # define ADJ(p, a) (++(p)) #endif static void* callback_param(VALUE proc, VALUE cbinfo); static inline void* getPointer(VALUE value, int type); static ID id_to_ptr, id_map_symbol, id_to_native; void rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes, FFIStorage* paramStorage, void** ffiValues, VALUE* callbackParameters, int callbackCount, VALUE enums) { VALUE callbackProc = Qnil; FFIStorage* param = ¶mStorage[0]; int i, argidx, cbidx, argCount; if (unlikely(paramCount != -1 && paramCount != argc)) { if (argc == (paramCount - 1) && callbackCount == 1 && rb_block_given_p()) { callbackProc = rb_block_proc(); } else { rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, paramCount); } } argCount = paramCount != -1 ? paramCount : argc; for (i = 0, argidx = 0, cbidx = 0; i < argCount; ++i) { Type* paramType = paramTypes[i]; int type; if (unlikely(paramType->nativeType == NATIVE_MAPPED)) { VALUE values[] = { argv[argidx], Qnil }; argv[argidx] = rb_funcall2(((MappedType *) paramType)->rbConverter, id_to_native, 2, values); paramType = ((MappedType *) paramType)->type; } type = argidx < argc ? TYPE(argv[argidx]) : T_NONE; ffiValues[i] = param; switch (paramType->nativeType) { case NATIVE_INT8: param->s8 = NUM2INT(argv[argidx]); ++argidx; ADJ(param, INT8); break; case NATIVE_INT16: param->s16 = NUM2INT(argv[argidx]); ++argidx; ADJ(param, INT16); break; case NATIVE_INT32: if (unlikely(type == T_SYMBOL && enums != Qnil)) { VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]); param->s32 = NUM2INT(value); } else { param->s32 = NUM2INT(argv[argidx]); } ++argidx; ADJ(param, INT32); break; case NATIVE_BOOL: if (type != T_TRUE && type != T_FALSE) { rb_raise(rb_eTypeError, "wrong argument type (expected a boolean parameter)"); } param->s8 = argv[argidx++] == Qtrue; ADJ(param, INT8); break; case NATIVE_UINT8: param->u8 = NUM2UINT(argv[argidx]); ADJ(param, INT8); ++argidx; break; case NATIVE_UINT16: param->u16 = NUM2UINT(argv[argidx]); ADJ(param, INT16); ++argidx; break; case NATIVE_UINT32: param->u32 = NUM2UINT(argv[argidx]); ADJ(param, INT32); ++argidx; break; case NATIVE_INT64: param->i64 = NUM2LL(argv[argidx]); ADJ(param, INT64); ++argidx; break; case NATIVE_UINT64: param->u64 = NUM2ULL(argv[argidx]); ADJ(param, INT64); ++argidx; break; case NATIVE_LONG: *(ffi_sarg *) param = NUM2LONG(argv[argidx]); ADJ(param, LONG); ++argidx; break; case NATIVE_ULONG: *(ffi_arg *) param = NUM2ULONG(argv[argidx]); ADJ(param, LONG); ++argidx; break; case NATIVE_FLOAT32: param->f32 = (float) NUM2DBL(argv[argidx]); ADJ(param, FLOAT32); ++argidx; break; case NATIVE_FLOAT64: param->f64 = NUM2DBL(argv[argidx]); ADJ(param, FLOAT64); ++argidx; break; case NATIVE_LONGDOUBLE: param->ld = rbffi_num2longdouble(argv[argidx]); ADJ(param, LONGDOUBLE); ++argidx; break; case NATIVE_STRING: if (type == T_NIL) { param->ptr = NULL; } else { if (rb_safe_level() >= 1 && OBJ_TAINTED(argv[argidx])) { rb_raise(rb_eSecurityError, "Unsafe string parameter"); } param->ptr = StringValueCStr(argv[argidx]); } ADJ(param, ADDRESS); ++argidx; break; case NATIVE_POINTER: case NATIVE_BUFFER_IN: case NATIVE_BUFFER_OUT: case NATIVE_BUFFER_INOUT: param->ptr = getPointer(argv[argidx++], type); ADJ(param, ADDRESS); break; case NATIVE_FUNCTION: case NATIVE_CALLBACK: if (callbackProc != Qnil) { param->ptr = callback_param(callbackProc, callbackParameters[cbidx++]); } else { param->ptr = callback_param(argv[argidx], callbackParameters[cbidx++]); ++argidx; } ADJ(param, ADDRESS); break; case NATIVE_STRUCT: ffiValues[i] = getPointer(argv[argidx++], type); break; default: rb_raise(rb_eArgError, "Invalid parameter type: %d", paramType->nativeType); } } } typedef struct BlockingCall_ { rbffi_frame_t* frame; void* function; FunctionType* info; void **ffiValues; void* retval; void* params; #if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) void* stkretval; #endif } BlockingCall; static VALUE call_blocking_function(void* data) { BlockingCall* b = (BlockingCall *) data; b->frame->has_gvl = false; ffi_call(&b->info->ffi_cif, FFI_FN(b->function), b->retval, b->ffiValues); b->frame->has_gvl = true; return Qnil; } static VALUE do_blocking_call(void *data) { rbffi_thread_blocking_region(call_blocking_function, data, (void *) -1, NULL); return Qnil; } static VALUE save_frame_exception(void *data, VALUE exc) { rbffi_frame_t* frame = (rbffi_frame_t *) data; frame->exc = exc; return Qnil; } VALUE rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo) { void* retval; void** ffiValues; FFIStorage* params; VALUE rbReturnValue; rbffi_frame_t frame = { 0 }; retval = alloca(MAX(fnInfo->ffi_cif.rtype->size, FFI_SIZEOF_ARG)); if (unlikely(fnInfo->blocking)) { BlockingCall* bc; /* * due to the way thread switching works on older ruby variants, we * cannot allocate anything passed to the blocking function on the stack */ #if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) ffiValues = ALLOCA_N(void *, fnInfo->parameterCount); params = ALLOCA_N(FFIStorage, fnInfo->parameterCount); bc = ALLOCA_N(BlockingCall, 1); bc->retval = retval; #else ffiValues = ALLOC_N(void *, fnInfo->parameterCount); params = ALLOC_N(FFIStorage, fnInfo->parameterCount); bc = ALLOC_N(BlockingCall, 1); bc->retval = xmalloc(MAX(fnInfo->ffi_cif.rtype->size, FFI_SIZEOF_ARG)); bc->stkretval = retval; #endif bc->info = fnInfo; bc->function = function; bc->ffiValues = ffiValues; bc->params = params; bc->frame = &frame; rbffi_SetupCallParams(argc, argv, fnInfo->parameterCount, fnInfo->parameterTypes, params, ffiValues, fnInfo->callbackParameters, fnInfo->callbackCount, fnInfo->rbEnums); rbffi_frame_push(&frame); rb_rescue2(do_blocking_call, (VALUE) bc, save_frame_exception, (VALUE) &frame, rb_eException, (VALUE) 0); rbffi_frame_pop(&frame); #if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) memcpy(bc->stkretval, bc->retval, MAX(bc->info->ffi_cif.rtype->size, FFI_SIZEOF_ARG)); xfree(bc->params); xfree(bc->ffiValues); xfree(bc->retval); xfree(bc); #endif } else { ffiValues = ALLOCA_N(void *, fnInfo->parameterCount); params = ALLOCA_N(FFIStorage, fnInfo->parameterCount); rbffi_SetupCallParams(argc, argv, fnInfo->parameterCount, fnInfo->parameterTypes, params, ffiValues, fnInfo->callbackParameters, fnInfo->callbackCount, fnInfo->rbEnums); rbffi_frame_push(&frame); ffi_call(&fnInfo->ffi_cif, FFI_FN(function), retval, ffiValues); rbffi_frame_pop(&frame); } if (unlikely(!fnInfo->ignoreErrno)) { rbffi_save_errno(); } if (RTEST(frame.exc) && frame.exc != Qnil) { rb_exc_raise(frame.exc); } RB_GC_GUARD(rbReturnValue) = rbffi_NativeValue_ToRuby(fnInfo->returnType, fnInfo->rbReturnType, retval); RB_GC_GUARD(fnInfo->rbReturnType); return rbReturnValue; } static inline void* getPointer(VALUE value, int type) { if (likely(type == T_DATA && rb_obj_is_kind_of(value, rbffi_AbstractMemoryClass))) { return ((AbstractMemory *) DATA_PTR(value))->address; } else if (type == T_DATA && rb_obj_is_kind_of(value, rbffi_StructClass)) { AbstractMemory* memory = ((Struct *) DATA_PTR(value))->pointer; return memory != NULL ? memory->address : NULL; } else if (type == T_STRING) { return StringValuePtr(value); } else if (type == T_NIL) { return NULL; } else if (rb_respond_to(value, id_to_ptr)) { VALUE ptr = rb_funcall2(value, id_to_ptr, 0, NULL); if (rb_obj_is_kind_of(ptr, rbffi_AbstractMemoryClass) && TYPE(ptr) == T_DATA) { return ((AbstractMemory *) DATA_PTR(ptr))->address; } rb_raise(rb_eArgError, "to_ptr returned an invalid pointer"); } rb_raise(rb_eArgError, ":pointer argument is not a valid pointer"); return NULL; } Invoker rbffi_GetInvoker(FunctionType *fnInfo) { return rbffi_CallFunction; } static void* callback_param(VALUE proc, VALUE cbInfo) { VALUE callback ; if (unlikely(proc == Qnil)) { return NULL ; } /* Handle Function pointers here */ if (rb_obj_is_kind_of(proc, rbffi_FunctionClass)) { AbstractMemory* ptr; Data_Get_Struct(proc, AbstractMemory, ptr); return ptr->address; } callback = rbffi_Function_ForProc(cbInfo, proc); RB_GC_GUARD(callback); return ((AbstractMemory *) DATA_PTR(callback))->address; } void rbffi_Call_Init(VALUE moduleFFI) { id_to_ptr = rb_intern("to_ptr"); id_to_native = rb_intern("to_native"); id_map_symbol = rb_intern("__map_symbol"); } ruby-ffi-1.9.3debian.orig/ext/ffi_c/Function.h0000644000175000017500000000541012261216357021374 0ustar terceiroterceiro/* * Copyright (c) 2009, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_FUNCTION_H #define RBFFI_FUNCTION_H #ifdef __cplusplus extern "C" { #endif #ifndef _MSC_VER # include #else # include "win32/stdbool.h" #endif #include typedef struct FunctionType_ FunctionType; #include "Type.h" #include "Call.h" #include "ClosurePool.h" struct FunctionType_ { Type type; /* The native type of a FunctionInfo object */ VALUE rbReturnType; VALUE rbParameterTypes; Type* returnType; Type** parameterTypes; NativeType* nativeParameterTypes; ffi_type* ffiReturnType; ffi_type** ffiParameterTypes; ffi_cif ffi_cif; Invoker invoke; ClosurePool* closurePool; int parameterCount; int flags; ffi_abi abi; int callbackCount; VALUE* callbackParameters; VALUE rbEnums; bool ignoreErrno; bool blocking; bool hasStruct; }; extern VALUE rbffi_FunctionTypeClass, rbffi_FunctionClass; void rbffi_Function_Init(VALUE moduleFFI); VALUE rbffi_Function_NewInstance(VALUE functionInfo, VALUE proc); VALUE rbffi_Function_ForProc(VALUE cbInfo, VALUE proc); void rbffi_FunctionInfo_Init(VALUE moduleFFI); #ifdef __cplusplus } #endif #endif /* RBFFI_FUNCTION_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/compat.h0000644000175000017500000000503012261216357021070 0ustar terceiroterceiro/* * Copyright (c) 2008, 2009, Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RBFFI_COMPAT_H #define RBFFI_COMPAT_H #include #ifndef RARRAY_LEN # define RARRAY_LEN(ary) RARRAY(ary)->len #endif #ifndef RARRAY_PTR # define RARRAY_PTR(ary) RARRAY(ary)->ptr #endif #ifndef RSTRING_LEN # define RSTRING_LEN(s) RSTRING(s)->len #endif #ifndef RSTRING_PTR # define RSTRING_PTR(s) RSTRING(s)->ptr #endif #ifndef NUM2ULL # define NUM2ULL(x) rb_num2ull((VALUE)x) #endif #ifndef roundup # define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) #endif #ifdef __GNUC__ # define likely(x) __builtin_expect((x), 1) # define unlikely(x) __builtin_expect((x), 0) #else # define likely(x) (x) # define unlikely(x) (x) #endif #ifndef MAX # define MAX(a, b) ((a) < (b) ? (b) : (a)) #endif #ifndef MIN # define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif #ifndef RB_GC_GUARD # define RB_GC_GUARD(x) (x) #endif #ifndef RB_GC_GUARD_PTR # define RB_GC_GUARD_PTR(x) (x) #endif #endif /* RBFFI_COMPAT_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/extconf.rb0000644000175000017500000000440512261216357021434 0ustar terceiroterceiro#!/usr/bin/env ruby if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx' require 'mkmf' require 'rbconfig' dir_config("ffi_c") # recent versions of ruby add restrictive ansi and warning flags on a whim - kill them all $warnflags = '' $CFLAGS.gsub!(/[\s+]-ansi/, '') $CFLAGS.gsub!(/[\s+]-std=[^\s]+/, '') # solaris needs -c99 for $CFLAGS << " -std=c99" if RbConfig::CONFIG['host_os'] =~ /solaris/ if ENV['RUBY_CC_VERSION'].nil? && (pkg_config("libffi") || have_header("ffi.h") || find_header("ffi.h", "/usr/local/include", "/usr/include/ffi")) # We need at least ffi_call and ffi_prep_closure libffi_ok = have_library("ffi", "ffi_call", [ "ffi.h" ]) || have_library("libffi", "ffi_call", [ "ffi.h" ]) libffi_ok &&= have_func("ffi_prep_closure") # Check if the raw api is available. $defs << "-DHAVE_RAW_API" if have_func("ffi_raw_call") && have_func("ffi_prep_raw_closure") end have_func('rb_thread_blocking_region') have_func('rb_thread_call_with_gvl') have_func('rb_thread_call_without_gvl') have_func('ffi_prep_cif_var') $defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works $defs << "-DUSE_INTERNAL_LIBFFI" unless libffi_ok $defs << "-DRUBY_1_9" if RUBY_VERSION >= "1.9.0" create_header $LOCAL_LIBS << " ./libffi/.libs/libffi_convenience.lib" if RbConfig::CONFIG['host_os'] =~ /mswin/ create_makefile("ffi_c") unless libffi_ok File.open("Makefile", "a") do |mf| mf.puts "LIBFFI_HOST=--host=#{RbConfig::CONFIG['host_alias']}" if RbConfig::CONFIG.has_key?("host_alias") if RbConfig::CONFIG['host_os'].downcase =~ /darwin/ mf.puts "include ${srcdir}/libffi.darwin.mk" elsif RbConfig::CONFIG['host_os'].downcase =~ /bsd/ mf.puts '.include "${srcdir}/libffi.bsd.mk"' elsif RbConfig::CONFIG['host_os'].downcase =~ /mswin64/ mf.puts '!include $(srcdir)/libffi.vc64.mk' elsif RbConfig::CONFIG['host_os'].downcase =~ /mswin32/ mf.puts '!include $(srcdir)/libffi.vc.mk' else mf.puts "include ${srcdir}/libffi.mk" end end end else File.open("Makefile", "w") do |mf| mf.puts "# Dummy makefile for non-mri rubies" mf.puts "all install::\n" end end ruby-ffi-1.9.3debian.orig/ext/ffi_c/Function.c0000644000175000017500000007207712261216357021404 0ustar terceiroterceiro/* * Copyright (c) 2009-2011 Wayne Meissner * * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER #include #endif #include #ifndef _WIN32 # include # include #endif #include #ifndef _MSC_VER # include # include #else # include "win32/stdbool.h" # if !defined(INT8_MIN) # include "win32/stdint.h" # endif #endif #include #include #if defined(HAVE_NATIVETHREAD) && !defined(_WIN32) #include #endif #include #include "rbffi.h" #include "compat.h" #include "AbstractMemory.h" #include "Pointer.h" #include "Struct.h" #include "Platform.h" #include "Type.h" #include "LastError.h" #include "Call.h" #include "ClosurePool.h" #include "MappedType.h" #include "Thread.h" #include "LongDouble.h" #include "MethodHandle.h" #include "Function.h" typedef struct Function_ { Pointer base; FunctionType* info; MethodHandle* methodHandle; bool autorelease; Closure* closure; VALUE rbProc; VALUE rbFunctionInfo; } Function; static void function_mark(Function *); static void function_free(Function *); static VALUE function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc); static void callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data); static bool callback_prep(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize); static VALUE callback_with_gvl(void* data); static VALUE invoke_callback(void* data); static VALUE save_callback_exception(void* data, VALUE exc); #define DEFER_ASYNC_CALLBACK 1 #if defined(DEFER_ASYNC_CALLBACK) static VALUE async_cb_event(void *); static VALUE async_cb_call(void *); #endif #ifdef HAVE_RB_THREAD_CALL_WITH_GVL extern void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1); #endif VALUE rbffi_FunctionClass = Qnil; #if defined(DEFER_ASYNC_CALLBACK) static VALUE async_cb_thread = Qnil; #endif static ID id_call = 0, id_to_native = 0, id_from_native = 0, id_cbtable = 0, id_cb_ref = 0; struct gvl_callback { Closure* closure; void* retval; void** parameters; bool done; rbffi_frame_t *frame; #if defined(DEFER_ASYNC_CALLBACK) struct gvl_callback* next; # ifndef _WIN32 pthread_cond_t async_cond; pthread_mutex_t async_mutex; # else HANDLE async_event; # endif #endif }; #if defined(DEFER_ASYNC_CALLBACK) static struct gvl_callback* async_cb_list = NULL; # ifndef _WIN32 static pthread_mutex_t async_cb_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t async_cb_cond = PTHREAD_COND_INITIALIZER; # if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) static int async_cb_pipe[2]; # endif # else static HANDLE async_cb_cond; static CRITICAL_SECTION async_cb_lock; # if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) static int async_cb_pipe[2]; # endif # endif #endif static VALUE function_allocate(VALUE klass) { Function *fn; VALUE obj; obj = Data_Make_Struct(klass, Function, function_mark, function_free, fn); fn->base.memory.flags = MEM_RD; fn->base.rbParent = Qnil; fn->rbProc = Qnil; fn->rbFunctionInfo = Qnil; fn->autorelease = true; return obj; } static void function_mark(Function *fn) { rb_gc_mark(fn->base.rbParent); rb_gc_mark(fn->rbProc); rb_gc_mark(fn->rbFunctionInfo); } static void function_free(Function *fn) { if (fn->methodHandle != NULL) { rbffi_MethodHandle_Free(fn->methodHandle); } if (fn->closure != NULL && fn->autorelease) { rbffi_Closure_Free(fn->closure); } xfree(fn); } /* * @param [Type, Symbol] return_type return type for the function * @param [Array] param_types array of parameters types * @param [Hash] options see {FFI::FunctionType} for available options * @return [self] * A new Function instance. * * Define a function from a Proc or a block. * * @overload initialize(return_type, param_types, options = {}) { |i| ... } * @yieldparam i parameters for the function * @overload initialize(return_type, param_types, proc, options = {}) * @param [Proc] proc */ static VALUE function_initialize(int argc, VALUE* argv, VALUE self) { VALUE rbReturnType = Qnil, rbParamTypes = Qnil, rbProc = Qnil, rbOptions = Qnil; VALUE rbFunctionInfo = Qnil; VALUE infoArgv[3]; int nargs; nargs = rb_scan_args(argc, argv, "22", &rbReturnType, &rbParamTypes, &rbProc, &rbOptions); /* * Callback with block, * e.g. Function.new(:int, [ :int ]) { |i| blah } * or Function.new(:int, [ :int ], { :convention => :stdcall }) { |i| blah } */ if (rb_block_given_p()) { if (nargs > 3) { rb_raise(rb_eArgError, "cannot create function with both proc/address and block"); } rbOptions = rbProc; rbProc = rb_block_proc(); } else { /* Callback with proc, or Function with address * e.g. Function.new(:int, [ :int ], Proc.new { |i| }) * Function.new(:int, [ :int ], Proc.new { |i| }, { :convention => :stdcall }) * Function.new(:int, [ :int ], addr) * Function.new(:int, [ :int ], addr, { :convention => :stdcall }) */ } infoArgv[0] = rbReturnType; infoArgv[1] = rbParamTypes; infoArgv[2] = rbOptions; rbFunctionInfo = rb_class_new_instance(rbOptions != Qnil ? 3 : 2, infoArgv, rbffi_FunctionTypeClass); function_init(self, rbFunctionInfo, rbProc); return self; } /* * call-seq: initialize_copy(other) * @return [nil] * DO NOT CALL THIS METHOD */ static VALUE function_initialize_copy(VALUE self, VALUE other) { rb_raise(rb_eRuntimeError, "cannot duplicate function instances"); return Qnil; } VALUE rbffi_Function_NewInstance(VALUE rbFunctionInfo, VALUE rbProc) { return function_init(function_allocate(rbffi_FunctionClass), rbFunctionInfo, rbProc); } VALUE rbffi_Function_ForProc(VALUE rbFunctionInfo, VALUE proc) { VALUE callback, cbref, cbTable; Function* fp; cbref = RTEST(rb_ivar_defined(proc, id_cb_ref)) ? rb_ivar_get(proc, id_cb_ref) : Qnil; /* If the first callback reference has the same function function signature, use it */ if (cbref != Qnil && CLASS_OF(cbref) == rbffi_FunctionClass) { Data_Get_Struct(cbref, Function, fp); if (fp->rbFunctionInfo == rbFunctionInfo) { return cbref; } } cbTable = RTEST(rb_ivar_defined(proc, id_cbtable)) ? rb_ivar_get(proc, id_cbtable) : Qnil; if (cbTable != Qnil && (callback = rb_hash_aref(cbTable, rbFunctionInfo)) != Qnil) { return callback; } /* No existing function for the proc with that signature, create a new one and cache it */ callback = rbffi_Function_NewInstance(rbFunctionInfo, proc); if (cbref == Qnil) { /* If there is no other cb already cached for this proc, we can use the ivar slot */ rb_ivar_set(proc, id_cb_ref, callback); } else { /* The proc instance has been used as more than one type of callback, store extras in a hash */ cbTable = rb_hash_new(); rb_ivar_set(proc, id_cbtable, cbTable); rb_hash_aset(cbTable, rbFunctionInfo, callback); } return callback; } static VALUE function_init(VALUE self, VALUE rbFunctionInfo, VALUE rbProc) { Function* fn = NULL; Data_Get_Struct(self, Function, fn); fn->rbFunctionInfo = rbFunctionInfo; Data_Get_Struct(fn->rbFunctionInfo, FunctionType, fn->info); if (rb_obj_is_kind_of(rbProc, rbffi_PointerClass)) { Pointer* orig; Data_Get_Struct(rbProc, Pointer, orig); fn->base.memory = orig->memory; fn->base.rbParent = rbProc; } else if (rb_obj_is_kind_of(rbProc, rb_cProc) || rb_respond_to(rbProc, id_call)) { if (fn->info->closurePool == NULL) { fn->info->closurePool = rbffi_ClosurePool_New(sizeof(ffi_closure), callback_prep, fn->info); if (fn->info->closurePool == NULL) { rb_raise(rb_eNoMemError, "failed to create closure pool"); } } #if defined(DEFER_ASYNC_CALLBACK) if (async_cb_thread == Qnil) { #if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) && defined(_WIN32) _pipe(async_cb_pipe, 1024, O_BINARY); #elif !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) pipe(async_cb_pipe); fcntl(async_cb_pipe[0], F_SETFL, fcntl(async_cb_pipe[0], F_GETFL) | O_NONBLOCK); fcntl(async_cb_pipe[1], F_SETFL, fcntl(async_cb_pipe[1], F_GETFL) | O_NONBLOCK); #endif async_cb_thread = rb_thread_create(async_cb_event, NULL); } #endif fn->closure = rbffi_Closure_Alloc(fn->info->closurePool); fn->closure->info = fn; fn->base.memory.address = fn->closure->code; fn->base.memory.size = sizeof(*fn->closure); fn->autorelease = true; } else { rb_raise(rb_eTypeError, "wrong argument type %s, expected pointer or proc", rb_obj_classname(rbProc)); } fn->rbProc = rbProc; return self; } /* * call-seq: call(*args) * @param [Array] args function arguments * @return [FFI::Type] * Call the function */ static VALUE function_call(int argc, VALUE* argv, VALUE self) { Function* fn; Data_Get_Struct(self, Function, fn); return (*fn->info->invoke)(argc, argv, fn->base.memory.address, fn->info); } /* * call-seq: attach(m, name) * @param [Module] m * @param [String] name * @return [self] * Attach a Function to the Module +m+ as +name+. */ static VALUE function_attach(VALUE self, VALUE module, VALUE name) { Function* fn; char var[1024]; Data_Get_Struct(self, Function, fn); if (fn->info->parameterCount == -1) { rb_raise(rb_eRuntimeError, "cannot attach variadic functions"); return Qnil; } if (!rb_obj_is_kind_of(module, rb_cModule)) { rb_raise(rb_eRuntimeError, "trying to attach function to non-module"); return Qnil; } if (fn->methodHandle == NULL) { fn->methodHandle = rbffi_MethodHandle_Alloc(fn->info, fn->base.memory.address); } /* * Stash the Function in a module variable so it does not get garbage collected */ snprintf(var, sizeof(var), "@@%s", StringValueCStr(name)); rb_cv_set(module, var, self); rb_define_singleton_method(module, StringValueCStr(name), rbffi_MethodHandle_CodeAddress(fn->methodHandle), -1); rb_define_method(module, StringValueCStr(name), rbffi_MethodHandle_CodeAddress(fn->methodHandle), -1); return self; } /* * call-seq: autorelease = autorelease * @param [Boolean] autorelease * @return [self] * Set +autorelease+ attribute (See {Pointer}). */ static VALUE function_set_autorelease(VALUE self, VALUE autorelease) { Function* fn; Data_Get_Struct(self, Function, fn); fn->autorelease = RTEST(autorelease); return self; } static VALUE function_autorelease_p(VALUE self) { Function* fn; Data_Get_Struct(self, Function, fn); return fn->autorelease ? Qtrue : Qfalse; } /* * call-seq: free * @return [self] * Free memory allocated by Function. */ static VALUE function_release(VALUE self) { Function* fn; Data_Get_Struct(self, Function, fn); if (fn->closure == NULL) { rb_raise(rb_eRuntimeError, "cannot free function which was not allocated"); } rbffi_Closure_Free(fn->closure); fn->closure = NULL; return self; } static void callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data) { struct gvl_callback cb = { 0 }; cb.closure = (Closure *) user_data; cb.retval = retval; cb.parameters = parameters; cb.done = false; cb.frame = rbffi_frame_current(); if (cb.frame != NULL) cb.frame->exc = Qnil; if (cb.frame != NULL && cb.frame->has_gvl) { callback_with_gvl(&cb); #if defined(HAVE_RB_THREAD_CALL_WITH_GVL) } else if (cb.frame != NULL) { rb_thread_call_with_gvl(callback_with_gvl, &cb); #endif #if defined(DEFER_ASYNC_CALLBACK) && !defined(_WIN32) } else { bool empty = false; pthread_mutex_init(&cb.async_mutex, NULL); pthread_cond_init(&cb.async_cond, NULL); /* Now signal the async callback thread */ pthread_mutex_lock(&async_cb_mutex); empty = async_cb_list == NULL; cb.next = async_cb_list; async_cb_list = &cb; #if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) pthread_mutex_unlock(&async_cb_mutex); /* Only signal if the list was empty */ if (empty) { char c; write(async_cb_pipe[1], &c, 1); } #else pthread_cond_signal(&async_cb_cond); pthread_mutex_unlock(&async_cb_mutex); #endif /* Wait for the thread executing the ruby callback to signal it is done */ pthread_mutex_lock(&cb.async_mutex); while (!cb.done) { pthread_cond_wait(&cb.async_cond, &cb.async_mutex); } pthread_mutex_unlock(&cb.async_mutex); pthread_cond_destroy(&cb.async_cond); pthread_mutex_destroy(&cb.async_mutex); #elif defined(DEFER_ASYNC_CALLBACK) && defined(_WIN32) } else { bool empty = false; cb.async_event = CreateEvent(NULL, FALSE, FALSE, NULL); /* Now signal the async callback thread */ EnterCriticalSection(&async_cb_lock); empty = async_cb_list == NULL; cb.next = async_cb_list; async_cb_list = &cb; LeaveCriticalSection(&async_cb_lock); #if !(defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) /* Only signal if the list was empty */ if (empty) { char c; write(async_cb_pipe[1], &c, 1); } #else SetEvent(async_cb_cond); #endif /* Wait for the thread executing the ruby callback to signal it is done */ WaitForSingleObject(cb.async_event, INFINITE); CloseHandle(cb.async_event); #endif } } #if defined(DEFER_ASYNC_CALLBACK) struct async_wait { void* cb; bool stop; }; static VALUE async_cb_wait(void *); static void async_cb_stop(void *); #if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) static VALUE async_cb_event(void* unused) { struct async_wait w = { 0 }; w.stop = false; while (!w.stop) { #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) rb_thread_call_without_gvl(async_cb_wait, &w, async_cb_stop, &w); #else rb_thread_blocking_region(async_cb_wait, &w, async_cb_stop, &w); #endif if (w.cb != NULL) { /* Start up a new ruby thread to run the ruby callback */ rb_thread_create(async_cb_call, w.cb); } } return Qnil; } #elif defined(_WIN32) static VALUE async_cb_event(void* unused) { while (true) { struct gvl_callback* cb; char buf[64]; fd_set rfds; FD_ZERO(&rfds); FD_SET(async_cb_pipe[0], &rfds); rb_thread_select(async_cb_pipe[0] + 1, &rfds, NULL, NULL, NULL); read(async_cb_pipe[0], buf, sizeof(buf)); EnterCriticalSection(&async_cb_lock); cb = async_cb_list; async_cb_list = NULL; LeaveCriticalSection(&async_cb_lock); while (cb != NULL) { struct gvl_callback* next = cb->next; /* Start up a new ruby thread to run the ruby callback */ rb_thread_create(async_cb_call, cb); cb = next; } } return Qnil; } #else static VALUE async_cb_event(void* unused) { while (true) { struct gvl_callback* cb; char buf[64]; if (read(async_cb_pipe[0], buf, sizeof(buf)) < 0) { rb_thread_wait_fd(async_cb_pipe[0]); while (read(async_cb_pipe[0], buf, sizeof (buf)) < 0) { if (rb_io_wait_readable(async_cb_pipe[0]) != Qtrue) { return Qfalse; } } } pthread_mutex_lock(&async_cb_mutex); cb = async_cb_list; async_cb_list = NULL; pthread_mutex_unlock(&async_cb_mutex); while (cb != NULL) { struct gvl_callback* next = cb->next; /* Start up a new ruby thread to run the ruby callback */ rb_thread_create(async_cb_call, cb); cb = next; } } return Qnil; } #endif #ifdef _WIN32 static VALUE async_cb_wait(void *data) { struct async_wait* w = (struct async_wait *) data; w->cb = NULL; EnterCriticalSection(&async_cb_lock); while (!w->stop && async_cb_list == NULL) { LeaveCriticalSection(&async_cb_lock); WaitForSingleObject(async_cb_cond, INFINITE); EnterCriticalSection(&async_cb_lock); } if (async_cb_list != NULL) { w->cb = async_cb_list; async_cb_list = async_cb_list->next; } LeaveCriticalSection(&async_cb_lock); return Qnil; } static void async_cb_stop(void *data) { struct async_wait* w = (struct async_wait *) data; EnterCriticalSection(&async_cb_lock); w->stop = true; LeaveCriticalSection(&async_cb_lock); SetEvent(async_cb_cond); } #else static VALUE async_cb_wait(void *data) { struct async_wait* w = (struct async_wait *) data; w->cb = NULL; pthread_mutex_lock(&async_cb_mutex); while (!w->stop && async_cb_list == NULL) { pthread_cond_wait(&async_cb_cond, &async_cb_mutex); } if (async_cb_list != NULL) { w->cb = async_cb_list; async_cb_list = async_cb_list->next; } pthread_mutex_unlock(&async_cb_mutex); return Qnil; } static void async_cb_stop(void *data) { struct async_wait* w = (struct async_wait *) data; pthread_mutex_lock(&async_cb_mutex); w->stop = true; pthread_cond_signal(&async_cb_cond); pthread_mutex_unlock(&async_cb_mutex); } #endif static VALUE async_cb_call(void *data) { struct gvl_callback* cb = (struct gvl_callback *) data; callback_with_gvl(data); /* Signal the original native thread that the ruby code has completed */ #ifdef _WIN32 SetEvent(cb->async_event); #else pthread_mutex_lock(&cb->async_mutex); cb->done = true; pthread_cond_signal(&cb->async_cond); pthread_mutex_unlock(&cb->async_mutex); #endif return Qnil; } #endif static VALUE callback_with_gvl(void* data) { rb_rescue2(invoke_callback, (VALUE) data, save_callback_exception, (VALUE) data, rb_eException, (VALUE) 0); } static VALUE invoke_callback(void* data) { struct gvl_callback* cb = (struct gvl_callback *) data; Function* fn = (Function *) cb->closure->info; FunctionType *cbInfo = fn->info; Type* returnType = cbInfo->returnType; void* retval = cb->retval; void** parameters = cb->parameters; VALUE* rbParams; VALUE rbReturnType = cbInfo->rbReturnType; VALUE rbReturnValue; int i; rbParams = ALLOCA_N(VALUE, cbInfo->parameterCount); for (i = 0; i < cbInfo->parameterCount; ++i) { VALUE param; Type* paramType = cbInfo->parameterTypes[i]; VALUE rbParamType = rb_ary_entry(cbInfo->rbParameterTypes, i); if (unlikely(paramType->nativeType == NATIVE_MAPPED)) { paramType = ((MappedType *) paramType)->type; rbParamType = ((MappedType *) paramType)->rbType; } switch (paramType->nativeType) { case NATIVE_INT8: param = INT2NUM(*(int8_t *) parameters[i]); break; case NATIVE_UINT8: param = UINT2NUM(*(uint8_t *) parameters[i]); break; case NATIVE_INT16: param = INT2NUM(*(int16_t *) parameters[i]); break; case NATIVE_UINT16: param = UINT2NUM(*(uint16_t *) parameters[i]); break; case NATIVE_INT32: param = INT2NUM(*(int32_t *) parameters[i]); break; case NATIVE_UINT32: param = UINT2NUM(*(uint32_t *) parameters[i]); break; case NATIVE_INT64: param = LL2NUM(*(int64_t *) parameters[i]); break; case NATIVE_UINT64: param = ULL2NUM(*(uint64_t *) parameters[i]); break; case NATIVE_LONG: param = LONG2NUM(*(long *) parameters[i]); break; case NATIVE_ULONG: param = ULONG2NUM(*(unsigned long *) parameters[i]); break; case NATIVE_FLOAT32: param = rb_float_new(*(float *) parameters[i]); break; case NATIVE_FLOAT64: param = rb_float_new(*(double *) parameters[i]); break; case NATIVE_LONGDOUBLE: param = rbffi_longdouble_new(*(long double *) parameters[i]); break; case NATIVE_STRING: param = (*(void **) parameters[i] != NULL) ? rb_tainted_str_new2(*(char **) parameters[i]) : Qnil; break; case NATIVE_POINTER: param = rbffi_Pointer_NewInstance(*(void **) parameters[i]); break; case NATIVE_BOOL: param = (*(uint8_t *) parameters[i]) ? Qtrue : Qfalse; break; case NATIVE_FUNCTION: case NATIVE_CALLBACK: case NATIVE_STRUCT: param = rbffi_NativeValue_ToRuby(paramType, rbParamType, parameters[i]); break; default: param = Qnil; break; } /* Convert the native value into a custom ruby value */ if (unlikely(cbInfo->parameterTypes[i]->nativeType == NATIVE_MAPPED)) { VALUE values[] = { param, Qnil }; param = rb_funcall2(((MappedType *) cbInfo->parameterTypes[i])->rbConverter, id_from_native, 2, values); } rbParams[i] = param; } rbReturnValue = rb_funcall2(fn->rbProc, id_call, cbInfo->parameterCount, rbParams); RB_GC_GUARD_PTR(rbParams); if (unlikely(returnType->nativeType == NATIVE_MAPPED)) { VALUE values[] = { rbReturnValue, Qnil }; rbReturnValue = rb_funcall2(((MappedType *) returnType)->rbConverter, id_to_native, 2, values); rbReturnType = ((MappedType *) returnType)->rbType; returnType = ((MappedType* ) returnType)->type; } if (rbReturnValue == Qnil || TYPE(rbReturnValue) == T_NIL) { memset(retval, 0, returnType->ffiType->size); } else switch (returnType->nativeType) { case NATIVE_INT8: case NATIVE_INT16: case NATIVE_INT32: *((ffi_sarg *) retval) = NUM2INT(rbReturnValue); break; case NATIVE_UINT8: case NATIVE_UINT16: case NATIVE_UINT32: *((ffi_arg *) retval) = NUM2UINT(rbReturnValue); break; case NATIVE_INT64: *((int64_t *) retval) = NUM2LL(rbReturnValue); break; case NATIVE_UINT64: *((uint64_t *) retval) = NUM2ULL(rbReturnValue); break; case NATIVE_LONG: *((ffi_sarg *) retval) = NUM2LONG(rbReturnValue); break; case NATIVE_ULONG: *((ffi_arg *) retval) = NUM2ULONG(rbReturnValue); break; case NATIVE_FLOAT32: *((float *) retval) = (float) NUM2DBL(rbReturnValue); break; case NATIVE_FLOAT64: *((double *) retval) = NUM2DBL(rbReturnValue); break; case NATIVE_POINTER: if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_PointerClass)) { *((void **) retval) = ((AbstractMemory *) DATA_PTR(rbReturnValue))->address; } else { /* Default to returning NULL if not a value pointer object. handles nil case as well */ *((void **) retval) = NULL; } break; case NATIVE_BOOL: *((ffi_arg *) retval) = rbReturnValue == Qtrue; break; case NATIVE_FUNCTION: case NATIVE_CALLBACK: if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_PointerClass)) { *((void **) retval) = ((AbstractMemory *) DATA_PTR(rbReturnValue))->address; } else if (rb_obj_is_kind_of(rbReturnValue, rb_cProc) || rb_respond_to(rbReturnValue, id_call)) { VALUE function; function = rbffi_Function_ForProc(rbReturnType, rbReturnValue); *((void **) retval) = ((AbstractMemory *) DATA_PTR(function))->address; } else { *((void **) retval) = NULL; } break; case NATIVE_STRUCT: if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_StructClass)) { AbstractMemory* memory = ((Struct *) DATA_PTR(rbReturnValue))->pointer; if (memory->address != NULL) { memcpy(retval, memory->address, returnType->ffiType->size); } else { memset(retval, 0, returnType->ffiType->size); } } else { memset(retval, 0, returnType->ffiType->size); } break; default: *((ffi_arg *) retval) = 0; break; } return Qnil; } static VALUE save_callback_exception(void* data, VALUE exc) { struct gvl_callback* cb = (struct gvl_callback *) data; memset(cb->retval, 0, ((Function *) cb->closure->info)->info->returnType->ffiType->size); if (cb->frame != NULL) cb->frame->exc = exc; return Qnil; } static bool callback_prep(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize) { FunctionType* fnInfo = (FunctionType *) ctx; ffi_status ffiStatus; ffiStatus = ffi_prep_closure(code, &fnInfo->ffi_cif, callback_invoke, closure); if (ffiStatus != FFI_OK) { snprintf(errmsg, errmsgsize, "ffi_prep_closure failed. status=%#x", ffiStatus); return false; } return true; } void rbffi_Function_Init(VALUE moduleFFI) { rbffi_FunctionInfo_Init(moduleFFI); /* * Document-class: FFI::Function < FFI::Pointer */ rbffi_FunctionClass = rb_define_class_under(moduleFFI, "Function", rbffi_PointerClass); rb_global_variable(&rbffi_FunctionClass); rb_define_alloc_func(rbffi_FunctionClass, function_allocate); rb_define_method(rbffi_FunctionClass, "initialize", function_initialize, -1); rb_define_method(rbffi_FunctionClass, "initialize_copy", function_initialize_copy, 1); rb_define_method(rbffi_FunctionClass, "call", function_call, -1); rb_define_method(rbffi_FunctionClass, "attach", function_attach, 2); rb_define_method(rbffi_FunctionClass, "free", function_release, 0); rb_define_method(rbffi_FunctionClass, "autorelease=", function_set_autorelease, 1); /* * call-seq: autorelease * @return [Boolean] * Get +autorelease+ attribute. * Synonymous for {#autorelease?}. */ rb_define_method(rbffi_FunctionClass, "autorelease", function_autorelease_p, 0); /* * call-seq: autorelease? * @return [Boolean] +autorelease+ attribute * Get +autorelease+ attribute. */ rb_define_method(rbffi_FunctionClass, "autorelease?", function_autorelease_p, 0); id_call = rb_intern("call"); id_cbtable = rb_intern("@__ffi_callback_table__"); id_cb_ref = rb_intern("@__ffi_callback__"); id_to_native = rb_intern("to_native"); id_from_native = rb_intern("from_native"); #if defined(_WIN32) InitializeCriticalSection(&async_cb_lock); async_cb_cond = CreateEvent(NULL, FALSE, FALSE, NULL); #endif } ruby-ffi-1.9.3debian.orig/ext/ffi_c/MethodHandle.c0000644000175000017500000002275012261216360022136 0ustar terceiroterceiro/* * Copyright (c) 2009, 2010 Wayne Meissner * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER #include #endif #include #ifndef _WIN32 # include #endif #include #ifndef _MSC_VER # include # include #else # include "win32/stdint.h" # include "win32/stdbool.h" #endif #ifndef _WIN32 # include #endif #include #include #if defined(HAVE_NATIVETHREAD) && !defined(_WIN32) && !defined(__WIN32__) # include #endif #include #include "rbffi.h" #include "compat.h" #include "Function.h" #include "Types.h" #include "Type.h" #include "LastError.h" #include "Call.h" #include "ClosurePool.h" #include "MethodHandle.h" #define MAX_METHOD_FIXED_ARITY (6) #ifndef roundup # define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) #endif #ifdef _WIN32 typedef char* caddr_t; #endif #ifdef USE_RAW # define METHOD_CLOSURE ffi_raw_closure # define METHOD_PARAMS ffi_raw* #else # define METHOD_CLOSURE ffi_closure # define METHOD_PARAMS void** #endif static bool prep_trampoline(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize); static long trampoline_size(void); #if defined(__x86_64__) && (defined(__linux__) || defined(__APPLE__)) # define CUSTOM_TRAMPOLINE 1 #endif struct MethodHandle { Closure* closure; }; static ClosurePool* defaultClosurePool; MethodHandle* rbffi_MethodHandle_Alloc(FunctionType* fnInfo, void* function) { MethodHandle* handle; Closure* closure = rbffi_Closure_Alloc(defaultClosurePool); if (closure == NULL) { rb_raise(rb_eNoMemError, "failed to allocate closure from pool"); return NULL; } handle = xcalloc(1, sizeof(*handle)); handle->closure = closure; closure->info = fnInfo; closure->function = function; return handle; } void rbffi_MethodHandle_Free(MethodHandle* handle) { if (handle != NULL) { rbffi_Closure_Free(handle->closure); } } void* rbffi_MethodHandle_CodeAddress(MethodHandle* handle) { return handle->closure->code; } #ifndef CUSTOM_TRAMPOLINE static void attached_method_invoke(ffi_cif* cif, void* retval, METHOD_PARAMS parameters, void* user_data); static ffi_type* methodHandleParamTypes[] = { &ffi_type_sint, &ffi_type_pointer, &ffi_type_ulong, }; static ffi_cif mh_cif; static bool prep_trampoline(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize) { ffi_status ffiStatus; #if defined(USE_RAW) ffiStatus = ffi_prep_raw_closure(code, &mh_cif, attached_method_invoke, closure); #else ffiStatus = ffi_prep_closure(code, &mh_cif, attached_method_invoke, closure); #endif if (ffiStatus != FFI_OK) { snprintf(errmsg, errmsgsize, "ffi_prep_closure failed. status=%#x", ffiStatus); return false; } return true; } static long trampoline_size(void) { return sizeof(METHOD_CLOSURE); } /* * attached_method_invoke is used functions with more than 6 parameters, or * with struct param or return values */ static void attached_method_invoke(ffi_cif* cif, void* mretval, METHOD_PARAMS parameters, void* user_data) { Closure* handle = (Closure *) user_data; FunctionType* fnInfo = (FunctionType *) handle->info; #ifdef USE_RAW int argc = parameters[0].sint; VALUE* argv = *(VALUE **) ¶meters[1]; #else int argc = *(int *) parameters[0]; VALUE* argv = *(VALUE **) parameters[1]; #endif *(VALUE *) mretval = (*fnInfo->invoke)(argc, argv, handle->function, fnInfo); } #endif #if defined(CUSTOM_TRAMPOLINE) #if defined(__x86_64__) static VALUE custom_trampoline(int argc, VALUE* argv, VALUE self, Closure*); #define TRAMPOLINE_CTX_MAGIC (0xfee1deadcafebabe) #define TRAMPOLINE_FUN_MAGIC (0xfeedfacebeeff00d) /* * This is a hand-coded trampoline to speedup entry from ruby to the FFI translation * layer for x86_64 arches. * * Since a ruby function has exactly 3 arguments, and the first 6 arguments are * passed in registers for x86_64, we can tack on a context pointer by simply * putting a value in %rcx, then jumping to the C trampoline code. * * This results in approx a 30% speedup for x86_64 FFI dispatch */ __asm__( ".text\n\t" ".globl ffi_trampoline\n\t" ".globl _ffi_trampoline\n\t" "ffi_trampoline:\n\t" "_ffi_trampoline:\n\t" "movabsq $0xfee1deadcafebabe, %rcx\n\t" "movabsq $0xfeedfacebeeff00d, %r11\n\t" "jmpq *%r11\n\t" ".globl ffi_trampoline_end\n\t" "ffi_trampoline_end:\n\t" ".globl _ffi_trampoline_end\n\t" "_ffi_trampoline_end:\n\t" ); static VALUE custom_trampoline(int argc, VALUE* argv, VALUE self, Closure* handle) { FunctionType* fnInfo = (FunctionType *) handle->info; VALUE rbReturnValue; RB_GC_GUARD(rbReturnValue) = (*fnInfo->invoke)(argc, argv, handle->function, fnInfo); RB_GC_GUARD_PTR(argv); RB_GC_GUARD(self); return rbReturnValue; } #elif defined(__i386__) && 0 static VALUE custom_trampoline(caddr_t args, Closure*); #define TRAMPOLINE_CTX_MAGIC (0xfee1dead) #define TRAMPOLINE_FUN_MAGIC (0xbeefcafe) /* * This is a hand-coded trampoline to speedup entry from ruby to the FFI translation * layer for i386 arches. * * This does not make a discernable difference vs a raw closure, so for now, * it is not enabled. */ __asm__( ".text\n\t" ".globl ffi_trampoline\n\t" ".globl _ffi_trampoline\n\t" "ffi_trampoline:\n\t" "_ffi_trampoline:\n\t" "subl $12, %esp\n\t" "leal 16(%esp), %eax\n\t" "movl %eax, (%esp)\n\t" "movl $0xfee1dead, 4(%esp)\n\t" "movl $0xbeefcafe, %eax\n\t" "call *%eax\n\t" "addl $12, %esp\n\t" "ret\n\t" ".globl ffi_trampoline_end\n\t" "ffi_trampoline_end:\n\t" ".globl _ffi_trampoline_end\n\t" "_ffi_trampoline_end:\n\t" ); static VALUE custom_trampoline(caddr_t args, Closure* handle) { FunctionType* fnInfo = (FunctionType *) handle->info; return (*fnInfo->invoke)(*(int *) args, *(VALUE **) (args + 4), handle->function, fnInfo); } #endif /* __x86_64__ else __i386__ */ extern void ffi_trampoline(int argc, VALUE* argv, VALUE self); extern void ffi_trampoline_end(void); static int trampoline_offsets(long *, long *); static long trampoline_ctx_offset, trampoline_func_offset; static long trampoline_offset(int off, const long value) { caddr_t ptr; for (ptr = (caddr_t) &ffi_trampoline + off; ptr < (caddr_t) &ffi_trampoline_end; ++ptr) { if (*(long *) ptr == value) { return ptr - (caddr_t) &ffi_trampoline; } } return -1; } static int trampoline_offsets(long* ctxOffset, long* fnOffset) { *ctxOffset = trampoline_offset(0, TRAMPOLINE_CTX_MAGIC); if (*ctxOffset == -1) { return -1; } *fnOffset = trampoline_offset(0, TRAMPOLINE_FUN_MAGIC); if (*fnOffset == -1) { return -1; } return 0; } static bool prep_trampoline(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize) { caddr_t ptr = (caddr_t) code; memcpy(ptr, &ffi_trampoline, trampoline_size()); /* Patch the context and function addresses into the stub code */ *(intptr_t *)(ptr + trampoline_ctx_offset) = (intptr_t) closure; *(intptr_t *)(ptr + trampoline_func_offset) = (intptr_t) custom_trampoline; return true; } static long trampoline_size(void) { return (caddr_t) &ffi_trampoline_end - (caddr_t) &ffi_trampoline; } #endif /* CUSTOM_TRAMPOLINE */ void rbffi_MethodHandle_Init(VALUE module) { #ifndef CUSTOM_TRAMPOLINE ffi_status ffiStatus; #endif defaultClosurePool = rbffi_ClosurePool_New((int) trampoline_size(), prep_trampoline, NULL); #if defined(CUSTOM_TRAMPOLINE) if (trampoline_offsets(&trampoline_ctx_offset, &trampoline_func_offset) != 0) { rb_raise(rb_eFatal, "Could not locate offsets in trampoline code"); } #else ffiStatus = ffi_prep_cif(&mh_cif, FFI_DEFAULT_ABI, 3, &ffi_type_ulong, methodHandleParamTypes); if (ffiStatus != FFI_OK) { rb_raise(rb_eFatal, "ffi_prep_cif failed. status=%#x", ffiStatus); } #endif } ruby-ffi-1.9.3debian.orig/ext/ffi_c/DynamicLibrary.h0000644000175000017500000000354212261216357022524 0ustar terceiroterceiro/* * Copyright (c) 2008-2010 Wayne Meissner * Copyright (c) 2008-2013, Ruby FFI project contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Ruby FFI project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _LIBRARY_H #define _LIBRARY_H #ifdef __cplusplus extern "C" { #endif typedef struct Library { void* handle; } Library; extern void rbffi_DynamicLibrary_Init(VALUE ffiModule); #ifdef __cplusplus } #endif #endif /* _LIBRARY_H */ ruby-ffi-1.9.3debian.orig/ext/ffi_c/StructByReference.c0000644000175000017500000001241612261216360023176 0ustar terceiroterceiro/* * Copyright (c) 2010, Wayne Meissner * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * The name of the author or authors may not be used to endorse or promote * products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MSC_VER # include #endif #include #include #ifndef _MSC_VER # include # include #else # include "win32/stdbool.h" # include "win32/stdint.h" #endif #include #include #include #include "rbffi.h" #include "compat.h" #include "Pointer.h" #include "Struct.h" #include "StructByReference.h" #define FFI_ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1) static VALUE sbr_allocate(VALUE); static VALUE sbr_initialize(VALUE, VALUE); static void sbr_mark(StructByReference *); VALUE rbffi_StructByReferenceClass = Qnil; static VALUE sbr_allocate(VALUE klass) { StructByReference* sbr; VALUE obj = Data_Make_Struct(klass, StructByReference, sbr_mark, -1, sbr); sbr->rbStructClass = Qnil; return obj; } /* * call-seq: initialize(struc_class) * @param [Struct] struct_calss * @return [self] * A new instance of StructByReference. */ static VALUE sbr_initialize(VALUE self, VALUE rbStructClass) { StructByReference* sbr = NULL; if (!rb_class_inherited_p(rbStructClass, rbffi_StructClass)) { rb_raise(rb_eTypeError, "wrong type (expected subclass of FFI::Struct)"); } Data_Get_Struct(self, StructByReference, sbr); sbr->rbStructClass = rbStructClass; return self; } static void sbr_mark(StructByReference *sbr) { rb_gc_mark(sbr->rbStructClass); } /* * call-seq: struct_class * @return [Struct] * Get +struct_class+. */ static VALUE sbr_struct_class(VALUE self) { StructByReference* sbr; Data_Get_Struct(self, StructByReference, sbr); return sbr->rbStructClass; } /* * call-seq: native_type * @return [Class] * Always get {FFI::Type}::POINTER. */ static VALUE sbr_native_type(VALUE self) { return rb_const_get(rbffi_TypeClass, rb_intern("POINTER")); } /* * call-seq: to_native(value, ctx) * @param [nil, Struct] value * @param [nil] ctx * @return [AbstractMemory] Pointer on +value+. */ static VALUE sbr_to_native(VALUE self, VALUE value, VALUE ctx) { StructByReference* sbr; Struct* s; if (unlikely(value == Qnil)) { return rbffi_NullPointerSingleton; } Data_Get_Struct(self, StructByReference, sbr); if (!rb_obj_is_kind_of(value, sbr->rbStructClass)) { rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", rb_obj_classname(value), RSTRING_PTR(rb_class_name(sbr->rbStructClass))); } Data_Get_Struct(value, Struct, s); return s->rbPointer; } /* * call-seq: from_native(value, ctx) * @param [AbstractMemory] value * @param [nil] ctx * @return [Struct] * Create a struct from content of memory +value+. */ static VALUE sbr_from_native(VALUE self, VALUE value, VALUE ctx) { StructByReference* sbr; Data_Get_Struct(self, StructByReference, sbr); return rb_class_new_instance(1, &value, sbr->rbStructClass); } void rbffi_StructByReference_Init(VALUE moduleFFI) { /* * Document-class: FFI::StructByReference * This class includes {FFI::DataConverter} module. */ rbffi_StructByReferenceClass = rb_define_class_under(moduleFFI, "StructByReference", rb_cObject); rb_global_variable(&rbffi_StructByReferenceClass); rb_include_module(rbffi_StructByReferenceClass, rb_const_get(moduleFFI, rb_intern("DataConverter"))); rb_define_alloc_func(rbffi_StructByReferenceClass, sbr_allocate); rb_define_method(rbffi_StructByReferenceClass, "initialize", sbr_initialize, 1); rb_define_method(rbffi_StructByReferenceClass, "struct_class", sbr_struct_class, 0); rb_define_method(rbffi_StructByReferenceClass, "native_type", sbr_native_type, 0); rb_define_method(rbffi_StructByReferenceClass, "to_native", sbr_to_native, 2); rb_define_method(rbffi_StructByReferenceClass, "from_native", sbr_from_native, 2); } ruby-ffi-1.9.3debian.orig/ffi.gemspec0000644000175000017500000000164012261216357017702 0ustar terceiroterceirorequire File.expand_path("../lib/#{File.basename(__FILE__, '.gemspec')}/version", __FILE__) Gem::Specification.new do |s| s.name = 'ffi' s.version = FFI::VERSION s.author = 'Wayne Meissner' s.email = 'wmeissner@gmail.com' s.homepage = 'http://wiki.github.com/ffi/ffi' s.summary = 'Ruby FFI' s.description = 'Ruby FFI library' s.files = %w(ffi.gemspec LICENSE COPYING README.md Rakefile) + Dir.glob("{ext,gen,lib,spec,libtest}/**/*").reject { |f| f =~ /(lib\/[12]\.[089]|\.so$|\.bundle$)/ } s.extensions << 'ext/ffi_c/extconf.rb' s.has_rdoc = false s.rdoc_options = %w[--exclude=ext/ffi_c/.*\.o$ --exclude=ffi_c\.(bundle|so)$] s.license = 'BSD' s.require_paths << 'ext/ffi_c' s.required_ruby_version = '>= 1.8.7' s.add_development_dependency 'rake' s.add_development_dependency 'rake-compiler', '>=0.6.0' s.add_development_dependency 'rspec' s.add_development_dependency 'rubygems-tasks' end ruby-ffi-1.9.3debian.orig/checksums.yaml.gz0000444000175000017500000000065312261216357021062 0ustar terceiroterceiro?qRA0FtJ9di927J*`{XE[;m*큓{vc|mBԤ y$磽{o$I X+]:-dv<0ڋ"*juJ#C8G?,p|m)J1y 3T8{!{(|i?hNKY583̅r W6y1&""/P* kѯʹ95MU&"WTgJr.s4W^ ~^X->.U[L3 VΩJjNvP޼R2v)eg_(`Ind?Zh]b{c`ʁXrz( <6rruby-ffi-1.9.3debian.orig/Rakefile0000644000175000017500000001321312261216357017235 0ustar terceiroterceirorequire 'rubygems' require 'rubygems/package_task' require 'rubygems/tasks' require 'rbconfig' require 'rake/clean' USE_RAKE_COMPILER = (RUBY_PLATFORM =~ /java/) ? false : true if USE_RAKE_COMPILER gem 'rake-compiler', '>=0.6.0' require 'rake/extensiontask' end require 'date' require 'fileutils' require 'rbconfig' LIBEXT = case RbConfig::CONFIG['host_os'].downcase when /darwin/ "dylib" when /mswin|mingw/ "dll" else RbConfig::CONFIG['DLEXT'] end CPU = case RbConfig::CONFIG['host_cpu'].downcase when /i[3456]86/ # Darwin always reports i686, even when running in 64bit mode if RbConfig::CONFIG['host_os'] =~ /darwin/ && 0xfee1deadbeef.is_a?(Fixnum) "x86_64" else "i386" end when /amd64|x86_64/ "x86_64" when /ppc64|powerpc64/ "powerpc64" when /ppc|powerpc/ "powerpc" when /^arm/ "arm" else RbConfig::CONFIG['host_cpu'] end OS = case RbConfig::CONFIG['host_os'].downcase when /linux/ "linux" when /darwin/ "darwin" when /freebsd/ "freebsd" when /openbsd/ "openbsd" when /sunos|solaris/ "solaris" when /mswin|mingw/ "win32" else RbConfig::CONFIG['host_os'].downcase end GMAKE = system('which gmake >/dev/null') && 'gmake' || 'make' LIBTEST = "build/libtest.#{LIBEXT}" BUILD_DIR = "build" BUILD_EXT_DIR = File.join(BUILD_DIR, "#{RbConfig::CONFIG['arch']}", 'ffi_c', RUBY_VERSION) def gem_spec @gem_spec ||= Gem::Specification.load('ffi.gemspec') end TEST_DEPS = [ LIBTEST ] if RUBY_PLATFORM == "java" desc "Run all specs" task :specs => TEST_DEPS do sh %{#{Gem.ruby} -w -S rspec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color} end desc "Run rubinius specs" task :rbxspecs => TEST_DEPS do sh %{#{Gem.ruby} -w -S rspec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color} end else TEST_DEPS.unshift :compile desc "Run all specs" task :specs => TEST_DEPS do ENV["MRI_FFI"] = "1" sh %{#{Gem.ruby} -w -Ilib -I#{BUILD_EXT_DIR} -S rspec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color} end desc "Run rubinius specs" task :rbxspecs => TEST_DEPS do ENV["MRI_FFI"] = "1" sh %{#{Gem.ruby} -w -Ilib -I#{BUILD_EXT_DIR} -S rspec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color} end end desc "Build all packages" task :package => 'gem:package' CLOBBER.include 'build' CLOBBER.include FileList['lib/**/ffi_c.so'] CLOBBER.include FileList["lib/**/ffi_c.#{RbConfig::CONFIG['DLEXT']}"] CLOBBER.include 'lib/ffi/types.conf' CLOBBER.include 'conftest.dSYM' CLOBBER.include 'pkg' task :distclean => :clobber desc "Build the native test lib" file "build/libtest.#{LIBEXT}" => FileList['libtest/**/*.[ch]'] do sh %{#{GMAKE} -f libtest/GNUmakefile CPU=#{CPU} OS=#{OS} } end desc "Build test helper lib" task :libtest => "build/libtest.#{LIBEXT}" desc "Test the extension" task :test => [ :specs, :rbxspecs ] namespace :bench do ITER = ENV['ITER'] ? ENV['ITER'].to_i : 100000 bench_libs = "-Ilib -I#{BUILD_DIR}" unless RUBY_PLATFORM == "java" bench_files = Dir["bench/bench_*.rb"].reject { |f| f == "bench_helper.rb" } bench_files.each do |bench| task File.basename(bench, ".rb")[6..-1] => TEST_DEPS do sh %{#{Gem.ruby} #{bench_libs} #{bench} #{ITER}} end end task :all => TEST_DEPS do bench_files.each do |bench| sh %{#{Gem.ruby} #{bench_libs} #{bench}} end end end task 'spec:run' => TEST_DEPS task 'spec:specdoc' => TEST_DEPS task :default => :specs task 'gem:win32' do sh("rake cross native gem RUBY_CC_VERSION='1.8.7:1.9.3:2.0.0'") || raise("win32 build failed!") end namespace 'java' do java_gem_spec = Gem::Specification.new do |s| s.name = gem_spec.name s.version = gem_spec.version s.author = gem_spec.author s.email = gem_spec.email s.homepage = gem_spec.homepage s.summary = gem_spec.summary s.description = gem_spec.description s.files = %w(History.txt LICENSE COPYING COPYING.LESSER README.md Rakefile) s.has_rdoc = false s.license = gem_spec.license s.platform = 'java' end Gem::PackageTask.new(java_gem_spec) do |pkg| pkg.need_zip = true pkg.need_tar = true pkg.package_dir = 'pkg' end end task 'gem:java' => 'java:gem' if USE_RAKE_COMPILER Rake::ExtensionTask.new('ffi_c', gem_spec) do |ext| ext.name = 'ffi_c' # indicate the name of the extension. # ext.lib_dir = BUILD_DIR # put binaries into this folder. ext.tmp_dir = BUILD_DIR # temporary folder used during compilation. ext.cross_compile = true # enable cross compilation (requires cross compile toolchain) ext.cross_platform = %w[i386-mingw32 x64-mingw32] # forces the Windows platform instead of the default one end ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version| task "copy:ffi_c:i386-mingw32:#{ruby_version}" do |t| %w[lib #{BUILD_DIR}/i386-mingw32/stage/lib].each do |dir| if File.exists?("#{dir}/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so") sh "i686-w64-mingw32-strip -S #{dir}/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so" end end end task "copy:ffi_c:x64-mingw32:#{ruby_version}" do |t| if File.exists?("#{BUILD_DIR}/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so") sh "x86_64-w64-mingw32-strip -S #{BUILD_DIR}/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so" end end end end Gem::Tasks.new do |t| t.scm.tag.format = '%s' end begin require 'yard' namespace :doc do YARD::Rake::YardocTask.new do |yard| end end rescue LoadError warn "[warn] YARD unavailable" end ruby-ffi-1.9.3debian.orig/lib/0000755000175000017500000000000012261216360016330 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi.rb0000644000175000017500000000140712261216360017423 0ustar terceiroterceiroif !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx' Object.send(:remove_const, :FFI) if defined?(::FFI) begin if RUBY_VERSION =~ /1.8/ require '1.8/ffi_c' elsif RUBY_VERSION =~ /1.9/ require '1.9/ffi_c' elsif RUBY_VERSION =~ /2.0/ require '2.0/ffi_c' else require 'ffi_c' end rescue Exception require 'ffi_c' end require 'ffi/ffi' elsif defined?(RUBY_ENGINE) # Remove the ffi gem dir from the load path, then reload the internal ffi implementation $LOAD_PATH.delete(File.dirname(__FILE__)) $LOAD_PATH.delete(File.join(File.dirname(__FILE__), 'ffi')) unless $LOADED_FEATURES.nil? $LOADED_FEATURES.delete(__FILE__) $LOADED_FEATURES.delete('ffi.rb') end require 'ffi.rb' end ruby-ffi-1.9.3debian.orig/lib/ffi/0000755000175000017500000000000012261216360017074 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/union.rb0000644000175000017500000000334512261216360020556 0ustar terceiroterceiro# # Copyright (C) 2009 Andrea Fazzi # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # require 'ffi/struct' module FFI class Union < FFI::Struct def self.builder b = StructLayoutBuilder.new b.union = true b end end end ruby-ffi-1.9.3debian.orig/lib/ffi/types.rb0000644000175000017500000001263412261216360020573 0ustar terceiroterceiro# # Copyright (C) 2008-2010 Wayne Meissner # Copyright (c) 2007, 2008 Evan Phoenix # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # see {file:README} module FFI # @param [Type, DataConverter, Symbol] old type definition used by {FFI.find_type} # @param [Symbol] add new type definition's name to add # @return [Type] # Add a definition type to type definitions. def self.typedef(old, add) TypeDefs[add] = self.find_type(old) end # (see FFI.typedef) def self.add_typedef(old, add) typedef old, add end # @param [Type, DataConverter, Symbol] name # @param [Hash] type_map if nil, {FFI::TypeDefs} is used # @return [Type] # Find a type in +type_map+ ({FFI::TypeDefs}, by default) from # a type objet, a type name (symbol). If +name+ is a {DataConverter}, # a new {Type::Mapped} is created. def self.find_type(name, type_map = nil) if name.is_a?(Type) name elsif type_map && type_map.has_key?(name) type_map[name] elsif TypeDefs.has_key?(name) TypeDefs[name] elsif name.is_a?(DataConverter) (type_map || TypeDefs)[name] = Type::Mapped.new(name) else raise TypeError, "unable to resolve type '#{name}'" end end # List of type definitions TypeDefs.merge!({ # The C void type; only useful for function return types :void => Type::VOID, # C boolean type :bool => Type::BOOL, # C nul-terminated string :string => Type::STRING, # C signed char :char => Type::CHAR, # C unsigned char :uchar => Type::UCHAR, # C signed short :short => Type::SHORT, # C unsigned short :ushort => Type::USHORT, # C signed int :int => Type::INT, # C unsigned int :uint => Type::UINT, # C signed long :long => Type::LONG, # C unsigned long :ulong => Type::ULONG, # C signed long long integer :long_long => Type::LONG_LONG, # C unsigned long long integer :ulong_long => Type::ULONG_LONG, # C single precision float :float => Type::FLOAT, # C double precision float :double => Type::DOUBLE, # C long double :long_double => Type::LONGDOUBLE, # Native memory address :pointer => Type::POINTER, # 8 bit signed integer :int8 => Type::INT8, # 8 bit unsigned integer :uint8 => Type::UINT8, # 16 bit signed integer :int16 => Type::INT16, # 16 bit unsigned integer :uint16 => Type::UINT16, # 32 bit signed integer :int32 => Type::INT32, # 32 bit unsigned integer :uint32 => Type::UINT32, # 64 bit signed integer :int64 => Type::INT64, # 64 bit unsigned integer :uint64 => Type::UINT64, :buffer_in => Type::BUFFER_IN, :buffer_out => Type::BUFFER_OUT, :buffer_inout => Type::BUFFER_INOUT, # Used in function prototypes to indicate the arguments are variadic :varargs => Type::VARARGS, }) class StrPtrConverter extend DataConverter native_type Type::POINTER # @param [Pointer] val # @param [] ctx # @return [Array(String, Pointer)] # Returns a [ String, Pointer ] tuple so the C memory for the string can be freed def self.from_native(val, ctx) [ val.null? ? nil : val.get_string(0), val ] end end typedef(StrPtrConverter, :strptr) # @param type +type+ is an instance of class accepted by {FFI.find_type} # @return [Numeric] # Get +type+ size, in bytes. def self.type_size(type) find_type(type).size end # Load all the platform dependent types begin File.open(File.join(Platform::CONF_DIR, 'types.conf'), "r") do |f| prefix = "rbx.platform.typedef." f.each_line { |line| if line.index(prefix) == 0 new_type, orig_type = line.chomp.slice(prefix.length..-1).split(/\s*=\s*/) typedef(orig_type.to_sym, new_type.to_sym) end } end typedef :pointer, :caddr_t rescue Errno::ENOENT end end ruby-ffi-1.9.3debian.orig/lib/ffi/library.rb0000644000175000017500000004107012261216360021067 0ustar terceiroterceiro# # Copyright (C) 2008-2010 Wayne Meissner # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.# module FFI CURRENT_PROCESS = USE_THIS_PROCESS_AS_LIBRARY = Object.new # @param [#to_s] lib library name # @return [String] library name formatted for current platform # Transform a generic library name to a platform library name # @example # # Linux # FFI.map_library_name 'c' # -> "libc.so.6" # FFI.map_library_name 'jpeg' # -> "libjpeg.so" # # Windows # FFI.map_library_name 'c' # -> "msvcrt.dll" # FFI.map_library_name 'jpeg' # -> "jpeg.dll" def self.map_library_name(lib) # Mangle the library name to reflect the native library naming conventions lib = lib.to_s unless lib.kind_of?(String) lib = Library::LIBC if lib == 'c' if lib && File.basename(lib) == lib lib = Platform::LIBPREFIX + lib unless lib =~ /^#{Platform::LIBPREFIX}/ r = Platform::IS_GNU ? "\\.so($|\\.[1234567890]+)" : "\\.#{Platform::LIBSUFFIX}$" lib += ".#{Platform::LIBSUFFIX}" unless lib =~ /#{r}/ end lib end # Exception raised when a function is not found in libraries class NotFoundError < LoadError def initialize(function, *libraries) super("Function '#{function}' not found in [#{libraries[0].nil? ? 'current process' : libraries.join(", ")}]") end end # This module is the base to use native functions. # # A basic usage may be: # require 'ffi' # # module Hello # extend FFI::Library # ffi_lib FFI::Library::LIBC # attach_function 'puts', [ :string ], :int # end # # Hello.puts("Hello, World") # # module Library CURRENT_PROCESS = FFI::CURRENT_PROCESS LIBC = FFI::Platform::LIBC # @param mod extended object # @return [nil] # @raise {RuntimeError} if +mod+ is not a Module # Test if extended object is a Module. If not, raise RuntimeError. def self.extended(mod) raise RuntimeError.new("must only be extended by module") unless mod.kind_of?(Module) end # @param [Array] names names of libraries to load # @return [Array] # @raise {LoadError} if a library cannot be opened # Load native libraries. def ffi_lib(*names) raise LoadError.new("library names list must not be empty") if names.empty? lib_flags = defined?(@ffi_lib_flags) ? @ffi_lib_flags : FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL ffi_libs = names.map do |name| if name == FFI::CURRENT_PROCESS FFI::DynamicLibrary.open(nil, FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL) else libnames = (name.is_a?(::Array) ? name : [ name ]).map { |n| [ n, FFI.map_library_name(n) ].uniq }.flatten.compact lib = nil errors = {} libnames.each do |libname| begin lib = FFI::DynamicLibrary.open(libname, lib_flags) break if lib rescue Exception => ex ldscript = false if ex.message =~ /(([^ \t()])+\.so([^ \t:()])*):([ \t])*invalid ELF header/ if File.read($1) =~ /GROUP *\( *([^ \)]+) *\)/ libname = $1 ldscript = true end end if ldscript retry else errors[libname] = ex end end end if lib.nil? raise LoadError.new(errors.values.join(".\n")) end # return the found lib lib end end @ffi_libs = ffi_libs end # Set the calling convention for {#attach_function} and {#callback} # # @see http://en.wikipedia.org/wiki/Stdcall#stdcall # @note +:stdcall+ is typically used for attaching Windows API functions # # @param [Symbol] convention one of +:default+, +:stdcall+ # @return [Symbol] the new calling convention def ffi_convention(convention = nil) @ffi_convention ||= :default @ffi_convention = convention if convention @ffi_convention end # @see #ffi_lib # @return [Array] array of currently loaded FFI libraries # @raise [LoadError] if no libraries have been loaded (using {#ffi_lib}) # Get FFI libraries loaded using {#ffi_lib}. def ffi_libraries raise LoadError.new("no library specified") if !defined?(@ffi_libs) || @ffi_libs.empty? @ffi_libs end # Flags used in {#ffi_lib}. # # This map allows you to supply symbols to {#ffi_lib_flags} instead of # the actual constants. FlagsMap = { :global => DynamicLibrary::RTLD_GLOBAL, :local => DynamicLibrary::RTLD_LOCAL, :lazy => DynamicLibrary::RTLD_LAZY, :now => DynamicLibrary::RTLD_NOW } # Sets library flags for {#ffi_lib}. # # @example # ffi_lib_flags(:lazy, :local) # => 5 # # @param [Symbol, …] flags (see {FlagsMap}) # @return [Fixnum] the new value def ffi_lib_flags(*flags) @ffi_lib_flags = flags.inject(0) { |result, f| result | FlagsMap[f] } end ## # @overload attach_function(func, args, returns, options = {}) # @example attach function without an explicit name # module Foo # extend FFI::Library # ffi_lib FFI::Library::LIBC # attach_function :malloc, [:size_t], :pointer # end # # now callable via Foo.malloc # @overload attach_function(name, func, args, returns, options = {}) # @example attach function with an explicit name # module Bar # extend FFI::Library # ffi_lib FFI::Library::LIBC # attach_function :c_malloc, :malloc, [:size_t], :pointer # end # # now callable via Bar.c_malloc # # Attach C function +func+ to this module. # # # @param [#to_s] name name of ruby method to attach as # @param [#to_s] func name of C function to attach # @param [Array] args an array of types # @param [Symbol] returns type of return value # @option options [Boolean] :blocking (@blocking) set to true if the C function is a blocking call # @option options [Symbol] :convention (:default) calling convention (see {#ffi_convention}) # @option options [FFI::Enums] :enums # @option options [Hash] :type_map # # @return [FFI::VariadicInvoker] # # @raise [FFI::NotFoundError] if +func+ cannot be found in the attached libraries (see {#ffi_lib}) def attach_function(name, func, args, returns = nil, options = nil) mname, a2, a3, a4, a5 = name, func, args, returns, options cname, arg_types, ret_type, opts = (a4 && (a2.is_a?(String) || a2.is_a?(Symbol))) ? [ a2, a3, a4, a5 ] : [ mname.to_s, a2, a3, a4 ] # Convert :foo to the native type arg_types = arg_types.map { |e| find_type(e) } options = { :convention => ffi_convention, :type_map => defined?(@ffi_typedefs) ? @ffi_typedefs : nil, :blocking => defined?(@blocking) && @blocking, :enums => defined?(@ffi_enums) ? @ffi_enums : nil, } @blocking = false options.merge!(opts) if opts && opts.is_a?(Hash) # Try to locate the function in any of the libraries invokers = [] ffi_libraries.each do |lib| if invokers.empty? begin function = nil function_names(cname, arg_types).find do |fname| function = lib.find_function(fname) end raise LoadError unless function invokers << if arg_types.length > 0 && arg_types[arg_types.length - 1] == FFI::NativeType::VARARGS VariadicInvoker.new(function, arg_types, find_type(ret_type), options) else Function.new(find_type(ret_type), arg_types, function, options) end rescue LoadError end end end invoker = invokers.compact.shift raise FFI::NotFoundError.new(cname.to_s, ffi_libraries.map { |lib| lib.name }) unless invoker invoker.attach(self, mname.to_s) invoker end # @param [#to_s] name function name # @param [Array] arg_types function's argument types # @return [Array] # This function returns a list of possible names to lookup. # @note Function names on windows may be decorated if they are using stdcall. See # * http://en.wikipedia.org/wiki/Name_mangling#C_name_decoration_in_Microsoft_Windows # * http://msdn.microsoft.com/en-us/library/zxk0tw93%28v=VS.100%29.aspx # * http://en.wikibooks.org/wiki/X86_Disassembly/Calling_Conventions#STDCALL # Note that decorated names can be overridden via def files. Also note that the # windows api, although using, doesn't have decorated names. def function_names(name, arg_types) result = [name.to_s] if ffi_convention == :stdcall # Get the size of each parameter size = arg_types.inject(0) do |mem, arg| mem + arg.size end # Next, the size must be a multiple of 4 size += (4 - size) % 4 result << "_#{name.to_s}@#{size}" # win32 result << "#{name.to_s}@#{size}" # win64 end result end # @overload attach_variable(mname, cname, type) # @example # module Bar # extend FFI::Library # ffi_lib 'my_lib' # attach_variable :c_myvar, :myvar, :long # end # # now callable via Bar.c_myvar # @overload attach_variable(cname, type) # @example # module Bar # extend FFI::Library # ffi_lib 'my_lib' # attach_variable :myvar, :long # end # # now callable via Bar.myvar # @param [#to_s] mname name of ruby method to attach as # @param [#to_s] cname name of C variable to attach # @param [DataConverter, Struct, Symbol, Type] type C varaible's type # @return [DynamicLibrary::Symbol] # @raise {FFI::NotFoundError} if +cname+ cannot be found in libraries # # Attach C variable +cname+ to this module. def attach_variable(mname, a1, a2 = nil) cname, type = a2 ? [ a1, a2 ] : [ mname.to_s, a1 ] address = nil ffi_libraries.each do |lib| begin address = lib.find_variable(cname.to_s) break unless address.nil? rescue LoadError end end raise FFI::NotFoundError.new(cname, ffi_libraries) if address.nil? || address.null? if type.is_a?(Class) && type < FFI::Struct # If it is a global struct, just attach directly to the pointer s = type.new(address) self.module_eval <<-code, __FILE__, __LINE__ @@ffi_gvar_#{mname} = s def self.#{mname} @@ffi_gvar_#{mname} end code else sc = Class.new(FFI::Struct) sc.layout :gvar, find_type(type) s = sc.new(address) # # Attach to this module as mname/mname= # self.module_eval <<-code, __FILE__, __LINE__ @@ffi_gvar_#{mname} = s def self.#{mname} @@ffi_gvar_#{mname}[:gvar] end def self.#{mname}=(value) @@ffi_gvar_#{mname}[:gvar] = value end code end address end # @overload callback(name, params, ret) # @overload callback(params, ret) # @param name callback name to add to type map # @param [Array] params array of parameters' types # @param [DataConverter, Struct, Symbol, Type] ret callback return type # @return [FFI::CallbackInfo] def callback(*args) raise ArgumentError, "wrong number of arguments" if args.length < 2 || args.length > 3 name, params, ret = if args.length == 3 args else [ nil, args[0], args[1] ] end native_params = params.map { |e| find_type(e) } raise ArgumentError, "callbacks cannot have variadic parameters" if native_params.include?(FFI::Type::VARARGS) options = Hash.new options[:convention] = ffi_convention options[:enums] = @ffi_enums if defined?(@ffi_enums) cb = FFI::CallbackInfo.new(find_type(ret), native_params, options) # Add to the symbol -> type map (unless there was no name) unless name.nil? typedef cb, name end cb end # @param [DataConverter, Symbol, Type] old # @param add # @param [] info # @return [FFI::Enum, FFI::Type] # Register or get an already registered type definition. # # To register a new type definition, +old+ should be a {FFI::Type}. +add+ # is in this case the type definition. # # If +old+ is a {DataConverter}, a {Type::Mapped} is returned. # # If +old+ is +:enum+ # * and +add+ is an +Array+, a call to {#enum} is made with +add+ as single parameter; # * in others cases, +info+ is used to create a named enum. # # If +old+ is a key for type map, #typedef get +old+ type definition. def typedef(old, add, info=nil) @ffi_typedefs = Hash.new unless defined?(@ffi_typedefs) @ffi_typedefs[add] = if old.kind_of?(FFI::Type) old elsif @ffi_typedefs.has_key?(old) @ffi_typedefs[old] elsif old.is_a?(DataConverter) FFI::Type::Mapped.new(old) elsif old == :enum if add.kind_of?(Array) self.enum(add) else self.enum(info, add) end else FFI.find_type(old) end end # @overload enum(name, values) # Create a named enum. # @example # enum :foo, [:zero, :one, :two] # named enum # @param [Symbol] name name for new enum # @param [Array] values values for enum # @overload enum(*args) # Create an unnamed enum. # @example # enum :zero, :one, :two # unnamed enum # @param args values for enum # @overload enum(values) # Create an unnamed enum. # @example # enum [:zero, :one, :two] # unnamed enum, equivalent to above example # @param [Array] values values for enum # @return [FFI::Enum] # Create a new {FFI::Enum}. def enum(*args) name, values = if args[0].kind_of?(Symbol) && args[1].kind_of?(Array) [ args[0], args[1] ] elsif args[0].kind_of?(Array) [ nil, args[0] ] else [ nil, args ] end @ffi_enums = FFI::Enums.new unless defined?(@ffi_enums) @ffi_enums << (e = FFI::Enum.new(values, name)) # If called as enum :foo, [ :zero, :one, :two ], add a typedef alias typedef(e, name) if name e end # @param name # @return [FFI::Enum] # Find an enum by name. def enum_type(name) @ffi_enums.find(name) if defined?(@ffi_enums) end # @param symbol # @return [FFI::Enum] # Find an enum by a symbol it contains. def enum_value(symbol) @ffi_enums.__map_symbol(symbol) end # @param [DataConverter, Type, Struct, Symbol] t type to find # @return [Type] # Find a type definition. def find_type(t) if t.kind_of?(Type) t elsif defined?(@ffi_typedefs) && @ffi_typedefs.has_key?(t) @ffi_typedefs[t] elsif t.is_a?(Class) && t < Struct Type::POINTER elsif t.is_a?(DataConverter) # Add a typedef so next time the converter is used, it hits the cache typedef Type::Mapped.new(t), t end || FFI.find_type(t) end end end ruby-ffi-1.9.3debian.orig/lib/ffi/buffer.rb0000644000175000017500000000021212261216360020665 0ustar terceiroterceiro# # All the code from this file is now implemented in C. This file remains # to satisfy any leftover require 'ffi/buffer' in user code # ruby-ffi-1.9.3debian.orig/lib/ffi/ffi.rb0000644000175000017500000000354212261216360020171 0ustar terceiroterceiro# # Copyright (C) 2008-2010 JRuby project # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. require 'ffi/platform' require 'ffi/types' require 'ffi/library' require 'ffi/errno' require 'ffi/pointer' require 'ffi/memorypointer' require 'ffi/struct' require 'ffi/union' require 'ffi/managedstruct' require 'ffi/callback' require 'ffi/io' require 'ffi/autopointer' require 'ffi/variadic' require 'ffi/enum' ruby-ffi-1.9.3debian.orig/lib/ffi/version.rb0000644000175000017500000000004412261216360021104 0ustar terceiroterceiromodule FFI VERSION = '1.9.3' end ruby-ffi-1.9.3debian.orig/lib/ffi/variadic.rb0000644000175000017500000000516712261216360021214 0ustar terceiroterceiro# # Copyright (C) 2008, 2009 Wayne Meissner # Copyright (C) 2009 Luc Heinrich # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # module FFI class VariadicInvoker def init(arg_types, type_map) @fixed = Array.new @type_map = type_map arg_types.each_with_index do |type, i| @fixed << type unless type == Type::VARARGS end end def call(*args, &block) param_types = Array.new(@fixed) param_values = Array.new @fixed.each_with_index do |t, i| param_values << args[i] end i = @fixed.length while i < args.length param_types << FFI.find_type(args[i], @type_map) param_values << args[i + 1] i += 2 end invoke(param_types, param_values, &block) end # # Attach the invoker to module +mod+ as +mname+ # def attach(mod, mname) invoker = self params = "*args" call = "call" mod.module_eval <<-code @@#{mname} = invoker def self.#{mname}(#{params}) @@#{mname}.#{call}(#{params}) end def #{mname}(#{params}) @@#{mname}.#{call}(#{params}) end code invoker end end end ruby-ffi-1.9.3debian.orig/lib/ffi/callback.rb0000644000175000017500000000021412261216360021152 0ustar terceiroterceiro# # All the code from this file is now implemented in C. This file remains # to satisfy any leftover require 'ffi/callback' in user code # ruby-ffi-1.9.3debian.orig/lib/ffi/platform/0000755000175000017500000000000012261216360020720 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/powerpc-linux/0000755000175000017500000000000012261216360023534 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/powerpc-linux/types.conf0000644000175000017500000000751312261216360025555 0ustar terceiroterceirorbx.platform.typedef.__u_char = uchar rbx.platform.typedef.__u_short = ushort rbx.platform.typedef.__u_int = uint rbx.platform.typedef.__u_long = ulong rbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__quad_t = long_long rbx.platform.typedef.__u_quad_t = ulong_long rbx.platform.typedef.__dev_t = ulong_long rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__ino_t = ulong rbx.platform.typedef.__ino64_t = ulong_long rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = uint rbx.platform.typedef.__off_t = long rbx.platform.typedef.__off64_t = long_long rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__clock_t = long rbx.platform.typedef.__rlim_t = ulong rbx.platform.typedef.__rlim64_t = ulong_long rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__time_t = long rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = long rbx.platform.typedef.__daddr_t = int rbx.platform.typedef.__swblk_t = long rbx.platform.typedef.__key_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__timer_t = pointer rbx.platform.typedef.__blksize_t = long rbx.platform.typedef.__blkcnt_t = long rbx.platform.typedef.__blkcnt64_t = long_long rbx.platform.typedef.__fsblkcnt_t = ulong rbx.platform.typedef.__fsblkcnt64_t = ulong_long rbx.platform.typedef.__fsfilcnt_t = ulong rbx.platform.typedef.__fsfilcnt64_t = ulong_long rbx.platform.typedef.__ssize_t = int rbx.platform.typedef.__loff_t = long_long rbx.platform.typedef.*__qaddr_t = long_long rbx.platform.typedef.*__caddr_t = char rbx.platform.typedef.__intptr_t = int rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.loff_t = long_long rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.dev_t = ulong_long rbx.platform.typedef.gid_t = uint rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.uid_t = uint rbx.platform.typedef.off_t = long_long rbx.platform.typedef.pid_t = int rbx.platform.typedef.id_t = uint rbx.platform.typedef.ssize_t = int rbx.platform.typedef.daddr_t = int rbx.platform.typedef.key_t = int rbx.platform.typedef.time_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = pointer rbx.platform.typedef.size_t = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = long rbx.platform.typedef.__sig_atomic_t = int rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.__fd_mask = long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.fsblkcnt_t = ulong_long rbx.platform.typedef.fsfilcnt_t = ulong_long rbx.platform.typedef.pthread_t = ulong rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.pthread_once_t = int rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.__rlimit_resource_t = int rbx.platform.typedef.__rusage_who_t = int rbx.platform.typedef.__priority_which_t = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/mipsel-linux/0000755000175000017500000000000012261216360023346 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/mipsel-linux/types.conf0000644000175000017500000000762512261216360025373 0ustar terceiroterceirorbx.platform.typedef.__u_char = uchar rbx.platform.typedef.__u_short = ushort rbx.platform.typedef.__u_int = uint rbx.platform.typedef.__u_long = ulong rbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__quad_t = long_long rbx.platform.typedef.__u_quad_t = ulong_long rbx.platform.typedef.__dev_t = ulong_long rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__ino_t = ulong rbx.platform.typedef.__ino64_t = ulong_long rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = uint rbx.platform.typedef.__off_t = long rbx.platform.typedef.__off64_t = long_long rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__clock_t = long rbx.platform.typedef.__rlim_t = ulong rbx.platform.typedef.__rlim64_t = ulong_long rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__time_t = long rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = long rbx.platform.typedef.__daddr_t = int rbx.platform.typedef.__swblk_t = long rbx.platform.typedef.__key_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__timer_t = pointer rbx.platform.typedef.__blksize_t = long rbx.platform.typedef.__blkcnt_t = long rbx.platform.typedef.__blkcnt64_t = long_long rbx.platform.typedef.__fsblkcnt_t = ulong rbx.platform.typedef.__fsblkcnt64_t = ulong_long rbx.platform.typedef.__fsfilcnt_t = ulong rbx.platform.typedef.__fsfilcnt64_t = ulong_long rbx.platform.typedef.__ssize_t = int rbx.platform.typedef.__loff_t = long_long rbx.platform.typedef.*__qaddr_t = long_long rbx.platform.typedef.*__caddr_t = char rbx.platform.typedef.__intptr_t = int rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.loff_t = long_long rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.dev_t = ulong_long rbx.platform.typedef.gid_t = uint rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.uid_t = uint rbx.platform.typedef.off_t = long_long rbx.platform.typedef.pid_t = int rbx.platform.typedef.id_t = uint rbx.platform.typedef.ssize_t = int rbx.platform.typedef.daddr_t = int rbx.platform.typedef.key_t = int rbx.platform.typedef.clock_t = long rbx.platform.typedef.time_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = pointer rbx.platform.typedef.size_t = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = long rbx.platform.typedef.__sig_atomic_t = int rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.__fd_mask = long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.blksize_t = long rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.fsblkcnt_t = ulong_long rbx.platform.typedef.fsfilcnt_t = ulong_long rbx.platform.typedef.pthread_t = ulong rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.pthread_once_t = int rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.__rlimit_resource_t = int rbx.platform.typedef.__rusage_who_t = int rbx.platform.typedef.__priority_which_t = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/s390x-linux/0000755000175000017500000000000012261216360022743 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/s390x-linux/types.conf0000644000175000017500000000745012261216360024764 0ustar terceiroterceirorbx.platform.typedef.__u_char = uchar rbx.platform.typedef.__u_short = ushort rbx.platform.typedef.__u_int = uint rbx.platform.typedef.__u_long = ulong rbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long rbx.platform.typedef.__uint64_t = ulong rbx.platform.typedef.__quad_t = long rbx.platform.typedef.__u_quad_t = ulong rbx.platform.typedef.__dev_t = ulong rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__ino_t = ulong rbx.platform.typedef.__ino64_t = ulong rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = ulong rbx.platform.typedef.__off_t = long rbx.platform.typedef.__off64_t = long rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__clock_t = long rbx.platform.typedef.__rlim_t = ulong rbx.platform.typedef.__rlim64_t = ulong rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__time_t = long rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = long rbx.platform.typedef.__daddr_t = int rbx.platform.typedef.__swblk_t = long rbx.platform.typedef.__key_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__timer_t = pointer rbx.platform.typedef.__blksize_t = long rbx.platform.typedef.__blkcnt_t = long rbx.platform.typedef.__blkcnt64_t = long rbx.platform.typedef.__fsblkcnt_t = ulong rbx.platform.typedef.__fsblkcnt64_t = ulong rbx.platform.typedef.__fsfilcnt_t = ulong rbx.platform.typedef.__fsfilcnt64_t = ulong rbx.platform.typedef.__ssize_t = long rbx.platform.typedef.__loff_t = long rbx.platform.typedef.*__qaddr_t = long rbx.platform.typedef.*__caddr_t = char rbx.platform.typedef.__intptr_t = long rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.quad_t = long rbx.platform.typedef.u_quad_t = ulong rbx.platform.typedef.loff_t = long rbx.platform.typedef.ino_t = ulong rbx.platform.typedef.dev_t = ulong rbx.platform.typedef.gid_t = uint rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = ulong rbx.platform.typedef.uid_t = uint rbx.platform.typedef.off_t = long rbx.platform.typedef.pid_t = int rbx.platform.typedef.id_t = uint rbx.platform.typedef.ssize_t = long rbx.platform.typedef.daddr_t = int rbx.platform.typedef.key_t = int rbx.platform.typedef.clock_t = long rbx.platform.typedef.time_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = pointer rbx.platform.typedef.size_t = ulong rbx.platform.typedef.ulong = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = long rbx.platform.typedef.__sig_atomic_t = int rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.__fd_mask = long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.blksize_t = long rbx.platform.typedef.blkcnt_t = long rbx.platform.typedef.fsblkcnt_t = ulong rbx.platform.typedef.fsfilcnt_t = ulong rbx.platform.typedef.pthread_t = ulong rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.pthread_once_t = int rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.rlim_t = ulong rbx.platform.typedef.__rlimit_resource_t = int rbx.platform.typedef.__rusage_who_t = int rbx.platform.typedef.__priority_which_t = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-linux/0000755000175000017500000000000012261216360022546 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-linux/types.conf0000644000175000017500000000767712261216360024602 0ustar terceiroterceirorbx.platform.typedef.__u_char = uchar rbx.platform.typedef.__u_short = ushort rbx.platform.typedef.__u_int = uint rbx.platform.typedef.__u_long = ulong rbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__quad_t = long_long rbx.platform.typedef.__u_quad_t = ulong_long rbx.platform.typedef.__dev_t = ulong_long rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__ino_t = ulong rbx.platform.typedef.__ino64_t = ulong_long rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = uint rbx.platform.typedef.__off_t = long rbx.platform.typedef.__off64_t = long_long rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__clock_t = long rbx.platform.typedef.__rlim_t = ulong rbx.platform.typedef.__rlim64_t = ulong_long rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__time_t = long rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = long rbx.platform.typedef.__daddr_t = int rbx.platform.typedef.__swblk_t = long rbx.platform.typedef.__key_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__timer_t = pointer rbx.platform.typedef.blksize_t = long rbx.platform.typedef.__blksize_t = long rbx.platform.typedef.__blkcnt_t = long rbx.platform.typedef.__blkcnt64_t = long_long rbx.platform.typedef.__fsblkcnt_t = ulong rbx.platform.typedef.__fsblkcnt64_t = ulong_long rbx.platform.typedef.__fsfilcnt_t = ulong rbx.platform.typedef.__fsfilcnt64_t = ulong_long rbx.platform.typedef.__ssize_t = int rbx.platform.typedef.__loff_t = long_long rbx.platform.typedef.*__qaddr_t = long_long rbx.platform.typedef.*__caddr_t = char rbx.platform.typedef.__intptr_t = int rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.loff_t = long_long rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.dev_t = ulong_long rbx.platform.typedef.gid_t = uint rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.uid_t = uint rbx.platform.typedef.off_t = long_long rbx.platform.typedef.pid_t = int rbx.platform.typedef.id_t = uint rbx.platform.typedef.ssize_t = int rbx.platform.typedef.daddr_t = int rbx.platform.typedef.key_t = int rbx.platform.typedef.time_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = pointer rbx.platform.typedef.size_t = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = long rbx.platform.typedef.__sig_atomic_t = int rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.__fd_mask = long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.fsblkcnt_t = ulong_long rbx.platform.typedef.fsfilcnt_t = ulong_long rbx.platform.typedef.pthread_t = ulong rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.pthread_once_t = int rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.__rlimit_resource_t = int rbx.platform.typedef.__rusage_who_t = int rbx.platform.typedef.__priority_which_t = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/mips-linux/0000755000175000017500000000000012261216360023025 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/mips-linux/types.conf0000644000175000017500000000762512261216360025052 0ustar terceiroterceirorbx.platform.typedef.__u_char = uchar rbx.platform.typedef.__u_short = ushort rbx.platform.typedef.__u_int = uint rbx.platform.typedef.__u_long = ulong rbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__quad_t = long_long rbx.platform.typedef.__u_quad_t = ulong_long rbx.platform.typedef.__dev_t = ulong_long rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__ino_t = ulong rbx.platform.typedef.__ino64_t = ulong_long rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = uint rbx.platform.typedef.__off_t = long rbx.platform.typedef.__off64_t = long_long rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__clock_t = long rbx.platform.typedef.__rlim_t = ulong rbx.platform.typedef.__rlim64_t = ulong_long rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__time_t = long rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = long rbx.platform.typedef.__daddr_t = int rbx.platform.typedef.__swblk_t = long rbx.platform.typedef.__key_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__timer_t = pointer rbx.platform.typedef.__blksize_t = long rbx.platform.typedef.__blkcnt_t = long rbx.platform.typedef.__blkcnt64_t = long_long rbx.platform.typedef.__fsblkcnt_t = ulong rbx.platform.typedef.__fsblkcnt64_t = ulong_long rbx.platform.typedef.__fsfilcnt_t = ulong rbx.platform.typedef.__fsfilcnt64_t = ulong_long rbx.platform.typedef.__ssize_t = int rbx.platform.typedef.__loff_t = long_long rbx.platform.typedef.*__qaddr_t = long_long rbx.platform.typedef.*__caddr_t = char rbx.platform.typedef.__intptr_t = int rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.loff_t = long_long rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.dev_t = ulong_long rbx.platform.typedef.gid_t = uint rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.uid_t = uint rbx.platform.typedef.off_t = long_long rbx.platform.typedef.pid_t = int rbx.platform.typedef.id_t = uint rbx.platform.typedef.ssize_t = int rbx.platform.typedef.daddr_t = int rbx.platform.typedef.key_t = int rbx.platform.typedef.clock_t = long rbx.platform.typedef.time_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = pointer rbx.platform.typedef.size_t = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = long rbx.platform.typedef.__sig_atomic_t = int rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.__fd_mask = long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.blksize_t = long rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.fsblkcnt_t = ulong_long rbx.platform.typedef.fsfilcnt_t = ulong_long rbx.platform.typedef.pthread_t = ulong rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.pthread_once_t = int rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.__rlimit_resource_t = int rbx.platform.typedef.__rusage_who_t = int rbx.platform.typedef.__priority_which_t = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/sparcv9-solaris/0000755000175000017500000000000012261216360023761 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/sparcv9-solaris/types.conf0000644000175000017500000001156012261216360025777 0ustar terceiroterceirorbx.platform.typedef.lock_t = uchar rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.uint8_t = uchar rbx.platform.typedef.uint16_t = ushort rbx.platform.typedef.uint32_t = uint rbx.platform.typedef.uint64_t = ulong_long rbx.platform.typedef.intmax_t = long_long rbx.platform.typedef.uintmax_t = ulong_long rbx.platform.typedef.intptr_t = int rbx.platform.typedef.uintptr_t = uint rbx.platform.typedef.int_fast8_t = char rbx.platform.typedef.int_fast16_t = int rbx.platform.typedef.int_fast32_t = int rbx.platform.typedef.int_fast64_t = long_long rbx.platform.typedef.uint_fast8_t = uchar rbx.platform.typedef.uint_fast16_t = uint rbx.platform.typedef.uint_fast32_t = uint rbx.platform.typedef.uint_fast64_t = ulong_long rbx.platform.typedef.int_least8_t = char rbx.platform.typedef.int_least16_t = short rbx.platform.typedef.int_least32_t = int rbx.platform.typedef.int_least64_t = long_long rbx.platform.typedef.uint_least8_t = uchar rbx.platform.typedef.uint_least16_t = ushort rbx.platform.typedef.uint_least32_t = uint rbx.platform.typedef.uint_least64_t = ulong_long rbx.platform.typedef.longlong_t = long_long rbx.platform.typedef.u_longlong_t = ulong_long rbx.platform.typedef.t_scalar_t = long rbx.platform.typedef.t_uscalar_t = ulong rbx.platform.typedef.uchar_t = uchar rbx.platform.typedef.ushort_t = ushort rbx.platform.typedef.uint_t = uint rbx.platform.typedef.ulong_t = ulong rbx.platform.typedef.*caddr_t = char rbx.platform.typedef.daddr_t = long rbx.platform.typedef.cnt_t = short rbx.platform.typedef.ptrdiff_t = int rbx.platform.typedef.pfn_t = ulong rbx.platform.typedef.pgcnt_t = ulong rbx.platform.typedef.spgcnt_t = long rbx.platform.typedef.use_t = uchar rbx.platform.typedef.sysid_t = short rbx.platform.typedef.index_t = short rbx.platform.typedef.off_t = long_long rbx.platform.typedef.off64_t = long_long rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.fsblkcnt_t = ulong_long rbx.platform.typedef.fsfilcnt_t = ulong_long rbx.platform.typedef.ino64_t = ulong_long rbx.platform.typedef.blkcnt64_t = long_long rbx.platform.typedef.fsblkcnt64_t = ulong_long rbx.platform.typedef.fsfilcnt64_t = ulong_long rbx.platform.typedef.blksize_t = long rbx.platform.typedef.pad64_t = long_long rbx.platform.typedef.upad64_t = ulong_long rbx.platform.typedef.offset_t = long_long rbx.platform.typedef.u_offset_t = ulong_long rbx.platform.typedef.len_t = ulong_long rbx.platform.typedef.diskaddr_t = ulong_long rbx.platform.typedef.k_fltset_t = uint rbx.platform.typedef.id_t = long rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.major_t = ulong rbx.platform.typedef.minor_t = ulong rbx.platform.typedef.pri_t = short rbx.platform.typedef.cpu_flag_t = ushort rbx.platform.typedef.o_mode_t = ushort rbx.platform.typedef.o_dev_t = short rbx.platform.typedef.o_uid_t = ushort rbx.platform.typedef.o_gid_t = ushort rbx.platform.typedef.o_nlink_t = short rbx.platform.typedef.o_pid_t = short rbx.platform.typedef.o_ino_t = ushort rbx.platform.typedef.key_t = int rbx.platform.typedef.mode_t = ulong rbx.platform.typedef.uid_t = long rbx.platform.typedef.gid_t = long rbx.platform.typedef.taskid_t = long rbx.platform.typedef.projid_t = long rbx.platform.typedef.poolid_t = long rbx.platform.typedef.zoneid_t = long rbx.platform.typedef.ctid_t = long rbx.platform.typedef.pthread_t = uint rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.dev_t = ulong rbx.platform.typedef.nlink_t = ulong rbx.platform.typedef.pid_t = long rbx.platform.typedef.size_t = uint rbx.platform.typedef.ssize_t = int rbx.platform.typedef.time_t = long rbx.platform.typedef.clock_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = int rbx.platform.typedef.unchar = uchar rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.hrtime_t = long_long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.fds_mask = long rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.Psocklen_t = pointer rbx.platform.typedef.disp_lock_t = uchar rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.rlim64_t = ulong_long rbx.platform.typedef.kid_t = int rbx.platform.typedef.int) = pointer rbx.platform.typedef.size_t) = pointer rbx.platform.typedef.int) = pointer rbx.platform.typedef.avl_index_t = uint rbx.platform.typedef.() = pointer rbx.platform.typedef.nfds_t = ulong rbx.platform.typedef.model_t = uint rbx.platform.typedef.ts_t = long_long rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.ipaddr_t = uint ruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-windows/0000755000175000017500000000000012261216360023101 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-windows/types.conf0000644000175000017500000001005712261216360025117 0ustar terceiroterceirorbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int_least16_t = short rbx.platform.typedef.__uint_least16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int_least32_t = int rbx.platform.typedef.__uint_least32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef._off_t = long rbx.platform.typedef._off64_t = long_long rbx.platform.typedef._ssize_t = int rbx.platform.typedef.wint_t = uint rbx.platform.typedef.ptrdiff_t = int rbx.platform.typedef.size_t = uint rbx.platform.typedef.__off_t = long rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__loff_t = long_long rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.clock_t = ulong rbx.platform.typedef.time_t = long rbx.platform.typedef.daddr_t = long rbx.platform.typedef.caddr_t = string rbx.platform.typedef.pid_t = int rbx.platform.typedef.ssize_t = int rbx.platform.typedef.nlink_t = ushort rbx.platform.typedef.fd_mask = long rbx.platform.typedef.clockid_t = ulong rbx.platform.typedef.timer_t = ulong rbx.platform.typedef.useconds_t = ulong rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = long rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.uint8_t = uchar rbx.platform.typedef.uint16_t = ushort rbx.platform.typedef.uint32_t = ulong rbx.platform.typedef.uint64_t = ulong_long rbx.platform.typedef.int_least8_t = char rbx.platform.typedef.int_least16_t = short rbx.platform.typedef.int_least32_t = long rbx.platform.typedef.int_least64_t = long_long rbx.platform.typedef.uint_least8_t = uchar rbx.platform.typedef.uint_least16_t = ushort rbx.platform.typedef.uint_least32_t = ulong rbx.platform.typedef.uint_least64_t = ulong_long rbx.platform.typedef.int_fast8_t = char rbx.platform.typedef.int_fast16_t = long rbx.platform.typedef.int_fast32_t = long rbx.platform.typedef.int_fast64_t = long_long rbx.platform.typedef.uint_fast8_t = uchar rbx.platform.typedef.uint_fast16_t = ulong rbx.platform.typedef.uint_fast32_t = ulong rbx.platform.typedef.uint_fast64_t = ulong_long rbx.platform.typedef.intptr_t = long rbx.platform.typedef.uintptr_t = ulong rbx.platform.typedef.intmax_t = long_long rbx.platform.typedef.uintmax_t = ulong_long rbx.platform.typedef.off_t = long_long rbx.platform.typedef.loff_t = long_long rbx.platform.typedef.__dev16_t = short rbx.platform.typedef.__dev32_t = ulong rbx.platform.typedef.dev_t = ulong rbx.platform.typedef.blksize_t = long rbx.platform.typedef.__blkcnt32_t = long rbx.platform.typedef.__blkcnt64_t = long_long rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.fsblkcnt_t = ulong rbx.platform.typedef.fsfilcnt_t = ulong rbx.platform.typedef.__uid16_t = ushort rbx.platform.typedef.__uid32_t = ulong rbx.platform.typedef.uid_t = ulong rbx.platform.typedef.__gid16_t = ushort rbx.platform.typedef.__gid32_t = ulong rbx.platform.typedef.gid_t = ulong rbx.platform.typedef.__ino32_t = ulong rbx.platform.typedef.__ino64_t = ulong_long rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.id_t = ulong rbx.platform.typedef.key_t = long_long rbx.platform.typedef.vm_offset_t = ulong rbx.platform.typedef.vm_size_t = ulong rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = int rbx.platform.typedef.*addr_t = char rbx.platform.typedef.socklen_t = int rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.__ULong = ulong rbx.platform.typedef._fpos_t = long rbx.platform.typedef._fpos64_t = long_long rbx.platform.typedef.sigset_t = ulong rbx.platform.typedef.sig_atomic_t = int rbx.platform.typedef.rlim_t = ulong ruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-darwin/0000755000175000017500000000000012261216360022673 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-darwin/types.conf0000644000175000017500000001002612261216360024705 0ustar terceiroterceirorbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__darwin_intptr_t = long rbx.platform.typedef.__darwin_natural_t = uint rbx.platform.typedef.__darwin_ct_rune_t = int rbx.platform.typedef.__darwin_ptrdiff_t = int rbx.platform.typedef.__darwin_size_t = ulong rbx.platform.typedef.__darwin_wchar_t = int rbx.platform.typedef.__darwin_rune_t = int rbx.platform.typedef.__darwin_wint_t = int rbx.platform.typedef.__darwin_clock_t = ulong rbx.platform.typedef.__darwin_socklen_t = uint rbx.platform.typedef.__darwin_ssize_t = long rbx.platform.typedef.__darwin_time_t = long rbx.platform.typedef.int8_t = char rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.int16_t = short rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.int32_t = int rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = int rbx.platform.typedef.intptr_t = long rbx.platform.typedef.uintptr_t = ulong rbx.platform.typedef.user_addr_t = ulong_long rbx.platform.typedef.user_size_t = ulong_long rbx.platform.typedef.user_ssize_t = long_long rbx.platform.typedef.user_long_t = long_long rbx.platform.typedef.user_ulong_t = ulong_long rbx.platform.typedef.user_time_t = long_long rbx.platform.typedef.syscall_arg_t = ulong_long rbx.platform.typedef.__darwin_blkcnt_t = long_long rbx.platform.typedef.__darwin_blksize_t = int rbx.platform.typedef.__darwin_dev_t = int rbx.platform.typedef.__darwin_fsblkcnt_t = uint rbx.platform.typedef.__darwin_fsfilcnt_t = uint rbx.platform.typedef.__darwin_gid_t = uint rbx.platform.typedef.__darwin_id_t = uint rbx.platform.typedef.__darwin_ino64_t = ulong_long rbx.platform.typedef.__darwin_ino_t = ulong_long rbx.platform.typedef.__darwin_mach_port_name_t = uint rbx.platform.typedef.__darwin_mach_port_t = uint rbx.platform.typedef.__darwin_mode_t = ushort rbx.platform.typedef.__darwin_off_t = long_long rbx.platform.typedef.__darwin_pid_t = int rbx.platform.typedef.__darwin_pthread_key_t = ulong rbx.platform.typedef.__darwin_sigset_t = uint rbx.platform.typedef.__darwin_suseconds_t = int rbx.platform.typedef.__darwin_uid_t = uint rbx.platform.typedef.__darwin_useconds_t = uint rbx.platform.typedef.__darwin_uuid_t[16] = uchar rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.qaddr_t = pointer rbx.platform.typedef.caddr_t = string rbx.platform.typedef.daddr_t = int rbx.platform.typedef.dev_t = int rbx.platform.typedef.fixpt_t = uint rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.blksize_t = int rbx.platform.typedef.gid_t = uint rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.ino64_t = ulong_long rbx.platform.typedef.key_t = int rbx.platform.typedef.mode_t = ushort rbx.platform.typedef.nlink_t = ushort rbx.platform.typedef.id_t = uint rbx.platform.typedef.pid_t = int rbx.platform.typedef.off_t = long_long rbx.platform.typedef.segsz_t = int rbx.platform.typedef.swblk_t = int rbx.platform.typedef.uid_t = uint rbx.platform.typedef.clock_t = ulong rbx.platform.typedef.size_t = ulong rbx.platform.typedef.ssize_t = long rbx.platform.typedef.time_t = long rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.suseconds_t = int rbx.platform.typedef.fd_mask = int rbx.platform.typedef.pthread_key_t = ulong rbx.platform.typedef.fsblkcnt_t = uint rbx.platform.typedef.fsfilcnt_t = uint rbx.platform.typedef.sa_family_t = uchar rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.rlim_t = ulong_long ruby-ffi-1.9.3debian.orig/lib/ffi/platform/s390-linux/0000755000175000017500000000000012261216360022553 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/s390-linux/types.conf0000644000175000017500000000763012261216360024574 0ustar terceiroterceirorbx.platform.typedef.__u_char = uchar rbx.platform.typedef.__u_short = ushort rbx.platform.typedef.__u_int = uint rbx.platform.typedef.__u_long = ulong rbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__quad_t = long_long rbx.platform.typedef.__u_quad_t = ulong_long rbx.platform.typedef.__dev_t = ulong_long rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__ino_t = ulong rbx.platform.typedef.__ino64_t = ulong_long rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = uint rbx.platform.typedef.__off_t = long rbx.platform.typedef.__off64_t = long_long rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__clock_t = long rbx.platform.typedef.__rlim_t = ulong rbx.platform.typedef.__rlim64_t = ulong_long rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__time_t = long rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = long rbx.platform.typedef.__daddr_t = int rbx.platform.typedef.__swblk_t = long rbx.platform.typedef.__key_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__timer_t = pointer rbx.platform.typedef.__blksize_t = long rbx.platform.typedef.__blkcnt_t = long rbx.platform.typedef.__blkcnt64_t = long_long rbx.platform.typedef.__fsblkcnt_t = ulong rbx.platform.typedef.__fsblkcnt64_t = ulong_long rbx.platform.typedef.__fsfilcnt_t = ulong rbx.platform.typedef.__fsfilcnt64_t = ulong_long rbx.platform.typedef.__ssize_t = long rbx.platform.typedef.__loff_t = long_long rbx.platform.typedef.*__qaddr_t = long_long rbx.platform.typedef.*__caddr_t = char rbx.platform.typedef.__intptr_t = int rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.loff_t = long_long rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.dev_t = ulong_long rbx.platform.typedef.gid_t = uint rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.uid_t = uint rbx.platform.typedef.off_t = long_long rbx.platform.typedef.pid_t = int rbx.platform.typedef.id_t = uint rbx.platform.typedef.ssize_t = long rbx.platform.typedef.daddr_t = int rbx.platform.typedef.key_t = int rbx.platform.typedef.clock_t = long rbx.platform.typedef.time_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = pointer rbx.platform.typedef.size_t = ulong rbx.platform.typedef.ulong = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = long rbx.platform.typedef.__sig_atomic_t = int rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.__fd_mask = long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.blksize_t = long rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.fsblkcnt_t = ulong_long rbx.platform.typedef.fsfilcnt_t = ulong_long rbx.platform.typedef.pthread_t = ulong rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.pthread_once_t = int rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.__rlimit_resource_t = int rbx.platform.typedef.__rusage_who_t = int rbx.platform.typedef.__priority_which_t = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-linux/0000755000175000017500000000000012261216360023013 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-linux/types.conf0000644000175000017500000000745212261216360025036 0ustar terceiroterceirorbx.platform.typedef.__u_char = uchar rbx.platform.typedef.__u_short = ushort rbx.platform.typedef.__u_int = uint rbx.platform.typedef.__u_long = ulong rbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long rbx.platform.typedef.__uint64_t = ulong rbx.platform.typedef.__quad_t = long rbx.platform.typedef.__u_quad_t = ulong rbx.platform.typedef.__dev_t = ulong rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__ino_t = ulong rbx.platform.typedef.__ino64_t = ulong rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = ulong rbx.platform.typedef.__off_t = long rbx.platform.typedef.__off64_t = long rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__clock_t = long rbx.platform.typedef.__rlim_t = ulong rbx.platform.typedef.__rlim64_t = ulong rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__time_t = long rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = long rbx.platform.typedef.__daddr_t = int rbx.platform.typedef.__swblk_t = long rbx.platform.typedef.__key_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__timer_t = pointer rbx.platform.typedef.blksize_t = long rbx.platform.typedef.__blkcnt_t = long rbx.platform.typedef.__blkcnt64_t = long rbx.platform.typedef.__fsblkcnt_t = ulong rbx.platform.typedef.__fsblkcnt64_t = ulong rbx.platform.typedef.__fsfilcnt_t = ulong rbx.platform.typedef.__fsfilcnt64_t = ulong rbx.platform.typedef.__ssize_t = long rbx.platform.typedef.__loff_t = long rbx.platform.typedef.*__qaddr_t = long rbx.platform.typedef.*__caddr_t = char rbx.platform.typedef.__intptr_t = long rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.quad_t = long rbx.platform.typedef.u_quad_t = ulong rbx.platform.typedef.loff_t = long rbx.platform.typedef.ino_t = ulong rbx.platform.typedef.dev_t = ulong rbx.platform.typedef.gid_t = uint rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = ulong rbx.platform.typedef.uid_t = uint rbx.platform.typedef.off_t = long rbx.platform.typedef.pid_t = int rbx.platform.typedef.id_t = uint rbx.platform.typedef.ssize_t = long rbx.platform.typedef.daddr_t = int rbx.platform.typedef.key_t = int rbx.platform.typedef.time_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = pointer rbx.platform.typedef.size_t = ulong rbx.platform.typedef.ulong = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = long rbx.platform.typedef.__sig_atomic_t = int rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.__fd_mask = long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.blkcnt_t = long rbx.platform.typedef.fsblkcnt_t = ulong rbx.platform.typedef.fsfilcnt_t = ulong rbx.platform.typedef.pthread_t = ulong rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.pthread_once_t = int rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.rlim_t = ulong rbx.platform.typedef.__rlimit_resource_t = int rbx.platform.typedef.__rusage_who_t = int rbx.platform.typedef.__priority_which_t = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/powerpc-darwin/0000755000175000017500000000000012261216360023661 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/powerpc-darwin/types.conf0000644000175000017500000001002612261216360025673 0ustar terceiroterceirorbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__darwin_intptr_t = long rbx.platform.typedef.__darwin_natural_t = uint rbx.platform.typedef.__darwin_ct_rune_t = int rbx.platform.typedef.__darwin_ptrdiff_t = int rbx.platform.typedef.__darwin_size_t = ulong rbx.platform.typedef.__darwin_wchar_t = int rbx.platform.typedef.__darwin_rune_t = int rbx.platform.typedef.__darwin_wint_t = int rbx.platform.typedef.__darwin_clock_t = ulong rbx.platform.typedef.__darwin_socklen_t = uint rbx.platform.typedef.__darwin_ssize_t = long rbx.platform.typedef.__darwin_time_t = long rbx.platform.typedef.int8_t = char rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.int16_t = short rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.int32_t = int rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = int rbx.platform.typedef.intptr_t = long rbx.platform.typedef.uintptr_t = ulong rbx.platform.typedef.user_addr_t = ulong_long rbx.platform.typedef.user_size_t = ulong_long rbx.platform.typedef.user_ssize_t = long_long rbx.platform.typedef.user_long_t = long_long rbx.platform.typedef.user_ulong_t = ulong_long rbx.platform.typedef.user_time_t = long_long rbx.platform.typedef.syscall_arg_t = ulong_long rbx.platform.typedef.__darwin_blkcnt_t = long_long rbx.platform.typedef.__darwin_blksize_t = int rbx.platform.typedef.__darwin_dev_t = int rbx.platform.typedef.__darwin_fsblkcnt_t = uint rbx.platform.typedef.__darwin_fsfilcnt_t = uint rbx.platform.typedef.__darwin_gid_t = uint rbx.platform.typedef.__darwin_id_t = uint rbx.platform.typedef.__darwin_ino64_t = ulong_long rbx.platform.typedef.__darwin_ino_t = ulong_long rbx.platform.typedef.__darwin_mach_port_name_t = uint rbx.platform.typedef.__darwin_mach_port_t = uint rbx.platform.typedef.__darwin_mode_t = ushort rbx.platform.typedef.__darwin_off_t = long_long rbx.platform.typedef.__darwin_pid_t = int rbx.platform.typedef.__darwin_pthread_key_t = ulong rbx.platform.typedef.__darwin_sigset_t = uint rbx.platform.typedef.__darwin_suseconds_t = int rbx.platform.typedef.__darwin_uid_t = uint rbx.platform.typedef.__darwin_useconds_t = uint rbx.platform.typedef.__darwin_uuid_t[16] = uchar rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.qaddr_t = pointer rbx.platform.typedef.caddr_t = string rbx.platform.typedef.daddr_t = int rbx.platform.typedef.dev_t = int rbx.platform.typedef.fixpt_t = uint rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.blksize_t = int rbx.platform.typedef.gid_t = uint rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.ino64_t = ulong_long rbx.platform.typedef.key_t = int rbx.platform.typedef.mode_t = ushort rbx.platform.typedef.nlink_t = ushort rbx.platform.typedef.id_t = uint rbx.platform.typedef.pid_t = int rbx.platform.typedef.off_t = long_long rbx.platform.typedef.segsz_t = int rbx.platform.typedef.swblk_t = int rbx.platform.typedef.uid_t = uint rbx.platform.typedef.clock_t = ulong rbx.platform.typedef.size_t = ulong rbx.platform.typedef.ssize_t = long rbx.platform.typedef.time_t = long rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.suseconds_t = int rbx.platform.typedef.fd_mask = int rbx.platform.typedef.pthread_key_t = ulong rbx.platform.typedef.fsblkcnt_t = uint rbx.platform.typedef.fsfilcnt_t = uint rbx.platform.typedef.sa_family_t = uchar rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.rlim_t = ulong_long ruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-solaris/0000755000175000017500000000000012261216360023330 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-solaris/types.conf0000644000175000017500000001104312261216360025342 0ustar terceiroterceirorbx.platform.typedef.lock_t = uchar rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long rbx.platform.typedef.uint8_t = uchar rbx.platform.typedef.uint16_t = ushort rbx.platform.typedef.uint32_t = uint rbx.platform.typedef.uint64_t = ulong rbx.platform.typedef.intmax_t = long rbx.platform.typedef.uintmax_t = ulong rbx.platform.typedef.intptr_t = long rbx.platform.typedef.uintptr_t = ulong rbx.platform.typedef.int_fast8_t = char rbx.platform.typedef.int_fast16_t = int rbx.platform.typedef.int_fast32_t = int rbx.platform.typedef.int_fast64_t = long rbx.platform.typedef.uint_fast8_t = uchar rbx.platform.typedef.uint_fast16_t = uint rbx.platform.typedef.uint_fast32_t = uint rbx.platform.typedef.uint_fast64_t = ulong rbx.platform.typedef.int_least8_t = char rbx.platform.typedef.int_least16_t = short rbx.platform.typedef.int_least32_t = int rbx.platform.typedef.int_least64_t = long rbx.platform.typedef.uint_least8_t = uchar rbx.platform.typedef.uint_least16_t = ushort rbx.platform.typedef.uint_least32_t = uint rbx.platform.typedef.uint_least64_t = ulong rbx.platform.typedef.longlong_t = long_long rbx.platform.typedef.u_longlong_t = ulong_long rbx.platform.typedef.t_scalar_t = int rbx.platform.typedef.t_uscalar_t = uint rbx.platform.typedef.uchar_t = uchar rbx.platform.typedef.ushort_t = ushort rbx.platform.typedef.uint_t = uint rbx.platform.typedef.ulong_t = ulong rbx.platform.typedef.*caddr_t = char rbx.platform.typedef.daddr_t = long rbx.platform.typedef.cnt_t = short rbx.platform.typedef.ptrdiff_t = long rbx.platform.typedef.pfn_t = ulong rbx.platform.typedef.pgcnt_t = ulong rbx.platform.typedef.spgcnt_t = long rbx.platform.typedef.use_t = uchar rbx.platform.typedef.sysid_t = short rbx.platform.typedef.index_t = short rbx.platform.typedef.off_t = long rbx.platform.typedef.off64_t = long rbx.platform.typedef.ino_t = ulong rbx.platform.typedef.blkcnt_t = long rbx.platform.typedef.fsblkcnt_t = ulong rbx.platform.typedef.fsfilcnt_t = ulong rbx.platform.typedef.ino64_t = ulong rbx.platform.typedef.blkcnt64_t = long rbx.platform.typedef.fsblkcnt64_t = ulong rbx.platform.typedef.fsfilcnt64_t = ulong rbx.platform.typedef.blksize_t = int rbx.platform.typedef.pad64_t = long rbx.platform.typedef.upad64_t = ulong rbx.platform.typedef.offset_t = long_long rbx.platform.typedef.u_offset_t = ulong_long rbx.platform.typedef.len_t = ulong_long rbx.platform.typedef.diskaddr_t = ulong_long rbx.platform.typedef.k_fltset_t = uint rbx.platform.typedef.id_t = int rbx.platform.typedef.lgrp_id_t = int rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.major_t = uint rbx.platform.typedef.minor_t = uint rbx.platform.typedef.pri_t = short rbx.platform.typedef.cpu_flag_t = ushort rbx.platform.typedef.o_mode_t = ushort rbx.platform.typedef.o_dev_t = short rbx.platform.typedef.o_uid_t = ushort rbx.platform.typedef.o_gid_t = ushort rbx.platform.typedef.o_nlink_t = short rbx.platform.typedef.o_pid_t = short rbx.platform.typedef.o_ino_t = ushort rbx.platform.typedef.key_t = int rbx.platform.typedef.mode_t = uint rbx.platform.typedef.uid_t = uint rbx.platform.typedef.gid_t = uint rbx.platform.typedef.datalink_id_t = uint rbx.platform.typedef.taskid_t = int rbx.platform.typedef.projid_t = int rbx.platform.typedef.poolid_t = int rbx.platform.typedef.zoneid_t = int rbx.platform.typedef.ctid_t = int rbx.platform.typedef.pthread_t = uint rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.dev_t = ulong rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.pid_t = int rbx.platform.typedef.size_t = ulong rbx.platform.typedef.ssize_t = long rbx.platform.typedef.time_t = long rbx.platform.typedef.clock_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = int rbx.platform.typedef.unchar = uchar rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.hrtime_t = long_long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.fds_mask = long rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.nfds_t = ulong rbx.platform.typedef.disp_lock_t = uchar rbx.platform.typedef.model_t = uint rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.ipaddr_t = uint rbx.platform.typedef.rlim_t = ulong rbx.platform.typedef.rlim64_t = ulong_long ruby-ffi-1.9.3debian.orig/lib/ffi/platform/sparc-solaris/0000755000175000017500000000000012261216360023502 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/sparc-solaris/types.conf0000644000175000017500000001156012261216360025520 0ustar terceiroterceirorbx.platform.typedef.lock_t = uchar rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.uint8_t = uchar rbx.platform.typedef.uint16_t = ushort rbx.platform.typedef.uint32_t = uint rbx.platform.typedef.uint64_t = ulong_long rbx.platform.typedef.intmax_t = long_long rbx.platform.typedef.uintmax_t = ulong_long rbx.platform.typedef.intptr_t = int rbx.platform.typedef.uintptr_t = uint rbx.platform.typedef.int_fast8_t = char rbx.platform.typedef.int_fast16_t = int rbx.platform.typedef.int_fast32_t = int rbx.platform.typedef.int_fast64_t = long_long rbx.platform.typedef.uint_fast8_t = uchar rbx.platform.typedef.uint_fast16_t = uint rbx.platform.typedef.uint_fast32_t = uint rbx.platform.typedef.uint_fast64_t = ulong_long rbx.platform.typedef.int_least8_t = char rbx.platform.typedef.int_least16_t = short rbx.platform.typedef.int_least32_t = int rbx.platform.typedef.int_least64_t = long_long rbx.platform.typedef.uint_least8_t = uchar rbx.platform.typedef.uint_least16_t = ushort rbx.platform.typedef.uint_least32_t = uint rbx.platform.typedef.uint_least64_t = ulong_long rbx.platform.typedef.longlong_t = long_long rbx.platform.typedef.u_longlong_t = ulong_long rbx.platform.typedef.t_scalar_t = long rbx.platform.typedef.t_uscalar_t = ulong rbx.platform.typedef.uchar_t = uchar rbx.platform.typedef.ushort_t = ushort rbx.platform.typedef.uint_t = uint rbx.platform.typedef.ulong_t = ulong rbx.platform.typedef.*caddr_t = char rbx.platform.typedef.daddr_t = long rbx.platform.typedef.cnt_t = short rbx.platform.typedef.ptrdiff_t = int rbx.platform.typedef.pfn_t = ulong rbx.platform.typedef.pgcnt_t = ulong rbx.platform.typedef.spgcnt_t = long rbx.platform.typedef.use_t = uchar rbx.platform.typedef.sysid_t = short rbx.platform.typedef.index_t = short rbx.platform.typedef.off_t = long_long rbx.platform.typedef.off64_t = long_long rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.fsblkcnt_t = ulong_long rbx.platform.typedef.fsfilcnt_t = ulong_long rbx.platform.typedef.ino64_t = ulong_long rbx.platform.typedef.blkcnt64_t = long_long rbx.platform.typedef.fsblkcnt64_t = ulong_long rbx.platform.typedef.fsfilcnt64_t = ulong_long rbx.platform.typedef.blksize_t = long rbx.platform.typedef.pad64_t = long_long rbx.platform.typedef.upad64_t = ulong_long rbx.platform.typedef.offset_t = long_long rbx.platform.typedef.u_offset_t = ulong_long rbx.platform.typedef.len_t = ulong_long rbx.platform.typedef.diskaddr_t = ulong_long rbx.platform.typedef.k_fltset_t = uint rbx.platform.typedef.id_t = long rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.major_t = ulong rbx.platform.typedef.minor_t = ulong rbx.platform.typedef.pri_t = short rbx.platform.typedef.cpu_flag_t = ushort rbx.platform.typedef.o_mode_t = ushort rbx.platform.typedef.o_dev_t = short rbx.platform.typedef.o_uid_t = ushort rbx.platform.typedef.o_gid_t = ushort rbx.platform.typedef.o_nlink_t = short rbx.platform.typedef.o_pid_t = short rbx.platform.typedef.o_ino_t = ushort rbx.platform.typedef.key_t = int rbx.platform.typedef.mode_t = ulong rbx.platform.typedef.uid_t = long rbx.platform.typedef.gid_t = long rbx.platform.typedef.taskid_t = long rbx.platform.typedef.projid_t = long rbx.platform.typedef.poolid_t = long rbx.platform.typedef.zoneid_t = long rbx.platform.typedef.ctid_t = long rbx.platform.typedef.pthread_t = uint rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.dev_t = ulong rbx.platform.typedef.nlink_t = ulong rbx.platform.typedef.pid_t = long rbx.platform.typedef.size_t = uint rbx.platform.typedef.ssize_t = int rbx.platform.typedef.time_t = long rbx.platform.typedef.clock_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = int rbx.platform.typedef.unchar = uchar rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.hrtime_t = long_long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.fds_mask = long rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.Psocklen_t = pointer rbx.platform.typedef.disp_lock_t = uchar rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.rlim64_t = ulong_long rbx.platform.typedef.kid_t = int rbx.platform.typedef.int) = pointer rbx.platform.typedef.size_t) = pointer rbx.platform.typedef.int) = pointer rbx.platform.typedef.avl_index_t = uint rbx.platform.typedef.() = pointer rbx.platform.typedef.nfds_t = ulong rbx.platform.typedef.model_t = uint rbx.platform.typedef.ts_t = long_long rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.ipaddr_t = uint ruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-cygwin/0000755000175000017500000000000012261216360023154 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-cygwin/types.conf0000755000175000017500000000016112261216360025170 0ustar terceiroterceirorbx.platform.typedef.size_t = uint64 rbx.platform.typedef.ptrdiff_t = int64 rbx.platform.typedef.ssize_t = int64 ruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-solaris/0000755000175000017500000000000012261216360023063 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-solaris/types.conf0000644000175000017500000001122612261216360025100 0ustar terceiroterceirorbx.platform.typedef.lock_t = uchar rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.uint8_t = uchar rbx.platform.typedef.uint16_t = ushort rbx.platform.typedef.uint32_t = uint rbx.platform.typedef.uint64_t = ulong_long rbx.platform.typedef.intmax_t = long_long rbx.platform.typedef.uintmax_t = ulong_long rbx.platform.typedef.intptr_t = int rbx.platform.typedef.uintptr_t = uint rbx.platform.typedef.int_fast8_t = char rbx.platform.typedef.int_fast16_t = int rbx.platform.typedef.int_fast32_t = int rbx.platform.typedef.int_fast64_t = long_long rbx.platform.typedef.uint_fast8_t = uchar rbx.platform.typedef.uint_fast16_t = uint rbx.platform.typedef.uint_fast32_t = uint rbx.platform.typedef.uint_fast64_t = ulong_long rbx.platform.typedef.int_least8_t = char rbx.platform.typedef.int_least16_t = short rbx.platform.typedef.int_least32_t = int rbx.platform.typedef.int_least64_t = long_long rbx.platform.typedef.uint_least8_t = uchar rbx.platform.typedef.uint_least16_t = ushort rbx.platform.typedef.uint_least32_t = uint rbx.platform.typedef.uint_least64_t = ulong_long rbx.platform.typedef.longlong_t = long_long rbx.platform.typedef.u_longlong_t = ulong_long rbx.platform.typedef.t_scalar_t = long rbx.platform.typedef.t_uscalar_t = ulong rbx.platform.typedef.uchar_t = uchar rbx.platform.typedef.ushort_t = ushort rbx.platform.typedef.uint_t = uint rbx.platform.typedef.ulong_t = ulong rbx.platform.typedef.*caddr_t = char rbx.platform.typedef.daddr_t = long rbx.platform.typedef.cnt_t = short rbx.platform.typedef.ptrdiff_t = int rbx.platform.typedef.pfn_t = ulong rbx.platform.typedef.pgcnt_t = ulong rbx.platform.typedef.spgcnt_t = long rbx.platform.typedef.use_t = uchar rbx.platform.typedef.sysid_t = short rbx.platform.typedef.index_t = short rbx.platform.typedef.off_t = long_long rbx.platform.typedef.off64_t = long_long rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.fsblkcnt_t = ulong_long rbx.platform.typedef.fsfilcnt_t = ulong_long rbx.platform.typedef.ino64_t = ulong_long rbx.platform.typedef.blkcnt64_t = long_long rbx.platform.typedef.fsblkcnt64_t = ulong_long rbx.platform.typedef.fsfilcnt64_t = ulong_long rbx.platform.typedef.blksize_t = long rbx.platform.typedef.pad64_t = long_long rbx.platform.typedef.upad64_t = ulong_long rbx.platform.typedef.offset_t = long_long rbx.platform.typedef.u_offset_t = ulong_long rbx.platform.typedef.len_t = ulong_long rbx.platform.typedef.diskaddr_t = ulong_long rbx.platform.typedef.k_fltset_t = uint rbx.platform.typedef.id_t = long rbx.platform.typedef.lgrp_id_t = long rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.major_t = ulong rbx.platform.typedef.minor_t = ulong rbx.platform.typedef.pri_t = short rbx.platform.typedef.cpu_flag_t = ushort rbx.platform.typedef.o_mode_t = ushort rbx.platform.typedef.o_dev_t = short rbx.platform.typedef.o_uid_t = ushort rbx.platform.typedef.o_gid_t = ushort rbx.platform.typedef.o_nlink_t = short rbx.platform.typedef.o_pid_t = short rbx.platform.typedef.o_ino_t = ushort rbx.platform.typedef.key_t = int rbx.platform.typedef.mode_t = ulong rbx.platform.typedef.uid_t = uint rbx.platform.typedef.gid_t = uint rbx.platform.typedef.datalink_id_t = uint rbx.platform.typedef.taskid_t = long rbx.platform.typedef.projid_t = long rbx.platform.typedef.poolid_t = long rbx.platform.typedef.zoneid_t = long rbx.platform.typedef.ctid_t = long rbx.platform.typedef.pthread_t = uint rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.dev_t = ulong rbx.platform.typedef.nlink_t = ulong rbx.platform.typedef.pid_t = long rbx.platform.typedef.size_t = uint rbx.platform.typedef.ssize_t = int rbx.platform.typedef.time_t = long rbx.platform.typedef.clock_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = int rbx.platform.typedef.unchar = uchar rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.hrtime_t = long_long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.fds_mask = long rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.nfds_t = ulong rbx.platform.typedef.disp_lock_t = uchar rbx.platform.typedef.model_t = uint rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.ipaddr_t = uint rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.rlim64_t = ulong_long ruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-openbsd/0000755000175000017500000000000012261216360023041 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-openbsd/types.conf0000644000175000017500000001155512261216360025063 0ustar terceiroterceirorbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__int_least8_t = char rbx.platform.typedef.__uint_least8_t = uchar rbx.platform.typedef.__int_least16_t = short rbx.platform.typedef.__uint_least16_t = ushort rbx.platform.typedef.__int_least32_t = int rbx.platform.typedef.__uint_least32_t = uint rbx.platform.typedef.__int_least64_t = long_long rbx.platform.typedef.__uint_least64_t = ulong_long rbx.platform.typedef.__int_fast8_t = int rbx.platform.typedef.__uint_fast8_t = uint rbx.platform.typedef.__int_fast16_t = int rbx.platform.typedef.__uint_fast16_t = uint rbx.platform.typedef.__int_fast32_t = int rbx.platform.typedef.__uint_fast32_t = uint rbx.platform.typedef.__int_fast64_t = long_long rbx.platform.typedef.__uint_fast64_t = ulong_long rbx.platform.typedef.__intptr_t = long rbx.platform.typedef.__uintptr_t = ulong rbx.platform.typedef.__intmax_t = long_long rbx.platform.typedef.__uintmax_t = ulong_long rbx.platform.typedef.__register_t = int rbx.platform.typedef.__vaddr_t = ulong rbx.platform.typedef.__paddr_t = ulong rbx.platform.typedef.__vsize_t = ulong rbx.platform.typedef.__psize_t = ulong rbx.platform.typedef.__clock_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__off_t = long_long rbx.platform.typedef.__ptrdiff_t = long rbx.platform.typedef.__size_t = ulong rbx.platform.typedef.__ssize_t = long rbx.platform.typedef.__time_t = int rbx.platform.typedef.__timer_t = int rbx.platform.typedef.__wchar_t = int rbx.platform.typedef.__wint_t = int rbx.platform.typedef.__rune_t = int rbx.platform.typedef.__wctrans_t = pointer rbx.platform.typedef.__wctype_t = pointer rbx.platform.typedef.__cpuid_t = ulong rbx.platform.typedef.__dev_t = int rbx.platform.typedef.__fixpt_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__in_addr_t = uint rbx.platform.typedef.__in_port_t = ushort rbx.platform.typedef.__ino_t = uint rbx.platform.typedef.__key_t = long rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = uint rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__rlim_t = ulong_long rbx.platform.typedef.__sa_family_t = uchar rbx.platform.typedef.__segsz_t = int rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.__swblk_t = int rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = int rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.unchar = uchar rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.cpuid_t = ulong rbx.platform.typedef.register_t = int rbx.platform.typedef.int8_t = char rbx.platform.typedef.uint8_t = uchar rbx.platform.typedef.int16_t = short rbx.platform.typedef.uint16_t = ushort rbx.platform.typedef.int32_t = int rbx.platform.typedef.uint32_t = uint rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.uint64_t = ulong_long rbx.platform.typedef.intptr_t = long rbx.platform.typedef.uintptr_t = ulong rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.qaddr_t = pointer rbx.platform.typedef.vaddr_t = ulong rbx.platform.typedef.paddr_t = ulong rbx.platform.typedef.vsize_t = ulong rbx.platform.typedef.psize_t = ulong rbx.platform.typedef.caddr_t = string rbx.platform.typedef.daddr_t = int rbx.platform.typedef.daddr32_t = int rbx.platform.typedef.daddr64_t = long_long rbx.platform.typedef.dev_t = int rbx.platform.typedef.fixpt_t = uint rbx.platform.typedef.gid_t = uint rbx.platform.typedef.id_t = uint rbx.platform.typedef.ino_t = uint rbx.platform.typedef.key_t = long rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.pid_t = int rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.segsz_t = int rbx.platform.typedef.swblk_t = int rbx.platform.typedef.uid_t = uint rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.suseconds_t = int rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.sa_family_t = uchar rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.clock_t = int rbx.platform.typedef.clockid_t = int rbx.platform.typedef.size_t = ulong rbx.platform.typedef.ssize_t = long rbx.platform.typedef.time_t = int rbx.platform.typedef.timer_t = int rbx.platform.typedef.off_t = long_long rbx.platform.typedef.__fd_mask = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-openbsd/0000755000175000017500000000000012261216360023306 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-openbsd/types.conf0000644000175000017500000001155512261216360025330 0ustar terceiroterceirorbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__int_least8_t = char rbx.platform.typedef.__uint_least8_t = uchar rbx.platform.typedef.__int_least16_t = short rbx.platform.typedef.__uint_least16_t = ushort rbx.platform.typedef.__int_least32_t = int rbx.platform.typedef.__uint_least32_t = uint rbx.platform.typedef.__int_least64_t = long_long rbx.platform.typedef.__uint_least64_t = ulong_long rbx.platform.typedef.__int_fast8_t = int rbx.platform.typedef.__uint_fast8_t = uint rbx.platform.typedef.__int_fast16_t = int rbx.platform.typedef.__uint_fast16_t = uint rbx.platform.typedef.__int_fast32_t = int rbx.platform.typedef.__uint_fast32_t = uint rbx.platform.typedef.__int_fast64_t = long_long rbx.platform.typedef.__uint_fast64_t = ulong_long rbx.platform.typedef.__intptr_t = long rbx.platform.typedef.__uintptr_t = ulong rbx.platform.typedef.__intmax_t = long_long rbx.platform.typedef.__uintmax_t = ulong_long rbx.platform.typedef.__register_t = int rbx.platform.typedef.__vaddr_t = ulong rbx.platform.typedef.__paddr_t = ulong rbx.platform.typedef.__vsize_t = ulong rbx.platform.typedef.__psize_t = ulong rbx.platform.typedef.__clock_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__off_t = long_long rbx.platform.typedef.__ptrdiff_t = long rbx.platform.typedef.__size_t = ulong rbx.platform.typedef.__ssize_t = long rbx.platform.typedef.__time_t = int rbx.platform.typedef.__timer_t = int rbx.platform.typedef.__wchar_t = int rbx.platform.typedef.__wint_t = int rbx.platform.typedef.__rune_t = int rbx.platform.typedef.__wctrans_t = pointer rbx.platform.typedef.__wctype_t = pointer rbx.platform.typedef.__cpuid_t = ulong rbx.platform.typedef.__dev_t = int rbx.platform.typedef.__fixpt_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__in_addr_t = uint rbx.platform.typedef.__in_port_t = ushort rbx.platform.typedef.__ino_t = uint rbx.platform.typedef.__key_t = long rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = uint rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__rlim_t = ulong_long rbx.platform.typedef.__sa_family_t = uchar rbx.platform.typedef.__segsz_t = int rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.__swblk_t = int rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = int rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.unchar = uchar rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.cpuid_t = ulong rbx.platform.typedef.register_t = int rbx.platform.typedef.int8_t = char rbx.platform.typedef.uint8_t = uchar rbx.platform.typedef.int16_t = short rbx.platform.typedef.uint16_t = ushort rbx.platform.typedef.int32_t = int rbx.platform.typedef.uint32_t = uint rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.uint64_t = ulong_long rbx.platform.typedef.intptr_t = long rbx.platform.typedef.uintptr_t = ulong rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.qaddr_t = pointer rbx.platform.typedef.vaddr_t = ulong rbx.platform.typedef.paddr_t = ulong rbx.platform.typedef.vsize_t = ulong rbx.platform.typedef.psize_t = ulong rbx.platform.typedef.caddr_t = string rbx.platform.typedef.daddr_t = int rbx.platform.typedef.daddr32_t = int rbx.platform.typedef.daddr64_t = long_long rbx.platform.typedef.dev_t = int rbx.platform.typedef.fixpt_t = uint rbx.platform.typedef.gid_t = uint rbx.platform.typedef.id_t = uint rbx.platform.typedef.ino_t = uint rbx.platform.typedef.key_t = long rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.pid_t = int rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.segsz_t = int rbx.platform.typedef.swblk_t = int rbx.platform.typedef.uid_t = uint rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.suseconds_t = int rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.sa_family_t = uchar rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.clock_t = int rbx.platform.typedef.clockid_t = int rbx.platform.typedef.size_t = ulong rbx.platform.typedef.ssize_t = long rbx.platform.typedef.time_t = int rbx.platform.typedef.timer_t = int rbx.platform.typedef.off_t = long_long rbx.platform.typedef.__fd_mask = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-windows/0000755000175000017500000000000012261216360023346 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-windows/types.conf0000644000175000017500000000203712261216360025363 0ustar terceiroterceirorbx.platform.typedef.size_t = ulong_long rbx.platform.typedef.ssize_t = long_long rbx.platform.typedef.intptr_t = long_long rbx.platform.typedef.uintptr_t = ulong_long rbx.platform.typedef.ptrdiff_t = long_long rbx.platform.typedef.wchar_t = ushort rbx.platform.typedef.wint_t = ushort rbx.platform.typedef.wctype_t = ushort rbx.platform.typedef.errno_t = int rbx.platform.typedef.__time32_t = long rbx.platform.typedef.__time64_t = long_long rbx.platform.typedef.time_t = long_long rbx.platform.typedef._ino_t = ushort rbx.platform.typedef.ino_t = ushort rbx.platform.typedef._dev_t = uint rbx.platform.typedef.dev_t = uint rbx.platform.typedef._pid_t = long_long rbx.platform.typedef.pid_t = long_long rbx.platform.typedef._mode_t = ushort rbx.platform.typedef.mode_t = ushort rbx.platform.typedef._off_t = long rbx.platform.typedef.off32_t = long rbx.platform.typedef._off64_t = long_long rbx.platform.typedef.off64_t = long_long rbx.platform.typedef.off_t = long_long rbx.platform.typedef.useconds_t = uint rbx.platform.typedef._sigset_t = ulong_long ruby-ffi-1.9.3debian.orig/lib/ffi/platform/ia64-linux/0000755000175000017500000000000012261216360022620 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/ia64-linux/types.conf0000644000175000017500000000757212261216360024646 0ustar terceiroterceirorbx.platform.typedef.__u_char = uchar rbx.platform.typedef.__u_short = ushort rbx.platform.typedef.__u_int = uint rbx.platform.typedef.__u_long = ulong rbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long rbx.platform.typedef.__uint64_t = ulong rbx.platform.typedef.__quad_t = long rbx.platform.typedef.__u_quad_t = ulong rbx.platform.typedef.__dev_t = ulong rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__in_addr_t = uint rbx.platform.typedef.__in_port_t = ushort rbx.platform.typedef.__ino_t = ulong rbx.platform.typedef.__ino64_t = ulong rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = ulong rbx.platform.typedef.__off_t = long rbx.platform.typedef.__off64_t = long rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__clock_t = long rbx.platform.typedef.__rlim_t = ulong rbx.platform.typedef.__rlim64_t = ulong rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__time_t = long rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = long rbx.platform.typedef.__daddr_t = int rbx.platform.typedef.__swblk_t = long rbx.platform.typedef.__key_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__timer_t = pointer rbx.platform.typedef.__blksize_t = long rbx.platform.typedef.__blkcnt_t = long rbx.platform.typedef.__blkcnt64_t = long rbx.platform.typedef.__fsblkcnt_t = ulong rbx.platform.typedef.__fsblkcnt64_t = ulong rbx.platform.typedef.__fsfilcnt_t = ulong rbx.platform.typedef.__fsfilcnt64_t = ulong rbx.platform.typedef.__ssize_t = long rbx.platform.typedef.__loff_t = long rbx.platform.typedef.*__qaddr_t = long rbx.platform.typedef.*__caddr_t = char rbx.platform.typedef.__intptr_t = long rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.quad_t = long rbx.platform.typedef.u_quad_t = ulong rbx.platform.typedef.loff_t = long rbx.platform.typedef.ino_t = ulong rbx.platform.typedef.dev_t = ulong rbx.platform.typedef.gid_t = uint rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = ulong rbx.platform.typedef.uid_t = uint rbx.platform.typedef.off_t = long rbx.platform.typedef.pid_t = int rbx.platform.typedef.id_t = uint rbx.platform.typedef.ssize_t = long rbx.platform.typedef.daddr_t = int rbx.platform.typedef.key_t = int rbx.platform.typedef.clock_t = long rbx.platform.typedef.time_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = pointer rbx.platform.typedef.size_t = ulong rbx.platform.typedef.ulong = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = long rbx.platform.typedef.__sig_atomic_t = int rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.__fd_mask = long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.blksize_t = long rbx.platform.typedef.blkcnt_t = long rbx.platform.typedef.fsblkcnt_t = ulong rbx.platform.typedef.fsfilcnt_t = ulong rbx.platform.typedef.pthread_t = ulong rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.pthread_once_t = int rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.rlim_t = ulong rbx.platform.typedef.__rlimit_resource_t = int rbx.platform.typedef.__rusage_who_t = int rbx.platform.typedef.__priority_which_t = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-freebsd/0000755000175000017500000000000012261216360023021 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-freebsd/types.conf0000644000175000017500000001352612261216360025043 0ustar terceiroterceirorbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__clock_t = ulong rbx.platform.typedef.__cpumask_t = uint rbx.platform.typedef.__critical_t = int rbx.platform.typedef.__intfptr_t = int rbx.platform.typedef.__intmax_t = long_long rbx.platform.typedef.__intptr_t = int rbx.platform.typedef.__int_fast8_t = int rbx.platform.typedef.__int_fast16_t = int rbx.platform.typedef.__int_fast32_t = int rbx.platform.typedef.__int_fast64_t = long_long rbx.platform.typedef.__int_least8_t = char rbx.platform.typedef.__int_least16_t = short rbx.platform.typedef.__int_least32_t = int rbx.platform.typedef.__int_least64_t = long_long rbx.platform.typedef.__ptrdiff_t = int rbx.platform.typedef.__register_t = int rbx.platform.typedef.__segsz_t = int rbx.platform.typedef.__size_t = uint rbx.platform.typedef.__ssize_t = int rbx.platform.typedef.__time_t = int rbx.platform.typedef.__uintfptr_t = uint rbx.platform.typedef.__uintmax_t = ulong_long rbx.platform.typedef.__uintptr_t = uint rbx.platform.typedef.__uint_fast8_t = uint rbx.platform.typedef.__uint_fast16_t = uint rbx.platform.typedef.__uint_fast32_t = uint rbx.platform.typedef.__uint_fast64_t = ulong_long rbx.platform.typedef.__uint_least8_t = uchar rbx.platform.typedef.__uint_least16_t = ushort rbx.platform.typedef.__uint_least32_t = uint rbx.platform.typedef.__uint_least64_t = ulong_long rbx.platform.typedef.__u_register_t = uint rbx.platform.typedef.__vm_offset_t = uint rbx.platform.typedef.__vm_ooffset_t = long_long rbx.platform.typedef.__vm_paddr_t = uint rbx.platform.typedef.__vm_pindex_t = ulong_long rbx.platform.typedef.__vm_size_t = uint rbx.platform.typedef.__blksize_t = uint rbx.platform.typedef.__blkcnt_t = long_long rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__fflags_t = uint rbx.platform.typedef.__fsblkcnt_t = ulong_long rbx.platform.typedef.__fsfilcnt_t = ulong_long rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__id_t = long_long rbx.platform.typedef.__ino_t = uint rbx.platform.typedef.__key_t = long rbx.platform.typedef.__lwpid_t = int rbx.platform.typedef.__mode_t = ushort rbx.platform.typedef.__accmode_t = int rbx.platform.typedef.__nl_item = int rbx.platform.typedef.__nlink_t = ushort rbx.platform.typedef.__off_t = long_long rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__rlim_t = long_long rbx.platform.typedef.__sa_family_t = uchar rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.__suseconds_t = long rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__cpuwhich_t = int rbx.platform.typedef.__cpulevel_t = int rbx.platform.typedef.__cpusetid_t = int rbx.platform.typedef.__ct_rune_t = int rbx.platform.typedef.__rune_t = int rbx.platform.typedef.__wchar_t = int rbx.platform.typedef.__wint_t = int rbx.platform.typedef.__wint_t = int rbx.platform.typedef.__dev_t = uint rbx.platform.typedef.__fixpt_t = uint rbx.platform.typedef.pthread_key_t = int rbx.platform.typedef.*) = pointer rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.uint8_t = uchar rbx.platform.typedef.uint16_t = ushort rbx.platform.typedef.uint32_t = uint rbx.platform.typedef.uint64_t = ulong_long rbx.platform.typedef.intptr_t = int rbx.platform.typedef.uintptr_t = uint rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.qaddr_t = pointer rbx.platform.typedef.caddr_t = string rbx.platform.typedef.c_caddr_t = pointer rbx.platform.typedef.blksize_t = uint rbx.platform.typedef.cpuwhich_t = int rbx.platform.typedef.cpulevel_t = int rbx.platform.typedef.cpusetid_t = int rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.clock_t = ulong rbx.platform.typedef.clockid_t = int rbx.platform.typedef.cpumask_t = uint rbx.platform.typedef.critical_t = int rbx.platform.typedef.daddr_t = long_long rbx.platform.typedef.dev_t = uint rbx.platform.typedef.fflags_t = uint rbx.platform.typedef.fixpt_t = uint rbx.platform.typedef.fsblkcnt_t = ulong_long rbx.platform.typedef.fsfilcnt_t = ulong_long rbx.platform.typedef.gid_t = uint rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.id_t = long_long rbx.platform.typedef.ino_t = uint rbx.platform.typedef.key_t = long rbx.platform.typedef.lwpid_t = int rbx.platform.typedef.mode_t = ushort rbx.platform.typedef.accmode_t = int rbx.platform.typedef.nlink_t = ushort rbx.platform.typedef.off_t = long_long rbx.platform.typedef.pid_t = int rbx.platform.typedef.register_t = int rbx.platform.typedef.rlim_t = long_long rbx.platform.typedef.segsz_t = int rbx.platform.typedef.size_t = uint rbx.platform.typedef.ssize_t = int rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.time_t = int rbx.platform.typedef.u_register_t = uint rbx.platform.typedef.uid_t = uint rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.vm_offset_t = uint rbx.platform.typedef.vm_ooffset_t = long_long rbx.platform.typedef.vm_paddr_t = uint rbx.platform.typedef.vm_pindex_t = ulong_long rbx.platform.typedef.vm_size_t = uint rbx.platform.typedef.__fd_mask = ulong rbx.platform.typedef.fd_mask = ulong rbx.platform.typedef.sa_family_t = uchar rbx.platform.typedef.socklen_t = uint ruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-cygwin/0000755000175000017500000000000012261216360022707 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-cygwin/types.conf0000755000175000017500000000015312261216360024724 0ustar terceiroterceirorbx.platform.typedef.size_t = uint rbx.platform.typedef.ptrdiff_t = int rbx.platform.typedef.ssize_t = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-freebsd/0000755000175000017500000000000012261216360023266 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-freebsd/types.conf0000644000175000017500000001155512261216360025310 0ustar terceiroterceirorbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__int_least8_t = char rbx.platform.typedef.__uint_least8_t = uchar rbx.platform.typedef.__int_least16_t = short rbx.platform.typedef.__uint_least16_t = ushort rbx.platform.typedef.__int_least32_t = int rbx.platform.typedef.__uint_least32_t = uint rbx.platform.typedef.__int_least64_t = long_long rbx.platform.typedef.__uint_least64_t = ulong_long rbx.platform.typedef.__int_fast8_t = int rbx.platform.typedef.__uint_fast8_t = uint rbx.platform.typedef.__int_fast16_t = int rbx.platform.typedef.__uint_fast16_t = uint rbx.platform.typedef.__int_fast32_t = int rbx.platform.typedef.__uint_fast32_t = uint rbx.platform.typedef.__int_fast64_t = long_long rbx.platform.typedef.__uint_fast64_t = ulong_long rbx.platform.typedef.__intptr_t = long rbx.platform.typedef.__uintptr_t = ulong rbx.platform.typedef.__intmax_t = long_long rbx.platform.typedef.__uintmax_t = ulong_long rbx.platform.typedef.__register_t = int rbx.platform.typedef.__vaddr_t = ulong rbx.platform.typedef.__paddr_t = ulong rbx.platform.typedef.__vsize_t = ulong rbx.platform.typedef.__psize_t = ulong rbx.platform.typedef.__clock_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__off_t = long_long rbx.platform.typedef.__ptrdiff_t = long rbx.platform.typedef.__size_t = ulong rbx.platform.typedef.__ssize_t = long rbx.platform.typedef.__time_t = int rbx.platform.typedef.__timer_t = int rbx.platform.typedef.__wchar_t = int rbx.platform.typedef.__wint_t = int rbx.platform.typedef.__rune_t = int rbx.platform.typedef.__wctrans_t = pointer rbx.platform.typedef.__wctype_t = pointer rbx.platform.typedef.__cpuid_t = ulong rbx.platform.typedef.__dev_t = int rbx.platform.typedef.__fixpt_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__in_addr_t = uint rbx.platform.typedef.__in_port_t = ushort rbx.platform.typedef.__ino_t = uint rbx.platform.typedef.__key_t = long rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = uint rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__rlim_t = ulong_long rbx.platform.typedef.__sa_family_t = uchar rbx.platform.typedef.__segsz_t = int rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.__swblk_t = int rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = int rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.unchar = uchar rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.cpuid_t = ulong rbx.platform.typedef.register_t = int rbx.platform.typedef.int8_t = char rbx.platform.typedef.uint8_t = uchar rbx.platform.typedef.int16_t = short rbx.platform.typedef.uint16_t = ushort rbx.platform.typedef.int32_t = int rbx.platform.typedef.uint32_t = uint rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.uint64_t = ulong_long rbx.platform.typedef.intptr_t = long rbx.platform.typedef.uintptr_t = ulong rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.qaddr_t = pointer rbx.platform.typedef.vaddr_t = ulong rbx.platform.typedef.paddr_t = ulong rbx.platform.typedef.vsize_t = ulong rbx.platform.typedef.psize_t = ulong rbx.platform.typedef.caddr_t = string rbx.platform.typedef.daddr_t = int rbx.platform.typedef.daddr32_t = int rbx.platform.typedef.daddr64_t = long_long rbx.platform.typedef.dev_t = int rbx.platform.typedef.fixpt_t = uint rbx.platform.typedef.gid_t = uint rbx.platform.typedef.id_t = uint rbx.platform.typedef.ino_t = uint rbx.platform.typedef.key_t = long rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.pid_t = int rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.segsz_t = int rbx.platform.typedef.swblk_t = int rbx.platform.typedef.uid_t = uint rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.suseconds_t = int rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.sa_family_t = uchar rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.clock_t = int rbx.platform.typedef.clockid_t = int rbx.platform.typedef.size_t = ulong rbx.platform.typedef.ssize_t = long rbx.platform.typedef.time_t = int rbx.platform.typedef.timer_t = int rbx.platform.typedef.off_t = long_long rbx.platform.typedef.__fd_mask = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/powerpc-aix/0000755000175000017500000000000012261216360023156 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/powerpc-aix/types.conf0000644000175000017500000001537512261216360025204 0ustar terceiroterceirorbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.uint8_t = uchar rbx.platform.typedef.uint16_t = ushort rbx.platform.typedef.uint32_t = uint rbx.platform.typedef.uint64_t = ulong_long rbx.platform.typedef.intmax_t = long_long rbx.platform.typedef.uintmax_t = ulong_long rbx.platform.typedef.intptr_t = long rbx.platform.typedef.uintptr_t = ulong rbx.platform.typedef.int_least8_t = char rbx.platform.typedef.int_least16_t = short rbx.platform.typedef.int_least32_t = int rbx.platform.typedef.int_least64_t = long_long rbx.platform.typedef.uint_least8_t = uchar rbx.platform.typedef.uint_least16_t = ushort rbx.platform.typedef.uint_least32_t = uint rbx.platform.typedef.uint_least64_t = ulong_long rbx.platform.typedef.int_fast8_t = char rbx.platform.typedef.int_fast16_t = short rbx.platform.typedef.int_fast32_t = int rbx.platform.typedef.uint_fast8_t = uchar rbx.platform.typedef.uint_fast16_t = ushort rbx.platform.typedef.uint_fast32_t = uint rbx.platform.typedef.int_fast64_t = long_long rbx.platform.typedef.uint_fast64_t = ulong_long rbx.platform.typedef.wchar_t = ushort rbx.platform.typedef.intfast_t = int rbx.platform.typedef.uintfast_t = uint rbx.platform.typedef.__long32_t = long rbx.platform.typedef.__ulong32_t = ulong rbx.platform.typedef.__long64_t = int rbx.platform.typedef.__ulong64_t = uint rbx.platform.typedef.int32long64_t = int rbx.platform.typedef.uint32long64_t = uint rbx.platform.typedef.long32int64_t = long rbx.platform.typedef.ulong32int64_t = ulong rbx.platform.typedef.int8 = char rbx.platform.typedef.int16 = short rbx.platform.typedef.int32 = int rbx.platform.typedef.int64 = long_long rbx.platform.typedef.u_int8 = uchar rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16 = ushort rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32 = uint rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64 = ulong_long rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.ptrdiff_t = long rbx.platform.typedef.wctype_t = uint rbx.platform.typedef.fpos_t = long rbx.platform.typedef.fpos64_t = long_long rbx.platform.typedef.time_t = int rbx.platform.typedef.clock_t = int rbx.platform.typedef.size_t = ulong rbx.platform.typedef.uchar_t = uchar rbx.platform.typedef.ushort_t = ushort rbx.platform.typedef.uint_t = uint rbx.platform.typedef.ulong_t = ulong rbx.platform.typedef.ssize_t = long rbx.platform.typedef.level_t = int rbx.platform.typedef.daddr_t = int rbx.platform.typedef.daddr32_t = int rbx.platform.typedef.daddr64_t = long_long rbx.platform.typedef.caddr_t = string rbx.platform.typedef.ino_t = uint rbx.platform.typedef.ino32_t = uint rbx.platform.typedef.ino64_t = ulong_long rbx.platform.typedef.cnt_t = short rbx.platform.typedef.dev_t = uint rbx.platform.typedef.dev32_t = uint rbx.platform.typedef.dev64_t = ulong_long rbx.platform.typedef.chan_t = int rbx.platform.typedef.time32_t = int rbx.platform.typedef.pid32_t = int rbx.platform.typedef.tid32_t = int rbx.platform.typedef.pid64_t = ulong_long rbx.platform.typedef.tid64_t = ulong_long rbx.platform.typedef.time64_t = long_long rbx.platform.typedef.__ptr32 = pointer rbx.platform.typedef.__cptr32 = string rbx.platform.typedef.soff_t = int rbx.platform.typedef.off_t = long rbx.platform.typedef.off64_t = long_long rbx.platform.typedef.paddr_t = long rbx.platform.typedef.key_t = int rbx.platform.typedef.timer_t = int rbx.platform.typedef.timer32_t = int rbx.platform.typedef.timer64_t = long_long rbx.platform.typedef.nlink_t = short rbx.platform.typedef.mode_t = uint rbx.platform.typedef.uid_t = uint rbx.platform.typedef.gid_t = uint rbx.platform.typedef.mid_t = pointer rbx.platform.typedef.pid_t = int rbx.platform.typedef.tid_t = int rbx.platform.typedef.slab_t[12] = char rbx.platform.typedef.mtyp_t = long rbx.platform.typedef.boolean_t = int rbx.platform.typedef.crid_t = int rbx.platform.typedef.blkcnt_t = int rbx.platform.typedef.blksize_t = int rbx.platform.typedef.blkcnt32_t = int rbx.platform.typedef.blksize32_t = int rbx.platform.typedef.blkcnt64_t = ulong_long rbx.platform.typedef.blksize64_t = ulong_long rbx.platform.typedef.fsblkcnt_t = ulong rbx.platform.typedef.fsfilcnt_t = ulong rbx.platform.typedef.wint_t = int rbx.platform.typedef.id_t = uint rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.suseconds_t = int rbx.platform.typedef.clockid_t = long_long rbx.platform.typedef.signal_t = int rbx.platform.typedef.pthread_t = uint rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.vmid_t = long rbx.platform.typedef.vmhandle_t = ulong rbx.platform.typedef.vmid32_t = int rbx.platform.typedef.vmhandle32_t = uint rbx.platform.typedef.kvmid_t = long rbx.platform.typedef.kvmhandle_t = ulong rbx.platform.typedef.vmid64_t = long_long rbx.platform.typedef.rpn64_t = long_long rbx.platform.typedef.cnt64_t = long_long rbx.platform.typedef.psize_t = long_long rbx.platform.typedef.vmidx_t = int rbx.platform.typedef.vmfkey_t = uint rbx.platform.typedef.vmprkey_t = uint rbx.platform.typedef.vmkey_t = int rbx.platform.typedef.vmhwkey_t = int rbx.platform.typedef.vpn_t = int rbx.platform.typedef.rpn_t = int rbx.platform.typedef.ptex_t = ulong rbx.platform.typedef.swhatx_t = ulong rbx.platform.typedef.esid_t = uint rbx.platform.typedef.aptx_t = ushort rbx.platform.typedef.pdtx_t = int rbx.platform.typedef.psx_t = short rbx.platform.typedef.pshift_t = ushort rbx.platform.typedef.sshift_t = ushort rbx.platform.typedef.unidx_t = int rbx.platform.typedef.snidx_t = int rbx.platform.typedef.vmnodeidx_t = int rbx.platform.typedef.kvpn_t = int rbx.platform.typedef.krpn_t = int rbx.platform.typedef.vmsize_t = int rbx.platform.typedef.vmm_lock_t = int rbx.platform.typedef.ureg_t = ulong rbx.platform.typedef.vmlpghandle_t = ulong rbx.platform.typedef.ext_t = int rbx.platform.typedef.va_list = string rbx.platform.typedef.__ptr64 = ulong_long rbx.platform.typedef.__cptr64 = ulong_long rbx.platform.typedef.UniChar = ushort rbx.platform.typedef.UTF32Char = uint rbx.platform.typedef.uchar = uchar rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.swblk_t = int rbx.platform.typedef.offset_t = long_long rbx.platform.typedef.ssize64_t = long_long rbx.platform.typedef.longlong_t = long_long rbx.platform.typedef.u_longlong_t = ulong_long rbx.platform.typedef.class_id_t = uint rbx.platform.typedef.liobn_t = uint rbx.platform.typedef.unit_addr_t = ulong_long rbx.platform.typedef.size64_t = ulong_long rbx.platform.typedef.socklen_t = ulong rbx.platform.typedef.sa_family_t = uchar rbx.platform.typedef.rlim_t = ulong rbx.platform.typedef.rlim64_t = ulong_long ruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-darwin/0000755000175000017500000000000012261216360023140 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-darwin/types.conf0000644000175000017500000001003512261216360025152 0ustar terceiroterceirorbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__darwin_intptr_t = long rbx.platform.typedef.__darwin_natural_t = uint rbx.platform.typedef.__darwin_ct_rune_t = int rbx.platform.typedef.__darwin_ptrdiff_t = long rbx.platform.typedef.__darwin_size_t = ulong rbx.platform.typedef.__darwin_wchar_t = int rbx.platform.typedef.__darwin_rune_t = int rbx.platform.typedef.__darwin_wint_t = int rbx.platform.typedef.__darwin_clock_t = ulong rbx.platform.typedef.__darwin_socklen_t = uint rbx.platform.typedef.__darwin_ssize_t = long rbx.platform.typedef.__darwin_time_t = long rbx.platform.typedef.int8_t = char rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.int16_t = short rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.int32_t = int rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = long_long rbx.platform.typedef.intptr_t = long rbx.platform.typedef.uintptr_t = ulong rbx.platform.typedef.user_addr_t = ulong_long rbx.platform.typedef.user_size_t = ulong_long rbx.platform.typedef.user_ssize_t = long_long rbx.platform.typedef.user_long_t = long_long rbx.platform.typedef.user_ulong_t = ulong_long rbx.platform.typedef.user_time_t = long_long rbx.platform.typedef.syscall_arg_t = ulong_long rbx.platform.typedef.__darwin_blkcnt_t = long_long rbx.platform.typedef.__darwin_blksize_t = int rbx.platform.typedef.__darwin_dev_t = int rbx.platform.typedef.__darwin_fsblkcnt_t = uint rbx.platform.typedef.__darwin_fsfilcnt_t = uint rbx.platform.typedef.__darwin_gid_t = uint rbx.platform.typedef.__darwin_id_t = uint rbx.platform.typedef.__darwin_ino64_t = ulong_long rbx.platform.typedef.__darwin_ino_t = ulong_long rbx.platform.typedef.__darwin_mach_port_name_t = uint rbx.platform.typedef.__darwin_mach_port_t = uint rbx.platform.typedef.__darwin_mode_t = ushort rbx.platform.typedef.__darwin_off_t = long_long rbx.platform.typedef.__darwin_pid_t = int rbx.platform.typedef.__darwin_pthread_key_t = ulong rbx.platform.typedef.__darwin_sigset_t = uint rbx.platform.typedef.__darwin_suseconds_t = int rbx.platform.typedef.__darwin_uid_t = uint rbx.platform.typedef.__darwin_useconds_t = uint rbx.platform.typedef.__darwin_uuid_t[16] = uchar rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.qaddr_t = pointer rbx.platform.typedef.caddr_t = string rbx.platform.typedef.daddr_t = int rbx.platform.typedef.dev_t = int rbx.platform.typedef.fixpt_t = uint rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.blksize_t = int rbx.platform.typedef.gid_t = uint rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.ino64_t = ulong_long rbx.platform.typedef.key_t = int rbx.platform.typedef.mode_t = ushort rbx.platform.typedef.nlink_t = ushort rbx.platform.typedef.id_t = uint rbx.platform.typedef.pid_t = int rbx.platform.typedef.off_t = long_long rbx.platform.typedef.segsz_t = int rbx.platform.typedef.swblk_t = int rbx.platform.typedef.uid_t = uint rbx.platform.typedef.clock_t = ulong rbx.platform.typedef.size_t = ulong rbx.platform.typedef.ssize_t = long rbx.platform.typedef.time_t = long rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.suseconds_t = int rbx.platform.typedef.fd_mask = int rbx.platform.typedef.pthread_key_t = ulong rbx.platform.typedef.fsblkcnt_t = uint rbx.platform.typedef.fsfilcnt_t = uint rbx.platform.typedef.sa_family_t = uchar rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.rlim_t = ulong_long ruby-ffi-1.9.3debian.orig/lib/ffi/platform/sparc-linux/0000755000175000017500000000000012261216360023165 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/sparc-linux/types.conf0000644000175000017500000000762312261216360025210 0ustar terceiroterceirorbx.platform.typedef.__u_char = uchar rbx.platform.typedef.__u_short = ushort rbx.platform.typedef.__u_int = uint rbx.platform.typedef.__u_long = ulong rbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__quad_t = long_long rbx.platform.typedef.__u_quad_t = ulong_long rbx.platform.typedef.__dev_t = ulong_long rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__ino_t = ulong rbx.platform.typedef.__ino64_t = ulong_long rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = uint rbx.platform.typedef.__off_t = long rbx.platform.typedef.__off64_t = long_long rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__clock_t = long rbx.platform.typedef.__rlim_t = ulong rbx.platform.typedef.__rlim64_t = ulong_long rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__time_t = long rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = int rbx.platform.typedef.__daddr_t = int rbx.platform.typedef.__swblk_t = long rbx.platform.typedef.__key_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__timer_t = pointer rbx.platform.typedef.__blksize_t = long rbx.platform.typedef.__blkcnt_t = long rbx.platform.typedef.__blkcnt64_t = long_long rbx.platform.typedef.__fsblkcnt_t = ulong rbx.platform.typedef.__fsblkcnt64_t = ulong_long rbx.platform.typedef.__fsfilcnt_t = ulong rbx.platform.typedef.__fsfilcnt64_t = ulong_long rbx.platform.typedef.__ssize_t = int rbx.platform.typedef.__loff_t = long_long rbx.platform.typedef.*__qaddr_t = long_long rbx.platform.typedef.*__caddr_t = char rbx.platform.typedef.__intptr_t = int rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.loff_t = long_long rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.dev_t = ulong_long rbx.platform.typedef.gid_t = uint rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.uid_t = uint rbx.platform.typedef.off_t = long_long rbx.platform.typedef.pid_t = int rbx.platform.typedef.id_t = uint rbx.platform.typedef.ssize_t = int rbx.platform.typedef.daddr_t = int rbx.platform.typedef.key_t = int rbx.platform.typedef.clock_t = long rbx.platform.typedef.time_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = pointer rbx.platform.typedef.size_t = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = long rbx.platform.typedef.__sig_atomic_t = int rbx.platform.typedef.suseconds_t = int rbx.platform.typedef.__fd_mask = long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.blksize_t = long rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.fsblkcnt_t = ulong_long rbx.platform.typedef.fsfilcnt_t = ulong_long rbx.platform.typedef.pthread_t = ulong rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.pthread_once_t = int rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.__rlimit_resource_t = int rbx.platform.typedef.__rusage_who_t = int rbx.platform.typedef.__priority_which_t = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/arm-linux/0000755000175000017500000000000012261216360022634 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/arm-linux/types.conf0000644000175000017500000000774712261216360024666 0ustar terceiroterceirorbx.platform.typedef.__u_char = uchar rbx.platform.typedef.__u_short = ushort rbx.platform.typedef.__u_int = uint rbx.platform.typedef.__u_long = ulong rbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__quad_t = long_long rbx.platform.typedef.__u_quad_t = ulong_long rbx.platform.typedef.__dev_t = ulong_long rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__in_addr_t = uint rbx.platform.typedef.__in_port_t = ushort rbx.platform.typedef.__ino_t = ulong rbx.platform.typedef.__ino64_t = ulong_long rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = uint rbx.platform.typedef.__off_t = long rbx.platform.typedef.__off64_t = long_long rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__clock_t = long rbx.platform.typedef.__rlim_t = ulong rbx.platform.typedef.__rlim64_t = ulong_long rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__time_t = long rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = long rbx.platform.typedef.__daddr_t = int rbx.platform.typedef.__swblk_t = long rbx.platform.typedef.__key_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__timer_t = pointer rbx.platform.typedef.__blksize_t = long rbx.platform.typedef.__blkcnt_t = long rbx.platform.typedef.__blkcnt64_t = long_long rbx.platform.typedef.__fsblkcnt_t = ulong rbx.platform.typedef.__fsblkcnt64_t = ulong_long rbx.platform.typedef.__fsfilcnt_t = ulong rbx.platform.typedef.__fsfilcnt64_t = ulong_long rbx.platform.typedef.__ssize_t = int rbx.platform.typedef.__loff_t = long_long rbx.platform.typedef.*__qaddr_t = long_long rbx.platform.typedef.*__caddr_t = char rbx.platform.typedef.__intptr_t = int rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.loff_t = long_long rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.dev_t = ulong_long rbx.platform.typedef.gid_t = uint rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.uid_t = uint rbx.platform.typedef.off_t = long_long rbx.platform.typedef.pid_t = int rbx.platform.typedef.id_t = uint rbx.platform.typedef.ssize_t = int rbx.platform.typedef.daddr_t = int rbx.platform.typedef.key_t = int rbx.platform.typedef.clock_t = long rbx.platform.typedef.time_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = pointer rbx.platform.typedef.size_t = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = long rbx.platform.typedef.__sig_atomic_t = int rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.__fd_mask = long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.blksize_t = long rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.fsblkcnt_t = ulong_long rbx.platform.typedef.fsfilcnt_t = ulong_long rbx.platform.typedef.pthread_t = ulong rbx.platform.typedef.pthread_key_t = uint rbx.platform.typedef.pthread_once_t = int rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.sa_family_t = ushort rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.__rlimit_resource_t = int rbx.platform.typedef.__rusage_who_t = int rbx.platform.typedef.__priority_which_t = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-netbsd/0000755000175000017500000000000012261216360023133 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/x86_64-netbsd/types.conf0000644000175000017500000001144112261216360025147 0ustar terceiroterceirorbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__int_least8_t = char rbx.platform.typedef.__uint_least8_t = uchar rbx.platform.typedef.__int_least16_t = short rbx.platform.typedef.__uint_least16_t = ushort rbx.platform.typedef.__int_least32_t = int rbx.platform.typedef.__uint_least32_t = uint rbx.platform.typedef.__int_least64_t = long_long rbx.platform.typedef.__uint_least64_t = ulong_long rbx.platform.typedef.__int_fast8_t = int rbx.platform.typedef.__uint_fast8_t = uint rbx.platform.typedef.__int_fast16_t = int rbx.platform.typedef.__uint_fast16_t = uint rbx.platform.typedef.__int_fast32_t = int rbx.platform.typedef.__uint_fast32_t = uint rbx.platform.typedef.__int_fast64_t = long_long rbx.platform.typedef.__uint_fast64_t = ulong_long rbx.platform.typedef.__intptr_t = long rbx.platform.typedef.__uintptr_t = ulong rbx.platform.typedef.__intmax_t = long_long rbx.platform.typedef.__uintmax_t = ulong_long rbx.platform.typedef.__register_t = int rbx.platform.typedef.__vaddr_t = ulong rbx.platform.typedef.__paddr_t = ulong rbx.platform.typedef.__vsize_t = ulong rbx.platform.typedef.__psize_t = ulong rbx.platform.typedef.__clock_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__off_t = long_long rbx.platform.typedef.__ptrdiff_t = long rbx.platform.typedef.__size_t = ulong rbx.platform.typedef.__ssize_t = long rbx.platform.typedef.__time_t = int rbx.platform.typedef.__timer_t = int rbx.platform.typedef.__wchar_t = int rbx.platform.typedef.__wint_t = int rbx.platform.typedef.__rune_t = int rbx.platform.typedef.__wctrans_t = pointer rbx.platform.typedef.__wctype_t = pointer rbx.platform.typedef.__cpuid_t = ulong rbx.platform.typedef.__dev_t = int rbx.platform.typedef.__fixpt_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__in_addr_t = uint rbx.platform.typedef.__in_port_t = ushort rbx.platform.typedef.__ino_t = uint rbx.platform.typedef.__key_t = long rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = uint rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__rlim_t = ulong_long rbx.platform.typedef.__sa_family_t = uchar rbx.platform.typedef.__segsz_t = int rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.__swblk_t = int rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = int rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.unchar = uchar rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.cpuid_t = ulong rbx.platform.typedef.register_t = int rbx.platform.typedef.int8_t = char rbx.platform.typedef.uint8_t = uchar rbx.platform.typedef.int16_t = short rbx.platform.typedef.uint16_t = ushort rbx.platform.typedef.int32_t = int rbx.platform.typedef.uint32_t = uint rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.uint64_t = ulong_long rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.qaddr_t = pointer rbx.platform.typedef.vaddr_t = ulong rbx.platform.typedef.paddr_t = ulong rbx.platform.typedef.vsize_t = ulong rbx.platform.typedef.psize_t = ulong rbx.platform.typedef.caddr_t = string rbx.platform.typedef.daddr_t = int rbx.platform.typedef.daddr32_t = int rbx.platform.typedef.daddr64_t = long_long rbx.platform.typedef.dev_t = int rbx.platform.typedef.fixpt_t = uint rbx.platform.typedef.gid_t = uint rbx.platform.typedef.id_t = uint rbx.platform.typedef.ino_t = uint rbx.platform.typedef.key_t = long rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.pid_t = int rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.segsz_t = int rbx.platform.typedef.swblk_t = int rbx.platform.typedef.uid_t = uint rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.suseconds_t = int rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.sa_family_t = uchar rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.clock_t = int rbx.platform.typedef.clockid_t = int rbx.platform.typedef.size_t = ulong rbx.platform.typedef.ssize_t = long rbx.platform.typedef.time_t = int rbx.platform.typedef.timer_t = int rbx.platform.typedef.off_t = long_long rbx.platform.typedef.__fd_mask = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-netbsd/0000755000175000017500000000000012261216360022666 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-netbsd/types.conf0000644000175000017500000001144112261216360024702 0ustar terceiroterceirorbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__int_least8_t = char rbx.platform.typedef.__uint_least8_t = uchar rbx.platform.typedef.__int_least16_t = short rbx.platform.typedef.__uint_least16_t = ushort rbx.platform.typedef.__int_least32_t = int rbx.platform.typedef.__uint_least32_t = uint rbx.platform.typedef.__int_least64_t = long_long rbx.platform.typedef.__uint_least64_t = ulong_long rbx.platform.typedef.__int_fast8_t = int rbx.platform.typedef.__uint_fast8_t = uint rbx.platform.typedef.__int_fast16_t = int rbx.platform.typedef.__uint_fast16_t = uint rbx.platform.typedef.__int_fast32_t = int rbx.platform.typedef.__uint_fast32_t = uint rbx.platform.typedef.__int_fast64_t = long_long rbx.platform.typedef.__uint_fast64_t = ulong_long rbx.platform.typedef.__intptr_t = long rbx.platform.typedef.__uintptr_t = ulong rbx.platform.typedef.__intmax_t = long_long rbx.platform.typedef.__uintmax_t = ulong_long rbx.platform.typedef.__register_t = int rbx.platform.typedef.__vaddr_t = ulong rbx.platform.typedef.__paddr_t = ulong rbx.platform.typedef.__vsize_t = ulong rbx.platform.typedef.__psize_t = ulong rbx.platform.typedef.__clock_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__off_t = long_long rbx.platform.typedef.__ptrdiff_t = long rbx.platform.typedef.__size_t = ulong rbx.platform.typedef.__ssize_t = long rbx.platform.typedef.__time_t = int rbx.platform.typedef.__timer_t = int rbx.platform.typedef.__wchar_t = int rbx.platform.typedef.__wint_t = int rbx.platform.typedef.__rune_t = int rbx.platform.typedef.__wctrans_t = pointer rbx.platform.typedef.__wctype_t = pointer rbx.platform.typedef.__cpuid_t = ulong rbx.platform.typedef.__dev_t = int rbx.platform.typedef.__fixpt_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__in_addr_t = uint rbx.platform.typedef.__in_port_t = ushort rbx.platform.typedef.__ino_t = uint rbx.platform.typedef.__key_t = long rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = uint rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__rlim_t = ulong_long rbx.platform.typedef.__sa_family_t = uchar rbx.platform.typedef.__segsz_t = int rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.__swblk_t = int rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = int rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.unchar = uchar rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.cpuid_t = ulong rbx.platform.typedef.register_t = int rbx.platform.typedef.int8_t = char rbx.platform.typedef.uint8_t = uchar rbx.platform.typedef.int16_t = short rbx.platform.typedef.uint16_t = ushort rbx.platform.typedef.int32_t = int rbx.platform.typedef.uint32_t = uint rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.uint64_t = ulong_long rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.qaddr_t = pointer rbx.platform.typedef.vaddr_t = ulong rbx.platform.typedef.paddr_t = ulong rbx.platform.typedef.vsize_t = ulong rbx.platform.typedef.psize_t = ulong rbx.platform.typedef.caddr_t = string rbx.platform.typedef.daddr_t = int rbx.platform.typedef.daddr32_t = int rbx.platform.typedef.daddr64_t = long_long rbx.platform.typedef.dev_t = int rbx.platform.typedef.fixpt_t = uint rbx.platform.typedef.gid_t = uint rbx.platform.typedef.id_t = uint rbx.platform.typedef.ino_t = uint rbx.platform.typedef.key_t = long rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.pid_t = int rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.segsz_t = int rbx.platform.typedef.swblk_t = int rbx.platform.typedef.uid_t = uint rbx.platform.typedef.useconds_t = uint rbx.platform.typedef.suseconds_t = int rbx.platform.typedef.in_addr_t = uint rbx.platform.typedef.in_port_t = ushort rbx.platform.typedef.sa_family_t = uchar rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.clock_t = int rbx.platform.typedef.clockid_t = int rbx.platform.typedef.size_t = ulong rbx.platform.typedef.ssize_t = long rbx.platform.typedef.time_t = int rbx.platform.typedef.timer_t = int rbx.platform.typedef.off_t = long_long rbx.platform.typedef.__fd_mask = int ruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-gnu/0000755000175000017500000000000012261216360022200 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/platform/i386-gnu/types.conf0000644000175000017500000001010512261216360024210 0ustar terceiroterceirorbx.platform.typedef.__u_char = uchar rbx.platform.typedef.__u_short = ushort rbx.platform.typedef.__u_int = uint rbx.platform.typedef.__u_long = ulong rbx.platform.typedef.__int8_t = char rbx.platform.typedef.__uint8_t = uchar rbx.platform.typedef.__int16_t = short rbx.platform.typedef.__uint16_t = ushort rbx.platform.typedef.__int32_t = int rbx.platform.typedef.__uint32_t = uint rbx.platform.typedef.__int64_t = long_long rbx.platform.typedef.__uint64_t = ulong_long rbx.platform.typedef.__quad_t = long_long rbx.platform.typedef.__u_quad_t = ulong_long rbx.platform.typedef.__dev_t = uint rbx.platform.typedef.__uid_t = uint rbx.platform.typedef.__gid_t = uint rbx.platform.typedef.__ino_t = ulong rbx.platform.typedef.__ino64_t = ulong_long rbx.platform.typedef.__mode_t = uint rbx.platform.typedef.__nlink_t = uint rbx.platform.typedef.__off_t = long rbx.platform.typedef.__off64_t = long_long rbx.platform.typedef.__pid_t = int rbx.platform.typedef.__fsid_t = ulong_long rbx.platform.typedef.__clock_t = long rbx.platform.typedef.__rlim_t = ulong rbx.platform.typedef.__rlim64_t = ulong_long rbx.platform.typedef.__id_t = uint rbx.platform.typedef.__time_t = long rbx.platform.typedef.__useconds_t = uint rbx.platform.typedef.__suseconds_t = long rbx.platform.typedef.__daddr_t = int rbx.platform.typedef.__swblk_t = long rbx.platform.typedef.__key_t = int rbx.platform.typedef.__clockid_t = int rbx.platform.typedef.__timer_t = int rbx.platform.typedef.__blksize_t = long rbx.platform.typedef.__blkcnt_t = long rbx.platform.typedef.__blkcnt64_t = long_long rbx.platform.typedef.__fsblkcnt_t = ulong rbx.platform.typedef.__fsblkcnt64_t = ulong_long rbx.platform.typedef.__fsfilcnt_t = ulong rbx.platform.typedef.__fsfilcnt64_t = ulong_long rbx.platform.typedef.__ssize_t = int rbx.platform.typedef.__loff_t = long_long rbx.platform.typedef.*__qaddr_t = long_long rbx.platform.typedef.*__caddr_t = char rbx.platform.typedef.__intptr_t = int rbx.platform.typedef.__socklen_t = uint rbx.platform.typedef.u_char = uchar rbx.platform.typedef.u_short = ushort rbx.platform.typedef.u_int = uint rbx.platform.typedef.u_long = ulong rbx.platform.typedef.quad_t = long_long rbx.platform.typedef.u_quad_t = ulong_long rbx.platform.typedef.fsid_t = ulong_long rbx.platform.typedef.loff_t = long_long rbx.platform.typedef.ino_t = ulong_long rbx.platform.typedef.dev_t = uint rbx.platform.typedef.gid_t = uint rbx.platform.typedef.mode_t = uint rbx.platform.typedef.nlink_t = uint rbx.platform.typedef.uid_t = uint rbx.platform.typedef.off_t = long_long rbx.platform.typedef.pid_t = int rbx.platform.typedef.id_t = uint rbx.platform.typedef.ssize_t = int rbx.platform.typedef.daddr_t = int rbx.platform.typedef.key_t = int rbx.platform.typedef.clock_t = long rbx.platform.typedef.time_t = long rbx.platform.typedef.clockid_t = int rbx.platform.typedef.timer_t = int rbx.platform.typedef.size_t = uint rbx.platform.typedef.ulong = ulong rbx.platform.typedef.ushort = ushort rbx.platform.typedef.uint = uint rbx.platform.typedef.int8_t = char rbx.platform.typedef.int16_t = short rbx.platform.typedef.int32_t = int rbx.platform.typedef.int64_t = long_long rbx.platform.typedef.u_int8_t = uchar rbx.platform.typedef.u_int16_t = ushort rbx.platform.typedef.u_int32_t = uint rbx.platform.typedef.u_int64_t = ulong_long rbx.platform.typedef.register_t = long rbx.platform.typedef.__sig_atomic_t = int rbx.platform.typedef.__sigset_t = ulong rbx.platform.typedef.sigset_t = ulong rbx.platform.typedef.suseconds_t = long rbx.platform.typedef.__fd_mask = long rbx.platform.typedef.fd_mask = long rbx.platform.typedef.blksize_t = long rbx.platform.typedef.blkcnt_t = long_long rbx.platform.typedef.fsblkcnt_t = ulong_long rbx.platform.typedef.fsfilcnt_t = ulong_long rbx.platform.typedef.__pthread_t = int rbx.platform.typedef.pthread_t = int rbx.platform.typedef.__pthread_key = int rbx.platform.typedef.pthread_key_t = int rbx.platform.typedef.socklen_t = uint rbx.platform.typedef.sa_family_t = uchar rbx.platform.typedef.rlim_t = ulong_long rbx.platform.typedef.__rlimit_resource_t = int rbx.platform.typedef.__rusage_who_t = int rbx.platform.typedef.__priority_which_t = int ruby-ffi-1.9.3debian.orig/lib/ffi/memorypointer.rb0000644000175000017500000000004512261216360022331 0ustar terceiroterceiro# This class is now implemented in C ruby-ffi-1.9.3debian.orig/lib/ffi/struct.rb0000644000175000017500000002335512261216360020755 0ustar terceiroterceiro# # Copyright (C) 2008-2010 Wayne Meissner # Copyright (C) 2008, 2009 Andrea Fazzi # Copyright (C) 2008, 2009 Luc Heinrich # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # require 'ffi/platform' require 'ffi/struct_layout_builder' module FFI class StructLayout # @return [Array # Get an array of tuples (field name, offset of the field). def offsets members.map { |m| [ m, self[m].offset ] } end # @return [Numeric] # Get the offset of a field. def offset_of(field_name) self[field_name].offset end # An enum {Field} in a {StructLayout}. class Enum < Field # @param [AbstractMemory] ptr pointer on a {Struct} # @return [Object] # Get an object of type {#type} from memory pointed by +ptr+. def get(ptr) type.find(ptr.get_int(offset)) end # @param [AbstractMemory] ptr pointer on a {Struct} # @param value # @return [nil] # Set +value+ into memory pointed by +ptr+. def put(ptr, value) ptr.put_int(offset, type.find(value)) end end class InnerStruct < Field def get(ptr) type.struct_class.new(ptr.slice(self.offset, self.size)) end def put(ptr, value) raise TypeError, "wrong value type (expected #{type.struct_class}" unless value.is_a?(type.struct_class) ptr.slice(self.offset, self.size).__copy_from__(value.pointer, self.size) end end class Mapped < Field def initialize(name, offset, type, orig_field) super(name, offset, type) @orig_field = orig_field end def get(ptr) type.from_native(@orig_field.get(ptr), nil) end def put(ptr, value) @orig_field.put(ptr, type.to_native(value, nil)) end end end class Struct # Get struct size # @return [Numeric] def size self.class.size end # @return [Fixnum] Struct alignment def alignment self.class.alignment end alias_method :align, :alignment # (see FFI::StructLayout#offset_of) def offset_of(name) self.class.offset_of(name) end # (see FFI::StructLayout#members) def members self.class.members end # @return [Array] # Get array of values from Struct fields. def values members.map { |m| self[m] } end # (see FFI::StructLayout#offsets) def offsets self.class.offsets end # Clear the struct content. # @return [self] def clear pointer.clear self end # Get {Pointer} to struct content. # @return [AbstractMemory] def to_ptr pointer end # Get struct size # @return [Numeric] def self.size defined?(@layout) ? @layout.size : defined?(@size) ? @size : 0 end # set struct size # @param [Numeric] size # @return [size] def self.size=(size) raise ArgumentError, "Size already set" if defined?(@size) || defined?(@layout) @size = size end # @return (see Struct#alignment) def self.alignment @layout.alignment end # (see FFI::Type#members) def self.members @layout.members end # (see FFI::StructLayout#offsets) def self.offsets @layout.offsets end # (see FFI::StructLayout#offset_of) def self.offset_of(name) @layout.offset_of(name) end def self.in ptr(:in) end def self.out ptr(:out) end def self.ptr(flags = :inout) @ref_data_type ||= Type::Mapped.new(StructByReference.new(self)) end def self.val @val_data_type ||= StructByValue.new(self) end def self.by_value self.val end def self.by_ref(flags = :inout) self.ptr(flags) end class ManagedStructConverter < StructByReference # @param [Struct] struct_class def initialize(struct_class) super(struct_class) raise NoMethodError, "release() not implemented for class #{struct_class}" unless struct_class.respond_to? :release @method = struct_class.method(:release) end # @param [Pointer] ptr # @param [nil] ctx # @return [Struct] def from_native(ptr, ctx) struct_class.new(AutoPointer.new(ptr, @method)) end end def self.auto_ptr @managed_type ||= Type::Mapped.new(ManagedStructConverter.new(self)) end class << self public # @return [StructLayout] # @overload layout # @return [StructLayout] # Get struct layout. # @overload layout(*spec) # @param [Array,Array(Hash)] spec # @return [StructLayout] # Create struct layout from +spec+. # @example Creating a layout from an array +spec+ # class MyStruct < Struct # layout :field1, :int, # :field2, :pointer, # :field3, :string # end # @example Creating a layout from an array +spec+ with offset # class MyStructWithOffset < Struct # layout :field1, :int, # :field2, :pointer, 6, # set offset to 6 for this field # :field3, :string # end # @example Creating a layout from a hash +spec+ (Ruby 1.9 only) # class MyStructFromHash < Struct # layout :field1 => :int, # :field2 => :pointer, # :field3 => :string # end # @note Creating a layout from a hash +spec+ is supported only for Ruby 1.9. def layout(*spec) # raise RuntimeError, "struct layout already defined for #{self.inspect}" if defined?(@layout) return @layout if spec.size == 0 builder = StructLayoutBuilder.new builder.union = self < Union builder.packed = @packed if defined?(@packed) builder.alignment = @min_alignment if defined?(@min_alignment) if spec[0].kind_of?(Hash) hash_layout(builder, spec) else array_layout(builder, spec) end builder.size = @size if defined?(@size) && @size > builder.size cspec = builder.build @layout = cspec unless self == Struct @size = cspec.size return cspec end protected def callback(params, ret) mod = enclosing_module FFI::CallbackInfo.new(find_type(ret, mod), params.map { |e| find_type(e, mod) }) end def packed(packed = 1) @packed = packed end alias :pack :packed def aligned(alignment = 1) @min_alignment = alignment end alias :align :aligned def enclosing_module begin mod = self.name.split("::")[0..-2].inject(Object) { |obj, c| obj.const_get(c) } (mod < FFI::Library || mod < FFI::Struct || mod.respond_to?(:find_type)) ? mod : nil rescue Exception nil end end def find_field_type(type, mod = enclosing_module) if type.kind_of?(Class) && type < Struct FFI::Type::Struct.new(type) elsif type.kind_of?(Class) && type < FFI::StructLayout::Field type elsif type.kind_of?(::Array) FFI::Type::Array.new(find_field_type(type[0]), type[1]) else find_type(type, mod) end end def find_type(type, mod = enclosing_module) if mod mod.find_type(type) end || FFI.find_type(type) end private # @param [StructLayoutBuilder] builder # @param [Hash] spec # @return [builder] # @raise if Ruby 1.8 # Add hash +spec+ to +builder+. def hash_layout(builder, spec) raise "Ruby version not supported" if RUBY_VERSION =~ /1.8.*/ spec[0].each do |name, type| builder.add name, find_field_type(type), nil end end # @param [StructLayoutBuilder] builder # @param [Array] spec # @return [builder] # Add array +spec+ to +builder+. def array_layout(builder, spec) i = 0 while i < spec.size name, type = spec[i, 2] i += 2 # If the next param is a Integer, it specifies the offset if spec[i].kind_of?(Integer) offset = spec[i] i += 1 else offset = nil end builder.add name, find_field_type(type), offset end end end end end ruby-ffi-1.9.3debian.orig/lib/ffi/io.rb0000644000175000017500000000471012261216360020032 0ustar terceiroterceiro# # Copyright (C) 2008, 2009 Wayne Meissner # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.# module FFI # This module implements a couple of class methods to play with IO. module IO # @param [Integer] fd file decriptor # @param [String] mode mode string # @return [::IO] # Synonym for IO::for_fd. def self.for_fd(fd, mode = "r") ::IO.for_fd(fd, mode) end # @param [#read] io io to read from # @param [AbstractMemory] buf destination for data read from +io+ # @param [nil, Numeric] len maximul number of bytes to read from +io+. If +nil+, # read until end of file. # @return [Numeric] length really read, in bytes # # A version of IO#read that reads data from an IO and put then into a native buffer. # # This will be optimized at some future time to eliminate the double copy. # def self.native_read(io, buf, len) tmp = io.read(len) return -1 unless tmp buf.put_bytes(0, tmp) tmp.length end end end ruby-ffi-1.9.3debian.orig/lib/ffi/struct_layout_builder.rb0000644000175000017500000001472212261216360024056 0ustar terceiroterceiro# # Copyright (C) 2008-2010 Wayne Meissner # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # module FFI # Build a {StructLayout struct layout}. class StructLayoutBuilder attr_reader :size attr_reader :alignment def initialize @size = 0 @alignment = 1 @min_alignment = 1 @packed = false @union = false @fields = Array.new end # @param [Numeric] size # Set size attribute with +size+ only if +size+ is greater than attribute value. def size=(size) @size = size if size > @size end # @param [Numeric] alignment # Set alignment attribute with +alignment+ only if it is greater than attribute value. def alignment=(align) @alignment = align if align > @alignment @min_alignment = align end # @param [Boolean] is_union # @return [is_union] # Set union attribute. # Set to +true+ to build a {Union} instead of a {Struct}. def union=(is_union) @union = is_union end # @return [Boolean] # Building a {Union} or a {Struct} ? def union? @union end # Set packed attribute # @overload packed=(packed) # @param [Fixnum] packed # @return [packed] # Set alignment and packed attributes to +packed+. # @overload packed=(packed) # @param packed # @return [0,1] # Set packed attribute. def packed=(packed) if packed.is_a?(Fixnum) @alignment = packed @packed = packed else @packed = packed ? 1 : 0 end end # List of number types NUMBER_TYPES = [ Type::INT8, Type::UINT8, Type::INT16, Type::UINT16, Type::INT32, Type::UINT32, Type::LONG, Type::ULONG, Type::INT64, Type::UINT64, Type::FLOAT32, Type::FLOAT64, Type::LONGDOUBLE, Type::BOOL, ] # @param [String, Symbol] name name of the field # @param [Array, DataConverter, Struct, StructLayout::Field, Symbol, Type] type type of the field # @param [Numeric, nil] offset # @return [self] # Add a field to the builder. # @note Setting +offset+ to +nil+ or +-1+ is equivalent to +0+. def add(name, type, offset = nil) if offset.nil? || offset == -1 offset = @union ? 0 : align(@size, @packed ? [ @packed, type.alignment ].min : [ @min_alignment, type.alignment ].max) end # # If a FFI::Type type was passed in as the field arg, try and convert to a StructLayout::Field instance # field = type.is_a?(StructLayout::Field) ? type : field_for_type(name, offset, type) @fields << field @alignment = [ @alignment, field.alignment ].max unless @packed @size = [ @size, field.size + (@union ? 0 : field.offset) ].max return self end # @param (see #add) # @return (see #add) # Same as {#add}. # @see #add def add_field(name, type, offset = nil) add(name, type, offset) end # @param (see #add) # @return (see #add) # Add a struct as a field to the builder. def add_struct(name, type, offset = nil) add(name, Type::Struct.new(type), offset) end # @param name (see #add) # @param type (see #add) # @param [Numeric] count array length # @param offset (see #add) # @return (see #add) # Add an array as a field to the builder. def add_array(name, type, count, offset = nil) add(name, Type::Array.new(type, count), offset) end # @return [StructLayout] # Build and return the struct layout. def build # Add tail padding if the struct is not packed size = @packed ? @size : align(@size, @alignment) layout = StructLayout.new(@fields, size, @alignment) layout.__union! if @union layout end private # @param [Numeric] offset # @param [Numeric] align # @return [Numeric] def align(offset, align) align + ((offset - 1) & ~(align - 1)); end # @param (see #add) # @return [StructLayout::Field] def field_for_type(name, offset, type) field_class = case when type.is_a?(Type::Function) StructLayout::Function when type.is_a?(Type::Struct) StructLayout::InnerStruct when type.is_a?(Type::Array) StructLayout::Array when type.is_a?(FFI::Enum) StructLayout::Enum when NUMBER_TYPES.include?(type) StructLayout::Number when type == Type::POINTER StructLayout::Pointer when type == Type::STRING StructLayout::String when type.is_a?(Class) && type < StructLayout::Field type when type.is_a?(DataConverter) return StructLayout::Mapped.new(name, offset, Type::Mapped.new(type), field_for_type(name, offset, type.native_type)) when type.is_a?(Type::Mapped) return StructLayout::Mapped.new(name, offset, type, field_for_type(name, offset, type.native_type)) else raise TypeError, "invalid struct field type #{type.inspect}" end field_class.new(name, offset, type) end end end ruby-ffi-1.9.3debian.orig/lib/ffi/tools/0000755000175000017500000000000012261216360020234 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/lib/ffi/tools/types_generator.rb0000644000175000017500000000765712261216360024012 0ustar terceiroterceirorequire 'tempfile' module FFI # @private class TypesGenerator ## # Maps different C types to the C type representations we use TYPE_MAP = { "char" => :char, "signed char" => :char, "__signed char" => :char, "unsigned char" => :uchar, "short" => :short, "signed short" => :short, "signed short int" => :short, "unsigned short" => :ushort, "unsigned short int" => :ushort, "int" => :int, "signed int" => :int, "unsigned int" => :uint, "long" => :long, "long int" => :long, "signed long" => :long, "signed long int" => :long, "unsigned long" => :ulong, "unsigned long int" => :ulong, "long unsigned int" => :ulong, "long long" => :long_long, "long long int" => :long_long, "signed long long" => :long_long, "signed long long int" => :long_long, "unsigned long long" => :ulong_long, "unsigned long long int" => :ulong_long, "char *" => :string, "void *" => :pointer, } def self.generate(options = {}) typedefs = nil Tempfile.open 'ffi_types_generator' do |io| io.puts <<-C #include #if !(defined(WIN32)) #include #include #endif C io.close cc = ENV['CC'] || 'gcc' cmd = "#{cc} -E -x c #{options[:cppflags]} -D_DARWIN_USE_64_BIT_INODE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -c" if options[:input] typedefs = File.read(options[:input]) elsif options[:remote] typedefs = `ssh #{options[:remote]} #{cmd} - < #{io.path}` else typedefs = `#{cmd} #{io.path}` end end code = "" typedefs.each_line do |type| # We only care about single line typedef next unless type =~ /typedef/ # Ignore unions or structs next if type =~ /union|struct/ # strip off the starting typedef and ending ; type.gsub!(/^(.*typedef\s*)/, "") type.gsub!(/\s*;\s*$/, "") parts = type.split(/\s+/) def_type = parts.join(" ") # GCC does mapping with __attribute__ stuf, also see # http://hal.cs.berkeley.edu/cil/cil016.html section 16.2.7. Problem # with this is that the __attribute__ stuff can either occur before or # after the new type that is defined... if type =~ /__attribute__/ if parts.last =~ /__QI__|__HI__|__SI__|__DI__|__word__/ # In this case, the new type is BEFORE __attribute__ we need to # find the final_type as the type before the part that starts with # __attribute__ final_type = "" parts.each do |p| break if p =~ /__attribute__/ final_type = p end else final_type = parts.pop end def_type = case type when /__QI__/ then "char" when /__HI__/ then "short" when /__SI__/ then "int" when /__DI__/ then "long long" when /__word__/ then "long" else "int" end def_type = "unsigned #{def_type}" if type =~ /unsigned/ else final_type = parts.pop def_type = parts.join(" ") end if type = TYPE_MAP[def_type] code << "rbx.platform.typedef.#{final_type} = #{type}\n" TYPE_MAP[final_type] = TYPE_MAP[def_type] else # Fallback to an ordinary pointer if we don't know the type if def_type =~ /\*/ code << "rbx.platform.typedef.#{final_type} = pointer\n" TYPE_MAP[final_type] = :pointer end end end code end end end ruby-ffi-1.9.3debian.orig/lib/ffi/tools/generator.rb0000644000175000017500000000261212261216360022550 0ustar terceiroterceiromodule FFI # @private class Generator def initialize(ffi_name, rb_name, options = {}) @ffi_name = ffi_name @rb_name = rb_name @options = options @name = File.basename rb_name, '.rb' file = File.read @ffi_name new_file = file.gsub(/^( *)@@@(.*?)@@@/m) do @constants = [] @structs = [] indent = $1 original_lines = $2.count "\n" instance_eval $2, @ffi_name, $`.count("\n") new_lines = [] @constants.each { |c| new_lines << c.to_ruby } @structs.each { |s| new_lines << s.generate_layout } new_lines = new_lines.join("\n").split "\n" # expand multiline blocks new_lines = new_lines.map { |line| indent + line } padding = original_lines - new_lines.length new_lines += [nil] * padding if padding >= 0 new_lines.join "\n" end open @rb_name, 'w' do |f| f.puts "# This file is generated by rake. Do not edit." f.puts f.puts new_file end end def constants(options = {}, &block) @constants << FFI::ConstGenerator.new(@name, @options.merge(options), &block) end def struct(options = {}, &block) @structs << FFI::StructGenerator.new(@name, @options.merge(options), &block) end ## # Utility converter for constants def to_s proc { |obj| obj.to_s.inspect } end end end ruby-ffi-1.9.3debian.orig/lib/ffi/tools/generator_task.rb0000644000175000017500000000133212261216360023570 0ustar terceiroterceirobegin require 'ffi/struct_generator' require 'ffi/const_generator' require 'ffi/generator' rescue LoadError # from Rakefile require 'lib/ffi/struct_generator' require 'lib/ffi/const_generator' require 'lib/ffi/generator' end require 'rake' require 'rake/tasklib' require 'tempfile' ## # Rake task that calculates C structs for FFI::Struct. # @private class FFI::Generator::Task < Rake::TaskLib def initialize(rb_names) task :clean do rm_f rb_names end rb_names.each do |rb_name| ffi_name = "#{rb_name}.ffi" file rb_name => ffi_name do |t| puts "Generating #{rb_name}..." if Rake.application.options.trace FFI::Generator.new ffi_name, rb_name end end end end ruby-ffi-1.9.3debian.orig/lib/ffi/tools/struct_generator.rb0000644000175000017500000001046612261216360024162 0ustar terceiroterceirorequire 'tempfile' module FFI ## # Generates an FFI Struct layout. # # Given the @@@ portion in: # # module Zlib::ZStream < FFI::Struct # @@@ # name "struct z_stream_s" # include "zlib.h" # # field :next_in, :pointer # field :avail_in, :uint # field :total_in, :ulong # # # ... # @@@ # end # # StructGenerator will create the layout: # # layout :next_in, :pointer, 0, # :avail_in, :uint, 4, # :total_in, :ulong, 8, # # ... # # StructGenerator does its best to pad the layout it produces to preserve # line numbers. Place the struct definition as close to the top of the file # for best results. class StructGenerator @options = {} attr_accessor :size attr_reader :fields def initialize(name, options = {}) @name = name @struct_name = nil @includes = [] @fields = [] @found = false @size = nil if block_given? then yield self calculate self.class.options.merge(options) end end def self.options=(options) @options = options end def self.options @options end def calculate(options = {}) binary = File.join Dir.tmpdir, "rb_struct_gen_bin_#{Process.pid}" raise "struct name not set" if @struct_name.nil? Tempfile.open("#{@name}.struct_generator") do |f| f.puts "#include " @includes.each do |inc| f.puts "#include <#{inc}>" end f.puts "#include \n\n" f.puts "int main(int argc, char **argv)\n{" f.puts " #{@struct_name} s;" f.puts %[ printf("sizeof(#{@struct_name}) %u\\n", (unsigned int) sizeof(#{@struct_name}));] @fields.each do |field| f.puts <<-EOF printf("#{field.name} %u %u\\n", (unsigned int) offsetof(#{@struct_name}, #{field.name}), (unsigned int) sizeof(s.#{field.name})); EOF end f.puts "\n return 0;\n}" f.flush output = `gcc #{options[:cppflags]} #{options[:cflags]} -D_DARWIN_USE_64_BIT_INODE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -x c -Wall -Werror #{f.path} -o #{binary} 2>&1` unless $?.success? then @found = false output = output.split("\n").map { |l| "\t#{l}" }.join "\n" raise "Compilation error generating struct #{@name} (#{@struct_name}):\n#{output}" end end output = `#{binary}`.split "\n" File.unlink(binary + (FFI::Platform.windows? ? ".exe" : "")) sizeof = output.shift unless @size m = /\s*sizeof\([^)]+\) (\d+)/.match sizeof @size = m[1] end line_no = 0 output.each do |line| md = line.match(/.+ (\d+) (\d+)/) @fields[line_no].offset = md[1].to_i @fields[line_no].size = md[2].to_i line_no += 1 end @found = true end def field(name, type=nil) field = Field.new(name, type) @fields << field return field end def found? @found end def dump_config(io) io.puts "rbx.platform.#{@name}.sizeof = #{@size}" @fields.each { |field| io.puts field.to_config(@name) } end def generate_layout buf = "" @fields.each_with_index do |field, i| if buf.empty? buf << "layout :#{field.name}, :#{field.type}, #{field.offset}" else buf << " :#{field.name}, :#{field.type}, #{field.offset}" end if i < @fields.length - 1 buf << ",\n" end end buf end def get_field(name) @fields.find { |f| name == f.name } end def include(i) @includes << i end def name(n) @struct_name = n end end ## # A field in a Struct. class StructGenerator::Field attr_reader :name attr_reader :type attr_reader :offset attr_accessor :size def initialize(name, type) @name = name @type = type @offset = nil @size = nil end def offset=(o) @offset = o end def to_config(name) buf = [] buf << "rbx.platform.#{name}.#{@name}.offset = #{@offset}" buf << "rbx.platform.#{name}.#{@name}.size = #{@size}" buf << "rbx.platform.#{name}.#{@name}.type = #{@type}" if @type buf end end end ruby-ffi-1.9.3debian.orig/lib/ffi/tools/const_generator.rb0000644000175000017500000001575312261216360023770 0ustar terceiroterceirorequire 'tempfile' require 'open3' module FFI # ConstGenerator turns C constants into ruby values. # # @example a simple example for stdio # cg = FFI::ConstGenerator.new('stdio') do |gen| # gen.const(:SEEK_SET) # gen.const('SEEK_CUR') # gen.const('seek_end') # this constant does not exist # end # #calculate called automatically at the end of the block # # cg['SEEK_SET'] # => 0 # cg['SEEK_CUR'] # => 1 # cg['seek_end'] # => nil # cg.to_ruby # => "SEEK_SET = 0\nSEEK_CUR = 1\n# seek_end not available" class ConstGenerator @options = {} attr_reader :constants # Creates a new constant generator that uses +prefix+ as a name, and an # options hash. # # The only option is +:required+, which if set to +true+ raises an error if a # constant you have requested was not found. # # @param [#to_s] prefix # @param [Hash] options # @return # @option options [Boolean] :required # @overload initialize(prefix, options) # @overload initialize(prefix, options) { |gen| ... } # @yieldparam [ConstGenerator] gen new generator is passed to the block # When passed a block, {#calculate} is automatically called at the end of # the block, otherwise you must call it yourself. def initialize(prefix = nil, options = {}) @includes = ['stdio.h', 'stddef.h'] @constants = {} @prefix = prefix @required = options[:required] @options = options if block_given? then yield self calculate self.class.options.merge(options) end end # Set class options # These options are merged with {#initialize} options when it is called with a block. # @param [Hash] options # @return [Hash] class options def self.options=(options) @options = options end # Get class options. # @return [Hash] class options def self.options @options end # @param [String] name # @return constant value (converted if a +converter+ was defined). # Access a constant by name. def [](name) @constants[name].converted_value end # Request the value for C constant +name+. # # @param [#to_s] name C constant name # @param [String] format a printf format string to print the value out # @param [String] cast a C cast for the value # @param ruby_name alternate ruby name for {#to_ruby} # # @overload const(name, format=nil, cast='', ruby_name=nil, converter=nil) # +converter+ is a Method or a Proc. # @param [#call] converter convert the value from a string to the appropriate # type for {#to_ruby}. # @overload const(name, format=nil, cast='', ruby_name=nil) { |value| ... } # Use a converter block. This block convert the value from a string to the # appropriate type for {#to_ruby}. # @yieldparam value constant value def const(name, format = nil, cast = '', ruby_name = nil, converter = nil, &converter_proc) format ||= '%d' cast ||= '' if converter_proc and converter then raise ArgumentError, "Supply only converter or converter block" end converter = converter_proc if converter.nil? const = Constant.new name, format, cast, ruby_name, converter @constants[name.to_s] = const return const end # Calculate constants values. # @param [Hash] options # @option options [String] :cppflags flags for C compiler # @return [nil] # @raise if a constant is missing and +:required+ was set to +true+ (see {#initialize}) def calculate(options = {}) binary = File.join Dir.tmpdir, "rb_const_gen_bin_#{Process.pid}" Tempfile.open("#{@prefix}.const_generator") do |f| @includes.each do |inc| f.puts "#include <#{inc}>" end f.puts "\nint main(int argc, char **argv)\n{" @constants.each_value do |const| f.puts <<-EOF #ifdef #{const.name} printf("#{const.name} #{const.format}\\n", #{const.cast}#{const.name}); #endif EOF end f.puts "\n\treturn 0;\n}" f.flush output = `gcc #{options[:cppflags]} -D_DARWIN_USE_64_BIT_INODE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -x c -Wall -Werror #{f.path} -o #{binary} 2>&1` unless $?.success? then output = output.split("\n").map { |l| "\t#{l}" }.join "\n" raise "Compilation error generating constants #{@prefix}:\n#{output}" end end output = `#{binary}` File.unlink(binary + (FFI::Platform.windows? ? ".exe" : "")) output.each_line do |line| line =~ /^(\S+)\s(.*)$/ const = @constants[$1] const.value = $2 end missing_constants = @constants.select do |name, constant| constant.value.nil? end.map { |name,| name } if @required and not missing_constants.empty? then raise "Missing required constants for #{@prefix}: #{missing_constants.join ', '}" end end # Dump constants to +io+. # @param [#puts] io # @return [nil] def dump_constants(io) @constants.each do |name, constant| name = [@prefix, name].join '.' if @prefix io.puts "#{name} = #{constant.converted_value}" end end # Outputs values for discovered constants. If the constant's value was # not discovered it is not omitted. # @return [String] def to_ruby @constants.sort_by { |name,| name }.map do |name, constant| if constant.value.nil? then "# #{name} not available" else constant.to_ruby end end.join "\n" end # Add additional C include file(s) to calculate constants from. # @note +stdio.h+ and +stddef.h+ automatically included # @param [List, Array] i include file(s) # @return [Array] array of include files def include(*i) @includes |= i.flatten end end # This class hold constants for {ConstGenerator} class ConstGenerator::Constant attr_reader :name, :format, :cast attr_accessor :value # @param [#to_s] name # @param [String] format a printf format string to print the value out # @param [String] cast a C cast for the value # @param ruby_name alternate ruby name for {#to_ruby} # @param [#call] converter convert the value from a string to the appropriate # type for {#to_ruby}. def initialize(name, format, cast, ruby_name = nil, converter=nil) @name = name @format = format @cast = cast @ruby_name = ruby_name @converter = converter @value = nil end # Return constant value (converted if a +converter+ was defined). # @return constant value. def converted_value if @converter @converter.call(@value) else @value end end # get constant ruby name # @return [String] def ruby_name @ruby_name || @name end # Get an evaluable string from constant. # @return [String] def to_ruby "#{ruby_name} = #{converted_value}" end end end ruby-ffi-1.9.3debian.orig/lib/ffi/managedstruct.rb0000644000175000017500000000632312261216360022266 0ustar terceiroterceiro# Copyright (C) 2008 Mike Dalessio # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. module FFI # # FFI::ManagedStruct allows custom garbage-collection of your FFI::Structs. # # The typical use case would be when interacting with a library # that has a nontrivial memory management design, such as a linked # list or a binary tree. # # When the {Struct} instance is garbage collected, FFI::ManagedStruct will # invoke the class's release() method during object finalization. # # @example Example usage: # module MyLibrary # ffi_lib "libmylibrary" # attach_function :new_dlist, [], :pointer # attach_function :destroy_dlist, [:pointer], :void # end # # class DoublyLinkedList < FFI::ManagedStruct # @@@ # struct do |s| # s.name 'struct dlist' # s.include 'dlist.h' # s.field :head, :pointer # s.field :tail, :pointer # end # @@@ # # def self.release ptr # MyLibrary.destroy_dlist(ptr) # end # end # # begin # ptr = DoublyLinkedList.new(MyLibrary.new_dlist) # # do something with the list # end # # struct is out of scope, and will be GC'd using DoublyLinkedList#release # # class ManagedStruct < FFI::Struct # @overload initialize(pointer) # @param [Pointer] pointer # Create a new ManagedStruct which will invoke the class method #release on # @overload initialize # A new instance of FFI::ManagedStruct. def initialize(pointer=nil) raise NoMethodError, "release() not implemented for class #{self}" unless self.class.respond_to? :release raise ArgumentError, "Must supply a pointer to memory for the Struct" unless pointer super AutoPointer.new(pointer, self.class.method(:release)) end end end ruby-ffi-1.9.3debian.orig/lib/ffi/errno.rb0000644000175000017500000000354412261216360020554 0ustar terceiroterceiro# # Copyright (C) 2008-2010 Wayne Meissner # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.# module FFI # @return (see FFI::LastError.error) # @see FFI::LastError.error def self.errno FFI::LastError.error end # @param error (see FFI::LastError.error=) # @return (see FFI::LastError.error=) # @see FFI::LastError.error= def self.errno=(error) FFI::LastError.error = error end end ruby-ffi-1.9.3debian.orig/lib/ffi/enum.rb0000644000175000017500000001130512261216360020365 0ustar terceiroterceiro# # Copyright (C) 2009, 2010 Wayne Meissner # Copyright (C) 2009 Luc Heinrich # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # module FFI # An instance of this class permits to manage {Enum}s. In fact, Enums is a collection of {Enum}s. class Enums # @return [nil] def initialize @all_enums = Array.new @tagged_enums = Hash.new @symbol_map = Hash.new end # @param [Enum] enum # Add an {Enum} to the collection. def <<(enum) @all_enums << enum @tagged_enums[enum.tag] = enum unless enum.tag.nil? @symbol_map.merge!(enum.symbol_map) end # @param query enum tag or part of an enum name # @return [Enum] # Find a {Enum} in collection. def find(query) if @tagged_enums.has_key?(query) @tagged_enums[query] else @all_enums.detect { |enum| enum.symbols.include?(query) } end end # @param symbol a symbol to find in merge symbol maps of all enums. # @return a symbol def __map_symbol(symbol) @symbol_map[symbol] end end # Represents a C enum. # # For a C enum: # enum fruits { # apple, # banana, # orange, # pineapple # }; # are defined this vocabulary: # * a _symbol_ is a word from the enumeration (ie. _apple_, by example); # * a _value_ is the value of a symbol in the enumeration (by example, apple has value _0_ and banana _1_). class Enum include DataConverter attr_reader :tag # @param [nil, Enumerable] info # @param tag enum tag def initialize(info, tag=nil) @tag = tag @kv_map = Hash.new unless info.nil? last_cst = nil value = 0 info.each do |i| case i when Symbol raise ArgumentError, "duplicate enum key" if @kv_map.has_key?(i) @kv_map[i] = value last_cst = i value += 1 when Integer @kv_map[last_cst] = i value = i+1 end end end @vk_map = @kv_map.invert end # @return [Array] enum symbol names def symbols @kv_map.keys end # Get a symbol or a value from the enum. # @overload [](query) # Get enum value from symbol. # @param [Symbol] query # @return [Integer] # @overload [](query) # Get enum symbol from value. # @param [Integer] query # @return [Symbol] def [](query) case query when Symbol @kv_map[query] when Integer @vk_map[query] end end alias find [] # Get the symbol map. # @return [Hash] def symbol_map @kv_map end alias to_h symbol_map alias to_hash symbol_map # Get native type of Enum # @return [Type::INT] def native_type Type::INT end # @param [Symbol, Integer, #to_int] val # @param ctx unused # @return [Integer] value of a enum symbol def to_native(val, ctx) @kv_map[val] || if val.is_a?(Integer) val elsif val.respond_to?(:to_int) val.to_int else raise ArgumentError, "invalid enum value, #{val.inspect}" end end # @param val # @return symbol name if it exists for +val+. def from_native(val, ctx) @vk_map[val] || val end end end ruby-ffi-1.9.3debian.orig/lib/ffi/pointer.rb0000644000175000017500000001064312261216360021105 0ustar terceiroterceiro# # Copyright (C) 2008, 2009 Wayne Meissner # Copyright (c) 2007, 2008 Evan Phoenix # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # require 'ffi/platform' module FFI class Pointer # Pointer size SIZE = Platform::ADDRESS_SIZE / 8 # Return the size of a pointer on the current platform, in bytes # @return [Numeric] def self.size SIZE end # @param [nil,Numeric] len length of string to return # @return [String] # Read pointer's contents as a string, or the first +len+ bytes of the # equivalent string if +len+ is not +nil+. def read_string(len=nil) if len get_bytes(0, len) else get_string(0) end end # @param [Numeric] len length of string to return # @return [String] # Read the first +len+ bytes of pointer's contents as a string. # # Same as: # ptr.read_string(len) # with len not nil def read_string_length(len) get_bytes(0, len) end # @return [String] # Read pointer's contents as a string. # # Same as: # ptr.read_string # with no len def read_string_to_null get_string(0) end # @param [String] str string to write # @param [Numeric] len length of string to return # @return [self] # Write +len+ first bytes of +str+ in pointer's contents. # # Same as: # ptr.write_string(str, len) # with len not nil def write_string_length(str, len) put_bytes(0, str, 0, len) end # @param [String] str string to write # @param [Numeric] len length of string to return # @return [self] # Write +str+ in pointer's contents, or first +len+ bytes if # +len+ is not +nil+. def write_string(str, len=nil) len = str.bytesize unless len # Write the string data without NUL termination put_bytes(0, str, 0, len) end # @param [Type] type type of data to read from pointer's contents # @param [Symbol] reader method to send to +self+ to read +type+ # @param [Numeric] length # @return [Array] # Read an array of +type+ of length +length+. # @example # ptr.read_array_of_type(TYPE_UINT8, :get_uint8, 4) # -> [1, 2, 3, 4] def read_array_of_type(type, reader, length) ary = [] size = FFI.type_size(type) tmp = self length.times { |j| ary << tmp.send(reader) tmp += size unless j == length-1 # avoid OOB } ary end # @param [Type] type type of data to write to pointer's contents # @param [Symbol] writer method to send to +self+ to write +type+ # @param [Array] ary # @return [self] # Write +ary+ in pointer's contents as +type+. # @example # ptr.write_array_of_type(TYPE_UINT8, :put_uint8, [1, 2, 3 ,4]) def write_array_of_type(type, writer, ary) size = FFI.type_size(type) tmp = self ary.each_with_index {|i, j| tmp.send(writer, i) tmp += size unless j == ary.length-1 # avoid OOB } self end end end ruby-ffi-1.9.3debian.orig/lib/ffi/autopointer.rb0000644000175000017500000001526712261216360022005 0ustar terceiroterceiro# # Copyright (C) 2008-2010 Wayne Meissner # Copyright (C) 2008 Mike Dalessio # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. module FFI class AutoPointer < Pointer extend DataConverter # @overload initialize(pointer, method) # @param [Pointer] pointer # @param [Method] method # @return [self] # The passed Method will be invoked at GC time. # @overload initialize(pointer, proc) # @param [Pointer] pointer # @return [self] # The passed Proc will be invoked at GC time (SEE WARNING BELOW!) # @note WARNING: passing a proc _may_ cause your pointer to never be GC'd, unless you're # careful to avoid trapping a reference to the pointer in the proc. See the test # specs for examples. # @overload initialize(pointer) { |p| ... } # @param [Pointer] pointer # @yieldparam [Pointer] p +pointer+ passed to the block # @return [self] # The passed block will be invoked at GC time. # @note WARNING: passing a block will cause your pointer to never be GC'd. This is bad. # @overload initialize(pointer) # @param [Pointer] pointer # @return [self] # The pointer's release() class method will be invoked at GC time. # # @note The safest, and therefore preferred, calling # idiom is to pass a Method as the second parameter. Example usage: # # class PointerHelper # def self.release(pointer) # ... # end # end # # p = AutoPointer.new(other_pointer, PointerHelper.method(:release)) # # The above code will cause PointerHelper#release to be invoked at GC time. # # @note # The last calling idiom (only one parameter) is generally only # going to be useful if you subclass {AutoPointer}, and override # #release, which by default does nothing. def initialize(ptr, proc=nil, &block) super(ptr.type_size, ptr) raise TypeError, "Invalid pointer" if ptr.nil? || !ptr.kind_of?(Pointer) \ || ptr.kind_of?(MemoryPointer) || ptr.kind_of?(AutoPointer) @releaser = if proc raise RuntimeError.new("proc must be callable") unless proc.respond_to?(:call) CallableReleaser.new(ptr, proc) else raise RuntimeError.new("no release method defined") unless self.class.respond_to?(:release) DefaultReleaser.new(ptr, self.class) end ObjectSpace.define_finalizer(self, @releaser) self end # @return [nil] # Free the pointer. def free @releaser.free end # @param [Boolean] autorelease # @return [Boolean] +autorelease+ # Set +autorelease+ property. See {Pointer Autorelease section at Pointer}. def autorelease=(autorelease) @releaser.autorelease=(autorelease) end # @return [Boolean] +autorelease+ # Get +autorelease+ property. See {Pointer Autorelease section at Pointer}. def autorelease? @releaser.autorelease end # @abstract Base class for {AutoPointer}'s releasers. # # All subclasses of Releaser should define a +#release(ptr)+ method. # A releaser is an object in charge of release an {AutoPointer}. class Releaser attr_accessor :autorelease # @param [Pointer] ptr # @param [#call] proc # @return [nil] # A new instance of Releaser. def initialize(ptr, proc) @ptr = ptr @proc = proc @autorelease = true end # @return [nil] # Free pointer. def free if @ptr release(@ptr) @autorelease = false @ptr = nil @proc = nil end end # @param args # Release pointer if +autorelease+ is set. def call(*args) release(@ptr) if @autorelease && @ptr end end # DefaultReleaser is a {Releaser} used when an {AutoPointer} is defined without Proc # or Method. In this case, the pointer to release must be of a class derived from # AutoPointer with a +#release+ class method. class DefaultReleaser < Releaser # @param [Pointer] ptr # @return [nil] # Release +ptr+ by using his #release class method. def release(ptr) @proc.release(ptr) end end # CallableReleaser is a {Releaser} used when an {AutoPointer} is defined with a # Proc or a Method. class CallableReleaser < Releaser # @param [Pointer] ptr # @return [nil] # Release +ptr+ by using Proc or Method defined at +ptr+ {AutoPointer#initialize initialization}. def release(ptr) @proc.call(ptr) end end # Return native type of AutoPointer. # # Override {DataConverter#native_type}. # @return [Type::POINTER] # @raise {RuntimeError} if class does not implement a +#release+ method def self.native_type raise RuntimeError.new("no release method defined for #{self.inspect}") unless self.respond_to?(:release) Type::POINTER end # Create a new AutoPointer. # # Override {DataConverter#from_native}. # @overload self.from_native(ptr, ctx) # @param [Pointer] ptr # @param ctx not used. Please set +nil+. # @return [AutoPointer] def self.from_native(val, ctx) self.new(val) end end end ruby-ffi-1.9.3debian.orig/lib/ffi/platform.rb0000644000175000017500000000745212261216360021255 0ustar terceiroterceiro# # Copyright (C) 2008, 2009 Wayne Meissner # # This file is part of ruby-ffi. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of the Ruby FFI project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.# require 'rbconfig' module FFI class PlatformError < LoadError; end # This module defines different constants and class methods to play with # various platforms. module Platform OS = case RbConfig::CONFIG['host_os'].downcase when /linux/ "linux" when /darwin/ "darwin" when /freebsd/ "freebsd" when /openbsd/ "openbsd" when /sunos|solaris/ "solaris" when /mingw|mswin/ "windows" else RbConfig::CONFIG['host_os'].downcase end ARCH = case CPU.downcase when /amd64|x86_64/ "x86_64" when /i?86|x86|i86pc/ "i386" when /ppc|powerpc/ "powerpc" else case RbConfig::CONFIG['host_cpu'] when /^arm/ "arm" else RbConfig::CONFIG['host_cpu'] end end private # @param [String) os # @return [Boolean] # Test if current OS is +os+. def self.is_os(os) OS == os end NAME = "#{ARCH}-#{OS}" IS_GNU = defined?(GNU_LIBC) IS_LINUX = is_os("linux") IS_MAC = is_os("darwin") IS_FREEBSD = is_os("freebsd") IS_OPENBSD = is_os("openbsd") IS_WINDOWS = is_os("windows") IS_BSD = IS_MAC || IS_FREEBSD || IS_OPENBSD CONF_DIR = File.join(File.dirname(__FILE__), 'platform', NAME) public LIBPREFIX = case OS when /windows/ '' when /cygwin/ 'cyg' else 'lib' end LIBSUFFIX = case OS when /darwin/ 'dylib' when /linux|bsd|solaris/ 'so' when /windows|cygwin/ 'dll' else # Punt and just assume a sane unix (i.e. anything but AIX) 'so' end LIBC = if IS_WINDOWS RbConfig::CONFIG['RUBY_SO_NAME'].split('-')[-2] + '.dll' elsif IS_GNU GNU_LIBC elsif OS == 'cygwin' "cygwin1.dll" else "#{LIBPREFIX}c.#{LIBSUFFIX}" end # Test if current OS is a *BSD (include MAC) # @return [Boolean] def self.bsd? IS_BSD end # Test if current OS is Windows # @return [Boolean] def self.windows? IS_WINDOWS end # Test if current OS is Mac OS # @return [Boolean] def self.mac? IS_MAC end # Test if current OS is a unix OS # @return [Boolean] def self.unix? !IS_WINDOWS end end end ruby-ffi-1.9.3debian.orig/metadata.yml0000644000175000017500000004545312261216360020100 0ustar terceiroterceiro--- !ruby/object:Gem::Specification name: ffi version: !ruby/object:Gem::Version version: 1.9.3 platform: ruby authors: - Wayne Meissner autorequire: bindir: bin cert_chain: [] date: 2013-10-30 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rake-compiler requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: 0.6.0 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: 0.6.0 - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rubygems-tasks requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' description: Ruby FFI library email: wmeissner@gmail.com executables: [] extensions: - ext/ffi_c/extconf.rb extra_rdoc_files: [] files: - ffi.gemspec - LICENSE - COPYING - README.md - Rakefile - ext/ffi_c/AbstractMemory.c - ext/ffi_c/AbstractMemory.h - ext/ffi_c/ArrayType.c - ext/ffi_c/ArrayType.h - ext/ffi_c/Buffer.c - ext/ffi_c/Call.c - ext/ffi_c/Call.h - ext/ffi_c/ClosurePool.c - ext/ffi_c/ClosurePool.h - ext/ffi_c/compat.h - ext/ffi_c/DataConverter.c - ext/ffi_c/DynamicLibrary.c - ext/ffi_c/DynamicLibrary.h - ext/ffi_c/extconf.rb - ext/ffi_c/ffi.c - ext/ffi_c/Function.c - ext/ffi_c/Function.h - ext/ffi_c/FunctionInfo.c - ext/ffi_c/LastError.c - ext/ffi_c/LastError.h - ext/ffi_c/libffi/acinclude.m4 - ext/ffi_c/libffi/aclocal.m4 - ext/ffi_c/libffi/build-ios.sh - ext/ffi_c/libffi/ChangeLog - ext/ffi_c/libffi/ChangeLog.libffi - ext/ffi_c/libffi/ChangeLog.libgcj - ext/ffi_c/libffi/ChangeLog.v1 - ext/ffi_c/libffi/compile - ext/ffi_c/libffi/config.guess - ext/ffi_c/libffi/config.sub - ext/ffi_c/libffi/configure - ext/ffi_c/libffi/configure.ac - ext/ffi_c/libffi/configure.host - ext/ffi_c/libffi/depcomp - ext/ffi_c/libffi/doc/libffi.info - ext/ffi_c/libffi/doc/libffi.texi - ext/ffi_c/libffi/doc/stamp-vti - ext/ffi_c/libffi/doc/version.texi - ext/ffi_c/libffi/fficonfig.h.in - ext/ffi_c/libffi/fficonfig.hw - ext/ffi_c/libffi/include/ffi.h.in - ext/ffi_c/libffi/include/ffi.h.vc - ext/ffi_c/libffi/include/ffi.h.vc64 - ext/ffi_c/libffi/include/ffi_common.h - ext/ffi_c/libffi/include/Makefile.am - ext/ffi_c/libffi/include/Makefile.in - ext/ffi_c/libffi/install-sh - ext/ffi_c/libffi/libffi.pc.in - ext/ffi_c/libffi/libtool-version - ext/ffi_c/libffi/LICENSE - ext/ffi_c/libffi/ltmain.sh - ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 - ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 - ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 - ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 - ext/ffi_c/libffi/m4/ax_configure_args.m4 - ext/ffi_c/libffi/m4/ax_enable_builddir.m4 - ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 - ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 - ext/ffi_c/libffi/m4/libtool.m4 - ext/ffi_c/libffi/m4/ltoptions.m4 - ext/ffi_c/libffi/m4/ltsugar.m4 - ext/ffi_c/libffi/m4/ltversion.m4 - ext/ffi_c/libffi/m4/lt~obsolete.m4 - ext/ffi_c/libffi/Makefile.am - ext/ffi_c/libffi/Makefile.in - ext/ffi_c/libffi/Makefile.vc - ext/ffi_c/libffi/Makefile.vc64 - ext/ffi_c/libffi/man/ffi.3 - ext/ffi_c/libffi/man/ffi_call.3 - ext/ffi_c/libffi/man/ffi_prep_cif.3 - ext/ffi_c/libffi/man/Makefile.am - ext/ffi_c/libffi/man/Makefile.in - ext/ffi_c/libffi/mdate-sh - ext/ffi_c/libffi/missing - ext/ffi_c/libffi/msvcc.sh - ext/ffi_c/libffi/README - ext/ffi_c/libffi/src/alpha/ffi.c - ext/ffi_c/libffi/src/alpha/ffitarget.h - ext/ffi_c/libffi/src/alpha/osf.S - ext/ffi_c/libffi/src/arm/ffi.c - ext/ffi_c/libffi/src/arm/ffitarget.h - ext/ffi_c/libffi/src/arm/gentramp.sh - ext/ffi_c/libffi/src/arm/sysv.S - ext/ffi_c/libffi/src/arm/trampoline.S - ext/ffi_c/libffi/src/avr32/ffi.c - ext/ffi_c/libffi/src/avr32/ffitarget.h - ext/ffi_c/libffi/src/avr32/sysv.S - ext/ffi_c/libffi/src/closures.c - ext/ffi_c/libffi/src/cris/ffi.c - ext/ffi_c/libffi/src/cris/ffitarget.h - ext/ffi_c/libffi/src/cris/sysv.S - ext/ffi_c/libffi/src/debug.c - ext/ffi_c/libffi/src/dlmalloc.c - ext/ffi_c/libffi/src/frv/eabi.S - ext/ffi_c/libffi/src/frv/ffi.c - ext/ffi_c/libffi/src/frv/ffitarget.h - ext/ffi_c/libffi/src/ia64/ffi.c - ext/ffi_c/libffi/src/ia64/ffitarget.h - ext/ffi_c/libffi/src/ia64/ia64_flags.h - ext/ffi_c/libffi/src/ia64/unix.S - ext/ffi_c/libffi/src/java_raw_api.c - ext/ffi_c/libffi/src/m32r/ffi.c - ext/ffi_c/libffi/src/m32r/ffitarget.h - ext/ffi_c/libffi/src/m32r/sysv.S - ext/ffi_c/libffi/src/m68k/ffi.c - ext/ffi_c/libffi/src/m68k/ffitarget.h - ext/ffi_c/libffi/src/m68k/sysv.S - ext/ffi_c/libffi/src/mips/ffi.c - ext/ffi_c/libffi/src/mips/ffitarget.h - ext/ffi_c/libffi/src/mips/n32.S - ext/ffi_c/libffi/src/mips/o32.S - ext/ffi_c/libffi/src/moxie/eabi.S - ext/ffi_c/libffi/src/moxie/ffi.c - ext/ffi_c/libffi/src/pa/ffi.c - ext/ffi_c/libffi/src/pa/ffitarget.h - ext/ffi_c/libffi/src/pa/hpux32.S - ext/ffi_c/libffi/src/pa/linux.S - ext/ffi_c/libffi/src/powerpc/aix.S - ext/ffi_c/libffi/src/powerpc/aix_closure.S - ext/ffi_c/libffi/src/powerpc/asm.h - ext/ffi_c/libffi/src/powerpc/darwin.S - ext/ffi_c/libffi/src/powerpc/darwin_closure.S - ext/ffi_c/libffi/src/powerpc/ffi.c - ext/ffi_c/libffi/src/powerpc/ffi_darwin.c - ext/ffi_c/libffi/src/powerpc/ffitarget.h - ext/ffi_c/libffi/src/powerpc/linux64.S - ext/ffi_c/libffi/src/powerpc/linux64_closure.S - ext/ffi_c/libffi/src/powerpc/ppc_closure.S - ext/ffi_c/libffi/src/powerpc/sysv.S - ext/ffi_c/libffi/src/prep_cif.c - ext/ffi_c/libffi/src/raw_api.c - ext/ffi_c/libffi/src/s390/ffi.c - ext/ffi_c/libffi/src/s390/ffitarget.h - ext/ffi_c/libffi/src/s390/sysv.S - ext/ffi_c/libffi/src/sh/ffi.c - ext/ffi_c/libffi/src/sh/ffitarget.h - ext/ffi_c/libffi/src/sh/sysv.S - ext/ffi_c/libffi/src/sh64/ffi.c - ext/ffi_c/libffi/src/sh64/ffitarget.h - ext/ffi_c/libffi/src/sh64/sysv.S - ext/ffi_c/libffi/src/sparc/ffi.c - ext/ffi_c/libffi/src/sparc/ffitarget.h - ext/ffi_c/libffi/src/sparc/v8.S - ext/ffi_c/libffi/src/sparc/v9.S - ext/ffi_c/libffi/src/types.c - ext/ffi_c/libffi/src/x86/darwin.S - ext/ffi_c/libffi/src/x86/darwin64.S - ext/ffi_c/libffi/src/x86/ffi.c - ext/ffi_c/libffi/src/x86/ffi64.c - ext/ffi_c/libffi/src/x86/ffitarget.h - ext/ffi_c/libffi/src/x86/freebsd.S - ext/ffi_c/libffi/src/x86/sysv.S - ext/ffi_c/libffi/src/x86/unix64.S - ext/ffi_c/libffi/src/x86/win32.S - ext/ffi_c/libffi/src/x86/win64.S - ext/ffi_c/libffi/testsuite/config/default.exp - ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp - ext/ffi_c/libffi/testsuite/lib/libffi.exp - ext/ffi_c/libffi/testsuite/lib/target-libpath.exp - ext/ffi_c/libffi/testsuite/lib/wrapper.exp - ext/ffi_c/libffi/testsuite/libffi.call/call.exp - ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c - ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c - ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c - ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c - ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c - ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c - ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c - ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c - ext/ffi_c/libffi/testsuite/libffi.call/closure_stdcall.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c - ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c - ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c - ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c - ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h - ext/ffi_c/libffi/testsuite/libffi.call/float.c - ext/ffi_c/libffi/testsuite/libffi.call/float1.c - ext/ffi_c/libffi/testsuite/libffi.call/float2.c - ext/ffi_c/libffi/testsuite/libffi.call/float3.c - ext/ffi_c/libffi/testsuite/libffi.call/float4.c - ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c - ext/ffi_c/libffi/testsuite/libffi.call/many.c - ext/ffi_c/libffi/testsuite/libffi.call/many_win32.c - ext/ffi_c/libffi/testsuite/libffi.call/negint.c - ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c - ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c - ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c - ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c - ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c - ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c - ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c - ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c - ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c - ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c - ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c - ext/ffi_c/libffi/testsuite/libffi.call/problem1.c - ext/ffi_c/libffi/testsuite/libffi.call/promotion.c - ext/ffi_c/libffi/testsuite/libffi.call/pyobjc-tc.c - ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c - ext/ffi_c/libffi/testsuite/libffi.call/return_dbl1.c - ext/ffi_c/libffi/testsuite/libffi.call/return_dbl2.c - ext/ffi_c/libffi/testsuite/libffi.call/return_fl.c - ext/ffi_c/libffi/testsuite/libffi.call/return_fl1.c - ext/ffi_c/libffi/testsuite/libffi.call/return_fl2.c - ext/ffi_c/libffi/testsuite/libffi.call/return_fl3.c - ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c - ext/ffi_c/libffi/testsuite/libffi.call/return_ll.c - ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c - ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c - ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c - ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c - ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c - ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c - ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c - ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c - ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c - ext/ffi_c/libffi/testsuite/libffi.call/strlen.c - ext/ffi_c/libffi/testsuite/libffi.call/strlen_win32.c - ext/ffi_c/libffi/testsuite/libffi.call/struct1.c - ext/ffi_c/libffi/testsuite/libffi.call/struct2.c - ext/ffi_c/libffi/testsuite/libffi.call/struct3.c - ext/ffi_c/libffi/testsuite/libffi.call/struct4.c - ext/ffi_c/libffi/testsuite/libffi.call/struct5.c - ext/ffi_c/libffi/testsuite/libffi.call/struct6.c - ext/ffi_c/libffi/testsuite/libffi.call/struct7.c - ext/ffi_c/libffi/testsuite/libffi.call/struct8.c - ext/ffi_c/libffi/testsuite/libffi.call/struct9.c - ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c - ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h - ext/ffi_c/libffi/testsuite/libffi.special/special.exp - ext/ffi_c/libffi/testsuite/libffi.special/unwindtest.cc - ext/ffi_c/libffi/testsuite/libffi.special/unwindtest_ffi_call.cc - ext/ffi_c/libffi/testsuite/Makefile.am - ext/ffi_c/libffi/testsuite/Makefile.in - ext/ffi_c/libffi/texinfo.tex - ext/ffi_c/libffi.bsd.mk - ext/ffi_c/libffi.darwin.mk - ext/ffi_c/libffi.gnu.mk - ext/ffi_c/libffi.mk - ext/ffi_c/libffi.vc.mk - ext/ffi_c/libffi.vc64.mk - ext/ffi_c/LongDouble.c - ext/ffi_c/LongDouble.h - ext/ffi_c/MappedType.c - ext/ffi_c/MappedType.h - ext/ffi_c/MemoryPointer.c - ext/ffi_c/MemoryPointer.h - ext/ffi_c/MethodHandle.c - ext/ffi_c/MethodHandle.h - ext/ffi_c/Platform.c - ext/ffi_c/Platform.h - ext/ffi_c/Pointer.c - ext/ffi_c/Pointer.h - ext/ffi_c/rbffi.h - ext/ffi_c/rbffi_endian.h - ext/ffi_c/Struct.c - ext/ffi_c/Struct.h - ext/ffi_c/StructByReference.c - ext/ffi_c/StructByReference.h - ext/ffi_c/StructByValue.c - ext/ffi_c/StructByValue.h - ext/ffi_c/StructLayout.c - ext/ffi_c/Thread.c - ext/ffi_c/Thread.h - ext/ffi_c/Type.c - ext/ffi_c/Type.h - ext/ffi_c/Types.c - ext/ffi_c/Types.h - ext/ffi_c/Variadic.c - ext/ffi_c/win32/stdbool.h - ext/ffi_c/win32/stdint.h - gen/Rakefile - lib/ffi/autopointer.rb - lib/ffi/buffer.rb - lib/ffi/callback.rb - lib/ffi/enum.rb - lib/ffi/errno.rb - lib/ffi/ffi.rb - lib/ffi/io.rb - lib/ffi/library.rb - lib/ffi/managedstruct.rb - lib/ffi/memorypointer.rb - lib/ffi/platform/arm-linux/types.conf - lib/ffi/platform/i386-cygwin/types.conf - lib/ffi/platform/i386-darwin/types.conf - lib/ffi/platform/i386-freebsd/types.conf - lib/ffi/platform/i386-gnu/types.conf - lib/ffi/platform/i386-linux/types.conf - lib/ffi/platform/i386-netbsd/types.conf - lib/ffi/platform/i386-openbsd/types.conf - lib/ffi/platform/i386-solaris/types.conf - lib/ffi/platform/i386-windows/types.conf - lib/ffi/platform/ia64-linux/types.conf - lib/ffi/platform/mips-linux/types.conf - lib/ffi/platform/mipsel-linux/types.conf - lib/ffi/platform/powerpc-aix/types.conf - lib/ffi/platform/powerpc-darwin/types.conf - lib/ffi/platform/powerpc-linux/types.conf - lib/ffi/platform/s390-linux/types.conf - lib/ffi/platform/s390x-linux/types.conf - lib/ffi/platform/sparc-linux/types.conf - lib/ffi/platform/sparc-solaris/types.conf - lib/ffi/platform/sparcv9-solaris/types.conf - lib/ffi/platform/x86_64-cygwin/types.conf - lib/ffi/platform/x86_64-darwin/types.conf - lib/ffi/platform/x86_64-freebsd/types.conf - lib/ffi/platform/x86_64-linux/types.conf - lib/ffi/platform/x86_64-netbsd/types.conf - lib/ffi/platform/x86_64-openbsd/types.conf - lib/ffi/platform/x86_64-solaris/types.conf - lib/ffi/platform/x86_64-windows/types.conf - lib/ffi/platform.rb - lib/ffi/pointer.rb - lib/ffi/struct.rb - lib/ffi/struct_layout_builder.rb - lib/ffi/tools/const_generator.rb - lib/ffi/tools/generator.rb - lib/ffi/tools/generator_task.rb - lib/ffi/tools/struct_generator.rb - lib/ffi/tools/types_generator.rb - lib/ffi/types.rb - lib/ffi/union.rb - lib/ffi/variadic.rb - lib/ffi/version.rb - lib/ffi.rb - spec/ffi/async_callback_spec.rb - spec/ffi/bool_spec.rb - spec/ffi/buffer_spec.rb - spec/ffi/callback_spec.rb - spec/ffi/custom_param_type.rb - spec/ffi/custom_type_spec.rb - spec/ffi/dup_spec.rb - spec/ffi/enum_spec.rb - spec/ffi/errno_spec.rb - spec/ffi/ffi_spec.rb - spec/ffi/function_spec.rb - spec/ffi/library_spec.rb - spec/ffi/long_double.rb - spec/ffi/managed_struct_spec.rb - spec/ffi/number_spec.rb - spec/ffi/pointer_spec.rb - spec/ffi/rbx/attach_function_spec.rb - spec/ffi/rbx/memory_pointer_spec.rb - spec/ffi/rbx/spec_helper.rb - spec/ffi/rbx/struct_spec.rb - spec/ffi/spec_helper.rb - spec/ffi/string_spec.rb - spec/ffi/strptr_spec.rb - spec/ffi/struct_by_ref_spec.rb - spec/ffi/struct_callback_spec.rb - spec/ffi/struct_initialize_spec.rb - spec/ffi/struct_packed_spec.rb - spec/ffi/struct_spec.rb - spec/ffi/typedef_spec.rb - spec/ffi/union_spec.rb - spec/ffi/variadic_spec.rb - spec/spec.opts - libtest/Benchmark.c - libtest/BoolTest.c - libtest/BufferTest.c - libtest/ClosureTest.c - libtest/EnumTest.c - libtest/FunctionTest.c - libtest/GlobalVariable.c - libtest/GNUmakefile - libtest/LastErrorTest.c - libtest/NumberTest.c - libtest/PointerTest.c - libtest/ReferenceTest.c - libtest/StringTest.c - libtest/StructTest.c - libtest/UnionTest.c - libtest/VariadicTest.c homepage: http://wiki.github.com/ffi/ffi licenses: - BSD metadata: {} post_install_message: rdoc_options: - --exclude=ext/ffi_c/.*\.o$ - --exclude=ffi_c\.(bundle|so)$ require_paths: - lib - ext/ffi_c required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: 1.8.7 required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.0.8 signing_key: specification_version: 4 summary: Ruby FFI test_files: [] ruby-ffi-1.9.3debian.orig/gen/0000755000175000017500000000000012261216360016333 5ustar terceiroterceiroruby-ffi-1.9.3debian.orig/gen/Rakefile0000644000175000017500000000134612261216360020004 0ustar terceiroterceiro$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') require 'fileutils' require 'ffi' require 'ffi/platform' require 'ffi/tools/types_generator' types_conf = File.expand_path(File.join(FFI::Platform::CONF_DIR, 'types.conf')) logfile = File.join(File.dirname(__FILE__), 'log') file types_conf do |task| options = {} FileUtils.mkdir_p(File.dirname(task.name), { :mode => 0755 }) File.open(task.name, File::CREAT|File::TRUNC|File::RDWR, 0644) do |f| f.puts FFI::TypesGenerator.generate(options) end File.open(logfile, 'w') do |log| log.puts(types_conf) end end task :default => types_conf do end task :clean do File.readlines(logfile).each do |file| file.strip! rm_f file end rm_f logfile end