Blender  V3.3
Classes | Macros | Typedefs | Enumerations | Functions | Variables

DNA handling. More...

#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_endian_switch.h"
#include "BLI_memarena.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BLI_ghash.h"
#include "DNA_genfile.h"
#include "DNA_sdna_types.h"

Go to the source code of this file.

Classes

struct  ReconstructStep
 
struct  DNA_ReconstructInfo
 

Macros

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

Typedefs

typedef enum eStructMemberCategory eStructMemberCategory
 
typedef enum eReconstructStepType eReconstructStepType
 
typedef struct ReconstructStep ReconstructStep
 
typedef struct DNA_ReconstructInfo DNA_ReconstructInfo
 

Enumerations

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

Functions

void DNA_sdna_free (SDNA *sdna)
 
static bool ispointer (const char *name)
 
int DNA_elem_size_nr (const SDNA *sdna, short type, short name)
 
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)
 
int DNA_struct_find_nr_ex (const SDNA *sdna, const char *str, unsigned int *index_last)
 
int DNA_struct_alias_find_nr_ex (const SDNA *sdna, const char *str, unsigned int *index_last)
 
int DNA_struct_find_nr (const SDNA *sdna, const char *str)
 
int DNA_struct_alias_find_nr (const SDNA *sdna, const char *str)
 
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)
 
SDNADNA_sdna_from_data (const void *data, const int data_len, bool do_endian_swap, bool data_alloc, const char **r_error_message)
 
void DNA_sdna_current_init (void)
 
const struct SDNADNA_sdna_current_get (void)
 
void DNA_sdna_current_free (void)
 
static void set_compare_flags_for_struct (const SDNA *oldsdna, const SDNA *newsdna, char *compare_flags, const int old_struct_index)
 
const char * DNA_struct_get_compareflags (const SDNA *oldsdna, const SDNA *newsdna)
 
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 cast_pointer_32_to_64 (const int array_len, const uint32_t *old_data, uint64_t *new_data)
 
static void cast_pointer_64_to_32 (const int array_len, const uint64_t *old_data, uint32_t *new_data)
 
static bool elem_streq (const char *name, const char *oname)
 
static bool elem_exists_impl (const char **types, const char **names, 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)
 
static bool elem_exists_alias (const SDNA *sdna, const char *type, const char *name, const SDNA_Struct *old)
 
static int elem_offset (const SDNA *sdna, const char *type, const char *name, const SDNA_Struct *old)
 
static eStructMemberCategory get_struct_member_category (const SDNA *sdna, const SDNA_StructMember *member)
 
static int get_member_size_in_bytes (const SDNA *sdna, const SDNA_StructMember *member)
 
void DNA_struct_switch_endian (const SDNA *sdna, int struct_nr, char *data)
 
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 void reconstruct_struct (const DNA_ReconstructInfo *reconstruct_info, const int new_struct_nr, const char *old_block, char *new_block)
 
voidDNA_struct_reconstruct (const DNA_ReconstructInfo *reconstruct_info, int old_struct_nr, int blocks, const void *old_blocks)
 
static const SDNA_StructMemberfind_member_with_matching_name (const SDNA *sdna, const SDNA_Struct *struct_info, const char *name, int *r_offset)
 
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)
 
static void print_reconstruct_step (ReconstructStep *step, const SDNA *oldsdna, const SDNA *newsdna)
 
static ReconstructStepcreate_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 compress_reconstruct_steps (ReconstructStep *steps, const int old_step_count)
 
DNA_ReconstructInfoDNA_reconstruct_info_create (const SDNA *oldsdna, const SDNA *newsdna, const char *compare_flags)
 
void DNA_reconstruct_info_free (DNA_ReconstructInfo *reconstruct_info)
 
int DNA_elem_offset (SDNA *sdna, const char *stype, const char *vartype, const char *name)
 
bool DNA_struct_find (const SDNA *sdna, const char *stype)
 
bool DNA_struct_elem_find (const SDNA *sdna, const char *stype, const char *vartype, const char *name)
 
bool DNA_struct_alias_elem_find (const SDNA *sdna, const char *stype, const char *vartype, const char *name)
 
