[Bf-blender-cvs] [c9b4094808a] id_override_static: Address points from initial review.

Bastien Montagne noreply at git.blender.org
Thu Nov 23 23:37:37 CET 2017


Commit: c9b4094808a79cab4153f212f4f91acfdc2120c4
Author: Bastien Montagne
Date:   Thu Nov 23 23:33:29 2017 +0100
Branches: id_override_static
https://developer.blender.org/rBc9b4094808a79cab4153f212f4f91acfdc2120c4

Address points from initial review.

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

M	source/blender/blenloader/intern/writefile.c
M	source/blender/makesrna/RNA_types.h
M	source/blender/makesrna/intern/rna_rna.c
M	source/blender/python/intern/bpy_props.h

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

diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 5aa880acd19..fbda91c8a17 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3949,10 +3949,10 @@ static bool write_file_handle(
 
 	/* This outer loop allows to save first datablocks from real mainvar, then the temp ones from override process,
 	 * if needed, without duplicating whole code. */
-	Main *main = mainvar;
+	Main *bmain = mainvar;
 	do {
 		ListBase *lbarray[MAX_LIBARRAY];
-		int a = set_listbasepointers(main, lbarray);
+		int a = set_listbasepointers(bmain, lbarray);
 		while (a--) {
 			ID *id = lbarray[a]->first;
 
@@ -3964,7 +3964,7 @@ static bool write_file_handle(
 				/* We should never attempt to write non-regular IDs (i.e. all kind of temp/runtime ones). */
 				BLI_assert((id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0);
 
-				const bool do_override = !ELEM(override_storage, NULL, main) && id->override;
+				const bool do_override = !ELEM(override_storage, NULL, bmain) && id->override;
 
 				if (do_override) {
 					BKE_override_operations_store_start(override_storage, id);
@@ -4093,7 +4093,7 @@ static bool write_file_handle(
 
 			mywrite_flush(wd);
 		}
-	} while ((main != override_storage) && (main = override_storage));
+	} while ((bmain != override_storage) && (bmain = override_storage));
 
 	if (override_storage) {
 		BKE_override_operations_store_finalize(override_storage);
diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h
index 343da4035c4..a3bba1984c1 100644
--- a/source/blender/makesrna/RNA_types.h
+++ b/source/blender/makesrna/RNA_types.h
@@ -108,6 +108,8 @@ typedef enum PropertyUnit {
 
 #define RNA_TRANSLATION_PREC_DEFAULT 5
 
+#define RNA_STACK_ARRAY 32
+
 /* also update enums in bpy_props.c when adding items here
  * watch it: these values are written to files as part of
  * node socket button subtypes!
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c
index 6646bf59d83..cc78378a922 100644
--- a/source/blender/makesrna/intern/rna_rna.c
+++ b/source/blender/makesrna/intern/rna_rna.c
@@ -1165,6 +1165,14 @@ static int rna_property_override_equals_propptr(
 	}
 }
 
+static char *rna_path_collection_prop_item_extend(const char *rna_path_prop, const char *item_name)
+{
+	const size_t esc_item_name_len = strlen(item_name) * 2;
+	char *esc_item_name = alloca(sizeof(*esc_item_name) * esc_item_name_len);
+	BLI_strescape(esc_item_name, item_name, esc_item_name_len);
+	return BLI_sprintfN("%s[\"%s\"]", rna_path_prop, esc_item_name);
+}
+
 int rna_property_override_diff_default(PointerRNA *ptr_a, PointerRNA *ptr_b,
         PropertyRNA *prop_a, PropertyRNA *prop_b,
         const int len_a, const int len_b,
@@ -1178,11 +1186,11 @@ int rna_property_override_diff_default(PointerRNA *ptr_a, PointerRNA *ptr_b,
 		case PROP_BOOLEAN:
 		{
 			if (len_a) {
-				int fixed_a[16], fixed_b[16];
+				int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
 				int *array_a, *array_b;
 
-				array_a = (len_a > 16) ? MEM_mallocN(sizeof(int) * len_a, "RNA equals") : fixed_a;
-				array_b = (len_a > 16) ? MEM_mallocN(sizeof(int) * len_a, "RNA equals") : fixed_b;
+				array_a = (len_a > 16) ? MEM_mallocN(sizeof(int) * len_a, "RNA equals") : array_stack_a;
+				array_b = (len_a > 16) ? MEM_mallocN(sizeof(int) * len_a, "RNA equals") : array_stack_b;
 
 				RNA_property_boolean_get_array(ptr_a, prop_a, array_a);
 				RNA_property_boolean_get_array(ptr_b, prop_b, array_b);
@@ -1205,8 +1213,8 @@ int rna_property_override_diff_default(PointerRNA *ptr_a, PointerRNA *ptr_b,
 					}
 				}
 
-				if (array_a != fixed_a) MEM_freeN(array_a);
-				if (array_b != fixed_b) MEM_freeN(array_b);
+				if (array_a != array_stack_a) MEM_freeN(array_a);
+				if (array_b != array_stack_b) MEM_freeN(array_b);
 
 				return comp;
 			}
@@ -1234,11 +1242,11 @@ int rna_property_override_diff_default(PointerRNA *ptr_a, PointerRNA *ptr_b,
 		case PROP_INT:
 		{
 			if (len_a) {
-				int fixed_a[16], fixed_b[16];
+				int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
 				int *array_a, *array_b;
 
-				array_a = (len_a > 16) ? MEM_mallocN(sizeof(int) * len_a, "RNA equals") : fixed_a;
-				array_b = (len_a > 16) ? MEM_mallocN(sizeof(int) * len_a, "RNA equals") : fixed_b;
+				array_a = (len_a > 16) ? MEM_mallocN(sizeof(int) * len_a, "RNA equals") : array_stack_a;
+				array_b = (len_a > 16) ? MEM_mallocN(sizeof(int) * len_a, "RNA equals") : array_stack_b;
 
 				RNA_property_int_get_array(ptr_a, prop_a, array_a);
 				RNA_property_int_get_array(ptr_b, prop_b, array_b);
@@ -1261,8 +1269,8 @@ int rna_property_override_diff_default(PointerRNA *ptr_a, PointerRNA *ptr_b,
 					}
 				}
 
-				if (array_a != fixed_a) MEM_freeN(array_a);
-				if (array_b != fixed_b) MEM_freeN(array_b);
+				if (array_a != array_stack_a) MEM_freeN(array_a);
+				if (array_b != array_stack_b) MEM_freeN(array_b);
 
 				return comp;
 			}
@@ -1291,11 +1299,11 @@ int rna_property_override_diff_default(PointerRNA *ptr_a, PointerRNA *ptr_b,
 		{
 			const bool is_proportional = (prop_a->flag & PROP_PROPORTIONAL) != 0;
 			if (len_a) {
-				float fixed_a[16], fixed_b[16];
+				float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
 				float *array_a, *array_b;
 
-				array_a = (len_a > 16) ? MEM_mallocN(sizeof(float) * len_a, "RNA equals") : fixed_a;
-				array_b = (len_a > 16) ? MEM_mallocN(sizeof(float) * len_a, "RNA equals") : fixed_b;
+				array_a = (len_a > 16) ? MEM_mallocN(sizeof(float) * len_a, "RNA equals") : array_stack_a;
+				array_b = (len_a > 16) ? MEM_mallocN(sizeof(float) * len_a, "RNA equals") : array_stack_b;
 
 				RNA_property_float_get_array(ptr_a, prop_a, array_a);
 				RNA_property_float_get_array(ptr_b, prop_b, array_b);
@@ -1319,8 +1327,8 @@ int rna_property_override_diff_default(PointerRNA *ptr_a, PointerRNA *ptr_b,
 					}
 				}
 
-				if (array_a != fixed_a) MEM_freeN(array_a);
-				if (array_b != fixed_b) MEM_freeN(array_b);
+				if (array_a != array_stack_a) MEM_freeN(array_a);
+				if (array_b != array_stack_b) MEM_freeN(array_b);
 
 				return comp;
 			}
@@ -1441,10 +1449,7 @@ int rna_property_override_diff_default(PointerRNA *ptr_a, PointerRNA *ptr_b,
 						equals = false;
 					}
 					else if (rna_path) {
-						const size_t esc_propname_a_len = strlen(propname_a) * 2;
-						char *esc_propname_a = alloca(sizeof(*esc_propname_a) * esc_propname_a_len);
-						BLI_strescape(esc_propname_a, propname_a, esc_propname_a_len);
-						extended_rna_path = BLI_sprintfN("%s[\"%s\"]", rna_path, esc_propname_a);
+						extended_rna_path = rna_path_collection_prop_item_extend(rna_path, propname_a);
 					}
 				}
 				else {  /* Based on index... */
@@ -1521,10 +1526,10 @@ bool rna_property_override_store_default(
 
 			if (len_local) {
 				if (index == -1) {
-					int fixed_a[16], fixed_b[16];
+					int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
 					int *array_a, *array_b;
 
-					array_a = (len_local > 16) ? MEM_mallocN(sizeof(*array_a) * len_local, __func__) : fixed_a;
+					array_a = (len_local > 16) ? MEM_mallocN(sizeof(*array_a) * len_local, __func__) : array_stack_a;
 					RNA_property_int_get_array(ptr_reference, prop_reference, array_a);
 
 					switch (opop->operation) {
@@ -1534,7 +1539,7 @@ bool rna_property_override_store_default(
 							const int fac = opop->operation == IDOVERRIDE_OP_ADD ? 1 : -1;
 							const int other_op = opop->operation == IDOVERRIDE_OP_ADD ? IDOVERRIDE_OP_SUBTRACT : IDOVERRIDE_OP_ADD;
 							bool do_set = true;
-							array_b = (len_local > 16) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : fixed_b;
+							array_b = (len_local > 16) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
 							RNA_property_int_get_array(ptr_local, prop_local, array_b);
 							for (int i = len_local; i--;) {
 								array_b[i] = fac * (array_b[i] - array_a[i]);
@@ -1557,7 +1562,7 @@ bool rna_property_override_store_default(
 								changed = true;
 								RNA_property_int_set_array(ptr_storage, prop_storage, array_b);
 							}
-							if (array_b != fixed_b) MEM_freeN(array_b);
+							if (array_b != array_stack_b) MEM_freeN(array_b);
 							break;
 						}
 						default:
@@ -1565,7 +1570,7 @@ bool rna_property_override_store_default(
 							break;
 					}
 
-					if (array_a != fixed_a) MEM_freeN(array_a);
+					if (array_a != array_stack_a) MEM_freeN(array_a);
 				}
 				else {
 					const int value = RNA_property_int_get_index(ptr_reference, prop_reference, index);
@@ -1631,10 +1636,10 @@ bool rna_property_override_store_default(
 
 			if (len_local) {
 				if (index == -1) {
-					float fixed_a[16], fixed_b[16];
+					float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
 					float *array_a, *array_b;
 
-					array_a = (len_local > 16) ? MEM_mallocN(sizeof(*array_a) * len_local, __func__) : fixed_a;
+					array_a = (len_local > 16) ? MEM_mallocN(sizeof(*array_a) * len_local, __func__) : array_stack_a;
 
 					RNA_property_float_get_array(ptr_reference, prop_reference, array_a);
 					switch (opop->operation) {
@@ -1644,7 +1649,7 @@ bool rna_property_override_store_default(
 							const float fac = opop->operation == IDOVERRIDE_OP_ADD ? 1.0 : -1.0;
 							const int other_op = opop->operation == IDOVERRIDE_OP_ADD ? IDOVERRIDE_OP_SUBTRACT : IDOVERRIDE_OP_ADD;
 							bool do_set = true;
-							array_b = (len_local > 16) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : fixed_b;
+							array_b = (len_local > 16) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
 							RNA_property_float_get_array(ptr_local, prop_local, array_b);
 							for (int i = len_local; i--;) {
 								array_b[i] = fac * (array_b[i] - array_a[i]);
@@ -1667,13 +1672,13 @@ bool rna_property_override_store_default(
 								changed = true;
 								RNA_property_float_set_array(ptr_storage, prop_storage, array_b);
 							}
-							if (array_b != fixed_b) MEM_freeN(array_b);
+							if (array_b != array_stack_b) MEM_freeN(array_b);
 							

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list