I'd like to use UNIQUE_VAR() outside of "common/utils/cleanup.h"; also,
I'd like to use it for type names as well.
Give UNIQUE_VAR() its own header file, and rename it to UNIQUE_NAME().
A number of Makefiles (using the cleanup module) have to be refreshed;
while at it, make sure the "-I$(top_srcdir)/..." lists are consistently
sorted, and terminated with $(NULL).
Signed-off-by: Laszlo Ersek <lersek(a)redhat.com>
---
Notes:
v3:
- new in v3
common/include/Makefile.am | 1 +
filters/exitwhen/Makefile.am | 3 ++-
filters/ext2/Makefile.am | 3 ++-
filters/limit/Makefile.am | 3 ++-
filters/log/Makefile.am | 3 ++-
filters/offset/Makefile.am | 3 ++-
filters/xz/Makefile.am | 3 ++-
plugins/cc/Makefile.am | 1 +
plugins/cdi/Makefile.am | 1 +
plugins/iso/Makefile.am | 1 +
plugins/memory/Makefile.am | 3 ++-
plugins/ondemand/Makefile.am | 3 ++-
plugins/perl/Makefile.am | 3 ++-
plugins/python/Makefile.am | 3 ++-
plugins/split/Makefile.am | 3 ++-
plugins/tmpdisk/Makefile.am | 3 ++-
tests/Makefile.am | 6 +++++-
common/include/unique-name.h | 41 ++++++++++++++++++++++++++++++++++++
common/utils/cleanup.h | 31 ++++++++++++---------------
server/internal.h | 2 +-
20 files changed, 89 insertions(+), 31 deletions(-)
create mode 100644 common/include/unique-name.h
diff --git a/common/include/Makefile.am b/common/include/Makefile.am
index 52d97216fe2b..5421a5e2decf 100644
--- a/common/include/Makefile.am
+++ b/common/include/Makefile.am
@@ -47,6 +47,7 @@ EXTRA_DIST = \
random.h \
rounding.h \
tvdiff.h \
+ unique-name.h \
unix-path-max.h \
$(NULL)
diff --git a/filters/exitwhen/Makefile.am b/filters/exitwhen/Makefile.am
index 68e61d4bb9a8..19985ece7ff6 100644
--- a/filters/exitwhen/Makefile.am
+++ b/filters/exitwhen/Makefile.am
@@ -41,9 +41,10 @@ nbdkit_exitwhen_filter_la_SOURCES = \
$(NULL)
nbdkit_exitwhen_filter_la_CPPFLAGS = \
- -I$(top_srcdir)/include \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/replacements \
-I$(top_srcdir)/common/utils \
+ -I$(top_srcdir)/include \
$(NULL)
nbdkit_exitwhen_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
nbdkit_exitwhen_filter_la_LIBADD = \
diff --git a/filters/ext2/Makefile.am b/filters/ext2/Makefile.am
index c73f963d0508..2266a7fdbf34 100644
--- a/filters/ext2/Makefile.am
+++ b/filters/ext2/Makefile.am
@@ -45,8 +45,9 @@ nbdkit_ext2_filter_la_SOURCES = \
$(NULL)
nbdkit_ext2_filter_la_CPPFLAGS = \
- -I$(top_srcdir)/include \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/utils \
+ -I$(top_srcdir)/include \
$(NULL)
nbdkit_ext2_filter_la_CFLAGS = \
$(WARNINGS_CFLAGS) \
diff --git a/filters/limit/Makefile.am b/filters/limit/Makefile.am
index b4951acef5ff..bea3d9f18844 100644
--- a/filters/limit/Makefile.am
+++ b/filters/limit/Makefile.am
@@ -41,8 +41,9 @@ nbdkit_limit_filter_la_SOURCES = \
$(NULL)
nbdkit_limit_filter_la_CPPFLAGS = \
- -I$(top_srcdir)/include \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/utils \
+ -I$(top_srcdir)/include \
$(NULL)
nbdkit_limit_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
nbdkit_limit_filter_la_LDFLAGS = \
diff --git a/filters/log/Makefile.am b/filters/log/Makefile.am
index 8b0d9facc28d..26241051fd6d 100644
--- a/filters/log/Makefile.am
+++ b/filters/log/Makefile.am
@@ -46,8 +46,9 @@ nbdkit_log_filter_la_SOURCES = \
$(NULL)
nbdkit_log_filter_la_CPPFLAGS = \
- -I$(top_srcdir)/include \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/utils \
+ -I$(top_srcdir)/include \
$(NULL)
nbdkit_log_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
nbdkit_log_filter_la_LDFLAGS = \
diff --git a/filters/offset/Makefile.am b/filters/offset/Makefile.am
index 5437e700177e..a596b6514cda 100644
--- a/filters/offset/Makefile.am
+++ b/filters/offset/Makefile.am
@@ -41,8 +41,9 @@ nbdkit_offset_filter_la_SOURCES = \
$(NULL)
nbdkit_offset_filter_la_CPPFLAGS = \
- -I$(top_srcdir)/include \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/utils \
+ -I$(top_srcdir)/include \
$(NULL)
nbdkit_offset_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
nbdkit_offset_filter_la_LDFLAGS = \
diff --git a/filters/xz/Makefile.am b/filters/xz/Makefile.am
index ce6bc3423bee..742991db1a1d 100644
--- a/filters/xz/Makefile.am
+++ b/filters/xz/Makefile.am
@@ -47,8 +47,9 @@ nbdkit_xz_filter_la_SOURCES = \
$(NULL)
nbdkit_xz_filter_la_CPPFLAGS = \
- -I$(top_srcdir)/include \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/utils \
+ -I$(top_srcdir)/include \
$(NULL)
nbdkit_xz_filter_la_CFLAGS = \
$(WARNINGS_CFLAGS) \
diff --git a/plugins/cc/Makefile.am b/plugins/cc/Makefile.am
index ffee90c5eb9f..ea36adcacd4e 100644
--- a/plugins/cc/Makefile.am
+++ b/plugins/cc/Makefile.am
@@ -47,6 +47,7 @@ nbdkit_cc_plugin_la_SOURCES = \
nbdkit_cc_plugin_la_CPPFLAGS = \
-DCC="\"$(CC)\"" \
-DCFLAGS="\"$(CFLAGS) -fPIC -shared\"" \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/utils \
-I$(top_srcdir)/include \
-I. \
diff --git a/plugins/cdi/Makefile.am b/plugins/cdi/Makefile.am
index be042ba1fc99..7a31da3dfa86 100644
--- a/plugins/cdi/Makefile.am
+++ b/plugins/cdi/Makefile.am
@@ -44,6 +44,7 @@ nbdkit_cdi_plugin_la_SOURCES = \
$(NULL)
nbdkit_cdi_plugin_la_CPPFLAGS = \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/utils \
-I$(top_srcdir)/include \
-I. \
diff --git a/plugins/iso/Makefile.am b/plugins/iso/Makefile.am
index f419feb2c5ad..abd9595b4202 100644
--- a/plugins/iso/Makefile.am
+++ b/plugins/iso/Makefile.am
@@ -46,6 +46,7 @@ nbdkit_iso_plugin_la_SOURCES = \
$(NULL)
nbdkit_iso_plugin_la_CPPFLAGS = \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/utils \
-I$(top_srcdir)/include \
-I. \
diff --git a/plugins/memory/Makefile.am b/plugins/memory/Makefile.am
index ab0f3a0dcac4..428914eff48f 100644
--- a/plugins/memory/Makefile.am
+++ b/plugins/memory/Makefile.am
@@ -41,10 +41,11 @@ nbdkit_memory_plugin_la_SOURCES = \
$(NULL)
nbdkit_memory_plugin_la_CPPFLAGS = \
- -I$(top_srcdir)/include \
-I$(top_srcdir)/common/allocators \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/replacements \
-I$(top_srcdir)/common/utils \
+ -I$(top_srcdir)/include \
$(NULL)
nbdkit_memory_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
nbdkit_memory_plugin_la_LDFLAGS = \
diff --git a/plugins/ondemand/Makefile.am b/plugins/ondemand/Makefile.am
index 3c391416ee0c..e5be80706d49 100644
--- a/plugins/ondemand/Makefile.am
+++ b/plugins/ondemand/Makefile.am
@@ -60,9 +60,10 @@ nbdkit_ondemand_plugin_la_SOURCES = \
$(NULL)
nbdkit_ondemand_plugin_la_CPPFLAGS = \
- -I$(top_srcdir)/include \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/replacements \
-I$(top_srcdir)/common/utils \
+ -I$(top_srcdir)/include \
$(NULL)
nbdkit_ondemand_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
nbdkit_ondemand_plugin_la_LDFLAGS = \
diff --git a/plugins/perl/Makefile.am b/plugins/perl/Makefile.am
index 89fe733e8261..a5b654a04f0d 100644
--- a/plugins/perl/Makefile.am
+++ b/plugins/perl/Makefile.am
@@ -46,8 +46,9 @@ nbdkit_perl_plugin_la_SOURCES = \
$(NULL)
nbdkit_perl_plugin_la_CPPFLAGS = \
- -I$(top_srcdir)/include \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/utils \
+ -I$(top_srcdir)/include \
$(NULL)
nbdkit_perl_plugin_la_CFLAGS = \
$(WARNINGS_CFLAGS) \
diff --git a/plugins/python/Makefile.am b/plugins/python/Makefile.am
index 2d8955ef566f..e2cd6116aacc 100644
--- a/plugins/python/Makefile.am
+++ b/plugins/python/Makefile.am
@@ -53,8 +53,9 @@ nbdkit_python_plugin_la_SOURCES = \
$(NULL)
nbdkit_python_plugin_la_CPPFLAGS = \
- -I$(top_srcdir)/include \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/utils \
+ -I$(top_srcdir)/include \
$(NULL)
nbdkit_python_plugin_la_CFLAGS = \
diff --git a/plugins/split/Makefile.am b/plugins/split/Makefile.am
index 1ac0fefef6fc..ffd69d19c733 100644
--- a/plugins/split/Makefile.am
+++ b/plugins/split/Makefile.am
@@ -41,9 +41,10 @@ nbdkit_split_plugin_la_SOURCES = \
$(NULL)
nbdkit_split_plugin_la_CPPFLAGS = \
- -I$(top_srcdir)/include \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/replacements \
-I$(top_srcdir)/common/utils \
+ -I$(top_srcdir)/include \
$(NULL)
nbdkit_split_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
nbdkit_split_plugin_la_LDFLAGS = \
diff --git a/plugins/tmpdisk/Makefile.am b/plugins/tmpdisk/Makefile.am
index ae263e1fe0d6..03c1af458fb7 100644
--- a/plugins/tmpdisk/Makefile.am
+++ b/plugins/tmpdisk/Makefile.am
@@ -59,8 +59,9 @@ nbdkit_tmpdisk_plugin_la_SOURCES = \
$(NULL)
nbdkit_tmpdisk_plugin_la_CPPFLAGS = \
- -I$(top_srcdir)/include \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/utils \
+ -I$(top_srcdir)/include \
$(NULL)
nbdkit_tmpdisk_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
nbdkit_tmpdisk_plugin_la_LIBADD = \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 64b56efbba92..9371c62b074a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -603,6 +603,7 @@ test_curl_header_script_SOURCES = \
web-server.h \
$(NULL)
test_curl_header_script_CPPFLAGS = \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/utils \
$(NULL)
test_curl_header_script_CFLAGS = \
@@ -624,6 +625,7 @@ test_curl_cookie_script_SOURCES = \
web-server.h \
$(NULL)
test_curl_cookie_script_CPPFLAGS = \
+ -I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/utils \
$(NULL)
test_curl_cookie_script_CFLAGS = \
@@ -1724,7 +1726,9 @@ test_retry_request_mirror_SOURCES = \
test.h \
$(NULL)
test_retry_request_mirror_CPPFLAGS = \
- -I$(top_srcdir)/common/utils
+ -I$(top_srcdir)/common/include \
+ -I$(top_srcdir)/common/utils \
+ $(NULL)
test_retry_request_mirror_CFLAGS = \
$(WARNINGS_CFLAGS) \
$(PTHREAD_CFLAGS) \
diff --git a/common/include/unique-name.h b/common/include/unique-name.h
new file mode 100644
index 000000000000..31d937fdbbad
--- /dev/null
+++ b/common/include/unique-name.h
@@ -0,0 +1,41 @@
+/* nbdkit
+ * Copyright (C) 2013-2021 Red Hat Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Red Hat nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef NBDKIT_UNIQUE_NAME_H
+#define NBDKIT_UNIQUE_NAME_H
+
+/*
https://stackoverflow.com/a/1597129 */
+#define XXUNIQUE_NAME(name, line) name ## line
+#define XUNIQUE_NAME(name, line) XXUNIQUE_NAME (name, line)
+#define UNIQUE_NAME(name) XUNIQUE_NAME (name, __LINE__)
+
+#endif /* NBDKIT_UNIQUE_NAME_H */
diff --git a/common/utils/cleanup.h b/common/utils/cleanup.h
index e6f899663663..ced16a009495 100644
--- a/common/utils/cleanup.h
+++ b/common/utils/cleanup.h
@@ -36,6 +36,8 @@
#include <pthread.h>
#include <assert.h>
+#include "unique-name.h"
+
/* Work around clang bug:
https://bugs.llvm.org/show_bug.cgi?id=43482 */
#ifdef __clang__
#define CLANG_UNUSED_VARIABLE_WORKAROUND __attribute__((__unused__))
@@ -43,11 +45,6 @@
#define CLANG_UNUSED_VARIABLE_WORKAROUND
#endif
-/*
https://stackoverflow.com/a/1597129 */
-#define XXUNIQUE_VAR(name, line) name ## line
-#define XUNIQUE_VAR(name, line) XXUNIQUE_VAR (name, line)
-#define UNIQUE_VAR(name) XUNIQUE_VAR (name, __LINE__)
-
/* cleanup.c */
extern void cleanup_free (void *ptr);
#define CLEANUP_FREE __attribute__((cleanup (cleanup_free)))
@@ -56,27 +53,27 @@ extern void cleanup_mutex_unlock (pthread_mutex_t **ptr);
#define CLEANUP_MUTEX_UNLOCK __attribute__((cleanup (cleanup_mutex_unlock)))
#define ACQUIRE_LOCK_FOR_CURRENT_SCOPE(mutex) \
- CLEANUP_MUTEX_UNLOCK pthread_mutex_t *UNIQUE_VAR(_lock) = mutex; \
+ CLEANUP_MUTEX_UNLOCK pthread_mutex_t *UNIQUE_NAME(_lock) = mutex; \
do { \
- int _r = pthread_mutex_lock (UNIQUE_VAR(_lock)); \
+ int _r = pthread_mutex_lock (UNIQUE_NAME(_lock)); \
assert (!_r); \
} while (0)
extern void cleanup_rwlock_unlock (pthread_rwlock_t **ptr);
#define CLEANUP_RWLOCK_UNLOCK __attribute__((cleanup (cleanup_rwlock_unlock)))
-#define ACQUIRE_WRLOCK_FOR_CURRENT_SCOPE(rwlock) \
- CLEANUP_RWLOCK_UNLOCK pthread_rwlock_t *UNIQUE_VAR(_rwlock) = rwlock; \
- do { \
- int _r = pthread_rwlock_wrlock (UNIQUE_VAR(_rwlock)); \
- assert (!_r); \
+#define ACQUIRE_WRLOCK_FOR_CURRENT_SCOPE(rwlock) \
+ CLEANUP_RWLOCK_UNLOCK pthread_rwlock_t *UNIQUE_NAME(_rwlock) = rwlock; \
+ do { \
+ int _r = pthread_rwlock_wrlock (UNIQUE_NAME(_rwlock)); \
+ assert (!_r); \
} while (0)
-#define ACQUIRE_RDLOCK_FOR_CURRENT_SCOPE(rwlock) \
- CLEANUP_RWLOCK_UNLOCK pthread_rwlock_t *UNIQUE_VAR(_rwlock) = rwlock; \
- do { \
- int _r = pthread_rwlock_rdlock (UNIQUE_VAR(_rwlock)); \
- assert (!_r); \
+#define ACQUIRE_RDLOCK_FOR_CURRENT_SCOPE(rwlock) \
+ CLEANUP_RWLOCK_UNLOCK pthread_rwlock_t *UNIQUE_NAME(_rwlock) = rwlock; \
+ do { \
+ int _r = pthread_rwlock_rdlock (UNIQUE_NAME(_rwlock)); \
+ assert (!_r); \
} while (0)
/* cleanup-nbdkit.c */
diff --git a/server/internal.h b/server/internal.h
index bc81b7861848..ccbf0f062d28 100644
--- a/server/internal.h
+++ b/server/internal.h
@@ -531,7 +531,7 @@ extern void threadlocal_pop_context (struct context **ctx);
#define CLEANUP_CONTEXT_POP __attribute__((cleanup (threadlocal_pop_context)))
#define PUSH_CONTEXT_FOR_SCOPE(ctx) \
CLEANUP_CONTEXT_POP CLANG_UNUSED_VARIABLE_WORKAROUND \
- struct context *UNIQUE_VAR(_ctx) = threadlocal_push_context (ctx)
+ struct context *UNIQUE_NAME(_ctx) = threadlocal_push_context (ctx)
/* Macro which sets local variable struct connection *conn from
* thread-local storage, asserting that it is non-NULL. If you want
--
2.19.1.3.g30247aa5d201