Skip to content

Commit

Permalink
fix all consumers
Browse files Browse the repository at this point in the history
Signed-off-by: Pantelis Antoniou <[email protected]>
  • Loading branch information
pantoniou committed Jun 17, 2024
1 parent ce2b28e commit cc90956
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/tool/fy-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,6 @@ struct reflection_object {
void *instance_data;
void *data;
size_t data_size;
bool consumer;
};

#define REFLECTION_OBJECT_SKIP ((struct reflection_object *)(void *)(uintptr_t)-1)
Expand Down Expand Up @@ -4532,21 +4531,10 @@ static int ptr_doc_setup(struct reflection_object *ro, struct fy_parser *fyp, st
if (!id->fydb)
goto err_out;

fprintf(stderr, "created ptr_doc parser\n");

rc = reflection_object_consume_event(ro, fyp, fye, path);
if (rc < 0)
goto err_out;

fprintf(stderr, "reflection_object_consume_event() %d\n", rc);

if (rc == 0) {
/* need to consume more */
ro->consumer = true;
} else {
/* done */
}

return 0;
err_out:
ptr_doc_instance_data_cleanup(id);
Expand Down Expand Up @@ -5760,18 +5748,21 @@ reflection_compose_process_event(struct fy_parser *fyp, struct fy_event *fye, st
fy_path_get_text_alloca(path));
#endif

/* are we under the control of consumer? */
if (rd->ro_consumer && fye->type != FYET_NONE) {
rc = reflection_object_consume_event(rd->ro_consumer, fyp, fye, path);
if (rc < 0)
return FYCR_ERROR;
if (rc == 1) {
rc = reflection_decoder_destroy_object(rd, rd->ro_consumer, fyp, fye, path);
rd->ro_consumer = NULL;
if (rc)
return FYCR_ERROR;
rd->ro_consumer = NULL;
}
return FYCR_OK_CONTINUE;
}

/* collect the keys before proceeding */
if (fy_path_in_mapping_key(path))
return FYCR_OK_CONTINUE;

Expand All @@ -5789,7 +5780,6 @@ reflection_compose_process_event(struct fy_parser *fyp, struct fy_event *fye, st

/* if we're skiping, do an early check */
if (rd->skip_start) {

/* the skip ends at the end of one of those */
if ((fye->type == FYET_SEQUENCE_END || fye->type == FYET_MAPPING_END) &&
fy_path_last_component(path) == rd->skip_start)
Expand Down Expand Up @@ -5835,14 +5825,19 @@ reflection_compose_process_event(struct fy_parser *fyp, struct fy_event *fye, st
return FYCR_ERROR;

/* handle skip */
if (ro == REFLECTION_OBJECT_SKIP || ro->consumer) {
if (fye->type != FYET_SCALAR) {
if (ro == REFLECTION_OBJECT_SKIP) {
if (fye->type != FYET_SCALAR)
rd->skip_start = fy_path_last_component(path);
rd->ro_consumer = ro != REFLECTION_OBJECT_SKIP && ro->consumer ? ro : NULL;
}
return FYCR_OK_CONTINUE;
}

/* handle consuming collection */
if (fye->type != FYET_SCALAR && ro->rtd->ops->consume_event) {
rd->ro_consumer = ro;
return FYCR_OK_CONTINUE;
}

/* scalars are short lived */
if (fye->type == FYET_SCALAR) {
rc = reflection_decoder_destroy_object(rd, ro, fyp, fye, path);
if (rc)
Expand Down

0 comments on commit cc90956

Please sign in to comment.