[Bf-blender-cvs] [f2a0062] master: Use ARRAY_SIZE to replace (sizeof(a) / sizeof(*a))

Campbell Barton noreply at git.blender.org
Mon Jun 16 18:49:44 CEST 2014


Commit: f2a0062042edfafab2c0d9472f2669521ff70930
Author: Campbell Barton
Date:   Tue Jun 17 02:47:57 2014 +1000
https://developer.blender.org/rBf2a0062042edfafab2c0d9472f2669521ff70930

Use ARRAY_SIZE to replace (sizeof(a) / sizeof(*a))

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

M	source/blender/bmesh/intern/bmesh_opdefines.c
M	source/blender/bmesh/intern/bmesh_walkers_impl.c
M	source/blender/bmesh/operators/bmo_subdivide.c
M	source/blender/python/generic/py_capi_utils.c
M	source/blender/python/intern/bpy_app.c
M	source/blender/python/intern/bpy_app_build_options.c
M	source/blender/python/intern/bpy_app_ffmpeg.c
M	source/blender/python/intern/bpy_app_handlers.c
M	source/blender/python/intern/bpy_app_ocio.c
M	source/blender/python/intern/bpy_app_oiio.c
M	source/blender/python/intern/bpy_app_translations.c
M	source/blender/python/intern/bpy_interface.c
M	source/blender/python/intern/bpy_intern_string.c

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

diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c
index f8cca0a..7c77302 100644
--- a/source/blender/bmesh/intern/bmesh_opdefines.c
+++ b/source/blender/bmesh/intern/bmesh_opdefines.c
@@ -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);
diff --git a/source/blender/bmesh/intern/bmesh_walkers_impl.c b/source/blender/bmesh/intern/bmesh_walkers_impl.c
index c76c203..406dd41 100644
--- a/source/blender/bmesh/intern/bmesh_walkers_impl.c
+++ b/source/blender/bmesh/intern/bmesh_walkers_impl.c
@@ -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);
diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c
index 4bc07c8..fc507cd 100644
--- a/source/blender/bmesh/operators/bmo_subdivide.c
+++ b/source/blender/bmesh/operators/bmo_subdivide.c
@@ -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;
diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c
index c000478..54e27a3 100644
--- a/source/blender/python/generic/py_capi_utils.c
+++ b/source/blender/python/generic/py_capi_utils.c
@@ -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);
diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c
index 795015c..6c4f8f0 100644
--- a/source/blender/python/intern/bpy_app.c
+++ b/source/blender/python/intern/bpy_app.c
@@ -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)
diff --git a/source/blender/python/intern/bpy_app_build_options.c b/source/blender/python/intern/bpy_app_build_options.c
index f43b67c..0227135 100644
--- a/source/blender/python/intern/bpy_app_build_options.c
+++ b/source/blender/python/intern/bpy_app_build_options.c
@@ -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)
diff --git a/source/blender/python/intern/bpy_app_ffmpeg.c b/source/blender/python/intern/bpy_app_ffmpeg.c
index 2f75779..fd516e4 100644
--- a/source/blender/python/intern/bpy_app_ffmpeg.c
+++ b/source/blender/python/intern/bpy_app_ffmpeg.c
@@ -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)
diff --git a/source/blender/python/intern/bpy_app_handlers.c b/source/blender/python/intern/bpy_app_handlers.c
index b3be5a8..0c13230 100644
--- a/source/blender/python/intern/bpy_app_handlers.c
+++ b/source/blender/python/intern/bpy_app_handlers.c
@@ -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
diff --git a/source/blender/python/intern/bpy_app_ocio.c b/source/blender/python/intern/bpy_app_ocio.c
index eff52bc..02e4044 100644
--- a/source/blender/python/intern/bpy_app_ocio.c
+++ b/source/blender/python/intern/bpy_app_ocio.c
@@ -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)
diff --git a/source/blender/python/intern/bpy_app_oiio.c b/source/blender/python/intern/bpy_app_oiio.c
index b5f0f32..60daf3d 100644
--- a/source/blender/python/intern/bpy_app_oiio.c
+++ b/source/blender/python/intern/bpy_app_oiio.c
@@ -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)
diff --git a/source/blender/python/intern/bpy_app_translations.c b/source/blender/python/intern/bpy_app_translations.c
index e168bf3..109e560 100644
--- a/source/blender/python/intern/bpy_app_translations.c
+++ b/source/blender/python/intern/bpy_app_translations.c
@@ -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)
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 045acc6..bf2de02 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -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 */
diff --git a/source/blender/python/intern/bpy_intern_string.c b/source/blender/python/intern/bpy_intern_string.c
index 9c93af1..fd32c91 100644
--- a/source/blender/python/intern/bpy_intern_string.c
+++ b/source/blender/python/intern/bpy_intern_string.c
@@ -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]);
 	}




More information about the Bf-blender-cvs mailing list