This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] lib: Provide MAX and MIN in system.h


This change also creates a new header file libeu.h to provide the
prototypes for the function of libeu. That hides the definition of function
crc32, which can conflict with zlib, from libelf. It also prevents mistakes
to refer those functions from a component which doesn't link with libeu,
such as libelf.

Signed-off-by: Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>
---
 lib/Makefile.am                      |  4 +-
 lib/color.c                          |  2 +-
 lib/crc32_file.c                     |  2 +-
 lib/fixedsizehash.h                  |  1 -
 lib/libeu.h                          | 78 ++++++++++++++++++++++++++++++++++++
 lib/system.h                         | 48 ++++------------------
 lib/xstrdup.c                        |  2 +-
 lib/xstrndup.c                       |  3 +-
 libasm/asm_align.c                   |  1 -
 libcpu/i386_lex.l                    |  2 +-
 libcpu/i386_parse.y                  |  2 +-
 libdwelf/dwelf_strtab.c              |  5 ---
 libdwfl/core-file.c                  |  1 -
 libdwfl/dwfl_segment_report_module.c |  7 +---
 libdwfl/frame_unwind.c               |  5 +--
 libdwfl/linux-core-attach.c          |  4 --
 libdwfl/linux-pid-attach.c           |  4 --
 libelf/elf32_updatefile.c            |  1 -
 libelf/elf32_updatenull.c            |  2 +-
 libelf/elf_begin.c                   |  1 -
 libelf/elf_compress.c                |  6 +--
 src/arlib.c                          |  2 +-
 src/elfcompress.c                    |  1 +
 src/elflint.c                        |  2 +-
 src/nm.c                             |  2 +-
 src/objdump.c                        |  1 +
 src/readelf.c                        |  2 +-
 src/size.c                           |  1 -
 src/strings.c                        |  2 +-
 src/strip.c                          |  1 +
 src/unstrip.c                        |  1 +
 31 files changed, 108 insertions(+), 88 deletions(-)
 create mode 100644 lib/libeu.h

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 2219eaa..7ca2bd4 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -37,8 +37,8 @@ libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \
 		  crc32.c crc32_file.c md5.c sha1.c \
 		  color.c
 
-noinst_HEADERS = fixedsizehash.h system.h dynamicsizehash.h list.h md5.h \
-		 sha1.h eu-config.h
+noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \
+		 md5.h sha1.h eu-config.h
 EXTRA_DIST = dynamicsizehash.c
 
 if !GPROF
diff --git a/lib/color.c b/lib/color.c
index d1309ed..fde2d9d 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -37,7 +37,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include "system.h"
+#include "libeu.h"
 
 
 /* Prototype for option handler.  */
diff --git a/lib/crc32_file.c b/lib/crc32_file.c
index c0b18e9..a8434d4 100644
--- a/lib/crc32_file.c
+++ b/lib/crc32_file.c
@@ -30,7 +30,7 @@
 # include <config.h>
 #endif
 
-#include "system.h"
+#include "libeu.h"
 #include <errno.h>
 #include <unistd.h>
 #include <sys/stat.h>
diff --git a/lib/fixedsizehash.h b/lib/fixedsizehash.h
index 06ce6a2..18921a4 100644
--- a/lib/fixedsizehash.h
+++ b/lib/fixedsizehash.h
@@ -31,7 +31,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/cdefs.h>
-#include <sys/param.h>
 
 #include <system.h>
 
diff --git a/lib/libeu.h b/lib/libeu.h
new file mode 100644
index 0000000..69fe3d7
--- /dev/null
+++ b/lib/libeu.h
@@ -0,0 +1,78 @@
+/* Declarations for the common library.
+   Copyright (C) 2006-2011 Red Hat, Inc.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils 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 copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef LIBEU_H
+#define LIBEU_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+extern void *xmalloc (size_t) __attribute__ ((__malloc__));
+extern void *xcalloc (size_t, size_t) __attribute__ ((__malloc__));
+extern void *xrealloc (void *, size_t) __attribute__ ((__malloc__));
+
+extern char *xstrdup (const char *) __attribute__ ((__malloc__));
+extern char *xstrndup (const char *, size_t) __attribute__ ((__malloc__));
+
+
+extern uint32_t crc32 (uint32_t crc, unsigned char *buf, size_t len);
+extern int crc32_file (int fd, uint32_t *resp);
+
+
+/* Color handling.  */
+
+/* Command line parser.  */
+extern const struct argp color_argp;
+
+/* Coloring mode.  */
+enum color_enum
+  {
+    color_never = 0,
+    color_always,
+    color_auto
+  } __attribute__ ((packed));
+extern enum color_enum color_mode;
+
+/* Colors to use for the various components.  */
+extern char *color_address;
+extern char *color_bytes;
+extern char *color_mnemonic;
+extern char *color_operand1;
+extern char *color_operand2;
+extern char *color_operand3;
+extern char *color_label;
+extern char *color_undef;
+extern char *color_undef_tls;
+extern char *color_undef_weak;
+extern char *color_symbol;
+extern char *color_tls;
+extern char *color_weak;
+
+extern const char color_off[];
+
+#endif
diff --git a/lib/system.h b/lib/system.h
index f31cfd0..ec387c3 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -32,6 +32,7 @@
 #include <argp.h>
 #include <stddef.h>
 #include <stdint.h>
