[Bf-blender-cvs] [fa17e3b] master: UI: refactor text cache to use zero length arrays

Campbell Barton noreply at git.blender.org
Sat Jun 14 20:33:53 CEST 2014


Commit: fa17e3b14c102e11887292536f62967388cbcba1
Author: Campbell Barton
Date:   Sun Jun 15 04:06:44 2014 +1000
https://developer.blender.org/rBfa17e3b14c102e11887292536f62967388cbcba1

UI: refactor text cache to use zero length arrays

also correct some bad casts

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

M	source/blender/editors/interface/view2d.c
M	source/blender/editors/space_view3d/drawobject.c

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

diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index 982e8f1..45dd470 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -2277,6 +2277,9 @@ typedef struct View2DString {
 	} col;
 	rcti rect;
 	int mval[2];
+
+	/* str is allocated past the end */
+	char str[0];
 } View2DString;
 
 /* assumes caches are used correctly, so for time being no local storage in v2d */
@@ -2309,7 +2312,7 @@ void UI_view2d_text_cache_add(View2D *v2d, float x, float y,
 		v2s->mval[0] = mval[0];
 		v2s->mval[1] = mval[1];
 
-		memcpy(v2s + 1, str, alloc_len);
+		memcpy(v2s->str, str, alloc_len);
 	}
 }
 
@@ -2340,7 +2343,7 @@ void UI_view2d_text_cache_add_rectf(View2D *v2d, const rctf *rect_view,
 		v2s->mval[0] = v2s->rect.xmin;
 		v2s->mval[1] = v2s->rect.ymin;
 
-		memcpy(v2s + 1, str, alloc_len);
+		memcpy(v2s->str, str, alloc_len);
 	}
 }
 
@@ -2360,7 +2363,6 @@ void UI_view2d_text_cache_draw(ARegion *ar)
 	ED_region_pixelspace(ar);
 
 	for (v2s = g_v2d_strings; v2s; v2s = v2s->next) {
-		const char *str = (const char *)(v2s + 1);
 		int xofs = 0, yofs;
 
 		yofs = ceil(0.5f * (BLI_rcti_size_y(&v2s->rect) - default_height));
@@ -2372,11 +2374,13 @@ void UI_view2d_text_cache_draw(ARegion *ar)
 		}
 
 		if (v2s->rect.xmin >= v2s->rect.xmax)
-			BLF_draw_default((float)v2s->mval[0] + xofs, (float)v2s->mval[1] + yofs, 0.0, str, BLF_DRAW_STR_DUMMY_MAX);
+			BLF_draw_default((float)(v2s->mval[0] + xofs), (float)(v2s->mval[1] + yofs), 0.0,
+			                  v2s->str, BLF_DRAW_STR_DUMMY_MAX);
 		else {
 			BLF_clipping_default(v2s->rect.xmin - 4, v2s->rect.ymin - 4, v2s->rect.xmax + 4, v2s->rect.ymax + 4);
 			BLF_enable_default(BLF_CLIPPING);
-			BLF_draw_default(v2s->rect.xmin + xofs, v2s->rect.ymin + yofs, 0.0f, str, BLF_DRAW_STR_DUMMY_MAX);
+			BLF_draw_default(v2s->rect.xmin + xofs, v2s->rect.ymin + yofs, 0.0f,
+			                 v2s->str, BLF_DRAW_STR_DUMMY_MAX);
 			BLF_disable_default(BLF_CLIPPING);
 		}
 	}
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 0510ecd..3393cf7 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -763,8 +763,10 @@ typedef struct ViewCachedString {
 	short sco[2];
 	short xoffs;
 	short flag;
-	int str_len, pad;
+	int str_len;
+
 	/* str is allocated past the end */
+	char str[0];
 } ViewCachedString;
 
 /* one arena for all 3 string lists */
@@ -809,7 +811,7 @@ void view3d_cached_text_draw_add(const float co[3],
 	vos->str_len = str_len;
 
 	/* allocate past the end */
-	memcpy(vos + 1, str, alloc_len);
+	memcpy(vos->str, str, alloc_len);
 }
 
 void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, bool depth_write, float mat[4][4])
@@ -868,8 +870,6 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, bool depth_write, flo
 		
 		for (vos = g_v3d_strings[g_v3d_string_level]; vos; vos = vos->next) {
 			if (vos->sco[0] != IS_CLIPPED) {
-				const char *str = (char *)(vos + 1);
-
 				if (col_pack_prev != vos->col.pack) {
 					glColor3ubv(vos->col.ub);
 					col_pack_prev = vos->col.pack;
@@ -878,10 +878,10 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, bool depth_write, flo
 				((vos->flag & V3D_CACHE_TEXT_ASCII) ?
 				 BLF_draw_default_ascii :
 				 BLF_draw_default
-				)( (float)vos->sco[0] + vos->xoffs,
-				   (float)vos->sco[1],
+				 )((float)(vos->sco[0] + vos->xoffs),
+				   (float)(vos->sco[1]),
 				   (depth_write) ? 0.0f : 2.0f,
-				   str,
+				   vos->str,
 				   vos->str_len);
 			}
 		}




More information about the Bf-blender-cvs mailing list