diff --git a/paddle/legacy/utils/PythonUtil.h b/paddle/legacy/utils/PythonUtil.h index b0c8612c378fbe12cdf24e51a5b6546740b2d4c8..ca052e188bdcaaff4cb51544310d7d230f1ee998 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.