aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-06-29 15:45:50 -0400
committerDavid Robillard <d@drobilla.net>2022-01-13 23:04:20 -0500
commitdc77dc04689254730de428e75a1da6f7a893c9e6 (patch)
treee2c2863a0e6c99be35d5470eb667164184c27889
parent963909d052a617e7f3e2ff7a2dd6483f5629e698 (diff)
downloadserd-dc77dc04689254730de428e75a1da6f7a893c9e6.tar.gz
serd-dc77dc04689254730de428e75a1da6f7a893c9e6.tar.bz2
serd-dc77dc04689254730de428e75a1da6f7a893c9e6.zip
Factor out TRY macro
-rw-r--r--src/n3.c8
-rw-r--r--src/try.h27
-rw-r--r--src/writer.c8
3 files changed, 29 insertions, 14 deletions
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 <d@drobilla.net>
+
+ 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