Commit: c256faa6a8b1a2c6f71a0e48f45d976a7b6be65d
Author: Campbell Barton
Date:   Tue Jun 17 14:48:13 2014 +1000
https://developer.blender.org/rBc256faa6a8b1a2c6f71a0e48f45d976a7b6be65d

Minor cleanup/changes to api & docstrings

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

M       source/blender/blenkernel/BKE_unit.h
M       source/blender/blenlib/BLI_string.h
M       source/blender/blenlib/intern/string.c
M       source/blender/python/generic/py_capi_utils.c
M       source/blender/python/intern/bpy_utils_units.c

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

diff --git a/source/blender/blenkernel/BKE_unit.h 
b/source/blender/blenkernel/BKE_unit.h
index 853a8db..5988172 100644
--- a/source/blender/blenkernel/BKE_unit.h
+++ b/source/blender/blenkernel/BKE_unit.h
@@ -62,17 +62,17 @@ double      bUnit_GetScaler(void *usys_pt, int index);
 
 /* aligned with PropertyUnit */
 enum {
-       B_UNIT_NONE          = 0,
-       B_UNIT_LENGTH        = 1,
-       B_UNIT_AREA          = 2,
-       B_UNIT_VOLUME        = 3,
-       B_UNIT_MASS          = 4,
-       B_UNIT_ROTATION      = 5,
-       B_UNIT_TIME          = 6,
-       B_UNIT_VELOCITY      = 7,
-       B_UNIT_ACCELERATION  = 8,
-       B_UNIT_CAMERA        = 9,
-       B_UNIT_TYPE_TOT      = 10,
+       B_UNIT_NONE             = 0,
+       B_UNIT_LENGTH           = 1,
+       B_UNIT_AREA             = 2,
+       B_UNIT_VOLUME           = 3,
+       B_UNIT_MASS             = 4,
+       B_UNIT_ROTATION         = 5,
+       B_UNIT_TIME             = 6,
+       B_UNIT_VELOCITY         = 7,
+       B_UNIT_ACCELERATION     = 8,
+       B_UNIT_CAMERA           = 9,
+       B_UNIT_TYPE_TOT         = 10,
 };
 
 #ifdef __cplusplus
diff --git a/source/blender/blenlib/BLI_string.h 
b/source/blender/blenlib/BLI_string.h
index d3172fd..235147d 100644
--- a/source/blender/blenlib/BLI_string.h
+++ b/source/blender/blenlib/BLI_string.h
@@ -76,7 +76,8 @@ void BLI_ascii_strtolower(char *str, const size_t len) 
ATTR_NONNULL();
 void BLI_ascii_strtoupper(char *str, const size_t len) ATTR_NONNULL();
 int BLI_str_rstrip_float_zero(char *str, const char pad) ATTR_NONNULL();
 
-int BLI_str_index_in_array(const char *str, const char **str_array, const int 
len);
+int BLI_str_index_in_array_n(const char *__restrict str, const char 
**__restrict str_array, const int str_array_len) ATTR_NONNULL();
+int BLI_str_index_in_array(const char *__restrict str, const char **__restrict 
str_array) ATTR_NONNULL();
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenlib/intern/string.c 
b/source/blender/blenlib/intern/string.c
index 8a4de00..4ab568e 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -642,33 +642,42 @@ int BLI_str_rstrip_float_zero(char *str, const char pad)
 
 /**
  * Return index of a string in a string array.
- * Note it accepts a 'null' len value (-1), in which case it expects str_array 
to be NULL terminated.
  *
  * \param str The string to find.
- * \param str_array The array of strings, must be NULL-terminated if len is -1.
- * \param len the length of the array, or -1 for a NULL-terminated array.
- * \return The index of str in str_array if found, else -1.
+ * \param str_array Array of strings.
+ * \param str_array_len The length of the array, or -1 for a NULL-terminated 
array.
+ * \return The index of str in str_array or -1.
  */