+#include <sys/param.h>
 #include <endian.h>
 #include <byteswap.h>
 #include <unistd.h>
@@ -50,16 +51,14 @@
 # error "Unknown byte order"
 #endif
 
-extern void *xmalloc (size_t) __attribute__ ((__malloc__));
-extern void *xcalloc (size_t, size_t) __attribute__ ((__malloc__));
-extern void *xrealloc (void *, size_t) __attribute__ ((__malloc__));
-
-extern char *xstrdup (const char *) __attribute__ ((__malloc__));
-extern char *xstrndup (const char *, size_t) __attribute__ ((__malloc__));
+#ifndef MAX
+#define MAX(m, n) ((m) < (n) ? (n) : (m))
+#endif
 
+#ifndef MIN
+#define MIN(m, n) ((m) < (n) ? (m) : (n))
+#endif
 
-extern uint32_t crc32 (uint32_t crc, unsigned char *buf, size_t len);
-extern int crc32_file (int fd, uint32_t *resp);
 
 /* A special gettext function we use if the strings are too short.  */
 #define sgettext(Str) \
@@ -142,39 +141,6 @@ pread_retry (int fd, void *buf, size_t len, off_t off)
 extern char *__cxa_demangle (const char *mangled_name, char *output_buffer,
 			     size_t *length, int *status);
 
-
-
-/* Color handling.  */
-
-/* Command line parser.  */
-extern const struct argp color_argp;
-
-/* Coloring mode.  */
-enum color_enum
-  {
-    color_never = 0,
-    color_always,
-    color_auto
-  } __attribute__ ((packed));
-extern enum color_enum color_mode;
-
-/* Colors to use for the various components.  */
-extern char *color_address;
-extern char *color_bytes;
-extern char *color_mnemonic;
-extern char *color_operand1;
-extern char *color_operand2;
-extern char *color_operand3;
-extern char *color_label;
-extern char *color_undef;
-extern char *color_undef_tls;
-extern char *color_undef_weak;
-extern char *color_symbol;
-extern char *color_tls;
-extern char *color_weak;
-
-extern const char color_off[];
-
 /* A static assertion.  This will cause a compile-time error if EXPR,
    which must be a compile-time constant, is false.  */
 
diff --git a/lib/xstrdup.c b/lib/xstrdup.c
index aa10352..ff1e3d4 100644
--- a/lib/xstrdup.c
+++ b/lib/xstrdup.c
@@ -31,7 +31,7 @@
 #endif
 
 #include <string.h>
-#include "system.h"
+#include "libeu.h"
 
 
 /* Return a newly allocated copy of STRING.  */
diff --git a/lib/xstrndup.c b/lib/xstrndup.c
index 92b79c1..d43e3b9 100644
--- a/lib/xstrndup.c
+++ b/lib/xstrndup.c
@@ -30,8 +30,9 @@
 # include <config.h>
 #endif
 
+#include <stdint.h>
 #include <string.h>
-#include "system.h"
+#include "libeu.h"
 
 
 /* Return a newly allocated copy of STRING.  */
diff --git a/libasm/asm_align.c b/libasm/asm_align.c
index 6631c4d..e59a070 100644
--- a/libasm/asm_align.c
+++ b/libasm/asm_align.c
@@ -33,7 +33,6 @@
 
 #include <inttypes.h>
 #include <stdlib.h>
-#include <sys/param.h>
 
 #include <libasmP.h>
 #include <system.h>
diff --git a/libcpu/i386_lex.l b/libcpu/i386_lex.l
index 1e10dd7..ef1b53b 100644
--- a/libcpu/i386_lex.l
+++ b/libcpu/i386_lex.l
@@ -34,7 +34,7 @@
 #include <error.h>
 #include <libintl.h>
 
