+2025-10-03 Niels Möller <nisse@lysator.liu.se>
+
+ * tools/output.c (sexp_output_init): Add hash argument, allocate
+ context if non-null.
+ (sexp_output_hash_init): Deleted function.
+ * tools/sexp-conv.c (main): Update call to sexp_output_init. Free
+ context before exiting.
+
2025-10-02 Niels Möller <nisse@lysator.liu.se>
* tools/sexp-conv-test: Improve tests, including --hash feature.
void
sexp_output_init(struct sexp_output *output, FILE *f,
+ const struct nettle_hash *hash,
unsigned width, int prefer_hex)
{
output->f = f;
output->line_width = width;
output->coding = NULL;
output->prefer_hex = prefer_hex;
- output->hash = NULL;
- output->ctx = NULL;
+ output->hash = hash;
+ if (output->hash)
+ {
+ output->ctx = xalloc (output->hash->context_size);
+ output->hash->init (output->ctx);
+ }
+ else
+ output->ctx = NULL;
output->pos = 0;
output->soft_newline = 0;
}
-void
-sexp_output_hash_init(struct sexp_output *output,
- const struct nettle_hash *hash, void *ctx)
-{
- output->hash = hash;
- output->ctx = ctx;
- hash->init(ctx);
-}
-
static void
sexp_put_raw_char(struct sexp_output *output, uint8_t c)
{
void
sexp_output_init(struct sexp_output *output, FILE *f,
+ const struct nettle_hash *hash,
unsigned width, int prefer_hex);
-void
-sexp_output_hash_init(struct sexp_output *output,
- const struct nettle_hash *hash, void *ctx);
-
void
sexp_put_newline(struct sexp_output *output,
unsigned indent);
sexp_input_init(&input, stdin);
sexp_parse_init(&parser, &input, SEXP_ADVANCED);
sexp_compound_token_init(&token);
- sexp_output_init(&output, stdout,
+ sexp_output_init(&output, stdout, options.hash,
options.width, options.prefer_hex);
#if HAVE_FCNTL_LOCKING
die("Locking output file failed: %s\n", strerror(errno));
}
#endif /* HAVE_FCNTL_LOCKING */
- if (options.hash)
- {
- /* Leaks the context, but that doesn't matter */
- void *ctx = xalloc(options.hash->context_size);
- sexp_output_hash_init(&output, options.hash, ctx);
- }
sexp_get_char(&input);
if (fflush(output.f) < 0)
die("Final fflush failed: %s.\n", strerror(errno));
-
+
+ free (output.ctx);
+
return EXIT_SUCCESS;
}