From f089a52865bd82a327fe9ef460cecdb812dcb56c Mon Sep 17 00:00:00 2001 From: shyouhei Date: Mon, 15 Jan 2018 02:35:16 +0000 Subject: __attibute__((__aligned__)) for RSTRING_PTR() For instance array.c:rb_ary_product() uses RSTRING_PTR() as an array of int. So to avoid misaligned memory access RSTRING_PTR() must at least be sizeof(int)-aligned. However the type of RSTRING_PTR() is char*, which of course can expect alignment as much as 1. This is a problem. The reality is, there is no misaligned memory access because the memory region behind RSTRING_PTR() is allocated using malloc(). Memory regions returned from malloc() are always aligned appropriately. So let's tell the compiler about this information. It seems GCC, clang, and MSVC have such feature. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- win32/Makefile.sub | 1 + 1 file changed, 1 insertion(+) (limited to 'win32') diff --git a/win32/Makefile.sub b/win32/Makefile.sub index 944573f1bb..a3ac277dd2 100644 --- a/win32/Makefile.sub +++ b/win32/Makefile.sub @@ -636,6 +636,7 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub #define PACKED_STRUCT_UNALIGNED(x) x !endif #define RUBY_EXTERN extern __declspec(dllimport) +#define RUBY_ALIGNAS(n) __declspec(align(n)) #define HAVE_DECL_SYS_NERR 1 #define HAVE_LIMITS_H 1 #define HAVE_FCNTL_H 1 -- cgit v1.2.3