Use ARRAY_SIZE to replace (sizeof(a) / sizeof(*a))
authorCampbell Barton <ideasman42@gmail.com>
Mon, 16 Jun 2014 16:47:57 +0000 (02:47 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 16 Jun 2014 16:47:57 +0000 (02:47 +1000)
13 files changed:
source/blender/bmesh/intern/bmesh_opdefines.c
source/blender/bmesh/intern/bmesh_walkers_impl.c
source/blender/bmesh/operators/bmo_subdivide.c
source/blender/python/generic/py_capi_utils.c
source/blender/python/intern/bpy_app.c
source/blender/python/intern/bpy_app_build_options.c
source/blender/python/intern/bpy_app_ffmpeg.c
source/blender/python/intern/bpy_app_handlers.c
source/blender/python/intern/bpy_app_ocio.c
source/blender/python/intern/bpy_app_oiio.c
source/blender/python/intern/bpy_app_translations.c
source/blender/python/intern/bpy_interface.c
source/blender/python/intern/bpy_intern_string.c

index f8cca0a3707a0ec75ddc9e84ee417f3d044650fd..7c77302c9429c8e7835f0799bc4982adc1200f24 100644 (file)
@@ -1904,4 +1904,4 @@ const BMOpDefine *bmo_opdefines[] = {
        &bmo_wireframe_def,
 };
 
-const int bmo_opdefines_total = (sizeof(bmo_opdefines) / sizeof(void *));
+const int bmo_opdefines_total = ARRAY_SIZE(bmo_opdefines);
index c76c203c2fba9e6055ecf0198d004084bdd9af3c..406dd412d6daacabf7d8fb86eaa72501f8b2b579 100644 (file)
@@ -1352,4 +1352,4 @@ BMWalker *bm_walker_types[] = {
        &bmw_ConnectedVertexWalker_Type,    /* BMW_CONNECTED_VERTEX */
 };
 
-const int bm_totwalkers = sizeof(bm_walker_types) / sizeof(*bm_walker_types);
+const int bm_totwalkers = ARRAY_SIZE(bm_walker_types);
index 4bc07c82c5caa42b9148a1797a50d6b88c780605..fc507cdbd210f9a7fadc4c794de1645d14ac3c8b 100644 (file)
@@ -752,7 +752,7 @@ static const SubDPattern *patterns[] = {
        NULL,
 };
 
-#define PATTERNS_TOT  (sizeof(patterns) / sizeof(void *))
+#define PATTERNS_TOT  ARRAY_SIZE(patterns)
 
 typedef struct SubDFaceData {
        BMVert *start;
index c0004789faa9dd6a8ad2fde0f10d86351fb26ea2..54e27a30791d275e8554467bb324eec892e0b922 100644 (file)
@@ -606,8 +606,7 @@ void PyC_SetHomePath(const char *py_path_bundle)
                /* cant use this, on linux gives bug: #23018, TODO: try LANG="en_US.UTF-8" /usr/bin/blender, suggested 22008 */
                /* mbstowcs(py_path_bundle_wchar, py_path_bundle, FILE_MAXDIR); */
 
-               BLI_strncpy_wchar_from_utf8(py_path_bundle_wchar, py_path_bundle,
-                                           sizeof(py_path_bundle_wchar) / sizeof(wchar_t));
+               BLI_strncpy_wchar_from_utf8(py_path_bundle_wchar, py_path_bundle, ARRAY_SIZE(py_path_bundle_wchar));
 
                Py_SetPythonHome(py_path_bundle_wchar);
                // printf("found python (wchar_t) '%ls'\n", py_path_bundle_wchar);
index 795015c42a00d64cce308c38effa659ae44bb636..6c4f8f0769f79541be423223147a926f2bc493e2 100644 (file)
@@ -107,7 +107,7 @@ static PyStructSequence_Desc app_info_desc = {
        (char *)"bpy.app",     /* name */
        (char *)"This module contains application values that remain unchanged during runtime.",    /* doc */
        app_info_fields,    /* fields */
-       (sizeof(app_info_fields) / sizeof(PyStructSequence_Field)) - 1
+       ARRAY_SIZE(app_info_fields) - 1
 };
 
 static PyObject *make_app_info(void)
index f43b67cf42f117827de1f6b2234ed5948655cc9b..022713558d708443128e62ab7e28ca73863dcef7 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <Python.h>
 
+#include "BLI_utildefines.h"
+
 #include "bpy_app_build_options.h"
 
 static PyTypeObject BlenderAppBuildOptionsType;
@@ -74,7 +76,7 @@ static PyStructSequence_Desc app_builtopts_info_desc = {
        (char *)"bpy.app.build_options",     /* name */
        (char *)"This module contains information about options blender is built with",    /* doc */
        app_builtopts_info_fields,    /* fields */
-       (sizeof(app_builtopts_info_fields) / sizeof(PyStructSequence_Field)) - 1
+       ARRAY_SIZE(app_builtopts_info_fields) - 1
 };
 
 static PyObject *make_builtopts_info(void)
index 2f7577928c5af4329afff29f10a05a370746b407..fd516e4547ff1f4d4bd65379bcb93ad4c29d3a3f 100644 (file)
@@ -60,7 +60,7 @@ static PyStructSequence_Desc app_ffmpeg_info_desc = {
        (char *)"bpy.app.ffmpeg",     /* name */
        (char *)"This module contains information about FFmpeg blender is linked against",    /* doc */
        app_ffmpeg_info_fields,    /* fields */
-       (sizeof(app_ffmpeg_info_fields) / sizeof(PyStructSequence_Field)) - 1
+       ARRAY_SIZE(app_ffmpeg_info_fields) - 1
 };
 
 static PyObject *make_ffmpeg_info(void)
index b3be5a819fb28cb546a7d02f4bce64194af2e6c7..0c13230c36598a5df8eb08ab5eca5c86c0dc7828 100644 (file)
@@ -71,11 +71,11 @@ static PyStructSequence_Desc app_cb_info_desc = {
        (char *)"bpy.app.handlers",     /* name */
        (char *)"This module contains callbacks",    /* doc */
        app_cb_info_fields,    /* fields */
-       (sizeof(app_cb_info_fields) / sizeof(PyStructSequence_Field)) - 1
+       ARRAY_SIZE(app_cb_info_fields) - 1
 };
 
 #if 0
-#  if (BLI_CB_EVT_TOT != ((sizeof(app_cb_info_fields) / sizeof(PyStructSequence_Field))))
+#  if (BLI_CB_EVT_TOT != ARRAY_SIZE(app_cb_info_fields))
 #    error "Callbacks are out of sync"
 #  endif
 #endif
index eff52bc9dae40f47227ced1b087ada3024dd2ea3..02e4044219a2358a3b82e0cd56a5969ed1714f87 100644 (file)
@@ -46,7 +46,7 @@ static PyStructSequence_Desc app_ocio_info_desc = {
        (char *)"bpy.app.ocio",     /* name */
        (char *)"This module contains information about OpenColorIO blender is linked against",    /* doc */
        app_ocio_info_fields,    /* fields */
-       (sizeof(app_ocio_info_fields) / sizeof(PyStructSequence_Field)) - 1
+       ARRAY_SIZE(app_ocio_info_fields) - 1
 };
 
 static PyObject *make_ocio_info(void)
index b5f0f321c6df3821729ed97eb5fd5c3b5497cbf7..60daf3ddd8b30150fb449005c05f92f8055ddb36 100644 (file)
@@ -46,7 +46,7 @@ static PyStructSequence_Desc app_oiio_info_desc = {
        (char *)"bpy.app.oiio",     /* name */
        (char *)"This module contains information about OpeImageIO blender is linked against",    /* doc */
        app_oiio_info_fields,    /* fields */
-       (sizeof(app_oiio_info_fields) / sizeof(PyStructSequence_Field)) - 1
+       ARRAY_SIZE(app_oiio_info_fields) - 1
 };
 
 static PyObject *make_oiio_info(void)
index e168bf33eb58eb10871de65ac339a1af695ccc50..109e560603720b0ffa5dfaca4d1ab41a02c11de7 100644 (file)
@@ -390,13 +390,13 @@ static BLF_i18n_contexts_descriptor _contexts[] = BLF_I18NCONTEXTS_DESC;
  * This allows us to avoid many handwriting, and above all, to keep all context definition stuff in BLF_translation.h!
  */
 static PyStructSequence_Field
-app_translations_contexts_fields[sizeof(_contexts) / sizeof(BLF_i18n_contexts_descriptor)] = {{NULL}};
+app_translations_contexts_fields[ARRAY_SIZE(_contexts)] = {{NULL}};
 
 static PyStructSequence_Desc app_translations_contexts_desc = {
        (char *)"bpy.app.translations.contexts",     /* name */
        (char *)"This named tuple contains all pre-defined translation contexts",    /* doc */
        app_translations_contexts_fields,    /* fields */
-       (sizeof(app_translations_contexts_fields) / sizeof(PyStructSequence_Field)) - 1
+       ARRAY_SIZE(app_translations_contexts_fields) - 1
 };
 
 static PyObject *app_translations_contexts_make(void)
index 045acc65d1eb4130af279bf59ab5969b1d1aea46..bf2de02625f4e4f5005df721965e57b639da4a7c 100644 (file)
@@ -243,7 +243,7 @@ void BPY_python_start(int argc, const char **argv)
 
        /* not essential but nice to set our name */
        static wchar_t program_path_wchar[FILE_MAX]; /* python holds a reference */
-       BLI_strncpy_wchar_from_utf8(program_path_wchar, BLI_program_path(), sizeof(program_path_wchar) / sizeof(wchar_t));
+       BLI_strncpy_wchar_from_utf8(program_path_wchar, BLI_program_path(), ARRAY_SIZE(program_path_wchar));
        Py_SetProgramName(program_path_wchar);
 
        /* must run before python initializes */
index 9c93af1786cab4aa6c328a2f50bfc2b672892efd..fd32c91a480848598c1ca5fbff7ad1a2f727637d 100644 (file)
@@ -69,12 +69,12 @@ void bpy_intern_string_init(void)
 
 #undef BPY_INTERN_STR
 
-       BLI_assert(i == (sizeof(bpy_intern_str_arr) / sizeof(*bpy_intern_str_arr)));
+       BLI_assert(i == ARRAY_SIZE(bpy_intern_str_arr));
 }
 
 void bpy_intern_string_exit(void)
 {
-       unsigned int i = sizeof(bpy_intern_str_arr) / sizeof(*bpy_intern_str_arr);
+       unsigned int i = ARRAY_SIZE(bpy_intern_str_arr);
        while (i--) {
                Py_DECREF(bpy_intern_str_arr[i]);
        }