[Bf-blender-cvs] [ee18a70] missing-libs: Move memory-zero-checking to BLI_memory_utils

Campbell Barton noreply at git.blender.org
Tue Oct 20 11:01:11 CEST 2015


Commit: ee18a70864bfcad0dd511999acddde0050f31185
Author: Campbell Barton
Date:   Tue Oct 20 19:49:58 2015 +1100
Branches: missing-libs
https://developer.blender.org/rBee18a70864bfcad0dd511999acddde0050f31185

Move memory-zero-checking to BLI_memory_utils

Add a new BLI module since this isn't typical use for BLI_array
(where element size is taken into account).

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

M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/camera.c
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/lamp.c
M	source/blender/blenkernel/intern/lattice.c
M	source/blender/blenkernel/intern/linestyle.c
M	source/blender/blenkernel/intern/material.c
M	source/blender/blenkernel/intern/mball.c
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenkernel/intern/speaker.c
M	source/blender/blenkernel/intern/text.c
M	source/blender/blenkernel/intern/texture.c
M	source/blender/blenkernel/intern/world.c
M	source/blender/blenlib/BLI_array_utils.h
M	source/blender/blenlib/BLI_utildefines.h
M	source/blender/blenlib/CMakeLists.txt
M	source/blender/blenlib/intern/array_utils.c

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

diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index d4c65af..c2a66ad 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -133,7 +133,7 @@ static void brush_defaults(Brush *brush)
 
 void BKE_brush_init(Brush *brush)
 {
-	BLI_assert(MEMCMP_NULL_STRUCT_OFS(brush, id));
+	BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(brush, id));
 
 	/* enable fake user by default */
 	brush->id.flag |= LIB_FAKEUSER;
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index e1bddec..46b74c5 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -59,7 +59,7 @@
 
 void BKE_camera_init(Camera *cam)
 {
-	BLI_assert(MEMCMP_NULL_STRUCT_OFS(cam, id));
+	BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(cam, id));
 
 	cam->lens = 35.0f;
 	cam->sensor_x = DEFAULT_SENSOR_WIDTH;
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index f078a93..3e0bdbe 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -163,7 +163,7 @@ void BKE_curve_free(Curve *cu)
 
 void BKE_curve_init(Curve *cu)
 {
-	/* BLI_assert(MEMCMP_NULL_STRUCT_OFS(cu, id)); */  /* cu->type is already initialized... */
+	/* BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(cu, id)); */  /* cu->type is already initialized... */
 
 	copy_v3_fl(cu->size, 1.0f);
 	cu->flag = CU_FRONT | CU_BACK | CU_DEFORM_BOUNDS_OFF | CU_PATH_RADIUS;
diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c
index 60b88b9..46b0ad8 100644
--- a/source/blender/blenkernel/intern/lamp.c
+++ b/source/blender/blenkernel/intern/lamp.c
@@ -55,7 +55,7 @@
 
 void BKE_lamp_init(Lamp *la)
 {
-	BLI_assert(MEMCMP_NULL_STRUCT_OFS(la, id));
+	BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(la, id));
 
 	la->r = la->g = la->b = la->k = 1.0f;
 	la->haint = la->energy = 1.0f;
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index e0fb27d..0240a46 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -253,7 +253,7 @@ void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb)
 
 void BKE_lattice_init(Lattice *lt)
 {
-	BLI_assert(MEMCMP_NULL_STRUCT_OFS(lt, id));
+	BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(lt, id));
 
 	lt->flag = LT_GRID;
 
diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c
index d8eb8f2..93d2b54 100644
--- a/source/blender/blenkernel/intern/linestyle.c
+++ b/source/blender/blenkernel/intern/linestyle.c
@@ -82,7 +82,7 @@ static const char *modifier_name[LS_MODIFIER_NUM] = {
 
 void BKE_linestyle_init(FreestyleLineStyle *linestyle)
 {
-	BLI_assert(MEMCMP_NULL_STRUCT_OFS(linestyle, id));
+	BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(linestyle, id));
 
 	linestyle->panel = LS_PANEL_STROKES;
 	linestyle->r = linestyle->g = linestyle->b = 0.0f;
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index a43906c..051324e 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -124,7 +124,7 @@ void BKE_material_free_ex(Material *ma, bool do_id_user)
 
 void BKE_init_material(Material *ma)
 {
-	BLI_assert(MEMCMP_NULL_STRUCT_OFS(ma, id));
+	BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ma, id));
 
 	ma->r = ma->g = ma->b = ma->ref = 0.8;
 	ma->specr = ma->specg = ma->specb = 1.0;
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c
index bab2a5d..d3f7fd7 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -93,7 +93,7 @@ void BKE_mball_free(MetaBall *mb)
 
 void BKE_mball_init(MetaBall *mb)
 {
-	BLI_assert(MEMCMP_NULL_STRUCT_OFS(mb, id));
+	BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(mb, id));
 
 	mb->size[0] = mb->size[1] = mb->size[2] = 1.0;
 	mb->texflag = MB_AUTOSPACE;
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index b3cca03..318040d 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -492,7 +492,7 @@ static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata)
 
 void BKE_mesh_init(Mesh *me)
 {
-	BLI_assert(MEMCMP_NULL_STRUCT_OFS(me, id));
+	BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(me, id));
 
 	me->size[0] = me->size[1] = me->size[2] = 1.0;
 	me->smoothresh = 30;
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index c493915..799696c 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -974,7 +974,7 @@ void *BKE_object_obdata_add_from_type(Main *bmain, int type, const char *name)
 
 void BKE_object_init(Object *ob)
 {
-	/* BLI_assert(MEMCMP_NULL_STRUCT_OFS(ob, id)); */  /* ob->type is already initialized... */
+	/* BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ob, id)); */  /* ob->type is already initialized... */
 
 	ob->col[0] = ob->col[1] = ob->col[2] = 1.0;
 	ob->col[3] = 1.0;
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index d4a8d29..cc65677 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -471,7 +471,7 @@ void BKE_scene_init(Scene *sce)
 	const char *colorspace_name;
 	SceneRenderView *srv;
 
-	BLI_assert(MEMCMP_NULL_STRUCT_OFS(sce, id));
+	BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(sce, id));
 
 	sce->lay = sce->layact = 1;
 	
diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c
index 4117ca3..30296c7 100644
--- a/source/blender/blenkernel/intern/speaker.c
+++ b/source/blender/blenkernel/intern/speaker.c
@@ -39,7 +39,7 @@
 
 void BKE_speaker_init(Speaker *spk)
 {
-	BLI_assert(MEMCMP_NULL_STRUCT_OFS(spk, id));
+	BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(spk, id));
 
 	spk->attenuation = 1.0f;
 	spk->cone_angle_inner = 360.0f;
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index fba68c5..80d15ce 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -175,7 +175,7 @@ void BKE_text_init(Text *ta)
 {
 	TextLine *tmp;
 
-	BLI_assert(MEMCMP_NULL_STRUCT_OFS(ta, id));
+	BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ta, id));
 
 	ta->name = NULL;
 
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index ab8bceb..463ca25 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -580,7 +580,7 @@ void BKE_texture_free(Tex *tex)
 
 void BKE_texture_default(Tex *tex)
 {
-	/* BLI_assert(MEMCMP_NULL_STRUCT_OFS(tex, id)); */  /* Not here, can be called with some pointers set. :/ */
+	/* BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(tex, id)); */  /* Not here, can be called with some pointers set. :/ */
 
 	tex->type = TEX_IMAGE;
 	tex->ima = NULL;
diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c
index 68e15d5..e076094 100644
--- a/source/blender/blenkernel/intern/world.c
+++ b/source/blender/blenkernel/intern/world.c
@@ -31,7 +31,9 @@
 
 
 #include <string.h>
+#include <stdlib.h>
 #include <math.h>
+
 #include "MEM_guardedalloc.h"
 
 #include "DNA_world_types.h"
@@ -85,7 +87,7 @@ void BKE_world_free(World *wrld)
 
 void BKE_world_init(World *wrld)
 {
-	BLI_assert(MEMCMP_NULL_STRUCT_OFS(wrld, id));
+	BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(wrld, id));
 
 	wrld->horr = 0.05f;
 	wrld->horg = 0.05f;
diff --git a/source/blender/blenlib/BLI_array_utils.h b/source/blender/blenlib/BLI_array_utils.h
index 36d9b2f..6e7ee3b 100644
--- a/source/blender/blenlib/BLI_array_utils.h
+++ b/source/blender/blenlib/BLI_array_utils.h
@@ -46,6 +46,6 @@ int _bli_array_findindex(const void *arr, unsigned int arr_len, size_t arr_strid
 #define BLI_array_findindex(arr, arr_len, p) \
 	_bli_array_findindex(arr, arr_len, sizeof(*(arr)), p)
 
-int BLI_memcmp_null(char *p, const size_t size);
+bool BLI_array_is_zero(const void *arr, const size_t size);
 
 #endif  /* __BLI_ARRAY_UTILS_H__ */
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index e9c8217..fb94a22 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -513,6 +513,17 @@ extern "C" {
 	       sizeof(*(struct_var)) - OFFSETOF_STRUCT(struct_var, member)); \
 } (void)0
 
+/* defined
+ * in array_utils.c for now. I do not know where we should put it actually... */
+#ifndef __BLI_MEMORY_UTILS_H__
+extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size);
+#endif
+
+#define MEMCMP_STRUCT_OFS_IS_ZERO(struct_var, member) \
+	(BLI_memory_is_zero( \
+	       (char *)(struct_var)  + OFFSETOF_STRUCT(struct_var, member), \
+	       sizeof(*(struct_var)) - OFFSETOF_STRUCT(struct_var, member)))
+
 /* Warning-free macros for storing ints in pointers. Use these _only_
  * for storing an int in a pointer, not a pointer in an int (64bit)! */
 #define SET_INT_IN_POINTER(i)    ((void *)(intptr_t)(i))
@@ -684,15 +695,6 @@ extern void BLI_system_backtrace(FILE *fp);
 #  define UNLIKELY(x)     (x)
 #endif
 
-/* XXX Defined in array_utils.c for now. I do not know where we should put it actually... */
-extern int BLI_memcmp_null(char *p, const size_t size);
-
-#define MEMCMP_NULL_STRUCT_OFS(struct_var, member) \
-	(BLI_memcmp_null( \
-	       (char *)(struct_var)  + OFFSETOF_STRUCT(struct_var, member), \
-	       sizeof(*(struct_var)) - OFFSETOF_STRUCT(struct_var, member)) == 0)
-
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index dcf7c3b..0de614a 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -88,6 +88,7 @@ set(SRC
 	intern/math_statistics.c
 	intern/math_vector.c
 	intern/math_vector_inline.c
+	intern/memory_utils.c
 	intern/noise.c
 	intern/path_util.c
 	intern/polyfill2d.c
@@ -169,6 +170,7 @@ set(SRC
 	BLI_math_statistic

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list