Move remaining C files in utility to C++
authorErik Lindahl <erik@kth.se>
Wed, 8 Jul 2015 14:59:06 +0000 (16:59 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 14 Jul 2015 09:29:00 +0000 (11:29 +0200)
Added spaces between strings and literals. The string handling
code should eventually be replaced with proper C++ versions using
std::string, so for this reason I have not bothered improving them.

Change-Id: I78b871113f4a3891139a412c7831a1e5209bfaec

src/gromacs/utility/cstringutil.cpp [moved from src/gromacs/utility/cstringutil.c with 99% similarity]
src/gromacs/utility/qsort_threadsafe.cpp [moved from src/gromacs/utility/qsort_threadsafe.c with 98% similarity]
src/gromacs/utility/smalloc.cpp [moved from src/gromacs/utility/smalloc.c with 95% similarity]

similarity index 99%
rename from src/gromacs/utility/cstringutil.c
rename to src/gromacs/utility/cstringutil.cpp
index bb0c250776f07540bef543c0404b5b973b1e1aeb..358201c6882caf3d6da15e128ddea39838aed66f 100644 (file)
 
 #include "cstringutil.h"
 
-#include <assert.h>
-#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+
+#include <cassert>
+#include <cctype>
+#include <cstring>
 
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/fatalerror.h"
@@ -129,7 +130,6 @@ void upstring (char *str)
 
 void ltrim (char *str)
 {
-    char *tr;
     int   i, c;
 
     if (NULL == str)
@@ -533,7 +533,7 @@ str_to_int64_t(const char *str, char **endptr)
 
 char *gmx_step_str(gmx_int64_t i, char *buf)
 {
-    sprintf(buf, "%"GMX_PRId64, i);
+    sprintf(buf, "%" GMX_PRId64, i);
     return buf;
 }
 
similarity index 98%
rename from src/gromacs/utility/qsort_threadsafe.c
rename to src/gromacs/utility/qsort_threadsafe.cpp
index 0f0849076d9d86296102516e970934c9d7c2b5d7..6a63bf225f43857a984686b22a2954ead4c47384 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2012,2014,2015, 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.
@@ -131,6 +131,11 @@ gmx_qsort(void *           base,
     int    t, v;
     size_t s, st;
 
+    if (size == 0)
+    {
+        return;
+    }
+
     cbase = (char *)base;
 
     swaptype = (size_t)(cbase - (char *)0) % sizeof(int) || size % sizeof(int) ? 2 : size == sizeof(int) ? 0 : 1;
@@ -175,8 +180,8 @@ gmx_qsort(void *           base,
     }
     else
     {
-        pv = (char*)(void*)&v;
         v  = *(int *)pm;
+        pv = (char*)(void*)&v;
     }
 
     pa = pb = cbase;
similarity index 95%
rename from src/gromacs/utility/smalloc.c
rename to src/gromacs/utility/smalloc.cpp
index 876675ecd440ad17f2346181bbed9b69c810e053..ac8fd499b0e6849de70030b19d7e9755ba3feb30 100644 (file)
@@ -43,7 +43,6 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 
 #ifdef WITH_DMALLOC
 #include <dmalloc.h>
@@ -52,6 +51,8 @@
 #include <malloc.h>
 #endif
 
+#include <cstring>
+
 #include "thread_mpi/threads.h"
 
 #include "gromacs/utility/dir_separator.h"
@@ -131,7 +132,7 @@ void *save_malloc(const char *name, const char *file, int line, size_t size)
         if ((p = malloc(size)) == NULL)
         {
             gmx_fatal(errno, __FILE__, __LINE__,
-                      "Not enough memory. Failed to malloc %"GMX_PRId64 " bytes for %s\n"
+                      "Not enough memory. Failed to malloc %" GMX_PRId64 " bytes for %s\n"
                       "(called from file %s, line %d)",
                       (gmx_int64_t)size, name, file, line);
         }
@@ -169,8 +170,8 @@ void *save_calloc(const char *name, const char *file, int line,
         if ((p = malloc((size_t)nelem*(size_t)elsize)) == NULL)
         {
             gmx_fatal(errno, __FILE__, __LINE__,
-                      "Not enough memory. Failed to calloc %"GMX_PRId64
-                      " elements of size %"GMX_PRId64
+                      "Not enough memory. Failed to calloc %" GMX_PRId64
+                      " elements of size %" GMX_PRId64
                       " for %s\n(called from file %s, line %d)",
                       (gmx_int64_t)nelem, (gmx_int64_t)elsize,
                       name, file, line);
@@ -180,8 +181,8 @@ void *save_calloc(const char *name, const char *file, int line,
         if ((p = calloc((size_t)nelem, (size_t)elsize)) == NULL)
         {
             gmx_fatal(errno, __FILE__, __LINE__,
-                      "Not enough memory. Failed to calloc %"GMX_PRId64
-                      " elements of size %"GMX_PRId64
+                      "Not enough memory. Failed to calloc %" GMX_PRId64
+                      " elements of size %" GMX_PRId64
                       " for %s\n(called from file %s, line %d)",
                       (gmx_int64_t)nelem, (gmx_int64_t)elsize, name, file, line);
         }
@@ -225,7 +226,7 @@ void *save_realloc(const char *name, const char *file, int line, void *ptr,
         if (p == NULL)
         {
             gmx_fatal(errno, __FILE__, __LINE__,
-                      "Not enough memory. Failed to realloc %"GMX_PRId64 " bytes for %s, %s=%x\n"
+                      "Not enough memory. Failed to realloc %" GMX_PRId64 " bytes for %s, %s=%x\n"
                       "(called from file %s, line %d)",
                       (gmx_int64_t)size, name, name, ptr, file, line);
         }
@@ -343,7 +344,6 @@ void *save_calloc_aligned(const char *name, const char *file, int line,
 /* This routine can NOT be called with any pointer */
 void save_free_aligned(const char gmx_unused *name, const char gmx_unused *file, int gmx_unused line, void *ptr)
 {
-    int   i, j;
     void *free = ptr;
 
     if (NULL != ptr)
@@ -375,7 +375,7 @@ int over_alloc_dd(int n)
 {
     if (g_bOverAllocDD)
     {
-        return OVER_ALLOC_FAC*n + 100;
+        return static_cast<int>(OVER_ALLOC_FAC*n + 100);
     }
     else
     {