[Asterisk-code-review] core: Improve/simplify handling of required headers. (asterisk[master])

Joshua Colp asteriskteam at digium.com
Fri Apr 7 14:48:36 CDT 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/5375 )

Change subject: core: Improve/simplify handling of required headers.
......................................................................


core: Improve/simplify handling of required headers.

* Report failures if configure finds a required header is missing.
* Deduplicate includes between asterisk.h, astmm.h and compat.h.
* Unconditionally include headers in compat.h if required elsewhere.

Change-Id: Ie67d0185ca71fbfb81c9bdfaebe46a49e3c56dc5
---
M configure
M configure.ac
M include/asterisk.h
M include/asterisk/astmm.h
M include/asterisk/autoconfig.h.in
M include/asterisk/compat.h
6 files changed, 116 insertions(+), 43 deletions(-)

Approvals:
  George Joseph: Looks good to me, approved
  Richard Mudgett: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Matthew Fredrickson: Looks good to me, but someone else must approve



diff --git a/configure b/configure
index b27c94e..3243323 100755
--- a/configure
+++ b/configure
@@ -13230,6 +13230,10 @@
 
 fi
 
+if test -z $ac_header_dirent -o "$ac_header_dirent" = "no"; then
+  as_fn_error $? "*** Could not find dirent header that defines 'DIR'." "$LINENO" 5
+fi
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
 $as_echo_n "checking for ANSI C header files... " >&6; }
 if ${ac_cv_header_stdc+:} false; then :
@@ -13342,6 +13346,10 @@
 
 fi
 
+if test "$ac_cv_header_stdc" != "yes"; then
+  as_fn_error $? "*** ANSI C header files not found." "$LINENO" 5
+fi
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sys/wait.h that is POSIX.1 compatible" >&5
 $as_echo_n "checking for sys/wait.h that is POSIX.1 compatible... " >&6; }
 if ${ac_cv_header_sys_wait_h+:} false; then :
@@ -13383,7 +13391,38 @@
 
 fi
 
-for ac_header in arpa/inet.h fcntl.h inttypes.h libintl.h limits.h locale.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h strings.h sys/event.h sys/file.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h termios.h unistd.h utime.h arpa/nameser.h sys/io.h
+if test "$ac_cv_header_sys_wait_h" != "yes"; then
+  as_fn_error $? "*** POSIX.1 compatible sys/wait.h is required." "$LINENO" 5
+fi
+
+# Check for headers that are unconditionally required on all platforms.  Do not use
+# this to check for headers that are only needed by modules.
+for ac_header in  \
+  arpa/nameser.h assert.h ctype.h dlfcn.h errno.h fcntl.h float.h grp.h \
+  inttypes.h limits.h locale.h math.h pwd.h netinet/in.h regex.h resolv.h \
+  sched.h stdarg.h stdint.h stdio.h stdlib.h string.h syslog.h \
+  sys/file.h sys/ioctl.h sys/param.h sys/resource.h sys/socket.h sys/stat.h \
+  sys/time.h sys/types.h sys/un.h \
+  termios.h time.h unistd.h \
+
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+else
+
+  as_fn_error $? "*** A required header was not found." "$LINENO" 5
+
+fi
+
+done
+
+
+for ac_header in arpa/inet.h libintl.h malloc.h netdb.h stddef.h strings.h sys/event.h utime.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
diff --git a/configure.ac b/configure.ac
index b0f0488..a8e66bc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -588,9 +588,34 @@
 
 AC_FUNC_ALLOCA
 AC_HEADER_DIRENT
+if test -z $ac_header_dirent -o "$ac_header_dirent" = "no"; then
+  AC_MSG_ERROR([*** Could not find dirent header that defines 'DIR'.])
+fi
+
 AC_HEADER_STDC
+if test "$ac_cv_header_stdc" != "yes"; then
+  AC_MSG_ERROR([*** ANSI C header files not found.])
+fi
+
 AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h libintl.h limits.h locale.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h strings.h sys/event.h sys/file.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h termios.h unistd.h utime.h arpa/nameser.h sys/io.h])
+if test "$ac_cv_header_sys_wait_h" != "yes"; then
+  AC_MSG_ERROR([*** POSIX.1 compatible sys/wait.h is required.])
+fi
+
+# Check for headers that are unconditionally required on all platforms.  Do not use
+# this to check for headers that are only needed by modules.
+AC_CHECK_HEADERS([ \
+  arpa/nameser.h assert.h ctype.h dlfcn.h errno.h fcntl.h float.h grp.h \
+  inttypes.h limits.h locale.h math.h pwd.h netinet/in.h regex.h resolv.h \
+  sched.h stdarg.h stdint.h stdio.h stdlib.h string.h syslog.h \
+  sys/file.h sys/ioctl.h sys/param.h sys/resource.h sys/socket.h sys/stat.h \
+  sys/time.h sys/types.h sys/un.h \
+  termios.h time.h unistd.h \
+], [], [
+  AC_MSG_ERROR([*** A required header was not found.])
+])
+
+AC_CHECK_HEADERS([arpa/inet.h libintl.h malloc.h netdb.h stddef.h strings.h sys/event.h utime.h])
 
 # Any one of these packages support a mandatory requirement, so we want to check on them as early as possible.
 AST_EXT_LIB_CHECK([TERMCAP], [termcap], [tgetent], [])
