]> granicus.if.org Git - strace/commitdiff
Introduce macros.h
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 2 Jul 2017 00:11:31 +0000 (00:11 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 2 Jul 2017 00:11:31 +0000 (00:11 +0000)
Introduce a separate header file for generic macros shared between
strace and its tests.  Start this unification with ARRAY_SIZE macro.

* defs.h: Include "macros.h".
(ARRAY_SIZE): Move ...
* macros.h: ... to new file.
* Makefile.am (strace_SOURCES): Add it.
* tests/tests.h: Include "macros.h".
(ARRAY_SIZE): Remove.  All callers updated.

12 files changed:
Makefile.am
defs.h
macros.h [new file with mode: 0644]
tests/mmsg.c
tests/poll.c
tests/preadv-pwritev.c
tests/preadv.c
tests/preadv2-pwritev2.c
tests/readv.c
tests/recvmsg.c
tests/tests.h
tests/vmsplice.c

index 7c0658d5babdaa48c9cc9eb39b3dbddf341f85af..cb650215356f7b735ba8aad73f3ef6a8f1390a72 100644 (file)
@@ -159,6 +159,7 @@ strace_SOURCES =    \
        lookup_dcookie.c \
        loop.c          \
        lseek.c         \
+       macros.h        \
        mem.c           \
        membarrier.c    \
        memfd_create.c  \
diff --git a/defs.h b/defs.h
index dcb4d94734c733d16a346a9c29bcf890bc60d2ab..b3a315f338c782186b4769dbc75d67d66c0b34f6 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -54,8 +54,9 @@
 #include <sys/time.h>
 
 #include "kernel_types.h"
-#include "mpers_type.h"
 #include "gcc_compat.h"
+#include "macros.h"
+#include "mpers_type.h"
 #include "sysent.h"
 
 #ifndef HAVE_STRERROR
@@ -75,8 +76,6 @@ extern char *stpcpy(char *dst, const char *src);
        (offsetof(type, member) + sizeof(((type *)NULL)->member))
 #endif
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]) + MUST_BE_ARRAY(a))
-
 /* macros */
 #ifndef MAX
 # define MAX(a, b)             (((a) > (b)) ? (a) : (b))
diff --git a/macros.h b/macros.h
new file mode 100644 (file)
index 0000000..218b057
--- /dev/null
+++ b/macros.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2001-2017 The strace developers.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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 STRACE_MACROS_H
+#define STRACE_MACROS_H
+
+#include "gcc_compat.h"
+
+#define ARRAY_SIZE(a_) (sizeof(a_) / sizeof((a_)[0]) + MUST_BE_ARRAY(a_))
+
+#endif /* !STRACE_MACROS_H */
index 88805d16a97bc6e44766303ba52292885b26eae7..a5cf0e7979a49824a7fccfa6f3a8e0fcfda94641 100644 (file)
@@ -113,14 +113,16 @@ main(void)
                " | 00000 %-49s  %-16s |\n",
                w0_c, LENGTH_OF(w0_c),
                w1_c, LENGTH_OF(w1_c),
-               ARRAY_SIZE(w0_iov_),
+               (unsigned int) ARRAY_SIZE(w0_iov_),
                LENGTH_OF(w0_c) + LENGTH_OF(w1_c),
-               w2_c, LENGTH_OF(w2_c), ARRAY_SIZE(w1_iov_),
+               w2_c, LENGTH_OF(w2_c), (unsigned int) ARRAY_SIZE(w1_iov_),
                LENGTH_OF(w2_c),
                n_w_mmh, r,
-               ARRAY_SIZE(w0_iov_), LENGTH_OF(w0_c), w0_d, w0_c,
+               (unsigned int) ARRAY_SIZE(w0_iov_),
+               LENGTH_OF(w0_c), w0_d, w0_c,
                LENGTH_OF(w1_c), w1_d, w1_c,
-               ARRAY_SIZE(w1_iov_), LENGTH_OF(w2_c), w2_d, w2_c);
+               (unsigned int) ARRAY_SIZE(w1_iov_),
+               LENGTH_OF(w2_c), w2_d, w2_c);
 
        const unsigned int w_len =
                LENGTH_OF(w0_c) + LENGTH_OF(w1_c) + LENGTH_OF(w2_c);
@@ -184,11 +186,14 @@ main(void)
                " = %u buffers in vector 1\n"
                " * %u bytes in buffer 0\n"
                " | 00000 %-49s  %-16s |\n",
-               r0_c, r_len, ARRAY_SIZE(r0_iov_), LENGTH_OF(r0_c),
-               r1_c, r_len, r_len, ARRAY_SIZE(r1_iov_), LENGTH_OF(r1_c),
+               r0_c, r_len, (unsigned int) ARRAY_SIZE(r0_iov_),
+               LENGTH_OF(r0_c), r1_c, r_len, r_len,
+               (unsigned int) ARRAY_SIZE(r1_iov_), LENGTH_OF(r1_c),
                n_r_mmh, r,
