By now, all "struct expr_ops" have a json() hook set. Thus, drop handling the possibility that they might not. From now on, it's a bug to create a ops without the hook. It's not clear what the code tried to do. It bothered to implement a fallback via fmemopen(), but apparently that fallback is no considered a good solution as it also printed a "warning". Either the fallback is good and does not warrant a warning. Or the condition is to be avoided to begin with, which we should do by testing the expr_ops structures. As the fallback path has an overhead to create the memory stream, the fallback path is indeed not great. That is the reason to outlaw a missing json() hook, to require that all hooks are present, and to drop the fallback path. A missing hook is very easy to cover with unit tests. Such a test shall be added soon. Signed-off-by: Thomas Haller <thaller@xxxxxxxxxx> --- src/json.c | 40 ++-------------------------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/src/json.c b/src/json.c index 0fd78b763af7..cbd2abbc8b52 100644 --- a/src/json.c +++ b/src/json.c @@ -44,26 +44,7 @@ static json_t *expr_print_json(const struct expr *expr, struct output_ctx *octx) { - const struct expr_ops *ops; - char buf[1024]; - FILE *fp; - - ops = expr_ops(expr); - if (ops->json) - return ops->json(expr, octx); - - fprintf(stderr, "warning: expr ops %s have no json callback\n", - expr_name(expr)); - - fp = octx->output_fp; - octx->output_fp = fmemopen(buf, 1024, "w"); - - ops->print(expr, octx); - - fclose(octx->output_fp); - octx->output_fp = fp; - - return json_pack("s", buf); + return expr_ops(expr)->json(expr, octx); } static json_t *set_dtype_json(const struct expr *key) @@ -89,24 +70,7 @@ static json_t *set_dtype_json(const struct expr *key) static json_t *stmt_print_json(const struct stmt *stmt, struct output_ctx *octx) { - char buf[1024]; - FILE *fp; - - if (stmt->ops->json) - return stmt->ops->json(stmt, octx); - - fprintf(stderr, "warning: stmt ops %s have no json callback\n", - stmt->ops->name); - - fp = octx->output_fp; - octx->output_fp = fmemopen(buf, 1024, "w"); - - stmt->ops->print(stmt, octx); - - fclose(octx->output_fp); - octx->output_fp = fp; - - return json_pack("s", buf); + return stmt->ops->json(stmt, octx); } static json_t *set_stmt_list_json(const struct list_head *stmt_list, -- 2.41.0