diff --git a/src/PYTHON/python_compat.h b/src/PYTHON/python_compat.h index 775435ffd8..d1194056d8 100644 --- a/src/PYTHON/python_compat.h +++ b/src/PYTHON/python_compat.h @@ -20,13 +20,12 @@ #if PY_MAJOR_VERSION == 2 #if defined(_MSC_VER) || defined(__MINGW32__) #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 #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_LONG_FROM_STRING(X) std::stol(X) #endif #define PY_STRING_FROM_STRING(X) PyString_FromString(X) #define PY_VOID_POINTER(X) PyCObject_FromVoidPtr((void *) X, nullptr) @@ -35,13 +34,12 @@ #elif PY_MAJOR_VERSION == 3 #if defined(_MSC_VER) || defined(__MINGW32__) #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 #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_LONG_FROM_STRING(X) std::stol(X) #endif #define PY_STRING_FROM_STRING(X) PyUnicode_FromString(X) #define PY_VOID_POINTER(X) PyCapsule_New((void *) X, nullptr, nullptr) diff --git a/src/PYTHON/python_impl.cpp b/src/PYTHON/python_impl.cpp index 87a57187bf..91e0a7abe5 100644 --- a/src/PYTHON/python_impl.cpp +++ b/src/PYTHON/python_impl.cpp @@ -341,7 +341,7 @@ void PythonImpl::invoke_function(int ifunc, char *result) if (!str) error->all(FLERR, "Could not evaluate Python function {} input variable: {}", 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 { pValue = PY_INT_FROM_LONG(pfuncs[ifunc].ivalue[i]); } @@ -351,7 +351,7 @@ void PythonImpl::invoke_function(int ifunc, char *result) if (!str) error->all(FLERR, "Could not evaluate Python function {} input variable: {}", pfuncs[ifunc].name, pfuncs[ifunc].svalue[i]); - pValue = PyFloat_FromDouble(atof(str)); + pValue = PyFloat_FromDouble(std::stod(str)); } else { pValue = PyFloat_FromDouble(pfuncs[ifunc].dvalue[i]); }