Cleanup: DNA code: sanitize naming.

Previous namings in makesdna code was very confusing and inconsistent.

This commit unifies names accross the codebase as such:
- `struct` for the structs definitions data.
- `type` for the types definitions data.
- `member` for the struct members definitions data.

Structs and types definitions are not in synced for two reasons:
- types contains also definitions for basic types (int, float, etc.).
- types can be discovered before their struct definition (as members of
  other structs).

This commit also groups all members of `SDNA` struct more logically (all
'structs' ones together, then all 'types' ones, then all 'struct
members' ones).

This commit should have no behavioral change at all.

Pull Request: https://projects.blender.org/blender/blender/pulls/125605
This commit is contained in:
Bastien Montagne
2024-07-22 18:11:17 +02:00
committed by Gitea
parent 09bae67c86
commit 2372bf1377
10 changed files with 1093 additions and 953 deletions

View File

@@ -1492,7 +1492,7 @@ static bool write_file_handle(Main *mainvar,
* *
* Note that we *borrow* the pointer to 'DNAstr', * Note that we *borrow* the pointer to 'DNAstr',
* so writing each time uses the same address and doesn't cause unnecessary undo overhead. */ * so writing each time uses the same address and doesn't cause unnecessary undo overhead. */
writedata(wd, BLO_CODE_DNA1, size_t(wd->sdna->data_len), wd->sdna->data); writedata(wd, BLO_CODE_DNA1, size_t(wd->sdna->data_size), wd->sdna->data);
/* End of file. */ /* End of file. */
memset(&bhead, 0, sizeof(BHead)); memset(&bhead, 0, sizeof(BHead));

View File

@@ -96,24 +96,24 @@ struct DNA_ReconstructInfo *DNA_reconstruct_info_create(const struct SDNA *oldsd
void DNA_reconstruct_info_free(struct DNA_ReconstructInfo *reconstruct_info); void DNA_reconstruct_info_free(struct DNA_ReconstructInfo *reconstruct_info);
/** /**
* \param index_last: Support faster lookups when there is the possibility * \param struct_index_last: Support faster lookups when there is the possibility
* of the same name being looked up multiple times. Initialize to `UINT_MAX`. * of the same name being looked up multiple times. Initialize to `UINT_MAX`.
* *
* \return the index of the struct or -1 on failure. * \return the index of the struct or -1 on failure.
*/ */
int DNA_struct_find_with_alias_ex(const struct SDNA *sdna, int DNA_struct_find_index_with_alias_ex(const struct SDNA *sdna,
const char *str, const char *str,
unsigned int *index_last); unsigned int *struct_index_last);
/** \note prefer #DNA_struct_find_with_alias_ex unless there is a good reason not to. */ /** \note prefer #DNA_struct_find_with_alias_ex unless there is a good reason not to. */
int DNA_struct_find_without_alias_ex(const struct SDNA *sdna, int DNA_struct_find_index_without_alias_ex(const struct SDNA *sdna,
const char *str, const char *str,
unsigned int *index_last); unsigned int *struct_index_last);
/** /**
* \return the index of the struct or -1 on failure. * \return the index of the struct or -1 on failure.
*/ */
int DNA_struct_find_with_alias(const struct SDNA *sdna, const char *str); int DNA_struct_find_with_alias(const struct SDNA *sdna, const char *str);
/** \note prefer #DNA_struct_find_with_alias unless there is a good reason not to. */ /** \note prefer #DNA_struct_find_with_alias unless there is a good reason not to. */
int DNA_struct_find_without_alias(const struct SDNA *sdna, const char *str); int DNA_struct_find_index_without_alias(const struct SDNA *sdna, const char *str);
/** /**
* A convenience function, the equivalent of: `DNA_struct_find_with_alias(..) != -1` * A convenience function, the equivalent of: `DNA_struct_find_with_alias(..) != -1`
@@ -141,7 +141,7 @@ bool DNA_struct_member_exists_without_alias(const struct SDNA *sdna,
* \param struct_nr: Index of struct info within sdna * \param struct_nr: Index of struct info within sdna
* \param data: Struct data that is to be converted * \param data: Struct data that is to be converted
*/ */
void DNA_struct_switch_endian(const struct SDNA *sdna, int struct_nr, char *data); void DNA_struct_switch_endian(const struct SDNA *sdna, int struct_index, char *data);
/** /**
* Constructs and returns an array of byte flags with one element for each struct in oldsdna, * Constructs and returns an array of byte flags with one element for each struct in oldsdna,
* indicating how it compares to newsdna. * indicating how it compares to newsdna.
@@ -149,14 +149,14 @@ void DNA_struct_switch_endian(const struct SDNA *sdna, int struct_nr, char *data
const char *DNA_struct_get_compareflags(const struct SDNA *sdna, const struct SDNA *newsdna); const char *DNA_struct_get_compareflags(const struct SDNA *sdna, const struct SDNA *newsdna);
/** /**
* \param reconstruct_info: Information preprocessed by #DNA_reconstruct_info_create. * \param reconstruct_info: Information preprocessed by #DNA_reconstruct_info_create.
* \param old_struct_nr: Index of struct info within oldsdna. * \param old_struct_index: Index of struct info within oldsdna.
* \param blocks: The number of array elements. * \param blocks: The number of array elements.
* \param old_blocks: Array of struct data. * \param old_blocks: Array of struct data.
* \param alloc_name: String to pass to the allocation calls for reconstructed data. * \param alloc_name: String to pass to the allocation calls for reconstructed data.
* \return An allocated reconstructed struct. * \return An allocated reconstructed struct.
*/ */
void *DNA_struct_reconstruct(const struct DNA_ReconstructInfo *reconstruct_info, void *DNA_struct_reconstruct(const struct DNA_ReconstructInfo *reconstruct_info,
int old_struct_nr, int old_struct_index,
int blocks, int blocks,
const void *old_blocks, const void *old_blocks,
const char *alloc_name); const char *alloc_name);
@@ -179,13 +179,13 @@ int DNA_struct_member_offset_by_name_with_alias(const struct SDNA *sdna,
const char *name); const char *name);
/** /**
* Returns the size of struct fields of the specified type and name. * Returns the size of struct fields of the specified type and member_index.
* *
* \param type: Index into sdna->types/types_size * \param type: Index into sdna->types/types_size
* \param name: Index into sdna->names, * \param member_index: Index into sdna->names, needed to extract possible pointer/array
* needed to extract possible pointer/array information. * information.
*/ */
int DNA_struct_member_size(const struct SDNA *sdna, short type, short name); int DNA_struct_member_size(const struct SDNA *sdna, short type, short member_index);
/** /**
* Returns the size in bytes of a primitive type. * Returns the size in bytes of a primitive type.
@@ -202,7 +202,7 @@ int DNA_struct_size(const struct SDNA *sdna, int struct_index);
/** /**
* Get the alignment that should be used when allocating memory for this type. * Get the alignment that should be used when allocating memory for this type.
*/ */
int DNA_struct_alignment(const struct SDNA *sdna, int struct_nr); int DNA_struct_alignment(const struct SDNA *sdna, int struct_index);
/** /**
* Return the current (alias) type name of the given struct index. * Return the current (alias) type name of the given struct index.
@@ -210,20 +210,28 @@ int DNA_struct_alignment(const struct SDNA *sdna, int struct_nr);
const char *DNA_struct_identifier(struct SDNA *sdna, int struct_index); const char *DNA_struct_identifier(struct SDNA *sdna, int struct_index);
/** /**
* Rename a struct * Find the struct matching the given `old_type_name`, and rename its type (referenced by its
* #SDNA_Struct.type_index) to the given `new_type_name`.
*
* WARNING: Deprecated, do not use in new code. Only used to version some renaming done during
* early 2.80 development.
*/ */
bool DNA_sdna_patch_struct_by_name(struct SDNA *sdna, bool DNA_sdna_patch_struct_by_name(struct SDNA *sdna,
const char *struct_name_old, const char *old_type_name,
const char *struct_name_new); const char *new_type_name);
/** /**
* Replace \a elem_old with \a elem_new for struct \a struct_name * Rename \a old_member_name with \a new_member_name for struct matching \a type_name.
* handles search & replace, maintaining surrounding non-identifier characters *
* such as pointer & array size. * Handles search & replace, maintaining surrounding non-identifier characters such as pointer &
* array size.
*
* WARNING: Deprecated, do not use in new code. Only used to version some renaming done during
* early 2.80 development.
*/ */
bool DNA_sdna_patch_struct_member_by_name(struct SDNA *sdna, bool DNA_sdna_patch_struct_member_by_name(struct SDNA *sdna,
const char *struct_name, const char *type_name,
const char *elem_old, const char *old_member_name,
const char *elem_new); const char *new_member_name);
void DNA_sdna_alias_data_ensure(struct SDNA *sdna); void DNA_sdna_alias_data_ensure(struct SDNA *sdna);

View File

@@ -23,7 +23,12 @@ typedef struct LinkData {
void *data; void *data;
} LinkData; } LinkData;
/** Never change the size of this! dna_genfile.cc detects pointer_size with it. */ /**
* The basic double linked-list structure.
*
* \warning Never change the size/definition of this struct! The #init_structDNA
* function (from dna_genfile.cc) uses it to compute the #pointer_size.
*/
typedef struct ListBase { typedef struct ListBase {
void *first, *last; void *first, *last;
} ListBase; } ListBase;

View File

@@ -15,9 +15,9 @@ typedef struct SDNA_StructMember {
/** This struct must not change, it's only a convenience view for raw data stored in SDNA. */ /** This struct must not change, it's only a convenience view for raw data stored in SDNA. */
/** An index into SDNA->types. */ /** An index into SDNA->types. */
short type; short type_index;
/** An index into SDNA->names. */ /** An index into SDNA->members. */
short name; short member_index;
} SDNA_StructMember; } SDNA_StructMember;
# #
@@ -26,9 +26,9 @@ typedef struct SDNA_Struct {
/** This struct must not change, it's only a convenience view for raw data stored in SDNA. */ /** This struct must not change, it's only a convenience view for raw data stored in SDNA. */
/** An index into SDNA->types. */ /** An index into SDNA->types. */
short type; short type_index;
/** The amount of members in this struct. */ /** The amount of members in this struct. */
short members_len; short members_num;
/** "Flexible array member" that contains information about all members of this struct. */ /** "Flexible array member" that contains information about all members of this struct. */
SDNA_StructMember members[]; SDNA_StructMember members[];
} SDNA_Struct; } SDNA_Struct;
@@ -36,57 +36,99 @@ typedef struct SDNA_Struct {
# #
# #
typedef struct SDNA { typedef struct SDNA {
/** Full copy of 'encoded' data (when data_alloc is set, otherwise borrowed). */ /** The 'encoded' data (full copy when #data_alloc is set, otherwise borrowed memory). */
const char *data; const char *data;
/** Length of data. */ /** Length of #data, in bytes. */
int data_len; int data_size;
bool data_alloc; bool data_alloc;
/** Total number of struct members. */
int names_len, names_len_alloc;
/** Struct member names. */
const char **names;
/** Result of #DNA_elem_array_size (aligned with #names). */
short *names_array_len;
/** Size of a pointer in bytes. */ /** Size of a pointer in bytes. */
int pointer_size; int pointer_size;
/* ***** Start of SDNA types. ***** */
/**
* This covers all known types (basic and structs ones) from SDNA.
*
* NOTE: This data is not in sync with the SDNA #structs info below. Among other things:
* - Basic types (int, float, etc.) have _no_ matching struct definitions currently.
* - Types can be discovered and added before their struct definition, when they are used for
* members of another struct which gets parsed first.
*/
/** Number of types. */
int types_num;
/** Type names. */ /** Type names. */
const char **types; const char **types;
/** Number of basic types + struct types. */
int types_len;
/** Type lengths. */ /** Type lengths. */
short *types_size; short *types_size;
/** Information about structs and their members. */
SDNA_Struct **structs;
/** Number of struct types. */
int structs_len;
/** #GHash for faster lookups, requires WITH_DNA_GHASH to be used for now. */
struct GHash *structs_map;
/** Temporary memory currently only used for version patching DNA. */
struct MemArena *mem_arena;
/** Runtime versions of data stored in DNA, lazy initialized,
* only different when renaming is done. */
struct {
/** Aligned with #SDNA.names, same pointers when unchanged. */
const char **names;
/** Aligned with #SDNA.types, same pointers when unchanged. */
const char **types;
/** A version of #SDNA.structs_map that uses #SDNA.alias.types for its keys. */
struct GHash *structs_map;
} alias;
/** /**
* Alignment used when allocating pointers to this type. The actual minimum alignment of the * Alignment used when allocating pointers to this type. The actual minimum alignment of the
* type may be lower in some cases. For example, the pointer alignment of a single char is at * type may be lower in some cases. For example, the pointer alignment of a single char is at
* least 8 bytes, but the alignment of the type itself is 1. * least 8 bytes, but the alignment of the type itself is 1.
*/ */
int *types_alignment; int *types_alignment;
/* ***** End of SDNA types. ***** */
/* ***** Start of SDNA structs. ***** */
/**
* This covers all known structs from SDNA (pointers to #SDNA_Struct data).
*
* NOTE: See comment above about SDNA types above for differences between structs and types
* definitions.
*/
/** Number of struct definitions. */
int structs_num;
/** Information about structs and their members. */
SDNA_Struct **structs;
/* ***** End of SDNA structs. ***** */
/* ***** Start of SDNA struct members. ***** */
/** Total number of struct members. */
int members_num;
/**
* Contains the number of allocated items in both #members and #members_array_num arrays below.
*
* Typically same as #members_len, unless after versionning DNA info (these arrays are
* reallocated by chunks, see #DNA_sdna_patch_struct_member).
*/
int members_num_alloc;
/** Struct member names. */
const char **members;
/**
* Aligned with #members. The total number of items in the array defined by the matching member,
* if any, otherwise 1.
*
* Result of #DNA_member_array_num.
*/
short *members_array_num;
/* ***** End of SDNA struct members. ***** */
/**
* Mapping between type names (from #types array above) and struct indices (into #structs array
* above).
*
* Requires WITH_DNA_GHASH to be used for now.
*/
struct GHash *types_to_structs_map;
/**
* Runtime versions of data stored in DNA, lazy initialized, only different when renaming is
* done.
*
* Contains mapping from original (static) types/members names to their current (alias)
* DNA-defined versions (i.e. results from calling #DNA_alias_maps with
* #DNA_RENAME_ALIAS_FROM_STATIC).
*/
struct {
/** Aligned with #SDNA.types, same pointers when unchanged. */
const char **types;
/** Aligned with #SDNA.members, same pointers when unchanged. */
const char **members;
/** A version of #SDNA.types_to_structs_map that uses #SDNA.alias.types for its keys. */
struct GHash *types_to_structs_map;
} alias;
/** Temporary memory currently only used for version patching DNA. */
struct MemArena *mem_arena;
} SDNA; } SDNA;
# #

View File

@@ -129,15 +129,15 @@ void DNA_sdna_free(SDNA *sdna)
MEM_freeN((void *)sdna->data); MEM_freeN((void *)sdna->data);
} }
MEM_freeN((void *)sdna->names); MEM_freeN((void *)sdna->members);
MEM_freeN((void *)sdna->names_array_len); MEM_freeN((void *)sdna->members_array_num);
MEM_freeN((void *)sdna->types); MEM_freeN((void *)sdna->types);
MEM_freeN(sdna->structs); MEM_freeN(sdna->structs);
MEM_freeN(sdna->types_alignment); MEM_freeN(sdna->types_alignment);
#ifdef WITH_DNA_GHASH #ifdef WITH_DNA_GHASH
if (sdna->structs_map) { if (sdna->types_to_structs_map) {
BLI_ghash_free(sdna->structs_map, nullptr, nullptr); BLI_ghash_free(sdna->types_to_structs_map, nullptr, nullptr);
} }
#endif #endif
@@ -145,11 +145,11 @@ void DNA_sdna_free(SDNA *sdna)
BLI_memarena_free(sdna->mem_arena); BLI_memarena_free(sdna->mem_arena);
} }
MEM_SAFE_FREE(sdna->alias.names); MEM_SAFE_FREE(sdna->alias.members);
MEM_SAFE_FREE(sdna->alias.types); MEM_SAFE_FREE(sdna->alias.types);
#ifdef WITH_DNA_GHASH #ifdef WITH_DNA_GHASH
if (sdna->alias.structs_map) { if (sdna->alias.types_to_structs_map) {
BLI_ghash_free(sdna->alias.structs_map, nullptr, nullptr); BLI_ghash_free(sdna->alias.types_to_structs_map, nullptr, nullptr);
} }
#endif #endif
@@ -158,7 +158,7 @@ void DNA_sdna_free(SDNA *sdna)
int DNA_struct_size(const SDNA *sdna, int struct_index) int DNA_struct_size(const SDNA *sdna, int struct_index)
{ {
return sdna->types_size[sdna->structs[struct_index]->type]; return sdna->types_size[sdna->structs[struct_index]->type_index];
} }
/** /**
@@ -170,30 +170,30 @@ static bool ispointer(const char *name)
return (name[0] == '*' || (name[0] == '(' && name[1] == '*')); return (name[0] == '*' || (name[0] == '(' && name[1] == '*'));
} }
int DNA_struct_member_size(const SDNA *sdna, short type, short name) int DNA_struct_member_size(const SDNA *sdna, short type, short member_index)
{ {
const char *cp = sdna->names[name]; const char *cp = sdna->members[member_index];
int len = 0; int len = 0;
/* is it a pointer or function pointer? */ /* is it a pointer or function pointer? */
if (ispointer(cp)) { if (ispointer(cp)) {
/* has the name an extra length? (array) */ /* has the name an extra length? (array) */
len = sdna->pointer_size * sdna->names_array_len[name]; len = sdna->pointer_size * sdna->members_array_num[member_index];
} }
else if (sdna->types_size[type]) { else if (sdna->types_size[type]) {
/* has the name an extra length? (array) */ /* has the name an extra length? (array) */
len = int(sdna->types_size[type]) * sdna->names_array_len[name]; len = int(sdna->types_size[type]) * sdna->members_array_num[member_index];
} }
return len; return len;
} }
#if 0 #if 0
static void printstruct(SDNA *sdna, short strnr) static void printstruct(SDNA *sdna, short struct_index)
{ {
/* is for debug */ /* is for debug */
SDNA_Struct *struct_info = sdna->structs[strnr]; SDNA_Struct *struct_info = sdna->structs[struct_index];
printf("struct %s\n", sdna->types[struct_info->type]); printf("struct %s\n", sdna->types[struct_info->type]);
for (int b = 0; b < struct_info->members_len; b++) { for (int b = 0; b < struct_info->members_len; b++) {
@@ -206,42 +206,42 @@ static void printstruct(SDNA *sdna, short strnr)
/** /**
* Returns the index of the struct info for the struct with the specified name. * Returns the index of the struct info for the struct with the specified name.
*/ */
static int dna_struct_find_nr_ex_impl( static int dna_struct_find_index_ex_impl(
/* From SDNA struct. */ /* From SDNA struct. */
const char **types, const char **types,
const int /*types_len*/, const int /*types_num*/,
SDNA_Struct **const structs, SDNA_Struct **const structs,
const int structs_len, const int structs_num,
#ifdef WITH_DNA_GHASH #ifdef WITH_DNA_GHASH
GHash *structs_map, GHash *structs_map,
#endif #endif
/* Regular args. */ /* Regular args. */
const char *str, const char *str,
uint *index_last) uint *struct_index_last)
{ {
if (*index_last < structs_len) { if (*struct_index_last < structs_num) {
const SDNA_Struct *struct_info = structs[*index_last]; const SDNA_Struct *struct_info = structs[*struct_index_last];
if (STREQ(types[struct_info->type], str)) { if (STREQ(types[struct_info->type_index], str)) {
return *index_last; return *struct_index_last;
} }
} }
#ifdef WITH_DNA_GHASH #ifdef WITH_DNA_GHASH
{ {
void **index_p = BLI_ghash_lookup_p(structs_map, str); void **struct_index_p = BLI_ghash_lookup_p(structs_map, str);
if (index_p) { if (struct_index_p) {
const int index = POINTER_AS_INT(*index_p); const int struct_index = POINTER_AS_INT(*struct_index_p);
*index_last = index; *struct_index_last = struct_index;
return index; return struct_index;
} }
} }
#else #else
{ {
for (int index = 0; index < structs_len; index++) { for (int struct_index = 0; struct_index < types_num; struct_index++) {
const SDNA_Struct *struct_info = structs[index]; const SDNA_Struct *struct_info = structs[struct_index];
if (STREQ(types[struct_info->type], str)) { if (STREQ(types[struct_info->type], str)) {
*index_last = index; *struct_index_last = struct_index;
return index; return struct_index;
} }
} }
} }
@@ -249,51 +249,56 @@ static int dna_struct_find_nr_ex_impl(
return -1; return -1;
} }
int DNA_struct_find_without_alias_ex(const SDNA *sdna, const char *str, uint *index_last) int DNA_struct_find_index_without_alias_ex(const SDNA *sdna,
const char *str,
uint *struct_index_last)
{ {
return dna_struct_find_nr_ex_impl( #ifdef WITH_DNA_GHASH
BLI_assert(sdna->types_to_structs_map != nullptr);
#endif
return dna_struct_find_index_ex_impl(
/* Expand SDNA. */ /* Expand SDNA. */
sdna->types, sdna->types,
sdna->types_len, sdna->types_num,
sdna->structs, sdna->structs,
sdna->structs_len, sdna->structs_num,
#ifdef WITH_DNA_GHASH #ifdef WITH_DNA_GHASH
sdna->structs_map, sdna->types_to_structs_map,
#endif #endif
/* Regular args. */ /* Regular args. */
str, str,
index_last); struct_index_last);
} }
int DNA_struct_find_with_alias_ex(const SDNA *sdna, const char *str, uint *index_last) int DNA_struct_find_index_with_alias_ex(const SDNA *sdna, const char *str, uint *struct_index_last)
{ {
#ifdef WITH_DNA_GHASH #ifdef WITH_DNA_GHASH
BLI_assert(sdna->alias.structs_map != nullptr); BLI_assert(sdna->alias.types_to_structs_map != nullptr);
#endif #endif
return dna_struct_find_nr_ex_impl( return dna_struct_find_index_ex_impl(
/* Expand SDNA. */ /* Expand SDNA. */
sdna->alias.types, sdna->alias.types,
sdna->types_len, sdna->types_num,
sdna->structs, sdna->structs,
sdna->structs_len, sdna->structs_num,
#ifdef WITH_DNA_GHASH #ifdef WITH_DNA_GHASH
sdna->alias.structs_map, sdna->alias.types_to_structs_map,
#endif #endif
/* Regular args. */ /* Regular args. */
str, str,
index_last); struct_index_last);
} }
int DNA_struct_find_without_alias(const SDNA *sdna, const char *str) int DNA_struct_find_index_without_alias(const SDNA *sdna, const char *str)
{ {
uint index_last_dummy = UINT_MAX; uint index_last_dummy = UINT_MAX;
return DNA_struct_find_without_alias_ex(sdna, str, &index_last_dummy); return DNA_struct_find_index_without_alias_ex(sdna, str, &index_last_dummy);
} }
int DNA_struct_find_with_alias(const SDNA *sdna, const char *str) int DNA_struct_find_with_alias(const SDNA *sdna, const char *str)
{ {
uint index_last_dummy = UINT_MAX; uint index_last_dummy = UINT_MAX;
return DNA_struct_find_with_alias_ex(sdna, str, &index_last_dummy); return DNA_struct_find_index_with_alias_ex(sdna, str, &index_last_dummy);
} }
bool DNA_struct_exists_with_alias(const SDNA *sdna, const char *str) bool DNA_struct_exists_with_alias(const SDNA *sdna, const char *str)
@@ -315,16 +320,16 @@ BLI_INLINE const char *pad_up_4(const char *ptr)
*/ */
static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error_message) static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error_message)
{ {
int gravity_fix = -1; int member_index_gravity_fix = -1;
int *data = (int *)sdna->data; int *data = (int *)sdna->data;
/* Clear pointers in case of error. */ /* Clear pointers in case of error. */
sdna->names = nullptr; sdna->members = nullptr;
sdna->types = nullptr; sdna->types = nullptr;
sdna->structs = nullptr; sdna->structs = nullptr;
#ifdef WITH_DNA_GHASH #ifdef WITH_DNA_GHASH
sdna->structs_map = nullptr; sdna->types_to_structs_map = nullptr;
#endif #endif
sdna->mem_arena = nullptr; sdna->mem_arena = nullptr;
@@ -344,15 +349,15 @@ static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error
if (*data == MAKE_ID('N', 'A', 'M', 'E')) { if (*data == MAKE_ID('N', 'A', 'M', 'E')) {
data++; data++;
sdna->names_len = *data; sdna->members_num = *data;
if (do_endian_swap) { if (do_endian_swap) {
BLI_endian_switch_int32(&sdna->names_len); BLI_endian_switch_int32(&sdna->members_num);
} }
sdna->names_len_alloc = sdna->names_len; sdna->members_num_alloc = sdna->members_num;
data++; data++;
sdna->names = static_cast<const char **>( sdna->members = static_cast<const char **>(
MEM_callocN(sizeof(void *) * sdna->names_len, "sdnanames")); MEM_callocN(sizeof(void *) * sdna->members_num, "sdnanames"));
} }
else { else {
*r_error_message = "NAME error in SDNA file"; *r_error_message = "NAME error in SDNA file";
@@ -360,16 +365,16 @@ static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error
} }
cp = (char *)data; cp = (char *)data;
for (int nr = 0; nr < sdna->names_len; nr++) { for (int member_index = 0; member_index < sdna->members_num; member_index++) {
sdna->names[nr] = cp; sdna->members[member_index] = cp;
/* "float gravity [3]" was parsed wrong giving both "gravity" and /* "float gravity [3]" was parsed wrong giving both "gravity" and
* "[3]" members. we rename "[3]", and later set the type of * "[3]" members. we rename "[3]", and later set the type of
* "gravity" to "void" so the offsets work out correct */ * "gravity" to "void" so the offsets work out correct */
if (*cp == '[' && STREQ(cp, "[3]")) { if (*cp == '[' && STREQ(cp, "[3]")) {
if (nr && STREQ(sdna->names[nr - 1], "Cvi")) { if (member_index && STREQ(sdna->members[member_index - 1], "Cvi")) {
sdna->names[nr] = "gravity[3]"; sdna->members[member_index] = "gravity[3]";
gravity_fix = nr; member_index_gravity_fix = member_index;
} }
} }
while (*cp) { while (*cp) {
@@ -385,14 +390,14 @@ static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error
if (*data == MAKE_ID('T', 'Y', 'P', 'E')) { if (*data == MAKE_ID('T', 'Y', 'P', 'E')) {
data++; data++;
sdna->types_len = *data; sdna->types_num = *data;
if (do_endian_swap) { if (do_endian_swap) {
BLI_endian_switch_int32(&sdna->types_len); BLI_endian_switch_int32(&sdna->types_num);
} }
data++; data++;
sdna->types = static_cast<const char **>( sdna->types = static_cast<const char **>(
MEM_callocN(sizeof(void *) * sdna->types_len, "sdnatypes")); MEM_callocN(sizeof(void *) * sdna->types_num, "sdnatypes"));
} }
else { else {
*r_error_message = "TYPE error in SDNA file"; *r_error_message = "TYPE error in SDNA file";
@@ -400,9 +405,9 @@ static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error
} }
cp = (char *)data; cp = (char *)data;
for (int nr = 0; nr < sdna->types_len; nr++) { for (int type_index = 0; type_index < sdna->types_num; type_index++) {
/* WARNING! See: DNA_struct_rename_legacy_hack_static_from_alias docs. */ /* WARNING! See: DNA_struct_rename_legacy_hack_static_from_alias docs. */
sdna->types[nr] = DNA_struct_rename_legacy_hack_static_from_alias(cp); sdna->types[type_index] = DNA_struct_rename_legacy_hack_static_from_alias(cp);
while (*cp) { while (*cp) {
cp++; cp++;
} }
@@ -420,17 +425,17 @@ static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error
sdna->types_size = sp; sdna->types_size = sp;
if (do_endian_swap) { if (do_endian_swap) {
BLI_endian_switch_int16_array(sp, sdna->types_len); BLI_endian_switch_int16_array(sp, sdna->types_num);
} }
sp += sdna->types_len; sp += sdna->types_num;
} }
else { else {
*r_error_message = "TLEN error in SDNA file"; *r_error_message = "TLEN error in SDNA file";
return false; return false;
} }
/* prevent BUS error */ /* prevent BUS error */
if (sdna->types_len & 1) { if (sdna->types_num & 1) {
sp++; sp++;
} }
@@ -439,14 +444,14 @@ static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error
if (*data == MAKE_ID('S', 'T', 'R', 'C')) { if (*data == MAKE_ID('S', 'T', 'R', 'C')) {
data++; data++;
sdna->structs_len = *data; sdna->structs_num = *data;
if (do_endian_swap) { if (do_endian_swap) {
BLI_endian_switch_int32(&sdna->structs_len); BLI_endian_switch_int32(&sdna->structs_num);
} }
data++; data++;
sdna->structs = static_cast<SDNA_Struct **>( sdna->structs = static_cast<SDNA_Struct **>(
MEM_callocN(sizeof(SDNA_Struct *) * sdna->structs_len, "sdnastrcs")); MEM_callocN(sizeof(SDNA_Struct *) * sdna->structs_num, "sdnastrcs"));
} }
else { else {
*r_error_message = "STRC error in SDNA file"; *r_error_message = "STRC error in SDNA file";
@@ -454,28 +459,28 @@ static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error
} }
sp = (short *)data; sp = (short *)data;
for (int nr = 0; nr < sdna->structs_len; nr++) { for (int struct_index = 0; struct_index < sdna->structs_num; struct_index++) {
SDNA_Struct *struct_info = (SDNA_Struct *)sp; SDNA_Struct *struct_info = (SDNA_Struct *)sp;
sdna->structs[nr] = struct_info; sdna->structs[struct_index] = struct_info;
if (do_endian_swap) { if (do_endian_swap) {
BLI_endian_switch_int16(&struct_info->type); BLI_endian_switch_int16(&struct_info->type_index);
BLI_endian_switch_int16(&struct_info->members_len); BLI_endian_switch_int16(&struct_info->members_num);
for (short a = 0; a < struct_info->members_len; a++) { for (short a = 0; a < struct_info->members_num; a++) {
SDNA_StructMember *member = &struct_info->members[a]; SDNA_StructMember *member = &struct_info->members[a];
BLI_endian_switch_int16(&member->type); BLI_endian_switch_int16(&member->type_index);
BLI_endian_switch_int16(&member->name); BLI_endian_switch_int16(&member->member_index);
} }
} }
sp += 2 + (sizeof(SDNA_StructMember) / sizeof(short)) * struct_info->members_len; sp += 2 + (sizeof(SDNA_StructMember) / sizeof(short)) * struct_info->members_num;
} }
{ {
/* second part of gravity problem, setting "gravity" type to void */ /* second part of gravity problem, setting "gravity" type to void */
if (gravity_fix > -1) { if (member_index_gravity_fix > -1) {
for (int nr = 0; nr < sdna->structs_len; nr++) { for (int struct_index = 0; struct_index < sdna->structs_num; struct_index++) {
sp = (short *)sdna->structs[nr]; sp = (short *)sdna->structs[struct_index];
if (STREQ(sdna->types[sp[0]], "ClothSimSettings")) { if (STREQ(sdna->types[sp[0]], "ClothSimSettings")) {
sp[10] = SDNA_TYPE_VOID; sp[10] = SDNA_TYPE_VOID;
} }
@@ -486,61 +491,72 @@ static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error
#ifdef WITH_DNA_GHASH #ifdef WITH_DNA_GHASH
{ {
/* create a ghash lookup to speed up */ /* create a ghash lookup to speed up */
sdna->structs_map = BLI_ghash_str_new_ex("init_structDNA gh", sdna->structs_len); sdna->types_to_structs_map = BLI_ghash_str_new_ex("init_structDNA gh", sdna->structs_num);
for (intptr_t nr = 0; nr < sdna->structs_len; nr++) { for (intptr_t struct_index = 0; struct_index < sdna->structs_num; struct_index++) {
SDNA_Struct *struct_info = sdna->structs[nr]; SDNA_Struct *struct_info = sdna->structs[struct_index];
BLI_ghash_insert( BLI_ghash_insert(sdna->types_to_structs_map,
sdna->structs_map, (void *)sdna->types[struct_info->type], POINTER_FROM_INT(nr)); (void *)sdna->types[struct_info->type_index],
POINTER_FROM_INT(struct_index));
} }
} }
#endif #endif
/* Calculate 'sdna->pointer_size' */ /* Calculate 'sdna->pointer_size'.
*
* NOTE: Cannot just do `sizeof(void *)` here, since the current DNA may come from a blendfile
* saved on a different system, using a different pointer size. So instead, use half the size of
* the #ListBase struct (only made of two pointers).
*/
{ {
const int nr = DNA_struct_find_without_alias(sdna, "ListBase"); const int struct_index = DNA_struct_find_index_without_alias(sdna, "ListBase");
/* should never happen, only with corrupt file for example */ /* Should never happen, only with corrupt file for example. */
if (UNLIKELY(nr == -1)) { if (UNLIKELY(struct_index == -1)) {
*r_error_message = "ListBase struct error! Not found."; *r_error_message = "ListBase struct error! Not found.";
return false; return false;
} }
/* finally pointer_size: use struct #ListBase to test it, never change the size of it! */ const SDNA_Struct *struct_info = sdna->structs[struct_index];
const SDNA_Struct *struct_info = sdna->structs[nr]; sdna->pointer_size = sdna->types_size[struct_info->type_index] / 2;
/* Weird; I have no memory of that... I think I used `sizeof(void *)` before... (ton). */
sdna->pointer_size = sdna->types_size[struct_info->type] / 2; /* Should never fail, double-check that #ListBase struct is still what is should be (akak a
* couple of pointers and nothing else). */
if (struct_info->members_len != 2 || !ELEM(sdna->pointer_size, 4, 8)) { if (UNLIKELY(struct_info->members_num != 2 || !ELEM(sdna->pointer_size, 4, 8))) {
*r_error_message = "ListBase struct error! Needs it to calculate pointer-size."; *r_error_message = "ListBase struct error: invalid computed pointer-size.";
/* Well, at least `sizeof(ListBase)` is error proof! (ton). */
return false; return false;
} }
} }
/* Cache name size. */ /* Cache name size. */
{ {
short *names_array_len = static_cast<short int *>( short *members_array_num = static_cast<short int *>(
MEM_mallocN(sizeof(*names_array_len) * sdna->names_len, __func__)); MEM_mallocN(sizeof(*members_array_num) * sdna->members_num, __func__));
for (int i = 0; i < sdna->names_len; i++) { for (int member_index = 0; member_index < sdna->members_num; member_index++) {
names_array_len[i] = DNA_elem_array_size(sdna->names[i]); members_array_num[member_index] = DNA_member_array_num(sdna->members[member_index]);
} }
sdna->names_array_len = names_array_len; sdna->members_array_num = members_array_num;
} }
sdna->types_alignment = static_cast<int *>( sdna->types_alignment = static_cast<int *>(
MEM_malloc_arrayN(sdna->types_len, sizeof(int), __func__)); MEM_malloc_arrayN(sdna->types_num, sizeof(int), __func__));
for (int i = 0; i < sdna->types_len; i++) { for (int type_index = 0; type_index < sdna->types_num; type_index++) {
sdna->types_alignment[i] = int(__STDCPP_DEFAULT_NEW_ALIGNMENT__); sdna->types_alignment[type_index] = int(__STDCPP_DEFAULT_NEW_ALIGNMENT__);
} }
{ {
/* TODO: This should be generalized at some point. We should be able to specify `overaligned` /* TODO: This should be generalized at some point. We should be able to specify `overaligned`
* types directly in the DNA struct definitions. */ * types directly in the DNA struct definitions. */
uint dummy_index = 0; uint dummy_index = 0;
const int mat4x4f_nr = DNA_struct_find_without_alias_ex(sdna, "mat4x4f", &dummy_index); const int mat4x4f_struct_index = DNA_struct_find_index_without_alias_ex(
if (mat4x4f_nr >= 0) { sdna, "mat4x4f", &dummy_index);
sdna->types_alignment[mat4x4f_nr] = alignof(blender::float4x4); if (mat4x4f_struct_index >= 0) {
#if 0 /* FIXME: This is using the wrong index. Code should be: */
SDNA_Struct *struct_info = sdna->structs[mat4x4f_struct_index];
const int mat4x4f_type_index = struct_info->type_index;
sdna->types_alignment[mat4x4f_type_index] = alignof(blender::float4x4);
#else
sdna->types_alignment[mat4x4f_struct_index] = alignof(blender::float4x4);
#endif
} }
} }
@@ -557,7 +573,7 @@ SDNA *DNA_sdna_from_data(const void *data,
SDNA *sdna = static_cast<SDNA *>(MEM_mallocN(sizeof(*sdna), "sdna")); SDNA *sdna = static_cast<SDNA *>(MEM_mallocN(sizeof(*sdna), "sdna"));
const char *error_message = nullptr; const char *error_message = nullptr;
sdna->data_len = data_len; sdna->data_size = data_len;
if (data_alloc) { if (data_alloc) {
char *data_copy = static_cast<char *>(MEM_mallocN(data_len, "sdna_data")); char *data_copy = static_cast<char *>(MEM_mallocN(data_len, "sdna_data"));
memcpy(data_copy, data, data_len); memcpy(data_copy, data, data_len);
@@ -629,9 +645,9 @@ static void set_compare_flags_for_struct(const SDNA *oldsdna,
} }
SDNA_Struct *old_struct = oldsdna->structs[old_struct_index]; SDNA_Struct *old_struct = oldsdna->structs[old_struct_index];
const char *struct_name = oldsdna->types[old_struct->type]; const char *struct_name = oldsdna->types[old_struct->type_index];
const int new_struct_index = DNA_struct_find_without_alias(newsdna, struct_name); const int new_struct_index = DNA_struct_find_index_without_alias(newsdna, struct_name);
if (new_struct_index == -1) { if (new_struct_index == -1) {
/* Didn't find a matching new struct, so it has been removed. */ /* Didn't find a matching new struct, so it has been removed. */
compare_flags[old_struct_index] = SDNA_CMP_REMOVED; compare_flags[old_struct_index] = SDNA_CMP_REMOVED;
@@ -639,32 +655,32 @@ static void set_compare_flags_for_struct(const SDNA *oldsdna,
} }
SDNA_Struct *new_struct = newsdna->structs[new_struct_index]; SDNA_Struct *new_struct = newsdna->structs[new_struct_index];
if (old_struct->members_len != new_struct->members_len) { if (old_struct->members_num != new_struct->members_num) {
/* Structs with a different amount of members are not equal. */ /* Structs with a different amount of members are not equal. */
compare_flags[old_struct_index] = SDNA_CMP_NOT_EQUAL; compare_flags[old_struct_index] = SDNA_CMP_NOT_EQUAL;
return; return;
} }
if (oldsdna->types_size[old_struct->type] != newsdna->types_size[new_struct->type]) { if (oldsdna->types_size[old_struct->type_index] != newsdna->types_size[new_struct->type_index]) {
/* Structs that don't have the same size are not equal. */ /* Structs that don't have the same size are not equal. */
compare_flags[old_struct_index] = SDNA_CMP_NOT_EQUAL; compare_flags[old_struct_index] = SDNA_CMP_NOT_EQUAL;
return; return;
} }
/* Compare each member individually. */ /* Compare each member individually. */
for (int member_index = 0; member_index < old_struct->members_len; member_index++) { for (int member_index = 0; member_index < old_struct->members_num; member_index++) {
const SDNA_StructMember *old_member = &old_struct->members[member_index]; const SDNA_StructMember *old_member = &old_struct->members[member_index];
const SDNA_StructMember *new_member = &new_struct->members[member_index]; const SDNA_StructMember *new_member = &new_struct->members[member_index];
const char *old_type_name = oldsdna->types[old_member->type]; const char *old_type_name = oldsdna->types[old_member->type_index];
const char *new_type_name = newsdna->types[new_member->type]; const char *new_type_name = newsdna->types[new_member->type_index];
if (!STREQ(old_type_name, new_type_name)) { if (!STREQ(old_type_name, new_type_name)) {
/* If two members have a different type in the same place, the structs are not equal. */ /* If two members have a different type in the same place, the structs are not equal. */
compare_flags[old_struct_index] = SDNA_CMP_NOT_EQUAL; compare_flags[old_struct_index] = SDNA_CMP_NOT_EQUAL;
return; return;
} }
const char *old_member_name = oldsdna->names[old_member->name]; const char *old_member_name = oldsdna->members[old_member->member_index];
const char *new_member_name = newsdna->names[new_member->name]; const char *new_member_name = newsdna->members[new_member->member_index];
if (!STREQ(old_member_name, new_member_name)) { if (!STREQ(old_member_name, new_member_name)) {
/* If two members have a different name in the same place, the structs are not equal. */ /* If two members have a different name in the same place, the structs are not equal. */
compare_flags[old_struct_index] = SDNA_CMP_NOT_EQUAL; compare_flags[old_struct_index] = SDNA_CMP_NOT_EQUAL;
@@ -680,7 +696,8 @@ static void set_compare_flags_for_struct(const SDNA *oldsdna,
} }
} }
else { else {
const int old_member_struct_index = DNA_struct_find_without_alias(oldsdna, old_type_name); const int old_member_struct_index = DNA_struct_find_index_without_alias(oldsdna,
old_type_name);
if (old_member_struct_index >= 0) { if (old_member_struct_index >= 0) {
set_compare_flags_for_struct(oldsdna, newsdna, compare_flags, old_member_struct_index); set_compare_flags_for_struct(oldsdna, newsdna, compare_flags, old_member_struct_index);
if (compare_flags[old_member_struct_index] != SDNA_CMP_EQUAL) { if (compare_flags[old_member_struct_index] != SDNA_CMP_EQUAL) {
@@ -697,18 +714,18 @@ static void set_compare_flags_for_struct(const SDNA *oldsdna,
const char *DNA_struct_get_compareflags(const SDNA *oldsdna, const SDNA *newsdna) const char *DNA_struct_get_compareflags(const SDNA *oldsdna, const SDNA *newsdna)
{ {
if (oldsdna->structs_len == 0) { if (oldsdna->structs_num == 0) {
printf("error: file without SDNA\n"); printf("error: file without SDNA\n");
return nullptr; return nullptr;
} }
char *compare_flags = static_cast<char *>(MEM_mallocN(oldsdna->structs_len, "compare flags")); char *compare_flags = static_cast<char *>(MEM_mallocN(oldsdna->structs_num, "compare flags"));
memset(compare_flags, SDNA_CMP_UNKNOWN, oldsdna->structs_len); memset(compare_flags, SDNA_CMP_UNKNOWN, oldsdna->structs_num);
/* Set correct flag for every struct. */ /* Set correct flag for every struct. */
for (int a = 0; a < oldsdna->structs_len; a++) { for (int old_struct_index = 0; old_struct_index < oldsdna->structs_num; old_struct_index++) {
set_compare_flags_for_struct(oldsdna, newsdna, compare_flags, a); set_compare_flags_for_struct(oldsdna, newsdna, compare_flags, old_struct_index);
BLI_assert(compare_flags[a] != SDNA_CMP_UNKNOWN); BLI_assert(compare_flags[old_struct_index] != SDNA_CMP_UNKNOWN);
} }
/* First struct is `struct Link`, this is skipped in compare_flags (at index `0`). /* First struct is `struct Link`, this is skipped in compare_flags (at index `0`).
@@ -926,10 +943,10 @@ static bool elem_exists_impl(
const SDNA_Struct *old) const SDNA_Struct *old)
{ {
/* in old is the old struct */ /* in old is the old struct */
for (int a = 0; a < old->members_len; a++) { for (int a = 0; a < old->members_num; a++) {
const SDNA_StructMember *member = &old->members[a]; const SDNA_StructMember *member = &old->members[a];
const char *otype = types[member->type]; const char *otype = types[member->type_index];
const char *oname = names[member->name]; const char *oname = names[member->member_index];
if (elem_streq(name, oname)) { /* name equal */ if (elem_streq(name, oname)) { /* name equal */
return STREQ(type, otype); /* type equal */ return STREQ(type, otype); /* type equal */
@@ -949,7 +966,7 @@ static bool elem_exists_without_alias(const SDNA *sdna,
return elem_exists_impl( return elem_exists_impl(
/* Expand SDNA. */ /* Expand SDNA. */
sdna->types, sdna->types,
sdna->names, sdna->members,
/* Regular args. */ /* Regular args. */
type, type,
name, name,
@@ -964,7 +981,7 @@ static bool elem_exists_with_alias(const SDNA *sdna,
return elem_exists_impl( return elem_exists_impl(
/* Expand SDNA. */ /* Expand SDNA. */
sdna->alias.types, sdna->alias.types,
sdna->alias.names, sdna->alias.members,
/* Regular args. */ /* Regular args. */
type, type,
name, name,
@@ -982,17 +999,17 @@ static int elem_offset_impl(const SDNA *sdna,
/* in old is the old struct */ /* in old is the old struct */
int offset = 0; int offset = 0;
for (int a = 0; a < old->members_len; a++) { for (int a = 0; a < old->members_num; a++) {
const SDNA_StructMember *member = &old->members[a]; const SDNA_StructMember *member = &old->members[a];
const char *otype = types[member->type]; const char *otype = types[member->type_index];
const char *oname = names[member->name]; const char *oname = names[member->member_index];
if (elem_streq(name, oname)) { /* name equal */ if (elem_streq(name, oname)) { /* name equal */
if (STREQ(type, otype)) { /* type equal */ if (STREQ(type, otype)) { /* type equal */
return offset; return offset;
} }
break; /* Fail below. */ break; /* Fail below. */
} }
offset += DNA_struct_member_size(sdna, member->type, member->name); offset += DNA_struct_member_size(sdna, member->type_index, member->member_index);
} }
return -1; return -1;
} }
@@ -1017,7 +1034,7 @@ static int elem_offset_without_alias(const SDNA *sdna,
const char *name, const char *name,
const SDNA_Struct *old) const SDNA_Struct *old)
{ {
return elem_offset_impl(sdna, sdna->types, sdna->names, type, name, old); return elem_offset_impl(sdna, sdna->types, sdna->members, type, name, old);
} }
/** /**
@@ -1028,7 +1045,7 @@ static int elem_offset_with_alias(const SDNA *sdna,
const char *name, const char *name,
const SDNA_Struct *old) const SDNA_Struct *old)
{ {
return elem_offset_impl(sdna, sdna->alias.types, sdna->alias.names, type, name, old); return elem_offset_impl(sdna, sdna->alias.types, sdna->alias.members, type, name, old);
} }
/* Each struct member belongs to one of the categories below. */ /* Each struct member belongs to one of the categories below. */
@@ -1041,11 +1058,11 @@ enum eStructMemberCategory {
static eStructMemberCategory get_struct_member_category(const SDNA *sdna, static eStructMemberCategory get_struct_member_category(const SDNA *sdna,
const SDNA_StructMember *member) const SDNA_StructMember *member)
{ {
const char *member_name = sdna->names[member->name]; const char *member_name = sdna->members[member->member_index];
if (ispointer(member_name)) { if (ispointer(member_name)) {
return STRUCT_MEMBER_CATEGORY_POINTER; return STRUCT_MEMBER_CATEGORY_POINTER;
} }
const char *member_type_name = sdna->types[member->type]; const char *member_type_name = sdna->types[member->type_index];
if (DNA_struct_exists_without_alias(sdna, member_type_name)) { if (DNA_struct_exists_without_alias(sdna, member_type_name)) {
return STRUCT_MEMBER_CATEGORY_STRUCT; return STRUCT_MEMBER_CATEGORY_STRUCT;
} }
@@ -1054,43 +1071,43 @@ static eStructMemberCategory get_struct_member_category(const SDNA *sdna,
static int get_member_size_in_bytes(const SDNA *sdna, const SDNA_StructMember *member) static int get_member_size_in_bytes(const SDNA *sdna, const SDNA_StructMember *member)
{ {
const char *name = sdna->names[member->name]; const char *name = sdna->members[member->member_index];
const int array_length = sdna->names_array_len[member->name]; const int array_length = sdna->members_array_num[member->member_index];
if (ispointer(name)) { if (ispointer(name)) {
return sdna->pointer_size * array_length; return sdna->pointer_size * array_length;
} }
const int type_size = sdna->types_size[member->type]; const int type_size = sdna->types_size[member->type_index];
return type_size * array_length; return type_size * array_length;
} }
void DNA_struct_switch_endian(const SDNA *sdna, int struct_nr, char *data) void DNA_struct_switch_endian(const SDNA *sdna, int struct_index, char *data)
{ {
if (struct_nr == -1) { if (struct_index == -1) {
return; return;
} }
const SDNA_Struct *struct_info = sdna->structs[struct_nr]; const SDNA_Struct *struct_info = sdna->structs[struct_index];
int offset_in_bytes = 0; int offset_in_bytes = 0;
for (int member_index = 0; member_index < struct_info->members_len; member_index++) { for (int member_index = 0; member_index < struct_info->members_num; member_index++) {
const SDNA_StructMember *member = &struct_info->members[member_index]; const SDNA_StructMember *member = &struct_info->members[member_index];
const eStructMemberCategory member_category = get_struct_member_category(sdna, member); const eStructMemberCategory member_category = get_struct_member_category(sdna, member);
char *member_data = data + offset_in_bytes; char *member_data = data + offset_in_bytes;
const char *member_type_name = sdna->types[member->type]; const char *member_type_name = sdna->types[member->type_index];
const int member_array_length = sdna->names_array_len[member->name]; const int member_array_length = sdna->members_array_num[member->member_index];
switch (member_category) { switch (member_category) {
case STRUCT_MEMBER_CATEGORY_STRUCT: { case STRUCT_MEMBER_CATEGORY_STRUCT: {
const int substruct_size = sdna->types_size[member->type]; const int substruct_size = sdna->types_size[member->type_index];
const int substruct_nr = DNA_struct_find_without_alias(sdna, member_type_name); const int substruct_index = DNA_struct_find_index_without_alias(sdna, member_type_name);
BLI_assert(substruct_nr != -1); BLI_assert(substruct_index != -1);
for (int a = 0; a < member_array_length; a++) { for (int a = 0; a < member_array_length; a++) {
DNA_struct_switch_endian(sdna, substruct_nr, member_data + a * substruct_size); DNA_struct_switch_endian(sdna, substruct_index, member_data + a * substruct_size);
} }
break; break;
} }
case STRUCT_MEMBER_CATEGORY_PRIMITIVE: { case STRUCT_MEMBER_CATEGORY_PRIMITIVE: {
switch (member->type) { switch (member->type_index) {
case SDNA_TYPE_SHORT: case SDNA_TYPE_SHORT:
case SDNA_TYPE_USHORT: { case SDNA_TYPE_USHORT: {
BLI_endian_switch_int16_array((int16_t *)member_data, member_array_length); BLI_endian_switch_int16_array((int16_t *)member_data, member_array_length);
@@ -1164,8 +1181,8 @@ struct ReconstructStep {
int old_offset; int old_offset;
int new_offset; int new_offset;
int array_len; int array_len;
short old_struct_nr; short old_struct_index;
short new_struct_nr; short new_struct_index;
} substruct; } substruct;
} data; } data;
}; };
@@ -1196,12 +1213,12 @@ static void reconstruct_structs(const DNA_ReconstructInfo *reconstruct_info,
* \param new_block: Where to put converted struct contents. * \param new_block: Where to put converted struct contents.
*/ */
static void reconstruct_struct(const DNA_ReconstructInfo *reconstruct_info, static void reconstruct_struct(const DNA_ReconstructInfo *reconstruct_info,
const int new_struct_nr, const int new_struct_index,
const char *old_block, const char *old_block,
char *new_block) char *new_block)
{ {
const ReconstructStep *steps = reconstruct_info->steps[new_struct_nr]; const ReconstructStep *steps = reconstruct_info->steps[new_struct_index];
const int step_count = reconstruct_info->step_counts[new_struct_nr]; const int step_count = reconstruct_info->step_counts[new_struct_index];
/* Execute all preprocessed steps. */ /* Execute all preprocessed steps. */
for (int a = 0; a < step_count; a++) { for (int a = 0; a < step_count; a++) {
@@ -1232,8 +1249,8 @@ static void reconstruct_struct(const DNA_ReconstructInfo *reconstruct_info,
case RECONSTRUCT_STEP_SUBSTRUCT: case RECONSTRUCT_STEP_SUBSTRUCT:
reconstruct_structs(reconstruct_info, reconstruct_structs(reconstruct_info,
step->data.substruct.array_len, step->data.substruct.array_len,
step->data.substruct.old_struct_nr, step->data.substruct.old_struct_index,
step->data.substruct.new_struct_nr, step->data.substruct.new_struct_index,
old_block + step->data.substruct.old_offset, old_block + step->data.substruct.old_offset,
new_block + step->data.substruct.new_offset); new_block + step->data.substruct.new_offset);
break; break;
@@ -1250,26 +1267,26 @@ static void reconstruct_struct(const DNA_ReconstructInfo *reconstruct_info,
/** Reconstructs an array of structs. */ /** Reconstructs an array of structs. */
static void reconstruct_structs(const DNA_ReconstructInfo *reconstruct_info, static void reconstruct_structs(const DNA_ReconstructInfo *reconstruct_info,
const int blocks, const int blocks,
const int old_struct_nr, const int old_struct_index,
const int new_struct_nr, const int new_struct_index,
const char *old_blocks, const char *old_blocks,
char *new_blocks) char *new_blocks)
{ {
const SDNA_Struct *old_struct = reconstruct_info->oldsdna->structs[old_struct_nr]; const SDNA_Struct *old_struct = reconstruct_info->oldsdna->structs[old_struct_index];
const SDNA_Struct *new_struct = reconstruct_info->newsdna->structs[new_struct_nr]; const SDNA_Struct *new_struct = reconstruct_info->newsdna->structs[new_struct_index];
const int old_block_size = reconstruct_info->oldsdna->types_size[old_struct->type]; const int old_block_size = reconstruct_info->oldsdna->types_size[old_struct->type_index];
const int new_block_size = reconstruct_info->newsdna->types_size[new_struct->type]; const int new_block_size = reconstruct_info->newsdna->types_size[new_struct->type_index];
for (int a = 0; a < blocks; a++) { for (int a = 0; a < blocks; a++) {
const char *old_block = old_blocks + a * old_block_size; const char *old_block = old_blocks + a * old_block_size;
char *new_block = new_blocks + a * new_block_size; char *new_block = new_blocks + a * new_block_size;
reconstruct_struct(reconstruct_info, new_struct_nr, old_block, new_block); reconstruct_struct(reconstruct_info, new_struct_index, old_block, new_block);
} }
} }
void *DNA_struct_reconstruct(const DNA_ReconstructInfo *reconstruct_info, void *DNA_struct_reconstruct(const DNA_ReconstructInfo *reconstruct_info,
int old_struct_nr, int old_struct_index,
int blocks, int blocks,
const void *old_blocks, const void *old_blocks,
const char *alloc_name) const char *alloc_name)
@@ -1277,24 +1294,24 @@ void *DNA_struct_reconstruct(const DNA_ReconstructInfo *reconstruct_info,
const SDNA *oldsdna = reconstruct_info->oldsdna; const SDNA *oldsdna = reconstruct_info->oldsdna;
const SDNA *newsdna = reconstruct_info->newsdna; const SDNA *newsdna = reconstruct_info->newsdna;
const SDNA_Struct *old_struct = oldsdna->structs[old_struct_nr]; const SDNA_Struct *old_struct = oldsdna->structs[old_struct_index];
const char *type_name = oldsdna->types[old_struct->type]; const char *type_name = oldsdna->types[old_struct->type_index];
const int new_struct_nr = DNA_struct_find_without_alias(newsdna, type_name); const int new_struct_index = DNA_struct_find_index_without_alias(newsdna, type_name);
if (new_struct_nr == -1) { if (new_struct_index == -1) {
return nullptr; return nullptr;
} }
const SDNA_Struct *new_struct = newsdna->structs[new_struct_nr]; const SDNA_Struct *new_struct = newsdna->structs[new_struct_index];
const int new_block_size = newsdna->types_size[new_struct->type]; const int new_block_size = newsdna->types_size[new_struct->type_index];
const int alignment = DNA_struct_alignment(newsdna, new_struct_nr); const int alignment = DNA_struct_alignment(newsdna, new_struct_index);
char *new_blocks = static_cast<char *>( char *new_blocks = static_cast<char *>(
MEM_calloc_arrayN_aligned(new_block_size, blocks, alignment, alloc_name)); MEM_calloc_arrayN_aligned(new_block_size, blocks, alignment, alloc_name));
reconstruct_structs(reconstruct_info, reconstruct_structs(reconstruct_info,
blocks, blocks,
old_struct_nr, old_struct_index,
new_struct_nr, new_struct_index,
static_cast<const char *>(old_blocks), static_cast<const char *>(old_blocks),
new_blocks); new_blocks);
return new_blocks; return new_blocks;
@@ -1307,9 +1324,9 @@ static const SDNA_StructMember *find_member_with_matching_name(const SDNA *sdna,
int *r_offset) int *r_offset)
{ {
int offset = 0; int offset = 0;
for (int a = 0; a < struct_info->members_len; a++) { for (int a = 0; a < struct_info->members_num; a++) {
const SDNA_StructMember *member = &struct_info->members[a]; const SDNA_StructMember *member = &struct_info->members[a];
const char *member_name = sdna->names[member->name]; const char *member_name = sdna->members[member->member_index];
if (elem_streq(name, member_name)) { if (elem_streq(name, member_name)) {
*r_offset = offset; *r_offset = offset;
return member; return member;
@@ -1331,7 +1348,7 @@ static void init_reconstruct_step_for_member(const SDNA *oldsdna,
/* Find the matching old member. */ /* Find the matching old member. */
int old_member_offset; int old_member_offset;
const char *new_name = newsdna->names[new_member->name]; const char *new_name = newsdna->members[new_member->member_index];
const SDNA_StructMember *old_member = find_member_with_matching_name( const SDNA_StructMember *old_member = find_member_with_matching_name(
oldsdna, old_struct, new_name, &old_member_offset); oldsdna, old_struct, new_name, &old_member_offset);
@@ -1352,30 +1369,32 @@ static void init_reconstruct_step_for_member(const SDNA *oldsdna,
return; return;
} }
const int new_array_length = newsdna->names_array_len[new_member->name]; const int new_array_length = newsdna->members_array_num[new_member->member_index];
const int old_array_length = oldsdna->names_array_len[old_member->name]; const int old_array_length = oldsdna->members_array_num[old_member->member_index];
const int shared_array_length = std::min(new_array_length, old_array_length); const int shared_array_length = std::min(new_array_length, old_array_length);
const char *new_type_name = newsdna->types[new_member->type]; const char *new_type_name = newsdna->types[new_member->type_index];
const char *old_type_name = oldsdna->types[old_member->type]; const char *old_type_name = oldsdna->types[old_member->type_index];
switch (new_category) { switch (new_category) {
case STRUCT_MEMBER_CATEGORY_STRUCT: { case STRUCT_MEMBER_CATEGORY_STRUCT: {
if (STREQ(new_type_name, old_type_name)) { if (STREQ(new_type_name, old_type_name)) {
const int old_struct_nr = DNA_struct_find_without_alias(oldsdna, old_type_name); const int old_struct_index = DNA_struct_find_index_without_alias(oldsdna, old_type_name);
BLI_assert(old_struct_nr != -1); BLI_assert(old_struct_index != -1);
enum eSDNA_StructCompare compare_flag = eSDNA_StructCompare(compare_flags[old_struct_nr]); enum eSDNA_StructCompare compare_flag = eSDNA_StructCompare(
compare_flags[old_struct_index]);
BLI_assert(compare_flag != SDNA_CMP_REMOVED); BLI_assert(compare_flag != SDNA_CMP_REMOVED);
if (compare_flag == SDNA_CMP_EQUAL) { if (compare_flag == SDNA_CMP_EQUAL) {
/* The old and new members are identical, just do a #memcpy. */ /* The old and new members are identical, just do a #memcpy. */
r_step->type = RECONSTRUCT_STEP_MEMCPY; r_step->type = RECONSTRUCT_STEP_MEMCPY;
r_step->data.memcpy.new_offset = new_member_offset; r_step->data.memcpy.new_offset = new_member_offset;
r_step->data.memcpy.old_offset = old_member_offset; r_step->data.memcpy.old_offset = old_member_offset;
r_step->data.memcpy.size = newsdna->types_size[new_member->type] * shared_array_length; r_step->data.memcpy.size = newsdna->types_size[new_member->type_index] *
shared_array_length;
} }
else { else {
const int new_struct_nr = DNA_struct_find_without_alias(newsdna, new_type_name); const int new_struct_index = DNA_struct_find_index_without_alias(newsdna, new_type_name);
BLI_assert(new_struct_nr != -1); BLI_assert(new_struct_index != -1);
/* The old and new members are different, use recursion to reconstruct the /* The old and new members are different, use recursion to reconstruct the
* nested struct. */ * nested struct. */
@@ -1384,8 +1403,8 @@ static void init_reconstruct_step_for_member(const SDNA *oldsdna,
r_step->data.substruct.new_offset = new_member_offset; r_step->data.substruct.new_offset = new_member_offset;
r_step->data.substruct.old_offset = old_member_offset; r_step->data.substruct.old_offset = old_member_offset;
r_step->data.substruct.array_len = shared_array_length; r_step->data.substruct.array_len = shared_array_length;
r_step->data.substruct.new_struct_nr = new_struct_nr; r_step->data.substruct.new_struct_index = new_struct_index;
r_step->data.substruct.old_struct_nr = old_struct_nr; r_step->data.substruct.old_struct_index = old_struct_index;
} }
} }
else { else {
@@ -1400,7 +1419,8 @@ static void init_reconstruct_step_for_member(const SDNA *oldsdna,
r_step->type = RECONSTRUCT_STEP_MEMCPY; r_step->type = RECONSTRUCT_STEP_MEMCPY;
r_step->data.memcpy.new_offset = new_member_offset; r_step->data.memcpy.new_offset = new_member_offset;
r_step->data.memcpy.old_offset = old_member_offset; r_step->data.memcpy.old_offset = old_member_offset;
r_step->data.memcpy.size = newsdna->types_size[new_member->type] * shared_array_length; r_step->data.memcpy.size = newsdna->types_size[new_member->type_index] *
shared_array_length;
} }
else { else {
/* The old and new primitive types are different, cast from the old to new type. */ /* The old and new primitive types are different, cast from the old to new type. */
@@ -1408,8 +1428,8 @@ static void init_reconstruct_step_for_member(const SDNA *oldsdna,
r_step->data.cast_primitive.array_len = shared_array_length; r_step->data.cast_primitive.array_len = shared_array_length;
r_step->data.cast_primitive.new_offset = new_member_offset; r_step->data.cast_primitive.new_offset = new_member_offset;
r_step->data.cast_primitive.old_offset = old_member_offset; r_step->data.cast_primitive.old_offset = old_member_offset;
r_step->data.cast_primitive.new_type = eSDNA_Type(new_member->type); r_step->data.cast_primitive.new_type = eSDNA_Type(new_member->type_index);
r_step->data.cast_primitive.old_type = eSDNA_Type(old_member->type); r_step->data.cast_primitive.old_type = eSDNA_Type(old_member->type_index);
} }
break; break;
} }
@@ -1494,9 +1514,9 @@ static void init_reconstruct_step_for_member(const SDNA *oldsdna,
"length: %d", "length: %d",
step->data.substruct.old_offset, step->data.substruct.old_offset,
step->data.substruct.new_offset, step->data.substruct.new_offset,
step->data.substruct.new_struct_nr, step->data.substruct.new_struct_index,
newsdna->types[newsdna->structs[step->data.substruct.new_struct_nr]->type], newsdna->types[newsdna->structs[step->data.substruct.new_struct_index]->type_index],
newsdna->types_size[newsdna->structs[step->data.substruct.new_struct_nr]->type], newsdna->types_size[newsdna->structs[step->data.substruct.new_struct_index]->type_index],
step->data.substruct.array_len); step->data.substruct.array_len);
break; break;
} }
@@ -1514,10 +1534,10 @@ static ReconstructStep *create_reconstruct_steps_for_struct(const SDNA *oldsdna,
const SDNA_Struct *new_struct) const SDNA_Struct *new_struct)
{ {
ReconstructStep *steps = static_cast<ReconstructStep *>( ReconstructStep *steps = static_cast<ReconstructStep *>(
MEM_calloc_arrayN(new_struct->members_len, sizeof(ReconstructStep), __func__)); MEM_calloc_arrayN(new_struct->members_num, sizeof(ReconstructStep), __func__));
int new_member_offset = 0; int new_member_offset = 0;
for (int new_member_index = 0; new_member_index < new_struct->members_len; new_member_index++) { for (int new_member_index = 0; new_member_index < new_struct->members_num; new_member_index++) {
const SDNA_StructMember *new_member = &new_struct->members[new_member_index]; const SDNA_StructMember *new_member = &new_struct->members[new_member_index];
init_reconstruct_step_for_member(oldsdna, init_reconstruct_step_for_member(oldsdna,
newsdna, newsdna,
@@ -1585,29 +1605,29 @@ DNA_ReconstructInfo *DNA_reconstruct_info_create(const SDNA *oldsdna,
reconstruct_info->newsdna = newsdna; reconstruct_info->newsdna = newsdna;
reconstruct_info->compare_flags = compare_flags; reconstruct_info->compare_flags = compare_flags;
reconstruct_info->step_counts = static_cast<int *>( reconstruct_info->step_counts = static_cast<int *>(
MEM_malloc_arrayN(newsdna->structs_len, sizeof(int), __func__)); MEM_malloc_arrayN(newsdna->structs_num, sizeof(int), __func__));
reconstruct_info->steps = static_cast<ReconstructStep **>( reconstruct_info->steps = static_cast<ReconstructStep **>(
MEM_malloc_arrayN(newsdna->structs_len, sizeof(ReconstructStep *), __func__)); MEM_malloc_arrayN(newsdna->structs_num, sizeof(ReconstructStep *), __func__));
/* Generate reconstruct steps for all structs. */ /* Generate reconstruct steps for all structs. */
for (int new_struct_nr = 0; new_struct_nr < newsdna->structs_len; new_struct_nr++) { for (int new_struct_index = 0; new_struct_index < newsdna->structs_num; new_struct_index++) {
const SDNA_Struct *new_struct = newsdna->structs[new_struct_nr]; const SDNA_Struct *new_struct = newsdna->structs[new_struct_index];
const char *new_struct_name = newsdna->types[new_struct->type]; const char *new_struct_name = newsdna->types[new_struct->type_index];
const int old_struct_nr = DNA_struct_find_without_alias(oldsdna, new_struct_name); const int old_struct_index = DNA_struct_find_index_without_alias(oldsdna, new_struct_name);
if (old_struct_nr < 0) { if (old_struct_index < 0) {
reconstruct_info->steps[new_struct_nr] = nullptr; reconstruct_info->steps[new_struct_index] = nullptr;
reconstruct_info->step_counts[new_struct_nr] = 0; reconstruct_info->step_counts[new_struct_index] = 0;
continue; continue;
} }
const SDNA_Struct *old_struct = oldsdna->structs[old_struct_nr]; const SDNA_Struct *old_struct = oldsdna->structs[old_struct_index];
ReconstructStep *steps = create_reconstruct_steps_for_struct( ReconstructStep *steps = create_reconstruct_steps_for_struct(
oldsdna, newsdna, compare_flags, old_struct, new_struct); oldsdna, newsdna, compare_flags, old_struct, new_struct);
/* Comment the line below to skip the compression for debugging purposes. */ /* Comment the line below to skip the compression for debugging purposes. */
const int steps_len = compress_reconstruct_steps(steps, new_struct->members_len); const int steps_len = compress_reconstruct_steps(steps, new_struct->members_num);
reconstruct_info->steps[new_struct_nr] = steps; reconstruct_info->steps[new_struct_index] = steps;
reconstruct_info->step_counts[new_struct_nr] = steps_len; reconstruct_info->step_counts[new_struct_index] = steps_len;
/* This is useful when debugging the reconstruct steps. */ /* This is useful when debugging the reconstruct steps. */
#if 0 #if 0
@@ -1625,9 +1645,11 @@ DNA_ReconstructInfo *DNA_reconstruct_info_create(const SDNA *oldsdna,
void DNA_reconstruct_info_free(DNA_ReconstructInfo *reconstruct_info) void DNA_reconstruct_info_free(DNA_ReconstructInfo *reconstruct_info)
{ {
for (int a = 0; a < reconstruct_info->newsdna->structs_len; a++) { for (int new_struct_index = 0; new_struct_index < reconstruct_info->newsdna->structs_num;
if (reconstruct_info->steps[a] != nullptr) { new_struct_index++)
MEM_freeN(reconstruct_info->steps[a]); {
if (reconstruct_info->steps[new_struct_index] != nullptr) {
MEM_freeN(reconstruct_info->steps[new_struct_index]);
} }
} }
MEM_freeN(reconstruct_info->steps); MEM_freeN(reconstruct_info->steps);
@@ -1640,10 +1662,10 @@ int DNA_struct_member_offset_by_name_without_alias(const SDNA *sdna,
const char *vartype, const char *vartype,
const char *name) const char *name)
{ {
const int SDNAnr = DNA_struct_find_without_alias(sdna, stype); const int struct_index = DNA_struct_find_index_without_alias(sdna, stype);
BLI_assert(SDNAnr != -1); BLI_assert(struct_index != -1);
const SDNA_Struct *const spo = sdna->structs[SDNAnr]; const SDNA_Struct *const struct_info = sdna->structs[struct_index];
return elem_offset_without_alias(sdna, vartype, name, spo); return elem_offset_without_alias(sdna, vartype, name, struct_info);
} }
int DNA_struct_member_offset_by_name_with_alias(const SDNA *sdna, int DNA_struct_member_offset_by_name_with_alias(const SDNA *sdna,
@@ -1651,15 +1673,15 @@ int DNA_struct_member_offset_by_name_with_alias(const SDNA *sdna,
const char *vartype, const char *vartype,
const char *name) const char *name)
{ {
const int SDNAnr = DNA_struct_find_with_alias(sdna, stype); const int struct_index = DNA_struct_find_with_alias(sdna, stype);
BLI_assert(SDNAnr != -1); BLI_assert(struct_index != -1);
const SDNA_Struct *const spo = sdna->structs[SDNAnr]; const SDNA_Struct *const struct_info = sdna->structs[struct_index];
return elem_offset_with_alias(sdna, vartype, name, spo); return elem_offset_with_alias(sdna, vartype, name, struct_info);
} }
bool DNA_struct_exists_without_alias(const SDNA *sdna, const char *stype) bool DNA_struct_exists_without_alias(const SDNA *sdna, const char *stype)
{ {
return DNA_struct_find_without_alias(sdna, stype) != -1; return DNA_struct_find_index_without_alias(sdna, stype) != -1;
} }
bool DNA_struct_member_exists_without_alias(const SDNA *sdna, bool DNA_struct_member_exists_without_alias(const SDNA *sdna,
@@ -1667,11 +1689,11 @@ bool DNA_struct_member_exists_without_alias(const SDNA *sdna,
const char *vartype, const char *vartype,
const char *name) const char *name)
{ {
const int SDNAnr = DNA_struct_find_without_alias(sdna, stype); const int struct_index = DNA_struct_find_index_without_alias(sdna, stype);
if (SDNAnr != -1) { if (struct_index != -1) {
const SDNA_Struct *const spo = sdna->structs[SDNAnr]; const SDNA_Struct *const struct_info = sdna->structs[struct_index];
const bool found = elem_exists_without_alias(sdna, vartype, name, spo); const bool found = elem_exists_without_alias(sdna, vartype, name, struct_info);
if (found) { if (found) {
return true; return true;
@@ -1722,90 +1744,96 @@ int DNA_elem_type_size(const eSDNA_Type elem_nr)
return 8; return 8;
} }
int DNA_struct_alignment(const SDNA *sdna, const int struct_nr) int DNA_struct_alignment(const SDNA *sdna, const int struct_index)
{ {
return sdna->types_alignment[struct_nr]; return sdna->types_alignment[struct_index];
} }
const char *DNA_struct_identifier(struct SDNA *sdna, const int struct_index) const char *DNA_struct_identifier(struct SDNA *sdna, const int struct_index)
{ {
DNA_sdna_alias_data_ensure(sdna); DNA_sdna_alias_data_ensure(sdna);
const SDNA_Struct *struct_info = sdna->structs[struct_index]; const SDNA_Struct *struct_info = sdna->structs[struct_index];
return sdna->alias.types[struct_info->type]; return sdna->alias.types[struct_info->type_index];
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/** \name Version Patch DNA /** \name Version Patch DNA
* \{ */ * \{ */
static bool DNA_sdna_patch_struct(SDNA *sdna, static bool DNA_sdna_patch_struct(SDNA *sdna, const int struct_index, const char *new_type_name)
const int struct_name_old_nr,
const char *struct_name_new)
{ {
BLI_assert(DNA_struct_find_without_alias(DNA_sdna_current_get(), struct_name_new) != -1); BLI_assert(DNA_struct_find_index_without_alias(DNA_sdna_current_get(), new_type_name) != -1);
const SDNA_Struct *struct_info = sdna->structs[struct_name_old_nr]; const SDNA_Struct *struct_info = sdna->structs[struct_index];
#ifdef WITH_DNA_GHASH #ifdef WITH_DNA_GHASH
BLI_ghash_remove(sdna->structs_map, (void *)sdna->types[struct_info->type], nullptr, nullptr); BLI_ghash_remove(
sdna->types_to_structs_map, (void *)sdna->types[struct_info->type_index], nullptr, nullptr);
BLI_ghash_insert( BLI_ghash_insert(
sdna->structs_map, (void *)struct_name_new, POINTER_FROM_INT(struct_name_old_nr)); sdna->types_to_structs_map, (void *)new_type_name, POINTER_FROM_INT(struct_index));
#endif #endif
sdna->types[struct_info->type] = struct_name_new; sdna->types[struct_info->type_index] = new_type_name;
return true; return true;
} }
bool DNA_sdna_patch_struct_by_name(SDNA *sdna, bool DNA_sdna_patch_struct_by_name(SDNA *sdna,
const char *struct_name_old, const char *old_type_name,
const char *struct_name_new) const char *new_type_name)
{ {
const int struct_name_old_nr = DNA_struct_find_without_alias(sdna, struct_name_old); const int struct_index = DNA_struct_find_index_without_alias(sdna, old_type_name);
if (struct_name_old_nr != -1) { if (struct_index != -1) {
return DNA_sdna_patch_struct(sdna, struct_name_old_nr, struct_name_new); return DNA_sdna_patch_struct(sdna, struct_index, new_type_name);
} }
return false; return false;
} }
/* Make public if called often with same struct (avoid duplicate lookups). */ /* Make public if called often with same struct (avoid duplicate lookups). */
static bool DNA_sdna_patch_struct_member(SDNA *sdna, static bool DNA_sdna_patch_struct_member(SDNA *sdna,
const int struct_name_nr, const int struct_index,
const char *elem_old, const char *old_member_name,
const char *elem_new) const char *new_member_name)
{ {
/* These names aren't handled here (it's not used). /* These names aren't handled here (it's not used).
* Ensure they are never used or we get out of sync arrays. */ * Ensure they are never used or we get out of sync arrays. */
BLI_assert(sdna->alias.names == nullptr); BLI_assert(sdna->alias.members == nullptr);
const int elem_old_len = strlen(elem_old); const int old_member_name_len = strlen(old_member_name);
const int elem_new_len = strlen(elem_new); const int new_member_name_len = strlen(new_member_name);
BLI_assert(elem_new != nullptr); BLI_assert(new_member_name != nullptr);
SDNA_Struct *sp = sdna->structs[struct_name_nr]; SDNA_Struct *struct_info = sdna->structs[struct_index];
for (int elem_index = sp->members_len; elem_index > 0; elem_index--) { for (int struct_member_index = struct_info->members_num; struct_member_index > 0;
SDNA_StructMember *member = &sp->members[elem_index]; struct_member_index--)
const char *elem_old_full = sdna->names[member->name]; {
/* Start & end offsets in 'elem_old_full'. */ SDNA_StructMember *member_info = &struct_info->members[struct_member_index];
uint elem_old_full_offset_start; const char *old_member_name_full = sdna->members[member_info->member_index];
if (DNA_elem_id_match(elem_old, elem_old_len, elem_old_full, &elem_old_full_offset_start)) { /* Start & end offsets in #old_member_full. */
uint old_member_name_full_offset_start;
if (DNA_member_id_match(old_member_name,
old_member_name_len,
old_member_name_full,
&old_member_name_full_offset_start))
{
if (sdna->mem_arena == nullptr) { if (sdna->mem_arena == nullptr) {
sdna->mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__); sdna->mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
} }
const char *elem_new_full = DNA_elem_id_rename(sdna->mem_arena, const char *new_member_name_full = DNA_member_id_rename(sdna->mem_arena,
elem_old, old_member_name,
elem_old_len, old_member_name_len,
elem_new, new_member_name,
elem_new_len, new_member_name_len,
elem_old_full, old_member_name_full,
strlen(elem_old_full), strlen(old_member_name_full),
elem_old_full_offset_start); old_member_name_full_offset_start);
if (sdna->names_len == sdna->names_len_alloc) { if (sdna->members_num == sdna->members_num_alloc) {
sdna->names_len_alloc += 64; sdna->members_num_alloc += 64;
sdna->names = static_cast<const char **>( sdna->members = static_cast<const char **>(MEM_recallocN(
MEM_recallocN((void *)sdna->names, sizeof(*sdna->names) * sdna->names_len_alloc)); (void *)sdna->members, sizeof(*sdna->members) * sdna->members_num_alloc));
sdna->names_array_len = static_cast<short int *>( sdna->members_array_num = static_cast<short int *>(
MEM_recallocN((void *)sdna->names_array_len, MEM_recallocN((void *)sdna->members_array_num,
sizeof(*sdna->names_array_len) * sdna->names_len_alloc)); sizeof(*sdna->members_array_num) * sdna->members_num_alloc));
} }
const short name_nr_prev = member->name; const short old_member_index = member_info->member_index;
member->name = sdna->names_len++; member_info->member_index = sdna->members_num++;
sdna->names[member->name] = elem_new_full; sdna->members[member_info->member_index] = new_member_name_full;
sdna->names_array_len[member->name] = sdna->names_array_len[name_nr_prev]; sdna->members_array_num[member_info->member_index] =
sdna->members_array_num[old_member_index];
return true; return true;
} }
@@ -1813,13 +1841,13 @@ static bool DNA_sdna_patch_struct_member(SDNA *sdna,
return false; return false;
} }
bool DNA_sdna_patch_struct_member_by_name(SDNA *sdna, bool DNA_sdna_patch_struct_member_by_name(SDNA *sdna,
const char *struct_name, const char *type_name,
const char *elem_old, const char *old_member_name,
const char *elem_new) const char *new_member_name)
{ {
const int struct_name_nr = DNA_struct_find_without_alias(sdna, struct_name); const int struct_index = DNA_struct_find_index_without_alias(sdna, type_name);
if (struct_name_nr != -1) { if (struct_index != -1) {
return DNA_sdna_patch_struct_member(sdna, struct_name_nr, elem_old, elem_new); return DNA_sdna_patch_struct_member(sdna, struct_index, old_member_name, new_member_name);
} }
return false; return false;
} }
@@ -1841,9 +1869,9 @@ bool DNA_sdna_patch_struct_member_by_name(SDNA *sdna,
static void sdna_expand_names(SDNA *sdna) static void sdna_expand_names(SDNA *sdna)
{ {
int names_expand_len = 0; int names_expand_len = 0;
for (int struct_nr = 0; struct_nr < sdna->structs_len; struct_nr++) { for (int struct_index = 0; struct_index < sdna->structs_num; struct_index++) {
const SDNA_Struct *struct_old = sdna->structs[struct_nr]; const SDNA_Struct *struct_old = sdna->structs[struct_index];
names_expand_len += struct_old->members_len; names_expand_len += struct_old->members_num;
} }
const char **names_expand = static_cast<const char **>( const char **names_expand = static_cast<const char **>(
MEM_mallocN(sizeof(*names_expand) * names_expand_len, __func__)); MEM_mallocN(sizeof(*names_expand) * names_expand_len, __func__));
@@ -1851,35 +1879,36 @@ static void sdna_expand_names(SDNA *sdna)
MEM_mallocN(sizeof(*names_array_len_expand) * names_expand_len, __func__)); MEM_mallocN(sizeof(*names_array_len_expand) * names_expand_len, __func__));
int names_expand_index = 0; int names_expand_index = 0;
for (int struct_nr = 0; struct_nr < sdna->structs_len; struct_nr++) { for (int struct_index = 0; struct_index < sdna->structs_num; struct_index++) {
/* We can't edit this memory 'sdna->structs' points to (read-only `datatoc` file). */ /* We can't edit this memory 'sdna->structs' points to (read-only `datatoc` file). */
const SDNA_Struct *struct_old = sdna->structs[struct_nr]; const SDNA_Struct *struct_old = sdna->structs[struct_index];
const int array_size = sizeof(short) * 2 + sizeof(SDNA_StructMember) * struct_old->members_len; const int array_size = sizeof(short) * 2 + sizeof(SDNA_StructMember) * struct_old->members_num;
SDNA_Struct *struct_new = static_cast<SDNA_Struct *>( SDNA_Struct *struct_new = static_cast<SDNA_Struct *>(
BLI_memarena_alloc(sdna->mem_arena, array_size)); BLI_memarena_alloc(sdna->mem_arena, array_size));
memcpy(struct_new, struct_old, array_size); memcpy(struct_new, struct_old, array_size);
sdna->structs[struct_nr] = struct_new; sdna->structs[struct_index] = struct_new;
for (int i = 0; i < struct_old->members_len; i++) { for (int i = 0; i < struct_old->members_num; i++) {
const SDNA_StructMember *member_old = &struct_old->members[i]; const SDNA_StructMember *member_old = &struct_old->members[i];
SDNA_StructMember *member_new = &struct_new->members[i]; SDNA_StructMember *member_new = &struct_new->members[i];
names_expand[names_expand_index] = sdna->names[member_old->name]; names_expand[names_expand_index] = sdna->members[member_old->member_index];
names_array_len_expand[names_expand_index] = sdna->names_array_len[member_old->name]; names_array_len_expand[names_expand_index] =
sdna->members_array_num[member_old->member_index];
BLI_assert(names_expand_index < SHRT_MAX); BLI_assert(names_expand_index < SHRT_MAX);
member_new->name = names_expand_index; member_new->member_index = names_expand_index;
names_expand_index++; names_expand_index++;
} }
} }
MEM_freeN((void *)sdna->names); MEM_freeN((void *)sdna->members);
sdna->names = names_expand; sdna->members = names_expand;
MEM_freeN((void *)sdna->names_array_len); MEM_freeN((void *)sdna->members_array_num);
sdna->names_array_len = names_array_len_expand; sdna->members_array_num = names_array_len_expand;
sdna->names_len = names_expand_len; sdna->members_num = names_expand_len;
} }
static const char *dna_sdna_alias_from_static_elem_full(SDNA *sdna, static const char *dna_sdna_alias_from_static_elem_full(SDNA *sdna,
@@ -1889,26 +1918,26 @@ static const char *dna_sdna_alias_from_static_elem_full(SDNA *sdna,
{ {
const int elem_static_full_len = strlen(elem_static_full); const int elem_static_full_len = strlen(elem_static_full);
char *elem_static = static_cast<char *>(alloca(elem_static_full_len + 1)); char *elem_static = static_cast<char *>(alloca(elem_static_full_len + 1));
const int elem_static_len = DNA_elem_id_strip_copy(elem_static, elem_static_full); const int elem_static_len = DNA_member_id_strip_copy(elem_static, elem_static_full);
const char *str_pair[2] = {struct_name_static, elem_static}; const char *str_pair[2] = {struct_name_static, elem_static};
const char *elem_alias = static_cast<const char *>( const char *elem_alias = static_cast<const char *>(
BLI_ghash_lookup(elem_map_alias_from_static, str_pair)); BLI_ghash_lookup(elem_map_alias_from_static, str_pair));
if (elem_alias) { if (elem_alias) {
return DNA_elem_id_rename(sdna->mem_arena, return DNA_member_id_rename(sdna->mem_arena,
elem_static, elem_static,
elem_static_len, elem_static_len,
elem_alias, elem_alias,
strlen(elem_alias), strlen(elem_alias),
elem_static_full, elem_static_full,
elem_static_full_len, elem_static_full_len,
DNA_elem_id_offset_start(elem_static_full)); DNA_member_id_offset_start(elem_static_full));
} }
return nullptr; return nullptr;
} }
void DNA_sdna_alias_data_ensure(SDNA *sdna) void DNA_sdna_alias_data_ensure(SDNA *sdna)
{ {
if (sdna->alias.names && sdna->alias.types) { if (sdna->alias.members && sdna->alias.types) {
return; return;
} }
@@ -1919,72 +1948,76 @@ void DNA_sdna_alias_data_ensure(SDNA *sdna)
sdna->mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__); sdna->mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
} }
GHash *struct_map_alias_from_static; GHash *type_map_alias_from_static;
GHash *elem_map_alias_from_static; GHash *member_map_alias_from_static;
DNA_alias_maps( DNA_alias_maps(
DNA_RENAME_ALIAS_FROM_STATIC, &struct_map_alias_from_static, &elem_map_alias_from_static); DNA_RENAME_ALIAS_FROM_STATIC, &type_map_alias_from_static, &member_map_alias_from_static);
if (sdna->alias.types == nullptr) { if (sdna->alias.types == nullptr) {
sdna->alias.types = static_cast<const char **>( sdna->alias.types = static_cast<const char **>(
MEM_mallocN(sizeof(*sdna->alias.types) * sdna->types_len, __func__)); MEM_mallocN(sizeof(*sdna->alias.types) * sdna->types_num, __func__));
for (int type_nr = 0; type_nr < sdna->types_len; type_nr++) { for (int type_index = 0; type_index < sdna->types_num; type_index++) {
const char *struct_name_static = sdna->types[type_nr]; const char *type_name_static = sdna->types[type_index];
if (use_legacy_hack) { if (use_legacy_hack) {
struct_name_static = DNA_struct_rename_legacy_hack_alias_from_static(struct_name_static); type_name_static = DNA_struct_rename_legacy_hack_alias_from_static(type_name_static);
} }
sdna->alias.types[type_nr] = static_cast<const char *>(BLI_ghash_lookup_default( sdna->alias.types[type_index] = static_cast<const char *>(BLI_ghash_lookup_default(
struct_map_alias_from_static, struct_name_static, (void *)struct_name_static)); type_map_alias_from_static, type_name_static, (void *)type_name_static));
} }
} }
if (sdna->alias.names == nullptr) { if (sdna->alias.members == nullptr) {
sdna_expand_names(sdna); sdna_expand_names(sdna);
sdna->alias.names = static_cast<const char **>( sdna->alias.members = static_cast<const char **>(
MEM_mallocN(sizeof(*sdna->alias.names) * sdna->names_len, __func__)); MEM_mallocN(sizeof(*sdna->alias.members) * sdna->members_num, __func__));
for (int struct_nr = 0; struct_nr < sdna->structs_len; struct_nr++) { for (int struct_index = 0; struct_index < sdna->structs_num; struct_index++) {
const SDNA_Struct *struct_info = sdna->structs[struct_nr]; const SDNA_Struct *struct_info = sdna->structs[struct_index];
const char *struct_name_static = sdna->types[struct_info->type]; const char *struct_name_static = sdna->types[struct_info->type_index];
if (use_legacy_hack) { if (use_legacy_hack) {
struct_name_static = DNA_struct_rename_legacy_hack_alias_from_static(struct_name_static); struct_name_static = DNA_struct_rename_legacy_hack_alias_from_static(struct_name_static);
} }
for (int a = 0; a < struct_info->members_len; a++) { for (int a = 0; a < struct_info->members_num; a++) {
const SDNA_StructMember *member = &struct_info->members[a]; const SDNA_StructMember *member = &struct_info->members[a];
const char *elem_alias_full = dna_sdna_alias_from_static_elem_full( const char *member_alias_full = dna_sdna_alias_from_static_elem_full(
sdna, elem_map_alias_from_static, struct_name_static, sdna->names[member->name]); sdna,
if (elem_alias_full != nullptr) { member_map_alias_from_static,
sdna->alias.names[member->name] = elem_alias_full; struct_name_static,
sdna->members[member->member_index]);
if (member_alias_full != nullptr) {
sdna->alias.members[member->member_index] = member_alias_full;
} }
else { else {
sdna->alias.names[member->name] = sdna->names[member->name]; sdna->alias.members[member->member_index] = sdna->members[member->member_index];
} }
} }
} }
} }
BLI_ghash_free(struct_map_alias_from_static, nullptr, nullptr); BLI_ghash_free(type_map_alias_from_static, nullptr, nullptr);
BLI_ghash_free(elem_map_alias_from_static, MEM_freeN, nullptr); BLI_ghash_free(member_map_alias_from_static, MEM_freeN, nullptr);
} }
void DNA_sdna_alias_data_ensure_structs_map(SDNA *sdna) void DNA_sdna_alias_data_ensure_structs_map(SDNA *sdna)
{ {
if (sdna->alias.structs_map) { if (sdna->alias.types_to_structs_map) {
return; return;
} }
DNA_sdna_alias_data_ensure(sdna); DNA_sdna_alias_data_ensure(sdna);
#ifdef WITH_DNA_GHASH #ifdef WITH_DNA_GHASH
/* create a ghash lookup to speed up */ /* create a ghash lookup to speed up */
GHash *structs_map = BLI_ghash_str_new_ex(__func__, sdna->structs_len); GHash *type_to_struct_index_map = BLI_ghash_str_new_ex(__func__, sdna->structs_num);
for (intptr_t nr = 0; nr < sdna->structs_len; nr++) { for (intptr_t struct_index = 0; struct_index < sdna->structs_num; struct_index++) {
const SDNA_Struct *struct_info = sdna->structs[nr]; const SDNA_Struct *struct_info = sdna->structs[struct_index];
BLI_ghash_insert( BLI_ghash_insert(type_to_struct_index_map,
structs_map, (void *)sdna->alias.types[struct_info->type], POINTER_FROM_INT(nr)); (void *)sdna->alias.types[struct_info->type_index],
POINTER_FROM_INT(struct_index));
} }
sdna->alias.structs_map = structs_map; sdna->alias.types_to_structs_map = type_to_struct_index_map;
#else #else
UNUSED_VARS(sdna); UNUSED_VARS(sdna);
#endif #endif

View File

@@ -47,190 +47,190 @@ DNA_STRUCT_RENAME(SeqRetimingHandle, SeqRetimingKey)
DNA_STRUCT_RENAME(SpaceButs, SpaceProperties) DNA_STRUCT_RENAME(SpaceButs, SpaceProperties)
DNA_STRUCT_RENAME(SpaceIpo, SpaceGraph) DNA_STRUCT_RENAME(SpaceIpo, SpaceGraph)
DNA_STRUCT_RENAME(SpaceOops, SpaceOutliner) DNA_STRUCT_RENAME(SpaceOops, SpaceOutliner)
DNA_STRUCT_RENAME_ELEM(BPoint, alfa, tilt) DNA_STRUCT_RENAME_MEMBER(BPoint, alfa, tilt)
DNA_STRUCT_RENAME_ELEM(BezTriple, alfa, tilt) DNA_STRUCT_RENAME_MEMBER(BezTriple, alfa, tilt)
DNA_STRUCT_RENAME_ELEM(Bone, curveInX, curve_in_x) DNA_STRUCT_RENAME_MEMBER(Bone, curveInX, curve_in_x)
DNA_STRUCT_RENAME_ELEM(Bone, curveInY, curve_in_z) DNA_STRUCT_RENAME_MEMBER(Bone, curveInY, curve_in_z)
DNA_STRUCT_RENAME_ELEM(Bone, curveOutX, curve_out_x) DNA_STRUCT_RENAME_MEMBER(Bone, curveOutX, curve_out_x)
DNA_STRUCT_RENAME_ELEM(Bone, curveOutY, curve_out_z) DNA_STRUCT_RENAME_MEMBER(Bone, curveOutY, curve_out_z)
DNA_STRUCT_RENAME_ELEM(Bone, scaleIn, scale_in_x) DNA_STRUCT_RENAME_MEMBER(Bone, scaleIn, scale_in_x)
DNA_STRUCT_RENAME_ELEM(Bone, scaleOut, scale_out_x) DNA_STRUCT_RENAME_MEMBER(Bone, scaleOut, scale_out_x)
DNA_STRUCT_RENAME_ELEM(Bone, scale_in_y, scale_in_z) DNA_STRUCT_RENAME_MEMBER(Bone, scale_in_y, scale_in_z)
DNA_STRUCT_RENAME_ELEM(Bone, scale_out_y, scale_out_z) DNA_STRUCT_RENAME_MEMBER(Bone, scale_out_y, scale_out_z)
DNA_STRUCT_RENAME_ELEM(BrushGpencilSettings, gradient_f, hardness) DNA_STRUCT_RENAME_MEMBER(BrushGpencilSettings, gradient_f, hardness)
DNA_STRUCT_RENAME_ELEM(BrushGpencilSettings, gradient_s, aspect_ratio) DNA_STRUCT_RENAME_MEMBER(BrushGpencilSettings, gradient_s, aspect_ratio)
DNA_STRUCT_RENAME_ELEM(Camera, YF_dofdist, dof_distance) DNA_STRUCT_RENAME_MEMBER(Camera, YF_dofdist, dof_distance)
DNA_STRUCT_RENAME_ELEM(Camera, clipend, clip_end) DNA_STRUCT_RENAME_MEMBER(Camera, clipend, clip_end)
DNA_STRUCT_RENAME_ELEM(Camera, clipsta, clip_start) DNA_STRUCT_RENAME_MEMBER(Camera, clipsta, clip_start)
DNA_STRUCT_RENAME_ELEM(Collection, dupli_ofs, instance_offset) DNA_STRUCT_RENAME_MEMBER(Collection, dupli_ofs, instance_offset)
DNA_STRUCT_RENAME_ELEM(Curve, ext1, extrude) DNA_STRUCT_RENAME_MEMBER(Curve, ext1, extrude)
DNA_STRUCT_RENAME_ELEM(Curve, ext2, bevel_radius) DNA_STRUCT_RENAME_MEMBER(Curve, ext2, bevel_radius)
DNA_STRUCT_RENAME_ELEM(Curve, len_wchar, len_char32) DNA_STRUCT_RENAME_MEMBER(Curve, len_wchar, len_char32)
DNA_STRUCT_RENAME_ELEM(Curve, loc, texspace_location) DNA_STRUCT_RENAME_MEMBER(Curve, loc, texspace_location)
DNA_STRUCT_RENAME_ELEM(Curve, size, texspace_size) DNA_STRUCT_RENAME_MEMBER(Curve, size, texspace_size)
DNA_STRUCT_RENAME_ELEM(Curve, texflag, texspace_flag) DNA_STRUCT_RENAME_MEMBER(Curve, texflag, texspace_flag)
DNA_STRUCT_RENAME_ELEM(Curve, width, offset) DNA_STRUCT_RENAME_MEMBER(Curve, width, offset)
DNA_STRUCT_RENAME_ELEM(Curves, attributes_active_index, attributes_active_index_legacy) DNA_STRUCT_RENAME_MEMBER(Curves, attributes_active_index, attributes_active_index_legacy)
DNA_STRUCT_RENAME_ELEM(CurvesGeometry, curve_size, curve_num) DNA_STRUCT_RENAME_MEMBER(CurvesGeometry, curve_size, curve_num)
DNA_STRUCT_RENAME_ELEM(CurvesGeometry, point_size, point_num) DNA_STRUCT_RENAME_MEMBER(CurvesGeometry, point_size, point_num)
DNA_STRUCT_RENAME_ELEM(CustomDataExternal, filename, filepath) DNA_STRUCT_RENAME_MEMBER(CustomDataExternal, filename, filepath)
DNA_STRUCT_RENAME_ELEM(Editing, over_border, overlay_frame_rect) DNA_STRUCT_RENAME_MEMBER(Editing, over_border, overlay_frame_rect)
DNA_STRUCT_RENAME_ELEM(Editing, over_cfra, overlay_frame_abs) DNA_STRUCT_RENAME_MEMBER(Editing, over_cfra, overlay_frame_abs)
DNA_STRUCT_RENAME_ELEM(Editing, over_flag, overlay_frame_flag) DNA_STRUCT_RENAME_MEMBER(Editing, over_flag, overlay_frame_flag)
DNA_STRUCT_RENAME_ELEM(Editing, over_ofs, overlay_frame_ofs) DNA_STRUCT_RENAME_MEMBER(Editing, over_ofs, overlay_frame_ofs)
DNA_STRUCT_RENAME_ELEM(FileAssetSelectParams, import_type, import_method) DNA_STRUCT_RENAME_MEMBER(FileAssetSelectParams, import_type, import_method)
DNA_STRUCT_RENAME_ELEM(FileGlobal, filename, filepath) DNA_STRUCT_RENAME_MEMBER(FileGlobal, filename, filepath)
DNA_STRUCT_RENAME_ELEM(FluidDomainSettings, cache_frame_pause_guiding, cache_frame_pause_guide) DNA_STRUCT_RENAME_MEMBER(FluidDomainSettings, cache_frame_pause_guiding, cache_frame_pause_guide)
DNA_STRUCT_RENAME_ELEM(FluidDomainSettings, guiding_alpha, guide_alpha) DNA_STRUCT_RENAME_MEMBER(FluidDomainSettings, guiding_alpha, guide_alpha)
DNA_STRUCT_RENAME_ELEM(FluidDomainSettings, guiding_beta, guide_beta) DNA_STRUCT_RENAME_MEMBER(FluidDomainSettings, guiding_beta, guide_beta)
DNA_STRUCT_RENAME_ELEM(FluidDomainSettings, guiding_parent, guide_parent) DNA_STRUCT_RENAME_MEMBER(FluidDomainSettings, guiding_parent, guide_parent)
DNA_STRUCT_RENAME_ELEM(FluidDomainSettings, guiding_source, guide_source) DNA_STRUCT_RENAME_MEMBER(FluidDomainSettings, guiding_source, guide_source)
DNA_STRUCT_RENAME_ELEM(FluidDomainSettings, guiding_vel_factor, guide_vel_factor) DNA_STRUCT_RENAME_MEMBER(FluidDomainSettings, guiding_vel_factor, guide_vel_factor)
DNA_STRUCT_RENAME_ELEM(FluidEffectorSettings, guiding_mode, guide_mode) DNA_STRUCT_RENAME_MEMBER(FluidEffectorSettings, guiding_mode, guide_mode)
DNA_STRUCT_RENAME_ELEM(GreasePencil, drawing_array_size, drawing_array_num) DNA_STRUCT_RENAME_MEMBER(GreasePencil, drawing_array_size, drawing_array_num)
DNA_STRUCT_RENAME_ELEM(GreasePencil, material_array_size, material_array_num) DNA_STRUCT_RENAME_MEMBER(GreasePencil, material_array_size, material_array_num)
DNA_STRUCT_RENAME_ELEM(GreasePencilLayerFramesMapStorage, size, num) DNA_STRUCT_RENAME_MEMBER(GreasePencilLayerFramesMapStorage, size, num)
DNA_STRUCT_RENAME_ELEM(HookModifierData, totindex, indexar_num) DNA_STRUCT_RENAME_MEMBER(HookModifierData, totindex, indexar_num)
DNA_STRUCT_RENAME_ELEM(Image, name, filepath) DNA_STRUCT_RENAME_MEMBER(Image, name, filepath)
DNA_STRUCT_RENAME_ELEM(LaplacianDeformModifierData, total_verts, verts_num) DNA_STRUCT_RENAME_MEMBER(LaplacianDeformModifierData, total_verts, verts_num)
DNA_STRUCT_RENAME_ELEM(Library, name, filepath) DNA_STRUCT_RENAME_MEMBER(Library, name, filepath)
DNA_STRUCT_RENAME_ELEM(Light, energy, energy_deprecated) DNA_STRUCT_RENAME_MEMBER(Light, energy, energy_deprecated)
DNA_STRUCT_RENAME_ELEM(Light, energy_new, energy) DNA_STRUCT_RENAME_MEMBER(Light, energy_new, energy)
DNA_STRUCT_RENAME_ELEM(LineartGpencilModifierData, line_types, edge_types) DNA_STRUCT_RENAME_MEMBER(LineartGpencilModifierData, line_types, edge_types)
DNA_STRUCT_RENAME_ELEM(LineartGpencilModifierData, transparency_flags, mask_switches) DNA_STRUCT_RENAME_MEMBER(LineartGpencilModifierData, transparency_flags, mask_switches)
DNA_STRUCT_RENAME_ELEM(LineartGpencilModifierData, transparency_mask, material_mask_bits) DNA_STRUCT_RENAME_MEMBER(LineartGpencilModifierData, transparency_mask, material_mask_bits)
DNA_STRUCT_RENAME_ELEM(MDefCell, totinfluence, influences_num) DNA_STRUCT_RENAME_MEMBER(MDefCell, totinfluence, influences_num)
DNA_STRUCT_RENAME_ELEM(MEdge, bweight, bweight_legacy) DNA_STRUCT_RENAME_MEMBER(MEdge, bweight, bweight_legacy)
DNA_STRUCT_RENAME_ELEM(MEdge, crease, crease_legacy) DNA_STRUCT_RENAME_MEMBER(MEdge, crease, crease_legacy)
DNA_STRUCT_RENAME_ELEM(MEdge, flag, flag_legacy) DNA_STRUCT_RENAME_MEMBER(MEdge, flag, flag_legacy)
DNA_STRUCT_RENAME_ELEM(MPoly, flag, flag_legacy) DNA_STRUCT_RENAME_MEMBER(MPoly, flag, flag_legacy)
DNA_STRUCT_RENAME_ELEM(MPoly, mat_nr, mat_nr_legacy) DNA_STRUCT_RENAME_MEMBER(MPoly, mat_nr, mat_nr_legacy)
DNA_STRUCT_RENAME_ELEM(MVert, bweight, bweight_legacy) DNA_STRUCT_RENAME_MEMBER(MVert, bweight, bweight_legacy)
DNA_STRUCT_RENAME_ELEM(MVert, co, co_legacy) DNA_STRUCT_RENAME_MEMBER(MVert, co, co_legacy)
DNA_STRUCT_RENAME_ELEM(MVert, flag, flag_legacy) DNA_STRUCT_RENAME_MEMBER(MVert, flag, flag_legacy)
DNA_STRUCT_RENAME_ELEM(MaskLayer, restrictflag, visibility_flag) DNA_STRUCT_RENAME_MEMBER(MaskLayer, restrictflag, visibility_flag)
DNA_STRUCT_RENAME_ELEM(MaterialLineArt, transparency_mask, material_mask_bits) DNA_STRUCT_RENAME_MEMBER(MaterialLineArt, transparency_mask, material_mask_bits)
DNA_STRUCT_RENAME_ELEM(Mesh, edata, edge_data) DNA_STRUCT_RENAME_MEMBER(Mesh, edata, edge_data)
DNA_STRUCT_RENAME_ELEM(Mesh, fdata, fdata_legacy) DNA_STRUCT_RENAME_MEMBER(Mesh, fdata, fdata_legacy)
DNA_STRUCT_RENAME_ELEM(Mesh, ldata, corner_data) DNA_STRUCT_RENAME_MEMBER(Mesh, ldata, corner_data)
DNA_STRUCT_RENAME_ELEM(Mesh, loc, texspace_location) DNA_STRUCT_RENAME_MEMBER(Mesh, loc, texspace_location)
DNA_STRUCT_RENAME_ELEM(Mesh, pdata, face_data) DNA_STRUCT_RENAME_MEMBER(Mesh, pdata, face_data)
DNA_STRUCT_RENAME_ELEM(Mesh, poly_offset_indices, face_offset_indices) DNA_STRUCT_RENAME_MEMBER(Mesh, poly_offset_indices, face_offset_indices)
DNA_STRUCT_RENAME_ELEM(Mesh, size, texspace_size) DNA_STRUCT_RENAME_MEMBER(Mesh, size, texspace_size)
DNA_STRUCT_RENAME_ELEM(Mesh, smoothresh, smoothresh_legacy) DNA_STRUCT_RENAME_MEMBER(Mesh, smoothresh, smoothresh_legacy)
DNA_STRUCT_RENAME_ELEM(Mesh, texflag, texspace_flag) DNA_STRUCT_RENAME_MEMBER(Mesh, texflag, texspace_flag)
DNA_STRUCT_RENAME_ELEM(Mesh, totedge, edges_num) DNA_STRUCT_RENAME_MEMBER(Mesh, totedge, edges_num)
DNA_STRUCT_RENAME_ELEM(Mesh, totface, totface_legacy) DNA_STRUCT_RENAME_MEMBER(Mesh, totface, totface_legacy)
DNA_STRUCT_RENAME_ELEM(Mesh, totloop, corners_num) DNA_STRUCT_RENAME_MEMBER(Mesh, totloop, corners_num)
DNA_STRUCT_RENAME_ELEM(Mesh, totpoly, faces_num) DNA_STRUCT_RENAME_MEMBER(Mesh, totpoly, faces_num)
DNA_STRUCT_RENAME_ELEM(Mesh, totvert, verts_num) DNA_STRUCT_RENAME_MEMBER(Mesh, totvert, verts_num)
DNA_STRUCT_RENAME_ELEM(Mesh, vdata, vert_data) DNA_STRUCT_RENAME_MEMBER(Mesh, vdata, vert_data)
DNA_STRUCT_RENAME_ELEM(MeshDeformModifierData, totcagevert, cage_verts_num) DNA_STRUCT_RENAME_MEMBER(MeshDeformModifierData, totcagevert, cage_verts_num)
DNA_STRUCT_RENAME_ELEM(MeshDeformModifierData, totinfluence, influences_num) DNA_STRUCT_RENAME_MEMBER(MeshDeformModifierData, totinfluence, influences_num)
DNA_STRUCT_RENAME_ELEM(MeshDeformModifierData, totvert, verts_num) DNA_STRUCT_RENAME_MEMBER(MeshDeformModifierData, totvert, verts_num)
DNA_STRUCT_RENAME_ELEM(MetaBall, loc, texspace_location) DNA_STRUCT_RENAME_MEMBER(MetaBall, loc, texspace_location)
DNA_STRUCT_RENAME_ELEM(MetaBall, size, texspace_size) DNA_STRUCT_RENAME_MEMBER(MetaBall, size, texspace_size)
DNA_STRUCT_RENAME_ELEM(MetaBall, texflag, texspace_flag) DNA_STRUCT_RENAME_MEMBER(MetaBall, texflag, texspace_flag)
DNA_STRUCT_RENAME_ELEM(MovieClip, name, filepath) DNA_STRUCT_RENAME_MEMBER(MovieClip, name, filepath)
DNA_STRUCT_RENAME_ELEM(MovieTracking, act_plane_track, act_plane_track_legacy) DNA_STRUCT_RENAME_MEMBER(MovieTracking, act_plane_track, act_plane_track_legacy)
DNA_STRUCT_RENAME_ELEM(MovieTracking, act_track, act_track_legacy) DNA_STRUCT_RENAME_MEMBER(MovieTracking, act_track, act_track_legacy)
DNA_STRUCT_RENAME_ELEM(MovieTracking, plane_tracks, plane_tracks_legacy) DNA_STRUCT_RENAME_MEMBER(MovieTracking, plane_tracks, plane_tracks_legacy)
DNA_STRUCT_RENAME_ELEM(MovieTracking, reconstruction, reconstruction_legacy) DNA_STRUCT_RENAME_MEMBER(MovieTracking, reconstruction, reconstruction_legacy)
DNA_STRUCT_RENAME_ELEM(MovieTracking, tracks, tracks_legacy) DNA_STRUCT_RENAME_MEMBER(MovieTracking, tracks, tracks_legacy)
DNA_STRUCT_RENAME_ELEM(MovieTrackingCamera, principal, principal_legacy) DNA_STRUCT_RENAME_MEMBER(MovieTrackingCamera, principal, principal_legacy)
DNA_STRUCT_RENAME_ELEM(MovieTrackingSettings, keyframe1, keyframe1_legacy) DNA_STRUCT_RENAME_MEMBER(MovieTrackingSettings, keyframe1, keyframe1_legacy)
DNA_STRUCT_RENAME_ELEM(MovieTrackingSettings, keyframe2, keyframe2_legacy) DNA_STRUCT_RENAME_MEMBER(MovieTrackingSettings, keyframe2, keyframe2_legacy)
DNA_STRUCT_RENAME_ELEM(MovieTrackingStabilization, rot_track, rot_track_legacy) DNA_STRUCT_RENAME_MEMBER(MovieTrackingStabilization, rot_track, rot_track_legacy)
DNA_STRUCT_RENAME_ELEM(MovieTrackingTrack, pat_max, pat_max_legacy) DNA_STRUCT_RENAME_MEMBER(MovieTrackingTrack, pat_max, pat_max_legacy)
DNA_STRUCT_RENAME_ELEM(MovieTrackingTrack, pat_min, pat_min_legacy) DNA_STRUCT_RENAME_MEMBER(MovieTrackingTrack, pat_min, pat_min_legacy)
DNA_STRUCT_RENAME_ELEM(MovieTrackingTrack, search_max, search_max_legacy) DNA_STRUCT_RENAME_MEMBER(MovieTrackingTrack, search_max, search_max_legacy)
DNA_STRUCT_RENAME_ELEM(MovieTrackingTrack, search_min, search_min_legacy) DNA_STRUCT_RENAME_MEMBER(MovieTrackingTrack, search_min, search_min_legacy)
DNA_STRUCT_RENAME_ELEM(NodeCryptomatte, num_inputs, inputs_num) DNA_STRUCT_RENAME_MEMBER(NodeCryptomatte, num_inputs, inputs_num)
DNA_STRUCT_RENAME_ELEM(NodeGeometryAttributeCapture, data_type, data_type_legacy) DNA_STRUCT_RENAME_MEMBER(NodeGeometryAttributeCapture, data_type, data_type_legacy)
DNA_STRUCT_RENAME_ELEM(NodesModifierData, simulation_bake_directory, bake_directory) DNA_STRUCT_RENAME_MEMBER(NodesModifierData, simulation_bake_directory, bake_directory)
DNA_STRUCT_RENAME_ELEM(Object, col, color) DNA_STRUCT_RENAME_MEMBER(Object, col, color)
DNA_STRUCT_RENAME_ELEM(Object, dup_group, instance_collection) DNA_STRUCT_RENAME_MEMBER(Object, dup_group, instance_collection)
DNA_STRUCT_RENAME_ELEM(Object, dupfacesca, instance_faces_scale) DNA_STRUCT_RENAME_MEMBER(Object, dupfacesca, instance_faces_scale)
DNA_STRUCT_RENAME_ELEM(Object, restrictflag, visibility_flag) DNA_STRUCT_RENAME_MEMBER(Object, restrictflag, visibility_flag)
DNA_STRUCT_RENAME_ELEM(Object, size, scale) DNA_STRUCT_RENAME_MEMBER(Object, size, scale)
DNA_STRUCT_RENAME_ELEM(OpacityGpencilModifierData, hardeness, hardness) DNA_STRUCT_RENAME_MEMBER(OpacityGpencilModifierData, hardeness, hardness)
DNA_STRUCT_RENAME_ELEM(Paint, num_input_samples, num_input_samples_deprecated) DNA_STRUCT_RENAME_MEMBER(Paint, num_input_samples, num_input_samples_deprecated)
DNA_STRUCT_RENAME_ELEM(ParticleSettings, child_nbr, child_percent) DNA_STRUCT_RENAME_MEMBER(ParticleSettings, child_nbr, child_percent)
DNA_STRUCT_RENAME_ELEM(ParticleSettings, dup_group, instance_collection) DNA_STRUCT_RENAME_MEMBER(ParticleSettings, dup_group, instance_collection)
DNA_STRUCT_RENAME_ELEM(ParticleSettings, dup_ob, instance_object) DNA_STRUCT_RENAME_MEMBER(ParticleSettings, dup_ob, instance_object)
DNA_STRUCT_RENAME_ELEM(ParticleSettings, dupliweights, instance_weights) DNA_STRUCT_RENAME_MEMBER(ParticleSettings, dupliweights, instance_weights)
DNA_STRUCT_RENAME_ELEM(ParticleSettings, ren_child_nbr, child_render_percent) DNA_STRUCT_RENAME_MEMBER(ParticleSettings, ren_child_nbr, child_render_percent)
DNA_STRUCT_RENAME_ELEM(RenderData, bake_filter, bake_margin) DNA_STRUCT_RENAME_MEMBER(RenderData, bake_filter, bake_margin)
DNA_STRUCT_RENAME_ELEM(RenderData, blurfac, motion_blur_shutter) DNA_STRUCT_RENAME_MEMBER(RenderData, blurfac, motion_blur_shutter)
DNA_STRUCT_RENAME_ELEM(RigidBodyWorld, steps_per_second, substeps_per_frame) DNA_STRUCT_RENAME_MEMBER(RigidBodyWorld, steps_per_second, substeps_per_frame)
DNA_STRUCT_RENAME_ELEM(SceneEEVEE, motion_blur_position, motion_blur_position_deprecated) DNA_STRUCT_RENAME_MEMBER(SceneEEVEE, motion_blur_position, motion_blur_position_deprecated)
DNA_STRUCT_RENAME_ELEM(SceneEEVEE, motion_blur_shutter, motion_blur_shutter_deprecated) DNA_STRUCT_RENAME_MEMBER(SceneEEVEE, motion_blur_shutter, motion_blur_shutter_deprecated)
DNA_STRUCT_RENAME_ELEM(SDefBind, numverts, verts_num) DNA_STRUCT_RENAME_MEMBER(SDefBind, numverts, verts_num)
DNA_STRUCT_RENAME_ELEM(SDefVert, numbinds, binds_num) DNA_STRUCT_RENAME_MEMBER(SDefVert, numbinds, binds_num)
DNA_STRUCT_RENAME_ELEM(Sequence, retiming_handle_num, retiming_keys_num) DNA_STRUCT_RENAME_MEMBER(Sequence, retiming_handle_num, retiming_keys_num)
DNA_STRUCT_RENAME_ELEM(Sequence, retiming_handles, retiming_keys) DNA_STRUCT_RENAME_MEMBER(Sequence, retiming_handles, retiming_keys)
DNA_STRUCT_RENAME_ELEM(SpaceImage, pixel_snap_mode, pixel_round_mode) DNA_STRUCT_RENAME_MEMBER(SpaceImage, pixel_snap_mode, pixel_round_mode)
DNA_STRUCT_RENAME_ELEM(SpaceSeq, overlay_type, overlay_frame_type) DNA_STRUCT_RENAME_MEMBER(SpaceSeq, overlay_type, overlay_frame_type)
DNA_STRUCT_RENAME_ELEM(Strip, dir, dirpath) DNA_STRUCT_RENAME_MEMBER(Strip, dir, dirpath)
DNA_STRUCT_RENAME_ELEM(StripElem, name, filename) DNA_STRUCT_RENAME_MEMBER(StripElem, name, filename)
DNA_STRUCT_RENAME_ELEM(StripProxy, dir, dirpath) DNA_STRUCT_RENAME_MEMBER(StripProxy, dir, dirpath)
DNA_STRUCT_RENAME_ELEM(StripProxy, file, filename) DNA_STRUCT_RENAME_MEMBER(StripProxy, file, filename)
DNA_STRUCT_RENAME_ELEM(SurfaceDeformModifierData, num_mesh_verts, mesh_verts_num) DNA_STRUCT_RENAME_MEMBER(SurfaceDeformModifierData, num_mesh_verts, mesh_verts_num)
DNA_STRUCT_RENAME_ELEM(SurfaceDeformModifierData, numpoly, target_polys_num) DNA_STRUCT_RENAME_MEMBER(SurfaceDeformModifierData, numpoly, target_polys_num)
DNA_STRUCT_RENAME_ELEM(SurfaceDeformModifierData, numverts, bind_verts_num) DNA_STRUCT_RENAME_MEMBER(SurfaceDeformModifierData, numverts, bind_verts_num)
DNA_STRUCT_RENAME_ELEM(Text, name, filepath) DNA_STRUCT_RENAME_MEMBER(Text, name, filepath)
DNA_STRUCT_RENAME_ELEM(ThemeSpace, scrubbing_background, time_scrub_background) DNA_STRUCT_RENAME_MEMBER(ThemeSpace, scrubbing_background, time_scrub_background)
DNA_STRUCT_RENAME_ELEM(ThemeSpace, show_back_grad, background_type) DNA_STRUCT_RENAME_MEMBER(ThemeSpace, show_back_grad, background_type)
DNA_STRUCT_RENAME_ELEM(UVProjectModifierData, num_projectors, projectors_num) DNA_STRUCT_RENAME_MEMBER(UVProjectModifierData, num_projectors, projectors_num)
DNA_STRUCT_RENAME_ELEM(UserDef, autokey_flag, keying_flag) DNA_STRUCT_RENAME_MEMBER(UserDef, autokey_flag, keying_flag)
DNA_STRUCT_RENAME_ELEM(UserDef, gp_manhattendist, gp_manhattandist) DNA_STRUCT_RENAME_MEMBER(UserDef, gp_manhattendist, gp_manhattandist)
DNA_STRUCT_RENAME_ELEM(UserDef, pythondir, pythondir_legacy) DNA_STRUCT_RENAME_MEMBER(UserDef, pythondir, pythondir_legacy)
DNA_STRUCT_RENAME_ELEM(VFont, name, filepath) DNA_STRUCT_RENAME_MEMBER(VFont, name, filepath)
DNA_STRUCT_RENAME_ELEM(View3D, far, clip_end) DNA_STRUCT_RENAME_MEMBER(View3D, far, clip_end)
DNA_STRUCT_RENAME_ELEM(View3D, local_collections_uuid, local_collections_uid) DNA_STRUCT_RENAME_MEMBER(View3D, local_collections_uuid, local_collections_uid)
DNA_STRUCT_RENAME_ELEM(View3D, local_view_uuid, local_view_uid) DNA_STRUCT_RENAME_MEMBER(View3D, local_view_uuid, local_view_uid)
DNA_STRUCT_RENAME_ELEM(View3D, near, clip_start) DNA_STRUCT_RENAME_MEMBER(View3D, near, clip_start)
DNA_STRUCT_RENAME_ELEM(View3D, ob_centre, ob_center) DNA_STRUCT_RENAME_MEMBER(View3D, ob_centre, ob_center)
DNA_STRUCT_RENAME_ELEM(View3D, ob_centre_bone, ob_center_bone) DNA_STRUCT_RENAME_MEMBER(View3D, ob_centre_bone, ob_center_bone)
DNA_STRUCT_RENAME_ELEM(View3D, ob_centre_cursor, ob_center_cursor) DNA_STRUCT_RENAME_MEMBER(View3D, ob_centre_cursor, ob_center_cursor)
DNA_STRUCT_RENAME_ELEM(bArmature, collections, collections_legacy) DNA_STRUCT_RENAME_MEMBER(bArmature, collections, collections_legacy)
DNA_STRUCT_RENAME_ELEM(bGPDstroke, gradient_f, hardness) DNA_STRUCT_RENAME_MEMBER(bGPDstroke, gradient_f, hardness)
DNA_STRUCT_RENAME_ELEM(bGPDstroke, gradient_s, aspect_ratio) DNA_STRUCT_RENAME_MEMBER(bGPDstroke, gradient_s, aspect_ratio)
DNA_STRUCT_RENAME_ELEM(bNodeLink, multi_input_socket_index, multi_input_sort_id) DNA_STRUCT_RENAME_MEMBER(bNodeLink, multi_input_socket_index, multi_input_sort_id)
DNA_STRUCT_RENAME_ELEM(bNodeTree, inputs, inputs_legacy) DNA_STRUCT_RENAME_MEMBER(bNodeTree, inputs, inputs_legacy)
DNA_STRUCT_RENAME_ELEM(bNodeTree, outputs, outputs_legacy) DNA_STRUCT_RENAME_MEMBER(bNodeTree, outputs, outputs_legacy)
DNA_STRUCT_RENAME_ELEM(bPoseChannel, curveInX, curve_in_x) DNA_STRUCT_RENAME_MEMBER(bPoseChannel, curveInX, curve_in_x)
DNA_STRUCT_RENAME_ELEM(bPoseChannel, curveInY, curve_in_z) DNA_STRUCT_RENAME_MEMBER(bPoseChannel, curveInY, curve_in_z)
DNA_STRUCT_RENAME_ELEM(bPoseChannel, curveOutX, curve_out_x) DNA_STRUCT_RENAME_MEMBER(bPoseChannel, curveOutX, curve_out_x)
DNA_STRUCT_RENAME_ELEM(bPoseChannel, curveOutY, curve_out_z) DNA_STRUCT_RENAME_MEMBER(bPoseChannel, curveOutY, curve_out_z)
DNA_STRUCT_RENAME_ELEM(bPoseChannel, scaleIn, scale_in_x) DNA_STRUCT_RENAME_MEMBER(bPoseChannel, scaleIn, scale_in_x)
DNA_STRUCT_RENAME_ELEM(bPoseChannel, scaleOut, scale_out_x) DNA_STRUCT_RENAME_MEMBER(bPoseChannel, scaleOut, scale_out_x)
DNA_STRUCT_RENAME_ELEM(bPoseChannel, scale_in_y, scale_in_z) DNA_STRUCT_RENAME_MEMBER(bPoseChannel, scale_in_y, scale_in_z)
DNA_STRUCT_RENAME_ELEM(bPoseChannel, scale_out_y, scale_out_z) DNA_STRUCT_RENAME_MEMBER(bPoseChannel, scale_out_y, scale_out_z)
DNA_STRUCT_RENAME_ELEM(bSameVolumeConstraint, flag, free_axis) DNA_STRUCT_RENAME_MEMBER(bSameVolumeConstraint, flag, free_axis)
DNA_STRUCT_RENAME_ELEM(bSound, name, filepath) DNA_STRUCT_RENAME_MEMBER(bSound, name, filepath)
DNA_STRUCT_RENAME_ELEM(bTheme, tact, space_action) DNA_STRUCT_RENAME_MEMBER(bTheme, tact, space_action)
DNA_STRUCT_RENAME_ELEM(bTheme, tbuts, space_properties) DNA_STRUCT_RENAME_MEMBER(bTheme, tbuts, space_properties)
DNA_STRUCT_RENAME_ELEM(bTheme, tclip, space_clip) DNA_STRUCT_RENAME_MEMBER(bTheme, tclip, space_clip)
DNA_STRUCT_RENAME_ELEM(bTheme, tconsole, space_console) DNA_STRUCT_RENAME_MEMBER(bTheme, tconsole, space_console)
DNA_STRUCT_RENAME_ELEM(bTheme, text, space_text) DNA_STRUCT_RENAME_MEMBER(bTheme, text, space_text)
DNA_STRUCT_RENAME_ELEM(bTheme, tfile, space_file) DNA_STRUCT_RENAME_MEMBER(bTheme, tfile, space_file)
DNA_STRUCT_RENAME_ELEM(bTheme, tima, space_image) DNA_STRUCT_RENAME_MEMBER(bTheme, tima, space_image)
DNA_STRUCT_RENAME_ELEM(bTheme, tinfo, space_info) DNA_STRUCT_RENAME_MEMBER(bTheme, tinfo, space_info)
DNA_STRUCT_RENAME_ELEM(bTheme, tipo, space_graph) DNA_STRUCT_RENAME_MEMBER(bTheme, tipo, space_graph)
DNA_STRUCT_RENAME_ELEM(bTheme, tnla, space_nla) DNA_STRUCT_RENAME_MEMBER(bTheme, tnla, space_nla)
DNA_STRUCT_RENAME_ELEM(bTheme, tnode, space_node) DNA_STRUCT_RENAME_MEMBER(bTheme, tnode, space_node)
DNA_STRUCT_RENAME_ELEM(bTheme, toops, space_outliner) DNA_STRUCT_RENAME_MEMBER(bTheme, toops, space_outliner)
DNA_STRUCT_RENAME_ELEM(bTheme, tseq, space_sequencer) DNA_STRUCT_RENAME_MEMBER(bTheme, tseq, space_sequencer)
DNA_STRUCT_RENAME_ELEM(bTheme, tstatusbar, space_statusbar) DNA_STRUCT_RENAME_MEMBER(bTheme, tstatusbar, space_statusbar)
DNA_STRUCT_RENAME_ELEM(bTheme, ttopbar, space_topbar) DNA_STRUCT_RENAME_MEMBER(bTheme, ttopbar, space_topbar)
DNA_STRUCT_RENAME_ELEM(bTheme, tuserpref, space_preferences) DNA_STRUCT_RENAME_MEMBER(bTheme, tuserpref, space_preferences)
DNA_STRUCT_RENAME_ELEM(bTheme, tv3d, space_view3d) DNA_STRUCT_RENAME_MEMBER(bTheme, tv3d, space_view3d)
DNA_STRUCT_RENAME_ELEM(bUserAssetLibrary, path, dirpath) DNA_STRUCT_RENAME_MEMBER(bUserAssetLibrary, path, dirpath)
/* NOTE: Keep sorted! */ /* NOTE: Keep sorted! */
/* Write with a different name, old Blender versions crash loading files with non-NULL /* Write with a different name, old Blender versions crash loading files with non-NULL
* global_areas. See D9442. */ * global_areas. See D9442. */
DNA_STRUCT_RENAME_ELEM(wmWindow, global_area_map, global_areas) DNA_STRUCT_RENAME_MEMBER(wmWindow, global_area_map, global_areas)
/* NOTE: Keep sorted! */ /* NOTE: Keep sorted! */

View File

@@ -26,7 +26,7 @@
/** \name Struct Member Evaluation /** \name Struct Member Evaluation
* \{ */ * \{ */
int DNA_elem_array_size(const char *str) int DNA_member_array_num(const char *str)
{ {
int result = 1; int result = 1;
int current = 0; int current = 0;
@@ -71,95 +71,100 @@ static bool is_identifier(const char c)
(c == '_')); (c == '_'));
} }
uint DNA_elem_id_offset_start(const char *elem_full) uint DNA_member_id_offset_start(const char *member_full)
{ {
uint elem_full_offset = 0; uint elem_full_offset = 0;
while (!is_identifier(elem_full[elem_full_offset])) { while (!is_identifier(member_full[elem_full_offset])) {
elem_full_offset++; elem_full_offset++;
} }
return elem_full_offset; return elem_full_offset;
} }
uint DNA_elem_id_offset_end(const char *elem_full) uint DNA_member_id_offset_end(const char *member_full)
{ {
uint elem_full_offset = 0; uint elem_full_offset = 0;
while (is_identifier(elem_full[elem_full_offset])) { while (is_identifier(member_full[elem_full_offset])) {
elem_full_offset++; elem_full_offset++;
} }
return elem_full_offset; return elem_full_offset;
} }
uint DNA_elem_id_strip_copy(char *elem_dst, const char *elem_src) uint DNA_member_id_strip_copy(char *member_id_dst, const char *member_full_src)
{ {
const uint elem_src_offset = DNA_elem_id_offset_start(elem_src); const uint member_src_offset = DNA_member_id_offset_start(member_full_src);
const char *elem_src_trim = elem_src + elem_src_offset; const char *member_src_trimmed = member_full_src + member_src_offset;
const uint elem_src_trim_len = DNA_elem_id_offset_end(elem_src_trim); const uint member_src_trimmed_len = DNA_member_id_offset_end(member_src_trimmed);
memcpy(elem_dst, elem_src_trim, elem_src_trim_len); memcpy(member_id_dst, member_src_trimmed, member_src_trimmed_len);
elem_dst[elem_src_trim_len] = '\0'; member_id_dst[member_src_trimmed_len] = '\0';
return elem_src_trim_len; return member_src_trimmed_len;
} }
uint DNA_elem_id_strip(char *elem) uint DNA_member_id_strip(char *member)
{ {
const uint elem_offset = DNA_elem_id_offset_start(elem); const uint member_offset = DNA_member_id_offset_start(member);
const char *elem_trim = elem + elem_offset; const char *member_trimmed = member + member_offset;
const uint elem_trim_len = DNA_elem_id_offset_end(elem_trim); const uint member_trimmed_len = DNA_member_id_offset_end(member_trimmed);
memmove(elem, elem_trim, elem_trim_len); memmove(member, member_trimmed, member_trimmed_len);
elem[elem_trim_len] = '\0'; member[member_trimmed_len] = '\0';
return elem_trim_len; return member_trimmed_len;
} }
bool DNA_elem_id_match(const char *elem_search, bool DNA_member_id_match(const char *member_id,
const int elem_search_len, const int member_id_len,
const char *elem_full, const char *member_full,
uint *r_elem_full_offset) uint *r_member_full_offset)
{ {
BLI_assert(strlen(elem_search) == elem_search_len); BLI_assert(strlen(member_id) == member_id_len);
const uint elem_full_offset = DNA_elem_id_offset_start(elem_full); const uint elem_full_offset = DNA_member_id_offset_start(member_full);
const char *elem_full_trim = elem_full + elem_full_offset; const char *elem_full_trim = member_full + elem_full_offset;
if (strncmp(elem_search, elem_full_trim, elem_search_len) == 0) { if (strncmp(member_id, elem_full_trim, member_id_len) == 0) {
const char c = elem_full_trim[elem_search_len]; const char c = elem_full_trim[member_id_len];
if (c == '\0' || !is_identifier(c)) { if (c == '\0' || !is_identifier(c)) {
*r_elem_full_offset = elem_full_offset; *r_member_full_offset = elem_full_offset;
return true; return true;
} }
} }
return false; return false;
} }
char *DNA_elem_id_rename(MemArena *mem_arena, char *DNA_member_id_rename(MemArena *mem_arena,
const char *elem_src, const char *member_id_src,
const int elem_src_len, const int member_id_src_len,
const char *elem_dst, const char *member_id_dst,
const int elem_dst_len, const int member_id_dst_len,
const char *elem_src_full, const char *member_full_src,
const int elem_src_full_len, const int member_full_src_len,
const uint elem_src_full_offset_len) const uint member_full_src_offset_len)
{ {
BLI_assert(strlen(elem_src) == elem_src_len); BLI_assert(strlen(member_id_src) == member_id_src_len);
BLI_assert(strlen(elem_dst) == elem_dst_len); BLI_assert(strlen(member_id_dst) == member_id_dst_len);
BLI_assert(strlen(elem_src_full) == elem_src_full_len); BLI_assert(strlen(member_full_src) == member_full_src_len);
BLI_assert(DNA_elem_id_offset_start(elem_src_full) == elem_src_full_offset_len); BLI_assert(DNA_member_id_offset_start(member_full_src) == member_full_src_offset_len);
UNUSED_VARS_NDEBUG(elem_src); UNUSED_VARS_NDEBUG(member_src);
const int elem_final_len = (elem_src_full_len - elem_src_len) + elem_dst_len; const int member_full_dst_len = (member_full_src_len - member_id_src_len) + member_id_dst_len;
char *elem_dst_full = static_cast<char *>(BLI_memarena_alloc(mem_arena, elem_final_len + 1)); char *member_full_dst = static_cast<char *>(
BLI_memarena_alloc(mem_arena, member_full_dst_len + 1));
uint i = 0; uint i = 0;
if (elem_src_full_offset_len != 0) { if (member_full_src_offset_len != 0) {
memcpy(elem_dst_full, elem_src_full, elem_src_full_offset_len); memcpy(member_full_dst, member_full_src, member_full_src_offset_len);
i = elem_src_full_offset_len; i = member_full_src_offset_len;
} }
memcpy(&elem_dst_full[i], elem_dst, elem_dst_len + 1); memcpy(&member_full_dst[i], member_id_dst, member_id_dst_len + 1);
i += elem_dst_len; i += member_id_dst_len;
uint elem_src_full_offset_end = elem_src_full_offset_len + elem_src_len; const uint member_full_src_offset_end = member_full_src_offset_len + member_id_src_len;
if (elem_src_full[elem_src_full_offset_end] != '\0') { BLI_assert(DNA_member_id_offset_end(member_full_src + member_full_src_offset_len) ==
const int elem_full_tail_len = (elem_src_full_len - elem_src_full_offset_end); (member_full_src_offset_end - member_full_src_offset_len));
memcpy(&elem_dst_full[i], &elem_src_full[elem_src_full_offset_end], elem_full_tail_len + 1); if (member_full_src[member_full_src_offset_end] != '\0') {
i += elem_full_tail_len; const int member_full_tail_len = (member_full_src_len - member_full_src_offset_end);
memcpy(&member_full_dst[i],
&member_full_src[member_full_src_offset_end],
member_full_tail_len + 1);
i += member_full_tail_len;
} }
BLI_assert((strlen(elem_dst_full) == elem_final_len) && (i == elem_final_len)); BLI_assert((strlen(member_full_dst) == member_full_dst_len) && (i == member_full_dst_len));
UNUSED_VARS_NDEBUG(i); UNUSED_VARS_NDEBUG(i);
return elem_dst_full; return member_full_dst;
} }
/** \} */ /** \} */
@@ -181,16 +186,16 @@ static bool strhash_pair_cmp(const void *a, const void *b)
return (STREQ(pair_a[0], pair_b[0]) && STREQ(pair_a[1], pair_b[1])) ? false : true; return (STREQ(pair_a[0], pair_b[0]) && STREQ(pair_a[1], pair_b[1])) ? false : true;
} }
void DNA_alias_maps(enum eDNA_RenameDir version_dir, GHash **r_struct_map, GHash **r_elem_map) void DNA_alias_maps(enum eDNA_RenameDir version_dir, GHash **r_type_map, GHash **r_member_map)
{ {
GHash *struct_map_local = nullptr; GHash *type_map_local = nullptr;
if (r_struct_map) { if (r_type_map) {
const char *data[][2] = { const char *type_data[][2] = {
#define DNA_STRUCT_RENAME(old, new) {#old, #new}, #define DNA_STRUCT_RENAME(old, new) {#old, #new},
#define DNA_STRUCT_RENAME_ELEM(struct_name, old, new) #define DNA_STRUCT_RENAME_MEMBER(struct_name, old, new)
#include "dna_rename_defs.h" #include "dna_rename_defs.h"
#undef DNA_STRUCT_RENAME #undef DNA_STRUCT_RENAME
#undef DNA_STRUCT_RENAME_ELEM #undef DNA_STRUCT_RENAME_MEMBER
}; };
int elem_key, elem_val; int elem_key, elem_val;
@@ -202,40 +207,41 @@ void DNA_alias_maps(enum eDNA_RenameDir version_dir, GHash **r_struct_map, GHash
elem_key = 1; elem_key = 1;
elem_val = 0; elem_val = 0;
} }
GHash *struct_map = BLI_ghash_str_new_ex(__func__, ARRAY_SIZE(data)); GHash *type_map = BLI_ghash_str_new_ex(__func__, ARRAY_SIZE(type_data));
for (int i = 0; i < ARRAY_SIZE(data); i++) { for (int i = 0; i < ARRAY_SIZE(type_data); i++) {
BLI_ghash_insert(struct_map, (void *)data[i][elem_key], (void *)data[i][elem_val]); BLI_ghash_insert(type_map, (void *)type_data[i][elem_key], (void *)type_data[i][elem_val]);
} }
if (version_dir == DNA_RENAME_STATIC_FROM_ALIAS) { if (version_dir == DNA_RENAME_STATIC_FROM_ALIAS) {
const char *renames[][2] = { const char *renames[][2] = {
{"uint8_t", "uchar"}, /* {old, new}, like in #DNA_STRUCT_RENAME */
{"int16_t", "short"}, {"uchar", "uint8_t"},
{"uint16_t", "ushort"}, {"short", "int16_t"},
{"int32_t", "int"}, {"ushort", "uint16_t"},
{"uint32_t", "int"}, {"int", "int32_t"},
{"int", "uint32_t"},
}; };
for (int i = 0; i < ARRAY_SIZE(renames); i++) { for (int i = 0; i < ARRAY_SIZE(renames); i++) {
BLI_ghash_insert(struct_map, (void *)renames[i][0], (void *)renames[i][1]); BLI_ghash_insert(type_map, (void *)renames[i][elem_key], (void *)renames[i][elem_val]);
} }
} }
*r_struct_map = struct_map; *r_type_map = type_map;
/* We know the direction of this, for local use. */ /* We know the direction of this, for local use. */
struct_map_local = BLI_ghash_str_new_ex(__func__, ARRAY_SIZE(data)); type_map_local = BLI_ghash_str_new_ex(__func__, ARRAY_SIZE(type_data));
for (int i = 0; i < ARRAY_SIZE(data); i++) { for (int i = 0; i < ARRAY_SIZE(type_data); i++) {
BLI_ghash_insert(struct_map_local, (void *)data[i][1], (void *)data[i][0]); BLI_ghash_insert(type_map_local, (void *)type_data[i][1], (void *)type_data[i][0]);
} }
} }
if (r_elem_map != nullptr) { if (r_member_map != nullptr) {
const char *data[][3] = { const char *member_data[][3] = {
#define DNA_STRUCT_RENAME(old, new) #define DNA_STRUCT_RENAME(old, new)
#define DNA_STRUCT_RENAME_ELEM(struct_name, old, new) {#struct_name, #old, #new}, #define DNA_STRUCT_RENAME_MEMBER(struct_name, old, new) {#struct_name, #old, #new},
#include "dna_rename_defs.h" #include "dna_rename_defs.h"
#undef DNA_STRUCT_RENAME #undef DNA_STRUCT_RENAME
#undef DNA_STRUCT_RENAME_ELEM #undef DNA_STRUCT_RENAME_MEMBER
}; };
int elem_key, elem_val; int elem_key, elem_val;
@@ -247,21 +253,21 @@ void DNA_alias_maps(enum eDNA_RenameDir version_dir, GHash **r_struct_map, GHash
elem_key = 2; elem_key = 2;
elem_val = 1; elem_val = 1;
} }
GHash *elem_map = BLI_ghash_new_ex( GHash *member_map = BLI_ghash_new_ex(
strhash_pair_p, strhash_pair_cmp, __func__, ARRAY_SIZE(data)); strhash_pair_p, strhash_pair_cmp, __func__, ARRAY_SIZE(member_data));
for (int i = 0; i < ARRAY_SIZE(data); i++) { for (int i = 0; i < ARRAY_SIZE(member_data); i++) {
const char **str_pair = static_cast<const char **>( const char **str_pair = static_cast<const char **>(
MEM_mallocN(sizeof(char *) * 2, __func__)); MEM_mallocN(sizeof(char *) * 2, __func__));
str_pair[0] = static_cast<const char *>( str_pair[0] = static_cast<const char *>(
BLI_ghash_lookup_default(struct_map_local, data[i][0], (void *)data[i][0])); BLI_ghash_lookup_default(type_map_local, member_data[i][0], (void *)member_data[i][0]));
str_pair[1] = data[i][elem_key]; str_pair[1] = member_data[i][elem_key];
BLI_ghash_insert(elem_map, (void *)str_pair, (void *)data[i][elem_val]); BLI_ghash_insert(member_map, (void *)str_pair, (void *)member_data[i][elem_val]);
} }
*r_elem_map = elem_map; *r_member_map = member_map;
} }
if (struct_map_local) { if (type_map_local) {
BLI_ghash_free(struct_map_local, nullptr, nullptr); BLI_ghash_free(type_map_local, nullptr, nullptr);
} }
} }
@@ -273,15 +279,15 @@ void DNA_alias_maps(enum eDNA_RenameDir version_dir, GHash **r_struct_map, GHash
/** \name Struct Name Legacy Hack /** \name Struct Name Legacy Hack
* \{ */ * \{ */
/* WARNING: Only keep this for compatibility: *NEVER ADD NEW STRINGS HERE*.
*
* The renaming here isn't complete, references to the old struct names
* are still included in DNA, now fixing these struct names properly
* breaks forward compatibility. Leave these as-is, but don't add to them!
* See D4342#98780. */
const char *DNA_struct_rename_legacy_hack_static_from_alias(const char *name) const char *DNA_struct_rename_legacy_hack_static_from_alias(const char *name)
{ {
/* Only keep this for compatibility: *NEVER ADD NEW STRINGS HERE*.
*
* The renaming here isn't complete, references to the old struct names
* are still included in DNA, now fixing these struct names properly
* breaks forward compatibility. Leave these as-is, but don't add to them!
* See D4342#98780. */
/* 'bScreen' replaces the old IrisGL 'Screen' struct */ /* 'bScreen' replaces the old IrisGL 'Screen' struct */
if (STREQ("bScreen", name)) { if (STREQ("bScreen", name)) {
return "Screen"; return "Screen";

View File

@@ -16,53 +16,86 @@ struct GHash;
struct MemArena; struct MemArena;
/** /**
* Parses the `[n1][n2]...` on the end of an array name * Naming convention in this header:
* and returns the number of array elements `n1 * n2 ...`. * - `member_full` refers to the full definition of a struct member, including its prefixes (like
* the pointer `*` ones) and suffixes (like the `[]` array ones).
* - `member_id` (for member identifier) refers to the bare name of the struct member (e.g. `var`
* is the member identifier of the `*var[n1][n2]` full member).
*/ */
int DNA_elem_array_size(const char *str);
uint DNA_elem_id_offset_start(const char *elem_full);
uint DNA_elem_id_offset_end(const char *elem_full);
/** /**
* \a elem_dst must be at least the size of \a elem_src. * Parse the `[n1][n2]...` at the end of an array struct member.
*
* \return the total number of array elements `n1 * n2 ...`, or `1` if the member is not an array.
*/ */
uint DNA_elem_id_strip_copy(char *elem_dst, const char *elem_src); int DNA_member_array_num(const char *str);
uint DNA_elem_id_strip(char *elem);
/** Find the start offset of the member id (the name) within the full member definition. */
uint DNA_member_id_offset_start(const char *member_full);
/** /**
* Check if 'var' matches '*var[3]' for eg, * Find the end offset of the member id (the name) within the trimmed full member definition.
* return true if it does, with start/end offsets. *
* WARNING: Expects an input string which has already been trimmed from its non-identifier
* prefixes. E.g. passing `*var[n1]` to this function will return `0`, while passing `var[n1]` will
* return the expected `3` value.
*/ */
bool DNA_elem_id_match(const char *elem_search, uint DNA_member_id_offset_end(const char *member_full_trimmed);
int elem_search_len,
const char *elem_full,
uint *r_elem_full_offset);
/** /**
* \return a renamed DNA name, allocated from \a mem_arena. * Copy the member id part (the bare name) of the full source member into \a member_id_dst.
*
* \param member_id_dst destination char buffer, must be at least the size of \a member_src_full.
*/ */
char *DNA_elem_id_rename(struct MemArena *mem_arena, uint DNA_member_id_strip_copy(char *member_id_dst, const char *member_full_src);
const char *elem_src, /**
int elem_src_len, * Same as #DNA_member_id_strip_copy, but modifies the given \a member string in place.
const char *elem_dst, */
int elem_dst_len, uint DNA_member_id_strip(char *member);
const char *elem_src_full, /**
int elem_src_full_len, * Check if the member identifier given in \a member_id matches the full name given in \a
uint elem_src_full_offset_len); * member_full. E.g. `var` matches full names like `var` or `*var[3]`, but not `variable`.
*
* \return true if it does, with the start offset of the match in \a r_member_full_offset.
*/
bool DNA_member_id_match(const char *member_id,
int member_id_len,
const char *member_full,
uint *r_member_full_offset);
/**
* Rename a struct member to a different name.
*
* Replace the source member identifier (\a member_id_src) by the destination one
* (\a member_id_dst), while preserving the potential prefixes and suffixes.
*
* \return a renamed DNA full member, allocated from \a mem_arena.
*/
char *DNA_member_id_rename(struct MemArena *mem_arena,
const char *member_id_src,
int member_id_src_len,
const char *member_id_dst,
int member_id_dst_len,
const char *member_full_src,
int member_full_src_len,
uint member_full_src_offset_len);
/** /**
* When requesting version info, support both directions. * When requesting version info, support both directions.
*
* - 'Static' is the original name of the data, the one that is still stored in blendfiles DNA
* info (to avoid breaking forward compatibility).
* - 'Alias' is the current name of the data, the one used in current DNA definition code.
*/ */
enum eDNA_RenameDir { enum eDNA_RenameDir {
DNA_RENAME_STATIC_FROM_ALIAS = -1, DNA_RENAME_STATIC_FROM_ALIAS = -1,
DNA_RENAME_ALIAS_FROM_STATIC = 1, DNA_RENAME_ALIAS_FROM_STATIC = 1,
}; };
void DNA_alias_maps(enum eDNA_RenameDir version_dir, void DNA_alias_maps(enum eDNA_RenameDir version_dir,
struct GHash **r_struct_map, struct GHash **r_type_map,
struct GHash **r_elem_map); struct GHash **r_member_map);
const char *DNA_struct_rename_legacy_hack_alias_from_static(const char *name);
/** /**
* DNA Compatibility Hack. * DNA Compatibility Hack.
*/ */
const char *DNA_struct_rename_legacy_hack_alias_from_static(const char *name);
const char *DNA_struct_rename_legacy_hack_static_from_alias(const char *name); const char *DNA_struct_rename_legacy_hack_static_from_alias(const char *name);
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -61,11 +61,11 @@ static const char *includefiles[] = {
static MemArena *mem_arena = nullptr; static MemArena *mem_arena = nullptr;
static int max_data_size = 500000, max_array_len = 50000; static int max_data_size = 500000, max_array_len = 50000;
static int names_len = 0; static int members_num = 0;
static int types_len = 0; static int types_num = 0;
static int structs_len = 0; static int structs_num = 0;
/** At address `names[a]` is string `a`. */ /** At address `members[a]` is string `a`. */
static char **names; static char **members;
/** At address `types[a]` is string `a`. */ /** At address `types[a]` is string `a`. */
static char **types; static char **types;
/** At `types_size[a]` is the size of type `a` on this systems bitness (32 or 64). */ /** At `types_size[a]` is the size of type `a` on this systems bitness (32 or 64). */
@@ -80,18 +80,18 @@ static short *types_size_32;
static short *types_size_64; static short *types_size_64;
/** /**
* At `sp = structs[a]` is the first address of a struct definition: * At `sp = structs[a]` is the first address of a struct definition:
* - `sp[0]` is type number. * - `sp[0]` is type index.
* - `sp[1]` is the length of the element array (next). * - `sp[1]` is the length of the member array (next).
* - `sp[2]` sp[3] is [(type_index, name_index), ..] (number of pairs is defined by `sp[1]`), * - `sp[2]` sp[3] is [(type_index, member_index), ..] (number of pairs is defined by `sp[1]`),
*/ */
static short **structs, *structdata; static short **structs, *structdata;
/** Versioning data */ /** Versioning data */
static struct { static struct {
GHash *struct_map_alias_from_static; GHash *type_map_alias_from_static;
GHash *struct_map_static_from_alias; GHash *type_map_static_from_alias;
GHash *elem_map_alias_from_static; GHash *member_map_alias_from_static;
GHash *elem_map_static_from_alias; GHash *member_map_static_from_alias;
} g_version_data = {nullptr}; } g_version_data = {nullptr};
/** /**
@@ -128,25 +128,26 @@ void BLI_system_backtrace(FILE *fp)
* \{ */ * \{ */
/** /**
* Ensure type \c str to is in the #types array. * Ensure that type \a type_name is in the #types array.
* \param str: Struct name without any qualifiers. * \param type_name: Struct name without any qualifiers.
* \param size: The struct size in bytes. * \param size: The struct size in bytes.
* \return Index in the #types array. * \return Index in the #types array.
*/ */
static int add_type(const char *str, int size); static int add_type(const char *type_name, int size);
/** /**
* Ensure \c str is int the #names array. * Ensure that \a member_name is in the #members array.
* \param str: Struct member name which may include pointer prefix & array size. * \param member_name: Full struct member name (may include pointer prefix & array size).
* \return Index in the #names array. * \return Index in the #members array.
*/ */
static int add_name(const char *str); static int add_member(const char *member_name);
/** /**
* Search whether this structure type was already found, and if not, * Add a new structure definition, of type matching the given \a type_index.
* add it. *
* NOTE: there is no lookup performed here, a new struct definition is always added.
*/ */
static short *add_struct(int namecode); static short *add_struct(int type_index);
/** /**
* Remove comments from this buffer. Assumes that the buffer refers to * Remove comments from this buffer. Assumes that the buffer refers to
@@ -214,45 +215,46 @@ static bool match_identifier_and_advance(char **str_ptr, const char *identifier)
return false; return false;
} }
static const char *version_struct_static_from_alias(const char *str) static const char *version_struct_static_from_alias(const char *type_alias)
{ {
const char *str_test = static_cast<const char *>( const char *type_static = static_cast<const char *>(
BLI_ghash_lookup(g_version_data.struct_map_static_from_alias, str)); BLI_ghash_lookup(g_version_data.type_map_static_from_alias, type_alias));
if (str_test != nullptr) { if (type_static != nullptr) {
return str_test; return type_static;
} }
return str; return type_alias;
} }
static const char *version_struct_alias_from_static(const char *str) static const char *version_struct_alias_from_static(const char *type_static)
{ {
const char *str_test = static_cast<const char *>( const char *type_alias = static_cast<const char *>(
BLI_ghash_lookup(g_version_data.struct_map_alias_from_static, str)); BLI_ghash_lookup(g_version_data.type_map_alias_from_static, type_static));
if (str_test != nullptr) { if (type_alias != nullptr) {
return str_test; return type_alias;
} }
return str; return type_static;
} }
static const char *version_elem_static_from_alias(const int strct, const char *elem_alias_full) static const char *version_member_static_from_alias(const int type_index,
const char *member_alias_full)
{ {
const uint elem_alias_full_len = strlen(elem_alias_full); const uint member_alias_full_len = strlen(member_alias_full);
char *elem_alias = static_cast<char *>(alloca(elem_alias_full_len + 1)); char *member_alias = static_cast<char *>(alloca(member_alias_full_len + 1));
const int elem_alias_len = DNA_elem_id_strip_copy(elem_alias, elem_alias_full); const int member_alias_len = DNA_member_id_strip_copy(member_alias, member_alias_full);
const char *str_pair[2] = {types[strct], elem_alias}; const char *str_pair[2] = {types[type_index], member_alias};
const char *elem_static = static_cast<const char *>( const char *member_static = static_cast<const char *>(
BLI_ghash_lookup(g_version_data.elem_map_static_from_alias, str_pair)); BLI_ghash_lookup(g_version_data.member_map_static_from_alias, str_pair));
if (elem_static != nullptr) { if (member_static != nullptr) {
return DNA_elem_id_rename(mem_arena, return DNA_member_id_rename(mem_arena,
elem_alias, member_alias,
elem_alias_len, member_alias_len,
elem_static, member_static,
strlen(elem_static), strlen(member_static),
elem_alias_full, member_alias_full,
elem_alias_full_len, member_alias_full_len,
DNA_elem_id_offset_start(elem_alias_full)); DNA_member_id_offset_start(member_alias_full));
} }
return elem_alias_full; return member_alias_full;
} }
/** /**
@@ -263,7 +265,7 @@ static bool is_name_legal(const char *name)
{ {
const int name_size = strlen(name) + 1; const int name_size = strlen(name) + 1;
char *name_strip = static_cast<char *>(alloca(name_size)); char *name_strip = static_cast<char *>(alloca(name_size));
DNA_elem_id_strip_copy(name_strip, name); DNA_member_id_strip_copy(name_strip, name);
const char prefix[] = {'p', 'a', 'd'}; const char prefix[] = {'p', 'a', 'd'};
@@ -298,51 +300,51 @@ static bool is_name_legal(const char *name)
return true; return true;
} }
static int add_type(const char *str, int size) static int add_type(const char *type_name, int size)
{ {
/* first do validity check */ /* first do validity check */
if (str[0] == 0) { if (type_name[0] == 0) {
return -1; return -1;
} }
if (strchr(str, '*')) { if (strchr(type_name, '*')) {
/* NOTE: this is valid C syntax but we can't parse, complain! /* NOTE: this is valid C syntax but we can't parse, complain!
* `struct SomeStruct* some_var;` <-- correct but we can't handle right now. */ * `struct SomeStruct* some_var;` <-- correct but we can't handle right now. */
return -1; return -1;
} }
str = version_struct_static_from_alias(str); type_name = version_struct_static_from_alias(type_name);
/* search through type array */ /* search through type array */
for (int index = 0; index < types_len; index++) { for (int type_index = 0; type_index < types_num; type_index++) {
if (STREQ(str, types[index])) { if (STREQ(type_name, types[type_index])) {
if (size) { if (size) {
types_size_native[index] = size; types_size_native[type_index] = size;
types_size_32[index] = size; types_size_32[type_index] = size;
types_size_64[index] = size; types_size_64[type_index] = size;
types_align_32[index] = size; types_align_32[type_index] = size;
types_align_64[index] = size; types_align_64[type_index] = size;
} }
return index; return type_index;
} }
} }
/* append new type */ /* append new type */
const int str_size = strlen(str) + 1; const int type_name_len = strlen(type_name) + 1;
char *cp = static_cast<char *>(BLI_memarena_alloc(mem_arena, str_size)); char *cp = static_cast<char *>(BLI_memarena_alloc(mem_arena, type_name_len));
memcpy(cp, str, str_size); memcpy(cp, type_name, type_name_len);
types[types_len] = cp; types[types_num] = cp;
types_size_native[types_len] = size; types_size_native[types_num] = size;
types_size_32[types_len] = size; types_size_32[types_num] = size;
types_size_64[types_len] = size; types_size_64[types_num] = size;
types_align_32[types_len] = size; types_align_32[types_num] = size;
types_align_64[types_len] = size; types_align_64[types_num] = size;
if (types_len >= max_array_len) { if (types_num >= max_array_len) {
printf("too many types\n"); printf("too many types\n");
return types_len - 1; return types_num - 1;
} }
types_len++; types_num++;
return types_len - 1; return types_num - 1;
} }
/** /**
@@ -351,30 +353,30 @@ static int add_type(const char *str, int size)
* we add name and type at the same time... There are two special * we add name and type at the same time... There are two special
* cases, unfortunately. These are explicitly checked. * cases, unfortunately. These are explicitly checked.
*/ */
static int add_name(const char *str) static int add_member(const char *member_name)
{ {
char buf[255]; /* stupid limit, change it :) */ char buf[255]; /* stupid limit, change it :) */
const char *name; const char *name;
additional_slen_offset = 0; additional_slen_offset = 0;
if (str[0] == 0 /* || (str[1] == 0) */) { if (member_name[0] == 0 /* || (member_name[1] == 0) */) {
return -1; return -1;
} }
if (str[0] == '(' && str[1] == '*') { if (member_name[0] == '(' && member_name[1] == '*') {
/* We handle function pointer and special array cases here, e.g. /* We handle function pointer and special array cases here, e.g.
* `void (*function)(...)` and `float (*array)[..]`. the array case * `void (*function)(...)` and `float (*array)[..]`. the array case
* name is still converted to (array *)() though because it is that * name is still converted to (array *)() though because it is that
* way in old DNA too, and works correct with #DNA_struct_member_size. */ * way in old DNA too, and works correct with #DNA_struct_member_size. */
int isfuncptr = (strchr(str + 1, '(')) != nullptr; int isfuncptr = (strchr(member_name + 1, '(')) != nullptr;
DEBUG_PRINTF(3, "\t\t\t\t*** Function pointer or multidim array pointer found\n"); DEBUG_PRINTF(3, "\t\t\t\t*** Function pointer or multidim array pointer found\n");
/* function-pointer: transform the type (sometimes). */ /* function-pointer: transform the type (sometimes). */
int i = 0; int i = 0;
while (str[i] != ')') { while (member_name[i] != ')') {
buf[i] = str[i]; buf[i] = member_name[i];
i++; i++;
} }
@@ -386,38 +388,38 @@ static int add_name(const char *str)
DEBUG_PRINTF(3, "first brace after offset %d\n", i); DEBUG_PRINTF(3, "first brace after offset %d\n", i);
j++; /* j beyond closing brace ? */ j++; /* j beyond closing brace ? */
while ((str[j] != 0) && (str[j] != ')')) { while ((member_name[j] != 0) && (member_name[j] != ')')) {
DEBUG_PRINTF(3, "seen %c (%d)\n", str[j], str[j]); DEBUG_PRINTF(3, "seen %c (%d)\n", member_name[j], member_name[j]);
j++; j++;
} }
DEBUG_PRINTF(3, DEBUG_PRINTF(3,
"seen %c (%d)\n" "seen %c (%d)\n"
"special after offset%d\n", "special after offset%d\n",
str[j], member_name[j],
str[j], member_name[j],
j); j);
if (!isfuncptr) { if (!isfuncptr) {
/* multidimensional array pointer case */ /* multidimensional array pointer case */
if (str[j] == 0) { if (member_name[j] == 0) {
DEBUG_PRINTF(3, "offsetting for multi-dimensional array pointer\n"); DEBUG_PRINTF(3, "offsetting for multi-dimensional array pointer\n");
} }
else { else {
printf("Error during tokenizing multi-dimensional array pointer\n"); printf("Error during tokenizing multi-dimensional array pointer\n");
} }
} }
else if (str[j] == 0) { else if (member_name[j] == 0) {
DEBUG_PRINTF(3, "offsetting for space\n"); DEBUG_PRINTF(3, "offsetting for space\n");
/* get additional offset */ /* get additional offset */
int k = 0; int k = 0;
while (str[j] != ')') { while (member_name[j] != ')') {
j++; j++;
k++; k++;
} }
DEBUG_PRINTF(3, "extra offset %d\n", k); DEBUG_PRINTF(3, "extra offset %d\n", k);
additional_slen_offset = k; additional_slen_offset = k;
} }
else if (str[j] == ')') { else if (member_name[j] == ')') {
DEBUG_PRINTF(3, "offsetting for brace\n"); DEBUG_PRINTF(3, "offsetting for brace\n");
/* don't get extra offset */ /* don't get extra offset */
} }
@@ -460,13 +462,13 @@ static int add_name(const char *str)
} }
else { else {
/* normal field: old code */ /* normal field: old code */
name = str; name = member_name;
} }
/* search name array */ /* search name array */
for (int nr = 0; nr < names_len; nr++) { for (int member_index = 0; member_index < members_num; member_index++) {
if (STREQ(name, names[nr])) { if (STREQ(name, members[member_index])) {
return nr; return member_index;
} }
} }
@@ -476,39 +478,39 @@ static int add_name(const char *str)
} }
/* Append new name. */ /* Append new name. */
const int name_size = strlen(name) + 1; const int name_len = strlen(name) + 1;
char *cp = static_cast<char *>(BLI_memarena_alloc(mem_arena, name_size)); char *cp = static_cast<char *>(BLI_memarena_alloc(mem_arena, name_len));
memcpy(cp, name, name_size); memcpy(cp, name, name_len);
names[names_len] = cp; members[members_num] = cp;
if (names_len >= max_array_len) { if (members_num >= max_array_len) {
printf("too many names\n"); printf("too many names\n");
return names_len - 1; return members_num - 1;
} }
names_len++; members_num++;
return names_len - 1; return members_num - 1;
} }
static short *add_struct(int namecode) static short *add_struct(int type_index)
{ {
if (structs_len == 0) { if (structs_num == 0) {
structs[0] = structdata; structs[0] = structdata;
} }
else { else {
short *sp = structs[structs_len - 1]; short *sp = structs[structs_num - 1];
const int len = sp[1]; const int len = sp[1];
structs[structs_len] = sp + 2 * len + 2; structs[structs_num] = sp + 2 * len + 2;
} }
short *sp = structs[structs_len]; short *sp = structs[structs_num];
sp[0] = namecode; sp[0] = type_index;
if (structs_len >= max_array_len) { if (structs_num >= max_array_len) {
printf("too many structs\n"); printf("too many structs\n");
return sp; return sp;
} }
structs_len++; structs_num++;
return sp; return sp;
} }
@@ -746,16 +748,16 @@ static int convert_include(const char *filepath)
/* we've got a struct name when... */ /* we've got a struct name when... */
if (match_identifier(md1 - 7, "struct")) { if (match_identifier(md1 - 7, "struct")) {
const int strct = add_type(md1, 0); const int struct_type_index = add_type(md1, 0);
if (strct == -1) { if (struct_type_index == -1) {
fprintf(stderr, "File '%s' contains struct we can't parse \"%s\"\n", filepath, md1); fprintf(stderr, "File '%s' contains struct we can't parse \"%s\"\n", filepath, md1);
return 1; return 1;
} }
short *structpoin = add_struct(strct); short *structpoin = add_struct(struct_type_index);
short *sp = structpoin + 2; short *sp = structpoin + 2;
DEBUG_PRINTF(1, "\t|\t|-- detected struct %s\n", types[strct]); DEBUG_PRINTF(1, "\t|\t|-- detected struct %s\n", types[struct_type_index]);
/* first lets make it all nice strings */ /* first lets make it all nice strings */
md1 = md + 1; md1 = md + 1;
@@ -807,8 +809,8 @@ static int convert_include(const char *filepath)
md1); md1);
return -1; return -1;
} }
const int type = add_type(md1, 0); const int member_type_index = add_type(md1, 0);
if (type == -1) { if (member_type_index == -1) {
fprintf( fprintf(
stderr, "File '%s' contains struct we can't parse \"%s\"\n", filepath, md1); stderr, "File '%s' contains struct we can't parse \"%s\"\n", filepath, md1);
return 1; return 1;
@@ -832,7 +834,8 @@ static int convert_include(const char *filepath)
if (md1[slen - 1] == ';') { if (md1[slen - 1] == ';') {
md1[slen - 1] = 0; md1[slen - 1] = 0;
const int name = add_name(version_elem_static_from_alias(strct, md1)); const int name = add_member(
version_member_static_from_alias(struct_type_index, md1));
if (name == -1) { if (name == -1) {
fprintf(stderr, fprintf(stderr,
"File '%s' contains struct with name that can't be added \"%s\"\n", "File '%s' contains struct with name that can't be added \"%s\"\n",
@@ -841,11 +844,11 @@ static int convert_include(const char *filepath)
return 1; return 1;
} }
slen += additional_slen_offset; slen += additional_slen_offset;
sp[0] = type; sp[0] = member_type_index;
sp[1] = name; sp[1] = name;
if (names[name] != nullptr) { if (members[name] != nullptr) {
DEBUG_PRINTF(1, "%s |", names[name]); DEBUG_PRINTF(1, "%s |", members[name]);
} }
structpoin[1]++; structpoin[1]++;
@@ -855,7 +858,8 @@ static int convert_include(const char *filepath)
break; break;
} }
const int name = add_name(version_elem_static_from_alias(strct, md1)); const int name = add_member(
version_member_static_from_alias(struct_type_index, md1));
if (name == -1) { if (name == -1) {
fprintf(stderr, fprintf(stderr,
"File '%s' contains struct with name that can't be added \"%s\"\n", "File '%s' contains struct with name that can't be added \"%s\"\n",
@@ -865,10 +869,10 @@ static int convert_include(const char *filepath)
} }
slen += additional_slen_offset; slen += additional_slen_offset;
sp[0] = type; sp[0] = member_type_index;
sp[1] = name; sp[1] = name;
if (names[name] != nullptr) { if (members[name] != nullptr) {
DEBUG_PRINTF(1, "%s ||", names[name]); DEBUG_PRINTF(1, "%s ||", members[name]);
} }
structpoin[1]++; structpoin[1]++;
@@ -895,15 +899,19 @@ static int convert_include(const char *filepath)
return 0; return 0;
} }
static bool check_field_alignment( static bool check_field_alignment(int firststruct,
int firststruct, int structtype, int type, int len, const char *name, const char *detail) int struct_type_index,
int type,
int len,
const char *name,
const char *detail)
{ {
bool result = true; bool result = true;
if (type < firststruct && types_size_native[type] > 4 && (len % 8)) { if (type < firststruct && types_size_native[type] > 4 && (len % 8)) {
fprintf(stderr, fprintf(stderr,
"Align 8 error (%s) in struct: %s %s (add %d padding bytes)\n", "Align 8 error (%s) in struct: %s %s (add %d padding bytes)\n",
detail, detail,
types[structtype], types[struct_type_index],
name, name,
len % 8); len % 8);
result = false; result = false;
@@ -912,7 +920,7 @@ static bool check_field_alignment(
fprintf(stderr, fprintf(stderr,
"Align 4 error (%s) in struct: %s %s (add %d padding bytes)\n", "Align 4 error (%s) in struct: %s %s (add %d padding bytes)\n",
detail, detail,
types[structtype], types[struct_type_index],
name, name,
len % 4); len % 4);
result = false; result = false;
@@ -921,7 +929,7 @@ static bool check_field_alignment(
fprintf(stderr, fprintf(stderr,
"Align 2 error (%s) in struct: %s %s (add %d padding bytes)\n", "Align 2 error (%s) in struct: %s %s (add %d padding bytes)\n",
detail, detail,
types[structtype], types[struct_type_index],
name, name,
len % 2); len % 2);
result = false; result = false;
@@ -948,19 +956,19 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
fprintf(file_verify, "\n"); fprintf(file_verify, "\n");
/* Multiple iterations to handle nested structs. */ /* Multiple iterations to handle nested structs. */
int unknown = structs_len; int unknown = structs_num;
while (unknown) { while (unknown) {
const int lastunknown = unknown; const int lastunknown = unknown;
unknown = 0; unknown = 0;
/* check all structs... */ /* check all structs... */
for (int a = 0; a < structs_len; a++) { for (int a = 0; a < structs_num; a++) {
const short *structpoin = structs[a]; const short *structpoin = structs[a];
const int structtype = structpoin[0]; const int struct_type_index = structpoin[0];
const char *structname = version_struct_alias_from_static(types[structtype]); const char *struct_type_name = version_struct_alias_from_static(types[struct_type_index]);
/* when length is not known... */ /* when length is not known... */
if (types_size_native[structtype] == 0) { if (types_size_native[struct_type_index] == 0) {
const short *sp = structpoin + 2; const short *sp = structpoin + 2;
int size_native = 0; int size_native = 0;
@@ -970,10 +978,10 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
int max_align_32 = 0; int max_align_32 = 0;
int max_align_64 = 0; int max_align_64 = 0;
/* check all elements in struct */ /* check all members in struct */
for (int b = 0; b < structpoin[1]; b++, sp += 2) { for (int b = 0; b < structpoin[1]; b++, sp += 2) {
int type = sp[0]; int type = sp[0];
const char *cp = names[sp[1]]; const char *cp = members[sp[1]];
int namelen = int(strlen(cp)); int namelen = int(strlen(cp));
/* Write size verification to file. */ /* Write size verification to file. */
@@ -983,14 +991,14 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
char name_static[1024]; char name_static[1024];
BLI_assert(sizeof(name_static) > namelen); BLI_assert(sizeof(name_static) > namelen);
DNA_elem_id_strip_copy(name_static, cp); DNA_member_id_strip_copy(name_static, cp);
const char *str_pair[2] = {types[structtype], name_static}; const char *str_pair[2] = {types[struct_type_index], name_static};
const char *name_alias = static_cast<const char *>( const char *name_alias = static_cast<const char *>(
BLI_ghash_lookup(g_version_data.elem_map_alias_from_static, str_pair)); BLI_ghash_lookup(g_version_data.member_map_alias_from_static, str_pair));
fprintf(file_verify, fprintf(file_verify,
"BLI_STATIC_ASSERT(offsetof(struct %s, %s) == %d, \"DNA member offset " "BLI_STATIC_ASSERT(offsetof(struct %s, %s) == %d, \"DNA member offset "
"verify\");\n", "verify\");\n",
structname, struct_type_name,
name_alias ? name_alias : name_static, name_alias ? name_alias : name_static,
size_native); size_native);
} }
@@ -1000,13 +1008,13 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
/* has the name an extra length? (array) */ /* has the name an extra length? (array) */
int mul = 1; int mul = 1;
if (cp[namelen - 1] == ']') { if (cp[namelen - 1] == ']') {
mul = DNA_elem_array_size(cp); mul = DNA_member_array_num(cp);
} }
if (mul == 0) { if (mul == 0) {
fprintf(stderr, fprintf(stderr,
"Zero array size found or could not parse %s: '%.*s'\n", "Zero array size found or could not parse %s: '%.*s'\n",
types[structtype], types[struct_type_index],
namelen + 1, namelen + 1,
cp); cp);
dna_error = true; dna_error = true;
@@ -1017,7 +1025,7 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
if (size_native % 4) { if (size_native % 4) {
fprintf(stderr, fprintf(stderr,
"Align pointer error in struct (size_native 4): %s %s\n", "Align pointer error in struct (size_native 4): %s %s\n",
types[structtype], types[struct_type_index],
cp); cp);
dna_error = true; dna_error = true;
} }
@@ -1026,7 +1034,7 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
if (size_native % 8) { if (size_native % 8) {
fprintf(stderr, fprintf(stderr,
"Align pointer error in struct (size_native 8): %s %s\n", "Align pointer error in struct (size_native 8): %s %s\n",
types[structtype], types[struct_type_index],
cp); cp);
dna_error = true; dna_error = true;
} }
@@ -1035,7 +1043,7 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
if (size_64 % 8) { if (size_64 % 8) {
fprintf(stderr, fprintf(stderr,
"Align pointer error in struct (size_64 8): %s %s\n", "Align pointer error in struct (size_64 8): %s %s\n",
types[structtype], types[struct_type_index],
cp); cp);
dna_error = true; dna_error = true;
} }
@@ -1051,7 +1059,7 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
* to be found for "float var [3]" */ * to be found for "float var [3]" */
fprintf(stderr, fprintf(stderr,
"Parse error in struct, invalid member name: %s %s\n", "Parse error in struct, invalid member name: %s %s\n",
types[structtype], types[struct_type_index],
cp); cp);
dna_error = true; dna_error = true;
} }
@@ -1059,13 +1067,13 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
/* has the name an extra length? (array) */ /* has the name an extra length? (array) */
int mul = 1; int mul = 1;
if (cp[namelen - 1] == ']') { if (cp[namelen - 1] == ']') {
mul = DNA_elem_array_size(cp); mul = DNA_member_array_num(cp);
} }
if (mul == 0) { if (mul == 0) {
fprintf(stderr, fprintf(stderr,
"Zero array size found or could not parse %s: '%.*s'\n", "Zero array size found or could not parse %s: '%.*s'\n",
types[structtype], types[struct_type_index],
namelen + 1, namelen + 1,
cp); cp);
dna_error = true; dna_error = true;
@@ -1077,7 +1085,7 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
fprintf(stderr, fprintf(stderr,
"Align struct error: %s::%s (starts at %d on the native platform; " "Align struct error: %s::%s (starts at %d on the native platform; "
"%d %% %zu = %d bytes)\n", "%d %% %zu = %d bytes)\n",
types[structtype], types[struct_type_index],
cp, cp,
size_native, size_native,
size_native, size_native,
@@ -1088,10 +1096,14 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
} }
/* Check 2-4-8 aligned. */ /* Check 2-4-8 aligned. */
if (!check_field_alignment(firststruct, structtype, type, size_32, cp, "32 bit")) { if (!check_field_alignment(
firststruct, struct_type_index, type, size_32, cp, "32 bit"))
{
dna_error = true; dna_error = true;
} }
if (!check_field_alignment(firststruct, structtype, type, size_64, cp, "64 bit")) { if (!check_field_alignment(
firststruct, struct_type_index, type, size_64, cp, "64 bit"))
{
dna_error = true; dna_error = true;
} }
@@ -1113,11 +1125,11 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
unknown++; unknown++;
} }
else { else {
types_size_native[structtype] = size_native; types_size_native[struct_type_index] = size_native;
types_size_32[structtype] = size_32; types_size_32[struct_type_index] = size_32;
types_size_64[structtype] = size_64; types_size_64[struct_type_index] = size_64;
types_align_32[structtype] = max_align_32; types_align_32[struct_type_index] = max_align_32;
types_align_64[structtype] = max_align_64; types_align_64[struct_type_index] = max_align_64;
/* Sanity check 1: alignment should never be 0. */ /* Sanity check 1: alignment should never be 0. */
BLI_assert(max_align_32); BLI_assert(max_align_32);
@@ -1135,12 +1147,12 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
if ((size_64 % max_align_64 == 0) && (size_32 % max_align_32 == 4)) { if ((size_64 % max_align_64 == 0) && (size_32 % max_align_32 == 4)) {
fprintf(stderr, fprintf(stderr,
"Sizeerror in 32 bit struct: %s (add padding pointer)\n", "Sizeerror in 32 bit struct: %s (add padding pointer)\n",
types[structtype]); types[struct_type_index]);
} }
else { else {
fprintf(stderr, fprintf(stderr,
"Sizeerror in 32 bit struct: %s (add %d bytes)\n", "Sizeerror in 32 bit struct: %s (add %d bytes)\n",
types[structtype], types[struct_type_index],
max_align_32 - (size_32 % max_align_32)); max_align_32 - (size_32 % max_align_32));
} }
dna_error = true; dna_error = true;
@@ -1149,7 +1161,7 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
if (size_64 % max_align_64) { if (size_64 % max_align_64) {
fprintf(stderr, fprintf(stderr,
"Sizeerror in 64 bit struct: %s (add %d bytes)\n", "Sizeerror in 64 bit struct: %s (add %d bytes)\n",
types[structtype], types[struct_type_index],
max_align_64 - (size_64 % max_align_64)); max_align_64 - (size_64 % max_align_64));
dna_error = true; dna_error = true;
} }
@@ -1157,7 +1169,7 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
if (size_native % 4 && !ELEM(size_native, 1, 2)) { if (size_native % 4 && !ELEM(size_native, 1, 2)) {
fprintf(stderr, fprintf(stderr,
"Sizeerror 4 in struct: %s (add %d bytes)\n", "Sizeerror 4 in struct: %s (add %d bytes)\n",
types[structtype], types[struct_type_index],
size_native % 4); size_native % 4);
dna_error = true; dna_error = true;
} }
@@ -1165,7 +1177,7 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
/* Write size verification to file. */ /* Write size verification to file. */
fprintf(file_verify, fprintf(file_verify,
"BLI_STATIC_ASSERT(sizeof(struct %s) == %d, \"DNA struct size verify\");\n\n", "BLI_STATIC_ASSERT(sizeof(struct %s) == %d, \"DNA struct size verify\");\n\n",
structname, struct_type_name,
size_native); size_native);
} }
} }
@@ -1182,7 +1194,7 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
if (debugSDNA) { if (debugSDNA) {
fprintf(stderr, "*** Known structs :\n"); fprintf(stderr, "*** Known structs :\n");
for (int a = 0; a < structs_len; a++) { for (int a = 0; a < structs_num; a++) {
const short *structpoin = structs[a]; const short *structpoin = structs[a];
const int structtype = structpoin[0]; const int structtype = structpoin[0];
@@ -1195,7 +1207,7 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
fprintf(stderr, "*** Unknown structs :\n"); fprintf(stderr, "*** Unknown structs :\n");
for (int a = 0; a < structs_len; a++) { for (int a = 0; a < structs_num; a++) {
const short *structpoin = structs[a]; const short *structpoin = structs[a];
const int structtype = structpoin[0]; const int structtype = structpoin[0];
@@ -1230,14 +1242,14 @@ static void dna_write(FILE *file, const void *pntr, const int size)
void print_struct_sizes() void print_struct_sizes()
{ {
int unknown = structs_len; int unknown = structs_num;
printf("\n\n*** All detected structs:\n"); printf("\n\n*** All detected structs:\n");
while (unknown) { while (unknown) {
unknown = 0; unknown = 0;
/* check all structs... */ /* check all structs... */
for (int a = 0; a < structs_len; a++) { for (int a = 0; a < structs_num; a++) {
const short *structpoin = structs[a]; const short *structpoin = structs[a];
const int structtype = structpoin[0]; const int structtype = structpoin[0];
printf("\t%s\t:%d\n", types[structtype], types_size_native[structtype]); printf("\t%s\t:%d\n", types[structtype], types_size_native[structtype]);
@@ -1263,7 +1275,7 @@ static int make_structDNA(const char *base_directory,
structdata = static_cast<short *>(MEM_callocN(max_data_size, "structdata")); structdata = static_cast<short *>(MEM_callocN(max_data_size, "structdata"));
/* a maximum of 5000 variables, must be sufficient? */ /* a maximum of 5000 variables, must be sufficient? */
names = static_cast<char **>(MEM_callocN(sizeof(char *) * max_array_len, "names")); members = static_cast<char **>(MEM_callocN(sizeof(char *) * max_array_len, "names"));
types = static_cast<char **>(MEM_callocN(sizeof(char *) * max_array_len, "types")); types = static_cast<char **>(MEM_callocN(sizeof(char *) * max_array_len, "types"));
types_size_native = static_cast<short *>( types_size_native = static_cast<short *>(
MEM_callocN(sizeof(short) * max_array_len, "types_size_native")); MEM_callocN(sizeof(short) * max_array_len, "types_size_native"));
@@ -1280,11 +1292,11 @@ static int make_structDNA(const char *base_directory,
/* Build versioning data */ /* Build versioning data */
DNA_alias_maps(DNA_RENAME_ALIAS_FROM_STATIC, DNA_alias_maps(DNA_RENAME_ALIAS_FROM_STATIC,
&g_version_data.struct_map_alias_from_static, &g_version_data.type_map_alias_from_static,
&g_version_data.elem_map_alias_from_static); &g_version_data.member_map_alias_from_static);
DNA_alias_maps(DNA_RENAME_STATIC_FROM_ALIAS, DNA_alias_maps(DNA_RENAME_STATIC_FROM_ALIAS,
&g_version_data.struct_map_static_from_alias, &g_version_data.type_map_static_from_alias,
&g_version_data.elem_map_static_from_alias); &g_version_data.member_map_static_from_alias);
/** /**
* Insertion of all known types. * Insertion of all known types.
@@ -1312,7 +1324,7 @@ static int make_structDNA(const char *base_directory,
add_type("int8_t", 1); /* SDNA_TYPE_INT8 */ add_type("int8_t", 1); /* SDNA_TYPE_INT8 */
/* the defines above shouldn't be output in the padding file... */ /* the defines above shouldn't be output in the padding file... */
const int firststruct = types_len; const int firststruct = types_num;
/* Add all include files defined in the global array. /* Add all include files defined in the global array.
* Since the internal file+path name buffer has limited length, * Since the internal file+path name buffer has limited length,
@@ -1343,30 +1355,29 @@ static int make_structDNA(const char *base_directory,
if (debugSDNA > 1) { if (debugSDNA > 1) {
int a, b; int a, b;
// short *elem; // short *elem;
short num_types; short struct_members_num;
printf("names_len %d types_len %d structs_len %d\n", names_len, types_len, structs_len); printf("names_len %d types_len %d structs_len %d\n", members_num, types_num, structs_num);
for (a = 0; a < names_len; a++) { for (a = 0; a < members_num; a++) {
printf(" %s\n", names[a]); printf(" %s\n", members[a]);
} }
printf("\n"); printf("\n");
const short *sp = types_size_native; const short *sp = types_size_native;
for (a = 0; a < types_len; a++, sp++) { for (a = 0; a < types_num; a++, sp++) {
printf(" %s %d\n", types[a], *sp); printf(" %s %d\n", types[a], *sp);
} }
printf("\n"); printf("\n");
for (a = 0; a < structs_len; a++) { for (a = 0; a < structs_num; a++) {
sp = structs[a]; sp = structs[a];
printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], types_size_native[sp[0]]); printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], types_size_native[sp[0]]);
num_types = sp[1]; struct_members_num = sp[1];
sp += 2; sp += 2;
/* ? num_types was elem? */ for (b = 0; b < struct_members_num; b++, sp += 2) {
for (b = 0; b < num_types; b++, sp += 2) {
printf(" %s %s allign32:%d, allign64:%d\n", printf(" %s %s allign32:%d, allign64:%d\n",
types[sp[0]], types[sp[0]],
names[sp[1]], members[sp[1]],
types_align_32[sp[0]], types_align_32[sp[0]],
types_align_64[sp[0]]); types_align_64[sp[0]]);
} }
@@ -1377,7 +1388,7 @@ static int make_structDNA(const char *base_directory,
DEBUG_PRINTF(0, "Writing file ... "); DEBUG_PRINTF(0, "Writing file ... ");
if (names_len == 0 || structs_len == 0) { if (members_num == 0 || structs_num == 0) {
/* pass */ /* pass */
} }
else { else {
@@ -1387,14 +1398,14 @@ static int make_structDNA(const char *base_directory,
/* write names */ /* write names */
dna_write(file, "NAME", 4); dna_write(file, "NAME", 4);
int len = names_len; int len = members_num;
dna_write(file, &len, 4); dna_write(file, &len, 4);
/* write array */ /* write array */
len = 0; len = 0;
for (int nr = 0; nr < names_len; nr++) { for (int member_index = 0; member_index < members_num; member_index++) {
int name_size = strlen(names[nr]) + 1; int member_len = strlen(members[member_index]) + 1;
dna_write(file, names[nr], name_size); dna_write(file, members[member_index], member_len);
len += name_size; len += member_len;
} }
int len_align = (len + 3) & ~3; int len_align = (len + 3) & ~3;
if (len != len_align) { if (len != len_align) {
@@ -1403,14 +1414,14 @@ static int make_structDNA(const char *base_directory,
/* write TYPES */ /* write TYPES */
dna_write(file, "TYPE", 4); dna_write(file, "TYPE", 4);
len = types_len; len = types_num;
dna_write(file, &len, 4); dna_write(file, &len, 4);
/* write array */ /* write array */
len = 0; len = 0;
for (int nr = 0; nr < types_len; nr++) { for (int type_index = 0; type_index < types_num; type_index++) {
int type_size = strlen(types[nr]) + 1; int type_len = strlen(types[type_index]) + 1;
dna_write(file, types[nr], type_size); dna_write(file, types[type_index], type_len);
len += type_size; len += type_len;
} }
len_align = (len + 3) & ~3; len_align = (len + 3) & ~3;
if (len != len_align) { if (len != len_align) {
@@ -1420,19 +1431,19 @@ static int make_structDNA(const char *base_directory,
/* WRITE TYPELENGTHS */ /* WRITE TYPELENGTHS */
dna_write(file, "TLEN", 4); dna_write(file, "TLEN", 4);
len = 2 * types_len; len = 2 * types_num;
if (types_len & 1) { if (types_num & 1) {
len += 2; len += 2;
} }
dna_write(file, types_size_native, len); dna_write(file, types_size_native, len);
/* WRITE STRUCTS */ /* WRITE STRUCTS */
dna_write(file, "STRC", 4); dna_write(file, "STRC", 4);
len = structs_len; len = structs_num;
dna_write(file, &len, 4); dna_write(file, &len, 4);
/* calc datablock size */ /* calc datablock size */
const short *sp = structs[structs_len - 1]; const short *sp = structs[structs_num - 1];
sp += 2 + 2 * (sp[1]); sp += 2 + 2 * (sp[1]);
len = intptr_t((char *)sp - (char *)structs[0]); len = intptr_t((char *)sp - (char *)structs[0]);
len = (len + 3) & ~3; len = (len + 3) & ~3;
@@ -1446,46 +1457,46 @@ static int make_structDNA(const char *base_directory,
fprintf(file_offsets, "#pragma once\n"); fprintf(file_offsets, "#pragma once\n");
fprintf(file_offsets, "#define SDNA_TYPE_FROM_STRUCT(id) _SDNA_TYPE_##id\n"); fprintf(file_offsets, "#define SDNA_TYPE_FROM_STRUCT(id) _SDNA_TYPE_##id\n");
fprintf(file_offsets, "enum {\n"); fprintf(file_offsets, "enum {\n");
for (int i = 0; i < structs_len; i++) { for (int i = 0; i < structs_num; i++) {
const short *structpoin = structs[i]; const short *structpoin = structs[i];
const int structtype = structpoin[0]; const int struct_type_index = structpoin[0];
fprintf(file_offsets, fprintf(file_offsets,
"\t_SDNA_TYPE_%s = %d,\n", "\t_SDNA_TYPE_%s = %d,\n",
version_struct_alias_from_static(types[structtype]), version_struct_alias_from_static(types[struct_type_index]),
i); i);
} }
fprintf(file_offsets, "\tSDNA_TYPE_MAX = %d,\n", structs_len); fprintf(file_offsets, "\tSDNA_TYPE_MAX = %d,\n", structs_num);
fprintf(file_offsets, "};\n\n"); fprintf(file_offsets, "};\n\n");
} }
/* Check versioning errors which could cause duplicate names, /* Check versioning errors which could cause duplicate names,
* do last because names are stripped. */ * do last because names are stripped. */
{ {
GSet *names_unique = BLI_gset_str_new_ex(__func__, 512); GSet *members_unique = BLI_gset_str_new_ex(__func__, 512);
for (int struct_nr = 0; struct_nr < structs_len; struct_nr++) { for (int struct_index = 0; struct_index < structs_num; struct_index++) {
const short *sp = structs[struct_nr]; const short *sp = structs[struct_index];
const char *struct_name = types[sp[0]]; const char *type = types[sp[0]];
const int len = sp[1]; const int len = sp[1];
sp += 2; sp += 2;
for (int a = 0; a < len; a++, sp += 2) { for (int a = 0; a < len; a++, sp += 2) {
char *name = names[sp[1]]; char *member = members[sp[1]];
DNA_elem_id_strip(name); DNA_member_id_strip(member);
if (!BLI_gset_add(names_unique, name)) { if (!BLI_gset_add(members_unique, member)) {
fprintf(stderr, fprintf(stderr,
"Error: duplicate name found '%s.%s', " "Error: duplicate name found '%s.%s', "
"likely cause is 'dna_rename_defs.h'\n", "likely cause is 'dna_rename_defs.h'\n",
struct_name, type,
name); member);
return 1; return 1;
} }
} }
BLI_gset_clear(names_unique, nullptr); BLI_gset_clear(members_unique, nullptr);
} }
BLI_gset_free(names_unique, nullptr); BLI_gset_free(members_unique, nullptr);
} }
MEM_freeN(structdata); MEM_freeN(structdata);
MEM_freeN(names); MEM_freeN(members);
MEM_freeN(types); MEM_freeN(types);
MEM_freeN(types_size_native); MEM_freeN(types_size_native);
MEM_freeN(types_size_32); MEM_freeN(types_size_32);
@@ -1496,10 +1507,10 @@ static int make_structDNA(const char *base_directory,
BLI_memarena_free(mem_arena); BLI_memarena_free(mem_arena);
BLI_ghash_free(g_version_data.struct_map_alias_from_static, nullptr, nullptr); BLI_ghash_free(g_version_data.type_map_alias_from_static, nullptr, nullptr);
BLI_ghash_free(g_version_data.struct_map_static_from_alias, nullptr, nullptr); BLI_ghash_free(g_version_data.type_map_static_from_alias, nullptr, nullptr);
BLI_ghash_free(g_version_data.elem_map_static_from_alias, MEM_freeN, nullptr); BLI_ghash_free(g_version_data.member_map_static_from_alias, MEM_freeN, nullptr);
BLI_ghash_free(g_version_data.elem_map_alias_from_static, MEM_freeN, nullptr); BLI_ghash_free(g_version_data.member_map_alias_from_static, MEM_freeN, nullptr);
DEBUG_PRINTF(0, "done.\n"); DEBUG_PRINTF(0, "done.\n");
@@ -1634,10 +1645,10 @@ int main(int argc, char **argv)
static void UNUSED_FUNCTION(dna_rename_defs_ensure)() static void UNUSED_FUNCTION(dna_rename_defs_ensure)()
{ {
#define DNA_STRUCT_RENAME(old, new) (void)sizeof(new); #define DNA_STRUCT_RENAME(old, new) (void)sizeof(new);
#define DNA_STRUCT_RENAME_ELEM(struct_name, old, new) (void)offsetof(struct_name, new); #define DNA_STRUCT_RENAME_MEMBER(struct_name, old, new) (void)offsetof(struct_name, new);
#include "dna_rename_defs.h" #include "dna_rename_defs.h"
#undef DNA_STRUCT_RENAME #undef DNA_STRUCT_RENAME
#undef DNA_STRUCT_RENAME_ELEM #undef DNA_STRUCT_RENAME_MEMBER
} }
/** \} */ /** \} */

View File

@@ -64,7 +64,7 @@ BlenderDefRNA DefRNA = {
#ifndef RNA_RUNTIME #ifndef RNA_RUNTIME
static struct { static struct {
GHash *struct_map_static_from_alias; GHash *type_map_static_from_alias;
} g_version_data; } g_version_data;
#endif #endif
@@ -202,17 +202,17 @@ static void rna_brna_structs_remove_and_free(BlenderRNA *brna, StructRNA *srna)
} }
#endif #endif
static int DNA_struct_find_nr_wrapper(const SDNA *sdna, const char *struct_name) static int DNA_struct_find_index_wrapper(const SDNA *sdna, const char *type_name)
{ {
struct_name = DNA_struct_rename_legacy_hack_static_from_alias(struct_name); type_name = DNA_struct_rename_legacy_hack_static_from_alias(type_name);
#ifdef RNA_RUNTIME #ifdef RNA_RUNTIME
/* We may support this at some point but for now we don't. */ /* We may support this at some point but for now we don't. */
BLI_assert_unreachable(); BLI_assert_unreachable();
#else #else
struct_name = static_cast<const char *>(BLI_ghash_lookup_default( type_name = static_cast<const char *>(BLI_ghash_lookup_default(
g_version_data.struct_map_static_from_alias, struct_name, (void *)struct_name)); g_version_data.type_map_static_from_alias, type_name, (void *)type_name));
#endif #endif
return DNA_struct_find_without_alias(sdna, struct_name); return DNA_struct_find_index_without_alias(sdna, type_name);
} }
StructDefRNA *rna_find_struct_def(StructRNA *srna) StructDefRNA *rna_find_struct_def(StructRNA *srna)
@@ -448,7 +448,7 @@ static int rna_find_sdna_member(SDNA *sdna,
CLOG_ERROR(&LOG, "only during preprocessing."); CLOG_ERROR(&LOG, "only during preprocessing.");
return 0; return 0;
} }
structnr = DNA_struct_find_nr_wrapper(sdna, structname); structnr = DNA_struct_find_index_wrapper(sdna, structname);
smember->offset = -1; smember->offset = -1;
if (structnr == -1) { if (structnr == -1) {
@@ -457,14 +457,14 @@ static int rna_find_sdna_member(SDNA *sdna,
} }
const SDNA_Struct *struct_info = sdna->structs[structnr]; const SDNA_Struct *struct_info = sdna->structs[structnr];
for (int a = 0; a < struct_info->members_len; a++) { for (int a = 0; a < struct_info->members_num; a++) {
const SDNA_StructMember *member = &struct_info->members[a]; const SDNA_StructMember *member = &struct_info->members[a];
const int size = DNA_struct_member_size(sdna, member->type, member->name); const int size = DNA_struct_member_size(sdna, member->type_index, member->member_index);
dnaname = sdna->alias.names[member->name]; dnaname = sdna->alias.members[member->member_index];
cmp = rna_member_cmp(dnaname, membername); cmp = rna_member_cmp(dnaname, membername);
if (cmp == 1) { if (cmp == 1) {
smember->type = sdna->alias.types[member->type]; smember->type = sdna->alias.types[member->type_index];
smember->name = dnaname; smember->name = dnaname;
smember->offset = *offset; smember->offset = *offset;
smember->size = size; smember->size = size;
@@ -473,7 +473,7 @@ static int rna_find_sdna_member(SDNA *sdna,
smember->arraylength = 0; smember->arraylength = 0;
} }
else { else {
smember->arraylength = DNA_elem_array_size(smember->name); smember->arraylength = DNA_member_array_num(smember->name);
} }
smember->pointerlevel = 0; smember->pointerlevel = 0;
@@ -492,7 +492,8 @@ static int rna_find_sdna_member(SDNA *sdna,
smember->arraylength = 0; smember->arraylength = 0;
membername = strstr(membername, ".") + strlen("."); membername = strstr(membername, ".") + strlen(".");
rna_find_sdna_member(sdna, sdna->alias.types[member->type], membername, smember, offset); rna_find_sdna_member(
sdna, sdna->alias.types[member->type_index], membername, smember, offset);
return 1; return 1;
} }
@@ -506,7 +507,8 @@ static int rna_find_sdna_member(SDNA *sdna,
*offset = -1; *offset = -1;
membername = strstr(membername, "->") + strlen("->"); membername = strstr(membername, "->") + strlen("->");
rna_find_sdna_member(sdna, sdna->alias.types[member->type], membername, smember, offset); rna_find_sdna_member(
sdna, sdna->alias.types[member->type_index], membername, smember, offset);
return 1; return 1;
} }
@@ -721,7 +723,7 @@ BlenderRNA *RNA_create()
#ifndef RNA_RUNTIME #ifndef RNA_RUNTIME
DNA_alias_maps( DNA_alias_maps(
DNA_RENAME_STATIC_FROM_ALIAS, &g_version_data.struct_map_static_from_alias, nullptr); DNA_RENAME_STATIC_FROM_ALIAS, &g_version_data.type_map_static_from_alias, nullptr);
#endif #endif
return brna; return brna;
@@ -887,8 +889,8 @@ void RNA_free(BlenderRNA *brna)
} }
#ifndef RNA_RUNTIME #ifndef RNA_RUNTIME
BLI_ghash_free(g_version_data.struct_map_static_from_alias, nullptr, nullptr); BLI_ghash_free(g_version_data.type_map_static_from_alias, nullptr, nullptr);
g_version_data.struct_map_static_from_alias = nullptr; g_version_data.type_map_static_from_alias = nullptr;
#endif #endif
} }
@@ -1092,7 +1094,7 @@ void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
* names, this can't be checked without adding an option to disable * names, this can't be checked without adding an option to disable
* (tested this and it means changes all over). */ * (tested this and it means changes all over). */
#if 0 #if 0
if (DNA_struct_find_nr_wrapper(DefRNA.sdna, structname) == -1) { if (DNA_struct_find_index_wrapper(DefRNA.sdna, structname) == -1) {
if (!DefRNA.silent) { if (!DefRNA.silent) {
CLOG_ERROR(&LOG, "%s not found.", structname); CLOG_ERROR(&LOG, "%s not found.", structname);
DefRNA.error = true; DefRNA.error = true;
@@ -1120,7 +1122,7 @@ void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const cha
return; return;
} }
if (DNA_struct_find_nr_wrapper(DefRNA.sdna, structname) == -1) { if (DNA_struct_find_index_wrapper(DefRNA.sdna, structname) == -1) {
if (!DefRNA.silent) { if (!DefRNA.silent) {
CLOG_ERROR(&LOG, "%s not found.", structname); CLOG_ERROR(&LOG, "%s not found.", structname);
DefRNA.error = true; DefRNA.error = true;
@@ -2367,7 +2369,7 @@ void RNA_def_property_boolean_sdna(PropertyRNA *prop,
#ifndef RNA_RUNTIME #ifndef RNA_RUNTIME
/* Set the default if possible. */ /* Set the default if possible. */
if (dp->dnaoffset != -1) { if (dp->dnaoffset != -1) {
int SDNAnr = DNA_struct_find_nr_wrapper(DefRNA.sdna, dp->dnastructname); int SDNAnr = DNA_struct_find_index_wrapper(DefRNA.sdna, dp->dnastructname);
if (SDNAnr != -1) { if (SDNAnr != -1) {
const void *default_data = DNA_default_table[SDNAnr]; const void *default_data = DNA_default_table[SDNAnr];
if (default_data) { if (default_data) {
@@ -2496,7 +2498,7 @@ void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const
#ifndef RNA_RUNTIME #ifndef RNA_RUNTIME
/* Set the default if possible. */ /* Set the default if possible. */
if (dp->dnaoffset != -1) { if (dp->dnaoffset != -1) {
int SDNAnr = DNA_struct_find_nr_wrapper(DefRNA.sdna, dp->dnastructname); int SDNAnr = DNA_struct_find_index_wrapper(DefRNA.sdna, dp->dnastructname);
if (SDNAnr != -1) { if (SDNAnr != -1) {
const void *default_data = DNA_default_table[SDNAnr]; const void *default_data = DNA_default_table[SDNAnr];
if (default_data) { if (default_data) {
@@ -2628,7 +2630,7 @@ void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, cons
#ifndef RNA_RUNTIME #ifndef RNA_RUNTIME
/* Set the default if possible. */ /* Set the default if possible. */
if (dp->dnaoffset != -1) { if (dp->dnaoffset != -1) {
int SDNAnr = DNA_struct_find_nr_wrapper(DefRNA.sdna, dp->dnastructname); int SDNAnr = DNA_struct_find_index_wrapper(DefRNA.sdna, dp->dnastructname);
if (SDNAnr != -1) { if (SDNAnr != -1) {
const void *default_data = DNA_default_table[SDNAnr]; const void *default_data = DNA_default_table[SDNAnr];
if (default_data) { if (default_data) {
@@ -2724,7 +2726,7 @@ void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const
#ifndef RNA_RUNTIME #ifndef RNA_RUNTIME
/* Set the default if possible. */ /* Set the default if possible. */
if (dp->dnaoffset != -1) { if (dp->dnaoffset != -1) {
int SDNAnr = DNA_struct_find_nr_wrapper(DefRNA.sdna, dp->dnastructname); int SDNAnr = DNA_struct_find_index_wrapper(DefRNA.sdna, dp->dnastructname);
if (SDNAnr != -1) { if (SDNAnr != -1) {
const void *default_data = DNA_default_table[SDNAnr]; const void *default_data = DNA_default_table[SDNAnr];
if (default_data) { if (default_data) {
@@ -2814,7 +2816,7 @@ void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, con
#ifndef RNA_RUNTIME #ifndef RNA_RUNTIME
/* Set the default if possible. */ /* Set the default if possible. */
if ((dp->dnaoffset != -1) && (dp->dnapointerlevel != 0)) { if ((dp->dnaoffset != -1) && (dp->dnapointerlevel != 0)) {
int SDNAnr = DNA_struct_find_nr_wrapper(DefRNA.sdna, dp->dnastructname); int SDNAnr = DNA_struct_find_index_wrapper(DefRNA.sdna, dp->dnastructname);
if (SDNAnr != -1) { if (SDNAnr != -1) {
const void *default_data = DNA_default_table[SDNAnr]; const void *default_data = DNA_default_table[SDNAnr];
if (default_data) { if (default_data) {