[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
xalloc.h drags in dependencies
From: |
Eric Blake |
Subject: |
xalloc.h drags in dependencies |
Date: |
Sat, 14 Nov 2009 07:30:56 -0700 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I was surprised when I got a link failure when using the Solaris cc on
test-chown.c due to missing program_name, even though using gcc did just
fine. It turns out that mgetgroups.c uses xalloc_oversized from
"xalloc.h", which is only a macro and by itself drags nothing in; but the
rest of xalloc.h includes four inline functions which in turn drag in
references to xalloc_die, error, program_name, and thus the link failure.
I thought about changing the #if HAVE_INLINE part of xalloc.h to instead
be #if HAVE_INLINE && defined __GNUC__, but this penalizes other
compilers. I don't want to just open-code xalloc_oversized into
mgetgroups.c. So my idea was to move the one portion of xalloc.h that
does not depend on xalloc_die into a header that is already LGPL; that
way, mgetgroups would depend only on xsize, not xalloc. So, how does this
patch look?
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEUEARECAAYFAkr+vyAACgkQ84KuGfSFAYBDUQCXaDqUzoyhSbyITU9+xg//Ny/g
NgCcC1BMCjY02xtKSwAey4JQD3KSI0w=
=64dy
-----END PGP SIGNATURE-----
>From 2540d680580bcdde870fc24aa748f0c749f02d8d Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Sat, 14 Nov 2009 07:24:39 -0700
Subject: [PATCH 1/2] xalloc: move xalloc_oversized to xsize
xalloc_oversized was the only thing in xalloc.h that did not
depend on xalloc_die. But due to inline functions in xalloc.h,
Solaris cc gives a link failure if you use only xalloc_oversized
and don't provide xalloc_die. Moving it to the LGPL header
xsize.h can allow other modules to break the link dependency.
* modules/xalloc (Depends-on): Add xsize.
* lib/xalloc.h (xalloc_oversized): Move...
* lib/xsize.h: ...here.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 7 +++++++
lib/xalloc.h | 19 +++----------------
lib/xsize.h | 17 ++++++++++++++++-
modules/xalloc | 1 +
4 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5fbff63..5ddacae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-11-14 Eric Blake <address@hidden>
+
+ xalloc: move xalloc_oversized to xsize
+ * modules/xalloc (Depends-on): Add xsize.
+ * lib/xalloc.h (xalloc_oversized): Move...
+ * lib/xsize.h: ...here.
+
2009-11-14 Robert Millan <address@hidden> (tiny change)
gnulib-tool: correctly detect absence of m4 directories
diff --git a/lib/xalloc.h b/lib/xalloc.h
index 57a13e0..b3166b4 100644
--- a/lib/xalloc.h
+++ b/lib/xalloc.h
@@ -1,7 +1,8 @@
/* xalloc.h -- malloc with out-of-memory checking
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
+ 1999, 2000, 2003, 2004, 2006, 2007, 2008, 2009 Free Software
+ Foundation, Inc.
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
@@ -21,6 +22,7 @@
# include <stddef.h>
+# include "xsize.h" /* for xalloc_oversized */
# ifdef __cplusplus
extern "C" {
@@ -60,21 +62,6 @@ void *x2realloc (void *p, size_t *pn);
void *xmemdup (void const *p, size_t s) ATTRIBUTE_MALLOC;
char *xstrdup (char const *str) ATTRIBUTE_MALLOC;
-/* Return 1 if an array of N objects, each of size S, cannot exist due
- to size arithmetic overflow. S must be positive and N must be
- nonnegative. This is a macro, not an inline function, so that it
- works correctly even when SIZE_MAX < N.
-
- By gnulib convention, SIZE_MAX represents overflow in size
- calculations, so the conservative dividend to use here is
- SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
- However, malloc (SIZE_MAX) fails on all known hosts where
- sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
- exactly-SIZE_MAX allocations on such hosts; this avoids a test and
- branch when S is known to be 1. */
-# define xalloc_oversized(n, s) \
- ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
-
/* In the following macros, T must be an elementary or structure/union or
typedef'ed type, or a pointer to such a type. To apply one of the
diff --git a/lib/xsize.h b/lib/xsize.h
index 2d99a6b..34bd778 100644
--- a/lib/xsize.h
+++ b/lib/xsize.h
@@ -1,6 +1,6 @@
/* xsize.h -- Checked size_t computations.
- Copyright (C) 2003, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2008, 2009 Free Software Foundation, Inc.
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
@@ -105,4 +105,19 @@ xmax (size_t size1, size_t size2)
#define size_in_bounds_p(SIZE) \
((SIZE) != SIZE_MAX)
+/* Return 1 if an array of N objects, each of size S, cannot exist due
+ to size arithmetic overflow. S must be positive and N must be
+ nonnegative. This is a macro, not an inline function, so that it
+ works correctly even when SIZE_MAX < N.
+
+ By gnulib convention, SIZE_MAX represents overflow in size
+ calculations, so the conservative dividend to use here is
+ SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
+ However, malloc (SIZE_MAX) fails on all known hosts where
+ sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
+ exactly-SIZE_MAX allocations on such hosts; this avoids a test and
+ branch when S is known to be 1. */
+#define xalloc_oversized(n, s) \
+ ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
+
#endif /* _XSIZE_H */
diff --git a/modules/xalloc b/modules/xalloc
index 43ee942..9ecffc5 100644
--- a/modules/xalloc
+++ b/modules/xalloc
@@ -9,6 +9,7 @@ m4/xalloc.m4
Depends-on:
inline
xalloc-die
+xsize
configure.ac:
gl_XALLOC
--
1.6.5.rc1
>From e5fe139b57709964c80f77f7388dcce7c595dd0d Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Sat, 14 Nov 2009 07:27:24 -0700
Subject: [PATCH 2/2] mgetgroups: reduce dependencies
mgetgroups doesn't use xalloc_die, just xalloc_oversized.
* modules/mgetgroups (Depends-on): Use xsize, not xalloc.
* lib/mgetgroups.c (includes): Likewise.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 4 ++++
lib/mgetgroups.c | 2 +-
modules/mgetgroups | 2 +-
3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5ddacae..5bcbd3d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2009-11-14 Eric Blake <address@hidden>
+ mgetgroups: reduce dependencies
+ * modules/mgetgroups (Depends-on): Use xsize, not xalloc.
+ * lib/mgetgroups.c (includes): Likewise.
+
xalloc: move xalloc_oversized to xsize
* modules/xalloc (Depends-on): Add xsize.
* lib/xalloc.h (xalloc_oversized): Move...
diff --git a/lib/mgetgroups.c b/lib/mgetgroups.c
index f68e28f..74fa10f 100644
--- a/lib/mgetgroups.c
+++ b/lib/mgetgroups.c
@@ -31,7 +31,7 @@
#endif
#include "getugroups.h"
-#include "xalloc.h"
+#include "xsize.h"
static gid_t *
realloc_groupbuf (gid_t *g, size_t num)
diff --git a/modules/mgetgroups b/modules/mgetgroups
index 58ef740..acc802e 100644
--- a/modules/mgetgroups
+++ b/modules/mgetgroups
@@ -9,7 +9,7 @@ m4/mgetgroups.m4
Depends-on:
getgroups
getugroups
-xalloc
+xsize
configure.ac:
gl_MGETGROUPS
--
1.6.5.rc1
- xalloc.h drags in dependencies,
Eric Blake <=