[tor-commits] [tor/master] Use the Autoconf macro AC_USE_SYSTEM_EXTENSIONS

nickm at torproject.org nickm at torproject.org
Fri Jun 17 14:27:42 UTC 2016


commit 94762e37b950f3ce1696c78dd4f7a89b6d05f1ac
Author: cypherpunks <cypherpunks at torproject.org>
Date:   Fri Jun 17 13:43:25 2016 +0000

    Use the Autoconf macro AC_USE_SYSTEM_EXTENSIONS
    
    The Autoconf macro AC_USE_SYSTEM_EXTENSIONS defines preprocessor macros
    which turn on extensions to C and POSIX. The macro also makes it easier
    for developers to use the extensions without needing (or forgetting) to
    define them manually.
    
    The macro can be safely used because it was introduced in Autoconf 2.60
    and Tor requires Autoconf 2.63 and above.
---
 changes/bug19139             |  3 +++
 configure.ac                 |  4 +---
 m4/pc_from_ucontext.m4       |  9 +++------
 src/common/backtrace.c       |  3 ---
 src/common/compat.c          | 12 ------------
 src/common/compat_pthreads.c |  2 --
 src/common/compat_threads.c  |  2 --
 src/common/crypto.c          |  1 -
 src/common/sandbox.c         |  2 --
 src/common/sandbox.h         |  6 ------
 src/common/util.c            |  4 ----
 src/ext/eventdns.c           |  3 ---
 12 files changed, 7 insertions(+), 44 deletions(-)

diff --git a/changes/bug19139 b/changes/bug19139
new file mode 100644
index 0000000..2e53d7d
--- /dev/null
+++ b/changes/bug19139
@@ -0,0 +1,3 @@
+  o Minor features (build):
+    - Use the Autoconf macro AC_USE_SYSTEM_EXTENSIONS to automatically
+      turn on C and POSIX extensions. Closes ticket 19139.
diff --git a/configure.ac b/configure.ac
index 386fcdd..6d721a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,6 +16,7 @@ AM_INIT_AUTOMAKE([foreign 1.11 subdir-objects])
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 AC_CONFIG_HEADERS([orconfig.h])
 
+AC_USE_SYSTEM_EXTENSIONS
 AC_CANONICAL_HOST
 
 PKG_PROG_PKG_CONFIG