diff --git a/include/asterisk.h b/include/asterisk.h
index dc530df..899438b 100644
--- a/include/asterisk.h
+++ b/include/asterisk.h
@@ -19,12 +19,11 @@
 #define _ASTERISK_H
 
 #include "asterisk/autoconfig.h"
+#include "asterisk/compat.h"
 
 #if !defined(NO_MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2) && defined(MALLOC_DEBUG)
 #include "asterisk/astmm.h"
 #endif
-
-#include "asterisk/compat.h"
 
 /* Default to allowing the umask or filesystem ACLs to determine actual file
  * creation permissions
@@ -54,8 +53,6 @@
 
 #if defined(DEBUG_FD_LEAKS) && !defined(STANDALONE) && !defined(STANDALONE2) && !defined(STANDALONE_AEL)
 /* These includes are all about ordering */
-#include <stdio.h>
-#include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/socket.h>
 #include <fcntl.h>
diff --git a/include/asterisk/astmm.h b/include/asterisk/astmm.h
index e129dc0..06300c8 100644
--- a/include/asterisk/astmm.h
+++ b/include/asterisk/astmm.h
@@ -30,20 +30,9 @@
 
 #ifndef _ASTERISK_ASTMM_H
 #define _ASTERISK_ASTMM_H
-/* IWYU pragma: private, include "asterisk/utils.h" */
-
-#ifndef STANDALONE
+/* IWYU pragma: private, include "asterisk.h" */
 
 #define __AST_DEBUG_MALLOC
-
-#include "asterisk.h"
-
-/* Include these now to prevent them from being needed later */
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdarg.h>
 
 void *ast_std_malloc(size_t size);
 void *ast_std_calloc(size_t nmemb, size_t size);
@@ -178,8 +167,6 @@
 
 #define ast_free(a) \
 	__ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#endif /* !STANDALONE */
 
 #else
 #error "NEVER INCLUDE astmm.h DIRECTLY!!"
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index b9b4e1f..af1c90b 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -62,6 +62,9 @@
 /* Define to 1 if you have the `asprintf' function. */
 #undef HAVE_ASPRINTF
 
+/* Define to 1 if you have the <assert.h> header file. */
+#undef HAVE_ASSERT_H
+
 /* Define to 1 if you have the `atan' function. */
 #undef HAVE_ATAN
 
@@ -170,6 +173,9 @@
 /* Define to 1 if you have the 'crypt_r' function. */
 #undef HAVE_CRYPT_R
 
+/* Define to 1 if you have the <ctype.h> header file. */
+#undef HAVE_CTYPE_H
+
 /* Define to 1 if you have a functional curl library. */
 #undef HAVE_CURL
 
@@ -198,6 +204,9 @@
 /* Define to 1 if your system has the dladdr() GNU extension */
 #undef HAVE_DLADDR
 
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#undef HAVE_DLFCN_H
+
 /* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
 #undef HAVE_DOPRNT
 
@@ -209,6 +218,9 @@
 
 /* Define to 1 if you have the `endpwent' function. */
 #undef HAVE_ENDPWENT
+
+/* Define to 1 if you have the <errno.h> header file. */
+#undef HAVE_ERRNO_H
 
 /* Define to 1 if you have the `euidaccess' function. */
 #undef HAVE_EUIDACCESS
@@ -242,6 +254,9 @@
 
 /* Define to 1 if you have the LIBFFTW3 library. */
 #undef HAVE_FFTW3
+
+/* Define to 1 if you have the <float.h> header file. */
+#undef HAVE_FLOAT_H
 
 /* Define to 1 if you have the `floor' function. */
 #undef HAVE_FLOOR
@@ -311,6 +326,9 @@
 
 /* Define if your system has the GMIME libraries. */
 #undef HAVE_GMIME
+
+/* Define to 1 if you have the <grp.h> header file. */
+#undef HAVE_GRP_H
 
 /* Define to indicate the GSM library */
 #undef HAVE_GSM
@@ -460,6 +478,9 @@
 
 /* Define to 1 if you have the <malloc.h> header file. */
 #undef HAVE_MALLOC_H
+
+/* Define to 1 if you have the <math.h> header file. */
+#undef HAVE_MATH_H
 
 /* Define to 1 if you have the `memchr' function. */
 #undef HAVE_MEMCHR
@@ -752,6 +773,9 @@
 /* Define to 1 if you have the `putenv' function. */
 #undef HAVE_PUTENV
 
+/* Define to 1 if you have the <pwd.h> header file. */
+#undef HAVE_PWD_H
+
 /* Define if your system has the PWLib libraries. */
 #undef HAVE_PWLIB
 
@@ -764,6 +788,9 @@
 /* Define to 1 if you have the `regcomp' function. */
 #undef HAVE_REGCOMP
 
+/* Define to 1 if you have the <regex.h> header file. */
+#undef HAVE_REGEX_H
+
 /* Define to 1 if you have the `remainder' function. */
 #undef HAVE_REMAINDER
 
@@ -772,6 +799,9 @@
 
 /* Define to 1 if you have the LIBRESAMPLE library. */
 #undef HAVE_RESAMPLE
+
+/* Define to 1 if you have the <resolv.h> header file. */
+#undef HAVE_RESOLV_H
 
 /* Define to 1 if your system has the close resolver function. */
 #undef HAVE_RES_CLOSE
@@ -808,6 +838,9 @@
 
 /* Define to 1 if your system has /sbin/launchd. */
 #undef HAVE_SBIN_LAUNCHD
+
+/* Define to 1 if you have the <sched.h> header file. */
+#undef HAVE_SCHED_H
 
 /* Define if your system has the SDL libraries. */
 #undef HAVE_SDL
@@ -889,6 +922,9 @@
    zero-length file name argument. */
 #undef HAVE_STAT_EMPTY_STRING_BUG
 
+/* Define to 1 if you have the <stdarg.h> header file. */
+#undef HAVE_STDARG_H
+
 /* Define to 1 if stdbool.h conforms to C99. */
 #undef HAVE_STDBOOL_H
 
@@ -897,6 +933,9 @@
 
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#undef HAVE_STDIO_H
 
 /* Define to 1 if you have the <stdlib.h> header file. */
 #undef HAVE_STDLIB_H
@@ -1066,9 +1105,6 @@
 /* Define to 1 if you have the <sys/ioctl.h> header file. */
 #undef HAVE_SYS_IOCTL_H
 
-/* Define to 1 if you have the <sys/io.h> header file. */
-#undef HAVE_SYS_IO_H
-
 /* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
    */
 #undef HAVE_SYS_NDIR_H
@@ -1078,6 +1114,9 @@
 
 /* Define to 1 if your system has working sys/poll.h */
 #undef HAVE_SYS_POLL_H
+
+/* Define to 1 if you have the <sys/resource.h> header file. */
+#undef HAVE_SYS_RESOURCE_H
 
 /* Define to 1 if you have the <sys/select.h> header file. */
 #undef HAVE_SYS_SELECT_H
@@ -1096,6 +1135,9 @@
 
 /* Define to 1 if you have the <sys/types.h> header file. */
 #undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <sys/un.h> header file. */
+#undef HAVE_SYS_UN_H
 
 /* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
 #undef HAVE_SYS_WAIT_H
@@ -1118,6 +1160,9 @@
 /* Define to 1 if your system defines timersub. */
 #undef HAVE_TIMERSUB
 
+/* Define to 1 if you have the <time.h> header file. */
+#undef HAVE_TIME_H
+
 /* Define to 1 if you have the Term Info library. */
 #undef HAVE_TINFO
 
diff --git a/include/asterisk/compat.h b/include/asterisk/compat.h
index 252ce91..88f88cf 100644
--- a/include/asterisk/compat.h
+++ b/include/asterisk/compat.h
@@ -27,35 +27,18 @@
 #define	__STDC_VERSION__ 0
 #endif
 
-#ifdef HAVE_INTTYPES_H
 #include <inttypes.h>
-#endif
-
-#ifdef HAVE_LIMITS_H
 #include <limits.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif
 
 #ifdef HAVE_STDDEF_H
 #include <stddef.h>
 #endif
 
-#ifdef HAVE_STDINT_H
 #include <stdint.h>
-#endif
-
-#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
-#endif
-
 #include <stdarg.h>
-
-#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif
 
 #ifdef HAVE_ALLOCA_H
 #include <alloca.h>    /* not necessarily present - could be in stdlib */
@@ -65,9 +48,7 @@
 
 #include <stdio.h>	/* this is always present */
 
-#ifdef HAVE_STRING_H
 #include <string.h>
-#endif
 
 #ifndef AST_POLL_COMPAT
 #include <poll.h>
@@ -158,7 +139,6 @@
 
 #include <alloca.h>
 #include <strings.h>
-#include <string.h>
 #include <pthread.h>
 #include <sys/stat.h>
 #include <signal.h>

-- 
To view, visit https://gerrit.asterisk.org/5375
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie67d0185ca71fbfb81c9bdfaebe46a49e3c56dc5
Gerrit-PatchSet: 3
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matthew Fredrickson <creslin at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-code-review mailing list