App: remove Py2 code from several src/App .cpp files
This commit is contained in:
@@ -445,17 +445,8 @@ static Py::Object _pyObjectFromAny(const App::any &value, const Expression *e) {
|
||||
else if (is_type(value,typeid(float)))
|
||||
return Py::Float(cast<float>(value));
|
||||
else if (is_type(value,typeid(int)))
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
return Py::Int(cast<int>(value));
|
||||
#else
|
||||
return Py::Long(cast<int>(value));
|
||||
#endif
|
||||
else if (is_type(value,typeid(long))) {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
long l = cast<long>(value);
|
||||
if(std::abs(l)<=INT_MAX)
|
||||
return Py::Int(int(l));
|
||||
#endif
|
||||
return Py::Long(cast<long>(value));
|
||||
} else if (is_type(value,typeid(bool)))
|
||||
return Py::Boolean(cast<bool>(value));
|
||||
@@ -490,23 +481,8 @@ App::any pyObjectToAny(Py::Object value, bool check) {
|
||||
}
|
||||
if (PyFloat_Check(pyvalue))
|
||||
return App::any(PyFloat_AsDouble(pyvalue));
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
if (PyInt_Check(pyvalue))
|
||||
return App::any(PyInt_AsLong(pyvalue));
|
||||
#endif
|
||||
if (PyLong_Check(pyvalue))
|
||||
return App::any(PyLong_AsLong(pyvalue));
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyString_Check(pyvalue))
|
||||
return App::any(std::string(PyString_AsString(pyvalue)));
|
||||
else if (PyUnicode_Check(pyvalue)) {
|
||||
PyObject * s = PyUnicode_AsUTF8String(pyvalue);
|
||||
if(!s)
|
||||
FC_THROWM(Base::ValueError,"Invalid unicode string");
|
||||
Py::Object o(s,true);
|
||||
return App::any(std::string(PyString_AsString(s)));
|
||||
}
|
||||
#else
|
||||
else if (PyUnicode_Check(pyvalue)) {
|
||||
const char* value = PyUnicode_AsUTF8(pyvalue);
|
||||
if (!value) {
|
||||
@@ -514,7 +490,6 @@ App::any pyObjectToAny(Py::Object value, bool check) {
|
||||
}
|
||||
return App::any(std::string(value));
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
return App::any(pyObjectWrap(pyvalue));
|
||||
}
|
||||
@@ -525,10 +500,6 @@ bool pyToQuantity(Quantity &q, const Py::Object &pyobj) {
|
||||
q = *static_cast<Base::QuantityPy*>(*pyobj)->getQuantityPtr();
|
||||
else if (PyFloat_Check(*pyobj))
|
||||
q = Quantity(PyFloat_AsDouble(*pyobj));
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyInt_Check(*pyobj))
|
||||
q = Quantity(PyInt_AsLong(*pyobj));
|
||||
#endif
|
||||
else if (PyLong_Check(*pyobj))
|
||||
q = Quantity(PyLong_AsLong(*pyobj));
|
||||
else
|
||||
@@ -1479,30 +1450,6 @@ static Py::Object calc(const Expression *expr, int op,
|
||||
BINARY_OP(DIV,TrueDivide)
|
||||
case OperatorExpression::ADD: {
|
||||
PyObject *res;
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
if (PyString_CheckExact(*l) && PyString_CheckExact(*r)) {
|
||||
Py_ssize_t v_len = PyString_GET_SIZE(*l);
|
||||
Py_ssize_t w_len = PyString_GET_SIZE(*r);
|
||||
Py_ssize_t new_len = v_len + w_len;
|
||||
if (new_len < 0)
|
||||
__EXPR_THROW(OverflowError, "strings are too large to concat", expr);
|
||||
|
||||
if (l.ptr()->ob_refcnt==1 && !PyString_CHECK_INTERNED(l.ptr())) {
|
||||
res = Py::new_reference_to(l);
|
||||
// Must make sure ob_refcnt is still 1
|
||||
l = Py::Object();
|
||||
if (_PyString_Resize(&res, new_len) != 0)
|
||||
EXPR_PY_THROW(expr);
|
||||
memcpy(PyString_AS_STRING(res) + v_len, PyString_AS_STRING(*r), w_len);
|
||||
}else{
|
||||
res = Py::new_reference_to(l);
|
||||
l = Py::Object();
|
||||
PyString_Concat(&res,*r);
|
||||
if(!res) EXPR_PY_THROW(expr);
|
||||
}
|
||||
return Py::asObject(res);
|
||||
}
|
||||
#else
|
||||
if (PyUnicode_CheckExact(*l) && PyUnicode_CheckExact(*r)) {
|
||||
if(inplace) {
|
||||
res = Py::new_reference_to(l);
|
||||
@@ -1516,7 +1463,6 @@ static Py::Object calc(const Expression *expr, int op,
|
||||
if(!res) EXPR_PY_THROW(expr);
|
||||
return Py::asObject(res);
|
||||
}
|
||||
#endif
|
||||
_BINARY_OP(Add);
|
||||
}
|
||||
case OperatorExpression::POW: {
|
||||
@@ -1530,15 +1476,9 @@ static Py::Object calc(const Expression *expr, int op,
|
||||
}
|
||||
case OperatorExpression::MOD: {
|
||||
PyObject *res;
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
if (PyString_CheckExact(l.ptr()) &&
|
||||
(!PyString_Check(r.ptr()) || PyString_CheckExact(r.ptr())))
|
||||
res = PyString_Format(l.ptr(), r.ptr());
|
||||
#else
|
||||
if (PyUnicode_CheckExact(l.ptr()) &&
|
||||
(!PyUnicode_Check(r.ptr()) || PyUnicode_CheckExact(r.ptr())))
|
||||
res = PyUnicode_Format(l.ptr(), r.ptr());
|
||||
#endif
|
||||
else if(inplace)
|
||||
res = PyNumber_InPlaceRemainder(l.ptr(),r.ptr());
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user