-               ARRAY_SIZE(r0_iov_), LENGTH_OF(r0_c), r0_d, r0_c,
-               ARRAY_SIZE(r1_iov_), LENGTH_OF(r1_c), r1_d, r1_c);
+               (unsigned int) ARRAY_SIZE(r0_iov_), LENGTH_OF(r0_c),
+               r0_d, r0_c,
+               (unsigned int) ARRAY_SIZE(r1_iov_), LENGTH_OF(r1_c),
+               r1_d, r1_c);
 
        tprintf("+++ exited with 0 +++\n");
        return 0;
index 5c07297fc562b6fa673d3d4b3fe43aa4749d7359..af66e536949771b34cddabefb9ba6b82bebe4a36 100644 (file)
@@ -194,7 +194,8 @@ main(int ac, char **av)
        tprintf("poll(");
        print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
                                    ARRAY_SIZE(pfds0), abbrev);
-       tprintf(", %u, %d) = %d (", ARRAY_SIZE(pfds0), timeout, rc);
+       tprintf(", %u, %d) = %d (",
+               (unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
        print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
        tprintf(")\n");
 
@@ -207,7 +208,8 @@ main(int ac, char **av)
        tprintf("poll(");
        print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
                                    ARRAY_SIZE(pfds0), abbrev);
-       tprintf(", %u, %d) = %d (", ARRAY_SIZE(pfds0), timeout, rc);
+       tprintf(", %u, %d) = %d (",
+               (unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
        print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
        tprintf(")\n");
 
@@ -219,7 +221,8 @@ main(int ac, char **av)
        tprintf("poll(");
        print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
                                    ARRAY_SIZE(pfds0), abbrev);
-       tprintf(", %u, %d) = %d (", ARRAY_SIZE(pfds0), timeout, rc);
+       tprintf(", %u, %d) = %d (",
+               (unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
        print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
        tprintf(")\n");
 
@@ -234,7 +237,8 @@ main(int ac, char **av)
        tprintf("poll(");
        print_pollfd_array_entering(tail_fds1, ARRAY_SIZE(pfds1),
                                    ARRAY_SIZE(pfds1), abbrev);
-       tprintf(", %u, %d) = %d (Timeout)\n", ARRAY_SIZE(pfds1), timeout, rc);
+       tprintf(", %u, %d) = %d (Timeout)\n",
+               (unsigned int) ARRAY_SIZE(pfds1), timeout, rc);
 
        const void *const efault = tail_fds0 + ARRAY_SIZE(pfds0);
        rc = syscall(__NR_poll, efault, 1, 0);
index b2d2a824857f4256feac07ca97982df2f3bdca9c..ddbd47f6727eb1716f57cc59bb722fa0e4b6264c 100644 (file)
@@ -121,7 +121,7 @@ main(void)
                " * %u bytes in buffer 2\n"
                " | 00000 %-49s  %-16s |\n",
                w0_c, LENGTH_OF(w0_c), w1_c, LENGTH_OF(w1_c),
-               w2_c, LENGTH_OF(w2_c), ARRAY_SIZE(w_iov_), w_len,
+               w2_c, LENGTH_OF(w2_c), (unsigned int) ARRAY_SIZE(w_iov_), w_len,
                LENGTH_OF(w0_c), w0_d, w0_c,
                LENGTH_OF(w1_c), w1_d, w1_c, LENGTH_OF(w2_c), w2_d, w2_c);
 
@@ -142,7 +142,8 @@ main(void)
        tprintf("preadv(0, [{iov_base=\"%s\", iov_len=%u}], %u, 0) = %u\n"
                " * %u bytes in buffer 0\n"
                " | 00000 %-49s  %-16s |\n",
-               r0_c, r_len, ARRAY_SIZE(r0_iov_), r_len, r_len, r0_d, r0_c);
+               r0_c, r_len, (unsigned int) ARRAY_SIZE(r0_iov_),
+               r_len, r_len, r0_d, r0_c);
 
        void *r1 = tail_alloc(r_len);
        void *r2 = tail_alloc(w_len);
@@ -166,7 +167,7 @@ main(void)
                ", {iov_base=\"\", iov_len=%u}], %u, %u) = %u\n"
                " * %u bytes in buffer 0\n"
                " | 00000 %-49s  %-16s |\n",
-               r1_c, r_len, w_len, ARRAY_SIZE(r1_iov_),
+               r1_c, r_len, w_len, (unsigned int) ARRAY_SIZE(r1_iov_),
                r_len, w_len - r_len,
                w_len - r_len, r1_d, r1_c);
        close(0);
index a55909b639b05d2c42035e55df538fde01ed0dd6..d5ad84f64a2922de4dad389fdf303dd0b65082fb 100644 (file)
@@ -125,7 +125,7 @@ main(void)
                perror_msg_and_fail("preadv: expected %u, returned %ld",
                                    r_len, rc);
        printf("preadv(%d, [{iov_base=\"%s\", iov_len=%u}], %u, 0) = %u\n",
-              fd, r0_c, r_len, ARRAY_SIZE(r0_iov_), r_len);
+              fd, r0_c, r_len, (unsigned int) ARRAY_SIZE(r0_iov_), r_len);
 
        void *r1 = tail_alloc(r_len);
        void *r2 = tail_alloc(LENGTH_OF(w));
