Blender V5.3

DNA handling. More...

#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <fmt/format.h>
#include "MEM_guardedalloc.h"
#include "BLI_index_range.hh"
#include "BLI_math_matrix_types.hh"
#include "BLI_set.hh"
#include "BLI_utildefines.hh"
#include "DNA_genfile.h"
#include "DNA_print.hh"
#include "DNA_sdna_pointers.hh"
#include "DNA_sdna_types.h"

Go to the source code of this file.

Classes

struct  blender::ReconstructStep
struct  blender::DNA_ReconstructInfo

Namespaces

namespace  blender
 BMesh Iterators.
namespace  blender::dna
namespace  blender::dna::pointers

Macros

#define MAKE_ID(a, b, c, d)

Enumerations

enum  blender::eStructMemberCategory { blender::STRUCT_MEMBER_CATEGORY_STRUCT , blender::STRUCT_MEMBER_CATEGORY_PRIMITIVE , blender::STRUCT_MEMBER_CATEGORY_POINTER }
enum  blender::eReconstructStepType {
  blender::RECONSTRUCT_STEP_MEMCPY , blender::RECONSTRUCT_STEP_CAST_PRIMITIVE , blender::RECONSTRUCT_STEP_CAST_POINTER_TO_32 , blender::RECONSTRUCT_STEP_CAST_POINTER_TO_64 ,
  blender::RECONSTRUCT_STEP_SUBSTRUCT , blender::RECONSTRUCT_STEP_INIT_ZERO
}

Functions

