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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
4
c/jv.c
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
2
c/main.c
2
c/main.c
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user