[Bf-blender-cvs] [0c603cffd12] master: RNA: support 64 bit boolean bitflags in DNA

Brecht Van Lommel noreply at git.blender.org
Tue Mar 3 18:05:26 CET 2020


Commit: 0c603cffd123689c3021862a9d76dad9fbe13f4d
Author: Brecht Van Lommel
Date:   Tue Mar 3 17:21:18 2020 +0100
Branches: master
https://developer.blender.org/rB0c603cffd123689c3021862a9d76dad9fbe13f4d

RNA: support 64 bit boolean bitflags in DNA

This does not affect the RNA access API, since how the boolean is read from
DNA abstracted away in the API.

Differential Revision: https://developer.blender.org/D7002

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

M	source/blender/makesrna/RNA_define.h
M	source/blender/makesrna/intern/makesrna.c
M	source/blender/makesrna/intern/rna_define.c
M	source/blender/makesrna/intern/rna_internal.h

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

diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h
index 349b30fa64e..026043cd7c5 100644
--- a/source/blender/makesrna/RNA_define.h
+++ b/source/blender/makesrna/RNA_define.h
@@ -23,6 +23,7 @@
  * Functions used during preprocess and runtime, for defining the RNA.
  */
 
+#include <inttypes.h>
 #include <float.h>
 #include <limits.h>
 
@@ -337,11 +338,11 @@ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont,
 void RNA_def_property_boolean_sdna(PropertyRNA *prop,
                                    const char *structname,
                                    const char *propname,
-                                   int bit);
+                                   int64_t bit);
 void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop,
                                             const char *structname,
                                             const char *propname,
-                                            int bit);
+                                            int64_t bit);
 void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname);
 void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname);
 void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname);
@@ -508,6 +509,8 @@ const char *RNA_property_typename(PropertyType type);
 #define IS_DNATYPE_FLOAT_COMPAT(_str) (strcmp(_str, "float") == 0 || strcmp(_str, "double") == 0)
 #define IS_DNATYPE_INT_COMPAT(_str) \
   (strcmp(_str, "int") == 0 || strcmp(_str, "short") == 0 || strcmp(_str, "char") == 0)
+#define IS_DNATYPE_BOOLEAN_COMPAT(_str) \
+  (IS_DNATYPE_INT_COMPAT(_str) || strcmp(_str, "int64_t") == 0 || strcmp(_str, "uint64_t") == 0)
 
 void RNA_identifier_sanitize(char *identifier, int property);
 
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 2f5d9ae7a50..7b23364bd90 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -18,6 +18,7 @@
  * \ingroup RNA
  */
 
+#include <inttypes.h>
 #include <float.h>
 #include <limits.h>
 #include <stdio.h>
@@ -595,7 +596,7 @@ static void rna_float_print(FILE *f, float num)
   }
 }
 
-static void rna_int_print(FILE *f, int num)
+static void rna_int_print(FILE *f, int64_t num)
 {
   if (num == INT_MIN) {
     fprintf(f, "INT_MIN");
@@ -603,8 +604,17 @@ static void rna_int_print(FILE *f, int num)
   else if (num == INT_MAX) {
     fprintf(f, "INT_MAX");
   }
+  else if (num == INT64_MIN) {
+    fprintf(f, "INT64_MIN");
+  }
+  else if (num == INT64_MAX) {
+    fprintf(f, "INT64_MAX");
+  }
+  else if (num < INT_MIN || num > INT_MAX) {
+    fprintf(f, "%" PRId64 "LL", num);
+  }
   else {
-    fprintf(f, "%d", num);
+    fprintf(f, "%d", (int)num);
   }
 }
 
@@ -642,7 +652,19 @@ static char *rna_def_property_get_func(
           }
         }
       }