int DNA_elem_type_size (const eSDNA_Type elem_nr)
 
Version Patch DNA
static bool DNA_sdna_patch_struct_nr (SDNA *sdna, const int struct_name_old_nr, const char *struct_name_new)
 
bool DNA_sdna_patch_struct (SDNA *sdna, const char *struct_name_old, const char *struct_name_new)
 
static bool DNA_sdna_patch_struct_member_nr (SDNA *sdna, const int struct_name_nr, const char *elem_old, const char *elem_new)
 
bool DNA_sdna_patch_struct_member (SDNA *sdna, const char *struct_name, const char *elem_old, const char *elem_new)
 
Versioning (Forward Compatible)

Versioning that allows new names.

static void sdna_expand_names (SDNA *sdna)
 
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)
 
void DNA_sdna_alias_data_ensure (SDNA *sdna)
 
void DNA_sdna_alias_data_ensure_structs_map (SDNA *sdna)
 

Variables

static SDNAg_sdna = NULL
 

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.c.

Macro Definition Documentation

◆ MAKE_ID

#define MAKE_ID (   a,
  b,
  c,
 
)    ((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's also used for converting endian and pointer size (32-64 bits) 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_nr(SDNA *, const char *) 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:

  • Endian compatibility.
  • 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 118 of file dna_genfile.c.

Typedef Documentation

◆ DNA_ReconstructInfo

◆ eReconstructStepType

◆ eStructMemberCategory

◆ ReconstructStep

Enumeration Type Documentation

◆ eReconstructStepType

Enumerator
RECONSTRUCT_STEP_MEMCPY 
RECONSTRUCT_STEP_CAST_PRIMITIVE 
RECONSTRUCT_STEP_CAST_POINTER_TO_32 
RECONSTRUCT_STEP_CAST_POINTER_TO_64 
RECONSTRUCT_STEP_SUBSTRUCT 
RECONSTRUCT_STEP_INIT_ZERO 

Definition at line 1078 of file dna_genfile.c.

◆ eStructMemberCategory

Enumerator
STRUCT_MEMBER_CATEGORY_STRUCT 
STRUCT_MEMBER_CATEGORY_PRIMITIVE 
STRUCT_MEMBER_CATEGORY_POINTER 

Definition at line 979 of file dna_genfile.c.

Function Documentation

◆ cast_pointer_32_to_64()

static void cast_pointer_32_to_64 ( const int  array_len,
const uint32_t old_data,
uint64_t new_data 
)
static

Definition at line 833 of file dna_genfile.c.

References Freestyle::a.

Referenced by reconstruct_struct().

◆ cast_pointer_64_to_32()

static void cast_pointer_64_to_32 ( const int  array_len,
const uint64_t old_data,
uint32_t new_data 
)
static

Definition at line 842 of file dna_genfile.c.

References Freestyle::a.

Referenced by reconstruct_struct().

◆ cast_primitive_type()

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

Converts a value of one primitive type to another.

Note
there is no optimization for the case where otype and ctype are the same: assumption is that caller will handle this case.
Parameters
old_typeType to convert from.
new_typeType to convert to.
array_lenNumber of elements to convert.
old_dataBuffer containing the old values.
new_dataBuffer the converted values will be written to.

Definition at line 709 of file dna_genfile.c.

References Freestyle::a, DNA_elem_type_size(), double(), SDNA_TYPE_CHAR, SDNA_TYPE_DOUBLE, SDNA_TYPE_FLOAT, SDNA_TYPE_INT, SDNA_TYPE_INT64, SDNA_TYPE_INT8, SDNA_TYPE_SHORT, SDNA_TYPE_UCHAR, SDNA_TYPE_UINT64, and SDNA_TYPE_USHORT.

Referenced by reconstruct_struct().

◆ compress_reconstruct_steps()

static int compress_reconstruct_steps ( ReconstructStep steps,
const int  old_step_count 
)
static

◆ create_reconstruct_steps_for_struct()

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

Generate an array of reconstruct steps for the given #new_struct. There will be one reconstruct step for every member.

Definition at line 1445 of file dna_genfile.c.

References get_member_size_in_bytes(), init_reconstruct_step_for_member(), MEM_calloc_arrayN, SDNA_Struct::members, SDNA_Struct::members_len, and steps.

Referenced by DNA_reconstruct_info_create().

◆ DNA_elem_offset()

int DNA_elem_offset ( struct SDNA sdna,
const char *  stype,
const char *  vartype,
const char *  name 
)

Returns the offset of the field with the specified name and type within the specified struct type in SDNA, -1 on failure.

Definition at line 1571 of file dna_genfile.c.

References BLI_assert, DNA_struct_find_nr(), elem_offset(), and SDNA::structs.

Referenced by read_file_dna().

◆ DNA_elem_size_nr()

int DNA_elem_size_nr ( const SDNA sdna,
short  type,
short  name 
)

Definition at line 164 of file dna_genfile.c.

References ispointer(), len, SDNA::names, SDNA::names_array_len, SDNA::pointer_size, type, and SDNA::types_size.

Referenced by elem_offset().

◆ DNA_elem_type_size()

int DNA_elem_type_size ( eSDNA_Type  elem_nr)

Returns the size in bytes of a primitive type.

Definition at line 1620 of file dna_genfile.c.

References SDNA_TYPE_CHAR, SDNA_TYPE_DOUBLE, SDNA_TYPE_FLOAT, SDNA_TYPE_INT, SDNA_TYPE_INT64, SDNA_TYPE_INT8, SDNA_TYPE_SHORT, SDNA_TYPE_UCHAR, SDNA_TYPE_UINT64, and SDNA_TYPE_USHORT.

Referenced by cast_primitive_type().

◆ DNA_reconstruct_info_create()

DNA_ReconstructInfo* DNA_reconstruct_info_create ( const SDNA oldsdna,
const SDNA newsdna,
const char *  compare_flags 
)

◆ DNA_reconstruct_info_free()

void DNA_reconstruct_info_free ( DNA_ReconstructInfo reconstruct_info)

◆ DNA_sdna_alias_data_ensure()

void DNA_sdna_alias_data_ensure ( SDNA sdna)

◆ DNA_sdna_alias_data_ensure_structs_map()

void DNA_sdna_alias_data_ensure_structs_map ( struct SDNA sdna)

Separated from DNA_sdna_alias_data_ensure because it's not needed unless we want to lookup aliased struct names (DNA_struct_alias_find_nr and friends).

Definition at line 1867 of file dna_genfile.c.

References SDNA::alias, BLI_ghash_insert(), BLI_ghash_str_new_ex(), DNA_sdna_alias_data_ensure(), POINTER_FROM_INT, SDNA::structs, SDNA::structs_len, SDNA::structs_map, SDNA_Struct::type, SDNA::types, and UNUSED_VARS.

◆ dna_sdna_alias_from_static_elem_full()

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 
)
static

◆ DNA_sdna_current_free()

void DNA_sdna_current_free ( void  )

Definition at line 572 of file dna_genfile.c.

References DNA_sdna_free(), g_sdna, and NULL.

Referenced by BlendfileLoadingBaseTest::TearDownTestCase(), and WM_exit_ex().

◆ DNA_sdna_current_get()

const struct SDNA* DNA_sdna_current_get ( void  )

Definition at line 566 of file dna_genfile.c.

References BLI_assert, g_sdna, and NULL.

Referenced by DNA_sdna_patch_struct_nr(), filedata_new(), and writedata_new().

◆ DNA_sdna_current_init()

void DNA_sdna_current_init ( void  )

Definition at line 561 of file dna_genfile.c.

References DNA_sdna_from_data(), DNAlen, DNAstr, g_sdna, and NULL.

Referenced by main(), and BlendfileLoadingBaseTest::SetUpTestCase().

◆ DNA_sdna_free()

void DNA_sdna_free ( SDNA sdna)

◆ DNA_sdna_from_data()

SDNA* DNA_sdna_from_data ( const void data,
int  data_len,
bool  do_endian_swap,
bool  data_alloc,
const char **  r_error_message 
)

Constructs and returns a decoded SDNA structure from the given encoded SDNA data block.

Definition at line 519 of file dna_genfile.c.

References data, SDNA::data, SDNA::data_alloc, SDNA::data_len, DNA_sdna_free(), init_structDNA(), MEM_mallocN, and NULL.

Referenced by DNA_sdna_current_init(), read_file_dna(), and RNA_create().

◆ DNA_sdna_patch_struct()

bool DNA_sdna_patch_struct ( struct SDNA sdna,
const char *  struct_name_old,
const char *  struct_name_new 
)

Rename a struct

Definition at line 1662 of file dna_genfile.c.

References DNA_sdna_patch_struct_nr(), and DNA_struct_find_nr().

Referenced by blo_do_versions_dna().

◆ DNA_sdna_patch_struct_member()

bool DNA_sdna_patch_struct_member ( struct SDNA sdna,
const char *  struct_name,
const char *  elem_old,
const char *  elem_new 
)

Replace elem_old with elem_new for struct struct_name handles search & replace, maintaining surrounding non-identifier characters such as pointer & array size.

Definition at line 1719 of file dna_genfile.c.

References DNA_sdna_patch_struct_member_nr(), and DNA_struct_find_nr().

Referenced by blo_do_versions_dna().

◆ DNA_sdna_patch_struct_member_nr()

static bool DNA_sdna_patch_struct_member_nr ( SDNA sdna,
const int  struct_name_nr,
const char *  elem_old,
const char *  elem_new 
)
static

◆ DNA_sdna_patch_struct_nr()

static bool DNA_sdna_patch_struct_nr ( SDNA sdna,
const int  struct_name_old_nr,
const char *  struct_name_new 
)
static

◆ DNA_struct_alias_elem_find()

bool DNA_struct_alias_elem_find ( const SDNA sdna,
const char *  stype,
const char *  vartype,
const char *  name 
)

Definition at line 1602 of file dna_genfile.c.

References DNA_struct_alias_find_nr(), elem_exists_alias(), and SDNA::structs.

◆ DNA_struct_alias_find_nr()

int DNA_struct_alias_find_nr ( const SDNA sdna,
const char *  str 
)

Definition at line 286 of file dna_genfile.c.

References DNA_struct_alias_find_nr_ex(), str, and UINT_MAX.

Referenced by DNA_struct_alias_elem_find().

◆ DNA_struct_alias_find_nr_ex()

int DNA_struct_alias_find_nr_ex ( const SDNA sdna,
const char *  str,
unsigned int *  index_last 
)

◆ DNA_struct_elem_find()

bool DNA_struct_elem_find ( const SDNA sdna,
const char *  stype,
const char *  vartype,
const char *  name 
)

Definition at line 1584 of file dna_genfile.c.

References DNA_struct_find_nr(), elem_exists(), and SDNA::structs.

◆ DNA_struct_find()

bool DNA_struct_find ( const SDNA sdna,
const char *  stype 
)

Definition at line 1579 of file dna_genfile.c.

References DNA_struct_find_nr().

Referenced by get_struct_member_category().

◆ DNA_struct_find_nr()

int DNA_struct_find_nr ( const SDNA sdna,
const char *  str 
)

◆ DNA_struct_find_nr_ex()

int DNA_struct_find_nr_ex ( const SDNA sdna,
const char *  str,
unsigned int *  index_last 
)

◆ dna_struct_find_nr_ex_impl()

static int dna_struct_find_nr_ex_impl ( const char **  types,
const int   UNUSEDtypes_len,
SDNA_Struct **const  structs,
const int  structs_len,
const char *  str,
unsigned int *  index_last 
)
static

Returns the index of the struct info for the struct with the specified name.

Definition at line 202 of file dna_genfile.c.

References BLI_ghash_lookup_p(), POINTER_AS_INT, str, STREQ, structs, structs_len, SDNA_Struct::type, and types.

Referenced by DNA_struct_alias_find_nr_ex(), and DNA_struct_find_nr_ex().

◆ DNA_struct_get_compareflags()

const char* DNA_struct_get_compareflags ( const SDNA oldsdna,
const SDNA newsdna 
)

◆ DNA_struct_reconstruct()

void* DNA_struct_reconstruct ( const DNA_ReconstructInfo reconstruct_info,
int  old_struct_nr,
int  blocks,
const void old_blocks 
)

◆ DNA_struct_switch_endian()

void DNA_struct_switch_endian ( const SDNA sdna,
int  struct_nr,
char *  data 
)

◆ elem_exists()

static bool elem_exists ( const SDNA sdna,
const char *  type,
const char *  name,
const SDNA_Struct old 
)
static
Parameters
sdnaOld SDNA.

Definition at line 910 of file dna_genfile.c.

References elem_exists_impl(), SDNA::names, type, and SDNA::types.

Referenced by DNA_struct_elem_find().

◆ elem_exists_alias()

static bool elem_exists_alias ( const SDNA sdna,
const char *  type,
const char *  name,
const SDNA_Struct old 
)
static

Definition at line 925 of file dna_genfile.c.

References SDNA::alias, elem_exists_impl(), SDNA::names, type, and SDNA::types.

Referenced by DNA_struct_alias_elem_find().

◆ elem_exists_impl()

static bool elem_exists_impl ( const char **  types,
const char **  names,
const char *  type,
const char *  name,
const SDNA_Struct old 
)
static

Returns whether the specified field exists according to the struct format pointed to by old.

Parameters
typeCurrent field type name.
nameCurrent field name.
oldPointer to struct information in sdna.
Returns
true when existing, false otherwise..

Definition at line 885 of file dna_genfile.c.

References Freestyle::a, elem_streq(), SDNA_Struct::members, SDNA_Struct::members_len, SDNA_StructMember::name, names, STREQ, type, SDNA_StructMember::type, and types.

Referenced by elem_exists(), and elem_exists_alias().

◆ elem_offset()

static int elem_offset ( const SDNA sdna,
const char *  type,
const char *  name,
const SDNA_Struct old 
)
static

Return the offset in bytes or -1 on failure to find the struct member with its expected type.

Parameters
sdnaOld SDNA.
typeCurrent field type name.
nameCurrent field name.
oldPointer to struct information in SDNA.
Returns
The offset or -1 on failure.
Note
Use elem_exists if additional information provided by this function is not needed.
We could have a version of this function that returns the SDNA_StructMember currently it's not needed.

Definition at line 954 of file dna_genfile.c.

References Freestyle::a, DNA_elem_size_nr(), elem_streq(), SDNA_Struct::members, SDNA_Struct::members_len, SDNA_StructMember::name, SDNA::names, offset, STREQ, type, SDNA_StructMember::type, and SDNA::types.

Referenced by BM_mesh_elem_index_ensure_ex(), DNA_elem_id_strip(), DNA_elem_offset(), and EDBM_mesh_elem_index_ensure_multi().

◆ elem_streq()

static bool elem_streq ( const char *  name,
const char *  oname 
)
static

Equality test on name and oname excluding any array-size suffix.

Definition at line 857 of file dna_genfile.c.

References Freestyle::a.

Referenced by elem_exists_impl(), elem_offset(), and find_member_with_matching_name().

◆ find_member_with_matching_name()

static const SDNA_StructMember* find_member_with_matching_name ( const SDNA sdna,
const SDNA_Struct struct_info,
const char *  name,
int *  r_offset 
)
static

Finds a member in the given struct with the given name.

Definition at line 1241 of file dna_genfile.c.

References Freestyle::a, elem_streq(), get_member_size_in_bytes(), SDNA_Struct::members, SDNA_Struct::members_len, SDNA_StructMember::name, SDNA::names, NULL, and offset.

Referenced by init_reconstruct_step_for_member().

◆ get_member_size_in_bytes()

static int get_member_size_in_bytes ( const SDNA sdna,
const SDNA_StructMember member 
)
static

◆ get_struct_member_category()

static eStructMemberCategory get_struct_member_category ( const SDNA sdna,
const SDNA_StructMember member 
)
static

◆ init_reconstruct_step_for_member()

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 
)
static

