22#include <fmt/format.h>
121#define MAKE_ID(a, b, c, d) (int(d) << 24 | int(c) << 16 | (b) << 8 | (a))
128 MEM_delete(this->
data);
143 return (name[0] ==
'*' || (name[0] ==
'(' && name[1] ==
'*'));
165static void printstruct(SDNA *sdna,
short struct_index)
169 SDNA_Struct *struct_info = sdna->structs[struct_index];
170 printf(
"struct %s\n", sdna->types[struct_info->type]);
172 for (
int b = 0;
b < struct_info->members_len;
b++) {
173 SDNA_StructMember *struct_member = &struct_info->members[
b];
174 printf(
" %s %s\n", sdna->types[struct_member->type], sdna->names[struct_member->name]);
192 uint *struct_index_last)
194 if (*struct_index_last < structs.
size()) {
195 const SDNA_Struct *struct_info = structs[*struct_index_last];
197 return *struct_index_last;
202 if (
const std::optional<int> struct_index = structs_map.lookup_try(
str)) {
203 *struct_index_last = *struct_index;
204 return *struct_index;
208 for (
int struct_index = 0; struct_index < types_num; struct_index++) {
209 const SDNA_Struct *struct_info = structs[struct_index];
210 if (types[struct_info->type] ==
str) {
211 *struct_index_last = struct_index;
222 uint *struct_index_last)
239 uint *struct_index_last)
277 return reinterpret_cast<const char *
>((
uintptr_t(ptr) + 3) & ~3);
283 const void *
const data_pointer_end,
284 const char **r_error_message)
286 BLI_STATIC_ASSERT(std::is_pointer_v<T> && std::is_const_v<std::remove_pointer_t<T>>,
287 "Data type for this util must be a pointer to const data")
289 if ((
data +
num) > data_pointer_end) [[unlikely]] {
290 *r_error_message =
"Invalid data in SDNA file";
300 T data_pointer_current,
301 const void *
const data_pointer_end,
302 const char **r_error_message)
304 BLI_STATIC_ASSERT(std::is_pointer_v<T> && std::is_const_v<std::remove_pointer_t<T>>,
305 "Data type for this util must be a pointer to const data")
306 if (size < 0 || size > (
static_cast<T>(data_pointer_end) - data_pointer_current)) [[unlikely]] {
307 *r_error_message =
"Invalid array size data in SDNA file";
314 const void *
const data_pointer_end,
315 const char **r_error_message)
318 const char *str_end = std::char_traits<char>::find(
319 data,
size_t(
static_cast<const char *
>(data_pointer_end) -
data),
'\0');
320 if (!str_end) [[unlikely]] {
321 *r_error_message =
"Invalid string data in SDNA file";
327 if (!string_size) [[unlikely]] {
328 *r_error_message =
"Invalid string data in SDNA file";
332 data += (string_size + 1);
351 const int64_t voided_members_size,
352 const char **r_error_message)
354 int64_t members_size = voided_members_size;
360 if (member_size < 0) [[unlikely]] {
361 *r_error_message =
"Invalid struct member size in SDNA file";
364 members_size += member_size * array_num;
367 *r_error_message =
"Invalid struct size in SDNA file";
380 const void *
const data_pointer_end = sdna->
data + sdna->
data_size;
382 int member_index_gravity_fix = -1;
385 const int *int_buf =
reinterpret_cast<int *
>(
const_cast<char *
>(sdna->
data));
387 const short *short_buf;
388 const short *short_data;
389 const char *char_buf;
401 if (*int_data !=
MAKE_ID(
'S',
'D',
'N',
'A')) {
402 *r_error_message =
"SDNA error in SDNA file";
410 if (*int_data ==
MAKE_ID(
'N',
'A',
'M',
'E')) {
420 if (sdna->
members.is_empty()) {
421 *r_error_message =
"NAME error in SDNA file";
425 char_buf =
reinterpret_cast<const char *
>(int_buf);
426 for (
int member_index = 0; member_index < sdna->
members_num; member_index++) {
428 char_buf, data_pointer_end, r_error_message);
432 sdna->
members[member_index] = orig_member_name;
437 if (orig_member_name ==
"[3]") {
438 if (member_index && sdna->
members[member_index - 1] ==
"Cvi") {
439 sdna->
members[member_index] =
"gravity[3]";
440 member_index_gravity_fix = member_index;
447 int_buf =
reinterpret_cast<const int *
>(char_buf);
451 if (*int_data ==
MAKE_ID(
'T',
'Y',
'P',
'E')) {
461 if (sdna->
types.is_empty()) {
462 *r_error_message =
"TYPE error in SDNA file";
466 char_buf =
reinterpret_cast<const char *
>(int_buf);
467 for (
int type_index = 0; type_index < sdna->
types_num; type_index++) {
469 char_buf, data_pointer_end, r_error_message);
479 int_buf =
reinterpret_cast<const int *
>(char_buf);
483 short_buf =
reinterpret_cast<const short *
>(int_buf);
484 if (*int_data ==
MAKE_ID(
'T',
'L',
'E',
'N')) {
487 short_buf, sdna->
types_num, data_pointer_end, r_error_message)))
491 sdna->
types_size =
const_cast<short *
>(short_data);
494 *r_error_message =
"TLEN error in SDNA file";
505 int_buf =
reinterpret_cast<const int *
>(short_buf);
509 if (*int_data ==
MAKE_ID(
'S',
'T',
'R',
'C')) {
516 const int structs_num = *int_data;
519 if (sdna->
structs.is_empty()) {
520 *r_error_message =
"STRC error in SDNA file";
527 short_buf =
reinterpret_cast<const short *
>(int_buf);
539 const int64_t struct_members_size = struct_member_short_size * struct_info->
members_num;
541 struct_members_size, short_buf, data_pointer_end, r_error_message) ||
549 *r_error_message =
"Invalid struct type index in SDNA file";
553 *r_error_message =
"Invalid duplicate struct type index in SDNA file";
559 *r_error_message =
"Invalid struct member's type index in SDNA file";
563 *r_error_message =
"Invalid struct member's member index in SDNA file";
575 if (member_index_gravity_fix > -1) {
576 constexpr int float_type_index = 7;
577 constexpr int void_type_index = 9;
578 constexpr int gravity_member_index = 4;
580 if (struct_info->
members_num < gravity_member_index + 2 ||
585 float_type_index >= sdna->
types_num || sdna->
types[float_type_index] !=
"float" ||
586 void_type_index >= sdna->
types_num || sdna->
types[void_type_index] !=
"void")
588 *r_error_message =
"Invalid data in SDNA file";
592 gravity_fix_struct = struct_info;
599 char_buf =
reinterpret_cast<const char *
>(short_buf);
600 if (char_buf != data_pointer_end) {
601 *r_error_message =
"Invalid data in SDNA file";
627 if (struct_index == -1) [[unlikely]] {
628 *r_error_message =
"ListBase struct error! Not found.";
638 *r_error_message =
"ListBase struct error: invalid computed pointer-size.";
645 for (
int member_index = 0; member_index < sdna->
members_num; member_index++) {
647 if (array_num < 0 || array_num >
SHRT_MAX) [[unlikely]] {
648 *r_error_message =
"Invalid struct member array size in SDNA file";
657 const int64_t voided_members_size = (struct_info == gravity_fix_struct) ?
sizeof(
float) : 0;
667 uint dummy_index = 0;
669 sdna,
"mat4x4f", &dummy_index);
670 if (mat4x4f_struct_index > 0) {
672 const int mat4x4f_type_index = struct_info->
type_index;
684 const char **r_error_message)
686 auto sdna = std::make_unique<SDNA>();
687 const char *error_message =
nullptr;
689 sdna->data_size = data_len;
692 memcpy(data_copy,
data, data_len);
693 sdna->data = data_copy;
696 sdna->data =
static_cast<const char *
>(
data);
698 sdna->data_alloc = data_alloc;
707 if (r_error_message ==
nullptr) {
708 fprintf(stderr,
"Error decoding blend file SDNA: %s\n", error_message);
711 *r_error_message = error_message;
735 const int old_struct_index)
746 if (new_struct_index == -1) {
765 for (
int member_index = 0; member_index < old_struct->
members_num; member_index++) {
771 if (old_type_name != new_type_name) {
779 if (old_member_name != new_member_name) {
796 if (old_member_struct_index >= 0) {
812 if (oldsdna->
structs.is_empty()) {
813 printf(
"error: file without SDNA\n");
822 for (
const int old_struct_index : oldsdna->
structs.index_range()) {
855 for (
int a = 0; a < oldsdna->structs_len; a++) {
858 printf(
"changed: %s\n", oldsdna->
types[struct_info->type]);
863 return compare_flags;
881 const char *old_data,
888 double old_value_f = 0.0;
893 for (
int a = 0; a < array_len; a++) {
896 const char value = *old_data;
898 old_value_f = double(value);
902 const uchar value = *
reinterpret_cast<const uchar *
>(old_data);
904 old_value_f = double(value);
908 const short value = *
reinterpret_cast<const short *
>(old_data);
910 old_value_f = double(value);
914 const ushort value = *
reinterpret_cast<const ushort *
>(old_data);
916 old_value_f = double(value);
920 const int value = *
reinterpret_cast<const int *
>(old_data);
922 old_value_f = double(value);
926 const float value = *
reinterpret_cast<const float *
>(old_data);
933 const double value = *
reinterpret_cast<const double *
>(old_data);
940 const int64_t value = *
reinterpret_cast<const int64_t *
>(old_data);
942 old_value_f = double(value);
948 old_value_f = double(value);
952 const int8_t value = *
reinterpret_cast<const int8_t *
>(old_data);
954 old_value_f = double(value);
960 "Conversion from SDNA_TYPE_VOID/SDNA_TYPE_RAW_DATA is not supported");
966 *new_data = char(old_value_i);
969 *
reinterpret_cast<uchar *
>(new_data) =
uchar(old_value_i);
972 *
reinterpret_cast<short *
>(new_data) =
short(old_value_i);
975 *
reinterpret_cast<ushort *
>(new_data) =
ushort(old_value_i);
978 *
reinterpret_cast<int *
>(new_data) =
int(old_value_i);
982 old_value_f /= 255.0;
984 *
reinterpret_cast<float *
>(new_data) = old_value_f;
988 old_value_f /= 255.0;
990 *
reinterpret_cast<double *
>(new_data) = old_value_f;
996 *
reinterpret_cast<uint64_t *
>(new_data) = old_value_i;
999 *
reinterpret_cast<int8_t *
>(new_data) =
int8_t(old_value_i);
1003 BLI_assert_msg(
false,
"Conversion to SDNA_TYPE_VOID/SDNA_TYPE_RAW_DATA is not supported");
1016 for (
int a = 0; a < array_len; a++) {
1017 new_data[a] = old_data[a];
1028 for (
int a = 0; a < array_len; a++) {
1029 new_data[a] = old_data[a] >> 3;
1039 if (name[a] != oname[a]) {
1042 if (name[a] ==
'[' || oname[a] ==
'[') {
1046 return name.
size() == oname.
size();
1074 return type == otype;
1129 if (type == otype) {
1202 return type_size * array_length;
1255 const int old_struct_index,
1256 const int new_struct_index,
1257 const char *old_blocks,
1270 const int new_struct_index,
1271 const char *old_block,
1275 const int step_count = reconstruct_info->
step_counts[new_struct_index];
1278 for (
int a = 0; a < step_count; a++) {
1280 switch (
step->type) {
1282 memcpy(new_block +
step->data.memcpy.new_offset,
1283 old_block +
step->data.memcpy.old_offset,
1284 step->data.memcpy.size);
1288 step->data.cast_primitive.new_type,
1289 step->data.cast_primitive.array_len,
1290 old_block +
step->data.cast_primitive.old_offset,
1291 new_block +
step->data.cast_primitive.new_offset);
1295 step->data.cast_pointer.array_len,
1296 reinterpret_cast<const uint64_t *
>(old_block +
step->data.cast_pointer.old_offset),
1297 reinterpret_cast<uint32_t *
>(new_block +
step->data.cast_pointer.new_offset));
1301 step->data.cast_pointer.array_len,
1302 reinterpret_cast<const uint32_t *
>(old_block +
step->data.cast_pointer.old_offset),
1303 reinterpret_cast<uint64_t *
>(new_block +
step->data.cast_pointer.new_offset));
1307 step->data.substruct.array_len,
1308 step->data.substruct.old_struct_index,
1309 step->data.substruct.new_struct_index,
1310 old_block +
step->data.substruct.old_offset,
1311 new_block +
step->data.substruct.new_offset);
1326 const int old_struct_index,
1327 const int new_struct_index,
1328 const char *old_blocks,
1337 for (
int a = 0; a < blocks; a++) {
1338 const char *old_block = old_blocks + a * old_block_size;
1339 char *new_block = new_blocks + a * new_block_size;
1345 int old_struct_index,
1347 const void *old_blocks,
1348 const char *alloc_name,
1358 if (new_struct_index == -1) {
1366 char *new_blocks =
static_cast<char *
>(
1372 static_cast<const char *
>(old_blocks),
1375 *r_alloc_size =
int64_t(new_block_size) * blocks;
1387 for (
int a = 0; a < struct_info->
members_num; a++) {
1401 const SDNA *newsdna,
1402 const char *compare_flags,
1405 const int new_member_offset,
1410 int old_member_offset;
1413 oldsdna, old_struct, new_name, &old_member_offset);
1415 if (old_member ==
nullptr) {
1425 if (new_category != old_category) {
1434 const int shared_array_length = std::min(new_array_length, old_array_length);
1439 switch (new_category) {
1441 if (new_type_name == old_type_name) {
1445 compare_flags[old_struct_index]);
1450 r_step->
data.memcpy.new_offset = new_member_offset;
1451 r_step->
data.memcpy.old_offset = old_member_offset;
1453 shared_array_length;
1463 r_step->
data.substruct.new_offset = new_member_offset;
1464 r_step->
data.substruct.old_offset = old_member_offset;
1465 r_step->
data.substruct.array_len = shared_array_length;
1466 r_step->
data.substruct.new_struct_index = new_struct_index;
1467 r_step->
data.substruct.old_struct_index = old_struct_index;
1477 if (new_type_name == old_type_name) {
1480 r_step->
data.memcpy.new_offset = new_member_offset;
1481 r_step->
data.memcpy.old_offset = old_member_offset;
1483 shared_array_length;
1488 r_step->
data.cast_primitive.array_len = shared_array_length;
1489 r_step->
data.cast_primitive.new_offset = new_member_offset;
1490 r_step->
data.cast_primitive.old_offset = old_member_offset;
1500 r_step->
data.memcpy.new_offset = new_member_offset;
1501 r_step->
data.memcpy.old_offset = old_member_offset;
1507 r_step->
data.cast_pointer.new_offset = new_member_offset;
1508 r_step->
data.cast_pointer.old_offset = old_member_offset;
1509 r_step->
data.cast_pointer.array_len = shared_array_length;
1514 r_step->
data.cast_pointer.new_offset = new_member_offset;
1515 r_step->
data.cast_pointer.old_offset = old_member_offset;
1516 r_step->
data.cast_pointer.array_len = shared_array_length;
1529 const SDNA *oldsdna,
1530 const SDNA *newsdna)
1532 switch (
step->type) {
1534 printf(
"initialize zero");
1538 printf(
"memcpy, size: %d, old offset: %d, new offset: %d",
1539 step->data.memcpy.size,
1540 step->data.memcpy.old_offset,
1541 step->data.memcpy.new_offset);
1546 "cast element, old type: %d ('%s'), new type: %d ('%s'), old offset: %d, new offset: "
1548 int(
step->data.cast_primitive.old_type),
1549 std::string(oldsdna->
types[
step->data.cast_primitive.old_type]).c_str(),
1550 int(
step->data.cast_primitive.new_type),
1551 std::string(newsdna->
types[
step->data.cast_primitive.new_type]).c_str(),
1552 step->data.cast_primitive.old_offset,
1553 step->data.cast_primitive.new_offset,
1554 step->data.cast_primitive.array_len);
1558 printf(
"pointer to 32, old offset: %d, new offset: %d, length: %d",
1559 step->data.cast_pointer.old_offset,
1560 step->data.cast_pointer.new_offset,
1561 step->data.cast_pointer.array_len);
1565 printf(
"pointer to 64, old offset: %d, new offset: %d, length: %d",
1566 step->data.cast_pointer.old_offset,
1567 step->data.cast_pointer.new_offset,
1568 step->data.cast_pointer.array_len);
1573 "substruct, old offset: %d, new offset: %d, new struct: %d ('%s', size per struct: %d), "
1575 step->data.substruct.old_offset,
1576 step->data.substruct.new_offset,
1577 step->data.substruct.new_struct_index,
1579 newsdna->
types[newsdna->
structs[
step->data.substruct.new_struct_index]->type_index])
1582 step->data.substruct.array_len);
1593 const SDNA *newsdna,
1594 const char *compare_flags,
1601 int new_member_offset = 0;
1602 for (
int new_member_index = 0; new_member_index < new_struct->
members_num; new_member_index++) {
1610 &steps[new_member_index]);
1620 int new_step_count = 0;
1621 for (
int a = 0; a < old_step_count; a++) {
1623 switch (
step->type) {
1628 if (new_step_count > 0) {
1633 if (prev_step->
data.memcpy.old_offset + prev_step->
data.memcpy.size ==
1634 step->data.memcpy.old_offset &&
1635 prev_step->
data.memcpy.new_offset + prev_step->
data.memcpy.size ==
1636 step->data.memcpy.new_offset)
1638 prev_step->
data.memcpy.size +=
step->data.memcpy.size;
1643 steps[new_step_count] = *
step;
1652 steps[new_step_count] = *
step;
1657 return new_step_count;
1661 const SDNA *newsdna,
1662 const char *compare_flags)
1665 reconstruct_info->
oldsdna = oldsdna;
1666 reconstruct_info->
newsdna = newsdna;
1671 size_t(newsdna->
structs.size()), __func__);
1674 for (
const int new_struct_index : newsdna->
structs.index_range()) {
1678 if (old_struct_index < 0) {
1679 reconstruct_info->
steps[new_struct_index] =
nullptr;
1680 reconstruct_info->
step_counts[new_struct_index] = 0;
1685 oldsdna, newsdna, compare_flags, old_struct, new_struct);
1690 reconstruct_info->
steps[new_struct_index] = steps;
1691 reconstruct_info->
step_counts[new_struct_index] = steps_len;
1695 printf(
"%s: \n", new_struct_name);
1696 for (
int a = 0; a < steps_len; a++) {
1704 return reconstruct_info;
1709 for (
const int new_struct_index : reconstruct_info->
newsdna->
structs.index_range()) {
1710 if (reconstruct_info->
steps[new_struct_index] !=
nullptr) {
1711 MEM_delete(reconstruct_info->
steps[new_struct_index]);
1714 MEM_delete(reconstruct_info->
steps);
1716 MEM_delete(reconstruct_info);
1753 if (struct_index != -1) {
1803 BLI_assert_msg(
false,
"Operations on the size of SDNA_TYPE_RAW_DATA is not supported");
1828 const int struct_index,
1833#ifdef WITH_DNA_GHASH
1845 if (struct_index != -1) {
1853 const int struct_index,
1862 for (
int struct_member_index = struct_info->
members_num; struct_member_index > 0;
1863 struct_member_index--)
1868 uint old_member_name_full_offset_start;
1870 old_member_name, old_member_name_full, &old_member_name_full_offset_start))
1876 old_member_name_full,
1877 old_member_name_full_offset_start);
1879 const short old_member_index = member_info->
member_index;
1882 sdna->
members.append(new_member_name_full);
1896 if (struct_index != -1) {
1918 int names_expand_len = 0;
1919 for (
const int struct_index : sdna->
structs.index_range()) {
1926 int names_expand_index = 0;
1927 for (
const int struct_index : sdna->
structs.index_range()) {
1934 memcpy(struct_new, struct_old, array_size);
1935 sdna->
structs[struct_index] = struct_new;
1937 for (
int i = 0; i < struct_old->
members_num; i++) {
1942 names_array_len_expand[names_expand_index] =
1947 names_expand_index++;
1950 sdna->
members = std::move(names_expand);
1962 const StringRef *elem_alias = rename_maps.
members.lookup_ptr({struct_name_static, elem_static});
1980 const bool use_legacy_hack =
true;
1986 for (
int type_index = 0; type_index < sdna->
types_num; type_index++) {
1989 if (use_legacy_hack) {
1993 sdna->
alias.
types[type_index] = rename_maps.
types.lookup_default_as(type_name_static,
2001 for (
const int struct_index : sdna->
structs.index_range()) {
2005 if (use_legacy_hack) {
2009 for (
int a = 0; a < struct_info->
members_num; a++) {
2013 if (member_alias_full !=
nullptr) {
2031#ifdef WITH_DNA_GHASH
2035 for (
const int struct_index : sdna->
structs.index_range()) {
2044namespace dna::pointers {
2048 structs_.resize(sdna.
structs.size());
2049 for (
const int struct_i : sdna.
structs.index_range()) {
2050 const SDNA_Struct &sdna_struct = *sdna.structs[struct_i];
2051 StructInfo &struct_info = structs_[struct_i];
2053 struct_info.size_in_bytes = 0;
2054 for (const int member_i : IndexRange(sdna_struct.members_num)) {
2055 struct_info.size_in_bytes += get_member_size_in_bytes(&sdna_,
2056 &sdna_struct.members[member_i]);
2059 this->gather_pointer_members_recursive(sdna_struct, 0, structs_[struct_i]);
2063void PointersInDNA::gather_pointer_members_recursive(
const SDNA_Struct &sdna_struct,
2065 StructInfo &r_struct_info)
const
2067 int offset = initial_offset;
2072 const int array_elem_num = sdna_.members_array_num[member.
member_index];
2075 for (
int elem_i = 0; elem_i < array_elem_num; elem_i++) {
2077 r_struct_info.pointers.append(
2078 {offset + elem_i * sdna_.pointer_size, member_type_name, member_name});
2083 const SDNA_Struct &sub_sdna_struct = *sdna_.structs[substruct_i];
2084 int substruct_size = sdna_.types_size[member.
type_index];
2085 for (
int elem_i = 0; elem_i < array_elem_num; elem_i++) {
2086 this->gather_pointer_members_recursive(
2087 sub_sdna_struct, offset + elem_i * substruct_size, r_struct_info);
2097 if (info.offset == offset) {
2117 const void *initial_data,
2120 fmt::appender &dst);
2123 const void *initial_data,
2125 fmt::appender &dst);
2132 const int string_length = strnlen(
data, array_len);
2133 if (string_length == array_len) {
2136 for (
const int i :
IndexRange(string_length)) {
2141 if (!std::isprint(c)) {
2155 if (element_num == 1) {
2164 fmt::format_to(dst,
"{:{}}{}: <{}>\n",
"", indent, i, struct_name);
2171 const void *initial_data,
2175 const void *
data = initial_data;
2184 fmt::format_to(dst,
"{:{}}{} {}:",
"", indent, member_type_name, member_name);
2189 const char *str_data =
static_cast<const char *
>(
data);
2190 fmt::format_to(dst,
" ");
2192 fmt::format_to(dst,
"'{}'", str_data);
2195 for (
const int i :
IndexRange(member_array_len)) {
2196 fmt::format_to(dst,
"{} ",
int(str_data[i]));
2199 fmt::format_to(dst,
"\n");
2202 switch (member_category) {
2204 fmt::format_to(dst,
"\n");
2208 sdna, sub_sdna_struct,
data, member_array_len, indent + 2, dst);
2212 fmt::format_to(dst,
" ");
2215 for ([[maybe_unused]]
const int elem_i :
IndexRange(member_array_len)) {
2219 const char value = *
reinterpret_cast<const char *
>(current_data);
2220 fmt::format_to(dst,
"{}",
int(value));
2224 const uchar value = *
reinterpret_cast<const uchar *
>(current_data);
2225 fmt::format_to(dst,
"{}",
int(value));
2229 fmt::format_to(dst,
"{}", *
reinterpret_cast<const int8_t *
>(current_data));
2233 fmt::format_to(dst,
"{}", *
reinterpret_cast<const short *
>(current_data));
2237 fmt::format_to(dst,
"{}", *
reinterpret_cast<const ushort *
>(current_data));
2241 fmt::format_to(dst,
"{}", *
reinterpret_cast<const int *
>(current_data));
2245 fmt::format_to(dst,
"{}", *
reinterpret_cast<const float *
>(current_data));
2249 fmt::format_to(dst,
"{}", *
reinterpret_cast<const double *
>(current_data));
2253 fmt::format_to(dst,
"{}", *
reinterpret_cast<const int64_t *
>(current_data));
2257 fmt::format_to(dst,
"{}", *
reinterpret_cast<const uint64_t *
>(current_data));
2266 fmt::format_to(dst,
" ");
2268 fmt::format_to(dst,
"\n");
2272 for ([[maybe_unused]]
const int elem_i :
IndexRange(member_array_len)) {
2274 fmt::format_to(dst,
" {}", *
reinterpret_cast<const void *
const *
>(current_data));
2276 fmt::format_to(dst,
"\n");
2287 const int struct_id,
2288 const void *initial_data,
2289 const void *address,
2291 std::ostream &stream)
2295 fmt::memory_buffer buf;
2296 fmt::appender dst{buf};
2299 fmt::format_to(dst,
"<{}> {}x at {}\n", struct_name, element_num, address);
2302 stream << fmt::to_string(buf);
blenloader genfile private function prototypes
const unsigned char DNAstr[]
#define SDNA_RAW_DATA_STRUCT_INDEX
Read Blender memory allocation and freeing.
#define MAKE_ID(a, b, c, d)
#define BLI_assert_unreachable()
#define POINTER_OFFSET(v, ofs)
#define BLI_assert_msg(a, msg)
#define BLI_STATIC_ASSERT_ALIGN(st, align)
Array(Allocator allocator={}) noexcept
constexpr IndexRange()=default
void * allocate(const int64_t size, const int64_t alignment)
void reserve(const int64_t n)
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr int64_t size() const
PointersInDNA(const SDNA &sdna)
void append(const T &value)
void resize(const int64_t new_size)
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
static void print_struct_array_recursive(const SDNA &sdna, const SDNA_Struct &sdna_struct, const void *initial_data, const int64_t element_num, const int indent, fmt::appender &dst)
static bool char_array_startswith_simple_name(const char *data, const int array_len)
static void print_single_struct_recursive(const SDNA &sdna, const SDNA_Struct &sdna_struct, const void *initial_data, const int indent, fmt::appender &dst)
void print_struct_by_id(int struct_id, const void *data)
void print_structs_at_address(const SDNA &sdna, int struct_id, const void *data, const void *address, int64_t element_num, std::ostream &stream)
uint32_t struct_size(Span< shader::ShaderCreateInfo::PushConst > push_constants)
static bool elem_exists_impl(const Span< StringRef > types, const Span< StringRef > names, const StringRef type, const StringRef name, const SDNA_Struct *old)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
struct DNA_ReconstructInfo * DNA_reconstruct_info_create(const struct SDNA *oldsdna, const struct SDNA *newsdna, const char *compare_flags)
unsigned __int64 uint64_t
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings)==CTX_MODE_NUM+1, "Must have a string for each context mode") const char *CTX_data_mode_string(const bContext *C)
int DNA_struct_member_offset_by_name_without_alias(const struct SDNA *sdna, StringRef stype, StringRef vartype, StringRef name)
static const StringRef sdna_data_pointer_read_string(const char *&data, const void *const data_pointer_end, const char **r_error_message)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static int dna_struct_find_index_ex_impl(const Span< StringRef > types, const int, const Span< SDNA_Struct * > structs, const StringRef str, uint *struct_index_last)
bool DNA_sdna_patch_struct_member_by_name(struct SDNA *sdna, StringRef type_name, StringRef old_member_name, StringRef new_member_name)
static int elem_offset_without_alias(const SDNA *sdna, const StringRef type, const StringRef name, const SDNA_Struct *old)
static bool elem_exists_with_alias(const SDNA *sdna, const StringRef type, const StringRef name, const SDNA_Struct *old)
bool DNA_member_id_match(const StringRef member_id, const StringRef member_full, uint *r_member_full_offset)
static void reconstruct_struct(const DNA_ReconstructInfo *reconstruct_info, const int new_struct_index, const char *old_block, char *new_block)
BLI_INLINE const char * pad_up_4(const char *ptr)
bool DNA_sdna_patch_struct_by_name(struct SDNA *sdna, StringRef old_type_name, StringRef new_type_name)
void DNA_reconstruct_info_free(struct DNA_ReconstructInfo *reconstruct_info)
MatBase< float, 4, 4 > float4x4
void * DNA_struct_reconstruct(const struct DNA_ReconstructInfo *reconstruct_info, int old_struct_index, int blocks, const void *old_blocks, const char *alloc_name, int64_t *r_alloc_size=nullptr)
static int elem_offset_impl(const SDNA *sdna, const Span< StringRef > types, const Span< StringRef > names, const StringRef type, const StringRef name, const SDNA_Struct *old)
int DNA_struct_member_size(const struct SDNA *sdna, short type, short member_index)
uint DNA_member_id_offset_start(const StringRef member_full)
static bool init_structDNA(SDNA *sdna, const char **r_error_message)
int DNA_elem_type_size(eSDNA_Type elem_nr)
static void print_reconstruct_step(const ReconstructStep *step, const SDNA *oldsdna, const SDNA *newsdna)
bool DNA_struct_exists_without_alias(const struct SDNA *sdna, StringRef stype)
StringRef DNA_member_id_rename(LinearAllocator<> &mem_arena, const StringRef member_id_src, const StringRef member_id_dst, const StringRef member_full_src, const uint member_full_src_offset_len)
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)
StringRef DNA_struct_identifier(struct SDNA *sdna, int struct_index)
static int get_member_size_in_bytes(const SDNA *sdna, const SDNA_StructMember *member)
@ STRUCT_MEMBER_CATEGORY_POINTER
@ STRUCT_MEMBER_CATEGORY_PRIMITIVE
@ STRUCT_MEMBER_CATEGORY_STRUCT
int DNA_struct_find_index_without_alias_ex(const struct SDNA *sdna, StringRef str, unsigned int *struct_index_last)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static void reconstruct_structs(const DNA_ReconstructInfo *reconstruct_info, const int blocks, const int old_struct_index, const int new_struct_index, const char *old_blocks, char *new_blocks)
DnaRenameMaps DNA_rename_maps_static_to_alias()
static eStructMemberCategory get_struct_member_category(const SDNA *sdna, const SDNA_StructMember *member)
const char * DNA_struct_get_compareflags(const struct SDNA *oldsdna, const struct SDNA *newsdna)
BMesh const char void * data
StringRef DNA_member_id_string_ref(const StringRef member_full)
static bool sdna_data_validate_array_size(const int64_t size, T data_pointer_current, const void *const data_pointer_end, const char **r_error_message)
static bool DNA_sdna_patch_struct_member(SDNA *sdna, const int struct_index, const StringRef old_member_name, const StringRef new_member_name)
StringRef DNA_struct_rename_legacy_hack_static_from_alias(const StringRef name)
static bool ispointer(const StringRef name)
static void sdna_expand_names(SDNA *sdna)
bool DNA_struct_member_exists_without_alias(const struct SDNA *sdna, StringRef stype, StringRef vartype, StringRef name)
static bool DNA_sdna_patch_struct(SDNA *sdna, const int struct_index, const StringRef new_type_name)
ATTR_WARN_UNUSED_RESULT const size_t num
int DNA_struct_size(const struct SDNA *sdna, int struct_index)
_W64 unsigned int uintptr_t
void DNA_sdna_alias_data_ensure_structs_map(struct SDNA *sdna)
static void set_compare_flags_for_struct(const SDNA *oldsdna, const SDNA *newsdna, char *compare_flags, const int old_struct_index)
int DNA_struct_find_with_alias(const struct SDNA *sdna, StringRef str)
static void cast_pointer_64_to_32(const int array_len, const uint64_t *old_data, uint32_t *new_data)
static bool elem_exists_without_alias(const SDNA *sdna, const StringRef type, const StringRef name, const SDNA_Struct *old)
int DNA_struct_find_index_without_alias(const struct SDNA *sdna, StringRef str)
int DNA_member_array_num(const StringRef str)
StringRef DNA_struct_rename_legacy_hack_alias_from_static(const StringRef name)
bool DNA_struct_member_exists_with_alias(const struct SDNA *sdna, StringRef stype, StringRef vartype, StringRef name)
int DNA_struct_alignment(const struct SDNA *sdna, int struct_index)
static void cast_pointer_32_to_64(const int array_len, const uint32_t *old_data, uint64_t *new_data)
void DNA_sdna_alias_data_ensure(struct SDNA *sdna)
const SDNA * DNA_sdna_current_get()
void *(*) MEM_new_array_zeroed_aligned(size_t len, size_t size, size_t alignment, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
int DNA_struct_member_offset_by_name_with_alias(const struct SDNA *sdna, StringRef stype, StringRef vartype, StringRef name)
int DNA_struct_find_index_with_alias_ex(const struct SDNA *sdna, StringRef str, unsigned int *struct_index_last)
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 bool sdna_struct_size_check(const SDNA *sdna, const SDNA_Struct *struct_info, const int64_t voided_members_size, const char **r_error_message)
@ RECONSTRUCT_STEP_CAST_POINTER_TO_32
@ RECONSTRUCT_STEP_SUBSTRUCT
@ RECONSTRUCT_STEP_MEMCPY
@ RECONSTRUCT_STEP_INIT_ZERO
@ RECONSTRUCT_STEP_CAST_POINTER_TO_64
@ RECONSTRUCT_STEP_CAST_PRIMITIVE
static T sdna_data_pointer_read(T &data, const int64_t num, const void *const data_pointer_end, const char **r_error_message)
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_exists_with_alias(const struct SDNA *sdna, StringRef str)
static const SDNA_StructMember * find_member_with_matching_name(const SDNA *sdna, const SDNA_Struct *struct_info, const StringRef name, int *r_offset)
static bool elem_streq(const StringRef name, const StringRef oname)
static int compress_reconstruct_steps(ReconstructStep *steps, const int old_step_count)
std::unique_ptr< SDNA > DNA_sdna_from_data(const void *data, int data_len, bool data_alloc, bool do_alias, const char **r_error_message)
static int elem_offset_with_alias(const SDNA *sdna, const StringRef type, const StringRef name, const SDNA_Struct *old)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static StringRef dna_sdna_alias_from_static_elem_full(SDNA *sdna, const DnaRenameMaps &rename_maps, const StringRef struct_name_static, const StringRef elem_static_full)
const char * compare_flags
Map< std::pair< StringRef, StringRef >, StringRef > members
Map< StringRef, StringRef > types
union blender::ReconstructStep::@370104264300151155006146011007205111233044333126 data
eReconstructStepType type
SDNA_StructMember members[]
Array< SDNA_Struct *, 0 > structs
Vector< short > members_array_num
LinearAllocator mem_arena
struct blender::SDNA::@276375047207276123200247134171113130103131113323 alias
Map< StringRef, int > types_to_structs_map
Array< int > types_alignment
Vector< StringRef > members
bool has_pointer_at_offset(int64_t offset) const
Vector< PointerInfo > pointers
void resize(int new_size)
struct blender::ReconstructStep::@370104264300151155006146011007205111233044333126::@056216020370063175064236300326054315042333105364 substruct
struct blender::ReconstructStep::@370104264300151155006146011007205111233044333126::@375215207215274014330373137311365227171066213356 memcpy
struct blender::ReconstructStep::@370104264300151155006146011007205111233044333126::@254275337223066047364002100163372131176351135173 cast_primitive
struct blender::ReconstructStep::@370104264300151155006146011007205111233044333126::@015052325033005042010174340106001303127333001106 cast_pointer