Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make code compatible with C90 #692

Merged
merged 1 commit into from Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions ext/oj/cache.c
Expand Up @@ -129,7 +129,9 @@ static void rehash(Cache c) {
}

void cache_free(Cache c) {
for (uint32_t i = 0; i < c->size; i++) {
uint32_t i;

for (i = 0; i < c->size; i++) {
Slot next;
Slot s;

Expand All @@ -147,7 +149,8 @@ void cache_mark(Cache c) {
uint32_t i;

for (i = 0; i < c->size; i++) {
for (Slot s = c->slots[i]; NULL != s; s = s->next) {
Slot s;
for (s = c->slots[i]; NULL != s; s = s->next) {
rb_gc_mark(s->val);
}
}
Expand Down
3 changes: 2 additions & 1 deletion ext/oj/debug.c
Expand Up @@ -109,8 +109,9 @@ static void mark(struct _ojParser *p) {

void oj_set_parser_debug(ojParser p) {
Funcs end = p->funcs + 3;
Funcs f;

for (Funcs f = p->funcs; f < end; f++) {
for (f = p->funcs; f < end; f++) {
f->add_null = add_null;
f->add_true = add_true;
f->add_false = add_false;
Expand Down
11 changes: 6 additions & 5 deletions ext/oj/parser.c
Expand Up @@ -622,14 +622,14 @@ static void big_change(ojParser p) {
buf_append_string(&p->buf, buf + len + 1, sizeof(buf) - len - 1);
if (0 < p->num.exp) {
int x = p->num.exp;
int d;
int d, div;
bool started = false;

buf_append(&p->buf, 'e');
if (0 < p->num.exp_neg) {
buf_append(&p->buf, '-');
}
for (int div = 1000; 0 < div; div /= 10) {
for (div = 1000; 0 < div; div /= 10) {
d = x / div % 10;
if (started || 0 < d) {
buf_append(&p->buf, '0' + d);
Expand All @@ -646,6 +646,7 @@ static void big_change(ojParser p) {
static void parse(ojParser p, const byte *json) {
const byte *start;
const byte *b = json;
int i;

#if DEBUG
printf("*** parse - mode: %c %s\n", p->map[256], (const char *)json);
Expand Down Expand Up @@ -1015,7 +1016,7 @@ static void parse(ojParser p, const byte *json) {
}
p->ri = 0;
*p->token = *b++;
for (int i = 1; i < 4; i++) {
for (i = 1; i < 4; i++) {
if ('\0' == *b) {
p->ri = i;
break;
Expand All @@ -1040,7 +1041,7 @@ static void parse(ojParser p, const byte *json) {
}
p->ri = 0;
*p->token = *b++;
for (int i = 1; i < 4; i++) {
for (i = 1; i < 4; i++) {
if ('\0' == *b) {
p->ri = i;
break;
Expand All @@ -1065,7 +1066,7 @@ static void parse(ojParser p, const byte *json) {
}
p->ri = 0;
*p->token = *b++;
for (int i = 1; i < 5; i++) {
for (i = 1; i < 5; i++) {
if ('\0' == *b) {
p->ri = i;
break;
Expand Down
6 changes: 4 additions & 2 deletions ext/oj/saj2.c
Expand Up @@ -182,8 +182,9 @@ static void add_str_key(ojParser p) {

static void reset(ojParser p) {
Funcs end = p->funcs + 3;
Funcs f;

for (Funcs f = p->funcs; f < end; f++) {
for (f = p->funcs; f < end; f++) {
f->add_null = noop;
f->add_true = noop;
f->add_false = noop;
Expand Down Expand Up @@ -312,13 +313,14 @@ static void mark(ojParser p) {
return;
}
Delegate d = (Delegate)p->ctx;
VALUE *kp;

cache_mark(d->str_cache);
if (Qnil != d->handler) {
rb_gc_mark(d->handler);
}
if (!d->cache_keys) {
for (VALUE *kp = d->keys; kp < d->tail; kp++) {
for (kp = d->keys; kp < d->tail; kp++) {
rb_gc_mark(*kp);
}
}
Expand Down
30 changes: 18 additions & 12 deletions ext/oj/usual.c
Expand Up @@ -323,6 +323,7 @@ static void open_array_key(ojParser p) {
}

static void close_object(ojParser p) {
VALUE *vp;
Delegate d = (Delegate)p->ctx;

d->ctail--;
Expand All @@ -333,15 +334,15 @@ static void close_object(ojParser p) {
volatile VALUE obj = rb_hash_new();

#if HAVE_RB_HASH_BULK_INSERT
for (VALUE *vp = head; kp < d->ktail; kp++, vp += 2) {
for (vp = head; kp < d->ktail; kp++, vp += 2) {
*vp = d->get_key(p, kp);
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
xfree(kp->key);
}
}
rb_hash_bulk_insert(d->vtail - head, head, obj);
#else
for (VALUE *vp = head; kp < d->ktail; kp++, vp += 2) {
for (vp = head; kp < d->ktail; kp++, vp += 2) {
rb_hash_aset(obj, d->get_key(p, kp), *(vp + 1));
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
xfree(kp->key);
Expand All @@ -355,6 +356,7 @@ static void close_object(ojParser p) {
}

static void close_object_class(ojParser p) {
VALUE *vp;
Delegate d = (Delegate)p->ctx;

d->ctail--;
Expand All @@ -364,7 +366,7 @@ static void close_object_class(ojParser p) {
VALUE * head = d->vhead + c->vi + 1;
volatile VALUE obj = rb_class_new_instance(0, NULL, d->hash_class);

for (VALUE *vp = head; kp < d->ktail; kp++, vp += 2) {
for (vp = head; kp < d->ktail; kp++, vp += 2) {
rb_funcall(obj, hset_id, 2, d->get_key(p, kp), *(vp + 1));
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
xfree(kp->key);
Expand All @@ -377,6 +379,7 @@ static void close_object_class(ojParser p) {
}

static void close_object_create(ojParser p) {
VALUE *vp;
Delegate d = (Delegate)p->ctx;

d->ctail--;
Expand All @@ -391,15 +394,15 @@ static void close_object_create(ojParser p) {
if (Qnil == d->hash_class) {
obj = rb_hash_new();
#if HAVE_RB_HASH_BULK_INSERT
for (VALUE *vp = head; kp < d->ktail; kp++, vp += 2) {
for (vp = head; kp < d->ktail; kp++, vp += 2) {
*vp = d->get_key(p, kp);
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
xfree(kp->key);
}
}
rb_hash_bulk_insert(d->vtail - head, head, obj);
#else
for (VALUE *vp = head; kp < d->ktail; kp++, vp += 2) {
for (vp = head; kp < d->ktail; kp++, vp += 2) {
rb_hash_aset(obj, d->get_key(p, kp), *(vp + 1));
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
xfree(kp->key);
Expand All @@ -408,7 +411,7 @@ static void close_object_create(ojParser p) {
#endif
} else {
obj = rb_class_new_instance(0, NULL, d->hash_class);
for (VALUE *vp = head; kp < d->ktail; kp++, vp += 2) {
for (vp = head; kp < d->ktail; kp++, vp += 2) {
rb_funcall(obj, hset_id, 2, d->get_key(p, kp), *(vp + 1));
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
xfree(kp->key);
Expand All @@ -423,15 +426,15 @@ static void close_object_create(ojParser p) {
volatile VALUE arg = rb_hash_new();

#if HAVE_RB_HASH_BULK_INSERT
for (VALUE *vp = head; kp < d->ktail; kp++, vp += 2) {
for (vp = head; kp < d->ktail; kp++, vp += 2) {
*vp = d->get_key(p, kp);
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
xfree(kp->key);
}
}
rb_hash_bulk_insert(d->vtail - head, head, arg);
#else
for (VALUE *vp = head; kp < d->ktail; kp++, vp += 2) {
for (vp = head; kp < d->ktail; kp++, vp += 2) {
rb_hash_aset(arg, d->get_key(p, kp), *(vp + 1));
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
xfree(kp->key);
Expand All @@ -441,7 +444,7 @@ static void close_object_create(ojParser p) {
obj = rb_funcall(clas, oj_json_create_id, 1, arg);
} else {
obj = rb_class_new_instance(0, NULL, clas);
for (VALUE *vp = head; kp < d->ktail; kp++, vp += 2) {
for (vp = head; kp < d->ktail; kp++, vp += 2) {
rb_ivar_set(obj, get_attr_id(p, kp), *(vp + 1));
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
xfree(kp->key);
Expand All @@ -468,13 +471,14 @@ static void close_array(ojParser p) {
}

static void close_array_class(ojParser p) {
VALUE *vp;
Delegate d = (Delegate)p->ctx;

d->ctail--;
VALUE * head = d->vhead + d->ctail->vi + 1;
volatile VALUE a = rb_class_new_instance(0, NULL, d->array_class);

for (VALUE *vp = head; vp < d->vtail; vp++) {
for (vp = head; vp < d->vtail; vp++) {
rb_funcall(a, ltlt_id, 1, *vp);
}
d->vtail = head;
Expand Down Expand Up @@ -682,6 +686,7 @@ static void mark(ojParser p) {
return;
}
Delegate d = (Delegate)p->ctx;
VALUE *vp;

if (NULL == d) {
return;
Expand All @@ -693,7 +698,7 @@ static void mark(ojParser p) {
if (NULL != d->class_cache) {
cache_mark(d->class_cache);
}
for (VALUE *vp = d->vhead; vp < d->vtail; vp++) {
for (vp = d->vhead; vp < d->vtail; vp++) {
if (Qundef != *vp) {
rb_gc_mark(*vp);
}
Expand Down Expand Up @@ -1091,6 +1096,7 @@ static VALUE opt_symbol_keys_set(ojParser p, VALUE value) {
}

static VALUE option(ojParser p, const char *key, VALUE value) {
struct opt *op;
struct opt opts[] = {
{.name = "array_class", .func = opt_array_class},
{.name = "array_class=", .func = opt_array_class_set},
Expand Down Expand Up @@ -1119,7 +1125,7 @@ static VALUE option(ojParser p, const char *key, VALUE value) {
{.name = NULL},
};

for (struct opt *op = opts; NULL != op->name; op++) {
for (op = opts; NULL != op->name; op++) {
if (0 == strcmp(key, op->name)) {
return op->func(p, value);
}
Expand Down
3 changes: 2 additions & 1 deletion ext/oj/validate.c
Expand Up @@ -28,8 +28,9 @@ mark(ojParser p) {
void oj_set_parser_validator(ojParser p) {
p->ctx = NULL;
Funcs end = p->funcs + 3;
Funcs f;

for (Funcs f = p->funcs; f < end; f++) {
for (f = p->funcs; f < end; f++) {
f->add_null = noop;
f->add_true = noop;
f->add_false = noop;
Expand Down