-#include <system.h>
+#include <libeu.h>
 #include "i386_parse.h"
 
 
diff --git a/libcpu/i386_parse.y b/libcpu/i386_parse.y
index 689ba22..15a72b1 100644
--- a/libcpu/i386_parse.y
+++ b/libcpu/i386_parse.y
@@ -44,8 +44,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/param.h>
 
+#include <libeu.h>
 #include <system.h>
 
 #define obstack_chunk_alloc xmalloc
diff --git a/libdwelf/dwelf_strtab.c b/libdwelf/dwelf_strtab.c
index c1b93d4..01e091c 100644
--- a/libdwelf/dwelf_strtab.c
+++ b/libdwelf/dwelf_strtab.c
@@ -38,15 +38,10 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <sys/param.h>
 
 #include "libdwelfP.h"
 #include <system.h>
 
-#ifndef MIN
-# define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
-
 
 struct Dwelf_Strent
 {
diff --git a/libdwfl/core-file.c b/libdwfl/core-file.c
index 67684c9..84cb89a 100644
--- a/libdwfl/core-file.c
+++ b/libdwfl/core-file.c
@@ -32,7 +32,6 @@
 #include "libdwflP.h"
 #include <gelf.h>
 
-#include <sys/param.h>
 #include <unistd.h>
 #include <endian.h>
 #include <byteswap.h>
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 40553c9..207a257 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -35,11 +35,12 @@
 #include <elf.h>
 #include <gelf.h>
 #include <inttypes.h>
-#include <sys/param.h>
 #include <endian.h>
 #include <unistd.h>
 #include <fcntl.h>
 
+#include <system.h>
+
 
 /* A good size for the initial read from memory, if it's not too costly.
    This more than covers the phdrs and note segment in the average 64-bit
@@ -53,10 +54,6 @@
 # define MY_ELFDATA	ELFDATA2MSB
 #endif
 
-#ifndef MAX
-# define MAX(a, b) ((a) > (b) ? (a) : (b))
-#endif
-
 
 /* Return user segment index closest to ADDR but not above it.
    If NEXT, return the closest to ADDR but not below it.  */
diff --git a/libdwfl/frame_unwind.c b/libdwfl/frame_unwind.c
index a885446..fb42c1a 100644
--- a/libdwfl/frame_unwind.c
+++ b/libdwfl/frame_unwind.c
@@ -35,6 +35,7 @@
 #include "libdwflP.h"
 #include "../libdw/dwarf.h"
 #include <sys/ptrace.h>
+#include <system.h>
 
 /* Maximum number of DWARF expression stack slots before returning an error.  */
 #define DWARF_EXPR_STACK_MAX 0x100
@@ -43,10 +44,6 @@
    error.  */
 #define DWARF_EXPR_STEPS_MAX 0x1000
 
-#ifndef MAX
-# define MAX(a, b) ((a) > (b) ? (a) : (b))
-#endif
-
 bool
 internal_function
 __libdwfl_frame_reg_get (Dwfl_Frame *state, unsigned regno, Dwarf_Addr *val)
diff --git a/libdwfl/linux-core-attach.c b/libdwfl/linux-core-attach.c
index 5a7b3b3..93d0e46 100644
--- a/libdwfl/linux-core-attach.c
+++ b/libdwfl/linux-core-attach.c
@@ -32,10 +32,6 @@
 
 #include "../libdw/memory-access.h"
 
-#ifndef MIN
-# define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
-
 struct core_arg
 {
   Elf *core;
diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c
index c13f2b6..adfc7f8 100644
--- a/libdwfl/linux-pid-attach.c
+++ b/libdwfl/linux-pid-attach.c
@@ -37,10 +37,6 @@
 #include <sys/syscall.h>
 #include <unistd.h>
 
-#ifndef MAX
-# define MAX(a, b) ((a) > (b) ? (a) : (b))
-#endif
-
 #ifdef __linux__
 
 static bool
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c
index d0fabb1..8dd85d1 100644
--- a/libelf/elf32_updatefile.c
+++ b/libelf/elf32_updatefile.c
@@ -39,7 +39,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/mman.h>
-#include <sys/param.h>
 
 #include <system.h>
 #include "libelfP.h"
diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c
index 939aa13..d83c0b3 100644
--- a/libelf/elf32_updatenull.c
+++ b/libelf/elf32_updatenull.c
@@ -36,8 +36,8 @@
 #include <libelf.h>
 #include <stdbool.h>
 #include <string.h>
-#include <sys/param.h>
 
+#include <system.h>
 #include "libelfP.h"
 #include "elf-knowledge.h"
 
diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
index 147f5f4..8fdb376 100644
--- a/libelf/elf_begin.c
+++ b/libelf/elf_begin.c
@@ -40,7 +40,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/mman.h>
-#include <sys/param.h>
 #include <sys/stat.h>
 
 #include <system.h>
diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c
index 3aebe82..dac0ac6 100644
--- a/libelf/elf_compress.c
+++ b/libelf/elf_compress.c
@@ -31,20 +31,16 @@
 #endif
 
 #include <libelf.h>
+#include <system.h>
 #include "libelfP.h"
 #include "common.h"
 
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/param.h>
 #include <unistd.h>
 #include <zlib.h>
 
-#ifndef MAX
-# define MAX(a, b) ((a) > (b) ? (a) : (b))
-#endif
-
 /* Cleanup and return result.  Don't leak memory.  */
 static void *
 do_deflate_cleanup (void *result, z_stream *z, void *out_buf,
diff --git a/src/arlib.c b/src/arlib.c
index 43a9145..c3cf47f 100644
--- a/src/arlib.c
+++ b/src/arlib.c
@@ -28,7 +28,7 @@
 #include <stdlib.h>
 #include <time.h>
 
-#include <system.h>
+#include <libeu.h>
 
 #include "arlib.h"
 
diff --git a/src/elfcompress.c b/src/elfcompress.c
index 86cc716..7392cb7 100644
--- a/src/elfcompress.c
+++ b/src/elfcompress.c
@@ -34,6 +34,7 @@
 #include ELFUTILS_HEADER(ebl)
 #include ELFUTILS_HEADER(dwelf)
 #include <gelf.h>
+#include "libeu.h"
 #include "system.h"
 
 /* Name and version of program.  */
diff --git a/src/elflint.c b/src/elflint.c
index 8c298c9..8b52ee2 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -35,9 +35,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/stat.h>
-#include <sys/param.h>
 
 #include <elf-knowledge.h>
+#include <libeu.h>
 #include <system.h>
 #include "../libelf/libelfP.h"
 #include "../libelf/common.h"
diff --git a/src/nm.c b/src/nm.c
index 010469d..37e54bf 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -41,8 +41,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <sys/param.h>
 
+#include <libeu.h>
 #include <system.h>
 #include "../libebl/libeblP.h"
 #include "../libdwfl/libdwflP.h"
diff --git a/src/objdump.c b/src/objdump.c
index 0aa41e8..a98fa56 100644
--- a/src/objdump.c
+++ b/src/objdump.c
@@ -34,6 +34,7 @@
 #include <unistd.h>
 #include <sys/param.h>
 
+#include <libeu.h>
 #include <system.h>
 #include "../libebl/libeblP.h"
 
diff --git a/src/readelf.c b/src/readelf.c
index f157290..204aeec 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -40,10 +40,10 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
-#include <sys/param.h>
 #include <sys/stat.h>
 #include <signal.h>
 
+#include <libeu.h>
 #include <system.h>
 #include "../libelf/libelfP.h"
 #include "../libelf/common.h"
diff --git a/src/size.c b/src/size.c
index 7c03cce..b98674c 100644
--- a/src/size.c
+++ b/src/size.c
@@ -34,7 +34,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <sys/param.h>
 
 #include <system.h>
 
diff --git a/src/strings.c b/src/strings.c
index c1d63cd..a4ffcbe 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -38,9 +38,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/mman.h>
-#include <sys/param.h>
 #include <sys/stat.h>
 
+#include <libeu.h>
 #include <system.h>
 
 #ifndef MAP_POPULATE
diff --git a/src/strip.c b/src/strip.c
index da093e9..e63dc9a 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -43,6 +43,7 @@
 #include <elf-knowledge.h>
 #include <libebl.h>
 #include "libdwelf.h"
+#include <libeu.h>
 #include <system.h>
 
 typedef uint8_t GElf_Byte;
diff --git a/src/unstrip.c b/src/unstrip.c
index 4673738..3bf4b19 100644
--- a/src/unstrip.c
+++ b/src/unstrip.c
@@ -49,6 +49,7 @@
 #include <libebl.h>
 #include <libdwfl.h>
 #include "libdwelf.h"
+#include "libeu.h"
 #include "system.h"
 
 #ifndef _
-- 
2.10.0

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]