◆ init_structDNA()

static bool init_structDNA ( SDNA sdna,
bool  do_endian_swap,
const char **  r_error_message 
)
static

◆ ispointer()

static bool ispointer ( const char *  name)
static

Return true if the name indicates a pointer of some kind.

Definition at line 158 of file dna_genfile.c.

Referenced by DNA_elem_size_nr(), get_member_size_in_bytes(), get_struct_member_category(), and set_compare_flags_for_struct().

◆ pad_up_4()

BLI_INLINE const char* pad_up_4 ( const char *  ptr)

Definition at line 296 of file dna_genfile.c.

References ptr.

Referenced by init_structDNA().

◆ print_reconstruct_step()

static void print_reconstruct_step ( ReconstructStep step,
const SDNA oldsdna,
const SDNA newsdna 
)
static

◆ reconstruct_struct()

static void reconstruct_struct ( const DNA_ReconstructInfo reconstruct_info,
const int  new_struct_nr,
const char *  old_block,
char *  new_block 
)
static

Converts the contents of an entire struct from oldsdna to newsdna format.

Parameters
reconstruct_infoPreprocessed reconstruct information generated by DNA_reconstruct_info_create.
new_struct_nrIndex in newsdna->structs of the struct that is being reconstructed.
old_blockMemory buffer containing the old struct.
new_blockWhere to put converted struct contents.

