summaryrefslogtreecommitdiff
path: root/ext/dl/dl.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-25 05:47:16 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-25 05:47:16 +0000
commitb4288080e7d025729f88479c44ed054f65b30f60 (patch)
tree2f77c1a499dd3a53e17e22f99de797f6a5e9afb9 /ext/dl/dl.c
parentd9adb03dd902c1cf7e5fadc8320dccec0ef73139 (diff)
* ext/dl/dl.c (Init_dl): support intrinsic types, size_t, ptrdiff_t
and intptr_t. [ruby-core:42460][Feature #5992] * ext/fiddle/fiddle.c (Init_fiddle): ditto. * ext/dl/lib/dl/cparser.rb (DL::CParser#parse_ctype): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34800 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/dl.c')
-rw-r--r--ext/dl/dl.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/ext/dl/dl.c b/ext/dl/dl.c
index 200c1d6dab2..cd4e0c1030a 100644
--- a/ext/dl/dl.c
+++ b/ext/dl/dl.c
@@ -17,6 +17,38 @@ VALUE rb_eDLTypeError;
ID rbdl_id_cdecl;
ID rbdl_id_stdcall;
+#ifndef DLTYPE_SSIZE_T
+# if SIZEOF_SIZE_T == SIZEOF_INT
+# define DLTYPE_SSIZE_T DLTYPE_INT
+# elif SIZEOF_SIZE_T == SIZEOF_LONG
+# define DLTYPE_SSIZE_T DLTYPE_LONG
+# elif defined HAVE_LONG_LONG && SIZEOF_SIZE_T == SIZEOF_LONG_LONG
+# define DLTYPE_SSIZE_T DLTYPE_LONG_LONG
+# endif
+#endif
+#define DLTYPE_SIZE_T (-1*SIGNEDNESS_OF_SIZE_T*DLTYPE_SSIZE_T)
+
+#ifndef DLTYPE_PTRDIFF_T
+# if SIZEOF_PTRDIFF_T == SIZEOF_INT
+# define DLTYPE_PTRDIFF_T DLTYPE_INT
+# elif SIZEOF_PTRDIFF_T == SIZEOF_LONG
+# define DLTYPE_PTRDIFF_T DLTYPE_LONG
+# elif defined HAVE_LONG_LONG && SIZEOF_PTRDIFF_T == SIZEOF_LONG_LONG
+# define DLTYPE_PTRDIFF_T DLTYPE_LONG_LONG
+# endif
+#endif
+
+#ifndef DLTYPE_INTPTR_T
+# if SIZEOF_INTPTR_T == SIZEOF_INT
+# define DLTYPE_INTPTR_T DLTYPE_INT
+# elif SIZEOF_INTPTR_T == SIZEOF_LONG
+# define DLTYPE_INTPTR_T DLTYPE_LONG
+# elif defined HAVE_LONG_LONG && SIZEOF_INTPTR_T == SIZEOF_LONG_LONG
+# define DLTYPE_INTPTR_T DLTYPE_LONG_LONG
+# endif
+#endif
+#define DLTYPE_UINTPTR_T (-DLTYPE_INTPTR_T)
+
VALUE
rb_dl_dlopen(int argc, VALUE argv[], VALUE self)
{
@@ -271,6 +303,36 @@ Init_dl(void)
*/
rb_define_const(rb_mDL, "TYPE_DOUBLE", INT2NUM(DLTYPE_DOUBLE));
+ /* Document-const: TYPE_SIZE_T
+ *
+ * DL::CFunc type - size_t
+ */
+ rb_define_const(rb_mDL, "TYPE_SIZE_T", INT2NUM(DLTYPE_SIZE_T));
+
+ /* Document-const: TYPE_SSIZE_T
+ *
+ * DL::CFunc type - ssize_t
+ */
+ rb_define_const(rb_mDL, "TYPE_SSIZE_T", INT2NUM(DLTYPE_SSIZE_T));
+
+ /* Document-const: TYPE_PTRDIFF_T
+ *
+ * DL::CFunc type - ptrdiff_t
+ */
+ rb_define_const(rb_mDL, "TYPE_PTRDIFF_T", INT2NUM(DLTYPE_PTRDIFF_T));
+
+ /* Document-const: TYPE_INTPTR_T
+ *
+ * DL::CFunc type - intptr_t
+ */
+ rb_define_const(rb_mDL, "TYPE_INTPTR_T", INT2NUM(DLTYPE_INTPTR_T));
+
+ /* Document-const: TYPE_UINTPTR_T
+ *
+ * DL::CFunc type - uintptr_t
+ */
+ rb_define_const(rb_mDL, "TYPE_UINTPTR_T", INT2NUM(DLTYPE_UINTPTR_T));
+
/* Document-const: ALIGN_VOIDP
*
* The alignment size of a void*
@@ -321,6 +383,36 @@ Init_dl(void)
*/
rb_define_const(rb_mDL, "ALIGN_DOUBLE",INT2NUM(ALIGN_DOUBLE));
+ /* Document-const: ALIGN_SIZE_T
+ *
+ * The alignment size of a size_t
+ */
+ rb_define_const(rb_mDL, "ALIGN_SIZE_T", INT2NUM(ALIGN_OF(size_t)));
+
+ /* Document-const: ALIGN_SSIZE_T
+ *
+ * The alignment size of a ssize_t
+ */
+ rb_define_const(rb_mDL, "ALIGN_SSIZE_T", INT2NUM(ALIGN_OF(size_t))); /* same as size_t */
+
+ /* Document-const: ALIGN_PTRDIFF_T
+ *
+ * The alignment size of a ptrdiff_t
+ */
+ rb_define_const(rb_mDL, "ALIGN_PTRDIFF_T", INT2NUM(ALIGN_OF(ptrdiff_t)));
+
+ /* Document-const: ALIGN_INTPTR_T
+ *
+ * The alignment size of a intptr_t
+ */
+ rb_define_const(rb_mDL, "ALIGN_INTPTR_T", INT2NUM(ALIGN_OF(intptr_t)));
+
+ /* Document-const: ALIGN_UINTPTR_T
+ *
+ * The alignment size of a uintptr_t
+ */
+ rb_define_const(rb_mDL, "ALIGN_UINTPTR_T", INT2NUM(ALIGN_OF(uintptr_t)));
+
/* Document-const: SIZEOF_VOIDP
*
* size of a void*
@@ -371,6 +463,36 @@ Init_dl(void)
*/
rb_define_const(rb_mDL, "SIZEOF_DOUBLE",INT2NUM(sizeof(double)));
+ /* Document-const: SIZEOF_SIZE_T
+ *
+ * size of a size_t
+ */
+ rb_define_const(rb_mDL, "SIZEOF_SIZE_T", INT2NUM(sizeof(size_t)));
+
+ /* Document-const: SIZEOF_SSIZE_T
+ *
+ * size of a ssize_t
+ */
+ rb_define_const(rb_mDL, "SIZEOF_SSIZE_T", INT2NUM(sizeof(size_t))); /* same as size_t */
+
+ /* Document-const: SIZEOF_PTRDIFF_T
+ *
+ * size of a ptrdiff_t
+ */
+ rb_define_const(rb_mDL, "SIZEOF_PTRDIFF_T", INT2NUM(sizeof(ptrdiff_t)));
+
+ /* Document-const: SIZEOF_INTPTR_T
+ *
+ * size of a intptr_t
+ */
+ rb_define_const(rb_mDL, "SIZEOF_INTPTR_T", INT2NUM(sizeof(intptr_t)));
+
+ /* Document-const: SIZEOF_UINTPTR_T
+ *
+ * size of a intptr_t
+ */
+ rb_define_const(rb_mDL, "SIZEOF_UINTPTR_T", INT2NUM(sizeof(uintptr_t)));
+
rb_define_module_function(rb_mDL, "dlwrap", rb_dl_value2ptr, 1);
rb_define_module_function(rb_mDL, "dlunwrap", rb_dl_ptr2value, 1);