summaryrefslogtreecommitdiff
path: root/ext/fiddle/conversions.h
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-06 06:59:24 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-06 06:59:24 +0000
commit4bada8b864e445b6eebe1a341e30cad94dbcaf84 (patch)
treebb7e4ed991aa16eda953d536265c6f9e5dc03a5d /ext/fiddle/conversions.h
parentca3c007f058f17b2f0bf3c5ccc6701f3f6d49ca5 (diff)
* ext/fiddle/*: Adding fiddle library to wrap libffi
* test/fiddle/*: testing fiddle extension * ext/dl/lib/dl.rb: Requiring fiddle if it is available * ext/dl/lib/dl/callback.rb: using Fiddle if it is available * ext/dl/lib/dl/func.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/fiddle/conversions.h')
-rw-r--r--ext/fiddle/conversions.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/ext/fiddle/conversions.h b/ext/fiddle/conversions.h
new file mode 100644
index 0000000..166c5d9
--- /dev/null
+++ b/ext/fiddle/conversions.h
@@ -0,0 +1,41 @@
+#ifndef FIDDLE_CONVERSIONS_H
+#define FIDDLE_CONVERSIONS_H
+
+#include <fiddle.h>
+
+typedef union
+{
+ 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
+ unsigned LONG_LONG long_long; /* ffi_type_uint64 */
+#endif
+ void * pointer; /* ffi_type_pointer */
+} fiddle_generic;
+
+ffi_type * int_to_ffi_type(int type);
+void value_to_generic(int type, VALUE src, fiddle_generic * dst);
+VALUE generic_to_value(VALUE rettype, fiddle_generic retval);
+
+#define VALUE2GENERIC(_type, _src, _dst) value_to_generic(_type, _src, _dst)
+#define INT2FFI_TYPE(_type) int_to_ffi_type(_type)
+#define GENERIC2VALUE(_type, _retval) generic_to_value(_type, _retval)
+
+#if SIZEOF_VOIDP == SIZEOF_LONG
+# define PTR2NUM(x) (ULONG2NUM((unsigned long)(x)))
+# define NUM2PTR(x) ((void*)(NUM2ULONG(x)))
+#else
+/* # error --->> Ruby/DL2 requires sizeof(void*) == sizeof(long) to be compiled. <<--- */
+# define PTR2NUM(x) (ULL2NUM((unsigned long long)(x)))
+# define NUM2PTR(x) ((void*)(NUM2ULL(x)))
+#endif
+
+#endif