From dc77dc04689254730de428e75a1da6f7a893c9e6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 29 Jun 2021 15:45:50 -0400 Subject: Factor out TRY macro --- src/n3.c | 8 +------- src/try.h | 27 +++++++++++++++++++++++++++ src/writer.c | 8 +------- 3 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 src/try.h diff --git a/src/n3.c b/src/n3.c index ab0cfb37..cd8119ae 100644 --- a/src/n3.c +++ b/src/n3.c @@ -20,6 +20,7 @@ #include "serd_internal.h" #include "stack.h" #include "string_utils.h" +#include "try.h" #include "uri_utils.h" #include "serd/serd.h" @@ -41,13 +42,6 @@ _Pragma("clang diagnostic ignored \"-Wmissing-declarations\"") # define SERD_FALLTHROUGH #endif -#define TRY(st, exp) \ - do { \ - if (((st) = (exp))) { \ - return (st); \ - } \ - } while (0) - static bool fancy_syntax(const SerdReader* const reader) { diff --git a/src/try.h b/src/try.h new file mode 100644 index 00000000..82893887 --- /dev/null +++ b/src/try.h @@ -0,0 +1,27 @@ +/* + Copyright 2011-2021 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef SERD_TRY_H +#define SERD_TRY_H + +#define TRY(st, exp) \ + do { \ + if (((st) = (exp))) { \ + return (st); \ + } \ + } while (0) + +#endif // SERD_TRY_H diff --git a/src/writer.c b/src/writer.c index 5a605cd4..55136b98 100644 --- a/src/writer.c +++ b/src/writer.c @@ -21,6 +21,7 @@ #include "sink.h" #include "string_utils.h" #include "system.h" +#include "try.h" #include "uri_utils.h" #include "world.h" @@ -40,13 +41,6 @@ # define SERD_WARN_UNUSED_RESULT #endif -#define TRY(st, exp) \ - do { \ - if (((st) = (exp))) { \ - return (st); \ - } \ - } while (0) - typedef enum { CTX_NAMED, ///< Normal non-anonymous context CTX_BLANK, ///< Anonymous blank node -- cgit v1.2.1