[Bf-blender-cvs] [976a0ff6910] master: RNA code cleanup: Fix wrong usages of `rna_idproperty_check()`.

Bastien Montagne noreply at git.blender.org
Mon Jul 13 12:52:01 CEST 2020


Commit: 976a0ff691040fee4633910b9ab6f898d406405a
Author: Bastien Montagne
Date:   Mon Jul 13 12:48:56 2020 +0200
Branches: master
https://developer.blender.org/rB976a0ff691040fee4633910b9ab6f898d406405a

RNA code cleanup: Fix wrong usages of `rna_idproperty_check()`.

This function is more expansive than the simpler `rna_ensure_property()`
one, and should only be used when IDProperty data is actually needed.

If one only needs to ensure it has a valid PropertyRNA pointer,
`rna_ensure_property()` is much more efficient.

Also add compiler warnings when results of those functions are unused,
this should never be the case.

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

M	source/blender/makesrna/intern/rna_access_internal.h
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_rna.c

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

diff --git a/source/blender/makesrna/intern/rna_access_internal.h b/source/blender/makesrna/intern/rna_access_internal.h
index 7d8fff21862..a5b554ec7a6 100644
--- a/source/blender/makesrna/intern/rna_access_internal.h
+++ b/source/blender/makesrna/intern/rna_access_internal.h
@@ -28,7 +28,6 @@
 struct IDProperty;
 struct PropertyRNAOrID;
 
-PropertyRNA *rna_ensure_property(PropertyRNA *prop);
 void rna_property_rna_or_id_get(PropertyRNA *prop,
                                 PointerRNA *ptr,
                                 PropertyRNAOrID *r_prop_rna_or_id);
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 8e6a360f2c9..a8085c00cb3 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -23,6 +23,8 @@
 
 #include "BLI_utildefines.h"
 
+#include "BLI_compiler_attrs.h"
+
 #include "rna_internal_types.h"
 
 #include "UI_resources.h"
@@ -478,9 +480,11 @@ extern StructRNA RNA_PropertyGroupItem;
 extern StructRNA RNA_PropertyGroup;
 #endif
 
-struct IDProperty *rna_idproperty_check(struct PropertyRNA **prop, struct PointerRNA *ptr);
+struct IDProperty *rna_idproperty_check(struct PropertyRNA **prop,
+                                        struct PointerRNA *ptr) ATTR_WARN_UNUSED_RESULT;
 struct PropertyRNA *rna_ensure_property_realdata(struct PropertyRNA **prop,
-                                                 struct PointerRNA *ptr);
+                                                 struct PointerRNA *ptr) ATTR_WARN_UNUSED_RESULT;
+struct PropertyRNA *rna_ensure_property(struct PropertyRNA *prop) ATTR_WARN_UNUSED_RESULT;
 
 /* Override default callbacks. */
 /* Default override callbacks for all types. */
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c
index 39949538726..f9f6defb2f1 100644
--- a/source/blender/makesrna/intern/rna_rna.c
+++ b/source/blender/makesrna/intern/rna_rna.c
@@ -479,7 +479,7 @@ static StructRNA *rna_Property_refine(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
 
-  rna_idproperty_check(&prop, ptr); /* XXX ptr? */
+  prop = rna_ensure_property(prop);
 
   switch (prop->type) {
     case PROP_BOOLEAN:
@@ -504,90 +504,90 @@ static StructRNA *rna_Property_refine(PointerRNA *ptr)
 static void rna_Property_identifier_get(PointerRNA *ptr, char *value)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   strcpy(value, ((PropertyRNA *)prop)->identifier);
 }
 
 static int rna_Property_identifier_length(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return strlen(prop->identifier);
 }
 
 static void rna_Property_name_get(PointerRNA *ptr, char *value)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   strcpy(value, prop->name ? prop->name : "");
 }
 
 static int rna_Property_name_length(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return prop->name ? strlen(prop->name) : 0;
 }
 
 static void rna_Property_description_get(PointerRNA *ptr, char *value)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   strcpy(value, prop->description ? prop->description : "");
 }
 static int rna_Property_description_length(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return prop->description ? strlen(prop->description) : 0;
 }
 
 static void rna_Property_translation_context_get(PointerRNA *ptr, char *value)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   strcpy(value, prop->translation_context);
 }
 
 static int rna_Property_translation_context_length(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return strlen(prop->translation_context);
 }
 
 static int rna_Property_type_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return prop->type;
 }
 
 static int rna_Property_subtype_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return prop->subtype;
 }
 
 static PointerRNA rna_Property_srna_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return rna_pointer_inherit_refine(ptr, &RNA_Struct, prop->srna);
 }
 
 static int rna_Property_unit_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return RNA_SUBTYPE_UNIT(prop->subtype);
 }
 
 static int rna_Property_icon_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return prop->icon;
 }
 
