mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 13:04:13 +02:00
__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
This commit is contained in:
parent
630ab3b925
commit
f089a52865
5 changed files with 39 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue