Blender  V3.3
Macros | Variables

Struct muncher for making SDNA. More...

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_alloca.h"
#include "BLI_ghash.h"
#include "BLI_memarena.h"
#include "BLI_sys_types.h"
#include "BLI_system.h"
#include "BLI_utildefines.h"
#include "dna_utils.h"
#include "dna_includes_as_strings.h"
#include "dna_includes_all.h"
#include "dna_rename_defs.h"

Go to the source code of this file.

Macros

#define DNA_DEPRECATED_ALLOW
 
#define SDNA_MAX_FILENAME_LENGTH   255
 
#define FORCE_ALIGN_4   " "
 
#define DNA_STRUCT_RENAME(old, new)   (void)sizeof(new);
 
#define DNA_STRUCT_RENAME_ELEM(struct_name, old, new)   (void)offsetof(struct_name, new);
 

Functions

Function Declarations
static int add_type (const char *str, int size)
 
static int add_name (const char *str)
 
static short * add_struct (int namecode)
 
static int preprocess_include (char *maindata, const int maindata_len)
 
static int convert_include (const char *filepath)
 
static int calculate_struct_sizes (int firststruct, FILE *file_verify, const char *base_directory)
 
static void dna_write (FILE *file, const void *pntr, const int size)
 
void print_struct_sizes (void)
 
DNA Renaming Sanity Check

Disable types:

  • 'long': even though DNA supports, 'long' shouldn't be used since it can be either 32 or 64bit, use int, int32_t or int64_t instead.

Only valid use would be as a runtime variable if an API expected a long, but so far we don't have this happening.

Without this it's possible to reference struct members that don't exist, breaking backward & forward compatibility.

static void UNUSED_FUNCTION() dna_rename_defs_ensure (void)
 

Variables

static const char * includefiles []
 

Variables

#define DEBUG_PRINTF(debug_level, ...)
 
static MemArenamem_arena = NULL
 
static int max_data_size = 500000
 
static int max_array_len = 50000
 
static int names_len = 0
 
static int types_len = 0
 
static int structs_len = 0
 
static char ** names
 
static char ** types
 
static short * types_size_native
 
static short * types_align_32
 
static short * types_align_64
 
static short * types_size_32
 
static short * types_size_64
 
static short ** structs
 
static short * structdata
 
struct {
   GHash *   struct_map_alias_from_static
 
   GHash *   struct_map_static_from_alias
 
   GHash *   elem_map_alias_from_static
 
   GHash *   elem_map_static_from_alias
 
g_version_data = {NULL}
 
static int debugSDNA = 0
 
static int additional_slen_offset
 
void BLI_system_backtrace (FILE *fp)
 

Implementation

Make DNA string (write to file).

#define MAX_DNA_LINE_LENGTH   20
 
static bool match_identifier_with_len (const char *str, const char *identifier, const size_t identifier_len)
 
static bool match_identifier (const char *str, const char *identifier)
 
static bool match_identifier_and_advance (char **str_ptr, const char *identifier)
 
static const char * version_struct_static_from_alias (const char *str)
 
static const char * version_struct_alias_from_static (const char *str)
 
static const char * version_elem_static_from_alias (const int strct, const char *elem_alias_full)
 
static bool is_name_legal (const char *name)
 
static voidread_file_data (const char *filepath, int *r_len)
 
static bool check_field_alignment (int firststruct, int structtype, int type, int len, const char *name, const char *detail)
 
static int make_structDNA (const char *base_directory, FILE *file, FILE *file_offsets, FILE *file_verify)
 

Main Function

#define BASE_HEADER   "../"
 
static void make_bad_file (const char *file, int line)
 
int main (int argc, char **argv)
 

Detailed Description

Struct muncher for making SDNA.

About makesdna tool

makesdna creates a .c file with a long string of numbers that encode the Blender file format. It is fast, because it is basically a binary dump. There are some details to mind when reconstructing the file (endianness and byte-alignment).

This little program scans all structs that need to be serialized, and determined the names and types of all members. It calculates how much memory (on disk or in ram) is needed to store that struct, and the offsets for reaching a particular one.

There is a facility to get verbose output from sdna. Search for debugSDNA. This int can be set to 0 (no output) to some int. Higher numbers give more output.

Definition in file makesdna.c.

Macro Definition Documentation

◆ BASE_HEADER

#define BASE_HEADER   "../"

Definition at line 1436 of file makesdna.c.

◆ DEBUG_PRINTF

#define DEBUG_PRINTF (   debug_level,
  ... 
)
Value:
{ \
if (debugSDNA > debug_level) { \
printf(__VA_ARGS__); \
} \
} \
((void)0)
SyclQueue void void size_t num_bytes void
static int debugSDNA
Definition: makesdna.c:102

Definition at line 105 of file makesdna.c.

◆ DNA_DEPRECATED_ALLOW

#define DNA_DEPRECATED_ALLOW

Definition at line 26 of file makesdna.c.

◆ DNA_STRUCT_RENAME

#define DNA_STRUCT_RENAME (   old,
  new 
)    (void)sizeof(new);

◆ DNA_STRUCT_RENAME_ELEM

#define DNA_STRUCT_RENAME_ELEM (   struct_name,
  old,
  new 
)    (void)offsetof(struct_name, new);

◆ FORCE_ALIGN_4

#define FORCE_ALIGN_4   " "

◆ MAX_DNA_LINE_LENGTH

#define MAX_DNA_LINE_LENGTH   20

Definition at line 1127 of file makesdna.c.

◆ SDNA_MAX_FILENAME_LENGTH

#define SDNA_MAX_FILENAME_LENGTH   255

Definition at line 44 of file makesdna.c.

Function Documentation

◆ add_name()

static int add_name ( const char *  str)
static

Ensure str is int the names array.

Parameters
strStruct member name which may include pointer prefix & array size.
Returns
Index in the names array.

Because of the weird way of tokenizing, we have to 'cast' function pointers to ... (*f)(), whatever the original signature. In fact, we add name and type at the same time... There are two special cases, unfortunately. These are explicitly checked.

Definition at line 347 of file makesdna.c.

References additional_slen_offset, BLI_memarena_alloc(), DEBUG_PRINTF, is_name_legal(), max_array_len, mem_arena, names, names_len, NULL, str, and STREQ.

Referenced by convert_include().

◆ add_struct()

static short * add_struct ( int  namecode)
static

Search whether this structure type was already found, and if not, add it.

Definition at line 486 of file makesdna.c.

References len, max_array_len, structdata, structs, and structs_len.

Referenced by convert_include().

◆ add_type()

static int add_type ( const char *  str,
int  size 
)
static

Ensure type str to is in the types array.

Parameters
strStruct name without any qualifiers.
sizeThe struct size in bytes.
Returns
Index in the types array.

Definition at line 294 of file makesdna.c.

References BLI_memarena_alloc(), max_array_len, mem_arena, size(), str, STREQ, types, types_align_32, types_align_64, types_len, types_size_32, types_size_64, types_size_native, and version_struct_static_from_alias().

Referenced by convert_include(), and make_structDNA().

◆ BLI_system_backtrace()

void BLI_system_backtrace ( FILE *  fp)

Write a backtrace into a file for systems which support it.

Definition at line 115 of file makesdna.c.

References void.

◆ calculate_struct_sizes()

static int calculate_struct_sizes ( int  firststruct,
FILE *  file_verify,
const char *  base_directory 
)
static

◆ check_field_alignment()

static bool check_field_alignment ( int  firststruct,
int  structtype,
int  type,
int  len,
const char *  name,
const char *  detail 
)
static

Definition at line 819 of file makesdna.c.

References len, result, type, types, and types_size_native.

Referenced by calculate_struct_sizes().

◆ convert_include()

static int convert_include ( const char *  filepath)
static

◆ dna_rename_defs_ensure()

static void UNUSED_FUNCTION() dna_rename_defs_ensure ( void  )
static

Definition at line 1555 of file makesdna.c.

◆ dna_write()

static void dna_write ( FILE *  file,
const void pntr,
const int  size 
)
static

Construct the DNA.c file

Definition at line 1129 of file makesdna.c.

References data, file, MAX_DNA_LINE_LENGTH, and size().

Referenced by make_structDNA().

◆ is_name_legal()

static bool is_name_legal ( const char *  name)
static

Enforce '_pad123' naming convention, disallow 'pad123' or 'pad_123', special exception for [a-z] after since there is a 'pad_rot_angle' preference.

Definition at line 255 of file makesdna.c.

References Freestyle::c, and DNA_elem_id_strip_copy().

