[Bf-blender-cvs] [24c9100] framebuffer: From review: use python callback for matrix error handling
Dalai Felinto
noreply at git.blender.org
Thu Oct 15 15:57:39 CEST 2015
Commit: 24c9100ad031f32e3e0b4c6aa7fb24352e9f4dc4
Author: Dalai Felinto
Date: Thu Oct 15 10:50:33 2015 -0300
Branches: framebuffer
https://developer.blender.org/rB24c9100ad031f32e3e0b4c6aa7fb24352e9f4dc4
>From review: use python callback for matrix error handling
Note: it could be added in py_capi_utils.c, but since it would require access to #include "../mathutils/mathutils.h" and we are the only ones using it, we can leave it here for now
===================================================================
M source/blender/python/intern/gpu_offscreen.c
===================================================================
diff --git a/source/blender/python/intern/gpu_offscreen.c b/source/blender/python/intern/gpu_offscreen.c
index b4f5970..9237734 100644
--- a/source/blender/python/intern/gpu_offscreen.c
+++ b/source/blender/python/intern/gpu_offscreen.c
@@ -168,25 +168,36 @@ static PyObject *pygpu_offscreen_unbind(PyGPUOffScreen *self, PyObject *args, Py
Py_RETURN_NONE;
}
-static bool pygpu_offscreen_check_matrix(MatrixObject *PyMat, const char *UNUSED(name))
+/**
+ * Use with PyArg_ParseTuple's "O&" formatting.
+ */
+static int pygpu_offscreen_check_matrix(PyObject *o, void *p)
{
+ MatrixObject **PyMat_p = p;
+ MatrixObject *PyMat = (MatrixObject *)o;
+
if (!MatrixObject_Check(PyMat)) {
- PyErr_SetString(PyExc_TypeError, "matrix is not in a valid format (e.g., mathutils.Matrix)");
- return false;
+ PyErr_Format(PyExc_TypeError,
+ "matrix is not in a valid format (e.g., mathutils.Matrix)",
+ Py_TYPE(o)->tp_name);
+ return 0;
}
if (BaseMath_ReadCallback(PyMat) == -1) {
- return false;
+ return 0;
}
if ((PyMat->num_col != 4) ||
(PyMat->num_row != 4))
{
- PyErr_SetString(PyExc_TypeError, "matrix need to have 4 rows and 4 columns");
- return false;
+ PyErr_Format(PyExc_TypeError,
+ "matrix must have 4 rows and 4 columns",
+ Py_TYPE(o)->tp_name);
+ return 0;
}
- return true;
+ *PyMat_p = PyMat;
+ return 1;
}
PyDoc_STRVAR(pygpu_offscreen_draw_doc,
@@ -211,12 +222,9 @@ static PyObject *pygpu_offscreen_draw(PyGPUOffScreen *self, PyObject *args, PyOb
BPY_GPU_OFFSCREEN_CHECK_OBJ(self, "draw");
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO:draw", (char **)(kwlist),
- &PyProjectionMatrix, &PyModelViewMatrix))
- return NULL;
-
- if ((!pygpu_offscreen_check_matrix(PyProjectionMatrix, "projection_matrix")) ||
- (!pygpu_offscreen_check_matrix(PyModelViewMatrix, "modelview_matrix")))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&:draw", (char **)(kwlist),
+ pygpu_offscreen_check_matrix, &PyProjectionMatrix,
+ pygpu_offscreen_check_matrix, &PyModelViewMatrix))
{
return NULL;
}
More information about the Bf-blender-cvs
mailing list