aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-09-10 13:20:47 -0400
committerDavid Robillard <d@drobilla.net>2022-01-28 21:57:07 -0500
commiteb804125430e3445e85c423b28e1c41346772ed0 (patch)
tree532f6995ace537170fbbfde2d0d8226d1a48279b /tools
parentcbf01be4126cbc0f6d80364a7e0b6ad777a7d8ae (diff)
downloadserd-eb804125430e3445e85c423b28e1c41346772ed0.tar.gz
serd-eb804125430e3445e85c423b28e1c41346772ed0.tar.bz2
serd-eb804125430e3445e85c423b28e1c41346772ed0.zip
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.
Diffstat (limited to 'tools')
-rw-r--r--tools/console.c11
-rw-r--r--tools/console.h3
-rw-r--r--tools/serd-filter.c6
3 files changed, 11 insertions, 9 deletions
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);