replace atoi()/atof() with std::stoX()

This commit is contained in:
Axel Kohlmeyer
2024-07-30 16:25:39 -04:00
parent 7b2c7e0df8
commit 3c6adde66b
2 changed files with 8 additions and 10 deletions

View File

@ -20,13 +20,12 @@
#if PY_MAJOR_VERSION == 2 #if PY_MAJOR_VERSION == 2
#if defined(_MSC_VER) || defined(__MINGW32__) #if defined(_MSC_VER) || defined(__MINGW32__)
#define PY_INT_FROM_LONG(X) PyLong_FromLongLong(X) #define PY_INT_FROM_LONG(X) PyLong_FromLongLong(X)
#define PY_INT_AS_LONG(X) PyLong_AsLongLong(X)
#define PY_LONG_FROM_STRING(X) std::stoll(X)
#else #else
#define PY_INT_FROM_LONG(X) PyInt_FromLong(X) #define PY_INT_FROM_LONG(X) PyInt_FromLong(X)
#endif
#if defined(_MSC_VER) || defined(__MINGW32__)
#define PY_INT_AS_LONG(X) PyLong_AsLongLong(X)
#else
#define PY_INT_AS_LONG(X) PyInt_AsLong(X) #define PY_INT_AS_LONG(X) PyInt_AsLong(X)
#define PY_LONG_FROM_STRING(X) std::stol(X)
#endif #endif
#define PY_STRING_FROM_STRING(X) PyString_FromString(X) #define PY_STRING_FROM_STRING(X) PyString_FromString(X)
#define PY_VOID_POINTER(X) PyCObject_FromVoidPtr((void *) X, nullptr) #define PY_VOID_POINTER(X) PyCObject_FromVoidPtr((void *) X, nullptr)
@ -35,13 +34,12 @@
#elif PY_MAJOR_VERSION == 3 #elif PY_MAJOR_VERSION == 3
#if defined(_MSC_VER) || defined(__MINGW32__) #if defined(_MSC_VER) || defined(__MINGW32__)
#define PY_INT_FROM_LONG(X) PyLong_FromLongLong(X) #define PY_INT_FROM_LONG(X) PyLong_FromLongLong(X)
#define PY_INT_AS_LONG(X) PyLong_AsLongLong(X)
#define PY_LONG_FROM_STRING(X) std::stoll(X)
#else #else
#define PY_INT_FROM_LONG(X) PyLong_FromLong(X) #define PY_INT_FROM_LONG(X) PyLong_FromLong(X)
#endif
#if defined(_MSC_VER) || defined(__MINGW32__)
#define PY_INT_AS_LONG(X) PyLong_AsLongLong(X)
#else
#define PY_INT_AS_LONG(X) PyLong_AsLong(X) #define PY_INT_AS_LONG(X) PyLong_AsLong(X)
#define PY_LONG_FROM_STRING(X) std::stol(X)
#endif #endif
#define PY_STRING_FROM_STRING(X) PyUnicode_FromString(X) #define PY_STRING_FROM_STRING(X) PyUnicode_FromString(X)
#define PY_VOID_POINTER(X) PyCapsule_New((void *) X, nullptr, nullptr) #define PY_VOID_POINTER(X) PyCapsule_New((void *) X, nullptr, nullptr)

View File

@ -341,7 +341,7 @@ void PythonImpl::invoke_function(int ifunc, char *result)
if (!str) if (!str)
error->all(FLERR, "Could not evaluate Python function {} input variable: {}", error->all(FLERR, "Could not evaluate Python function {} input variable: {}",
pfuncs[ifunc].name, pfuncs[ifunc].svalue[i]); pfuncs[ifunc].name, pfuncs[ifunc].svalue[i]);
pValue = PY_INT_FROM_LONG(atoi(str)); pValue = PY_INT_FROM_LONG(PY_LONG_FROM_STRING(str));
} else { } else {
pValue = PY_INT_FROM_LONG(pfuncs[ifunc].ivalue[i]); pValue = PY_INT_FROM_LONG(pfuncs[ifunc].ivalue[i]);
} }
@ -351,7 +351,7 @@ void PythonImpl::invoke_function(int ifunc, char *result)
if (!str) if (!str)
error->all(FLERR, "Could not evaluate Python function {} input variable: {}", error->all(FLERR, "Could not evaluate Python function {} input variable: {}",
pfuncs[ifunc].name, pfuncs[ifunc].svalue[i]); pfuncs[ifunc].name, pfuncs[ifunc].svalue[i]);
pValue = PyFloat_FromDouble(atof(str)); pValue = PyFloat_FromDouble(std::stod(str));
} else { } else {
pValue = PyFloat_FromDouble(pfuncs[ifunc].dvalue[i]); pValue = PyFloat_FromDouble(pfuncs[ifunc].dvalue[i]);
} }