Make embedded string length a long for VWA

A short (2 bytes) will cause unaligned struct accesses when strings are
used as a buffer to directly store binary data.
This commit is contained in:
Peter Zhu 2022-01-11 15:19:39 -05:00
parent e28dbd0f3d
commit 2d81a718ec
Notes: git 2022-01-13 02:01:32 +09:00
2 changed files with 2 additions and 2 deletions

View File

@ -280,7 +280,7 @@ struct RString {
/** Embedded contents. */ /** Embedded contents. */
struct { struct {
#if USE_RVARGC #if USE_RVARGC
unsigned short len; long len;
/* This is a length 1 array because: /* This is a length 1 array because:
* 1. GCC has a bug that does not optimize C flexible array members * 1. GCC has a bug that does not optimize C flexible array members
* (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102452) * (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102452)

View File

@ -66,7 +66,7 @@ class Test_StringCapacity < Test::Unit::TestCase
def embed_header_size def embed_header_size
if GC.using_rvargc? if GC.using_rvargc?
2 * RbConfig::SIZEOF['void*'] + RbConfig::SIZEOF['short'] 2 * RbConfig::SIZEOF['void*'] + RbConfig::SIZEOF['long']
else else
2 * RbConfig::SIZEOF['void*'] 2 * RbConfig::SIZEOF['void*']
end end