[ruby-cvs:69008] shyouhei:r61827 (trunk): __attibute__((__aligned__)) for RSTRING_PTR()

shyouhei at ruby-lang.org shyouhei at ruby-lang.org
Mon Jan 15 11:35:16 JST 2018


shyouhei	2018-01-15 11:35:16 +0900 (Mon, 15 Jan 2018)

  New Revision: 61827

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61827

  Log:
    __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.

  Modified files:
    trunk/compile.c
    trunk/configure.ac
    trunk/include/ruby/defines.h
    trunk/include/ruby/ruby.h
    trunk/win32/Makefile.sub


More information about the ruby-cvs mailing list