int blender::DNA_struct_size (const SDNA *sdna, int struct_index)
static bool blender::ispointer (const StringRef name)
int blender::DNA_struct_member_size (const SDNA *sdna, short type, short member_index)
static int blender::dna_struct_find_index_ex_impl (const Span< StringRef > types, const int, const Span< SDNA_Struct * > structs, const StringRef str, uint *struct_index_last)
int blender::DNA_struct_find_index_without_alias_ex (const SDNA *sdna, const StringRef str, uint *struct_index_last)
int blender::DNA_struct_find_index_with_alias_ex (const SDNA *sdna, const StringRef str, uint *struct_index_last)
int blender::DNA_struct_find_index_without_alias (const SDNA *sdna, const StringRef str)
int blender::DNA_struct_find_with_alias (const SDNA *sdna, const StringRef str)
bool blender::DNA_struct_exists_with_alias (const SDNA *sdna, const StringRef str)
BLI_INLINE const char * blender::pad_up_4 (const char *ptr)
template<typename T>
static T blender::sdna_data_pointer_read (T &data, const int64_t num, const void *const data_pointer_end, const char **r_error_message)
template<typename T>
static bool blender::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 const StringRef blender::sdna_data_pointer_read_string (const char *&data, const void *const data_pointer_end, const char **r_error_message)
static bool blender::sdna_struct_size_check (const SDNA *sdna, const SDNA_Struct *struct_info, const int64_t voided_members_size, const char **r_error_message)
static bool blender::init_structDNA (SDNA *sdna, const char **r_error_message)
std::unique_ptr< SDNA > blender::DNA_sdna_from_data (const void *data, int data_len, bool data_alloc, bool do_alias, const char **r_error_message)
const SDNA * blender::DNA_sdna_current_get ()
static void blender::set_compare_flags_for_struct (const SDNA *oldsdna, const SDNA *newsdna, char *compare_flags, const int old_struct_index)
const char * blender::DNA_struct_get_compareflags (const SDNA *oldsdna, const SDNA *newsdna)
static void blender::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 blender::cast_pointer_32_to_64 (const int array_len, const uint32_t *old_data, uint64_t *new_data)
static void blender::cast_pointer_64_to_32 (const int array_len, const uint64_t *old_data, uint32_t *new_data)
static bool blender::elem_streq (const StringRef name, const StringRef oname)
static bool blender::elem_exists_impl (const Span< StringRef > types, const Span< StringRef > names, const StringRef type, const StringRef name, const SDNA_Struct *old)
static bool blender::elem_exists_without_alias (const SDNA *sdna, const StringRef type, const StringRef name, const SDNA_Struct *old)
static bool blender::elem_exists_with_alias (const SDNA *sdna, const StringRef type, const StringRef name, const SDNA_Struct *old)
static int blender::elem_offset_impl (const SDNA *sdna, const Span< StringRef > types, const Span< StringRef > names, const StringRef type, const StringRef name, const SDNA_Struct *old)
static int blender::elem_offset_without_alias (const SDNA *sdna, const StringRef type, const StringRef name, const SDNA_Struct *old)
static int blender::elem_offset_with_alias (const SDNA *sdna, const StringRef type, const StringRef name, const SDNA_Struct *old)
static eStructMemberCategory blender::get_struct_member_category (const SDNA *sdna, const SDNA_StructMember *member)
static int blender::get_member_size_in_bytes (const SDNA *sdna, const SDNA_StructMember *member)
static void blender::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)
static void blender::reconstruct_struct (const DNA_ReconstructInfo *reconstruct_info, const int new_struct_index, const char *old_block, char *new_block)
void * blender::DNA_struct_reconstruct (const DNA_ReconstructInfo *reconstruct_info, int old_struct_index, int blocks, const void *old_blocks, const char *alloc_name, int64_t *r_alloc_size)
static const SDNA_StructMember * blender::find_member_with_matching_name (const SDNA *sdna, const SDNA_Struct *struct_info, const StringRef name, int *r_offset)
static void blender::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)
static void blender::print_reconstruct_step (const ReconstructStep *step, const SDNA *oldsdna, const SDNA *newsdna)
static ReconstructStep * blender::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 int blender::compress_reconstruct_steps (ReconstructStep *steps, const int old_step_count)
DNA_ReconstructInfo * blender::DNA_reconstruct_info_create (const SDNA *oldsdna, const SDNA *newsdna, const char *compare_flags)
void blender::DNA_reconstruct_info_free (struct DNA_ReconstructInfo *reconstruct_info)
int blender::DNA_struct_member_offset_by_name_without_alias (const SDNA *sdna, const StringRef stype, const StringRef vartype, const StringRef name)
int blender::DNA_struct_member_offset_by_name_with_alias (const SDNA *sdna, const StringRef stype, const StringRef vartype, const StringRef name)
bool blender::DNA_struct_exists_without_alias (const SDNA *sdna, const StringRef stype)
bool blender::DNA_struct_member_exists_without_alias (const SDNA *sdna, const StringRef stype, const StringRef vartype, const StringRef name)
bool blender::DNA_struct_member_exists_with_alias (const SDNA *sdna, const StringRef stype, const StringRef vartype, const StringRef name)
int blender::DNA_elem_type_size (eSDNA_Type elem_nr)
int blender::DNA_struct_alignment (const SDNA *sdna, const int struct_index)
StringRef blender::DNA_struct_identifier (struct SDNA *sdna, int struct_index)
static void blender::dna::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 void blender::dna::print_single_struct_recursive (const SDNA &sdna, const SDNA_Struct &sdna_struct, const void *initial_data, const int indent, fmt::appender &dst)
static bool blender::dna::char_array_startswith_simple_name (const char *data, const int array_len)
void blender::dna::print_structs_at_address (const SDNA &sdna, int struct_id, const void *data, const void *address, int64_t element_num, std::ostream &stream)
void blender::dna::print_struct_by_id (int struct_id, const void *data)
Version Patch DNA
static bool blender::DNA_sdna_patch_struct (SDNA *sdna, const int struct_index, const StringRef new_type_name)
bool blender::DNA_sdna_patch_struct_by_name (struct SDNA *sdna, StringRef old_type_name, StringRef new_type_name)
static bool blender::DNA_sdna_patch_struct_member (SDNA *sdna, const int struct_index, const StringRef old_member_name, const StringRef new_member_name)
bool blender::DNA_sdna_patch_struct_member_by_name (struct SDNA *sdna, StringRef type_name, StringRef old_member_name, StringRef new_member_name)
Versioning (Forward Compatible)

