You are on page 1of 5

AN ANALYSIS OF THE BLENDER SOURCE CODE

Written by

Anoop Thykkandiyil

Based on, the Blender Source Code

Address: Thykkandiyil House, Thattolikkara, P.O.Chombala, Vatakara


Phone Number: 9446446105
DNA_LISTBASE - BF_DNA - C HEADER FILE

These structs are the foundation for all linked lists in the
library system

Doubly linked lists start from a ListBase and contain


elements beginning with link

LINK
Generic. All structs put into
linked lists begin with this. i.e.
link is going to be the first
element of another struct that is
going to actually implement the
linked list.

LINKDATA
Simple subclass of link which as
also the ability to actually use a
data carrier. Used when it is not
necessary to create a separate
structure for this.

LISTBASE
I suspect this to be the starting
point of a linked list made using
the above link structure.

DNA_GENFILE - BF_DNA - C CODE FILE

Lowest level functions for decoding the parts of a .blend


File, including interpretation of its SDNA block and
conversion of contents of other parts according to the
difference between the SDNA and the SDNA of the current
(running) version of Blender.

Structure of DNA data is added to each blender file and to


each executable, this is to detect in .blend Files new
variables in structs, changed array sizes, etc. Its also used
for converting endian and pointer size(32-64bits)

As an extra, Python uses a call to detect run-time the


contents of a blender struct.

Create a structDNA: only needed when on of the inputs


include(.h) files change.

File syntax is given.

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

For the moment the complete DNA file is included in a .blend


File. For the future we can think of smarter methods, like
only include the used structs. Only needed to keep the file
short though...

DNA_elem_array_size(CONST CHAR* STR)


Parses the “[n]” on the end of an
array name and returns the number
of array elements n

The function scans through the string str and searches for an
opening “[” and when it finds one it points to the string at
address next to “[” to the const char* cp. Next it searches
for the string “]” and when it finds one it converts the
entire string pointed to be cp into an integer and then
multiplies it to variable int mul which had been initialized
to a value “1”. Effectively I feel mul contains the integer
value represented by the string between brackets.

DNA_sdna_free (SDNA *sdna)


I am a function to free the memory
allocated to a SDNA structure the
one pointed to by SDNA* sdna. It
uses secure memory freeing
functions called MEM_freeN which
does bounds checking and NULL
pointer checking etc to prevent
program from Crashing due to a
memory mis management

First I check whether sdna->data_alloc is True or False. If


it is true then it means that the structure holds the pointer
to an individual copy of encoded data in memory and is not
pointing to someone else’s copy. If data_alloc is true then
use MEM_freeN to free memory pointed to by sdna->data.

Free memory pointed to by sdna->names.

Free memory pointed to by sdna->types.

Free memory pointed to by sdna->structs.

If compiled with WITH_DNA_GHASH free sdna->structs_map.

Only after these allocated memory locations pointed to by


pointers within the sdna struct are cleared are we going to
ventrue to clearing the memory allocated to sdna structure
itself.

Free memory pointed allocated for sdna.


3.

Static bool ispointer (const char


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

Function checks if the first character is a “*” or if the


first character is a “(” and the second character is a “*” in
either case it returns a True Value else false.

STATIC INT ELEMENTSIZE (CONST SDNA


*SDNA, SHORT TYPE, SHORT NAME)
Returns the size of struct fields
of the specified type and name

PARAMETERS

Const SDNA *sdna: pointer to the SDNA datastructure

SHORT TYPE: Index into sdna->types/typelens

SHORT NAME: Index into sdna->names

These are needed to extract possible pointer/array


information

DNA_sdna_types - BF_DNA - HEADER FILE

SDNA

Primarily contains the SDNA datastructure defined as a struct

It contains the

const char* data (which contains the encoded data)

Int datalen; (lenght of data)

Bool data_alloc; (if true it says data contains full copy of


encoded data and if false it says its borrowed don’t know
what data borrowing means)

Int nr_names; (total number of struct members)

Const char **names; (struct of member names)

Int pointerlen; (size of pointer in bytes)

Int nr_types; (number of basic types + struct types)

Const char **types; (type names)

Short *typelens; (type lengths)


4.

Int nr_structs; (number of struct types)

Short **structs; (sp = structs[a] is the address of a struct


defenition sp[0] is struct type number, sp[1] amount of
members, (sp[2], sp[3]), (sp[4], sp[5]), are the member type
and name numbers respectively

Struct GHash *structs_map; (ghash for faster lookups,


requires WITH_DNA_GHASH to be used for now)

BHEAD

Is a struct which contains a code variable and len variable


both of type int.

The main thing is the old* which is of type void in this but
in BHead4 and BHead8 are of type INT and int64_t types.

BHEAD4

Same as above but the old pointer is of type INT

BHEAD8

Same as above but the old pinter is of tyep int64_t

You might also like