[Bf-blender-cvs] [9b15c552cc1] master: DNA: support int8_t type in DNA structs

Jacques Lucke noreply at git.blender.org
Tue Apr 13 09:39:30 CEST 2021


Commit: 9b15c552cc125ff7b41ba81220c2072db6a46848
Author: Jacques Lucke
Date:   Tue Apr 13 09:39:05 2021 +0200
Branches: master
https://developer.blender.org/rB9b15c552cc125ff7b41ba81220c2072db6a46848

DNA: support int8_t type in DNA structs

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

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

M	source/blender/makesdna/DNA_genfile.h
M	source/blender/makesdna/intern/dna_genfile.c
M	source/blender/makesdna/intern/dna_utils.c
M	source/blender/makesdna/intern/makesdna.c
M	source/blender/makesrna/RNA_define.h
M	source/blender/makesrna/intern/rna_define.c

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

diff --git a/source/blender/makesdna/DNA_genfile.h b/source/blender/makesdna/DNA_genfile.h
index 6fcbc53d47b..74d668a1081 100644
--- a/source/blender/makesdna/DNA_genfile.h
+++ b/source/blender/makesdna/DNA_genfile.h
@@ -63,6 +63,7 @@ typedef enum eSDNA_Type {
 #define SDNA_TYPE_VOID 9
   SDNA_TYPE_INT64 = 10,
   SDNA_TYPE_UINT64 = 11,
+  SDNA_TYPE_INT8 = 12,
 } eSDNA_Type;
 
 /**
diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c
index d199638710d..6c88d5f7230 100644
--- a/source/blender/makesdna/intern/dna_genfile.c
+++ b/source/blender/makesdna/intern/dna_genfile.c
@@ -792,6 +792,9 @@ static void cast_primitive_type(const eSDNA_Type old_type,
         old_value_i = *((uint64_t *)old_data);
         old_value_f = (double)old_value_i;
         break;
+      case SDNA_TYPE_INT8:
+        old_value_i = (uint64_t) * ((int8_t *)old_data);
+        old_value_f = (double)old_value_i;
     }
 
     switch (new_type) {
@@ -828,6 +831,9 @@ static void cast_primitive_type(const eSDNA_Type old_type,
       case SDNA_TYPE_UINT64:
         *((uint64_t *)new_data) = old_value_i;
         break;
+      case SDNA_TYPE_INT8:
+        *((int8_t *)new_data) = (int8_t)old_value_i;
+        break;
     }
 
     old_data += oldlen;
@@ -1655,6 +1661,7 @@ int DNA_elem_type_size(const eSDNA_Type elem_nr)
   switch (elem_nr) {
     case SDNA_TYPE_CHAR:
     case SDNA_TYPE_UCHAR:
+    case SDNA_TYPE_INT8:
       return 1;
     case SDNA_TYPE_SHORT:
     case SDNA_TYPE_USHORT:
diff --git a/source/blender/makesdna/intern/dna_utils.c b/source/blender/makesdna/intern/dna_utils.c
index 3cf5c52a4c6..f050934b5b3 100644
--- a/source/blender/makesdna/intern/dna_utils.c
+++ b/source/blender/makesdna/intern/dna_utils.c
@@ -235,9 +235,6 @@ void DNA_alias_maps(enum eDNA_RenameDir version_dir, GHash **r_struct_map, GHash
 
     if (version_dir == DNA_RENAME_STATIC_FROM_ALIAS) {
       const char *renames[][2] = {
-          /* Disable 'int8_t' until we support 'signed char', since changing negative
-           * values to a different type isn't supported and will change the value. */
-          /* {"int8_t", "char"}, */
           {"uint8_t", "uchar"},
           {"int16_t", "short"},
           {"uint16_t", "ushort"},
diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c
index 26fc56cfa1d..85bcc94c335 100644
--- a/source/blender/makesdna/intern/makesdna.c
+++ b/source/blender/makesdna/intern/makesdna.c
@@ -1222,6 +1222,7 @@ static int make_structDNA(const char *base_directory,
   add_type("int64_t", 8);  /* SDNA_TYPE_INT64 */
   add_type("uint64_t", 8); /* SDNA_TYPE_UINT64 */
   add_type("void", 0);     /* SDNA_TYPE_VOID */
+  add_type("int8_t", 1);   /* SDNA_TYPE_INT8 */
 
   /* the defines above shouldn't be output in the padding file... */
   const int firststruct = types_len;
@@ -1516,16 +1517,12 @@ int main(int argc, char **argv)
  *
  * - 'long': even though DNA supports, 'long' shouldn't be used since it can be either 32 or 64bit,
  *   use int, int32_t or int64_t instead.
- * - 'int8_t': as DNA doesn't yet support 'signed char' types,
- *   all char types are assumed to be unsigned.
- *   We should be able to support this, it's just not something which has been added yet.
  *
  * Only valid use would be as a runtime variable if an API expected a long,
  * but so far we don't have this happening.
  */
 #ifdef __GNUC__
 #  pragma GCC poison long
-#  pragma GCC poison int8_t
 #endif
 
 #include "DNA_ID.h"
diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h
index bc1a8f52b8d..17309d847bd 100644
--- a/source/blender/makesrna/RNA_define.h
+++ b/source/blender/makesrna/RNA_define.h
@@ -513,7 +513,7 @@ 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 || \
-   strcmp(_str, "uchar") == 0 || strcmp(_str, "ushort") == 0)
+   strcmp(_str, "uchar") == 0 || strcmp(_str, "ushort") == 0 || strcmp(_str, "int8_t") == 0)
 #define IS_DNATYPE_BOOLEAN_COMPAT(_str) \
   (IS_DNATYPE_INT_COMPAT(_str) || strcmp(_str, "int64_t") == 0 || strcmp(_str, "uint64_t") == 0)
 
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index 08f52be4257..2fdf7e5eaa7 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -2410,6 +2410,10 @@ void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const
       iprop->softmin = -10000; /* rather arbitrary .. */
       iprop->softmax = 10000;
     }
+    else if (dp->dnatype && STREQ(dp->dnatype, "int8_t")) {
+      iprop->hardmin = iprop->softmin = INT8_MIN;
+      iprop->hardmax = iprop->softmax = INT8_MAX;
+    }
 
     if (prop->subtype == PROP_UNSIGNED || prop->subtype == PROP_PERCENTAGE ||
         prop->subtype == PROP_FACTOR) {



More information about the Bf-blender-cvs mailing list