From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org
Subject: [committed] Add util.h
Date: Fri, 9 Apr 2021 17:15:38 +0200 [thread overview]
Message-ID: <20210409151536.GA21626@delia> (raw)
Hi,
Factor out utility macros into new file util.h.
Committed to trunk.
Thanks,
- Tom
Add util.h
2021-04-09 Tom de Vries <tdevries@suse.de>
* args.c (IMPLIES): Remove.
* dwz.c (pool_alloc): Use ALIGNOF_STRUCT.
(USE_GNUC, likely, unlikely, FORCE_INLINE, UNUSED, USED, IMPLIES):
(MAX, MIN, ALIGN_STRUCT): Move ...
* util.h: ... here. New file. Add ALIGNOF_STRUCT.
---
args.c | 2 +-
dwz.c | 46 +++-------------------------------------------
util.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 64 insertions(+), 44 deletions(-)
diff --git a/args.c b/args.c
index 23bf1d4..cb11f25 100644
--- a/args.c
+++ b/args.c
@@ -31,7 +31,7 @@
#include "args.h"
-#define IMPLIES(A, B) (!((A) && !(B)))
+#include "util.h"
#if DEVEL
int tracing;
diff --git a/dwz.c b/dwz.c
index dfae64f..07c576e 100644
--- a/dwz.c
+++ b/dwz.c
@@ -43,14 +43,7 @@
#include "hashtab.h"
#include "sha1.h"
#include "args.h"
-
-#ifndef USE_GNUC
-#ifdef __GNUC__
-#define USE_GNUC 1
-#else
-#define USE_GNUC 0
-#endif
-#endif
+#include "util.h"
#ifndef SHF_COMPRESSED
/* Glibc elf.h contains SHF_COMPRESSED starting v2.22. Libelf libelf.h has
@@ -118,29 +111,6 @@
# define NT_GNU_BUILD_ID 3
#endif
-#if USE_GNUC && __GNUC__ >= 3
-# define likely(x) __builtin_expect (!!(x), 1)
-# define unlikely(x) __builtin_expect (!!(x), 0)
-#else
-# define likely(x) (x)
-# define unlikely(x) (x)
-#endif
-
-#if USE_GNUC
-# define FORCE_INLINE __attribute__((always_inline))
-# define UNUSED __attribute__((unused))
-# define USED __attribute__((used))
-#else
-# define FORCE_INLINE
-# define UNUSED
-# define USED
-#endif
-
-/* Utility macro. */
-#define IMPLIES(A, B) (!((A) && !(B)))
-#define MAX(A, B) ((A) > (B) ? (A) : (B))
-#define MIN(A, B) ((A) < (B) ? (A) : (B))
-
/* Print memory amount M (in kb) in both exact and human readable, like so:
1382508 (1.3G). */
static void
@@ -1129,11 +1099,6 @@ die_cu (dw_die_ref die)
#define die_safe_nextdup(die) \
((die)->die_toplevel ? (die)->die_nextdup : (dw_die_ref) NULL)
-#if USE_GNUC
-# define ALIGN_STRUCT(name)
-#else
-# define ALIGN_STRUCT(name) struct align_##name { char c; struct name s; };
-#endif
ALIGN_STRUCT (abbrev_tag)
ALIGN_STRUCT (dw_file)
ALIGN_STRUCT (dw_cu)
@@ -1194,13 +1159,8 @@ pool_destroy (void)
}
}
-#if USE_GNUC
-# define pool_alloc(name, size) \
- (struct name *) pool_alloc_1 (__alignof__ (struct name), size)
-#else
-# define pool_alloc(name, size) \
- (struct name *) pool_alloc_1 (offsetof (struct align_##name, s), size)
-#endif
+#define pool_alloc(name, size) \
+ (struct name *) pool_alloc_1 (ALIGNOF_STRUCT (name), size)
static struct abbrev_tag *
pool_clone_abbrev (struct abbrev_tag *t)
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..7caac06
--- /dev/null
+++ b/util.h
@@ -0,0 +1,60 @@
+/* Copyright (C) 2001-2021 Red Hat, Inc.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2019-2021 SUSE LLC.
+ Written by Jakub Jelinek <jakub@redhat.com>, 2012.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, 51 Franklin Street - Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+/* Utility macros. */
+
+#define IMPLIES(A, B) (!((A) && !(B)))
+
+#define MAX(A, B) ((A) > (B) ? (A) : (B))
+#define MIN(A, B) ((A) < (B) ? (A) : (B))
+
+#ifndef USE_GNUC
+#ifdef __GNUC__
+#define USE_GNUC 1
+#else
+#define USE_GNUC 0
+#endif
+#endif
+
+#if USE_GNUC && __GNUC__ >= 3
+# define likely(x) __builtin_expect (!!(x), 1)
+# define unlikely(x) __builtin_expect (!!(x), 0)
+#else
+# define likely(x) (x)
+# define unlikely(x) (x)
+#endif
+
+#if USE_GNUC
+# define FORCE_INLINE __attribute__((always_inline))
+# define UNUSED __attribute__((unused))
+# define USED __attribute__((used))
+#else
+# define FORCE_INLINE
+# define UNUSED
+# define USED
+#endif
+
+#if USE_GNUC
+# define ALIGN_STRUCT(name)
+# define ALIGNOF_STRUCT(name) __alignof__ (struct name)
+#else
+# define ALIGN_STRUCT(name) struct align_##name { char c; struct name s; };
+# define ALIGNOF_STRUCT(name) offsetof (struct align_##name, s)
+#endif
reply other threads:[~2021-04-09 15:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210409151536.GA21626@delia \
--to=tdevries@suse.de \
--cc=dwz@sourceware.org \
--cc=jakub@redhat.com \
--cc=mark@klomp.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).