Versioning that allows new names.

static void blender::sdna_expand_names (SDNA *sdna)
static StringRef blender::dna_sdna_alias_from_static_elem_full (SDNA *sdna, const DnaRenameMaps &rename_maps, const StringRef struct_name_static, const StringRef elem_static_full)
void blender::DNA_sdna_alias_data_ensure (struct SDNA *sdna)
void blender::DNA_sdna_alias_data_ensure_structs_map (struct SDNA *sdna)

Detailed Description

DNA handling.

Lowest-level functions for decoding the parts of a saved .blend file, including interpretation of its SDNA block and conversion of contents of other parts according to the differences between that SDNA and the SDNA of the current (running) version of Blender.

Definition in file dna_genfile.cc.

Macro Definition Documentation

◆ MAKE_ID

#define MAKE_ID ( a,
b,
c,
d )
Value:
(int(d) << 24 | int(c) << 16 | (b) << 8 | (a))

Overview

  • please NOTE: no builtin security to detect input of double structs
  • if you want a struct not to be in DNA file: add two hash marks above it (#<enter>#<enter>).

Structure DNA data is added to each blender file and to each executable, this to detect in .blend files new variables in structs, changed array sizes, etc. It is also used for converting pointer size (32-64 bits) (and it used to be to handle endianness). As an extra, Python uses a call to detect run-time the contents of a blender struct.

Create a structDNA: only needed when one of the input include (.h) files change. File Syntax:

SDNA (4 bytes) (magic number)
NAME (4 bytes)
<nr> (4 bytes) amount of names `int`.
<string>
<string>
...
...
TYPE (4 bytes)
<nr> amount of types `int`.
<string>
<string>
...
...
TLEN (4 bytes)
<len> (short) the lengths of types
<len>
...
...
STRC (4 bytes)
<nr> amount of structs `int`.
<typenr><nr_of_elems> <typenr><namenr> <typenr><namenr> ...

Remember to read/write integer and short aligned!

While writing a file, the names of a struct is indicated with a type number, to be found with: type = DNA_struct_find_with_alias(SDNA *, StringRef) The value of type corresponds with the index within the structs array

For the moment: the complete DNA file is included in a .blend file. For the future we can think of smarter methods, like only included the used structs. Only needed to keep a file short though...

ALLOWED AND TESTED CHANGES IN STRUCTS:

  • Type change (a char to float will be divided by 255).
  • Location within a struct (everything can be randomly mixed up).
  • Struct within struct (within struct etc), this is recursive.
  • Adding new elements, will be default initialized zero.
  • Removing elements.
  • Change of array sizes.
  • Change of a pointer type: when the name doesn't change the contents is copied.

NOT YET:

  • array (vec[3]) to float struct (vec3f).

DONE:

  • Pointer conversion (32-64 bits).

IMPORTANT:

  • Do not use #defines in structs for array lengths, this cannot be read by the dna functions.
  • Do not use uint, but unsigned int instead, ushort and ulong are allowed.
  • Only use a long in Blender if you want this to be the size of a pointer. so it is 32 bits or 64 bits, dependent at the cpu architecture.
  • Chars are always unsigned
  • Alignment of variables has to be done in such a way, that any system does not create 'padding' (gaps) in structures. So make sure that:
    • short: 2 aligned.
    • int: 4 aligned.
    • float: 4 aligned.
    • double: 8 aligned.
    • long: 8 aligned.
    • int64: 8 aligned.
    • struct: 8 aligned.
  • the sdna functions have several error prints builtin, always check blender running from a console.

Definition at line 121 of file dna_genfile.cc.