Definition at line 1142 of file dna_genfile.c.

References Freestyle::a, ReconstructStep::cast_pointer, cast_pointer_32_to_64(), cast_pointer_64_to_32(), ReconstructStep::cast_primitive, cast_primitive_type(), ReconstructStep::data, ReconstructStep::memcpy, RECONSTRUCT_STEP_CAST_POINTER_TO_32, RECONSTRUCT_STEP_CAST_POINTER_TO_64, RECONSTRUCT_STEP_CAST_PRIMITIVE, RECONSTRUCT_STEP_INIT_ZERO, RECONSTRUCT_STEP_MEMCPY, RECONSTRUCT_STEP_SUBSTRUCT, reconstruct_structs(), DNA_ReconstructInfo::step_counts, steps, DNA_ReconstructInfo::steps, ReconstructStep::substruct, and ReconstructStep::type.

Referenced by reconstruct_structs().

◆ reconstruct_structs()

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

◆ sdna_expand_names()

static void sdna_expand_names ( SDNA sdna)
static

Names are shared between structs which causes problems renaming. Make sure every struct member gets its own name so renaming only ever impacts a single struct.

The resulting SDNA is never written to disk.

Definition at line 1745 of file dna_genfile.c.

References BLI_assert, BLI_memarena_alloc(), SDNA::mem_arena, MEM_freeN, MEM_mallocN, SDNA_Struct::members, SDNA_Struct::members_len, SDNA_StructMember::name, SDNA::names, SDNA::names_array_len, SDNA::names_len, SDNA::structs, and SDNA::structs_len.

