1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Fix some confusion between "null" and "invalid".

This commit is contained in:
Stephen Dolan
2012-09-03 17:26:52 +01:00
parent 32e324a283
commit 520c7bb15e
5 changed files with 10 additions and 9 deletions

View File

@@ -22,7 +22,6 @@ typedef struct {
jv* pathbuf;
int pathsize; // number of allocated elements
// FIXME mem
int path_push(stackval sv, jv val) {
int pos = sv.pathidx;
assert(pos <= pathsize);
@@ -32,7 +31,7 @@ int path_push(stackval sv, jv val) {
pathsize = oldpathsize ? oldpathsize * 2 : 100;
pathbuf = realloc(pathbuf, sizeof(pathbuf[0]) * pathsize);
for (int i=oldpathsize; i<pathsize; i++) {
pathbuf[i] = jv_null();
pathbuf[i] = jv_invalid();
}
}
jv_free(pathbuf[pos]);
@@ -179,7 +178,7 @@ jv jq_next() {
case LOADK: {
jv v = jv_array_get(jv_copy(frame_current_bytecode(&frame_stk)->constants), *pc++);
//FIXME assert(v);
assert(jv_is_valid(v));
stack_push(stackval_replace(stack_pop(), v));
break;
}

View File

@@ -88,7 +88,7 @@ static frame_ptr frame_push(struct forkable_stack* stk, struct closure cl, uint1
cc->retaddr = retaddr;
cc->is_backtrack_frame = 0;
for (int i=0; i<cl.bc->nlocals; i++) {
*frame_local_var(fp, i) = jv_null();
*frame_local_var(fp, i) = jv_invalid();
}
return fp;
}

4
c/jv.c
View File

@@ -619,7 +619,7 @@ static jv* jvp_object_write(jv_complex* object, jvp_string* key) {
jvp_string_free_p(key);
} else {
slot = jvp_object_add_slot(object, key, bucket);
slot->value = jv_null();
slot->value = jv_invalid();
}
if (slot == 0) {
jvp_object_rehash(object);
@@ -627,7 +627,7 @@ static jv* jvp_object_write(jv_complex* object, jvp_string* key) {
assert(!jvp_object_find_slot(object, key, bucket));
slot = jvp_object_add_slot(object, key, bucket);
assert(slot);
slot->value = jv_null();
slot->value = jv_invalid();
}
return &slot->value;
}

View File

@@ -18,7 +18,7 @@ void jv_parser_init(struct jv_parser* p) {
p->stack = 0;
p->stacklen = p->stackpos = 0;
p->hasnext = 0;
p->next = jv_null(); //FIXME: jv_invalid
p->next = jv_invalid(); //FIXME: jv_invalid
p->tokenbuf = 0;
p->tokenlen = p->tokenpos = 0;
p->st = JV_PARSER_NORMAL;
@@ -357,13 +357,13 @@ jv jv_parse_sized(const char* string, int length) {
presult msg = scan(&parser, ch);
if (msg){
printf("ERROR: %s (parsing '%s')\n", msg, string);
return jv_null();
return jv_invalid();
}
}
presult msg = finish(&parser);
if (msg) {
printf("ERROR: %s (parsing '%s')\n", msg, string);
return jv_null();
return jv_invalid();
}
jv value = jv_copy(parser.next);
jv_parser_free(&parser);

View File

@@ -40,11 +40,13 @@ void run_tests() {
printf("\n");
fgets(buf, sizeof(buf), testdata);
jv input = jv_parse(buf);
assert(jv_is_valid(input));
jq_init(bc, input);
while (fgets(buf, sizeof(buf), testdata)) {
if (skipline(buf)) break;
jv expected = jv_parse(buf);
assert(jv_is_valid(expected));
jv actual = jq_next();
if (!jv_is_valid(actual)) {
printf("Insufficient results\n");