__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:
shyouhei 2018-01-15 02:35:16 +00:00
parent 630ab3b925
commit f089a52865
5 changed files with 39 additions and 11 deletions

View file

@ -8077,7 +8077,7 @@ struct ibf_dump {
rb_iseq_t * iseq_alloc(void);
struct ibf_load {
const char *buff;
const RUBY_ALIGNAS(sizeof(VALUE)) char *buff;
const struct ibf_header *header;
ID *id_list; /* [id0, ...] */
VALUE iseq_list; /* [iseq0, ...] */