提交 4cbee8ac 编写于 作者: M minqiyang

Add the PYTHON_VERSION support

上级 bbed762b
......@@ -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 <typename T>
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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册