Skip to content

Instantly share code, notes, and snippets.

@yugui
Created June 27, 2010 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yugui/454779 to your computer and use it in GitHub Desktop.
Save yugui/454779 to your computer and use it in GitHub Desktop.
diff --git a/ext/fiddle/conversions.c b/ext/fiddle/conversions.c
index bb5361a..2291829 100644
--- a/ext/fiddle/conversions.c
+++ b/ext/fiddle/conversions.c
@@ -1,5 +1,55 @@
#include <fiddle.h>
+#undef ffi_type_uchar
+#undef ffi_type_schar
+#undef ffi_type_ushort
+#undef ffi_type_sshort
+#undef ffi_type_uint
+#undef ffi_type_sint
+#undef ffi_type_ulong
+#undef ffi_type_slong
+
+#ifdef CHAR_BIT == 8
+# define ffi_type_uchar ffi_type_uint8
+# define ffi_type_schar ffi_type_sint8
+
+# ifdef SIZEOF_SHORT == 2
+# define ffi_type_ushort ffi_type_uint16
+# define ffi_type_sshort ffi_type_sint16
+# elif SIZEOF_SHORT == 4
+# define ffi_type_ushort ffi_type_uint32
+# define ffi_type_sshort ffi_type_sint32
+# else
+# error "short size not supported"
+# endif
+
+# ifdef SIZEOF_INT == 2
+# define ffi_type_uint ffi_type_uint16
+# define ffi_type_sint ffi_type_sint16
+# elif SIZEOF_INT == 4
+# define ffi_type_uint ffi_type_uint32
+# define ffi_type_sint ffi_type_sint32
+# elif SIZEOF_INT == 8
+# define ffi_type_uint ffi_type_uint64
+# define ffi_type_sint ffi_type_sint64
+# else
+# error "int size not supported"
+# endif
+
+# ifdef SIZEOF_LONG == 4
+# define ffi_type_ulong ffi_type_uint32
+# define ffi_type_slong ffi_type_sint32
+# elif SIZEOF_LONG == 8
+# define ffi_type_ulong ffi_type_uint64
+# define ffi_type_slong ffi_type_sint64
+# else
+# error "long size not supported"
+# endif
+
+#else
+# error "CHAR_BIT not supported"
+#endif
+
ffi_type *
int_to_ffi_type(int type)
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment