[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54712] trunk/blender: style cleanup: ' sizeof foo' --> 'sizeof(foo)', add check in style checking script.

Campbell Barton ideasman42 at gmail.com
Thu Feb 21 18:18:27 CET 2013


Revision: 54712
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54712
Author:   campbellbarton
Date:     2013-02-21 17:18:27 +0000 (Thu, 21 Feb 2013)
Log Message:
-----------
style cleanup: 'sizeof foo' --> 'sizeof(foo)', add check in style checking script.

Modified Paths:
--------------
    trunk/blender/intern/ghost/intern/GHOST_DisplayManagerSDL.cpp
    trunk/blender/source/blender/blenlib/intern/BLI_heap.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
    trunk/blender/source/blender/editors/uvedit/uvedit_parametrizer.c
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/tools/check_style_c.py

Modified: trunk/blender/intern/ghost/intern/GHOST_DisplayManagerSDL.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_DisplayManagerSDL.cpp	2013-02-21 17:16:51 UTC (rev 54711)
+++ trunk/blender/intern/ghost/intern/GHOST_DisplayManagerSDL.cpp	2013-02-21 17:18:27 UTC (rev 54712)
@@ -39,7 +39,7 @@
       GHOST_DisplayManager(),
       m_system(system)
 {
-	memset(&m_mode, 0, sizeof m_mode);
+	memset(&m_mode, 0, sizeof(m_mode));
 }
 
 GHOST_TSuccess

Modified: trunk/blender/source/blender/blenlib/intern/BLI_heap.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_heap.c	2013-02-21 17:16:51 UTC (rev 54711)
+++ trunk/blender/source/blender/blenlib/intern/BLI_heap.c	2013-02-21 17:18:27 UTC (rev 54712)
@@ -167,7 +167,7 @@
 		heap->freenodes = (HeapNode *)(((HeapNode *)heap->freenodes)->ptr);
 	}
 	else {
-		node = (HeapNode *)BLI_memarena_alloc(heap->arena, sizeof *node);
+		node = (HeapNode *)BLI_memarena_alloc(heap->arena, sizeof(*node));
 	}
 
 	node->value = value;

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2013-02-21 17:16:51 UTC (rev 54711)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2013-02-21 17:18:27 UTC (rev 54712)
@@ -5035,7 +5035,7 @@
 		ps->is_texbrush = false;
 	}
 
-	/* sizeof ProjPixel, since we alloc this a _lot_ */
+	/* sizeof(ProjPixel), since we alloc this a _lot_ */
 	ps->pixel_sizeof = project_paint_pixel_sizeof(ps->tool);
 	BLI_assert(ps->pixel_sizeof >= sizeof(ProjPixel));
 