@@ -147,8 +147,9 @@ main(void)
                                    (int) LENGTH_OF(w) - r_len, rc);
        printf("preadv(%d, [{iov_base=\"%s\", iov_len=%u}"
               ", {iov_base=\"\", iov_len=%u}], %u, %u) = %u\n",
-              fd, r1_c, r_len, LENGTH_OF(w), ARRAY_SIZE(r1_iov_),
-               r_len, LENGTH_OF(w) - r_len);
+              fd, r1_c, r_len, LENGTH_OF(w),
+              (unsigned int) ARRAY_SIZE(r1_iov_),
+              r_len, LENGTH_OF(w) - r_len);
 
        puts("+++ exited with 0 +++");
        return 0;
index e31e0463137c9dc2689d6edbd1a44f03fc58cf42..89f37dd6cb52e0a8c42d2fa26970022b2d6f578a 100644 (file)
@@ -127,7 +127,7 @@ dumpio(void)
                " * %u bytes in buffer 2\n"
                " | 00000 %-49s  %-16s |\n",
                w0_c, LENGTH_OF(w0_c), w1_c, LENGTH_OF(w1_c),
-               w2_c, LENGTH_OF(w2_c), ARRAY_SIZE(w_iov_), w_len,
+               w2_c, LENGTH_OF(w2_c), (unsigned int) ARRAY_SIZE(w_iov_), w_len,
                LENGTH_OF(w0_c), w0_d, w0_c,
                LENGTH_OF(w1_c), w1_d, w1_c, LENGTH_OF(w2_c), w2_d, w2_c);
 
@@ -148,7 +148,8 @@ dumpio(void)
        tprintf("preadv2(0, [{iov_base=\"%s\", iov_len=%u}], %u, 0, 0) = %u\n"
                " * %u bytes in buffer 0\n"
                " | 00000 %-49s  %-16s |\n",
-               r0_c, r_len, ARRAY_SIZE(r0_iov_), r_len, r_len, r0_d, r0_c);
+               r0_c, r_len, (unsigned int) ARRAY_SIZE(r0_iov_),
+               r_len, r_len, r0_d, r0_c);
 
        void *r1 = tail_alloc(r_len);
        void *r2 = tail_alloc(w_len);
@@ -172,7 +173,7 @@ dumpio(void)
                ", {iov_base=\"\", iov_len=%u}], %u, %u, 0) = %u\n"
                " * %u bytes in buffer 0\n"
                " | 00000 %-49s  %-16s |\n",
-               r1_c, r_len, w_len, ARRAY_SIZE(r1_iov_),
+               r1_c, r_len, w_len, (unsigned int) ARRAY_SIZE(r1_iov_),
                r_len, w_len - r_len,
                w_len - r_len, r1_d, r1_c);
        close(0);
index 0e5aab65c2c114ab1d8d02c5a82f6cca1c46b609..93f0760570e0727d69fd4f660c53630a9981bbdd 100644 (file)
@@ -108,7 +108,7 @@ main(void)
                " * %u bytes in buffer 2\n"
                " | 00000 %-49s  %-16s |\n",
                fds[1], w0_c, LENGTH_OF(w0_c), w1_c, LENGTH_OF(w1_c),
-               w2_c, LENGTH_OF(w2_c), ARRAY_SIZE(w_iov_), w_len,
+               w2_c, LENGTH_OF(w2_c), (unsigned int) ARRAY_SIZE(w_iov_), w_len,
                LENGTH_OF(w0_c), w0_d, w0_c,
                LENGTH_OF(w1_c), w1_d, w1_c, LENGTH_OF(w2_c), w2_d, w2_c);
 
@@ -126,8 +126,8 @@ main(void)
        tprintf("readv(%d, [{iov_base=\"%s\", iov_len=%u}], %u) = %u\n"
                " * %u bytes in buffer 0\n"
                " | 00000 %-49s  %-16s |\n",
-               fds[0],
-               r0_c, r_len, ARRAY_SIZE(r0_iov_), r_len, r_len, r0_d, r0_c);
+               fds[0], r0_c, r_len, (unsigned int) ARRAY_SIZE(r0_iov_),
+               r_len, r_len, r0_d, r0_c);
 
        void *r1 = tail_alloc(r_len);
        void *r2 = tail_alloc(w_len);
@@ -148,8 +148,8 @@ main(void)
                ", {iov_base=\"\", iov_len=%u}], %u) = %u\n"
                " * %u bytes in buffer 0\n"
                " | 00000 %-49s  %-16s |\n",
-               fds[0], r1_c, r_len, w_len, ARRAY_SIZE(r1_iov_), w_len - r_len,
-               w_len - r_len, r1_d, r1_c);
+               fds[0], r1_c, r_len, w_len, (unsigned int) ARRAY_SIZE(r1_iov_),
+               w_len - r_len, w_len - r_len, r1_d, r1_c);
        close(fds[0]);
 
        tprintf("+++ exited with 0 +++\n");
index fa41a9d415cae8bdc96f03386b2f71fbd6421388..2d55d55474a4a01eb447fcae1d368e7b1173db49 100644 (file)
@@ -100,7 +100,7 @@ main(void)
                w0_c, LENGTH_OF(w0_c),
                w1_c, LENGTH_OF(w1_c),
                w2_c, LENGTH_OF(w2_c),
-               ARRAY_SIZE(w_iov_), w_len,
+               (unsigned int) ARRAY_SIZE(w_iov_), w_len,
                LENGTH_OF(w0_c), w0_d, w0_c,
                LENGTH_OF(w1_c), w1_d, w1_c,
                LENGTH_OF(w2_c), w2_d, w2_c);
@@ -127,7 +127,8 @@ main(void)
                ", msg_controllen=0, msg_flags=0}, 0) = %u\n"
                " * %u bytes in buffer 0\n"
                " | 00000 %-49s  %-16s |\n",
-               r0_c, r_len, ARRAY_SIZE(r0_iov_), r_len, r_len, r0_d, r0_c);
+               r0_c, r_len, (unsigned int) ARRAY_SIZE(r0_iov_),
+               r_len, r_len, r0_d, r0_c);
 
        void *r1 = tail_alloc(r_len);
        void *r2 = tail_alloc(w_len);
@@ -151,8 +152,8 @@ main(void)
                ", msg_iovlen=%u, msg_controllen=0, msg_flags=0}, 0) = %u\n"
                " * %u bytes in buffer 0\n"
                " | 00000 %-49s  %-16s |\n",
-               r1_c, r_len, w_len, ARRAY_SIZE(r1_iov_), w_len - r_len,
-               w_len - r_len, r1_d, r1_c);
+               r1_c, r_len, w_len, (unsigned int) ARRAY_SIZE(r1_iov_),
+               w_len - r_len, w_len - r_len, r1_d, r1_c);
        close(0);
 
        tprintf("+++ exited with 0 +++\n");
index 199d21a603e3b5dde34a8709e57d88e847bdde1f..00d10eaec10645dd102531c4243b774610f2f2c8 100644 (file)
@@ -36,6 +36,7 @@
 # include <sys/types.h>
 # include "kernel_types.h"
 # include "gcc_compat.h"
+# include "macros.h"
 
 /*
  * The printf-like function to use in header files
@@ -198,7 +199,6 @@ f8ill_ptr_to_kulong(const void *const ptr)
               ? F8ILL_KULONG_MASK | uptr : (kernel_ulong_t) uptr;
 }
 
-# define ARRAY_SIZE(arg) ((unsigned int) (sizeof(arg) / sizeof((arg)[0])))
 # define LENGTH_OF(arg) ((unsigned int) sizeof(arg) - 1)
 
 /* Zero-extend a signed integer type to unsigned long long. */
index f29962e3d5bbf4706b3a609da61d8dd983b59b7d..4242d9e6f15774a13076cd9ddc297641a26e9909 100644 (file)
@@ -86,7 +86,7 @@ main(void)
                " * %u bytes in buffer 2\n"
                " | 00000 %-49s  %-16s |\n",
                w0_c, LENGTH_OF(w0_c), w1_c, LENGTH_OF(w1_c),
-               w2_c, LENGTH_OF(w2_c), ARRAY_SIZE(iov_),
+               w2_c, LENGTH_OF(w2_c), (unsigned int) ARRAY_SIZE(iov_),
                "SPLICE_F_NONBLOCK", len,
                LENGTH_OF(w0_c), w0_d, w0_c,
                LENGTH_OF(w1_c), w1_d, w1_c, LENGTH_OF(w2_c), w2_d, w2_c);