[glib] Fix usage of _GNU_SOURCE
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Fix usage of _GNU_SOURCE
- Date: Tue, 3 May 2011 11:09:07 +0000 (UTC)
commit e56498ee0b1bdac0ad3c18a1f7bff83d4a5b1323
Author: Dan Winship <danw gnome org>
Date: Sun May 1 11:17:14 2011 -0400
Fix usage of _GNU_SOURCE
_GNU_SOURCE must be defined before including any other (system)
header, so defining it in glib-unix.h (and hoping no one has included
anything else before that) is wrong. And the "#define _USE_GNU"
workaround for this problem in gnetworkingprivate.h is even wronger
(and still prone to failure anyway due to single-include guards).
Fix this by defining _GNU_SOURCE in config.h when building against
glibc. In theory this is bad because new releases of glibc may include
symbols that conflict with glib symbols, which could then cause
compile failures. However, most people only see new releases of glibc
when they upgrade their distro, at which point they also generally get
new releases of gcc, which have new warnings/errors to clean up
anyway.
https://bugzilla.gnome.org/show_bug.cgi?id=649201
configure.ac | 6 ++++--
gio/gfile.c | 1 -
gio/glib-compile-schemas.c | 1 -
gio/glocalfileinfo.c | 1 -
gio/gnetworkingprivate.h | 22 ++++------------------
gio/gsettings.c | 1 -
gio/gunixcredentialsmessage.c | 2 --
gio/gunixfdlist.c | 2 --
gio/libasyncns/g-asyncns.h | 2 --
gio/tests/gdbus-peer.c | 2 ++
glib/glib-unix.h | 8 --------
glib/gmain.c | 15 ---------------
glib/gprintf.c | 4 ----
glib/gqsort.c | 1 -
glib/gslice.c | 2 +-
glib/gstrfuncs.c | 2 --
16 files changed, 11 insertions(+), 61 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a44c77a..378b082 100644
--- a/configure.ac
+++ b/configure.ac
@@ -206,6 +206,10 @@ if test "x$glib_have_carbon" = "xyes"; then
LDFLAGS="$LDFLAGS -framework Carbon"
fi
+gl_GLIBC21
+if test "x$GLIBC21" = "xyes"; then
+ AC_DEFINE([_GNU_SOURCE], 1, [Make all glibc extensions visible])
+fi
dnl declare --enable-* args and collect ac_help strings
AC_ARG_ENABLE(debug,
@@ -412,7 +416,6 @@ else
fi
fi
-gl_GLIBC21
AC_ARG_ENABLE(iconv-cache,
[AC_HELP_STRING([--enable-iconv-cache=@<:@yes/no/auto@:>@],
[cache iconv descriptors [default=auto]])],,
@@ -929,7 +932,6 @@ AC_CHECK_MEMBERS([struct tm.tm_gmtoff, struct tm.__tm_gmtoff],,,[#include <time.
# Checks for libcharset
AM_LANGINFO_CODESET
-gl_GLIBC21
AC_CHECK_HEADERS([stddef.h stdlib.h string.h])
AC_CHECK_FUNCS(setlocale)
diff --git a/gio/gfile.c b/gio/gfile.c
index 4cecc8a..a5d00fe 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -24,7 +24,6 @@
#include "config.h"
#ifdef HAVE_SPLICE
-#define _GNU_SOURCE
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
diff --git a/gio/glib-compile-schemas.c b/gio/glib-compile-schemas.c
index a301dff..7369c67 100644
--- a/gio/glib-compile-schemas.c
+++ b/gio/glib-compile-schemas.c
@@ -20,7 +20,6 @@
*/
/* Prologue {{{1 */
-#define _GNU_SOURCE
#include "config.h"
#include <gstdio.h>
diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c
index 5e4def7..6c1fe20 100644
--- a/gio/glocalfileinfo.c
+++ b/gio/glocalfileinfo.c
@@ -33,7 +33,6 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#define _GNU_SOURCE
#include <fcntl.h>
#include <errno.h>
#ifdef HAVE_GRP_H
diff --git a/gio/gnetworkingprivate.h b/gio/gnetworkingprivate.h
index 92d2645..d38928b 100644
--- a/gio/gnetworkingprivate.h
+++ b/gio/gnetworkingprivate.h
@@ -40,38 +40,24 @@
#else /* !G_OS_WIN32 */
-/* need this for struct ucred on Linux */
-#ifdef __linux__
-#define __USE_GNU
#include <sys/types.h>
-#include <sys/socket.h>
-#undef __USE_GNU
-#endif
-#include <sys/types.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#if defined(HAVE_ARPA_NAMESER_COMPAT_H) && !defined(GETSHORT)
#include <arpa/nameser_compat.h>
#endif
-
-#ifndef T_SRV
-#define T_SRV 33
-#endif
-
-/* We're supposed to define _GNU_SOURCE to get EAI_NODATA, but that
- * won't actually work since <features.h> has already been included at
- * this point. So we define __USE_GNU instead.
- */
-#define __USE_GNU
#include <netdb.h>
-#undef __USE_GNU
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <resolv.h>
#include <sys/socket.h>
#include <sys/un.h>
+#ifndef T_SRV
+#define T_SRV 33
+#endif
+
#ifndef _PATH_RESCONF
#define _PATH_RESCONF "/etc/resolv.conf"
#endif
diff --git a/gio/gsettings.c b/gio/gsettings.c
index 275edf1..e75d5b8 100644
--- a/gio/gsettings.c
+++ b/gio/gsettings.c
@@ -20,7 +20,6 @@
*/
/* Prelude {{{1 */
-#define _GNU_SOURCE
#include "config.h"
#include <glib.h>
diff --git a/gio/gunixcredentialsmessage.c b/gio/gunixcredentialsmessage.c
index a1094be..8658b67 100644
--- a/gio/gunixcredentialsmessage.c
+++ b/gio/gunixcredentialsmessage.c
@@ -37,8 +37,6 @@
/* ---------------------------------------------------------------------------------------------------- */
#ifdef __linux__
-
-#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
diff --git a/gio/gunixfdlist.c b/gio/gunixfdlist.c
index 0348512..b92238f 100644
--- a/gio/gunixfdlist.c
+++ b/gio/gunixfdlist.c
@@ -31,8 +31,6 @@
* <filename>gio-unix-2.0.pc</filename> pkg-config file when using it.
*/
-#define _GNU_SOURCE /* for F_DUPFD_CLOEXEC */
-
#include "config.h"
#include <sys/types.h>
diff --git a/gio/libasyncns/g-asyncns.h b/gio/libasyncns/g-asyncns.h
index a8fbf46..8a526d1 100644
--- a/gio/libasyncns/g-asyncns.h
+++ b/gio/libasyncns/g-asyncns.h
@@ -20,8 +20,6 @@
#include "config.h"
-#define _GNU_SOURCE
-
/* We want to build the fork-based version, not the threaded version. */
#undef HAVE_PTHREAD
diff --git a/gio/tests/gdbus-peer.c b/gio/tests/gdbus-peer.c
index e582d57..3fba622 100644
--- a/gio/tests/gdbus-peer.c
+++ b/gio/tests/gdbus-peer.c
@@ -20,6 +20,8 @@
* Author: David Zeuthen <davidz redhat com>
*/
+#include "config.h"
+
#include <gio/gio.h>
#include <unistd.h>
#include <string.h>
diff --git a/glib/glib-unix.h b/glib/glib-unix.h
index e724778..c6eef4a 100644
--- a/glib/glib-unix.h
+++ b/glib/glib-unix.h
@@ -26,10 +26,6 @@
* system, work around it here (or better, fix the system or tell
* people to use a better one).
*/
-#ifndef _GNU_SOURCE
-#define _G_GNU_SOURCE_TEMPORARILY_DEFINED
-#define _GNU_SOURCE
-#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -37,10 +33,6 @@
#include <sys/wait.h>
#include <stdlib.h>
#include <fcntl.h>
-#ifdef _G_GNU_SOURCE_TEMPORARILY_DEFINED
-#undef _GNU_SOURCE
-#undef _G_GNU_SOURCE_TEMPORARILY_DEFINED
-#endif
#include <glib.h>
diff --git a/glib/gmain.c b/glib/gmain.c
index 0be3733..f31405a 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -31,21 +31,6 @@
* MT safe
*/
-#ifndef _WIN32
-/* for pipe2; need to define it first to avoid
- * other headers pulling in unistd.h
- */
-/* The meaning of_GNU_SOURCE that is intended here is present only on
- * Linux; avoid the possibility that some misguided header in MinGW
- * looks at it. Ideally we should define _GNU_SOURCE only on platforms
- * where we know what it means and that is what we want here
- * (i.e. Linux with glibc). After all, there might be some other POSIX
- * platform even where _GNU_SOURCE is used for some unrelated change
- * in semantics that isn't wanted. Sigh.
- */
-#define _GNU_SOURCE
-#endif
-
#include "config.h"
#include "glibconfig.h"
diff --git a/glib/gprintf.c b/glib/gprintf.c
index 7ef15d3..9108acb 100644
--- a/glib/gprintf.c
+++ b/glib/gprintf.c
@@ -19,10 +19,6 @@
#include "config.h"
-#ifndef _WIN32
-#define _GNU_SOURCE /* For vasprintf */
-#endif
-
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/glib/gqsort.c b/glib/gqsort.c
index 03b2db9..db4bed2 100644
--- a/glib/gqsort.c
+++ b/glib/gqsort.c
@@ -34,7 +34,6 @@
#include "config.h"
-#define _GNU_SOURCE
#include <limits.h>
#include <stdlib.h>
#include <string.h>
diff --git a/glib/gslice.c b/glib/gslice.c
index 05de6b3..76bcf04 100644
--- a/glib/gslice.c
+++ b/glib/gslice.c
@@ -25,7 +25,7 @@
# define HAVE_COMPLIANT_POSIX_MEMALIGN 1
#endif
-#ifdef HAVE_COMPLIANT_POSIX_MEMALIGN
+#if defined(HAVE_COMPLIANT_POSIX_MEMALIGN) && !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600 /* posix_memalign() */
#endif
#include <stdlib.h> /* posix_memalign() */
diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c
index 04f686b..3924b02 100644
--- a/glib/gstrfuncs.c
+++ b/glib/gstrfuncs.c
@@ -30,8 +30,6 @@
#include "config.h"
-#define _GNU_SOURCE /* For stpcpy */
-
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]