-int BLI_str_index_in_array(const char *str, const char **str_array, const int 
len)
+int BLI_str_index_in_array_n(const char *str, const char **str_array, const 
int str_array_len)
 {
-       int idx;
-       char **arr = str_array;
+       int index;
+       const char **str_iter = str_array;
 
-       if (len == -1) {
-               for (idx = 0; *arr; ++arr, ++idx) {
-                       if (STREQ(str, *arr)) {
-                               break;
-                       }
+       for (index = 0; index < str_array_len; str_iter++, index++) {
+               if (STREQ(str, *str_iter)) {
+                       return index;
                }
-               return *arr ? idx : -1;
        }
-       else {
-               for (idx = 0; idx < len; ++arr, ++idx) {
-                       if (STREQ(str, *arr)) {
-                               break;
-                       }
+       return -1;
+}
+
+/**
+ * Return index of a string in a string array.
+ *
+ * \param str The string to find.
+ * \param str_array Array of strings, (must be NULL-terminated).
+ * \return The index of str in str_array or -1.
+ */
+int BLI_str_index_in_array(const char *str, const char **str_array)
+{
+       int index;
+       const char **str_iter = str_array;
+
+       for (index = 0; *str_iter; str_iter++, index++) {
+               if (STREQ(str, *str_iter)) {
+                       return index;
                }
-               return (idx == len) ? -1 : idx;
        }
+       return -1;
 }
 
diff --git a/source/blender/python/generic/py_capi_utils.c 
b/source/blender/python/generic/py_capi_utils.c
index d653cfb..8454f5b 100644
--- a/source/blender/python/generic/py_capi_utils.c
+++ b/source/blender/python/generic/py_capi_utils.c
@@ -906,8 +906,10 @@ PyObject *PyC_FlagSet_FromBitfield(PyC_FlagSet *items, int 
flag)
 }
 
 
-/* return -1 on error, else 0
- * Note it is caller's responsibility to acquire & release GIL!
+/**
+ * \return -1 on error, else 0
+ *
+ * \note it is caller's responsibility to acquire & release GIL!
  */
 int PyC_RunString_AsNumber(const char *expr, double *value, const char 
*filename)
 {
diff --git a/source/blender/python/intern/bpy_utils_units.c 
b/source/blender/python/intern/bpy_utils_units.c
index 3fef39c..7d50bc7 100644
--- a/source/blender/python/intern/bpy_utils_units.c
+++ b/source/blender/python/intern/bpy_utils_units.c
@@ -94,23 +94,23 @@ static const char *bpyunits_ucategories[] = {
  * This allows us to avoid many handwriting, and above all, to keep all 
systems/categories definition stuff in
  * BKE_unit.h!
  */
-static PyStructSequence_Field 
utils_units_systems_fields[ARRAY_SIZE(bpyunits_usystems)] = {{NULL}};
-static PyStructSequence_Field 
utils_units_categories_fields[ARRAY_SIZE(bpyunits_ucategories)] = {{NULL}};
+static PyStructSequence_Field 
bpyunits_systems_fields[ARRAY_SIZE(bpyunits_usystems)] = {{NULL}};
+static PyStructSequence_Field 
bpyunits_categories_fields[ARRAY_SIZE(bpyunits_ucategories)] = {{NULL}};
 
-static PyStructSequence_Desc utils_units_systems_desc = {
+static PyStructSequence_Desc bpyunits_systems_desc = {
        (char *)"bpy.utils.units.systems",     /* name */
        (char *)"This named tuple contains all pre-defined unit systems",    /* 
doc */
-       utils_units_systems_fields,    /* fields */
-       (sizeof(utils_units_systems_fields) / sizeof(PyStructSequence_Field)) - 
1
+       bpyunits_systems_fields,    /* fields */
+       ARRAY_SIZE(bpyunits_systems_fields) - 1
 };
-static PyStructSequence_Desc utils_units_categories_desc = {
+static PyStructSequence_Desc bpyunits_categories_desc = {
        (char *)"bpy.utils.units.categories",     /* name */
        (char *)"This named tuple contains all pre-defined unit names",    /* 
doc */
-       utils_units_categories_fields,    /* fields */
-       (sizeof(utils_units_categories_fields) / 
sizeof(PyStructSequence_Field)) - 1
+       bpyunits_categories_fields,    /* fields */
+       ARRAY_SIZE(bpyunits_categories_fields) - 1
 };
 
-static PyObject *utils_units_systems_make(void)
+static PyObject *bpyunits_systems_make(void)
 {
        PyObject *units_systems;
        const char **sys;
@@ -128,7 +128,7 @@ static PyObject *utils_units_systems_make(void)
        return units_systems;
 }
 
-static PyObject *utils_units_categories_make(void)
+static PyObject *bpyunits_categories_make(void)
 {
        PyObject *units_categories;
        const char **categories;
@@ -148,47 +148,53 @@ static PyObject *utils_units_categories_make(void)
 
 /***** Main BlenderAppTranslations Py object definition *****/
 
-PyDoc_STRVAR(utils_units_systems_doc, "A named tuple containing all 
pre-defined unit systems.\n");
-PyDoc_STRVAR(utils_units_categories_doc, "A named tuple containing all 
pre-defined unit categories.\n");
+PyDoc_STRVAR(bpyunits_systems_doc, "A named tuple containing all pre-defined 
unit systems.\n");
+PyDoc_STRVAR(bpyunits_categories_doc, "A named tuple containing all 
pre-defined unit categories.\n");
 
-static PyMemberDef utils_units_members[] = {
-       {(char *)"systems", T_OBJECT_EX, offsetof(BlenderUtilsUnits, systems), 
READONLY, utils_units_systems_doc},
-       {(char *)"categories", T_OBJECT_EX, offsetof(BlenderUtilsUnits, 
categories), READONLY, utils_units_categories_doc},
+static PyMemberDef bpyunits_members[] = {
+       {(char *)"systems", T_OBJECT_EX, offsetof(BlenderUtilsUnits, systems), 
READONLY, bpyunits_systems_doc},
+       {(char *)"categories", T_OBJECT_EX, offsetof(BlenderUtilsUnits, 
categories), READONLY, bpyunits_categories_doc},
        {NULL},
 };
 
-static PyGetSetDef utils_units_getseters[] = {{NULL}};
+static PyGetSetDef bpyunits_getseters[] = {{NULL}};
 
-static bool utils_units_validate(const char *usys_str, const char *ucat_str, 
int *r_usys, int *r_ucat)
+static bool bpyunits_validate(const char *usys_str, const char *ucat_str, int 
*r_usys, int *r_ucat)
 {
-       *r_usys = BLI_str_index_in_array(usys_str, bpyunits_usystems, -1);
+       *r_usys = BLI_str_index_in_array(usys_str, bpyunits_usystems);
        if (*r_usys < 0) {
-               PyErr_Format(PyExc_ValueError, "Unknown unit system specified: 
%s.", usys_str);
+               PyErr_Format(PyExc_ValueError,
+                            "Unknown unit system specified: %.200s.",
+                            usys_str);
                return false;
        }
 
-       *r_ucat = BLI_str_index_in_array(ucat_str, bpyunits_ucategories, -1);
+       *r_ucat = BLI_str_index_in_array(ucat_str, bpyunits_ucategories);
        if (*r_ucat < 0) {
-               PyErr_Format(PyExc_ValueError, "Unknown unit category 
specified: %s.", ucat_str);
+               PyErr_Format(PyExc_ValueError,
+                            "Unknown unit category specified: %.200s.",
+                            ucat_str);
                return false;
        }
 
        if (!bUnit_IsValid(*r_usys, *r_ucat)) {
-               PyErr_Format(PyExc_ValueError, "%s / %s unit system/category 
combination is not valid.", usys_str, ucat_str);
+               PyErr_Format(PyExc_ValueError,
+                            "%.200s / %.200s unit system/category combination 
is not valid.",
+                            usys_str, ucat_str);
                return false;
        }
 
        return true;
 }
 
-PyDoc_STRVAR(utils_units_to_value_doc,
+PyDoc_STRVAR(bpyunits_to_value_doc,
 ".. method:: to_value(unit_system, unit_category, str_input, 
[str_ref_unit=None])\n"
 "\n"
 "   Convert a given input string into a float value.\n"
 "\n"
 "   :arg str unit_system: The unit system, from 
:attribute:`bpy.utils.units.systems`.\n"
 "   :arg str unit_category: The category of data we are converting (length, 
area, rotation, etc.), "
-"from :attribute:`bpy.utils.units.categories`.\n"
+"      from :attribute:`bpy.utils.units.categories`.\n"
 "   :arg str str_input: The string to convert to a float value.\n"
 "   :arg str_ref_unit: A reference string from which to extract a default 
unit, if none is found in :arg:`str_input`.\n"
 "   :type: string or None\n"
@@ -197,7 +203,7 @@ PyDoc_STRVAR(utils_units_to_value_doc,
 "   :raises ValueError: if conversion fails to generate a valid python float 
value.\n"
 "\n"
 );
-static PyObject *utils_units_to_value(BlenderUtilsUnits *UNUSED(self), 
PyObject *args, PyObject *kw)
+static PyObject *bpyunits_to_value(BlenderUt

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to