Move part of types/simple.h to utility/
authorTeemu Murtola <teemu.murtola@gmail.com>
Sun, 6 Apr 2014 18:55:25 +0000 (21:55 +0300)
committerMark Abraham <mark.j.abraham@gmail.com>
Thu, 10 Apr 2014 10:26:55 +0000 (12:26 +0200)
- Move those parts of types/simple.h that are wrapping C99 features and
  some compiler-specific attributes (gmx_unused) into
  utility/basedefinitions.h.
- Replace some uses of types/simple.h with the new header, removing a
  few module-level dependencies on legacyheaders/
- For now, types/simple.h includes the new header to avoid touching a
  lot of code.
- Remove unused BIG_STRLEN from types/simple.h.
- Move XXXX etc. into calcvir.c, which is the only place where they are
  used.

Change-Id: Idad2aff77048cc1487945e90c8b50ff8bd7010d4

16 files changed:
doxygen/Doxyfile-common.cmakein
src/gromacs/legacyheaders/types/simple.h
src/gromacs/mdlib/calcvir.c
src/gromacs/options/basicoptions.h
src/gromacs/simd/simd.h
src/gromacs/simd/tests/base.h
src/gromacs/simd/tests/bootstrap_loadstore.cpp
src/gromacs/timing/walltime_accounting.c
src/gromacs/timing/walltime_accounting.h
src/gromacs/utility/CMakeLists.txt
src/gromacs/utility/basedefinitions.h [new file with mode: 0644]
src/gromacs/utility/basenetwork.h
src/gromacs/utility/cstringutil.c
src/gromacs/utility/cstringutil.h
src/gromacs/utility/fatalerror.h
src/gromacs/utility/gmxomp.h

index 344173026f4fdf01f0bec29d7ffc6eeeacd7179f..b82710da300ae2b1e81d1cbcd3c27154a44f1228 100644 (file)
@@ -17,6 +17,7 @@ EXCLUDE                = @CMAKE_SOURCE_DIR@/doxygen/examples \
                          @CMAKE_SOURCE_DIR@/src/gromacs/selection/parser.h \
                          @CMAKE_SOURCE_DIR@/src/gromacs/selection/scanner.cpp @NB_KERNEL_DIRS_TO_IGNORE_IN_DOXYGEN@
 EXCLUDE_SYMBOLS        = YY* yy* _gmx_sel_yy*
+EXCLUDE_SYMBOLS       += __STDC*
 EXCLUDE_SYMBOLS       += TEST TEST_F TEST_P TYPED_TEST_CASE TYPED_TEST INSTANTIATE_TEST_CASE_P
 EXCLUDE_SYMBOLS       += MOCK_METHOD* MOCK_CONST_METHOD*
 FULL_PATH_NAMES        = YES
index f00da633cb59f22468413daa2b2c068bff50fca1..30c0c9079b36aa442ebf60f0aea0e13f471fe0f9 100644 (file)
 #ifndef _simple_h
 #define _simple_h
 
-/* Information about integer data type sizes */
-#include <limits.h>
-#define __STDC_LIMIT_MACROS
-#include <stdint.h>
-#ifndef _MSC_VER
-#define __STDC_FORMAT_MACROS
-#include <inttypes.h>
-#endif
+#include "../../utility/basedefinitions.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -54,39 +47,10 @@ extern "C" {
 }
 #endif
 
-
-#define XX      0           /* Defines for indexing in */
-#define YY      1           /* vectors                 */
+#define XX      0                 /* Defines for indexing in */
+#define YY      1                 /* vectors                 */
 #define ZZ      2
-#define DIM     3           /* Dimension of vectors            */
-#define XXXX    0           /* defines to index matrices */
-#define XXYY    1
-#define XXZZ    2
-#define YYXX    3
-#define YYYY    4
-#define YYZZ    5
-#define ZZXX    6
-#define ZZYY    7
-#define ZZZZ    8
-
-/* There is no standard size for 'bool' in C++, so when
- * we previously defined it to int for C code the data types
- * (and structs) would have different size depending on your compiler,
- * both at gromacs build time and when you use the library.
- * The only way around this is to NOT assume anything about the C++ type,
- * so we cannot use the name 'bool' in our C code anymore.
- */
-
-typedef int gmx_bool;
-
-#ifndef FALSE
-#  define FALSE   0
-#endif
-#ifndef TRUE
-#  define TRUE    1
-#endif
-#define BOOL_NR 2
-
+#define DIM     3                 /* Dimension of vectors    */
 
 typedef int         atom_id;      /* To indicate an atoms id         */
 #define NO_ATID     (atom_id)(~0) /* Use this to indicate invalid atid */
@@ -149,94 +113,8 @@ typedef int             ivec[DIM];
 
 typedef int             imatrix[DIM][DIM];
 
