Commit: 4599dadbaa2447160ab68f6ee86cfe1694527a20
Author: Campbell Barton
Date:   Tue Jun 17 23:19:19 2014 +1000
https://developer.blender.org/rB4599dadbaa2447160ab68f6ee86cfe1694527a20

remove unused includes, simplify alloc/free

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

M       source/blender/python/intern/bpy_utils_units.c

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

diff --git a/source/blender/python/intern/bpy_utils_units.c 
b/source/blender/python/intern/bpy_utils_units.c
index 95fdaa6..887eb44 100644
--- a/source/blender/python/intern/bpy_utils_units.c
+++ b/source/blender/python/intern/bpy_utils_units.c
@@ -31,7 +31,6 @@
 #define PY_SSIZE_T_CLEAN
 
 #include <Python.h>
-/* XXX Why bloody hell isn't that included in Python.h???? */
 #include <structmember.h>
 
 #include "BLI_utildefines.h"
@@ -43,13 +42,8 @@
 
 #include "../generic/py_capi_utils.h"
 
-#include "MEM_guardedalloc.h"
-
 #include "BKE_unit.h"
 
-#include "RNA_types.h"
-#include "RNA_access.h"
-
 /***** C-defined systems and types *****/
 
 static PyTypeObject BPyUnitsSystemsType;
@@ -191,6 +185,7 @@ static PyObject *bpyunits_to_value(PyObject *UNUSED(self), 
PyObject *args, PyObj
        Py_ssize_t str_len;
        double result;
        int usys, ucat;
+       PyObject *ret;
 
        if (!PyArg_ParseTupleAndKeywords(args, kw, 
"sss#|z:bpy.utils.units.to_value", (char **)kwlist,
                                         &usys_str, &ucat_str, &inpt, &str_len, 
&uref))
@@ -198,15 +193,14 @@ static PyObject *bpyunits_to_value(PyObject 
*UNUSED(self), PyObject *args, PyObj
                return NULL;
        }
 
-       str_len = str_len * 2 + 64;
-       str = MEM_mallocN(sizeof(*str) * (size_t)str_len, __func__);
-       BLI_strncpy(str, inpt, (size_t)str_len);
-
        if (!bpyunits_validate(usys_str, ucat_str, &usys, &ucat)) {
-               MEM_freeN(str);
                return NULL;
        }
 
+       str_len = str_len * 2 + 64;
+       str = PyMem_MALLOC(sizeof(*str) * (size_t)str_len);
+       BLI_strncpy(str, inpt, (size_t)str_len);
+
        bUnit_ReplaceString(str, (int)str_len, uref, scale, usys, ucat);
 
        if (PyC_RunString_AsNumber(str, &result, "<bpy_units_api>") != 0) {
@@ -218,12 +212,14 @@ static PyObject *bpyunits_to_value(PyObject 
*UNUSED(self), PyObject *args, PyObj
                PyErr_Format(PyExc_ValueError,
                             "'%.200s' (converted as '%s') could not be 
evaluated.",
                             inpt, str);
-               MEM_freeN(str);
-               return NULL;
+               ret = NULL;
+       }
+       else {
+               ret = PyFloat_FromDouble(result);
        }
 
-       MEM_freeN(str);
-       return PyFloat_FromDouble(result);
+       PyMem_FREE(str);
+       return ret;
 }
 
 PyDoc_STRVAR(bpyunits_to_string_doc,

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

Reply via email to