Ruby  2.0.0p247(2013-06-27revision41674)
ext/fiddle/conversions.h
Go to the documentation of this file.
00001 #ifndef FIDDLE_CONVERSIONS_H
00002 #define FIDDLE_CONVERSIONS_H
00003 
00004 #include <fiddle.h>
00005 
00006 typedef union
00007 {
00008     ffi_arg  fffi_arg;     /* rvalue smaller than unsigned long */
00009     ffi_sarg fffi_sarg;    /* rvalue smaller than signed long */
00010     unsigned char uchar;   /* ffi_type_uchar */
00011     signed char   schar;   /* ffi_type_schar */
00012     unsigned short ushort; /* ffi_type_sshort */
00013     signed short sshort;   /* ffi_type_ushort */
00014     unsigned int uint;     /* ffi_type_uint */
00015     signed int sint;       /* ffi_type_sint */
00016     unsigned long ulong;   /* ffi_type_ulong */
00017     signed long slong;     /* ffi_type_slong */
00018     float ffloat;          /* ffi_type_float */
00019     double ddouble;        /* ffi_type_double */
00020 #if HAVE_LONG_LONG
00021     unsigned LONG_LONG ulong_long; /* ffi_type_ulong_long */
00022     signed LONG_LONG slong_long; /* ffi_type_ulong_long */
00023 #endif
00024     void * pointer;        /* ffi_type_pointer */
00025 } fiddle_generic;
00026 
00027 ffi_type * int_to_ffi_type(int type);
00028 void value_to_generic(int type, VALUE src, fiddle_generic * dst);
00029 VALUE generic_to_value(VALUE rettype, fiddle_generic retval);
00030 
00031 #define VALUE2GENERIC(_type, _src, _dst) value_to_generic((_type), (_src), (_dst))
00032 #define INT2FFI_TYPE(_type) int_to_ffi_type(_type)
00033 #define GENERIC2VALUE(_type, _retval) generic_to_value((_type), (_retval))
00034 
00035 #if SIZEOF_VOIDP == SIZEOF_LONG
00036 # define PTR2NUM(x)   (ULONG2NUM((unsigned long)(x)))
00037 # define NUM2PTR(x)   ((void*)(NUM2ULONG(x)))
00038 #else
00039 /* # error --->> Ruby/DL2 requires sizeof(void*) == sizeof(long) to be compiled. <<--- */
00040 # define PTR2NUM(x)   (ULL2NUM((unsigned long long)(x)))
00041 # define NUM2PTR(x)   ((void*)(NUM2ULL(x)))
00042 #endif
00043 
00044 #endif
00045