@@ -698,7 +698,7 @@ static const EnumPropertyItem *rna_Property_tags_itemf(bContext *UNUSED(C),
 static int rna_Property_array_length_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return prop->totarraylength;
 }
 
@@ -706,7 +706,7 @@ static void rna_Property_array_dimensions_get(PointerRNA *ptr,
                                               int dimensions[RNA_MAX_ARRAY_DIMENSION])
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
 
   if (prop->arraydimension > 1) {
     for (int i = RNA_MAX_ARRAY_DIMENSION; i--;) {
@@ -740,14 +740,14 @@ static bool rna_Property_is_runtime_get(PointerRNA *ptr)
 static bool rna_BoolProperty_default_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return ((BoolPropertyRNA *)prop)->defaultvalue;
 }
 
 static int rna_IntProperty_default_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return ((IntPropertyRNA *)prop)->defaultvalue;
 }
 /* int/float/bool */
@@ -755,7 +755,7 @@ static int rna_NumberProperty_default_array_get_length(PointerRNA *ptr,
                                                        int length[RNA_MAX_ARRAY_DIMENSION])
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
 
   length[0] = prop->totarraylength;
 
@@ -771,7 +771,7 @@ static bool rna_NumberProperty_is_array_get(PointerRNA *ptr)
 static void rna_IntProperty_default_array_get(PointerRNA *ptr, int *values)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   if (prop->totarraylength > 0) {
     PointerRNA null_ptr = PointerRNA_NULL;
     RNA_property_int_get_default_array(&null_ptr, prop, values);
@@ -781,7 +781,7 @@ static void rna_IntProperty_default_array_get(PointerRNA *ptr, int *values)
 static void rna_BoolProperty_default_array_get(PointerRNA *ptr, bool *values)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   if (prop->totarraylength > 0) {
     PointerRNA null_ptr = PointerRNA_NULL;
     RNA_property_boolean_get_default_array(&null_ptr, prop, values);
@@ -791,7 +791,7 @@ static void rna_BoolProperty_default_array_get(PointerRNA *ptr, bool *values)
 static void rna_FloatProperty_default_array_get(PointerRNA *ptr, float *values)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   if (prop->totarraylength > 0) {
     PointerRNA null_ptr = PointerRNA_NULL;
     RNA_property_float_get_default_array(&null_ptr, prop, values);
@@ -801,103 +801,103 @@ static void rna_FloatProperty_default_array_get(PointerRNA *ptr, float *values)
 static int rna_IntProperty_hard_min_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return ((IntPropertyRNA *)prop)->hardmin;
 }
 
 static int rna_IntProperty_hard_max_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return ((IntPropertyRNA *)prop)->hardmax;
 }
 
 static int rna_IntProperty_soft_min_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return ((IntPropertyRNA *)prop)->softmin;
 }
 
 static int rna_IntProperty_soft_max_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return ((IntPropertyRNA *)prop)->softmax;
 }
 
 static int rna_IntProperty_step_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return ((IntPropertyRNA *)prop)->step;
 }
 
 static float rna_FloatProperty_default_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return ((FloatPropertyRNA *)prop)->defaultvalue;
 }
 static float rna_FloatProperty_hard_min_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idproperty_check(&prop, ptr);
+  prop = rna_ensure_property(prop);
   return ((FloatPropertyRNA *)prop)->hardmin;
 }
 
 static float rna_FloatProperty_hard_max_get(PointerRNA *ptr)
 {
   PropertyRNA *prop = (PropertyRNA *)ptr->data;
-  rna_idp

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list