Ruby: ext/fiddle/conversions.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

conversions.h
Go to the documentation of this file.
1#ifndef FIDDLE_CONVERSIONS_H
2#define FIDDLE_CONVERSIONS_H
3
4#include <fiddle.h>
5
6 typedef union
7{
8 ffi_arg fffi_arg; /* rvalue smaller than unsigned long */
9 ffi_sarg fffi_sarg; /* rvalue smaller than signed long */
10 unsigned char uchar; /* ffi_type_uchar */
11 signed char schar; /* ffi_type_schar */
12 unsigned short ushort; /* ffi_type_sshort */
13 signed short sshort; /* ffi_type_ushort */
14 unsigned int uint; /* ffi_type_uint */
15 signed int sint; /* ffi_type_sint */
16 unsigned long ulong; /* ffi_type_ulong */
17 signed long slong; /* ffi_type_slong */
18 float ffloat; /* ffi_type_float */
19 double ddouble; /* ffi_type_double */
20#if HAVE_LONG_LONG
21 unsigned LONG_LONG ulong_long; /* ffi_type_ulong_long */
22 signed LONG_LONG slong_long; /* ffi_type_ulong_long */
23#endif
24 void * pointer; /* ffi_type_pointer */
25} fiddle_generic;
26
27 VALUE rb_fiddle_type_ensure(VALUE type);
28ffi_type * rb_fiddle_int_to_ffi_type(int type);
29void rb_fiddle_value_to_generic(int type, VALUE *src, fiddle_generic *dst);
30 VALUE rb_fiddle_generic_to_value(VALUE rettype, fiddle_generic retval);
31
32/* Deprecated. Use rb_fiddle_*() version. */
33ffi_type * int_to_ffi_type(int type);
34void value_to_generic(int type, VALUE src, fiddle_generic *dst);
35 VALUE generic_to_value(VALUE rettype, fiddle_generic retval);
36
37#define VALUE2GENERIC(_type, _src, _dst) \
38 rb_fiddle_value_to_generic((_type), &(_src), (_dst))
39#define INT2FFI_TYPE(_type) \
40 rb_fiddle_int_to_ffi_type(_type)
41#define GENERIC2VALUE(_type, _retval) \
42 rb_fiddle_generic_to_value((_type), (_retval))
43
44#if SIZEOF_VOIDP == SIZEOF_LONG
45# define PTR2NUM(x) (LONG2NUM((long)(x)))
46# define NUM2PTR(x) ((void*)(NUM2ULONG(x)))
47#else
48/* # error --->> Ruby/DL2 requires sizeof(void*) == sizeof(long) to be compiled. <<--- */
49# define PTR2NUM(x) (LL2NUM((LONG_LONG)(x)))
50# define NUM2PTR(x) ((void*)(NUM2ULL(x)))
51#endif
52
53#endif
ffi_arg
unsigned long ffi_arg
Definition: ffitarget.h:30
ffi_sarg
signed long ffi_sarg
Definition: ffitarget.h:31
int_to_ffi_type
ffi_type * int_to_ffi_type(int type)
Definition: conversions.c:197
rb_fiddle_generic_to_value
VALUE rb_fiddle_generic_to_value(VALUE rettype, fiddle_generic retval)
Definition: conversions.c:271
rb_fiddle_int_to_ffi_type
ffi_type * rb_fiddle_int_to_ffi_type(int type)
Definition: conversions.c:156
rb_fiddle_type_ensure
VALUE rb_fiddle_type_ensure(VALUE type)
Definition: conversions.c:4
value_to_generic
void value_to_generic(int type, VALUE src, fiddle_generic *dst)
Definition: conversions.c:263
generic_to_value
VALUE generic_to_value(VALUE rettype, fiddle_generic retval)
Definition: conversions.c:325
rb_fiddle_value_to_generic
void rb_fiddle_value_to_generic(int type, VALUE *src, fiddle_generic *dst)
Definition: conversions.c:203
fiddle.h
fiddle_generic
Definition: conversions.h:7
fiddle_generic::pointer
void * pointer
Definition: conversions.h:24
fiddle_generic::uint
unsigned int uint
Definition: conversions.h:14
fiddle_generic::ddouble
double ddouble
Definition: conversions.h:19
fiddle_generic::fffi_sarg
ffi_sarg fffi_sarg
Definition: conversions.h:9
fiddle_generic::ushort
unsigned short ushort
Definition: conversions.h:12
fiddle_generic::schar
signed char schar
Definition: conversions.h:11
fiddle_generic::uchar
unsigned char uchar
Definition: conversions.h:10
fiddle_generic::ffloat
float ffloat
Definition: conversions.h:18
fiddle_generic::fffi_arg
ffi_arg fffi_arg
Definition: conversions.h:8
fiddle_generic::slong
signed long slong
Definition: conversions.h:17
fiddle_generic::ulong
unsigned long ulong
Definition: conversions.h:16
fiddle_generic::sshort
signed short sshort
Definition: conversions.h:13
fiddle_generic::sint
signed int sint
Definition: conversions.h:15
VALUE
unsigned long VALUE
Definition: value.h:38