diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-09-09 23:08:54 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-09-09 23:14:07 +0900 |
| commit | 9d9cb0ab6a052c658a861b33a48a16cb2fb5b655 (patch) | |
| tree | 795bc376fbebfaf41c22bde1507a79a2af401212 /src/variable.c | |
| parent | a1a838d96667131571cc10999ff33dcb79d62627 (diff) | |
| download | mruby-9d9cb0ab6a052c658a861b33a48a16cb2fb5b655.tar.gz mruby-9d9cb0ab6a052c658a861b33a48a16cb2fb5b655.zip | |
Fix `mod.constants` not to have duplicate constant names; #4698
The fix was based on PR from @dearblue
Diffstat (limited to 'src/variable.c')
| -rw-r--r-- | src/variable.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/variable.c b/src/variable.c index 32416da4e..06756a69f 100644 --- a/src/variable.c +++ b/src/variable.c @@ -882,7 +882,15 @@ const_i(mrb_state *mrb, mrb_sym sym, mrb_value v, void *p) ary = *(mrb_value*)p; s = mrb_sym2name_len(mrb, sym, &len); if (len >= 1 && ISUPPER(s[0])) { - mrb_ary_push(mrb, ary, mrb_symbol_value(sym)); + mrb_int i, alen = RARRAY_LEN(ary); + + for (i=0; i<alen; i++) { + if (mrb_symbol(RARRAY_PTR(ary)[i]) == sym) + break; + } + if (i==alen) { + mrb_ary_push(mrb, ary, mrb_symbol_value(sym)); + } } return 0; } |