Referenced by DNA_sdna_alias_data_ensure().

◆ set_compare_flags_for_struct()

static void set_compare_flags_for_struct ( const SDNA oldsdna,
const SDNA newsdna,
char *  compare_flags,
const int  old_struct_index 
)
static

This function changes compare_flags[old_struct_index] from SDNA_CMP_UNKNOWN to something else. It might call itself recursively.

Definition at line 586 of file dna_genfile.c.

References DNA_struct_find_nr(), ispointer(), SDNA_Struct::members, SDNA_Struct::members_len, SDNA_StructMember::name, SDNA::names, SDNA::pointer_size, SDNA_CMP_EQUAL, SDNA_CMP_NOT_EQUAL, SDNA_CMP_REMOVED, SDNA_CMP_UNKNOWN, STREQ, SDNA::structs, SDNA_StructMember::type, SDNA_Struct::type, SDNA::types, and SDNA::types_size.

Referenced by DNA_struct_get_compareflags().

Variable Documentation

◆ g_sdna

SDNA* g_sdna = NULL
static

Using a global is acceptable here, the data is read-only and only changes between Blender versions.

So it is safe to create once and reuse.

Definition at line 559 of file dna_genfile.c.

Referenced by DNA_sdna_current_free(), DNA_sdna_current_get(), and DNA_sdna_current_init().