Actions
Bug #18387
closedBackport of fix for #16798 to Ruby 2.6 introduced C99 syntax
Description
Building Ruby 2.6.9 on OpenBSD/sparc64 fails with the following error:
cc -O2 -pipe -fPIC -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -DCANONICALIZATION_FOR_MATHN -DOPENSSL_NO_STATIC_ENGINE -I/usr/local/include -I. -I.ext/include/sparc64-openbsd -I./include -I. -I./enc/unicode/12.1.0 -o hash.o -c hash.c
hash.c: In function 'keylist_delete':
hash.c:5661: error: 'for' loop initial declaration used outside C99 mode
The system compiler in this case is gcc 4.2.1, which defaults to C89/C90. I believe Ruby didn't switch to C99 until Ruby 2.7, so I think this is a bug that should be fixed in the next release of Ruby 2.6.
This issue was introduced by fe85a3d5271c4e3aeda42ec32e9c3f9ee02b6897, a backport of 08529a61153e5c40f57a65272211357511d6e6db.
This patch should hopefully fix it (untested):
diff --git a/hash.c b/hash.c
index 38440f4b96..65a0419af3 100644
--- a/hash.c
+++ b/hash.c
@@ -5655,10 +5655,10 @@ env_invert(void)
static void
keylist_delete(VALUE keys, VALUE key)
{
- long keylen, elen;
+ long keylen, elen, i;
const char *keyptr, *eptr;
RSTRING_GETMEM(key, keyptr, keylen);
- for (long i=0; i<RARRAY_LEN(keys); i++) {
+ for (i=0; i<RARRAY_LEN(keys); i++) {
VALUE e = RARRAY_AREF(keys, i);
RSTRING_GETMEM(e, eptr, elen);
if (elen != keylen) continue;
I'm not sure if this is the only C99 issue introduced in Ruby 2.6.9, so other changes between 2.6.8 and 2.6.9 should be audited to ensure they do not introduce C99 syntax.
Updated by usa (Usaku NAKAMURA) over 3 years ago
it's unintentionally, so I'll fix it later. thx!
Updated by usa (Usaku NAKAMURA) about 3 years ago
- Backport changed from 2.6: REQUIRED, 2.7: DONTNEED, 3.0: DONTNEED to 2.6: DONE, 2.7: DONTNEED, 3.0: DONTNEED
Actions
Like0
Like0Like0