@@ -1552,9 +1553,6 @@ int main(int c, char **v) { puts(__FUNCTION__); }])],
 AC_CACHE_CHECK([whether we have extern char **environ already declared],
   tor_cv_have_environ_declared,
   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
-/* We define _GNU_SOURCE here because it is also defined in compat.c.
- * Without it environ doesn't get declared. */
-#define _GNU_SOURCE
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
diff --git a/m4/pc_from_ucontext.m4 b/m4/pc_from_ucontext.m4
index 6bedcbb..8a9dc45 100644
--- a/m4/pc_from_ucontext.m4
+++ b/m4/pc_from_ucontext.m4
@@ -79,24 +79,21 @@ AC_DEFUN([AC_PC_FROM_UCONTEXT],
      if ! $pc_field_found; then
        # Prefer sys/ucontext.h to ucontext.h, for OS X's sake.
        if test "x$ac_cv_header_cygwin_signal_h" = xyes; then
-         AC_TRY_COMPILE([#define _GNU_SOURCE 1
-                         #include <cygwin/signal.h>],
+         AC_TRY_COMPILE([#include <cygwin/signal.h>],
                         [ucontext_t u; return u.$pc_field == 0;],
                         AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
                                            How to access the PC from a struct ucontext)
                         AC_MSG_RESULT([$pc_field])
                         pc_field_found=true)
        elif test "x$ac_cv_header_sys_ucontext_h" = xyes; then
-         AC_TRY_COMPILE([#define _GNU_SOURCE 1
-                         #include <sys/ucontext.h>],
+         AC_TRY_COMPILE([#include <sys/ucontext.h>],
                         [ucontext_t u; return u.$pc_field == 0;],
                         AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
                                            How to access the PC from a struct ucontext)
                         AC_MSG_RESULT([$pc_field])
                         pc_field_found=true)
        elif test "x$ac_cv_header_ucontext_h" = xyes; then
-         AC_TRY_COMPILE([#define _GNU_SOURCE 1
-                         #include <ucontext.h>],
+         AC_TRY_COMPILE([#include <ucontext.h>],
                         [ucontext_t u; return u.$pc_field == 0;],
                         AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
                                            How to access the PC from a struct ucontext)
diff --git a/src/common/backtrace.c b/src/common/backtrace.c
index 3b762b6..afdc10d 100644
--- a/src/common/backtrace.c
+++ b/src/common/backtrace.c
@@ -13,9 +13,6 @@
  * detect crashes.
  */
 
-#define __USE_GNU
-#define _GNU_SOURCE 1
-
 #include "orconfig.h"
 #include "compat.h"
 #include "util.h"
diff --git a/src/common/compat.c b/src/common/compat.c
index 370881b..72dffe2 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -12,18 +12,6 @@
  * the platform.
  **/
 
-/* This is required on rh7 to make strptime not complain.
- * We also need it to make memmem get defined (where available)
- */
-
-/* XXXX We should just  use AC_USE_SYSTEM_EXTENSIONS in our autoconf,
- * and get this (and other important stuff!) automatically. Once we do that,
- * make sure to also change the extern char **environ detection in
- * configure.ac, because whether that is declared or not depends on whether
- * we have _GNU_SOURCE defined! Maybe that means that once we take this out,
- * we can also take out the configure check. */
-#define _GNU_SOURCE
-
 #define COMPAT_PRIVATE
 #include "compat.h"
 
diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c
index 1b24cc3..1d6db34 100644
--- a/src/common/compat_pthreads.c
+++ b/src/common/compat_pthreads.c
@@ -10,8 +10,6 @@
  * functions.
  */
 
-#define _GNU_SOURCE
-
 #include "orconfig.h"
 #include <pthread.h>
 #include <signal.h>
diff --git a/src/common/compat_threads.c b/src/common/compat_threads.c
index 8f90012..9c6fa55 100644
--- a/src/common/compat_threads.c
+++ b/src/common/compat_threads.c
@@ -11,8 +11,6 @@
  *  modules.)
  */
 
-#define _GNU_SOURCE
-
 #include "orconfig.h"
 #include <stdlib.h>
 #include "compat.h"
diff --git a/src/common/crypto.c b/src/common/crypto.c
index f47f5d2..d5043c3 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -56,7 +56,6 @@ ENABLE_GCC_WARNING(redundant-decls)
 #include <ctype.h>
 #endif
 #ifdef HAVE_UNISTD_H
-#define _GNU_SOURCE
 #include <unistd.h>
 #endif
 #ifdef HAVE_FCNTL_H
diff --git a/src/common/sandbox.c b/src/common/sandbox.c
index 4e2c5cd..94b2fc6 100644
--- a/src/common/sandbox.c
+++ b/src/common/sandbox.c
@@ -39,8 +39,6 @@
 
 #if defined(USE_LIBSECCOMP)
 
-#define _GNU_SOURCE
-
 #include <sys/mman.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
diff --git a/src/common/sandbox.h b/src/common/sandbox.h
index 2defd8b..c5963e3 100644
--- a/src/common/sandbox.h
+++ b/src/common/sandbox.h
@@ -39,12 +39,6 @@ typedef struct sandbox_cfg_elem sandbox_cfg_t;
  */
 #ifdef USE_LIBSECCOMP
 
-#ifndef __USE_GNU
-#define __USE_GNU
-#endif
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
 #include <sys/ucontext.h>
 #include <seccomp.h>
 #include <netdb.h>
diff --git a/src/common/util.c b/src/common/util.c
index 2f7cc4f..7217cdc 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -9,10 +9,6 @@
  * process control.
  **/
 
-/* This is required on rh7 to make strptime not complain.
- */
-#define _GNU_SOURCE
-
 #include "orconfig.h"
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
diff --git a/src/ext/eventdns.c b/src/ext/eventdns.c
index 7046f32..f5b7723 100644
--- a/src/ext/eventdns.c
+++ b/src/ext/eventdns.c
@@ -50,9 +50,6 @@
 #endif
 #endif
 
-/* #define _POSIX_C_SOURCE 200507 */
-#define _GNU_SOURCE
-
 #ifdef DNS_USE_CPU_CLOCK_FOR_ID
 #ifdef DNS_USE_OPENSSL_FOR_ID
 #error Multiple id options selected



More information about the tor-commits mailing list