[Bf-blender-cvs] [f67e81e295a] master: Cleanup: SDNA/DNA naming

Campbell Barton noreply at git.blender.org
Sat Mar 2 15:40:18 CET 2019


Commit: f67e81e295ac7da6857edc441e0ba582cfcd6424
Author: Campbell Barton
Date:   Sun Mar 3 01:05:58 2019 +1100
Branches: master
https://developer.blender.org/rBf67e81e295ac7da6857edc441e0ba582cfcd6424

Cleanup: SDNA/DNA naming

Use 'size' instead of 'len' to represent the size of data in bytes,
'len' is used for the result of 'strlen' or the length of an array
in some parts of 'makesdna.c' & 'dna_genfile.c'.

Also clarify comments and some variable names, no functional changes.

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

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

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index fec4f3486d5..dc988afaabe 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2118,7 +2118,7 @@ static void switch_endian_structs(const struct SDNA *filesdna, BHead *bhead)
 	char *data;
 
 	data = (char *)(bhead + 1);
-	blocksize = filesdna->typelens[filesdna->structs[bhead->SDNAnr][0]];
+	blocksize = filesdna->types_size[filesdna->structs[bhead->SDNAnr][0]];
 
 	nblocks = bhead->nr;
 	while (nblocks--) {
@@ -2264,9 +2264,9 @@ static void test_pointer_array(FileData *fd, void **mat)
 	 * the new dna format.
 	 */
 	if (*mat) {
-		len = MEM_allocN_len(*mat) / fd->filesdna->pointerlen;
+		len = MEM_allocN_len(*mat) / fd->filesdna->pointer_size;
 
-		if (fd->filesdna->pointerlen == 8 && fd->memsdna->pointerlen == 4) {
+		if (fd->filesdna->pointer_size == 8 && fd->memsdna->pointer_size == 4) {
 			ipoin = imat = MEM_malloc_arrayN(len, 4, "newmatar");
 			lpoin = *mat;
 
@@ -2281,7 +2281,7 @@ static void test_pointer_array(FileData *fd, void **mat)
 			*mat = imat;
 		}
 
-		if (fd->filesdna->pointerlen == 4 && fd->memsdna->pointerlen == 8) {
+		if (fd->filesdna->pointer_size == 4 && fd->memsdna->pointer_size == 8) {
 			lpoin = lmat = MEM_malloc_arrayN(len, 8, "newmatar");
 			ipoin = *mat;
 
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index ef2c73a675f..6694e050695 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -531,7 +531,7 @@ static void writestruct_at_address_nr(
 	bh.SDNAnr = struct_nr;
 	sp = wd->sdna->structs[bh.SDNAnr];
 
-	bh.len = nr * wd->sdna->typelens[sp[0]];
+	bh.len = nr * wd->sdna->types_size[sp[0]];
 
 	if (bh.len == 0) {
 		return;
@@ -4047,7 +4047,7 @@ static bool write_file_handle(
 	 *
 	 * Note that we *borrow* the pointer to 'DNAstr',
 	 * so writing each time uses the same address and doesn't cause unnecessary undo overhead. */
-	writedata(wd, DNA1, wd->sdna->datalen, wd->sdna->data);
+	writedata(wd, DNA1, wd->sdna->data_len, wd->sdna->data);
 
 #ifdef USE_NODE_COMPAT_CUSTOMNODES
 	/* compatibility data not created on undo */
diff --git a/source/blender/makesdna/DNA_genfile.h b/source/blender/makesdna/DNA_genfile.h
index b6c0da59038..d9fc14d9393 100644
--- a/source/blender/makesdna/DNA_genfile.h
+++ b/source/blender/makesdna/DNA_genfile.h
@@ -78,7 +78,7 @@ enum eSDNA_StructCompare {
 };
 
 struct SDNA *DNA_sdna_from_data(
-        const void *data, const int datalen,
+        const void *data, const int data_len,
         bool do_endian_swap, bool data_alloc,
         const char **r_error_message);
 void DNA_sdna_free(struct SDNA *sdna);
diff --git a/source/blender/makesdna/DNA_listBase.h b/source/blender/makesdna/DNA_listBase.h
index 084f1a17cf0..359aa7a219c 100644
--- a/source/blender/makesdna/DNA_listBase.h
+++ b/source/blender/makesdna/DNA_listBase.h
@@ -19,8 +19,7 @@
 
 /** \file
  * \ingroup DNA
- * \brief These structs are the foundation for all linked lists in the
- *         library system.
+ * \brief These structs are the foundation for all linked lists in the library system.
  *
  * Doubly-linked lists start from a ListBase and contain elements beginning
  * with Link.
@@ -33,19 +32,19 @@
 extern "C" {
 #endif
 
-/* generic - all structs which are put into linked lists begin with this */
+/** Generic - all structs which are put into linked lists begin with this. */
 typedef struct Link {
 	struct Link *next, *prev;
 } Link;
 
 
-/* simple subclass of Link--use this when it is not worth defining a custom one... */
+/** Simple subclass of Link. Use this when it is not worth defining a custom one. */
 typedef struct LinkData {
 	struct LinkData *next, *prev;
 	void *data;
 } LinkData;
 
-/* never change the size of this! genfile.c detects pointerlen with it */
+/** Never change the size of this! dna_genfile.c detects pointer_size with it. */
 typedef struct ListBase  {
 	void *first, *last;
 } ListBase;
diff --git a/source/blender/makesdna/DNA_sdna_types.h b/source/blender/makesdna/DNA_sdna_types.h
index 4167f9b61ee..5b57065dff3 100644
--- a/source/blender/makesdna/DNA_sdna_types.h
+++ b/source/blender/makesdna/DNA_sdna_types.h
@@ -31,7 +31,7 @@ typedef struct SDNA {
 	/** Full copy of 'encoded' data (when data_alloc is set, otherwise borrowed). */
 	const char *data;
 	/** Length of data. */
-	int datalen;
+	int data_len;
 	bool data_alloc;
 
 	/** Total number of struct members. */
@@ -40,14 +40,14 @@ typedef struct SDNA {
 	const char **names;
 
 	/** Size of a pointer in bytes. */
-	int pointerlen;
+	int pointer_size;
 
 	/** Number of basic types + struct types. */
 	int nr_types;
 	/** Type names. */
 	const char **types;
 	/** Type lengths. */
-	short *typelens;
+	short *types_size;
 
 	/** Number of struct types. */
 	int nr_structs;
diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c
index 4d65fb8f1ed..e25bbdf7d46 100644
--- a/source/blender/makesdna/intern/dna_genfile.c
+++ b/source/blender/makesdna/intern/dna_genfile.c
@@ -175,7 +175,7 @@ static bool ispointer(const char *name)
 /**
  * Returns the size of struct fields of the specified type and name.
  *
- * \param type: Index into sdna->types/typelens
+ * \param type: Index into sdna->types/types_size
  * \param name: Index into sdna->names,
  * needed to extract possible pointer/array information.
  */
@@ -196,16 +196,16 @@ static int elementsize(const SDNA *sdna, short type, short name)
 			mul = DNA_elem_array_size(cp);
 		}
 
-		len = sdna->pointerlen * mul;
+		len = sdna->pointer_size * mul;
 	}
-	else if (sdna->typelens[type]) {
+	else if (sdna->types_size[type]) {
 		/* has the name an extra length? (array) */
 		mul = 1;
 		if (cp[namelen - 1] == ']') {
 			mul = DNA_elem_array_size(cp);
 		}
 
-		len = mul * sdna->typelens[type];
+		len = mul * sdna->types_size[type];
 
 	}
 
@@ -397,7 +397,7 @@ static bool init_structDNA(
 		if (*data == MAKE_ID('T', 'L', 'E', 'N')) {
 			data++;
 			sp = (short *)data;
-			sdna->typelens = sp;
+			sdna->types_size = sp;
 
 			if (do_endian_swap) {
 				BLI_endian_switch_int16_array(sp, sdna->nr_types);
@@ -476,7 +476,7 @@ static bool init_structDNA(
 	}
 #endif
 
-	/* Calculate 'sdna->pointerlen' */
+	/* Calculate 'sdna->pointer_size' */
 	{
 		const int nr = DNA_struct_find_nr(sdna, "ListBase");
 
@@ -486,13 +486,13 @@ static bool init_structDNA(
 			return false;
 		}
 
-		/* finally pointerlen: use struct ListBase to test it, never change the size of it! */
+		/* finally pointer_size: use struct ListBase to test it, never change the size of it! */
 		sp = sdna->structs[nr];
 		/* weird; i have no memory of that... I think I used sizeof(void *) before... (ton) */
 
-		sdna->pointerlen = sdna->typelens[sp[0]] / 2;
+		sdna->pointer_size = sdna->types_size[sp[0]] / 2;
 
-		if (sp[1] != 2 || (sdna->pointerlen != 4 && sdna->pointerlen != 8)) {
+		if (sp[1] != 2 || (sdna->pointer_size != 4 && sdna->pointer_size != 8)) {
 			*r_error_message = "ListBase struct error! Needs it to calculate pointerize.";
 			/* well, at least sizeof(ListBase) is error proof! (ton) */
 			return false;
@@ -506,17 +506,17 @@ static bool init_structDNA(
  * Constructs and returns a decoded SDNA structure from the given encoded SDNA data block.
  */
 SDNA *DNA_sdna_from_data(
-        const void *data, const int datalen,
+        const void *data, const int data_len,
         bool do_endian_swap, bool data_alloc,
         const char **r_error_message)
 {
 	SDNA *sdna = MEM_mallocN(sizeof(*sdna), "sdna");
 	const char *error_message = NULL;
 
-	sdna->datalen = datalen;
+	sdna->data_len = data_len;
 	if (data_alloc) {
-		char *data_copy = MEM_mallocN(datalen, "sdna_data");
-		memcpy(data_copy, data, datalen);
+		char *data_copy = MEM_mallocN(data_len, "sdna_data");
+		memcpy(data_copy, data, data_len);
 		sdna->data = data_copy;
 	}
 	else {
@@ -641,7 +641,7 @@ const char *DNA_struct_get_compareflags(const SDNA *oldsdna, const SDNA *newsdna
 
 			/* compare length and amount of elems */
 			if (sp_new[1] == sp_old[1]) {
-				if (newsdna->typelens[sp_new[0]] == oldsdna->typelens[sp_old[0]]) {
+				if (newsdna->types_size[sp_new[0]] == oldsdna->types_size[sp_old[0]]) {
 
 					/* same length, same amount of elems, now per type and name */
 					b = sp_old[1];
@@ -658,7 +658,7 @@ const char *DNA_struct_get_compareflags(const SDNA *oldsdna, const SDNA *newsdna
 
 						/* same type and same name, now pointersize */
 						if (ispointer(str1)) {
-							if (oldsdna->pointerlen != newsdna->pointerlen) break;
+							if (oldsdna->pointer_size != newsdna->pointer_size) break;
 						}
 
 						b--;
@@ -1004,7 +1004,7 @@ static void reconstruct_elem(
 		if (strcmp(name, oname) == 0) { /* name equal */
 
 			if (ispointer(name)) {  /* pointer of functionpointer afhandelen */
-				cast_pointer(newsdna->pointerlen, oldsdna->pointerlen, name, curdata, olddata);
+				cast_pointer(newsdna->pointer_size, oldsdna->pointer_size, name, curdata, olddata);
 			}
 			else if (strcmp(type, otype) == 0) {    /* type equal */
 				memcpy(curdata, olddata, len);
@@ -1023,7 +1023,7 @@ static void reconstruct_elem(
 				oldsize = DNA_elem_array_size(oname);
 
 				if (ispointer(name)) {  /* handle pointer or functionpointer */
-					cast_pointer(newsdna->pointerlen, oldsdna->pointerlen,
+					cast_pointer(newsdna->pointer_size, oldsdna->pointer_size,
 					             cursize > oldsize ? oname : name,
 					             curdata, olddata);
 				}
@@ -1096,7 +1096,7 @@ static void reconstruct_struct(
 	if (compflags[oldSDNAnr] == SDNA_CMP_EQUAL) {
 		/* if recursive: test for equal */
 		spo = oldsdna->structs[oldSDNAnr];
-		elen = oldsdna->typelens[spo[0]];
+		elen = oldsdna->types_size[spo[0]];
 		memcpy(cur, data, elen);
 
 		return;
@@ -1214,7 +1214,7 @@ void DNA_struct_switch_endian(const SDNA *oldsdna, int oldSDNAnr, char *data)
 		else {
 			/* non-struct field type */
 			if (ispointer(name)) {
-				if (oldsdna->pointerlen == 8) {
+				if (oldsdna->pointer_size == 8) {
 					BLI_endian_switch_int64_array((int64_t *)cur,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list