Referenced by add_name().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 1439 of file makesdna.c.

References BASE_HEADER, ELEM, FORCE_ALIGN_4, make_bad_file(), make_structDNA(), and NULL.

◆ make_bad_file()

static void make_bad_file ( const char *  file,
int  line 
)
static

Definition at line 1425 of file makesdna.c.

References file.

Referenced by main().

◆ make_structDNA()

static int make_structDNA ( const char *  base_directory,
FILE *  file,
FILE *  file_offsets,
FILE *  file_verify 
)
static

◆ match_identifier()

static bool match_identifier ( const char *  str,
const char *  identifier 
)
static

Definition at line 197 of file makesdna.c.

References match_identifier_with_len(), and str.

Referenced by convert_include(), and preprocess_include().

◆ match_identifier_and_advance()

static bool match_identifier_and_advance ( char **  str_ptr,
const char *  identifier 
)
static

Definition at line 203 of file makesdna.c.

References match_identifier_with_len().

Referenced by convert_include().

◆ match_identifier_with_len()

static bool match_identifier_with_len ( const char *  str,
const char *  identifier,
const size_t  identifier_len 
)
static

Definition at line 182 of file makesdna.c.

References str.

Referenced by match_identifier(), and match_identifier_and_advance().

◆ preprocess_include()

static int preprocess_include ( char *  maindata,
const int  maindata_len 
)
static

Remove comments from this buffer. Assumes that the buffer refers to ascii-code text.

Definition at line 509 of file makesdna.c.

References Freestyle::a, match_identifier(), MEM_freeN, and MEM_mallocN.

Referenced by convert_include().

◆ print_struct_sizes()

void print_struct_sizes ( void  )

Report all structures found so far, and print their lengths.

Definition at line 1144 of file makesdna.c.

References Freestyle::a, structs, structs_len, types, and types_size_native.

◆ read_file_data()

static void* read_file_data ( const char *  filepath,
int *  r_len 
)
static

Definition at line 592 of file makesdna.c.

References data, L, MEM_freeN, MEM_mallocN, and NULL.

Referenced by convert_include().

◆ version_elem_static_from_alias()

static const char* version_elem_static_from_alias ( const int  strct,
const char *  elem_alias_full 
)
static

◆ version_struct_alias_from_static()

static const char* version_struct_alias_from_static ( const char *  str)
static

Definition at line 222 of file makesdna.c.

References BLI_ghash_lookup(), g_version_data, NULL, and str.

Referenced by calculate_struct_sizes(), and make_structDNA().

◆ version_struct_static_from_alias()

static const char* version_struct_static_from_alias ( const char *  str)
static

Definition at line 213 of file makesdna.c.

References BLI_ghash_lookup(), g_version_data, NULL, and str.

Referenced by add_type().

Variable Documentation

◆ additional_slen_offset

int additional_slen_offset
static

Definition at line 103 of file makesdna.c.

Referenced by add_name(), and convert_include().

◆ debugSDNA

int debugSDNA = 0
static

Variable to control debug output of makesdna. debugSDNA:

  • 0 = no output, except errors
  • 1 = detail actions
  • 2 = full trace, tell which names and types were found
  • 4 = full trace, plus all gritty details

Definition at line 102 of file makesdna.c.

Referenced by calculate_struct_sizes(), and make_structDNA().

◆ elem_map_alias_from_static

GHash* elem_map_alias_from_static

Definition at line 90 of file makesdna.c.

Referenced by DNA_sdna_alias_data_ensure(), and dna_sdna_alias_from_static_elem_full().

◆ elem_map_static_from_alias

GHash* elem_map_static_from_alias

Definition at line 91 of file makesdna.c.

◆ 

struct { ... } g_version_data

◆ includefiles

const char* includefiles[]
static
Initial value:
= {
"",
}

Definition at line 48 of file makesdna.c.

Referenced by calculate_struct_sizes(), and make_structDNA().

◆ max_array_len

int max_array_len = 50000
static

Definition at line 60 of file makesdna.c.

Referenced by add_name(), add_struct(), add_type(), and make_structDNA().

◆ max_data_size

int max_data_size = 500000
static

Definition at line 60 of file makesdna.c.

Referenced by make_structDNA().

◆ mem_arena

MemArena* mem_arena = NULL
static

◆ names

char** names
static

◆ names_len

int names_len = 0
static

