Unverified Commit 3e0d29b7 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4279 from dearblue/fix-inline-packed-symbols

Fix destroyed "inline packed symbols" on 32 bit mode with `MRB_WORD_BOXING`
parents a3e8b750 5067a5cd
...@@ -160,6 +160,10 @@ typedef void mrb_value; ...@@ -160,6 +160,10 @@ typedef void mrb_value;
#ifndef mrb_bool #ifndef mrb_bool
#define mrb_bool(o) (mrb_type(o) != MRB_TT_FALSE) #define mrb_bool(o) (mrb_type(o) != MRB_TT_FALSE)
#endif #endif
#if !defined(MRB_SYMBOL_BITSIZE)
#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT)
#define MRB_SYMBOL_MAX UINT32_MAX
#endif
#ifndef MRB_WITHOUT_FLOAT #ifndef MRB_WITHOUT_FLOAT
#define mrb_float_p(o) (mrb_type(o) == MRB_TT_FLOAT) #define mrb_float_p(o) (mrb_type(o) == MRB_TT_FLOAT)
#endif #endif
......
...@@ -34,13 +34,16 @@ static const char pack_table[] = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS ...@@ -34,13 +34,16 @@ static const char pack_table[] = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS
static mrb_sym static mrb_sym
sym_inline_pack(const char *name, uint16_t len) sym_inline_pack(const char *name, uint16_t len)
{ {
const int lower_length_max = (MRB_SYMBOL_BITSIZE - 2) / 5;
const int mix_length_max = (MRB_SYMBOL_BITSIZE - 2) / 6;
char c; char c;
const char *p; const char *p;
int i; int i;
mrb_sym sym = 0; mrb_sym sym = 0;
int lower = 1; int lower = 1;
if (len > 6) return 0; /* too long */ if (len > lower_length_max) return 0; /* too long */
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
uint32_t bits; uint32_t bits;
...@@ -64,7 +67,7 @@ sym_inline_pack(const char *name, uint16_t len) ...@@ -64,7 +67,7 @@ sym_inline_pack(const char *name, uint16_t len)
} }
return sym | 3; return sym | 3;
} }
if (len == 6) return 0; if (len > mix_length_max) return 0;
return sym | 1; return sym | 1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment