Skip to content

Commit

Permalink
Removes pre-C99 build and header cruft (#700)
Browse files Browse the repository at this point in the history
* Committing clang-format changes

* Removes pre-C99 build and header cruft

* Assumes ANSI C headers exist
* Assumes stdbool.h, stdint.h, and inttypes.h are present
* Assumes the C++ compiler can handle stdint.h
* Removes all work-arounds for missing functionality, especially stdbool.h

* Formats source

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
derobins and github-actions[bot] authored May 28, 2021
1 parent 4454fca commit e60ac6e
Show file tree
Hide file tree
Showing 17 changed files with 11 additions and 146 deletions.
15 changes: 0 additions & 15 deletions config/cmake/H5pubconf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@
optimization operation */
#cmakedefine H5_HAVE_INSTRUMENTED_LIBRARY @H5_HAVE_INSTRUMENTED_LIBRARY@

/* Define to 1 if you have the <inttypes.h> header file. */
#cmakedefine H5_HAVE_INTTYPES_H @H5_HAVE_INTTYPES_H@

/* Define to 1 if you have the `ioctl' function. */
#cmakedefine H5_HAVE_IOCTL @H5_HAVE_IOCTL@

Expand Down Expand Up @@ -343,18 +340,9 @@
/* Define if `struct stat' has the `st_blocks' field */
#cmakedefine H5_HAVE_STAT_ST_BLOCKS @H5_HAVE_STAT_ST_BLOCKS@

/* Define to 1 if you have the <stdbool.h> header file. */
#cmakedefine H5_HAVE_STDBOOL_H @H5_HAVE_STDBOOL_H@

/* Define to 1 if you have the <stddef.h> header file. */
#cmakedefine H5_HAVE_STDDEF_H @H5_HAVE_STDDEF_H@

/* Define to 1 if you have the <stdint.h> header file. */
#cmakedefine H5_HAVE_STDINT_H @H5_HAVE_STDINT_H@

/* Define to 1 if you have the <stdint.h> header file for Cplusplus. */
#cmakedefine H5_HAVE_STDINT_H_CXX @H5_HAVE_STDINT_H_CXX@

/* Define to 1 if you have the <stdlib.h> header file. */
#cmakedefine H5_HAVE_STDLIB_H @H5_HAVE_STDLIB_H@

Expand Down Expand Up @@ -698,9 +686,6 @@
/* The size of `__int64', as computed by sizeof. */
#define H5_SIZEOF___INT64 @H5_SIZEOF___INT64@

/* Define to 1 if you have the ANSI C header files. */
#cmakedefine H5_STDC_HEADERS @H5_STDC_HEADERS@

/* Define if strict file format checks are enabled */
#cmakedefine H5_STRICT_FORMAT_CHECKS @H5_STRICT_FORMAT_CHECKS@

Expand Down
20 changes: 3 additions & 17 deletions config/cmake_ext_mod/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ CHECK_INCLUDE_FILE_CONCAT ("features.h" ${HDF_PREFIX}_HAVE_FEATURES_H)
CHECK_INCLUDE_FILE_CONCAT ("dirent.h" ${HDF_PREFIX}_HAVE_DIRENT_H)
CHECK_INCLUDE_FILE_CONCAT ("setjmp.h" ${HDF_PREFIX}_HAVE_SETJMP_H)
CHECK_INCLUDE_FILE_CONCAT ("stddef.h" ${HDF_PREFIX}_HAVE_STDDEF_H)
CHECK_INCLUDE_FILE_CONCAT ("stdint.h" ${HDF_PREFIX}_HAVE_STDINT_H)
CHECK_INCLUDE_FILE_CONCAT ("unistd.h" ${HDF_PREFIX}_HAVE_UNISTD_H)

# Windows
Expand All @@ -146,12 +145,9 @@ CHECK_INCLUDE_FILE_CONCAT ("strings.h" ${HDF_PREFIX}_HAVE_STRINGS_H)
CHECK_INCLUDE_FILE_CONCAT ("stdlib.h" ${HDF_PREFIX}_HAVE_STDLIB_H)
CHECK_INCLUDE_FILE_CONCAT ("memory.h" ${HDF_PREFIX}_HAVE_MEMORY_H)
CHECK_INCLUDE_FILE_CONCAT ("dlfcn.h" ${HDF_PREFIX}_HAVE_DLFCN_H)
CHECK_INCLUDE_FILE_CONCAT ("inttypes.h" ${HDF_PREFIX}_HAVE_INTTYPES_H)
CHECK_INCLUDE_FILE_CONCAT ("netinet/in.h" ${HDF_PREFIX}_HAVE_NETINET_IN_H)
CHECK_INCLUDE_FILE_CONCAT ("netdb.h" ${HDF_PREFIX}_HAVE_NETDB_H)
CHECK_INCLUDE_FILE_CONCAT ("arpa/inet.h" ${HDF_PREFIX}_HAVE_ARPA_INET_H)
# _Bool type support
CHECK_INCLUDE_FILE_CONCAT (stdbool.h ${HDF_PREFIX}_HAVE_STDBOOL_H)

## Check for non-standard extenstion quadmath.h

Expand Down Expand Up @@ -237,11 +233,6 @@ macro (HDF_FUNCTION_TEST OTHER_TEST)
endif ()
endmacro ()

#-----------------------------------------------------------------------------
# Check for these functions before the time headers are checked
#-----------------------------------------------------------------------------
HDF_FUNCTION_TEST (STDC_HEADERS)

#-----------------------------------------------------------------------------
# Check for large file support
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -416,13 +407,9 @@ HDF_CHECK_TYPE_SIZE (time_t ${HDF_PREFIX}_SIZEOF_TIME_T)
# Extra C99 types
#-----------------------------------------------------------------------------

# _Bool type support
if (HAVE_STDBOOL_H)
set (CMAKE_EXTRA_INCLUDE_FILES stdbool.h)
HDF_CHECK_TYPE_SIZE (bool ${HDF_PREFIX}_SIZEOF_BOOL)
else ()
HDF_CHECK_TYPE_SIZE (_Bool ${HDF_PREFIX}_SIZEOF_BOOL)
endif ()
# Size of bool
set (CMAKE_EXTRA_INCLUDE_FILES stdbool.h)
HDF_CHECK_TYPE_SIZE (_Bool ${HDF_PREFIX}_SIZEOF_BOOL)

if (MINGW OR NOT WINDOWS)
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -554,7 +541,6 @@ if (MINGW OR NOT WINDOWS)
foreach (other_test
HAVE_ATTRIBUTE
HAVE_C99_FUNC
# STDC_HEADERS
HAVE_FUNCTION
HAVE_C99_DESIGNATED_INITIALIZER
SYSTEM_SCOPE_THREADS
Expand Down
8 changes: 0 additions & 8 deletions config/cmake_ext_mod/HDFTests.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ int main(void)
}
#endif

#ifdef STDC_HEADERS
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <float.h>
int main() { return 0; }
#endif /* STDC_HEADERS */


#ifdef HAVE_ATTRIBUTE

Expand Down
11 changes: 0 additions & 11 deletions config/cmake_ext_mod/HDFUseCXX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,6 @@ endif ()
include (CheckIncludeFileCXX)
include (TestForSTDNamespace)

# IF the c compiler found stdint, check the C++ as well. On some systems this
# file will be found by C but not C++, only do this test IF the C++ compiler
# has been initialized (e.g. the project also includes some c++)
if (${HDF_PREFIX}_HAVE_STDINT_H AND CMAKE_CXX_COMPILER_LOADED)
CHECK_INCLUDE_FILE_CXX ("stdint.h" ${HDF_PREFIX}_HAVE_STDINT_H_CXX)
if (NOT ${HDF_PREFIX}_HAVE_STDINT_H_CXX)
set (${HDF_PREFIX}_HAVE_STDINT_H "" CACHE INTERNAL "Have includes HAVE_STDINT_H")
set (USE_INCLUDES ${USE_INCLUDES} "stdint.h")
endif ()
endif ()

# For other CXX specific tests, use this MACRO.
macro (HDF_CXX_FUNCTION_TEST OTHER_TEST)
if (NOT DEFINED ${OTHER_TEST})
Expand Down
10 changes: 1 addition & 9 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1251,8 +1251,6 @@ AC_CHECK_HEADERS([sys/resource.h sys/time.h unistd.h sys/ioctl.h sys/stat.h])
AC_CHECK_HEADERS([sys/socket.h sys/types.h sys/file.h])
AC_CHECK_HEADERS([stddef.h setjmp.h features.h])
AC_CHECK_HEADERS([dirent.h])
AC_CHECK_HEADERS([stdint.h], [C9x=yes])
AC_CHECK_HEADERS([stdbool.h])
AC_CHECK_HEADERS([netdb.h netinet/in.h arpa/inet.h])

## Darwin
Expand Down Expand Up @@ -1417,11 +1415,7 @@ AC_CHECK_SIZEOF([off_t])

if test "X$C9x" = "Xyes"; then
cat >>confdefs.h <<\EOF
#ifdef HAVE_STDBOOL_H
#include <stdbool.h> /* for bool definition */
#else
#define bool _Bool
#endif
#include <stdbool.h>
EOF
AC_CHECK_SIZEOF([bool])
fi
Expand Down Expand Up @@ -1938,10 +1932,8 @@ if test "X$THREADSAFE" = "Xyes"; then
AC_CACHE_VAL([hdf5_cv_system_scope_threads],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM([
#if STDC_HEADERS
#include <stdlib.h>
#include <pthread.h>
#endif
],[
pthread_attr_t attribute;
int ret;
Expand Down
12 changes: 0 additions & 12 deletions src/H5private.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
#endif /* H5_HAVE_WIN32_API */
#endif /* H5_HAVE_THREADSAFE */

/*
* Include ANSI-C header files.
*/
#ifdef H5_STDC_HEADERS
#include <assert.h>
#include <ctype.h>
#include <errno.h>
Expand All @@ -56,7 +52,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif

/*
* If _POSIX_VERSION is defined in unistd.h then this system is Posix.1
Expand All @@ -71,14 +66,7 @@
#include <pwd.h>
#endif

/*
* C9x integer types
*/
#ifndef __cplusplus
#ifdef H5_HAVE_STDINT_H
#include <stdint.h>
#endif
#endif

/*
* The `struct stat' data type for stat() and fstat(). This is a Posix file
Expand Down
31 changes: 6 additions & 25 deletions src/H5public.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,21 @@
#ifdef H5_HAVE_FEATURES_H
#include <features.h> /* For setting POSIX, BSD, etc. compatibility */
#endif

#ifdef H5_HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef H5_STDC_HEADERS

#include <limits.h> /* For H5T_NATIVE_CHAR defn in H5Tpublic.h */
#include <stdarg.h> /* For variadic functions in H5VLpublic.h */
#endif
#ifndef __cplusplus
#ifdef H5_HAVE_STDINT_H
#include <stdint.h> /* For C9x types */
#endif
#else
#ifdef H5_HAVE_STDINT_H_CXX
#include <stdint.h> /* For C9x types (when included from C++) */
#endif
#endif
#ifdef H5_HAVE_INTTYPES_H

#include <stdint.h> /* For C9x types */
#include <inttypes.h> /* C99/POSIX.1 header for uint64_t, PRIu64 */
#endif

#ifdef H5_HAVE_STDDEF_H
#include <stddef.h>
#endif

#ifdef H5_HAVE_PARALLEL
/* Don't link against MPI C++ bindings */
#define MPICH_SKIP_MPICXX 1
Expand Down Expand Up @@ -220,19 +213,7 @@ typedef int herr_t;
* }
* \endcode
*/
#ifdef H5_HAVE_STDBOOL_H
#include <stdbool.h>
#else /* H5_HAVE_STDBOOL_H */
#ifndef __cplusplus
#if defined(H5_SIZEOF_BOOL) && (H5_SIZEOF_BOOL != 0)
#define bool _Bool
#else
#define bool unsigned int
#endif
#define true 1
#define false 0
#endif /* __cplusplus */
#endif /* H5_HAVE_STDBOOL_H */
typedef bool hbool_t;
typedef int htri_t;

Expand Down
13 changes: 0 additions & 13 deletions test/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -8068,19 +8068,6 @@ check_flush_cache__flush_op_test(H5F_t *file_ptr, int test_num, unsigned int flu
if ((check[i].entry_num != i) || (check[i].entry_type < 0) ||
(check[i].entry_type >= NUMBER_OF_ENTRY_TYPES) || (check[i].entry_index < 0) ||
(check[i].entry_index > max_indices[check[i].entry_type]) ||
#ifndef H5_HAVE_STDBOOL_H
/* Check for nonsense values if hbool_t is an integral
* type instead of a real Boolean.
*/
((check[i].in_cache != TRUE) && (check[i].in_cache != FALSE)) ||
((check[i].at_main_addr != TRUE) && (check[i].at_main_addr != FALSE)) ||
((check[i].is_dirty != TRUE) && (check[i].is_dirty != FALSE)) ||
((check[i].is_protected != TRUE) && (check[i].is_protected != FALSE)) ||
((check[i].is_pinned != TRUE) && (check[i].is_pinned != FALSE)) ||
((check[i].expected_deserialized != TRUE) && (check[i].expected_deserialized != FALSE)) ||
((check[i].expected_serialized != TRUE) && (check[i].expected_serialized != FALSE)) ||
((check[i].expected_destroyed != TRUE) && (check[i].expected_destroyed != FALSE)) ||
#endif /* H5_HAVE_STDBOOL_H */
(check[i].expected_size <= (size_t)0)) {

pass = FALSE;
Expand Down
12 changes: 0 additions & 12 deletions test/cache_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1487,12 +1487,6 @@ add_flush_op(int target_type, int target_idx, int op_code, int type, int idx, hb
HDassert((0 <= type) && (type < NUMBER_OF_ENTRY_TYPES));
HDassert((0 <= idx) && (idx <= max_indices[type]));
HDassert(new_size <= VARIABLE_ENTRY_SIZE);
#ifndef H5_HAVE_STDBOOL_H
/* Check for TRUE or FALSE if we're using an integer type instead
* of a real Boolean type.
*/
HDassert((flag == TRUE) || (flag == FALSE));
#endif /* H5_HAVE_STDBOOL_H */

if (pass) {

Expand Down Expand Up @@ -1692,12 +1686,6 @@ execute_flush_op(H5F_t *file_ptr, struct test_entry_t *entry_ptr, struct flush_o
HDassert((0 <= op_ptr->type) && (op_ptr->type < NUMBER_OF_ENTRY_TYPES));
HDassert((0 <= op_ptr->idx) && (op_ptr->idx <= max_indices[op_ptr->type]));
HDassert(flags_ptr != NULL);
#ifndef H5_HAVE_STDBOOL_H
/* Check for TRUE or FALSE if we're using an integer type instead
* of a real Boolean type.
*/
HDassert((op_ptr->flag == FALSE) || (op_ptr->flag == TRUE));
#endif /* H5_HAVE_STDBOOL_H */

if (pass) {

Expand Down
2 changes: 0 additions & 2 deletions tools/test/perform/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
#undef NDEBUG
#include "hdf5.h"

#ifdef H5_STDC_HEADERS
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif

/* Solaris Studio defines attribute, but for the attributes we need */
#if !defined(H5_HAVE_ATTRIBUTE) || defined __cplusplus || defined(__SUNPRO_C)
Expand Down
5 changes: 1 addition & 4 deletions tools/test/perform/direct_write_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@

#if !defined(WIN32) && !defined(__MINGW32__)

#include <math.h>

#ifdef H5_STDC_HEADERS
#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#endif

#ifdef H5_HAVE_UNISTD_H
#include <sys/types.h>
Expand Down
2 changes: 0 additions & 2 deletions tools/test/perform/overhead.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
#include "hdf5.h"
#include "H5private.h"

#ifdef H5_STDC_HEADERS
#include <ctype.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#endif

#ifdef H5_HAVE_IO_H
#include <io.h>
Expand Down
2 changes: 0 additions & 2 deletions tools/test/perform/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@

#ifdef H5_HAVE_PARALLEL

#ifdef H5_STDC_HEADERS
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif

#ifdef H5_HAVE_UNISTD_H
#include <sys/types.h>
Expand Down
2 changes: 0 additions & 2 deletions tools/test/perform/pio_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

#include "hdf5.h"

#ifdef H5_STDC_HEADERS
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#endif

#ifdef H5_HAVE_UNISTD_H
#include <sys/types.h>
Expand Down
5 changes: 0 additions & 5 deletions tools/test/perform/pio_standalone.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

#include "H5public.h" /* Include Public Definitions */

/*
* Include ANSI-C header files.
*/
#ifdef H5_STDC_HEADERS
#include <assert.h>
#include <ctype.h>
#include <errno.h>
Expand All @@ -37,7 +33,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif

/*
* Redefine all the POSIX functions. We should never see a POSIX
Expand Down
2 changes: 0 additions & 2 deletions tools/test/perform/sio_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

#include "hdf5.h"

#ifdef H5_STDC_HEADERS
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#endif

#ifdef H5_HAVE_UNISTD_H
#include <sys/types.h>
Expand Down
Loading

0 comments on commit e60ac6e

Please sign in to comment.