-      else if (prop->type == PROP_INT || prop->type == PROP_BOOLEAN || prop->type == PROP_ENUM) {
+      else if (prop->type == PROP_BOOLEAN) {
+        if (IS_DNATYPE_BOOLEAN_COMPAT(dp->dnatype) == 0) {
+          CLOG_ERROR(&LOG,
+                     "%s.%s is a '%s' but wrapped as type '%s'.",
+                     srna->identifier,
+                     prop->identifier,
+                     dp->dnatype,
+                     RNA_property_typename(prop->type));
+          DefRNA.error = 1;
+          return NULL;
+        }
+      }
+      else if (prop->type == PROP_INT || prop->type == PROP_ENUM) {
         if (IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
           CLOG_ERROR(&LOG,
                      "%s.%s is a '%s' but wrapped as type '%s'.",
@@ -784,10 +806,11 @@ static char *rna_def_property_get_func(
           if (dp->dnaarraylength == 1) {
             if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
               fprintf(f,
-                      "        values[i] = %s((data->%s & (%du << i)) != 0);\n",
+                      "        values[i] = %s((data->%s & (",
                       (dp->booleannegative) ? "!" : "",
-                      dp->dnaname,
-                      dp->booleanbit);
+                      dp->dnaname);
+              rna_int_print(f, dp->booleanbit);
+              fprintf(f, " << i)) != 0);\n");
             }
             else {
               fprintf(f,
@@ -1111,11 +1134,14 @@ static char *rna_def_property_set_func(
           if (dp->dnaarraylength == 1) {
             if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
               fprintf(f,
-                      "        if (%svalues[i]) data->%s |= (%du << i);\n",
+                      "        if (%svalues[i]) data->%s |= (",
                       (dp->booleannegative) ? "!" : "",
-                      dp->dnaname,
-                      dp->booleanbit);
-              fprintf(f, "        else data->%s &= ~(%du << i);\n", dp->dnaname, dp->booleanbit);
+                      dp->dnaname);
+              rna_int_print(f, dp->booleanbit);
+              fprintf(f, " << i);\n");
+              fprintf(f, "        else data->%s &= ~(", dp->dnaname);
+              rna_int_print(f, dp->booleanbit);
+              fprintf(f, " << i);\n");
             }
             else {
               fprintf(
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index 4150daa0f63..56516c8af4d 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -2188,7 +2188,7 @@ static PropertyDefRNA *rna_def_property_sdna(PropertyRNA *prop,
 void RNA_def_property_boolean_sdna(PropertyRNA *prop,
                                    const char *structname,
                                    const char *propname,
-                                   int bit)
+                                   int64_t bit)
 {
   PropertyDefRNA *dp;
   BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
@@ -2209,7 +2209,7 @@ void RNA_def_property_boolean_sdna(PropertyRNA *prop,
 
     if (DefRNA.silent == 0) {
       /* error check to ensure floats are not wrapped as ints/bools */
-      if (dp->dnatype && *dp->dnatype && IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
+      if (dp->dnatype && *dp->dnatype && IS_DNATYPE_BOOLEAN_COMPAT(dp->dnatype) == 0) {
         CLOG_ERROR(&LOG,
                    "%s.%s is a '%s' but wrapped as type '%s'.",
                    srna->identifier,
@@ -2279,7 +2279,7 @@ void RNA_def_property_boolean_sdna(PropertyRNA *prop,
 void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop,
                                             const char *structname,
                                             const char *propname,
-                                            int booleanbit)
+                                            int64_t booleanbit)
 {
   PropertyDefRNA *dp;
 
@@ -2288,7 +2288,7 @@ void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop,
   dp = rna_find_struct_property_def(DefRNA.laststruct, prop);
 
   if (dp) {
-    dp->booleannegative = 1;
+    dp->booleannegative = true;
   }
 }
 
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 56c99194b93..6bda8ebdb4c 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -85,7 +85,8 @@ typedef struct PropertyDefRNA {
   const char *dnalengthname;
   int dnalengthfixed;
 
-  int booleanbit, booleannegative;
+  int64_t booleanbit;
+  bool booleannegative;
 
   /* not to be confused with PROP_ENUM_FLAG
    * this only allows one of the flags to be set at a time, clearing all others */



More information about the Bf-blender-cvs mailing list