Modified: trunk/blender/source/blender/editors/uvedit/uvedit_parametrizer.c
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_parametrizer.c	2013-02-21 17:16:51 UTC (rev 54711)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_parametrizer.c	2013-02-21 17:18:27 UTC (rev 54712)
@@ -709,7 +709,7 @@
 
 static PVert *p_vert_add(PHandle *handle, PHashKey key, const float co[3], PEdge *e)
 {
-	PVert *v = (PVert *)BLI_memarena_alloc(handle->arena, sizeof *v);
+	PVert *v = (PVert *)BLI_memarena_alloc(handle->arena, sizeof(*v));
 	copy_v3_v3(v->co, co);
 	v->u.key = key;
 	v->edge = e;
@@ -732,7 +732,7 @@
 
 static PVert *p_vert_copy(PChart *chart, PVert *v)
 {
-	PVert *nv = (PVert *)BLI_memarena_alloc(chart->handle->arena, sizeof *nv);
+	PVert *nv = (PVert *)BLI_memarena_alloc(chart->handle->arena, sizeof(*nv));
 
 	copy_v3_v3(nv->co, v->co);
 	nv->uv[0] = v->uv[0];
@@ -786,7 +786,7 @@
 
 static PChart *p_chart_new(PHandle *handle)
 {
-	PChart *chart = (PChart *)MEM_callocN(sizeof *chart, "PChart");
+	PChart *chart = (PChart *)MEM_callocN(sizeof(*chart), "PChart");
 	chart->handle = handle;
 
 	return chart;
@@ -904,7 +904,7 @@
 
 static int p_connect_pairs(PHandle *handle, PBool impl)
 {
-	PEdge **stackbase = MEM_mallocN(sizeof *stackbase * phash_size(handle->hash_faces), "Pstackbase");
+	PEdge **stackbase = MEM_mallocN(sizeof(*stackbase) * phash_size(handle->hash_faces), "Pstackbase");
 	PEdge **stack = stackbase;
 	PFace *f, *first;
 	PEdge *e, *e1, *e2;
@@ -999,7 +999,7 @@
 
 static PChart **p_split_charts(PHandle *handle, PChart *chart, int ncharts)
 {
-	PChart **charts = MEM_mallocN(sizeof *charts * ncharts, "PCharts"), *nchart;
+	PChart **charts = MEM_mallocN(sizeof(*charts) * ncharts, "PCharts"), *nchart;
 	PFace *f, *nextf;
 	int i;
 
@@ -1041,12 +1041,12 @@
 	PEdge *e1, *e2, *e3;
 
 	/* allocate */
-	f = (PFace *)BLI_memarena_alloc(handle->arena, sizeof *f);
+	f = (PFace *)BLI_memarena_alloc(handle->arena, sizeof(*f));
 	f->flag = 0;  /* init ! */
 
-	e1 = (PEdge *)BLI_memarena_alloc(handle->arena, sizeof *e1);
-	e2 = (PEdge *)BLI_memarena_alloc(handle->arena, sizeof *e2);
-	e3 = (PEdge *)BLI_memarena_alloc(handle->arena, sizeof *e3);
+	e1 = (PEdge *)BLI_memarena_alloc(handle->arena, sizeof(*e1));
+	e2 = (PEdge *)BLI_memarena_alloc(handle->arena, sizeof(*e2));
+	e3 = (PEdge *)BLI_memarena_alloc(handle->arena, sizeof(*e3));
 
 	/* set up edges */
 	f->edge = e1;
@@ -3674,7 +3674,7 @@
 
 static SmoothNode *p_node_new(MemArena *arena, SmoothTriangle **tri, int ntri, float *bmin, float *bmax, int depth)
 {
-	SmoothNode *node = BLI_memarena_alloc(arena, sizeof *node);
+	SmoothNode *node = BLI_memarena_alloc(arena, sizeof(*node));
 	int axis, i, t1size = 0, t2size = 0;
 	float split, /* mi, */ /* UNUSED */ mx;
 	SmoothTriangle **t1, **t2, *t;
@@ -4114,7 +4114,7 @@
 
 ParamHandle *param_construct_begin(void)
 {
-	PHandle *handle = MEM_callocN(sizeof *handle, "PHandle");
+	PHandle *handle = MEM_callocN(sizeof(*handle), "PHandle");
 	handle->construction_chart = p_chart_new(handle);
 	handle->state = PHANDLE_STATE_ALLOCATED;
 	handle->arena = BLI_memarena_new((1 << 16), "param construct arena");

Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2013-02-21 17:16:51 UTC (rev 54711)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2013-02-21 17:18:27 UTC (rev 54712)
@@ -1308,7 +1308,7 @@
 
 static void init(void)
 {
-	memset(nodes, 0, sizeof nodes);
+	memset(nodes, 0, sizeof(nodes));
 	
 	#define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \
 		reg_node(ID, Category_##Category, EnumName, STRINGIFY_ARG(Category##StructName), #Category, UIName, UIDesc);

Modified: trunk/blender/source/tools/check_style_c.py
===================================================================
--- trunk/blender/source/tools/check_style_c.py	2013-02-21 17:16:51 UTC (rev 54711)
+++ trunk/blender/source/tools/check_style_c.py	2013-02-21 17:18:27 UTC (rev 54712)
@@ -126,6 +126,14 @@
     return index + direction
 
 
+def tk_advance_line_start(index):
+    """ Go the the first non-whitespace token of the line.
+    """
+    while tokens[index].line == tokens[index - 1].line and index > 0:
+        index -= 1
+    return tk_advance_no_ws(index, 1)
+
+
 def tk_match_backet(index):
     backet_start = tokens[index].text
     assert(tokens[index].type == Token.Punctuation)
@@ -173,13 +181,13 @@
 
     # print(tokens[i_next])
 
+    # ignore preprocessor
+    i_linestart = tk_advance_line_start(index_kw)
+    if tokens[i_linestart].text.startswith("#"):
+        return None
+
     if tokens[i_next].type != Token.Punctuation or tokens[i_next].text != "(":
-        print("Error line: %d" % tokens[index_kw].line)
-        print("if (\n"
-              "   ^\n"
-              ""
-              "Character not found, insetad found:")
-        print(tk_range_to_str(i_start, i_next))
+        warning("no '(' after '%s'" % tokens[index_kw].text, i_start, i_next)
         return None
 
     i_end = tk_match_backet(i_next)
@@ -373,6 +381,11 @@
             warning("else has no newline before the brace '} else'", i_prev, index_kw)
 
 
+def blender_check_kw_sizeof(index_kw):
+    if tokens[index_kw + 1].text != "(":
+        warning("expected '%s('" % tokens[index_kw].text, index_kw, index_kw + 1)
+
+
 def blender_check_cast(index_kw_start, index_kw_end):
     # detect: '( float...'
     if tokens[index_kw_start + 1].text.isspace():
@@ -700,6 +713,8 @@
                     blender_check_kw_if(item_range[0], i, item_range[1])
             elif tok.text == "else":
                 blender_check_kw_else(i)
+            elif tok.text == "sizeof":
+                blender_check_kw_sizeof(i)
         elif tok.type == Token.Punctuation:
             if tok.text == ",":
                 blender_check_comma(i)




More information about the Bf-blender-cvs mailing list