113 #ifdef __BIG_ENDIAN__
115 # define MAKE_ID(a, b, c, d) ((int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d))
118 # define MAKE_ID(a, b, c, d) ((int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a))
134 #ifdef WITH_DNA_GHASH
146 #ifdef WITH_DNA_GHASH
161 return (name[0] ==
'*' || (name[0] ==
'(' && name[1] ==
'*'));
166 const char *cp = sdna->
names[name];
183 static void printstruct(
SDNA *sdna,
short strnr)
188 printf(
"struct %s\n", sdna->
types[struct_info->
type]);
208 #ifdef WITH_DNA_GHASH
213 unsigned int *index_last)
222 #ifdef WITH_DNA_GHASH
233 for (
int index = 0; index <
structs_len; index++) {
253 #ifdef WITH_DNA_GHASH
263 #ifdef WITH_DNA_GHASH
272 #ifdef WITH_DNA_GHASH
282 unsigned int index_last_dummy =
UINT_MAX;
288 unsigned int index_last_dummy =
UINT_MAX;
306 int gravity_fix = -1;
314 #ifdef WITH_DNA_GHASH
324 *r_error_message =
"SDNA error in SDNA file";
336 if (do_endian_swap) {
345 *r_error_message =
"NAME error in SDNA file";
350 for (
int nr = 0; nr < sdna->
names_len; nr++) {
351 sdna->
names[nr] = cp;
356 if (*cp ==
'[' &&
STREQ(cp,
"[3]")) {
357 if (nr &&
STREQ(sdna->
names[nr - 1],
"Cvi")) {
358 sdna->
names[nr] =
"gravity[3]";
376 if (do_endian_swap) {
384 *r_error_message =
"TYPE error in SDNA file";
389 for (
int nr = 0; nr < sdna->
types_len; nr++) {
408 if (do_endian_swap) {
415 *r_error_message =
"TLEN error in SDNA file";
429 if (do_endian_swap) {
437 *r_error_message =
"STRC error in SDNA file";
444 sdna->
structs[nr] = struct_info;
446 if (do_endian_swap) {
461 if (gravity_fix > -1) {
463 sp = (
short *)sdna->
structs[nr];
471 #ifdef WITH_DNA_GHASH
490 *r_error_message =
"ListBase struct error! Not found.";
501 *r_error_message =
"ListBase struct error! Needs it to calculate pointerize.";
510 for (
int i = 0; i < sdna->
names_len; i++) {
523 const char **r_error_message)
526 const char *error_message =
NULL;
530 char *data_copy =
MEM_mallocN(data_len,
"sdna_data");
531 memcpy(data_copy,
data, data_len);
532 sdna->
data = data_copy;
543 if (r_error_message ==
NULL) {
544 fprintf(stderr,
"Error decoding blend file SDNA: %s\n", error_message);
547 *r_error_message = error_message;
589 const int old_struct_index)
597 const char *struct_name = oldsdna->
types[old_struct->
type];
600 if (new_struct_index == -1) {
619 for (
int member_index = 0; member_index < old_struct->
members_len; member_index++) {
623 const char *old_type_name = oldsdna->
types[old_member->
type];
624 const char *new_type_name = newsdna->
types[new_member->
type];
625 if (!
STREQ(old_type_name, new_type_name)) {
631 const char *old_member_name = oldsdna->
names[old_member->
name];
632 const char *new_member_name = newsdna->
names[new_member->
name];
633 if (!
STREQ(old_member_name, new_member_name)) {
649 if (old_member_struct_index >= 0) {
666 printf(
"error: file without SDNA\n");
689 printf(
"changed: %s\n", oldsdna->
types[struct_info->
type]);
694 return compare_flags;
712 const char *old_data,
719 double old_value_f = 0.0;
724 for (
int a = 0;
a < array_len;
a++) {
727 const char value = *old_data;
729 old_value_f = (
double)value;
735 old_value_f = (
double)value;
739 const short value = *((
short *)old_data);
741 old_value_f = (
double)value;
745 const ushort value = *((
unsigned short *)old_data);
747 old_value_f = (
double)value;
751 const int value = *((
int *)old_data);
753 old_value_f = (
double)value;
757 const float value = *((
float *)old_data);
764 const double value = *((
double *)old_data);
773 old_value_f = (
double)value;
779 old_value_f = (
double)value;
785 old_value_f = (
double)value;
791 *new_data = (char)old_value_i;
794 *((
unsigned char *)new_data) = (
unsigned char)old_value_i;
797 *((
short *)new_data) = (short)old_value_i;
800 *((
unsigned short *)new_data) = (
unsigned short)old_value_i;
803 *((
int *)new_data) = (int)old_value_i;
807 old_value_f /= 255.0;
809 *((
float *)new_data) = old_value_f;
813 old_value_f /= 255.0;
815 *((
double *)new_data) = old_value_f;
821 *((
uint64_t *)new_data) = old_value_i;
837 for (
int a = 0;
a < array_len;
a++) {
838 new_data[
a] = old_data[
a];
849 for (
int a = 0;
a < array_len;
a++) {
850 new_data[
a] = old_data[
a] >> 3;
862 if (name[
a] != oname[
a]) {
865 if (name[
a] ==
'[' || oname[
a] ==
'[') {
868 if (name[
a] == 0 || oname[
a] == 0) {
965 const char *otype = sdna->
types[member->
type];
966 const char *oname = sdna->
names[member->
name];
988 const char *member_name = sdna->
names[member->
name];
992 const char *member_type_name = sdna->
types[member->
type];
1001 const char *name = sdna->
names[member->
name];
1007 return type_size * array_length;
1012 if (struct_nr == -1) {
1018 int offset_in_bytes = 0;
1019 for (
int member_index = 0; member_index < struct_info->
members_len; member_index++) {
1022 char *member_data =
data + offset_in_bytes;
1023 const char *member_type_name = sdna->
types[member->
type];
1026 switch (member_category) {
1031 for (
int a = 0;
a < member_array_length;
a++) {
1037 switch (member->
type) {
1066 if (
sizeof(
void *) < 8) {
1128 const int old_struct_nr,
1129 const int new_struct_nr,
1130 const char *old_blocks,
1143 const int new_struct_nr,
1144 const char *old_block,
1148 const int step_count = reconstruct_info->
step_counts[new_struct_nr];
1151 for (
int a = 0;
a < step_count;
a++) {
1153 switch (step->
type) {
1155 memcpy(new_block + step->
data.
memcpy.new_offset,
1197 const int old_struct_nr,
1198 const int new_struct_nr,
1199 const char *old_blocks,
1208 for (
int a = 0;
a < blocks;
a++) {
1209 const char *old_block = old_blocks +
a * old_block_size;
1210 char *new_block = new_blocks +
a * new_block_size;
1218 const void *old_blocks)
1224 const char *type_name = oldsdna->
types[old_struct->
type];
1227 if (new_struct_nr == -1) {
1232 const int new_block_size = newsdna->
types_size[new_struct->
type];
1234 char *new_blocks =
MEM_callocN(blocks * new_block_size,
"reconstruct");
1236 reconstruct_info, blocks, old_struct_nr, new_struct_nr, old_blocks, new_blocks);
1249 const char *member_name = sdna->
names[member->
name];
1261 const SDNA *newsdna,
1262 const char *compare_flags,
1265 const int new_member_offset,
1270 int old_member_offset;
1271 const char *new_name = newsdna->
names[new_member->
name];
1273 oldsdna, old_struct, new_name, &old_member_offset);
1275 if (old_member ==
NULL) {
1285 if (new_category != old_category) {
1294 const int shared_array_length =
MIN2(new_array_length, old_array_length);
1296 const char *new_type_name = newsdna->
types[new_member->
type];
1297 const char *old_type_name = oldsdna->
types[old_member->
type];
1299 switch (new_category) {
1301 if (
STREQ(new_type_name, old_type_name)) {
1309 r_step->
data.
memcpy.new_offset = new_member_offset;
1310 r_step->
data.
memcpy.old_offset = old_member_offset;
1335 if (
STREQ(new_type_name, old_type_name)) {
1338 r_step->
data.
memcpy.new_offset = new_member_offset;
1339 r_step->
data.
memcpy.old_offset = old_member_offset;
1357 r_step->
data.
memcpy.new_offset = new_member_offset;
1358 r_step->
data.
memcpy.old_offset = old_member_offset;
1387 switch (step->
type) {
1389 printf(
"init zero");
1393 printf(
"memcpy, size: %d, old offset: %d, new offset: %d",
1401 "cast element, old type: %d ('%s'), new type: %d ('%s'), old offset: %d, new offset: "
1413 printf(
"pointer to 32, old offset: %d, new offset: %d, length: %d",
1420 printf(
"pointer to 64, old offset: %d, new offset: %d, length: %d",
1428 "substruct, old offset: %d, new offset: %d, new struct: %d ('%s', size per struct: %d), "
1446 const SDNA *newsdna,
1447 const char *compare_flags,
1454 int new_member_offset = 0;
1455 for (
int new_member_index = 0; new_member_index < new_struct->
members_len; new_member_index++) {
1463 &
steps[new_member_index]);
1473 int new_step_count = 0;
1474 for (
int a = 0;
a < old_step_count;
a++) {
1476 switch (step->
type) {
1481 if (new_step_count > 0) {
1495 steps[new_step_count] = *step;
1504 steps[new_step_count] = *step;
1509 return new_step_count;
1513 const SDNA *newsdna,
1514 const char *compare_flags)
1517 reconstruct_info->
oldsdna = oldsdna;
1518 reconstruct_info->
newsdna = newsdna;
1525 for (
int new_struct_nr = 0; new_struct_nr < newsdna->
structs_len; new_struct_nr++) {
1527 const char *new_struct_name = newsdna->
types[new_struct->
type];
1529 if (old_struct_nr < 0) {
1530 reconstruct_info->
steps[new_struct_nr] =
NULL;
1536 oldsdna, newsdna, compare_flags, old_struct, new_struct);
1541 reconstruct_info->
steps[new_struct_nr] =
steps;
1542 reconstruct_info->
step_counts[new_struct_nr] = steps_len;
1546 printf(
"%s: \n", new_struct_name);
1547 for (
int a = 0;
a < steps_len;
a++) {
1556 return reconstruct_info;
1586 const char *vartype,
1593 const bool found =
elem_exists(sdna, vartype, name, spo);
1604 const char *vartype,
1649 const int struct_name_old_nr,
1650 const char *struct_name_new)
1654 #ifdef WITH_DNA_GHASH
1659 sdna->
types[struct_info->
type] = struct_name_new;
1665 if (struct_name_old_nr != -1) {
1673 const int struct_name_nr,
1674 const char *elem_old,
1675 const char *elem_new)
1680 const int elem_old_len = strlen(elem_old);
1681 const int elem_new_len = strlen(elem_new);
1684 for (
int elem_index = sp->
members_len; elem_index > 0; elem_index--) {
1686 const char *elem_old_full = sdna->
names[member->
name];
1688 uint elem_old_full_offset_start;
1689 if (
DNA_elem_id_match(elem_old, elem_old_len, elem_old_full, &elem_old_full_offset_start)) {
1699 strlen(elem_old_full),
1700 elem_old_full_offset_start);
1709 const short name_nr_prev = member->
name;
1711 sdna->
names[member->
name] = elem_new_full;
1720 const char *struct_name,
1721 const char *elem_old,
1722 const char *elem_new)
1725 if (struct_name_nr != -1) {
1747 int names_expand_len = 0;
1748 for (
int struct_nr = 0; struct_nr < sdna->
structs_len; struct_nr++) {
1752 const char **names_expand =
MEM_mallocN(
sizeof(*names_expand) * names_expand_len, __func__);
1753 short *names_array_len_expand =
MEM_mallocN(
sizeof(*names_array_len_expand) * names_expand_len,
1756 int names_expand_index = 0;
1757 for (
int struct_nr = 0; struct_nr < sdna->
structs_len; struct_nr++) {
1763 memcpy(struct_new, struct_old, array_size);
1764 sdna->
structs[struct_nr] = struct_new;
1766 for (
int i = 0; i < struct_old->
members_len; i++) {
1770 names_expand[names_expand_index] = sdna->
names[member_old->
name];
1774 member_new->
name = names_expand_index;
1775 names_expand_index++;
1779 sdna->
names = names_expand;
1789 const char *struct_name_static,
1790 const char *elem_static_full)
1792 const int elem_static_full_len = strlen(elem_static_full);
1793 char *elem_static = alloca(elem_static_full_len + 1);
1795 const char *str_pair[2] = {struct_name_static, elem_static};
1804 elem_static_full_len,
1813 const bool use_legacy_hack =
true;
1827 for (
int type_nr = 0; type_nr < sdna->
types_len; type_nr++) {
1828 const char *struct_name_static = sdna->
types[type_nr];
1830 if (use_legacy_hack) {
1842 for (
int struct_nr = 0; struct_nr < sdna->
structs_len; struct_nr++) {
1844 const char *struct_name_static = sdna->
types[struct_info->
type];
1846 if (use_legacy_hack) {
1854 if (elem_alias_full !=
NULL) {
1870 #ifdef WITH_DNA_GHASH
#define BLI_assert_msg(a, msg)
BLI_INLINE void BLI_endian_switch_int32(int *val) ATTR_NONNULL(1)
void BLI_endian_switch_int32_array(int *val, int size) ATTR_NONNULL(1)
void BLI_endian_switch_uint64_array(uint64_t *val, int size) ATTR_NONNULL(1)
void BLI_endian_switch_int64_array(int64_t *val, int size) ATTR_NONNULL(1)
void BLI_endian_switch_int16_array(short *val, int size) ATTR_NONNULL(1)
BLI_INLINE void BLI_endian_switch_int16(short *val) ATTR_NONNULL(1)
GHash * BLI_ghash_str_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
void * BLI_ghash_lookup_default(const 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_memarena_free(struct MemArena *ma) ATTR_NONNULL(1)
struct MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
#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)
#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
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
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)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
_W64 unsigned int uintptr_t
unsigned __int64 uint64_t
const char * compare_flags
struct ReconstructStep::@1138::@1142 substruct
eReconstructStepType type
struct ReconstructStep::@1138::@1141 cast_pointer
union ReconstructStep::@1138 data
struct ReconstructStep::@1138::@1140 cast_primitive
struct ReconstructStep::@1138::@1139 memcpy
SDNA_StructMember members[]
struct GHash * structs_map
struct MemArena * mem_arena