-#ifdef _MSC_VER
-typedef __int32 gmx_int32_t;
-#define GMX_PRId32 "I32d"
-#define GMX_SCNd32 "I32d"
-
-typedef __int64 gmx_int64_t;
-#define GMX_PRId64 "I64d"
-#define GMX_SCNd64 "I64d"
-
-typedef unsigned __int32 gmx_uint32_t;
-#define GMX_PRIu32 "I32u"
-#define GMX_SCNu32 "I32u"
-
-typedef unsigned __int64 gmx_uint64_t;
-#define GMX_PRIu64 "I64u"
-#define GMX_SCNu64 "I64u"
-#else
-typedef int32_t gmx_int32_t;
-#define GMX_PRId32 PRId32
-#define GMX_SCNd32 SCNd32
-
-typedef int64_t gmx_int64_t;
-#define GMX_PRId64 PRId64
-#define GMX_SCNd64 SCNd64
-
-typedef uint32_t gmx_uint32_t;
-#define GMX_PRIu32 PRIu32
-#define GMX_SCNu32 SCNu32
-
-typedef uint64_t gmx_uint64_t;
-#define GMX_PRIu64 PRIu64
-#define GMX_SCNu64 SCNu64
-#endif
-
-#define GMX_INT32_MAX INT32_MAX
-#define GMX_INT32_MIN INT32_MIN
-
-#define GMX_INT64_MAX INT64_MAX
-#define GMX_INT64_MIN INT64_MIN
-
-#define GMX_UINT32_MAX UINT32_MAX
-#define GMX_UINT32_MIN UINT32_MIN
-
-#define GMX_UINT64_MAX UINT64_MAX
-#define GMX_UINT64_MIN UINT64_MIN
-
-#if !defined __cplusplus && _MSC_VER
-#define gmx_inline __inline
-#else
-/* C++ or C99 */
-#define gmx_inline inline
-#endif
-
-/* ICC, GCC, MSVC, Pathscale, PGI, XLC support __restrict.
- * Any other compiler can be added here. We cannot
- * use restrict because it is in C99 but not in C++ */
-#define gmx_restrict __restrict
-
-/*
- * These attributes suppress compiler warnings about unused function arguments
- * by marking them as possibly unused. Some arguments are unused but
- * have to be retained to preserve a function signature
- * that must match that of another function.
- * Some arguments are only used in *some* code paths (e.g. MPI)
- */
-
-#ifndef gmx_unused
-#ifdef __GNUC__
-/* GCC, clang, and some ICC pretending to be GCC */
-#  define gmx_unused __attribute__ ((unused))
-#elif (defined(__INTEL_COMPILER) || defined(__ECC)) && !defined(_MSC_VER)
-/* ICC on *nix */
-#  define gmx_unused __attribute__ ((unused))
-#elif defined _MSC_VER
-/* MSVC */
-#  define gmx_unused /*@unused@*/
-#elif defined(__xlC__)
-/* IBM */
-#  define gmx_unused __attribute__ ((unused))
-#else
-#  define gmx_unused
-#endif
-#endif
-
 /* Standard sizes for char* string buffers */
 #define STRLEN 4096
-#define BIG_STRLEN 1048576
-
 
 #ifdef __cplusplus
 }
index 395b9c38f5200c0adcf27ca83f3ec67957802a69..b3c80997470370f95778f4411412aaf2c107883e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "mshift.h"
 #include "macros.h"
 
