From 4cbee8ac6e528a29f368a0afe3cd11851af49228 Mon Sep 17 00:00:00 2001 From: minqiyang Date: Wed, 11 Jul 2018 19:05:17 +0800 Subject: [PATCH] Add the PYTHON_VERSION support --- paddle/legacy/utils/PythonUtil.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/paddle/legacy/utils/PythonUtil.h b/paddle/legacy/utils/PythonUtil.h index b0c8612c3..ca052e188 100644 --- a/paddle/legacy/utils/PythonUtil.h +++ b/paddle/legacy/utils/PythonUtil.h @@ -88,6 +88,7 @@ PyObjectPtr createPythonClass(const std::string& moduleName, namespace py { PyObjectPtr import(const std::string& moduleName); +#if PY_MAJOR_VERSION >= 3 /** * Cast a PyLong or PyInt to int type T. * @tparam T return type. @@ -98,17 +99,18 @@ PyObjectPtr import(const std::string& moduleName); */ template T castInt(PyObject* obj, bool* ok = nullptr) { - if (PyLong_Check(obj)) { + if (::PyLong_Check(obj)) { if (ok) *ok = true; return (T)PyLong_AsUnsignedLong(obj); - } else if (PyInt_Check(obj)) { + } else if (::PyInt_Check(obj)) { if (ok) *ok = true; - return (T)PyInt_AsLong(obj); + return (T)::PyInt_AsLong(obj); } else { if (ok) *ok = false; return (T)0; } } +#endif // PY_MAJOR_VERSION /** * Invoke repr of python object. -- GitLab