[Bf-blender-cvs] [63006c8] master: writefile: use const for old address

Campbell Barton noreply at git.blender.org
Wed Jun 22 04:15:10 CEST 2016


Commit: 63006c88a1527c9199b9db0f6f22309781eaa4c3
Author: Campbell Barton
Date:   Wed Jun 22 08:44:26 2016 +1000
Branches: master
https://developer.blender.org/rB63006c88a1527c9199b9db0f6f22309781eaa4c3

writefile: use const for old address

Also remove temp preview overwriting.

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

M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/makesdna/DNA_sdna_types.h

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 5c7b664..689a975 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8519,7 +8519,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
 
 struct BHeadSort {
 	BHead *bhead;
-	void *old;
+	const void *old;
 };
 
 static int verg_bheadsort(const void *v1, const void *v2)
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 327b7b5..b5a2115 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -449,7 +449,9 @@ static int endwrite(WriteData *wd)
 
 /* ********** WRITE FILE ****************** */
 
-static void writestruct_at_address(WriteData *wd, int filecode, const char *structname, int nr, void *adr, void *data)
+static void writestruct_at_address(
+        WriteData *wd, int filecode, const char *structname, int nr,
+        const void *adr, const void *data)
 {
 	BHead bh;
 	const short *sp;
@@ -476,7 +478,9 @@ static void writestruct_at_address(WriteData *wd, int filecode, const char *stru
 	mywrite(wd, data, bh.len);
 }
 
-static void writestruct(WriteData *wd, int filecode, const char *structname, int nr, void *adr)
+static void writestruct(
+        WriteData *wd, int filecode, const char *structname, int nr,
+        const void *adr)
 {
 	writestruct_at_address(wd, filecode, structname, nr, adr, adr);
 }
@@ -493,7 +497,7 @@ static void writedata(WriteData *wd, int filecode, int len, const void *adr)  /*
 
 	/* init BHead */
 	bh.code   = filecode;
-	bh.old    = (void *)adr;  /* this is safe to cast from const */
+	bh.old    = adr;
 	bh.nr     = 1;
 	bh.SDNAnr = 0;
 	bh.len    = len;
@@ -503,9 +507,9 @@ static void writedata(WriteData *wd, int filecode, int len, const void *adr)  /*
 }
 
 /* use this to force writing of lists in same order as reading (using link_list) */
-static void writelist(WriteData *wd, int filecode, const char *structname, ListBase *lb)
+static void writelist(WriteData *wd, int filecode, const char *structname, const ListBase *lb)
 {
-	Link *link = lb->first;
+	const Link *link = lb->first;
 	
 	while (link) {
 		writestruct(wd, filecode, structname, 1, link);
@@ -515,10 +519,10 @@ static void writelist(WriteData *wd, int filecode, const char *structname, ListB
 
 /* *************** writing some direct data structs used in more code parts **************** */
 /*These functions are used by blender's .blend system for file saving/loading.*/
-void IDP_WriteProperty_OnlyData(IDProperty *prop, void *wd);
-void IDP_WriteProperty(IDProperty *prop, void *wd);
+void IDP_WriteProperty_OnlyData(const IDProperty *prop, void *wd);
+void IDP_WriteProperty(const IDProperty *prop, void *wd);
 
-static void IDP_WriteArray(IDProperty *prop, void *wd)
+static void IDP_WriteArray(const IDProperty *prop, void *wd)
 {
 	/*REMEMBER to set totalen to len in the linking code!!*/
 	if (prop->data.pointer) {
@@ -534,11 +538,11 @@ static void IDP_WriteArray(IDProperty *prop, void *wd)
 	}
 }
 
-static void IDP_WriteIDPArray(IDProperty *prop, void *wd)
+static void IDP_WriteIDPArray(const IDProperty *prop, void *wd)
 {
 	/*REMEMBER to set totalen to len in the linking code!!*/
 	if (prop->data.pointer) {
-		IDProperty *array = prop->data.pointer;
+		const IDProperty *array = prop->data.pointer;
 		int a;
 
 		writestruct(wd, DATA, "IDProperty", prop->len, array);
@@ -548,13 +552,13 @@ static void IDP_WriteIDPArray(IDProperty *prop, void *wd)
 	}
 }
 
-static void IDP_WriteString(IDProperty *prop, void *wd)
+static void IDP_WriteString(const IDProperty *prop, void *wd)
 {
 	/*REMEMBER to set totalen to len in the linking code!!*/
 	writedata(wd, DATA, prop->len, prop->data.pointer);
 }
 
-static void IDP_WriteGroup(IDProperty *prop, void *wd)
+static void IDP_WriteGroup(const IDProperty *prop, void *wd)
 {
 	IDProperty *loop;
 
@@ -564,7 +568,7 @@ static void IDP_WriteGroup(IDProperty *prop, void *wd)
 }
 
 /* Functions to read/write ID Properties */
-void IDP_WriteProperty_OnlyData(IDProperty *prop, void *wd)
+void IDP_WriteProperty_OnlyData(const IDProperty *prop, void *wd)
 {
 	switch (prop->type) {
 		case IDP_GROUP:
@@ -582,13 +586,13 @@ void IDP_WriteProperty_OnlyData(IDProperty *prop, void *wd)
 	}
 }
 
-void IDP_WriteProperty(IDProperty *prop, void *wd)
+void IDP_WriteProperty(const IDProperty *prop, void *wd)
 {
 	writestruct(wd, DATA, "IDProperty", 1, prop);
 	IDP_WriteProperty_OnlyData(prop, wd);
 }
 
-static void write_iddata(void *wd, ID *id)
+static void write_iddata(void *wd, const ID *id)
 {
 	/* ID_WM's id->properties are considered runtime only, and never written in .blend file. */
 	if (id->properties && !ELEM(GS(id->name), ID_WM)) {
@@ -596,29 +600,24 @@ static void write_iddata(void *wd, ID *id)
 	}
 }
 
-static void write_previews(WriteData *wd, PreviewImage *prv)
+static void write_previews(WriteData *wd, const PreviewImage *prv_orig)
 {
 	/* Never write previews when doing memsave (i.e. undo/redo)! */
-	if (prv && !wd->current) {
-		short w = prv->w[1];
-		short h = prv->h[1];
-		unsigned int *rect = prv->rect[1];
+	if (prv_orig && !wd->current) {
+		PreviewImage prv = *prv_orig;
 
 		/* don't write out large previews if not requested */
 		if (!(U.flag & USER_SAVE_PREVIEWS)) {
-			prv->w[1] = 0;
-			prv->h[1] = 0;
-			prv->rect[1] = NULL;
-		}
-		writestruct(wd, DATA, "PreviewImage", 1, prv);
-		if (prv->rect[0]) writedata(wd, DATA, prv->w[0] * prv->h[0] * sizeof(unsigned int), prv->rect[0]);
-		if (prv->rect[1]) writedata(wd, DATA, prv->w[1] * prv->h[1] * sizeof(unsigned int), prv->rect[1]);
-
-		/* restore preview, we still want to keep it in memory even if not saved to file */
-		if (!(U.flag & USER_SAVE_PREVIEWS) ) {
-			prv->w[1] = w;
-			prv->h[1] = h;
-			prv->rect[1] = rect;
+			prv.w[1] = 0;
+			prv.h[1] = 0;
+			prv.rect[1] = NULL;
+		}
+		writestruct_at_address(wd, DATA, "PreviewImage", 1, prv_orig, &prv);
+		if (prv.rect[0]) {
+			writedata(wd, DATA, prv.w[0] * prv.h[0] * sizeof(unsigned int), prv.rect[0]);
+		}
+		if (prv.rect[1]) {
+			writedata(wd, DATA, prv.w[1] * prv.h[1] * sizeof(unsigned int), prv.rect[1]);
 		}
 	}
 }
diff --git a/source/blender/makesdna/DNA_sdna_types.h b/source/blender/makesdna/DNA_sdna_types.h
index 28204eb..cb7a371 100644
--- a/source/blender/makesdna/DNA_sdna_types.h
+++ b/source/blender/makesdna/DNA_sdna_types.h
@@ -67,7 +67,7 @@ typedef struct SDNA {
 #
 typedef struct BHead {
 	int code, len;
-	void *old;
+	const void *old;
 	int SDNAnr, nr;
 } BHead;
 #




More information about the Bf-blender-cvs mailing list