Commit: 9748a300cc974be8215906b1b7b64163fc708ccf
Author: Campbell Barton
Date:   Thu Jul 16 18:52:02 2015 +1000
Branches: mathutils_bvhtree
https://developer.blender.org/rB9748a300cc974be8215906b1b7b64163fc708ccf

Use PyC_AsArray macro

===================================================================

M       source/blender/python/mathutils/mathutils_bvhtree.c

===================================================================

diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c 
b/source/blender/python/mathutils/mathutils_bvhtree.c
index 46c1610..66d3337 100644
--- a/source/blender/python/mathutils/mathutils_bvhtree.c
+++ b/source/blender/python/mathutils/mathutils_bvhtree.c
@@ -244,7 +244,6 @@ static bool py_BVHTreeDerivedMesh_find_nearest_parse_args(
        return true;
 }
 
-
 static int dm_tessface_to_poly_index(DerivedMesh *dm, int tessface_index)
 {
        if (tessface_index != ORIGINDEX_NONE && tessface_index < 
dm->getNumTessFaces(dm)) {
@@ -810,38 +809,23 @@ static int PyBVHTreeCustom__tp_init(PyBVHTree_Custom 
*self, PyObject *args, PyOb
                tp = tris = MEM_mallocN(sizeof(BVHTriangle) * (size_t)numtris, 
"BPy BVHTree triangles");
                for (i = 0; i < numtris; i++) {
                        PyObject *py_triverts = 
PySequence_Fast_GET_ITEM(py_tris_fast, i);
-                       PyObject *py_triverts_fast = 
PySequence_Fast(py_triverts, error_prefix);
                        int j;
 
-                       if (py_triverts_fast == NULL) {
-                               valid = false;
-                               break;
-                       }
-                       
-                       if (PySequence_Fast_GET_SIZE(py_triverts_fast) != 3) {
-                               Py_DECREF(py_triverts_fast);
-                               PyErr_SetString(PyExc_TypeError,
-                                               "One or more of the triangles 
does not have 3 indices");
+                       if (PyC_AsArray((void *)tp->tri, py_triverts, 3, 
&PyLong_Type, false, error_prefix) == -1) {
                                valid = false;
                                break;
                        }
-                       
+
                        for (j = 0; j < 3; j++) {
-                               const int index = 
_PyLong_AsInt(PySequence_Fast_GET_ITEM(py_triverts_fast, j));
-                               if (UNLIKELY(index == -1 && PyErr_Occurred())) {
-                                       valid = false;
-                                       break;
-                               }
-                               else if (UNLIKELY((unsigned int)index >= 
numverts)) {
+                               if (UNLIKELY((unsigned int)tp->tri[j] >= 
(unsigned int)numverts)) {
                                        PyErr_Format(PyExc_ValueError,
-                                                    "Index %d out of range 
[0-%d]", index, numverts);
+                                                    "%s: index %d must be less 
than %d",
+                                                    error_prefix, tp->tri[j], 
numverts);
+
                                        valid = false;
                                        break;
                                }
-
-                               tp->tri[j] = index;
                        }
-                       Py_DECREF(py_triverts_fast);
                }
        }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to