[Bf-blender-cvs] [4073bfe80bf] pygpu_extensions: Buffer: Correct wrong error message in buffer creation

Germano Cavalcante noreply at git.blender.org
Fri Feb 12 22:56:30 CET 2021


Commit: 4073bfe80bfbbde80ffba3743f128d919f4fb813
Author: Germano Cavalcante
Date:   Fri Feb 12 18:21:44 2021 -0300
Branches: pygpu_extensions
https://developer.blender.org/rB4073bfe80bfbbde80ffba3743f128d919f4fb813

Buffer: Correct wrong error message in buffer creation

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

M	source/blender/python/gpu/gpu_py_buffer.c
M	source/blender/python/gpu/gpu_py_framebuffer.c

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

diff --git a/source/blender/python/gpu/gpu_py_buffer.c b/source/blender/python/gpu/gpu_py_buffer.c
index 2055660ce8a..d0144620c55 100644
--- a/source/blender/python/gpu/gpu_py_buffer.c
+++ b/source/blender/python/gpu/gpu_py_buffer.c
@@ -275,8 +275,7 @@ static PyObject *py_buffer_tp_new(PyTypeObject *UNUSED(type), PyObject *args, Py
   if (PyLong_Check(length_ob)) {
     ndimensions = 1;
     if (((dimensions[0] = PyLong_AsLong(length_ob)) < 1)) {
-      PyErr_SetString(PyExc_AttributeError,
-                      "dimensions must be between 1 and " STRINGIFY(MAX_DIMENSIONS));
+      PyErr_SetString(PyExc_AttributeError, "dimension must be greater than or equal to 1");
       return NULL;
     }
   }
@@ -293,9 +292,13 @@ static PyObject *py_buffer_tp_new(PyTypeObject *UNUSED(type), PyObject *args, Py
     }
     for (i = 0; i < ndimensions; i++) {
       PyObject *ob = PySequence_GetItem(length_ob, i);
-
       if (!PyLong_Check(ob)) {
-        dimensions[i] = 1;
+        PyErr_Format(PyExc_TypeError,
+                     "invalid dimension %i, expected an int, not a %.200s",
+                     i,
+                     Py_TYPE(ob)->tp_name);
+        Py_DECREF(ob);
+        return NULL;
       }
       else {
         dimensions[i] = PyLong_AsLong(ob);
@@ -303,8 +306,7 @@ static PyObject *py_buffer_tp_new(PyTypeObject *UNUSED(type), PyObject *args, Py
       Py_DECREF(ob);
 
       if (dimensions[i] < 1) {
-        PyErr_SetString(PyExc_AttributeError,
-                        "dimensions must be between 1 and " STRINGIFY(MAX_DIMENSIONS));
+        PyErr_SetString(PyExc_AttributeError, "dimension must be greater than or equal to 1");
         return NULL;
       }
     }
diff --git a/source/blender/python/gpu/gpu_py_framebuffer.c b/source/blender/python/gpu/gpu_py_framebuffer.c
index b44508faa35..6def4eec472 100644
--- a/source/blender/python/gpu/gpu_py_framebuffer.c
+++ b/source/blender/python/gpu/gpu_py_framebuffer.c
@@ -268,7 +268,9 @@ static PyObject *py_framebuffer_new(PyTypeObject *UNUSED(self), PyObject *args,
       int len = PySequence_Size(color_attachements);
       for (int i = 0; i < len; i++) {
         PyObject *o = PySequence_GetItem(color_attachements, i);
-        if (!py_framebuffer_parse_arg(o, &slot[i].tex, &slot[i].layer, &slot[i].mip)) {
+        bool ok = py_framebuffer_parse_arg(o, &slot[i].tex, &slot[i].layer, &slot[i].mip);
+        Py_DECREF(o);
+        if (!ok) {
           return NULL;
         }
       }



More information about the Bf-blender-cvs mailing list