summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArvind Sankar <[email protected]>2020-07-04 18:24:13 -0400
committerBrian Behlendorf <[email protected]>2020-07-10 14:25:24 -0700
commitb6437ea41c7611481925d72d294677434639b847 (patch)
treeeec95e7d4fd2a809f88f27f25bf7bfba8e43771b
parent2054f35e564b59e23950ee573e91dbae3fd2ccd9 (diff)
Move libspl_assertf into .c file
Variadic functions cannot be inlined. libspl_assertf ends up being duplicated in every file that uses it. Fix this by moving the function into a new assert.c. Also move the definition of aok into the new file instead of zone.c. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Arvind Sankar <[email protected]> Closes #10538
-rw-r--r--lib/libspl/Makefile.am10
-rw-r--r--lib/libspl/assert.c46
-rw-r--r--lib/libspl/include/assert.h33
-rw-r--r--lib/libspl/zone.c2
-rw-r--r--tests/zfs-tests/tests/functional/checksum/Makefile.am4
-rw-r--r--tests/zfs-tests/tests/functional/checksum/edonr_test.c2
6 files changed, 64 insertions, 33 deletions
diff --git a/lib/libspl/Makefile.am b/lib/libspl/Makefile.am
index b3d9ee79c..ad34c3588 100644
--- a/lib/libspl/Makefile.am
+++ b/lib/libspl/Makefile.am
@@ -17,7 +17,10 @@ AM_CFLAGS += $(LIBTIRPC_CFLAGS)
AM_CCASFLAGS = \
$(CFLAGS)
-noinst_LTLIBRARIES = libspl.la
+noinst_LTLIBRARIES = libspl_assert.la libspl.la
+
+libspl_assert_la_SOURCES = \
+ assert.c
USER_C = \
list.c \
@@ -49,4 +52,7 @@ libspl_la_SOURCES = \
$(USER_C) \
$(TARGET_CPU_ATOMIC_SOURCE)
-libspl_la_LIBADD = -lrt $(LIBTIRPC_LIBS)
+libspl_la_LIBADD = \
+ libspl_assert.la
+
+libspl_la_LIBADD += -lrt $(LIBTIRPC_LIBS)
diff --git a/lib/libspl/assert.c b/lib/libspl/assert.c
new file mode 100644
index 000000000..94290ae13
--- /dev/null
+++ b/lib/libspl/assert.c
@@ -0,0 +1,46 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <assert.h>
+
+int aok = 0;
+
+/* printf version of libspl_assert */
+void
+libspl_assertf(const char *file, const char *func, int line,
+ const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ vfprintf(stderr, format, args);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "ASSERT at %s:%d:%s()", file, line, func);
+ va_end(args);
+ if (aok) {
+ return;
+ }
+ abort();
+}
diff --git a/lib/libspl/include/assert.h b/lib/libspl/include/assert.h
index 6f80f1334..0503ce492 100644
--- a/lib/libspl/include/assert.h
+++ b/lib/libspl/include/assert.h
@@ -33,37 +33,18 @@
#include <stdlib.h>
#include <stdarg.h>
-#ifndef _KERNEL
+/* Set to non-zero to avoid abort()ing on an assertion failure */
extern int aok;
-#endif
+
+/* printf version of libspl_assert */
+extern void libspl_assertf(const char *file, const char *func, int line,
+ const char *format, ...);
static inline int
libspl_assert(const char *buf, const char *file, const char *func, int line)
{
- fprintf(stderr, "%s\n", buf);
- fprintf(stderr, "ASSERT at %s:%d:%s()", file, line, func);
- if (aok) {
- return (0);
- }
- abort();
-}
-
-/* printf version of libspl_assert */
-static inline void
-libspl_assertf(const char *file, const char *func, int line,
- const char *format, ...)
-{
- va_list args;
-
- va_start(args, format);
- vfprintf(stderr, format, args);
- fprintf(stderr, "\n");
- fprintf(stderr, "ASSERT at %s:%d:%s()", file, line, func);
- va_end(args);
- if (aok) {
- return;
- }
- abort();
+ libspl_assertf(file, func, line, "%s", buf);
+ return (0);
}
#ifdef verify
diff --git a/lib/libspl/zone.c b/lib/libspl/zone.c
index 4a0e600ca..5ca93b224 100644
--- a/lib/libspl/zone.c
+++ b/lib/libspl/zone.c
@@ -27,8 +27,6 @@
#include <string.h>
#include <errno.h>
-int aok = 0;
-
zoneid_t
getzoneid()
{
diff --git a/tests/zfs-tests/tests/functional/checksum/Makefile.am b/tests/zfs-tests/tests/functional/checksum/Makefile.am
index a8eb41331..7cd15324e 100644
--- a/tests/zfs-tests/tests/functional/checksum/Makefile.am
+++ b/tests/zfs-tests/tests/functional/checksum/Makefile.am
@@ -1,7 +1,9 @@
include $(top_srcdir)/config/Rules.am
AM_CPPFLAGS += -I$(top_srcdir)/include
-LDADD = $(top_builddir)/lib/libicp/libicp.la
+LDADD = \
+ $(top_builddir)/lib/libicp/libicp.la \
+ $(top_builddir)/lib/libspl/libspl_assert.la
AUTOMAKE_OPTIONS = subdir-objects
diff --git a/tests/zfs-tests/tests/functional/checksum/edonr_test.c b/tests/zfs-tests/tests/functional/checksum/edonr_test.c
index 3c676c91f..a88756091 100644
--- a/tests/zfs-tests/tests/functional/checksum/edonr_test.c
+++ b/tests/zfs-tests/tests/functional/checksum/edonr_test.c
@@ -40,8 +40,6 @@
#include <sys/time.h>
#include <sys/stdtypes.h>
-int aok = 0;
-
/*
* Test messages from:
* http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA_All.pdf