129 #ifdef __BIG_ENDIAN__
131 # define MAKE_ID(a, b, c, d) ((int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d))
134 # define MAKE_ID(a, b, c, d) ((int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a))
150 #ifdef WITH_DNA_GHASH
162 #ifdef WITH_DNA_GHASH
177 return (name[0] ==
'*' || (name[0] ==
'(' && name[1] ==
'*'));
189 const char *cp = sdna->
names[name];
206 static void printstruct(
SDNA *sdna,
short strnr)
211 printf(
"struct %s\n", sdna->
types[struct_info->
type]);
213 for (
int b = 0; b < struct_info->
members_len; b++) {
231 #ifdef WITH_DNA_GHASH
236 unsigned int *index_last)
245 #ifdef WITH_DNA_GHASH
256 for (
int index = 0; index <
structs_len; index++) {
279 #ifdef WITH_DNA_GHASH
290 #ifdef WITH_DNA_GHASH
299 #ifdef WITH_DNA_GHASH
309 unsigned int index_last_dummy =
UINT_MAX;
316 unsigned int index_last_dummy =
UINT_MAX;
334 int gravity_fix = -1;
342 #ifdef WITH_DNA_GHASH
352 *r_error_message =
"SDNA error in SDNA file";
364 if (do_endian_swap) {
373 *r_error_message =
"NAME error in SDNA file";
378 for (
int nr = 0; nr < sdna->
names_len; nr++) {
379 sdna->
names[nr] = cp;
384 if (*cp ==
'[' &&
STREQ(cp,
"[3]")) {
385 if (nr &&
STREQ(sdna->
names[nr - 1],
"Cvi")) {
386 sdna->
names[nr] =
"gravity[3]";
404 if (do_endian_swap) {
412 *r_error_message =
"TYPE error in SDNA file";
417 for (
int nr = 0; nr < sdna->
types_len; nr++) {
436 if (do_endian_swap) {
443 *r_error_message =
"TLEN error in SDNA file";
457 if (do_endian_swap) {
465 *r_error_message =
"STRC error in SDNA file";
472 sdna->
structs[nr] = struct_info;
474 if (do_endian_swap) {
489 if (gravity_fix > -1) {
491 sp = (
short *)sdna->
structs[nr];
499 #ifdef WITH_DNA_GHASH
518 *r_error_message =
"ListBase struct error! Not found.";
529 *r_error_message =
"ListBase struct error! Needs it to calculate pointerize.";
538 for (
int i = 0; i < sdna->
names_len; i++) {
554 const char **r_error_message)
557 const char *error_message =
NULL;
561 char *data_copy =
MEM_mallocN(data_len,
"sdna_data");
562 memcpy(data_copy,
data, data_len);
563 sdna->
data = data_copy;
574 if (r_error_message ==
NULL) {
575 fprintf(stderr,
"Error decoding blend file SDNA: %s\n", error_message);
578 *r_error_message = error_message;
620 const int old_struct_index)
628 const char *struct_name = oldsdna->
types[old_struct->
type];
631 if (new_struct_index == -1) {
650 for (
int member_index = 0; member_index < old_struct->
members_len; member_index++) {
654 const char *old_type_name = oldsdna->
types[old_member->
type];
655 const char *new_type_name = newsdna->
types[new_member->
type];
656 if (!
STREQ(old_type_name, new_type_name)) {
662 const char *old_member_name = oldsdna->
names[old_member->
name];
663 const char *new_member_name = newsdna->
names[new_member->
name];
664 if (!
STREQ(old_member_name, new_member_name)) {
680 if (old_member_struct_index >= 0) {
701 printf(
"error: file without SDNA\n");
724 printf(
"changed: %s\n", oldsdna->
types[struct_info->
type]);
729 return compare_flags;
747 const char *old_data,
754 double old_value_f = 0.0;
760 for (
int a = 0;
a < array_len;
a++) {
763 const char value = *old_data;
765 old_value_f = (
double)old_value_i;
771 old_value_f = (
double)old_value_i;
775 const short value = *((
short *)old_data);
781 const ushort value = *((
unsigned short *)old_data);
783 old_value_f = (
double)old_value_i;
787 const int value = *((
int *)old_data);
793 const float value = *((
float *)old_data);
799 const double value = *((
double *)old_data);
813 old_value_f = (
double)old_value_i;
825 *new_data = (char)old_value_i;
828 *((
unsigned char *)new_data) = (
unsigned char)old_value_i;
831 *((
short *)new_data) = (short)old_value_i;
834 *((
unsigned short *)new_data) = (
unsigned short)old_value_i;
837 *((
int *)new_data) = (int)old_value_i;
841 old_value_f /= 255.0;
843 *((
float *)new_data) = old_value_f;
847 old_value_f /= 255.0;
849 *((
double *)new_data) = old_value_f;
855 *((
uint64_t *)new_data) = old_value_i;
871 for (
int a = 0;
a < array_len;
a++) {
872 new_data[
a] = old_data[
a];
883 for (
int a = 0;
a < array_len;
a++) {
884 new_data[
a] = old_data[
a] >> 3;
896 if (name[
a] != oname[
a]) {
899 if (name[
a] ==
'[' || oname[
a] ==
'[') {
902 if (name[
a] == 0 || oname[
a] == 0) {
999 const char *otype = sdna->
types[member->
type];
1000 const char *oname = sdna->
names[member->
name];
1022 const char *member_name = sdna->
names[member->
name];
1026 const char *member_type_name = sdna->
types[member->
type];
1035 const char *name = sdna->
names[member->
name];
1041 return type_size * array_length;
1053 if (struct_nr == -1) {
1059 int offset_in_bytes = 0;
1060 for (
int member_index = 0; member_index < struct_info->
members_len; member_index++) {
1063 char *member_data =
data + offset_in_bytes;
1064 const char *member_type_name = sdna->
types[member->
type];
1067 switch (member_category) {
1072 for (
int a = 0;
a < member_array_length;
a++) {
1078 switch (member->
type) {
1107 if (
sizeof(
void *) < 8) {
1169 const int old_struct_nr,
1170 const int new_struct_nr,
1171 const char *old_blocks,
1184 const int new_struct_nr,
1185 const char *old_block,
1189 const int step_count = reconstruct_info->
step_counts[new_struct_nr];
1192 for (
int a = 0;
a < step_count;
a++) {
1194 switch (step->
type) {
1196 memcpy(new_block + step->
data.
memcpy.new_offset,
1238 const int old_struct_nr,
1239 const int new_struct_nr,
1240 const char *old_blocks,
1249 for (
int a = 0;
a < blocks;
a++) {
1250 const char *old_block = old_blocks +
a * old_block_size;
1251 char *new_block = new_blocks +
a * new_block_size;
1266 const void *old_blocks)
1272 const char *type_name = oldsdna->
types[old_struct->
type];
1275 if (new_struct_nr == -1) {
1280 const int new_block_size = newsdna->
types_size[new_struct->
type];
1282 char *new_blocks =
MEM_callocN(blocks * new_block_size,
"reconstruct");
1284 reconstruct_info, blocks, old_struct_nr, new_struct_nr, old_blocks, new_blocks);
1297 const char *member_name = sdna->
names[member->
name];
1309 const SDNA *newsdna,
1310 const char *compare_flags,
1313 const int new_member_offset,
1318 int old_member_offset;
1319 const char *new_name = newsdna->
names[new_member->
name];
1321 oldsdna, old_struct, new_name, &old_member_offset);
1323 if (old_member ==
NULL) {
1333 if (new_category != old_category) {
1342 const int shared_array_length =
MIN2(new_array_length, old_array_length);
1344 const char *new_type_name = newsdna->
types[new_member->
type];
1345 const char *old_type_name = oldsdna->
types[old_member->
type];
1347 switch (new_category) {
1349 if (
STREQ(new_type_name, old_type_name)) {
1357 r_step->
data.
memcpy.new_offset = new_member_offset;
1358 r_step->
data.
memcpy.old_offset = old_member_offset;
1383 if (
STREQ(new_type_name, old_type_name)) {
1386 r_step->
data.
memcpy.new_offset = new_member_offset;
1387 r_step->
data.
memcpy.old_offset = old_member_offset;
1405 r_step->
data.
memcpy.new_offset = new_member_offset;
1406 r_step->
data.
memcpy.old_offset = old_member_offset;
1435 switch (step->
type) {
1437 printf(
"init zero");
1441 printf(
"memcpy, size: %d, old offset: %d, new offset: %d",
1449 "cast element, old type: %d ('%s'), new type: %d ('%s'), old offset: %d, new offset: "
1461 printf(
"pointer to 32, old offset: %d, new offset: %d, length: %d",
1468 printf(
"pointer to 64, old offset: %d, new offset: %d, length: %d",
1476 "substruct, old offset: %d, new offset: %d, new struct: %d ('%s', size per struct: %d), "
1494 const SDNA *newsdna,
1495 const char *compare_flags,
1502 int new_member_offset = 0;
1503 for (
int new_member_index = 0; new_member_index < new_struct->
members_len; new_member_index++) {
1511 &
steps[new_member_index]);
1521 int new_step_count = 0;
1522 for (
int a = 0;
a < old_step_count;
a++) {
1524 switch (step->
type) {
1529 if (new_step_count > 0) {
1543 steps[new_step_count] = *step;
1552 steps[new_step_count] = *step;
1557 return new_step_count;
1565 const SDNA *newsdna,
1566 const char *compare_flags)
1569 reconstruct_info->
oldsdna = oldsdna;
1570 reconstruct_info->
newsdna = newsdna;
1577 for (
int new_struct_nr = 0; new_struct_nr < newsdna->
structs_len; new_struct_nr++) {
1579 const char *new_struct_name = newsdna->
types[new_struct->
type];
1581 if (old_struct_nr < 0) {
1582 reconstruct_info->
steps[new_struct_nr] =
NULL;
1588 oldsdna, newsdna, compare_flags, old_struct, new_struct);
1594 reconstruct_info->
steps[new_struct_nr] =
steps;
1595 reconstruct_info->
step_counts[new_struct_nr] = steps_len;
1599 printf(
"%s: \n", new_struct_name);
1600 for (
int a = 0;
a < steps_len;
a++) {
1609 return reconstruct_info;
1643 const char *vartype,
1650 const bool found =
elem_exists(sdna, vartype, name, spo);
1662 const char *vartype,
1710 const int struct_name_old_nr,
1711 const char *struct_name_new)
1715 #ifdef WITH_DNA_GHASH
1720 sdna->
types[struct_info->
type] = struct_name_new;
1729 if (struct_name_old_nr != -1) {
1737 const int struct_name_nr,
1738 const char *elem_old,
1739 const char *elem_new)
1744 const int elem_old_len = strlen(elem_old);
1745 const int elem_new_len = strlen(elem_new);
1748 for (
int elem_index = sp->
members_len; elem_index > 0; elem_index--) {
1750 const char *elem_old_full = sdna->
names[member->
name];
1752 uint elem_old_full_offset_start;
1753 if (
DNA_elem_id_match(elem_old, elem_old_len, elem_old_full, &elem_old_full_offset_start)) {
1763 strlen(elem_old_full),
1764 elem_old_full_offset_start);
1773 const short name_nr_prev = member->
name;
1775 sdna->
names[member->
name] = elem_new_full;
1789 const char *struct_name,
1790 const char *elem_old,
1791 const char *elem_new)
1794 if (struct_name_nr != -1) {
1816 int names_expand_len = 0;
1817 for (
int struct_nr = 0; struct_nr < sdna->
structs_len; struct_nr++) {
1821 const char **names_expand =
MEM_mallocN(
sizeof(*names_expand) * names_expand_len, __func__);
1822 short *names_array_len_expand =
MEM_mallocN(
sizeof(*names_array_len_expand) * names_expand_len,
1825 int names_expand_index = 0;
1826 for (
int struct_nr = 0; struct_nr < sdna->
structs_len; struct_nr++) {
1832 memcpy(struct_new, struct_old, array_size);
1833 sdna->
structs[struct_nr] = struct_new;
1835 for (
int i = 0; i < struct_old->
members_len; i++) {
1839 names_expand[names_expand_index] = sdna->
names[member_old->
name];
1843 member_new->
name = names_expand_index;
1844 names_expand_index++;
1848 sdna->
names = names_expand;
1858 const char *struct_name_static,
1859 const char *elem_static_full)
1861 const int elem_static_full_len = strlen(elem_static_full);
1862 char *elem_static = alloca(elem_static_full_len + 1);
1864 const char *str_pair[2] = {struct_name_static, elem_static};
1873 elem_static_full_len,
1882 const bool use_legacy_hack =
true;
1896 for (
int type_nr = 0; type_nr < sdna->
types_len; type_nr++) {
1897 const char *struct_name_static = sdna->
types[type_nr];
1899 if (use_legacy_hack) {
1911 for (
int struct_nr = 0; struct_nr < sdna->
structs_len; struct_nr++) {
1913 const char *struct_name_static = sdna->
types[struct_info->
type];
1915 if (use_legacy_hack) {
1923 if (elem_alias_full !=
NULL) {
1943 #ifdef WITH_DNA_GHASH
void BLI_endian_switch_int32_array(int *val, const int size) ATTR_NONNULL(1)
void BLI_endian_switch_uint64_array(uint64_t *val, const int size) ATTR_NONNULL(1)
void BLI_endian_switch_int64_array(int64_t *val, const int size) ATTR_NONNULL(1)
BLI_INLINE void BLI_endian_switch_int32(int *val) ATTR_NONNULL(1)
BLI_INLINE void BLI_endian_switch_int16(short *val) ATTR_NONNULL(1)
void BLI_endian_switch_int16_array(short *val, const int size) ATTR_NONNULL(1)
GHash * BLI_ghash_str_new_ex(const char *info, const unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void * BLI_ghash_lookup_default(GHash *gh, const void *key, void *val_default) ATTR_WARN_UNUSED_RESULT
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
void BLI_ghash_insert(GHash *gh, void *key, void *val)
void ** BLI_ghash_lookup_p(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
void * BLI_ghash_lookup(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
void BLI_memarena_free(struct MemArena *ma) ATTR_NONNULL(1)
#define BLI_MEMARENA_STD_BUFSIZE
void * BLI_memarena_alloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
struct MemArena * BLI_memarena_new(const size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2) ATTR_MALLOC
#define POINTER_FROM_INT(i)
#define POINTER_AS_INT(i)
typedef double(DMatrix)[4][4]
blenloader genfile private function prototypes
const unsigned char DNAstr[]
struct SDNA_StructMember SDNA_StructMember
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
#define MEM_recallocN(vmemh, len)
static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error_message)
static const char * dna_sdna_alias_from_static_elem_full(SDNA *sdna, GHash *elem_map_alias_from_static, const char *struct_name_static, const char *elem_static_full)
struct ReconstructStep ReconstructStep
SDNA * DNA_sdna_from_data(const void *data, const int data_len, bool do_endian_swap, bool data_alloc, const char **r_error_message)
int DNA_elem_size_nr(const SDNA *sdna, short type, short name)
static bool DNA_sdna_patch_struct_member_nr(SDNA *sdna, const int struct_name_nr, const char *elem_old, const char *elem_new)
@ RECONSTRUCT_STEP_CAST_POINTER_TO_32
@ RECONSTRUCT_STEP_CAST_POINTER_TO_64
@ RECONSTRUCT_STEP_INIT_ZERO
@ RECONSTRUCT_STEP_SUBSTRUCT
@ RECONSTRUCT_STEP_CAST_PRIMITIVE
@ RECONSTRUCT_STEP_MEMCPY
int DNA_elem_type_size(const eSDNA_Type elem_nr)
static void reconstruct_structs(const DNA_ReconstructInfo *reconstruct_info, const int blocks, const int old_struct_nr, const int new_struct_nr, const char *old_blocks, char *new_blocks)
static bool ispointer(const char *name)
bool DNA_struct_find(const SDNA *sdna, const char *stype)
static bool elem_exists_impl(const char **types, const char **names, const char *type, const char *name, const SDNA_Struct *old)
static void cast_primitive_type(const eSDNA_Type old_type, const eSDNA_Type new_type, const int array_len, const char *old_data, char *new_data)
static void init_reconstruct_step_for_member(const SDNA *oldsdna, const SDNA *newsdna, const char *compare_flags, const SDNA_Struct *old_struct, const SDNA_StructMember *new_member, const int new_member_offset, ReconstructStep *r_step)
bool DNA_struct_alias_elem_find(const SDNA *sdna, const char *stype, const char *vartype, const char *name)
static void cast_pointer_64_to_32(const int array_len, const uint64_t *old_data, uint32_t *new_data)
static void sdna_expand_names(SDNA *sdna)
BLI_INLINE const char * pad_up_4(const char *ptr)
static int get_member_size_in_bytes(const SDNA *sdna, const SDNA_StructMember *member)
static bool DNA_sdna_patch_struct_nr(SDNA *sdna, const int struct_name_old_nr, const char *struct_name_new)
static void print_reconstruct_step(ReconstructStep *step, const SDNA *oldsdna, const SDNA *newsdna)
#define MAKE_ID(a, b, c, d)
static bool elem_exists_alias(const SDNA *sdna, const char *type, const char *name, const SDNA_Struct *old)
static bool elem_exists(const SDNA *sdna, const char *type, const char *name, const SDNA_Struct *old)
void DNA_sdna_current_free(void)
static eStructMemberCategory get_struct_member_category(const SDNA *sdna, const SDNA_StructMember *member)
static void set_compare_flags_for_struct(const SDNA *oldsdna, const SDNA *newsdna, char *compare_flags, const int old_struct_index)
void DNA_sdna_current_init(void)
void DNA_reconstruct_info_free(DNA_ReconstructInfo *reconstruct_info)
bool DNA_struct_elem_find(const SDNA *sdna, const char *stype, const char *vartype, const char *name)
void DNA_sdna_alias_data_ensure(SDNA *sdna)
static const SDNA_StructMember * find_member_with_matching_name(const SDNA *sdna, const SDNA_Struct *struct_info, const char *name, int *r_offset)
static int dna_struct_find_nr_ex_impl(const char **types, const int UNUSED(types_len), SDNA_Struct **const structs, const int structs_len, const char *str, unsigned int *index_last)
@ STRUCT_MEMBER_CATEGORY_STRUCT
@ STRUCT_MEMBER_CATEGORY_POINTER
@ STRUCT_MEMBER_CATEGORY_PRIMITIVE
static int elem_offset(const SDNA *sdna, const char *type, const char *name, const SDNA_Struct *old)
DNA_ReconstructInfo * DNA_reconstruct_info_create(const SDNA *oldsdna, const SDNA *newsdna, const char *compare_flags)
static void cast_pointer_32_to_64(const int array_len, const uint32_t *old_data, uint64_t *new_data)
int DNA_struct_alias_find_nr_ex(const SDNA *sdna, const char *str, unsigned int *index_last)
void DNA_sdna_free(SDNA *sdna)
static bool elem_streq(const char *name, const char *oname)
struct DNA_ReconstructInfo DNA_ReconstructInfo
void DNA_struct_switch_endian(const SDNA *sdna, int struct_nr, char *data)
bool DNA_sdna_patch_struct(SDNA *sdna, const char *struct_name_old, const char *struct_name_new)
void DNA_sdna_alias_data_ensure_structs_map(SDNA *sdna)
void * DNA_struct_reconstruct(const DNA_ReconstructInfo *reconstruct_info, int old_struct_nr, int blocks, const void *old_blocks)
int DNA_struct_alias_find_nr(const SDNA *sdna, const char *str)
int DNA_elem_offset(SDNA *sdna, const char *stype, const char *vartype, const char *name)
static ReconstructStep * create_reconstruct_steps_for_struct(const SDNA *oldsdna, const SDNA *newsdna, const char *compare_flags, const SDNA_Struct *old_struct, const SDNA_Struct *new_struct)
static void reconstruct_struct(const DNA_ReconstructInfo *reconstruct_info, const int new_struct_nr, const char *old_block, char *new_block)
const char * DNA_struct_get_compareflags(const SDNA *oldsdna, const SDNA *newsdna)
int DNA_struct_find_nr_ex(const SDNA *sdna, const char *str, unsigned int *index_last)
const struct SDNA * DNA_sdna_current_get(void)
bool DNA_sdna_patch_struct_member(SDNA *sdna, const char *struct_name, const char *elem_old, const char *elem_new)
static int compress_reconstruct_steps(ReconstructStep *steps, const int old_step_count)
int DNA_struct_find_nr(const SDNA *sdna, const char *str)
const char * DNA_struct_rename_legacy_hack_static_from_alias(const char *name)
char * DNA_elem_id_rename(struct MemArena *mem_arena, const char *elem_src, const int elem_src_len, const char *elem_dst, const int elem_dst_len, const char *elem_src_full, const int elem_src_full_len, const uint elem_src_full_offset_len)
void DNA_alias_maps(enum eDNA_RenameDir version_dir, GHash **r_struct_map, GHash **r_elem_map)
uint DNA_elem_id_offset_start(const char *elem_full)
bool DNA_elem_id_match(const char *elem_search, const int elem_search_len, const char *elem_full, uint *r_elem_full_offset)
const char * DNA_struct_rename_legacy_hack_alias_from_static(const char *name)
uint DNA_elem_id_strip_copy(char *elem_dst, const char *elem_src)
int DNA_elem_array_size(const char *str)
@ DNA_RENAME_ALIAS_FROM_STATIC
GHash * elem_map_alias_from_static
GHash * struct_map_alias_from_static
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_mallocN)(size_t len, const char *str)
_W64 unsigned int uintptr_t
unsigned __int64 uint64_t
const char * compare_flags
union ReconstructStep::@1090 data
eReconstructStepType type
struct ReconstructStep::@1090::@1094 substruct
struct ReconstructStep::@1090::@1092 cast_primitive
struct ReconstructStep::@1090::@1091 memcpy
struct ReconstructStep::@1090::@1093 cast_pointer
SDNA_StructMember members[]
struct GHash * structs_map
struct MemArena * mem_arena