aboutsummaryrefslogtreecommitdiffstats
path: root/id_table.c
diff options
context:
space:
mode:
authorngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-20 14:55:23 +0000
committerngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-20 14:55:23 +0000
commit7f6f4b22bbfc398c67b19e27bdb6ed1a57f91209 (patch)
treeefc49b1d988f1dab52d0c32af677043a3705ccb5 /id_table.c
parentbbc0c7289d21046bc2b7ab88f6ceae12ba8d306f (diff)
downloadruby-7f6f4b22bbfc398c67b19e27bdb6ed1a57f91209.tar.gz
capa should be even number on 64-bit SPARC for 8-byte word alignment
* id_table.c (list_id_table_init): When unaligned word access is prohibited and sizeof(VALUE) is 8 (64-bit machines), capa should always be even number for 8-byte word alignment of the values of a table. This code assumes that sizeof(ID) is 4, sizeof(VALUE) is 8, and xmalloc() returns 8-byte aligned memory. This fixes bus error on 64-bit SPARC Solaris 10. [Bug #12406][ruby-dev:49631] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'id_table.c')
-rw-r--r--id_table.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/id_table.c b/id_table.c
index 324abf15f1..b8111aa86c 100644
--- a/id_table.c
+++ b/id_table.c
@@ -379,6 +379,14 @@ static struct list_id_table *
list_id_table_init(struct list_id_table *tbl, size_t capa)
{
if (capa > 0) {
+#if ID_TABLE_USE_CALC_VALUES && \
+ (UNALIGNED_WORD_ACCESS == 0) && (SIZEOF_VALUE == 8)
+ /* Workaround for 8-byte word alignment on 64-bit SPARC.
+ * This code assumes that sizeof(ID) == 4, sizeof(VALUE) == 8, and
+ * xmalloc() returns 8-byte aligned memory block.
+ */
+ if (capa & (size_t)1) capa += 1;
+#endif
tbl->capa = (int)capa;
#if ID_TABLE_USE_CALC_VALUES
tbl->keys = (id_key_t *)xmalloc(sizeof(id_key_t) * capa + sizeof(VALUE) * capa);