PyAPI: add utilities PyTuple_SET_ITEMS, Py_INCREF_RET
Setting all values of a tuple is such a common operation that it deserves its own macro. Also added Py_INCREF_RET to avoid confusing use of comma operator.
This commit is contained in:
@@ -92,10 +92,11 @@ ContextFunctions_get_border(PyObject *self)
|
||||
{
|
||||
BBox<Vec2i> border(ContextFunctions::GetBorderCF());
|
||||
PyObject *v = PyTuple_New(4);
|
||||
PyTuple_SET_ITEM(v, 0, PyLong_FromLong(border.getMin().x()));
|
||||
PyTuple_SET_ITEM(v, 1, PyLong_FromLong(border.getMin().y()));
|
||||
PyTuple_SET_ITEM(v, 2, PyLong_FromLong(border.getMax().x()));
|
||||
PyTuple_SET_ITEM(v, 3, PyLong_FromLong(border.getMax().y()));
|
||||
PyTuple_SET_ITEMS(v,
|
||||
PyLong_FromLong(border.getMin().x()),
|
||||
PyLong_FromLong(border.getMin().y()),
|
||||
PyLong_FromLong(border.getMax().x()),
|
||||
PyLong_FromLong(border.getMax().y()));
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
@@ -401,8 +401,9 @@ PyObject *BPy_CurvePoint_from_CurvePoint(CurvePoint& cp)
|
||||
PyObject *BPy_directedViewEdge_from_directedViewEdge(ViewVertex::directedViewEdge& dve)
|
||||
{
|
||||
PyObject *py_dve = PyTuple_New(2);
|
||||
PyTuple_SET_ITEM(py_dve, 0, BPy_ViewEdge_from_ViewEdge(*(dve.first)));
|
||||
PyTuple_SET_ITEM(py_dve, 1, PyBool_from_bool(dve.second));
|
||||
PyTuple_SET_ITEMS(py_dve,
|
||||
BPy_ViewEdge_from_ViewEdge(*(dve.first)),
|
||||
PyBool_from_bool(dve.second));
|
||||
return py_dve;
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ extern "C" {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "mathutils/mathutils.h"
|
||||
#include "generic/python_utildefines.h"
|
||||
|
||||
//==============================
|
||||
// C++ => Python
|
||||
|
||||
@@ -400,13 +400,14 @@ static PyObject *SVertex_curvatures_get(BPy_SVertex *self, void *UNUSED(closure)
|
||||
Vec3r e2(info->e2.x(), info->e2.y(), info->e2.z());
|
||||
Vec3r er(info->er.x(), info->er.y(), info->er.z());
|
||||
PyObject *retval = PyTuple_New(7);
|
||||
PyTuple_SET_ITEM(retval, 0, PyFloat_FromDouble(info->K1));
|
||||
PyTuple_SET_ITEM(retval, 2, Vector_from_Vec3r(e1));
|
||||
PyTuple_SET_ITEM(retval, 1, PyFloat_FromDouble(info->K2));
|
||||
PyTuple_SET_ITEM(retval, 3, Vector_from_Vec3r(e2));
|
||||
PyTuple_SET_ITEM(retval, 4, PyFloat_FromDouble(info->Kr));
|
||||
PyTuple_SET_ITEM(retval, 5, Vector_from_Vec3r(er));
|
||||
PyTuple_SET_ITEM(retval, 6, PyFloat_FromDouble(info->dKr));
|
||||
PyTuple_SET_ITEMS(retval,
|
||||
PyFloat_FromDouble(info->K1),
|
||||
PyFloat_FromDouble(info->K2),
|
||||
Vector_from_Vec3r(e1),
|
||||
Vector_from_Vec3r(e2),
|
||||
PyFloat_FromDouble(info->Kr),
|
||||
Vector_from_Vec3r(er),
|
||||
PyFloat_FromDouble(info->dKr));
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user