From eb804125430e3445e85c423b28e1c41346772ed0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 10 Sep 2021 13:20:47 -0400 Subject: Make environments and sinks part of the world Although functions/components that require minimal pre-existing state are nice, these allocate memory and could potentially share resources. So, give them a pointer to a world which can be used to configure such things. In particular, this is working towards supporting custom allocators everywhere. --- tools/console.c | 11 ++++++----- tools/console.h | 3 ++- tools/serd-filter.c | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) (limited to 'tools') diff --git a/tools/console.c b/tools/console.c index c6e55c17..c2166130 100644 --- a/tools/console.c +++ b/tools/console.c @@ -50,8 +50,8 @@ serd_tool_setup(SerdTool* const tool, // We have something to write to, so build the writing environment if (!(tool->world = serd_world_new()) || - !(tool->env = - serd_create_env(program, options.base_uri, options.out_filename)) || + !(tool->env = serd_create_env( + tool->world, program, options.base_uri, options.out_filename)) || !(tool->writer = serd_writer_new( tool->world, serd_choose_syntax( @@ -291,7 +291,8 @@ serd_parse_common_option(OptionIter* const iter, SerdCommonOptions* const opts) } SerdEnv* -serd_create_env(const char* const program, +serd_create_env(SerdWorld* const world, + const char* const program, const char* const base_string, const char* const out_filename) { @@ -302,10 +303,10 @@ serd_create_env(const char* const program, } if (base_string && serd_uri_string_has_scheme(base_string)) { - return serd_env_new(SERD_STRING(base_string)); + return serd_env_new(world, SERD_STRING(base_string)); } - SerdEnv* const env = serd_env_new(SERD_EMPTY_STRING()); + SerdEnv* const env = serd_env_new(world, SERD_EMPTY_STRING()); serd_set_base_uri_from_path(env, is_rebase ? out_filename : base_string); return env; } diff --git a/tools/console.h b/tools/console.h index 43bc7a12..ef3d7b8d 100644 --- a/tools/console.h +++ b/tools/console.h @@ -109,7 +109,8 @@ SerdStatus serd_parse_common_option(OptionIter* iter, SerdCommonOptions* opts); SerdEnv* -serd_create_env(const char* program, +serd_create_env(SerdWorld* world, + const char* program, const char* base_string, const char* out_filename); diff --git a/tools/serd-filter.c b/tools/serd-filter.c index b172d05d..199125d5 100644 --- a/tools/serd-filter.c +++ b/tools/serd-filter.c @@ -71,9 +71,9 @@ parse_pattern(SerdWorld* const world, SerdInputStream* const in, const bool inclusive) { - SerdEnv* const env = serd_env_new(SERD_EMPTY_STRING()); + SerdEnv* const env = serd_env_new(world, SERD_EMPTY_STRING()); FilterPattern pat = {NULL, NULL, NULL, NULL}; - SerdSink* in_sink = serd_sink_new(&pat, on_pattern_event, NULL); + SerdSink* in_sink = serd_sink_new(world, &pat, on_pattern_event, NULL); SerdReader* reader = serd_reader_new( world, SERD_NQUADS, SERD_READ_VARIABLES, env, in_sink, 4096); @@ -99,7 +99,7 @@ parse_pattern(SerdWorld* const world, } SerdSink* filter = - serd_filter_new(sink, pat.s, pat.p, pat.o, pat.g, inclusive); + serd_filter_new(world, sink, pat.s, pat.p, pat.o, pat.g, inclusive); serd_node_free(pat.s); serd_node_free(pat.p); -- cgit v1.2.1