From 14175e11c82a0e9441df797357c8c52acd96b5e0 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 15 Jan 2023 18:45:17 -0800 Subject: til_stream: comment fix, and assert/error on mismatch Just clarify some verbiage, and actually assert type+n_elems match. Note mismatch also fallsthrough to an -EINVAL just in case asserts() have been compiled out (-DNDEBUG). --- src/til_stream.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/til_stream.c') diff --git a/src/til_stream.c b/src/til_stream.c index 5f26c72..cafa35a 100644 --- a/src/til_stream.c +++ b/src/til_stream.c @@ -120,9 +120,9 @@ til_stream_t * til_stream_free(til_stream_t *stream) /* Taps the key-named type-typed pipe on the supplied stream. - * If this is the first use of the tap on this stream, new pipe will be created. - * If the tap exists on this stream, and the type matches, existing pipe will be used as-is. - * If the key exists on this stream, but the type mismatches, an error is returned. + * If this is the first use of the pipe on this stream, new pipe will be created. + * If the pipe exists on this stream, and the type/n_elems match, existing pipe will be used as-is. + * If the pipe exists on this stream, but the type/n_elems mismatch, it's a program error and asserted * * -errno is returned on error, 0 when tap is driving, 1 when tap is passenger. * @@ -157,6 +157,12 @@ int til_stream_tap(til_stream_t *stream, const void *owner, const void *owner_fo if (pipe->driving_tap->elems == *(tap->ptr) || (!strcmp(pipe->driving_tap->name, tap->name) && !strcmp(pipe->parent_path, parent_path))) { + if (pipe->driving_tap->type != tap->type || + pipe->driving_tap->n_elems != tap->n_elems) { + assert(0); /* I don't really want to handle such errors at runtime */ + return -1; + } + /* this looks to be our pipe, but we're not driving */ *(tap->ptr) = pipe->driving_tap->elems; -- cgit v1.2.1