+#define XXXX    0
+#define XXYY    1
+#define XXZZ    2
+#define YYXX    3
+#define YYYY    4
+#define YYZZ    5
+#define ZZXX    6
+#define ZZYY    7
+#define ZZZZ    8
+
 static void upd_vir(rvec vir, real dvx, real dvy, real dvz)
 {
     vir[XX] -= 0.5*dvx;
index e733ad876019ac37cf8d3fc9d3ac9d0b52a78883..35e91cc817ddb6145a87399a97baf1ea5cf5a578 100644 (file)
@@ -48,7 +48,7 @@
 
 #include <string>
 
-#include "../legacyheaders/types/simple.h"
+#include "../utility/basedefinitions.h"
 #include "../utility/gmxassert.h"
 
 #include "abstractoption.h"
index 53a65e984a97cecaf6ffdea03ae8dabe77fc08d7..44b9d356f73166965c38b947a3e2c360033fd199 100644 (file)
@@ -75,7 +75,8 @@
 #endif
 
 #include <stddef.h>
-#include "gromacs/legacyheaders/types/simple.h"
+
+#include "gromacs/utility/basedefinitions.h"
 
 /* Forward declarations so memory allocation can be used in implementations */
 static gmx_inline float *  gmx_simd_align_f(float *p);
index f4af291973c05c94182172955a9cad461ed5373f..0f5c4dcca980276bcbbc0a12acdbbc192fb34ee9 100644 (file)
  * \ingroup module_simd
  */
 #include <vector>
+
 #include <gtest/gtest.h>
-#include "gromacs/simd/simd.h"
 
+#include "gromacs/legacyheaders/types/simple.h"
+
+#include "gromacs/simd/simd.h"
 
 namespace gmx
 {
index d7a38e9b510a01be958a168149fd9b29574de6c6..5ea86fbb8f53fee42b373c71db6987b7013c8f6e 100644 (file)
@@ -55,6 +55,9 @@
  */
 
 #include <gtest/gtest.h>
+
+#include "gromacs/legacyheaders/types/simple.h"
+
 #include "gromacs/simd/simd.h"
 
 namespace
index ec256b22730656de4a25d9f39352d96410aab715..bed1ad92191c8af77af6218ea299d1b0170a8289 100644 (file)
@@ -47,8 +47,7 @@
 #include <sys/time.h>
 #endif
 
-#include "gromacs/legacyheaders/types/simple.h"
-
+#include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/smalloc.h"
 
 /* TODO in future: convert gmx_walltime_accounting to a class,
index 641393a0ddac227f50650cace0f90b9ef1c54e17..8ed947eb8fa10c5610c209e2ecba3ffdef9e469f 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,7 +38,7 @@
 #ifndef GMX_TIMING_WALLTIME_ACCOUNTING_H
 #define GMX_TIMING_WALLTIME_ACCOUNTING_H
 
-#include "../legacyheaders/types/simple.h"
+#include "../utility/basedefinitions.h"
 
 #ifdef __cplusplus
 extern "C" {
index b0871b57c892f21c47634ef1acc84121138a9af6..0e02634a3d5e3f6c66a0897f8f8de22e64eb119f 100644 (file)
@@ -41,6 +41,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/gmx_header_config_gen.h.cmakein
 
 set(UTILITY_PUBLIC_HEADERS
     arrayref.h
+    basedefinitions.h
     cstringutil.h
     common.h
     errorcodes.h
diff --git a/src/gromacs/utility/basedefinitions.h b/src/gromacs/utility/basedefinitions.h
new file mode 100644 (file)
index 0000000..c8e65c2
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \file
+ * \brief
+ * Basic types and macros used throughout \Gromacs.
+ *
+ * \inpublicapi
+ * \ingroup module_utility
+ */
+#ifndef GMX_UTILITY_BASEDEFINITIONS_H
+#define GMX_UTILITY_BASEDEFINITIONS_H
+
+/* Information about integer data type sizes */
+#include <limits.h>
+#define __STDC_LIMIT_MACROS
+#include <stdint.h>
+#ifndef _MSC_VER
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+#endif
+
+/*! \brief
+ * Boolean type for use in \Gromacs C code.
+ *
+ * There is no standard size for 'bool' in C++, so when
+ * we previously defined it to int for C code the data types
+ * (and structs) would have different size depending on your compiler,
+ * both at \Gromacs build time and when you use the library.
+ * The only way around this is to NOT assume anything about the C++ type,
+ * so we cannot use the name 'bool' in our C code anymore.
+ */
+typedef int gmx_bool;
+
+#ifndef FALSE
+/** False value for ::gmx_bool. */
+#  define FALSE   0
+#endif
+#ifndef TRUE
+/** True value for ::gmx_bool. */
+#  define TRUE    1
+#endif
+/** Number of gmx_bool values. */
+#define BOOL_NR 2
+
+/*! \name Fixed-width integer types
+ *
+ * These types and macros provide the equivalent of 32- and 64-bit integer
+ * types from C99 headers `stdint.h` and `inttypes.h`.  These headers are also
+ * there in C++11.  The types and macros from here should be used instead of
+ * `int32_t` etc.
+ * MSVC doesn't support these before Visual Studio 2013.
+ */
+/*! \{ */
+#ifdef _MSC_VER
+typedef __int32 gmx_int32_t;
+#define GMX_PRId32 "I32d"
+#define GMX_SCNd32 "I32d"
+
+typedef __int64 gmx_int64_t;
+#define GMX_PRId64 "I64d"
+#define GMX_SCNd64 "I64d"
+
+typedef unsigned __int32 gmx_uint32_t;
+#define GMX_PRIu32 "I32u"
+#define GMX_SCNu32 "I32u"
+
+typedef unsigned __int64 gmx_uint64_t;
+#define GMX_PRIu64 "I64u"
+#define GMX_SCNu64 "I64u"
+#else
+typedef int32_t gmx_int32_t;
+#define GMX_PRId32 PRId32
+#define GMX_SCNd32 SCNd32
+
+typedef int64_t gmx_int64_t;
+#define GMX_PRId64 PRId64
+#define GMX_SCNd64 SCNd64
+
+typedef uint32_t gmx_uint32_t;
+#define GMX_PRIu32 PRIu32
+#define GMX_SCNu32 SCNu32
+
+typedef uint64_t gmx_uint64_t;
+#define GMX_PRIu64 PRIu64
+#define GMX_SCNu64 SCNu64
+#endif
+
+#define GMX_INT32_MAX INT32_MAX
+#define GMX_INT32_MIN INT32_MIN
+
+#define GMX_INT64_MAX INT64_MAX
+#define GMX_INT64_MIN INT64_MIN
+
+#define GMX_UINT32_MAX UINT32_MAX
+#define GMX_UINT32_MIN UINT32_MIN
+
+#define GMX_UINT64_MAX UINT64_MAX
+#define GMX_UINT64_MIN UINT64_MIN
+/*! \} */
+
+/*! \def gmx_inline
+ * \brief
+ * Keyword to use in C code instead of C99 `inline`.
+ *
+ * Some of the C compilers we support do not recognize the C99 keyword
+ * `inline`.  This macro should be used in C code and in shared C/C++ headers
+ * to indicate a function is inlined.
+ * C++ code should use plain `inline`, as that is already in C++98.
+ */
+#if !defined __cplusplus && _MSC_VER
+#define gmx_inline __inline
+#else
+/* C++ or C99 */
+#define gmx_inline inline
+#endif
+
+/* ICC, GCC, MSVC, Pathscale, PGI, XLC support __restrict.
+ * Any other compiler can be added here. */
+/*! \brief
+ * Keyword to use in instead of C99 `restrict`.
+ *
+ * We cannot use `restrict` because it is only in C99, but not in C++.
+ * This macro should instead be used to allow easily supporting different
+ * compilers.
+ */
+#define gmx_restrict __restrict
+
+/*! \def gmx_unused
+ * \brief
+ * Attribute to suppres compiler warnings about unused function parameters.
+ *
+ * This attribute suppresses compiler warnings about unused function arguments
+ * by marking them as possibly unused.  Some arguments are unused but
+ * have to be retained to preserve a function signature
+ * that must match that of another function.
+ * Some arguments are only used in *some* conditional compilation code paths
+ * (e.g. MPI).
+ */
+#ifndef gmx_unused
+#ifdef __GNUC__
+/* GCC, clang, and some ICC pretending to be GCC */
+#  define gmx_unused __attribute__ ((unused))
+#elif (defined(__INTEL_COMPILER) || defined(__ECC)) && !defined(_MSC_VER)
+/* ICC on *nix */
+#  define gmx_unused __attribute__ ((unused))
+#elif defined _MSC_VER
+/* MSVC */
+#  define gmx_unused /*@unused@*/
+#elif defined(__xlC__)
+/* IBM */
+#  define gmx_unused __attribute__ ((unused))
+#else
+#  define gmx_unused
+#endif
+#endif
+
+#endif
index 5c460c2dc006da332f48d9af9f6064d8625d8cbf..78aa66a782595194df4506b1f8c3fed67df64253 100644 (file)
@@ -46,7 +46,7 @@
 
 #include <stddef.h>
 
-#include "gromacs/legacyheaders/types/simple.h"
+#include "gromacs/utility/basedefinitions.h"
 
 #ifdef __cplusplus
 extern "C" {
index 74d6e06ded567ef0eed5048d57eae11d0ba4101a..58f1c64129f068814acfe8d951a37b009f381439 100644 (file)
@@ -59,9 +59,8 @@
 #include <unistd.h>
 #endif
 
-#include "gromacs/legacyheaders/types/simple.h"
-
 #include "gromacs/fileio/futil.h"
+#include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/basenetwork.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
index 6d8f94b4e7472dc27b5d5703360aa278437f75b0..15045d569ab5be8edd8dccbcc5d0858005d4e05e 100644 (file)
@@ -46,7 +46,7 @@
 #include <stdio.h>
 #include <time.h>
 
-#include "../legacyheaders/types/simple.h"
+#include "basedefinitions.h"
 
 #include "gmx_header_config.h"
 
index 8e8c0912f426ec201e531f5cf5316902e41f4efb..90808bd0fab29869700d61946f74f23732f7db61 100644 (file)
@@ -46,7 +46,7 @@
 
 #include <stdio.h>
 
-#include "../legacyheaders/types/simple.h"
+#include "basedefinitions.h"
 
 #ifdef __cplusplus
 extern "C" {
index 9b5303b05b22f82a7d9d7edd250e9b9bfc404aad..39664aecb6077e6b2df8c76240b2bfcad042a852 100644 (file)
@@ -69,7 +69,7 @@
 #include <windows.h>
 #endif
 
-#include "gromacs/legacyheaders/types/simple.h"
+#include "basedefinitions.h"
 
 #ifdef __cplusplus
 extern "C"