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;
00009 ffi_sarg fffi_sarg;
00010 unsigned char uchar;
00011 signed char schar;
00012 unsigned short ushort;
00013 signed short sshort;
00014 unsigned int uint;
00015 signed int sint;
00016 unsigned long ulong;
00017 signed long slong;
00018 float ffloat;
00019 double ddouble;
00020 #if HAVE_LONG_LONG
00021 unsigned LONG_LONG ulong_long;
00022 signed LONG_LONG slong_long;
00023 #endif
00024 void * 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
00040 # define PTR2NUM(x) (ULL2NUM((unsigned long long)(x)))
00041 # define NUM2PTR(x) ((void*)(NUM2ULL(x)))
00042 #endif
00043
00044 #endif
00045