From: Erik Lindahl Date: Wed, 8 Jul 2015 14:59:06 +0000 (+0200) Subject: Move remaining C files in utility to C++ X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=5ef65c767e11c97eefeb759754286305e3ec8ce0;hp=af0aa4aec0fc1ecae9c3f921e6dfe7ed2aa7d10a;p=alexxy%2Fgromacs.git Move remaining C files in utility to C++ 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 --- diff --git a/src/gromacs/utility/cstringutil.c b/src/gromacs/utility/cstringutil.cpp similarity index 99% rename from src/gromacs/utility/cstringutil.c rename to src/gromacs/utility/cstringutil.cpp index bb0c250776..358201c688 100644 --- a/src/gromacs/utility/cstringutil.c +++ b/src/gromacs/utility/cstringutil.cpp @@ -39,11 +39,12 @@ #include "cstringutil.h" -#include -#include #include #include -#include + +#include +#include +#include #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; } diff --git a/src/gromacs/utility/qsort_threadsafe.c b/src/gromacs/utility/qsort_threadsafe.cpp similarity index 98% rename from src/gromacs/utility/qsort_threadsafe.c rename to src/gromacs/utility/qsort_threadsafe.cpp index 0f0849076d..6a63bf225f 100644 --- a/src/gromacs/utility/qsort_threadsafe.c +++ b/src/gromacs/utility/qsort_threadsafe.cpp @@ -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; diff --git a/src/gromacs/utility/smalloc.c b/src/gromacs/utility/smalloc.cpp similarity index 95% rename from src/gromacs/utility/smalloc.c rename to src/gromacs/utility/smalloc.cpp index 876675ecd4..ac8fd499b0 100644 --- a/src/gromacs/utility/smalloc.c +++ b/src/gromacs/utility/smalloc.cpp @@ -43,7 +43,6 @@ #include #include #include -#include #ifdef WITH_DMALLOC #include @@ -52,6 +51,8 @@ #include #endif +#include + #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(OVER_ALLOC_FAC*n + 100); } else {