summaryrefslogtreecommitdiff
path: root/ext/dl
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-09 16:30:43 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-09 16:30:43 +0000
commit96ab37015ecb57a65c80f4ae92dcf241dacb161e (patch)
tree3a5db3872104d7b3e0fb37e314ad33035193f569 /ext/dl
parent196151158fa777dc88fa54825250898ff1ab5410 (diff)
* ext/dl/dl.h (ALIGN_OF): use offsetof().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl')
-rw-r--r--ext/dl/dl.h26
1 files changed, 9 insertions, 17 deletions
diff --git a/ext/dl/dl.h b/ext/dl/dl.h
index d0a461f..07adbbf 100644
--- a/ext/dl/dl.h
+++ b/ext/dl/dl.h
@@ -134,26 +134,18 @@ extern VALUE rb_cDLSymbol;
extern VALUE rb_eDLError;
extern VALUE rb_eDLTypeError;
-typedef struct { char c; void *x; } s_voidp;
-typedef struct { char c; short x; } s_short;
-typedef struct { char c; int x; } s_int;
-typedef struct { char c; long x; } s_long;
-typedef struct { char c; float x; } s_float;
-typedef struct { char c; double x; } s_double;
-#if HAVE_LONG_LONG
-typedef struct { char c; LONG_LONG x; } s_long_long;
-#endif
+#define ALIGN_OF(type) offsetof(struct {char align_c; type align_x;}, align_x)
-#define ALIGN_VOIDP (sizeof(s_voidp) - sizeof(void *))
-#define ALIGN_SHORT (sizeof(s_short) - sizeof(short))
-#define ALIGN_CHAR (1)
-#define ALIGN_INT (sizeof(s_int) - sizeof(int))
-#define ALIGN_LONG (sizeof(s_long) - sizeof(long))
+#define ALIGN_VOIDP ALIGN_OF(void*)
+#define ALIGN_SHORT ALIGN_OF(short)
+#define ALIGN_CHAR ALIGN_OF(char)
+#define ALIGN_INT ALIGN_OF(int)
+#define ALIGN_LONG ALIGN_OF(long)
#if HAVE_LONG_LONG
-#define ALIGN_LONG_LONG (sizeof(s_long_long) - sizeof(LONG_LONG))
+#define ALIGN_LONG_LONG ALIGN_OF(LONG_LONG)
#endif
-#define ALIGN_FLOAT (sizeof(s_float) - sizeof(float))
-#define ALIGN_DOUBLE (sizeof(s_double) - sizeof(double))
+#define ALIGN_FLOAT ALIGN_OF(float)
+#define ALIGN_DOUBLE ALIGN_OF(double)
#define DLALIGN(ptr,offset,align) \
((offset) += ((align) - ((uintptr_t)((char *)(ptr) + (offset))) % (align)) % (align))