Definition at line 61 of file makesdna.c.

Referenced by add_name(), driver_compile_simple_expr_impl(), and make_structDNA().

◆ struct_map_alias_from_static

GHash* struct_map_alias_from_static

Definition at line 88 of file makesdna.c.

Referenced by DNA_sdna_alias_data_ensure().

◆ struct_map_static_from_alias

GHash* struct_map_static_from_alias

Definition at line 89 of file makesdna.c.

◆ structdata

short * structdata
static

Definition at line 84 of file makesdna.c.

Referenced by add_struct(), and make_structDNA().

◆ structs

short** structs
static

At sp = structs[a] is the first address of a struct definition:

  • sp[0] is type number.
  • sp[1] is the length of the element array (next).
  • sp[2] sp[3] is [(type_index, name_index), ..] (number of pairs is defined by sp[1]),

Definition at line 84 of file makesdna.c.

Referenced by add_struct(), calculate_struct_sizes(), dna_struct_find_nr_ex_impl(), make_structDNA(), and print_struct_sizes().

◆ structs_len

int structs_len = 0
static

◆ types

char** types
static

At address types[a] is string a.

Definition at line 67 of file makesdna.c.

Referenced by add_type(), Device::available_types(), BKE_sculpt_color_layer_create_if_needed(), BLI_filelist_entry_mode_to_string(), blender::bke::CurvesGeometry::calculate_bezier_auto_handles(), blender::bke::calculate_evaluated_offsets(), calculate_struct_sizes(), blender::bke::calculate_type_counts(), check_field_alignment(), blender::nodes::node_geo_input_tangent_cc::construct_curve_tangent_gvarray(), convert_include(), blender::bke::curve_legacy_to_curves(), blender::nodes::node_geo_curve_spline_parameter_cc::curve_length_point_domain(), blender::bke::curve_normal_point_domain(), blender::bke::curve_normals_varray(), curve_render_data_create(), blender::nodes::node_geo_input_tangent_cc::curve_tangent_point_domain(), data_offer_handle_offer(), dna_struct_find_nr_ex_impl(), dt_add_vcol_layers(), elem_exists_impl(), blender::bke::CurvesGeometry::evaluated_normals(), blender::bke::CurvesGeometry::evaluated_positions(), blender::bke::curves::foreach_curve_by_type(), GeometrySet::gather_component_types(), AnimationImporter::get_animation_type(), blender::bke::CurvesGeometry::has_curve_with_type(), blender::bke::curves::indices_for_type(), blender::bke::CurvesGeometry::interpolate_to_evaluated(), lattice_render_data_create(), lineart_gpencil_generate(), make_structDNA(), blender::nodes::node_geo_attribute_capture_cc::node_geo_exec(), blender::nodes::node_geo_instance_on_points_cc::node_geo_exec(), options_parse(), print_struct_sizes(), AnimationImporter::setAnimType(), sort_bmelem_flag(), blender::tests::TEST(), DocumentImporter::translate_anim_recursive(), and version_elem_static_from_alias().

◆ types_align_32

short* types_align_32
static

Contains align requirements for a struct on 32 bit systems.

Definition at line 71 of file makesdna.c.

Referenced by add_type(), calculate_struct_sizes(), and make_structDNA().

◆ types_align_64

short* types_align_64
static

Contains align requirements for a struct on 64 bit systems.

Definition at line 73 of file makesdna.c.

Referenced by add_type(), calculate_struct_sizes(), and make_structDNA().

◆ types_len

int types_len = 0
static

Definition at line 62 of file makesdna.c.

Referenced by add_type(), and make_structDNA().

◆ types_size_32

short* types_size_32
static

Contains sizes as they are calculated on 32 bit systems.

Definition at line 75 of file makesdna.c.

Referenced by add_type(), calculate_struct_sizes(), and make_structDNA().

◆ types_size_64

short* types_size_64
static

Contains sizes as they are calculated on 64 bit systems.

Definition at line 77 of file makesdna.c.

Referenced by add_type(), calculate_struct_sizes(), and make_structDNA().

◆ types_size_native

short* types_size_native
static

At types_size[a] is the size of type a on this systems bitness (32 or 64).

Definition at line 69 of file makesdna.c.

Referenced by add_type(), calculate_struct_sizes(), check_field_alignment(), make_structDNA(), and print_struct_sizes().