[Bf-blender-cvs] [fc3fc94] temp-pyapi-units: Revert to static size for our buffers.
Bastien Montagne
noreply at git.blender.org
Tue Jun 17 15:06:57 CEST 2014
Commit: fc3fc949ffe7e4ee706c50b585c23b6635da7af9
Author: Bastien Montagne
Date: Tue Jun 17 14:59:37 2014 +0200
https://developer.blender.org/rBfc3fc949ffe7e4ee706c50b585c23b6635da7af9
Revert to static size for our buffers.
64 should be more than enough, never could get strings longer than ~21 chars so far.
===================================================================
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 c8d728f..95fdaa6 100644
--- a/source/blender/python/intern/bpy_utils_units.c
+++ b/source/blender/python/intern/bpy_utils_units.c
@@ -274,16 +274,15 @@ static PyObject *bpyunits_to_string(PyObject *UNUSED(self), PyObject *args, PyOb
* - number itself: precision + decimal dot + up to four 'above dot' digits.
* - unit: up to ten chars (six currently, let's be conservative, also because we use some utf8 chars).
* This can be repeated twice (e.g. 1m20cm), and we add ten more spare chars (spaces, trailing '\0'...).
+ * So in practice, 64 should be more than enough.
*/
- const size_t buflen = (precision + 5 + 10) * 2 + 10;
- char *buf1 = MEM_mallocN(sizeof(char) * buflen, __func__), *buf2 = NULL, *str;
+ char buf1[64], buf2[64], *str;
PyObject *result;
- bUnit_AsString(buf1, buflen, value, precision, usys, ucat, (bool)split_unit, false);
+ bUnit_AsString(buf1, sizeof(buf1), value, precision, usys, ucat, (bool)split_unit, false);
if (compatible_unit) {
- buf2 = MEM_mallocN(sizeof(char) * buflen, __func__);
- bUnit_ToUnitAltName(buf2, buflen, buf1, usys, ucat);
+ bUnit_ToUnitAltName(buf2, sizeof(buf2), buf1, usys, ucat);
str = buf2;
}
else {
@@ -291,13 +290,10 @@ static PyObject *bpyunits_to_string(PyObject *UNUSED(self), PyObject *args, PyOb
}
/* Just for test, to remove before final commit! */
- printf("%d for %d used...\n", (int)buflen, (int)strlen(str));
+ printf("%d for %d used...\n", (int)sizeof(buf1), (int)strlen(str));
result = PyUnicode_FromString(str);
- MEM_SAFE_FREE(buf1);
- MEM_SAFE_FREE(buf2);
-
return result;
}
}
More information about the Bf-blender-cvs
mailing list