summaryrefslogtreecommitdiff
path: root/ext/dl
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-17 06:34:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-17 06:34:48 +0000
commit711ed72b7967b6dc9cc0375a4e331aa24f7b2c0f (patch)
treee8ead01447aeef97668746ec0a317ad5fc381487 /ext/dl
parentf95348378770d8d0967690ae0de492a1444187a3 (diff)
* ext/dl/dl_conversions.c (rb_dl_type_to_ffi_type): support signed
long long. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26694 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl')
-rw-r--r--ext/dl/dl_conversions.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/ext/dl/dl_conversions.c b/ext/dl/dl_conversions.c
index 01d6218..1331006 100644
--- a/ext/dl/dl_conversions.c
+++ b/ext/dl/dl_conversions.c
@@ -1,38 +1,40 @@
#include <dl_conversions.h>
-ffi_type * rb_dl_type_to_ffi_type(int dl_type)
+ffi_type *
+rb_dl_type_to_ffi_type(int dl_type)
{
int signed_p = 1;
- if(dl_type < 0) {
+ if (dl_type < 0) {
dl_type = -1 * dl_type;
signed_p = 0;
}
- switch(dl_type) {
- case DLTYPE_VOID:
- return &ffi_type_void;
- case DLTYPE_VOIDP:
- return &ffi_type_pointer;
- case DLTYPE_CHAR:
- return signed_p ? &ffi_type_schar : &ffi_type_uchar;
- case DLTYPE_SHORT:
- return signed_p ? &ffi_type_sshort : &ffi_type_ushort;
- case DLTYPE_INT:
- return signed_p ? &ffi_type_sint : &ffi_type_uint;
- case DLTYPE_LONG:
- return signed_p ? &ffi_type_slong : &ffi_type_ulong;
+#define rb_ffi_type_of(t) (signed_p ? &ffi_type_s##t : &ffi_type_u##t)
+
+ switch (dl_type) {
+ case DLTYPE_VOID:
+ return &ffi_type_void;
+ case DLTYPE_VOIDP:
+ return &ffi_type_pointer;
+ case DLTYPE_CHAR:
+ return rb_ffi_type_of(char);
+ case DLTYPE_SHORT:
+ return rb_ffi_type_of(short);
+ case DLTYPE_INT:
+ return rb_ffi_type_of(int);
+ case DLTYPE_LONG:
+ return rb_ffi_type_of(long);
#if HAVE_LONG_LONG
- case DLTYPE_LONG_LONG:
- return &ffi_type_uint64;
- break;
+ case DLTYPE_LONG_LONG:
+ return rb_ffi_type_of(int64);
#endif
- case DLTYPE_FLOAT:
- return &ffi_type_float;
- case DLTYPE_DOUBLE:
- return &ffi_type_double;
- default:
- rb_raise(rb_eRuntimeError, "unknown type %d", dl_type);
+ case DLTYPE_FLOAT:
+ return &ffi_type_float;
+ case DLTYPE_DOUBLE:
+ return &ffi_type_double;
+ default:
+ rb_raise(rb_eRuntimeError, "unknown type %d", dl_type);
}
return &ffi_type_pointer;
}