2010-05-06 02:59:24 -04:00
|
|
|
#ifndef FIDDLE_CONVERSIONS_H
|
|
|
|
#define FIDDLE_CONVERSIONS_H
|
|
|
|
|
|
|
|
#include <fiddle.h>
|
|
|
|
|
|
|
|
typedef union
|
|
|
|
{
|
2011-08-09 01:31:47 -04:00
|
|
|
ffi_arg fffi_arg; /* rvalue smaller than unsigned long */
|
|
|
|
ffi_sarg fffi_sarg; /* rvalue smaller than signed long */
|
2010-05-06 02:59:24 -04:00
|
|
|
unsigned char uchar; /* ffi_type_uchar */
|
|
|
|
signed char schar; /* ffi_type_schar */
|
|
|
|
unsigned short ushort; /* ffi_type_sshort */
|
|
|
|
signed short sshort; /* ffi_type_ushort */
|
|
|
|
unsigned int uint; /* ffi_type_uint */
|
|
|
|
signed int sint; /* ffi_type_sint */
|
|
|
|
unsigned long ulong; /* ffi_type_ulong */
|
|
|
|
signed long slong; /* ffi_type_slong */
|
|
|
|
float ffloat; /* ffi_type_float */
|
|
|
|
double ddouble; /* ffi_type_double */
|
|
|
|
#if HAVE_LONG_LONG
|
2012-02-15 05:57:05 -05:00
|
|
|
unsigned LONG_LONG ulong_long; /* ffi_type_ulong_long */
|
|
|
|
signed LONG_LONG slong_long; /* ffi_type_ulong_long */
|
2010-05-06 02:59:24 -04:00
|
|
|
#endif
|
|
|
|
void * pointer; /* ffi_type_pointer */
|
|
|
|
} fiddle_generic;
|
|
|
|
|
2020-07-09 07:19:20 -04:00
|
|
|
/* Deprecated. Use rb_fiddle_*() version. */
|
2020-07-09 08:39:51 -04:00
|
|
|
VALUE rb_fiddle_type_ensure(VALUE type);
|
2020-07-09 07:19:20 -04:00
|
|
|
ffi_type * rb_fiddle_int_to_ffi_type(int type);
|
|
|
|
void rb_fiddle_value_to_generic(int type, VALUE *src, fiddle_generic *dst);
|
|
|
|
VALUE rb_fiddle_generic_to_value(VALUE rettype, fiddle_generic retval);
|
|
|
|
|
|
|
|
/* Deprecated. Use rb_fiddle_*() version. */
|
2010-05-06 02:59:24 -04:00
|
|
|
ffi_type * int_to_ffi_type(int type);
|
2020-07-09 07:19:20 -04:00
|
|
|
void value_to_generic(int type, VALUE src, fiddle_generic *dst);
|
2010-05-06 02:59:24 -04:00
|
|
|
VALUE generic_to_value(VALUE rettype, fiddle_generic retval);
|
|
|
|
|
2020-07-09 07:19:20 -04:00
|
|
|
#define VALUE2GENERIC(_type, _src, _dst) \
|
|
|
|
rb_fiddle_value_to_generic((_type), &(_src), (_dst))
|
|
|
|
#define INT2FFI_TYPE(_type) \
|
|
|
|
rb_fiddle_int_to_ffi_type(_type)
|
|
|
|
#define GENERIC2VALUE(_type, _retval) \
|
|
|
|
rb_fiddle_generic_to_value((_type), (_retval))
|
2010-05-06 02:59:24 -04:00
|
|
|
|
|
|
|
#if SIZEOF_VOIDP == SIZEOF_LONG
|
2015-12-13 04:35:10 -05:00
|
|
|
# define PTR2NUM(x) (LONG2NUM((long)(x)))
|
2010-05-06 02:59:24 -04:00
|
|
|
# define NUM2PTR(x) ((void*)(NUM2ULONG(x)))
|
|
|
|
#else
|
|
|
|
/* # error --->> Ruby/DL2 requires sizeof(void*) == sizeof(long) to be compiled. <<--- */
|
2015-12-13 04:35:10 -05:00
|
|
|
# define PTR2NUM(x) (LL2NUM((LONG_LONG)(x)))
|
2010-05-06 02:59:24 -04:00
|
|
|
# define NUM2PTR(x) ((void*)(NUM2ULL(x)))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|