Blender V5.0
readfile.cc File Reference
#include "fmt/core.h"
#include <cerrno>
#include <cstdarg>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fcntl.h>
#include <queue>
#include <unistd.h>
#include <fmt/format.h>
#include "CLG_log.h"
#include "DNA_asset_types.h"
#include "DNA_collection_types.h"
#include "DNA_constraint_types.h"
#include "DNA_fileglobal_types.h"
#include "DNA_genfile.h"
#include "DNA_key_types.h"
#include "DNA_layer_types.h"
#include "DNA_node_types.h"
#include "DNA_packedFile_types.h"
#include "DNA_screen_types.h"
#include "DNA_sdna_types.h"
#include "DNA_userdef_types.h"
#include "DNA_windowmanager_types.h"
#include "MEM_alloc_string_storage.hh"
#include "MEM_guardedalloc.h"
#include "BLI_endian_defines.h"
#include "BLI_fileops.h"
#include "BLI_ghash.h"
#include "BLI_map.hh"
#include "BLI_memarena.h"
#include "BLI_set.hh"
#include "BLI_string.h"
#include "BLI_string_ref.hh"
#include "BLI_string_utf8.h"
#include "BLI_string_utils.hh"
#include "BLI_threads.h"
#include "BLI_time.h"
#include "BLI_utildefines.h"
#include "BLT_translation.hh"
#include "BKE_anim_data.hh"
#include "BKE_animsys.h"
#include "BKE_asset.hh"
#include "BKE_blender_version.h"
#include "BKE_collection.hh"
#include "BKE_global.hh"
#include "BKE_idprop.hh"
#include "BKE_idtype.hh"
#include "BKE_layer.hh"
#include "BKE_lib_id.hh"
#include "BKE_lib_override.hh"
#include "BKE_lib_query.hh"
#include "BKE_lib_remap.hh"
#include "BKE_library.hh"
#include "BKE_main.hh"
#include "BKE_main_idmap.hh"
#include "BKE_main_invariants.hh"
#include "BKE_main_namemap.hh"
#include "BKE_material.hh"
#include "BKE_mesh.hh"
#include "BKE_modifier.hh"
#include "BKE_nla.hh"
#include "BKE_node.hh"
#include "BKE_node_tree_update.hh"
#include "BKE_object.hh"
#include "BKE_packedFile.hh"
#include "BKE_preferences.h"
#include "BKE_report.hh"
#include "BKE_scene.hh"
#include "BKE_screen.hh"
#include "BKE_undo_system.hh"
#include "BKE_workspace.hh"
#include "DRW_engine.hh"
#include "DEG_depsgraph.hh"
#include "BLO_blend_validate.hh"
#include "BLO_read_write.hh"
#include "BLO_readfile.hh"
#include "BLO_undofile.hh"
#include "SEQ_iterator.hh"
#include "SEQ_modifier.hh"
#include "SEQ_sequencer.hh"
#include "SEQ_utils.hh"
#include "IMB_colormanagement.hh"
#include "readfile.hh"
#include "versioning_common.hh"

Go to the source code of this file.

Classes

struct  BHeadN
struct  NewAddress
struct  OldNewMap
struct  BlendDataReader
struct  BlendLibReader
struct  BLOCacheStorage
struct  BLOCacheStorageValue
struct  BHeadSort
struct  BlendExpander

Macros

#define DNA_DEPRECATED_ALLOW
#define U   (*((const UserDef *)&U))
#define USE_BHEAD_READ_ON_DEMAND
#define BHEADN_FROM_BHEAD(bh)
#define BHEAD_USE_READ_ON_DEMAND(bhead)

Functions

Library Reading
static void read_libraries (FileData *basefd)
static int has_linked_ids_to_read (Main *mainvar)
static void read_library_linked_id (FileData *basefd, FileData *fd, Main *mainvar, ID *id, ID **r_id)
static void read_library_linked_ids (FileData *basefd, FileData *fd, Main *mainvar)
static void read_library_clear_weak_links (FileData *basefd, Main *mainvar)
static FileDataread_library_file_data (FileData *basefd, Main *bmain, Main *lib_bmain)
static void * blo_verify_data_address (FileData *fd, void *new_address, const void *, const size_t expected_size)
void * BLO_read_get_new_data_address (BlendDataReader *reader, const void *old_address)
void * BLO_read_get_new_data_address_no_us (BlendDataReader *reader, const void *old_address, const size_t expected_size)
void * BLO_read_struct_array_with_size (BlendDataReader *reader, const void *old_address, const size_t expected_size)
void * BLO_read_struct_by_name_array (BlendDataReader *reader, const char *struct_name, const int64_t items_num, const void *old_address)
IDBLO_read_get_new_id_address (BlendLibReader *reader, ID *self_id, const bool is_linked_only, ID *id)
IDBLO_read_get_new_id_address_from_session_uid (BlendLibReader *reader, const uint session_uid)
int BLO_read_fileversion_get (BlendDataReader *reader)
void BLO_read_struct_list_with_size (BlendDataReader *reader, const size_t expected_elem_size, ListBase *list)
void BLO_read_char_array (BlendDataReader *reader, const int64_t array_size, char **ptr_p)
void BLO_read_uint8_array (BlendDataReader *reader, const int64_t array_size, uint8_t **ptr_p)
void BLO_read_int8_array (BlendDataReader *reader, const int64_t array_size, int8_t **ptr_p)
void BLO_read_int16_array (BlendDataReader *reader, const int64_t array_size, int16_t **ptr_p)
void BLO_read_int32_array (BlendDataReader *reader, const int64_t array_size, int32_t **ptr_p)
void BLO_read_uint32_array (BlendDataReader *reader, const int64_t array_size, uint32_t **ptr_p)
void BLO_read_float_array (BlendDataReader *reader, const int64_t array_size, float **ptr_p)
void BLO_read_float3_array (BlendDataReader *reader, const int64_t array_size, float **ptr_p)
void BLO_read_double_array (BlendDataReader *reader, const int64_t array_size, double **ptr_p)
void BLO_read_string (BlendDataReader *reader, char **ptr_p)
void BLO_read_string (BlendDataReader *reader, char *const *ptr_p)
static void convert_pointer_array_64_to_32 (BlendDataReader *reader, const int64_t array_size, const uint64_t *src, uint32_t *dst)
static void convert_pointer_array_32_to_64 (BlendDataReader *, const int64_t array_size, const uint32_t *src, uint64_t *dst)
void BLO_read_pointer_array (BlendDataReader *reader, const int64_t array_size, void **ptr_p)
blender::ImplicitSharingInfoAndData blo_read_shared_impl (BlendDataReader *reader, const void **ptr_p, const blender::FunctionRef< const blender::ImplicitSharingInfo *()> read_fn)
bool BLO_read_data_is_undo (BlendDataReader *reader)
void BLO_read_data_globmap_add (BlendDataReader *reader, void *oldaddr, void *newaddr)
void BLO_read_glob_list (BlendDataReader *reader, ListBase *list)
BlendFileReadReportBLO_read_data_reports (BlendDataReader *reader)
bool BLO_read_lib_is_undo (BlendLibReader *reader)
MainBLO_read_lib_get_main (BlendLibReader *reader)
BlendFileReadReportBLO_read_lib_reports (BlendLibReader *reader)
DNA Struct Loading
static void * read_struct (FileData *fd, BHead *bh, const char *blockname, const int id_type_index)
static const char * get_alloc_name (FileData *fd, BHead *bh, const char *blockname, const int id_type_index=INDEX_ID_NULL)
static IDread_id_struct (FileData *fd, BHead *bh, const char *blockname, const int id_type_index)
static const void * peek_struct_undo (FileData *fd, BHead *bhead)
static void link_glob_list (FileData *fd, ListBase *lb)
Library Linking

Also used for append.

static BHeadfind_bhead_from_code_name (FileData *fd, const short idcode, const char *name)
static int verg_bheadsort (const void *v1, const void *v2)
static void sort_bhead_old_map (FileData *fd)
static BHeadfind_previous_lib (FileData *fd, BHead *bhead)
static BHeadfind_bhead (FileData *fd, void *old)
static BHeadfind_bhead_from_idname (FileData *fd, const char *idname)
static IDlibrary_id_is_yet_read_deep_hash (FileData *fd, BHead *bhead)
static IDlibrary_id_is_yet_read_main (Main *mainvar, const char *idname)
static void read_libraries_report_invalid_id_names (FileData *fd, ReportList *reports, const bool has_forward_compatibility_issues, const char *filepath)
Blend Loader Reporting Wrapper
void BLO_reportf_wrap (BlendFileReadReport *reports, const eReportType type, const char *format,...)
static const char * library_parent_filepath (Library *lib)
OldNewMap API
static OldNewMapoldnewmap_new ()
static bool oldnewmap_insert (OldNewMap *onm, const void *oldaddr, void *newaddr, const int nr)
static void oldnewmap_lib_insert (FileData *fd, const void *oldaddr, ID *newaddr, const int id_code)
void blo_do_versions_oldnewmap_insert (OldNewMap *onm, const void *oldaddr, void *newaddr, const int nr)
static void * oldnewmap_lookup_and_inc (OldNewMap *onm, const void *addr, const bool increase_users)
static void * oldnewmap_liblookup (OldNewMap *onm, const void *addr, const bool is_linked_only)
static void oldnewmap_clear (OldNewMap *onm)
static void oldnewmap_free (OldNewMap *onm)
Helper Functions
static void add_main_to_main (Main *mainvar, Main *from)
void blo_join_main (Main *bmain)
static void split_libdata (ListBase *lb_src, blender::Vector< Main * > &lib_main_array, const bool do_split_packed_ids)
void blo_split_main (Main *bmain, const bool do_split_packed_ids)
static void read_file_version_and_colorspace (FileData *fd, Main *main)
static bool blo_bhead_is_id (const BHead *bhead)
static bool blo_bhead_is_id_valid_type (const BHead *bhead)
static void read_file_bhead_idname_map_create (FileData *fd)
void blo_readfile_invalidate (FileData *fd, Main *bmain, const char *message)
File Parsing
static BHeadNget_bhead (FileData *fd)
BHeadblo_bhead_first (FileData *fd)
BHeadblo_bhead_prev (FileData *, BHead *thisblock)
BHeadblo_bhead_next (FileData *fd, BHead *thisblock)
static bool blo_bhead_read_data (FileData *fd, BHead *thisblock, void *buf)
static BHeadblo_bhead_read_full (FileData *fd, BHead *thisblock)
const char * blo_bhead_id_name (FileData *fd, const BHead *bhead)
short blo_bhead_id_flag (const FileData *fd, const BHead *bhead)
AssetMetaDatablo_bhead_id_asset_data_address (const FileData *fd, const BHead *bhead)
static const IDHashblo_bhead_id_deep_hash (const FileData *fd, const BHead *bhead)
static void read_blender_header (FileData *fd)
static bool read_file_dna (FileData *fd, const char **r_error_message)
static int * read_file_thumbnail (FileData *fd)
static void long_id_names_ensure_unique_id_names (Main *bmain)
static void long_id_names_process_action_slots_identifiers (Main *bmain)
File Data API
static FileDatafiledata_new (BlendFileReadReport *reports)
static bool is_minversion_older_than_blender (FileData *fd, ReportList *reports)
static FileDatablo_decode_and_check (FileData *fd, ReportList *reports)
static FileDatablo_filedata_from_file_descriptor (const char *filepath, BlendFileReadReport *reports, const int filedes)
static FileDatablo_filedata_from_file_open (const char *filepath, BlendFileReadReport *reports)
FileDatablo_filedata_from_file (const char *filepath, BlendFileReadReport *reports)
static FileDatablo_filedata_from_file_minimal (const char *filepath)
FileDatablo_filedata_from_memory (const void *mem, const int memsize, BlendFileReadReport *reports)
FileDatablo_filedata_from_memfile (MemFile *memfile, const BlendFileReadParams *params, BlendFileReadReport *reports)
void blo_filedata_free (FileData *fd)
Read Thumbnail from Blend File
BlendThumbnailBLO_thumbnail_from_file (const char *filepath)
short BLO_version_from_file (const char *filepath)
Old/New Pointer Map
static void * newdataadr (FileData *fd, const void *adr)
static void * newdataadr_no_us (FileData *fd, const void *adr)
void * blo_read_get_new_globaldata_address (FileData *fd, const void *adr)
static void * newlibadr (FileData *fd, ID *, const bool is_linked_only, const void *adr)
void * blo_do_versions_newlibadr (FileData *fd, ID *self_id, const bool is_linked_only, const void *adr)
static void change_link_placeholder_to_real_ID_pointer_fd (FileData *fd, const void *old, void *newp)
static void change_ID_pointer_to_real_ID_pointer_fd (FileData *fd, const void *old, void *newp)
static FileDatachange_ID_link_filedata_get (Main *bmain, FileData *basefd)
static void change_link_placeholder_to_real_ID_pointer (FileData *basefd, void *old, void *newp)
static void change_ID_pointer_to_real_ID_pointer (FileData *basefd, void *old, void *newp)
void blo_make_old_idmap_from_main (FileData *fd, Main *bmain)
static void blo_cache_storage_entry_register (ID *id, const IDCacheKey *key, void **cache_p, uint, void *cache_storage_v)
static void blo_cache_storage_entry_restore_in_new (ID *id, const IDCacheKey *key, void **cache_p, const uint flags, void *cache_storage_v)
static void blo_cache_storage_entry_clear_in_old (ID *, const IDCacheKey *key, void **cache_p, const uint, void *cache_storage_v)
void blo_cache_storage_init (FileData *fd, Main *bmain)
void blo_cache_storage_old_bmain_clear (FileData *fd, Main *bmain_old)
void blo_cache_storage_end (FileData *fd)
Read ID
static void after_liblink_id_process (BlendLibReader *reader, ID *id)
static void after_liblink_id_embedded_id_process (BlendLibReader *reader, ID *id)
static void direct_link_id_override_property (BlendDataReader *reader, IDOverrideLibraryProperty *op)
static void direct_link_id_common (BlendDataReader *reader, Library *current_library, ID *id, ID *id_old, int id_tag, ID_Readfile_Data::Tags id_read_tags)
static void direct_link_id_embedded_id (BlendDataReader *reader, Library *current_library, ID *id, ID *id_old)
static int direct_link_id_restore_recalc_exceptions (const ID *id_current)
static int direct_link_id_restore_recalc (const FileData *fd, const ID *id_target, const ID *id_current, const bool is_identical)
static void readfile_id_runtime_data_ensure (ID &id)
ID_Readfile_Data::Tags BLO_readfile_id_runtime_tags (ID &id)
ID_Readfile_Data::TagsBLO_readfile_id_runtime_tags_for_write (ID &id)
void BLO_readfile_id_runtime_data_free (ID &id)
void BLO_readfile_id_runtime_data_free_all (Main &bmain)
Read ID: Shape Keys
void blo_do_versions_key_uidgen (Key *key)
Read ID: Scene
static void lib_link_scenes_check_set (Main *bmain)
Read ID: Library
static void library_filedata_release (Library *lib)
static void direct_link_library (FileData *fd, Library *lib, Main *main)
static void fix_relpaths_library (const char *basepath, Main *main)
Read Library Data Block
static IDcreate_placeholder (Main *mainvar, const short idcode, const char *idname, const int tag, const bool was_liboverride)
static void placeholders_ensure_valid (Main *bmain)
static bool direct_link_id (FileData *fd, Main *main, const int tag, const ID_Readfile_Data::Tags id_read_tags, ID *id, ID *id_old)
static BHeadread_data_into_datamap (FileData *fd, BHead *bhead, const char *allocname, const int id_type_index)
static Mainblo_add_main_for_library (FileData *fd, Library *lib, Library *reference_lib, const char *lib_filepath, char(&filepath_abs)[FILE_MAX], const bool is_packed_library)
static bool read_libblock_is_identical (FileData *fd, BHead *bhead)
static void read_undo_reuse_noundo_local_ids (FileData *fd)
static void read_undo_move_libmain_data (FileData *fd, Main *libmain, BHead *bhead)
static bool read_libblock_undo_restore_library (FileData *fd, const ID *id, ID *id_old, BHead *bhead)
static IDlibrary_id_is_yet_read (FileData *fd, Main *mainvar, BHead *bhead)
static bool read_libblock_undo_restore_linked (FileData *fd, Main *libmain, const ID *id, ID **r_id_old, BHead *bhead)
static void read_libblock_undo_restore_identical (FileData *fd, Main *main, const ID *, ID *id_old, BHead *bhead, const int id_tag)
static void read_libblock_undo_restore_at_old_address (FileData *fd, Main *main, ID *id, ID *id_old)
static bool read_libblock_undo_restore (FileData *fd, Main *main, BHead *bhead, const int id_tag, ID **r_id_old)
static BHeadread_libblock (FileData *fd, Main *main, BHead *bhead, int id_tag, ID_Readfile_Data::Tags id_read_tags, const bool placeholder_set_indirect_extern, ID **r_id)
Read Asset Data
BHeadblo_read_asset_data_block (FileData *fd, BHead *bhead, AssetMetaData **r_asset_data)
Read Global Data
static BHeadread_global (BlendFileData *bfd, FileData *fd, BHead *bhead)
static void link_global (FileData *fd, BlendFileData *bfd)
Versioning
static void do_versions_userdef (FileData *, BlendFileData *bfd)
static void do_versions (FileData *fd, Library *lib, Main *main)
static void do_versions_after_linking (FileData *fd, Main *main)
Read Library Data Block (all)
static int lib_link_cb (LibraryIDLinkCallbackData *cb_data)
static void lib_link_all (FileData *fd, Main *bmain)
static void after_liblink_merged_bmain_process (Main *bmain, BlendFileReadReport *reports)
Read User Preferences
static void direct_link_keymapitem (BlendDataReader *reader, wmKeyMapItem *kmi)
static BHeadread_userdef (BlendFileData *bfd, FileData *fd, BHead *bhead)
Read File (Internal)
static int read_undo_remap_noundo_data_cb (LibraryIDLinkCallbackData *cb_data)
static void read_undo_remap_noundo_data (FileData *fd)
static void blo_read_file_checks (Main *bmain)
BlendFileDatablo_read_file_internal (FileData *fd, const char *filepath)
Library Linking (helper functions)
static IDlink_named_part (Main *mainl, FileData *fd, const short idcode, const char *name, const int flag)
IDBLO_library_link_named_part (Main *mainl, BlendHandle **bh, const short idcode, const char *name, const LibraryLink_Params *params)
static Mainlibrary_link_begin (Main *mainvar, FileData *fd, const char *filepath, const int id_tag_extra)
void BLO_library_link_params_init (LibraryLink_Params *params, Main *bmain, const int flag, const int id_tag_extra)
void BLO_library_link_params_init_with_context (LibraryLink_Params *params, Main *bmain, const int flag, const int id_tag_extra, Scene *scene, ViewLayer *view_layer, const View3D *v3d)
MainBLO_library_link_begin (BlendHandle **bh, const char *filepath, const LibraryLink_Params *params)
static void split_main_newid (Main *mainptr, Main *main_newid)
static void library_link_end (Main *mainl, FileData **fd, const int flag, ReportList *reports)
void BLO_library_link_end (Main *mainl, BlendHandle **bh, const LibraryLink_Params *params, ReportList *reports)
void * BLO_library_read_struct (FileData *fd, BHead *bh, const char *blockname)

Variables

static CLG_LogRef LOG = {"blend.readfile"}
static CLG_LogRef LOG_UNDO = {"undo"}

Library Linking (expand pointers)

using BLOExpandDoitCallback
static Mainblo_find_main_for_library_and_idname (FileData *fd, const char *lib_filepath, const char *relabase, const BHead *id_bhead, const char *id_name, const bool is_packed_id)
static void read_id_in_lib (FileData *fd, std::queue< ID * > &ids_to_expand, Main *libmain, Library *parent_lib, BHead *bhead, ID *existing_id, ID_Readfile_Data::Tags id_read_tags)
static void expand_doit_library (void *fdhandle, std::queue< ID * > &ids_to_expand, Main *mainvar, void *old)
static int expand_cb (LibraryIDLinkCallbackData *cb_data)
static void expand_main (void *fdhandle, Main *mainvar, BLOExpandDoitCallback callback)

Macro Definition Documentation

◆ BHEAD_USE_READ_ON_DEMAND

#define BHEAD_USE_READ_ON_DEMAND ( bhead)
Value:
((bhead)->code == BLO_CODE_DATA)
@ BLO_CODE_DATA

We could change this in the future, for now it's simplest if only data is delayed because ID names are used in lookup tables.

Definition at line 212 of file readfile.cc.

Referenced by blo_filedata_free(), and get_bhead().

◆ BHEADN_FROM_BHEAD

#define BHEADN_FROM_BHEAD ( bh)
Value:
((BHeadN *)POINTER_OFFSET(bh, -int(offsetof(BHeadN, bhead))))
#define POINTER_OFFSET(v, ofs)
#define offsetof(t, d)

Definition at line 206 of file readfile.cc.

Referenced by blo_bhead_next(), blo_bhead_prev(), blo_bhead_read_data(), blo_bhead_read_full(), read_libblock_is_identical(), and read_struct().

◆ DNA_DEPRECATED_ALLOW

#define DNA_DEPRECATED_ALLOW

Definition at line 33 of file readfile.cc.

◆ U

#define U   (*((const UserDef *)&U))

Definition at line 121 of file readfile.cc.

◆ USE_BHEAD_READ_ON_DEMAND

#define USE_BHEAD_READ_ON_DEMAND

READ

  • Existing Library (Main) push or free
  • allocate new Main
  • load file
  • read SDNA
  • for each LibBlock
    • read LibBlock
    • if a Library
      • make a new Main
      • attach ID's to it
    • else
      • read associated 'direct data'
      • link direct data (internal and to LibBlock)
  • read FileGlobal
  • read #USER data, only when indicated (file is ~/.config/blender/X.X/config/userpref.blend)
  • free file
  • per Library (per Main)
    • read file
    • read SDNA
    • find LibBlocks and attach ID's to Main
      • if external LibBlock
        • search all Main's
          • or it's already read,
          • or not read yet
          • or make new Main
    • per LibBlock
      • read recursive
      • read associated direct data
      • link direct data (internal and to LibBlock)
    • free file
  • per Library with unread LibBlocks
    • read file
    • read SDNA
    • per LibBlock
      • read recursive
      • read associated direct data
      • link direct data (internal and to LibBlock)
    • free file
  • join all Main's
  • link all LibBlocks and indirect pointers to libblocks
  • initialize FileGlobal and copy pointers to Global
Note
Still a weak point is the new-address function, that doesn't solve reading from multiple files at the same time. (added remark: oh, i thought that was solved? will look at that... (ton). Delay reading blocks we might not use (especially applies to library linking). which keeps large arrays in memory from data-blocks we may not even use.
This is disabled when using compression, while ZLIB supports seek it's unusably slow, see: #61880.

Definition at line 180 of file readfile.cc.

Typedef Documentation

◆ BLOExpandDoitCallback

Initial value:
void (*)(void *fdhandle,
std::queue<ID *> &ids_to_expand,
Main *mainvar,
void *idv)

Definition at line 4593 of file readfile.cc.

Function Documentation

◆ add_main_to_main()

void add_main_to_main ( Main * mainvar,
Main * from )
static

◆ after_liblink_id_embedded_id_process()

void after_liblink_id_embedded_id_process ( BlendLibReader * reader,
ID * id )
static

◆ after_liblink_id_process()

◆ after_liblink_merged_bmain_process()

void after_liblink_merged_bmain_process ( Main * bmain,
BlendFileReadReport * reports )
static

Checks to perform after lib_link_all. Those operations cannot perform properly in a split bmain case, since some data from other bmain's (aka libraries) may not have been processed yet.

Definition at line 3771 of file readfile.cc.

References BKE_main_collections_parent_relations_rebuild(), BKE_main_namemap_validate_and_fix(), BKE_report(), BLI_assert, BLO_main_validate_embedded_flag(), BLO_main_validate_embedded_liboverrides(), BLO_main_validate_shapekeys(), lib_link_scenes_check_set(), BlendFileReadReport::reports, RPT_ERROR, and Main::split_mains.

Referenced by blo_read_file_internal(), and library_link_end().

◆ blo_add_main_for_library()

◆ blo_bhead_first()

◆ blo_bhead_id_asset_data_address()

AssetMetaData * blo_bhead_id_asset_data_address ( const FileData * fd,
const BHead * bhead )

Warning! Caller's responsibility to ensure given bhead is an ID one!

Definition at line 808 of file readfile.cc.

References BLI_assert, blo_bhead_is_id_valid_type(), FileData::id_asset_data_offset, and POINTER_OFFSET.

Referenced by blendhandle_load_id_data_and_validate().

◆ blo_bhead_id_deep_hash()

◆ blo_bhead_id_flag()

short blo_bhead_id_flag ( const FileData * fd,
const BHead * bhead )

Warning! It's the caller's responsibility to ensure that the given bhead is an ID one!

Returns the ID flag value (or 0 if the blendfile is too old and the offset of the ID::flag member could not be computed).

Definition at line 798 of file readfile.cc.

References BLI_assert, blo_bhead_is_id(), FileData::id_flag_offset, and POINTER_OFFSET.

Referenced by blendhandle_load_id_data_and_validate(), blo_bhead_id_deep_hash(), blo_read_file_internal(), expand_doit_library(), and read_libblock_undo_restore().

◆ blo_bhead_id_name()

const char * blo_bhead_id_name ( FileData * fd,
const BHead * bhead )

Warning! Caller's responsibility to ensure given bhead is an ID one!

Will return nullptr if the name is not valid (e.g. because it has no null-char terminator, if it was saved in a version of Blender with higher MAX_ID_NAME value).

Definition at line 784 of file readfile.cc.

References BLI_assert, blo_bhead_is_id(), FD_FLAGS_HAS_INVALID_ID_NAMES, FileData::flags, FileData::id_name_offset, MAX_ID_NAME, and POINTER_OFFSET.

Referenced by blendhandle_load_id_data_and_validate(), BLO_blendhandle_get_preview_for_id(), expand_doit_library(), library_id_is_yet_read(), and read_file_bhead_idname_map_create().

◆ blo_bhead_is_id()

bool blo_bhead_is_id ( const BHead * bhead)
static

Definition at line 512 of file readfile.cc.

References BHead::code.

Referenced by blo_bhead_id_flag(), blo_bhead_id_name(), and blo_bhead_is_id_valid_type().

◆ blo_bhead_is_id_valid_type()

◆ blo_bhead_next()

◆ blo_bhead_prev()

BHead * blo_bhead_prev ( FileData * ,
BHead * thisblock )

Definition at line 705 of file readfile.cc.

References BHEADN_FROM_BHEAD, and BHeadN::prev.

Referenced by BLO_blendhandle_get_datablock_info(), and find_previous_lib().

◆ blo_bhead_read_data()

◆ blo_bhead_read_full()

BHead * blo_bhead_read_full ( FileData * fd,
BHead * thisblock )
static

◆ blo_cache_storage_end()

void blo_cache_storage_end ( FileData * fd)

◆ blo_cache_storage_entry_clear_in_old()

void blo_cache_storage_entry_clear_in_old ( ID * ,
const IDCacheKey * key,
void ** cache_p,
const uint ,
void * cache_storage_v )
static

Clear as needed a cache data entry from old ID, when reading some undo memfile.

Definition at line 1667 of file readfile.cc.

References BLI_assert, BLI_ghash_lookup(), BLOCacheStorage::cache_map, BLOCacheStorageValue::cache_v, and BLOCacheStorageValue::new_usage_count.

Referenced by blo_cache_storage_old_bmain_clear().

◆ blo_cache_storage_entry_register()

void blo_cache_storage_entry_register ( ID * id,
const IDCacheKey * key,
void ** cache_p,
uint ,
void * cache_storage_v )
static

◆ blo_cache_storage_entry_restore_in_new()

void blo_cache_storage_entry_restore_in_new ( ID * id,
const IDCacheKey * key,
void ** cache_p,
const uint flags,
void * cache_storage_v )
static

Restore a cache data entry from old ID into new one, when reading some undo memfile.

Definition at line 1632 of file readfile.cc.

References BLI_ghash_lookup(), BLOCacheStorage::cache_map, BLOCacheStorageValue::cache_v, ID_RECALC_SOURCE, IDTYPE_CACHE_CB_FLAGS_PERSISTENT, BLOCacheStorageValue::new_usage_count, and ID::recalc.

Referenced by direct_link_id().

◆ blo_cache_storage_init()

◆ blo_cache_storage_old_bmain_clear()

◆ blo_decode_and_check()

◆ blo_do_versions_key_uidgen()

void blo_do_versions_key_uidgen ( Key * key)

Definition at line 2394 of file readfile.cc.

References Key::block, LISTBASE_FOREACH, and Key::uidgen.

Referenced by blo_do_versions_260().

◆ blo_do_versions_newlibadr()

void * blo_do_versions_newlibadr ( FileData * fd,
ID * self_id,
const bool is_linked_only,
const void * adr )

Only library data.

Definition at line 1523 of file readfile.cc.

References newlibadr().

Referenced by blo_do_versions_250(), blo_do_versions_260(), blo_do_versions_pre250(), and ntree_version_245().

◆ blo_do_versions_oldnewmap_insert()

void blo_do_versions_oldnewmap_insert ( OldNewMap * onm,
const void * oldaddr,
void * newaddr,
const int nr )

Definition at line 286 of file readfile.cc.

References oldnewmap_insert().

Referenced by blo_do_versions_pre250().

◆ blo_filedata_free()

◆ blo_filedata_from_file()

FileData * blo_filedata_from_file ( const char * filepath,
BlendFileReadReport * reports )

On each new library added, it now checks for the current FileData and expands relativeness

cannot be called with relative paths anymore!

Definition at line 1320 of file readfile.cc.

References blo_decode_and_check(), blo_filedata_from_file_open(), FileData::relabase, BlendFileReadReport::reports, and STRNCPY().

Referenced by BLO_blendhandle_from_file(), BLO_read_from_file(), and read_library_file_data().

◆ blo_filedata_from_file_descriptor()

◆ blo_filedata_from_file_minimal()

FileData * blo_filedata_from_file_minimal ( const char * filepath)
static

Same as blo_filedata_from_file(), but does not reads DNA data, only header. Use it for light access (e.g. thumbnail reading).

Definition at line 1336 of file readfile.cc.

References blo_filedata_free(), blo_filedata_from_file_open(), FD_FLAGS_FILE_OK, FileData::flags, and read_blender_header().

Referenced by BLO_thumbnail_from_file(), and BLO_version_from_file().

◆ blo_filedata_from_file_open()

FileData * blo_filedata_from_file_open ( const char * filepath,
BlendFileReadReport * reports )
static

◆ blo_filedata_from_memfile()

◆ blo_filedata_from_memory()

◆ blo_find_main_for_library_and_idname()

◆ blo_join_main()

void blo_join_main ( Main * bmain)

◆ BLO_library_link_begin()

Main * BLO_library_link_begin ( BlendHandle ** bh,
const char * filepath,
const LibraryLink_Params * params )

Initialize the #BlendHandle for linking library data.

Parameters
bhA blender file handle as returned by BLO_blendhandle_from_file or BLO_blendhandle_from_memory.
filepathUsed for relative linking, copied to the lib->filepath.
paramsSettings for linking that don't change from beginning to end of linking.
Returns
the library Main, to be passed to BLO_library_link_named_part as mainl.

Definition at line 5133 of file readfile.cc.

References library_link_begin(), and params.

Referenced by BKE_blendfile_link(), and BLO_library_temp_load_id().

◆ BLO_library_link_end()

void BLO_library_link_end ( Main * mainl,
BlendHandle ** bh,
const LibraryLink_Params * params,
ReportList * reports )

Finalize linking from a given .blend file (library). Optionally instance the indirect object/collection in the scene when the flags are set.

Note
Do not use bh after calling this function, it may frees it.
Parameters
mainlThe main database to link from (not the active one).
bhThe blender file handle (WARNING! may be freed by this function!).
paramsSettings for linking that don't change from beginning to end of linking.

Definition at line 5293 of file readfile.cc.

References Main::is_read_invalid, lib, library_filedata_release(), library_link_end(), LISTBASE_FOREACH, and params.

Referenced by BKE_blendfile_link(), and BLO_library_temp_load_id().

◆ BLO_library_link_named_part()

ID * BLO_library_link_named_part ( Main * mainl,
BlendHandle ** bh,
short idcode,
const char * name,
const LibraryLink_Params * params )

Link a named data-block from an external blend file.

Parameters
mainlThe main database to link from (not the active one).
bhThe blender file handle.
idcodeThe kind of data-block to link.
nameThe name of the data-block (without the 2 char ID prefix).
Returns
the linked ID when found.

Definition at line 5037 of file readfile.cc.

References Main::is_read_invalid, link_named_part(), name, and params.

Referenced by BKE_blendfile_link(), and BLO_library_temp_load_id().

◆ BLO_library_link_params_init()

void BLO_library_link_params_init ( LibraryLink_Params * params,
Main * bmain,
const int flag,
const int id_tag_extra )

◆ BLO_library_link_params_init_with_context()

void BLO_library_link_params_init_with_context ( LibraryLink_Params * params,
Main * bmain,
const int flag,
const int id_tag_extra,
Scene * scene,
ViewLayer * view_layer,
const View3D * v3d )

◆ BLO_library_read_struct()

void * BLO_library_read_struct ( FileData * fd,
BHead * bh,
const char * blockname )

◆ blo_make_old_idmap_from_main()

void blo_make_old_idmap_from_main ( FileData * fd,
Main * bmain )

◆ blo_read_asset_data_block()

◆ BLO_read_char_array()

void BLO_read_char_array ( BlendDataReader * reader,
const int64_t array_size,
char ** ptr_p )

◆ BLO_read_data_globmap_add()

void BLO_read_data_globmap_add ( BlendDataReader * reader,
void * oldaddr,
void * newaddr )

Definition at line 5968 of file readfile.cc.

References BlendDataReader::fd, FileData::globmap, and oldnewmap_insert().

Referenced by window_manager_blend_read_data().

◆ BLO_read_data_is_undo()

◆ BLO_read_data_reports()

BlendFileReadReport * BLO_read_data_reports ( BlendDataReader * reader)

◆ BLO_read_double_array()

void BLO_read_double_array ( BlendDataReader * reader,
const int64_t array_size,
double ** ptr_p )

◆ blo_read_file_checks()

void blo_read_file_checks ( Main * bmain)
static

Contains sanity/debug checks to be performed at the very end of the reading process (i.e. after data, liblink, linked data, etc. has been done).

Definition at line 3962 of file readfile.cc.

References BLI_assert, Main::is_read_invalid, LISTBASE_FOREACH, Main::split_mains, UNUSED_VARS_NDEBUG, and Main::wm.

Referenced by blo_read_file_internal(), and library_link_end().

◆ blo_read_file_internal()

BlendFileData * blo_read_file_internal ( FileData * fd,
const char * filepath )

Definition at line 3978 of file readfile.cc.

References after_liblink_merged_bmain_process(), blender::Vector< T, InlineBufferCapacity, Allocator >::as_span(), ATTR_FALLTHROUGH, BKE_collections_after_lib_link(), BKE_id_delete(), BKE_layer_collection_resync_allow(), BKE_layer_collection_resync_forbid(), BKE_lib_override_library_main_update(), BKE_lib_override_library_main_validate(), BKE_main_collections_parent_relations_rebuild(), BKE_main_ensure_invariants(), BKE_main_id_refcount_recompute(), BKE_main_id_tag_all(), BKE_main_idmap_create(), BKE_main_lists_get(), BKE_main_new(), BKE_reportf(), BKE_view_layer_find(), Main::blen_thumb, BLEN_THUMB_MEMSIZE, BLEN_THUMB_MEMSIZE_FILE, BLEN_THUMB_MEMSIZE_IS_VALID, BLENFILETYPE_BLEND, BLI_assert, BLI_assert_msg, BLI_time_now_seconds(), blo_bhead_first(), blo_bhead_id_flag(), blo_bhead_is_id_valid_type(), blo_bhead_next(), BLO_CODE_DATA, BLO_CODE_DNA1, BLO_CODE_ENDB, BLO_CODE_GLOB, BLO_CODE_REND, BLO_CODE_TEST, BLO_CODE_USER, blo_join_main(), blo_read_file_checks(), BLO_READ_SKIP_DATA, BLO_READ_SKIP_USERDEF, blo_split_main(), FileData::bmain, CLOG_DEBUG, BHead::code, BlendFileData::cur_view_layer, Main::curlib, BlendFileData::curscene, data, do_versions(), do_versions_after_linking(), do_versions_userdef(), BlendFileReadReport::duration, FileData::fd_bmain, FD_FLAGS_HAS_INVALID_ID_NAMES, FD_FLAGS_IS_MEMFILE, BlendFileData::filepath, Main::filepath, FileData::fileversion, fix_relpaths_library(), Library::flag, FileData::flags, FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, G, Main::has_forward_compatibility_issues, BlendThumbnail::height, ID_FLAG_LINKED_AND_PACKED, ID_LI, ID_LINK_PLACEHOLDER, Main::id_map, ID_SCR, ID_SCRN, ID_TAG_NEW, IMB_colormanagement_working_space_convert(), Main::is_read_invalid, ID::lib, lib, lib_link_all(), BlendFileReadReport::lib_overrides, BlendFileReadReport::libraries, Main::libraries, library_filedata_release(), LIBRARY_FLAG_IS_ARCHIVE, link_global(), LISTBASE_FOREACH_MUTABLE, LOG_UNDO, long_id_names_ensure_unique_id_names(), long_id_names_process_action_slots_identifiers(), BlendFileData::main, MAIN_IDMAP_TYPE_UID, MEM_mallocN(), ViewLayer::name, FileData::new_idmap_uid, blender::bke::node_tree_update_all_new(), FileData::old_bmain, placeholders_ensure_valid(), read_file_thumbnail(), read_global(), read_libblock(), read_libraries(), read_undo_move_libmain_data(), read_undo_remap_noundo_data(), read_undo_reuse_noundo_local_ids(), read_userdef(), BlendThumbnail::rect, FileData::relabase, BlendFileReadReport::reports, FileData::reports, RPT_ERROR, RPT_WARNING, Library::runtime, FileData::skip_flags, Main::split_mains, STRNCPY(), BlendFileData::type, Main::versionfile, and BlendThumbnail::width.

Referenced by BLO_read_from_file(), BLO_read_from_memfile(), and BLO_read_from_memory().

◆ BLO_read_fileversion_get()

◆ BLO_read_float3_array()

void BLO_read_float3_array ( BlendDataReader * reader,
const int64_t array_size,
float ** ptr_p )

◆ BLO_read_float_array()

◆ BLO_read_get_new_data_address()

void * BLO_read_get_new_data_address ( BlendDataReader * reader,
const void * old_address )

Definition at line 5698 of file readfile.cc.

References BlendDataReader::fd, and newdataadr().

◆ BLO_read_get_new_data_address_no_us()

void * BLO_read_get_new_data_address_no_us ( BlendDataReader * reader,
const void * old_address,
size_t expected_size )

Does not consider the read data as 'used'. It will still be freed by readfile code at the end of the reading process, if no other 'real' usage was detected for it.

Typical valid usages include:

  • Restoring pointers to a specific item in an array or list (usually 'active' item e.g.). The found item is expected to also be read as part of its array/list storage reading.
  • Doing temporary access to deprecated data as part of some versioning code.

Definition at line 5703 of file readfile.cc.

References blo_verify_data_address(), BlendDataReader::fd, and newdataadr_no_us().

Referenced by BKE_modifier_blend_read_data(), modifier_replace_with_fluid(), blender::ed::outliner::outliner_space_blend_read_data(), and scene_blend_read_data().

◆ blo_read_get_new_globaldata_address()

void * blo_read_get_new_globaldata_address ( FileData * fd,
const void * adr )

Direct data-blocks with global linking.

Note
This is rather unfortunate to have to expose this here, but better use that nasty hack in do_version than readfile itself.

Definition at line 1512 of file readfile.cc.

References FileData::globmap, and oldnewmap_lookup_and_inc().

Referenced by blo_do_versions_290(), and link_global().

◆ BLO_read_get_new_id_address()

ID * BLO_read_get_new_id_address ( BlendLibReader * reader,
ID * self_id,
const bool is_linked_only,
ID * id )

Search for the new address of given id, during library linking part of blend-file reading process.

Parameters
self_idthe ID owner of the given id pointer. Note that it may be an embedded ID.
is_linked_onlyIf true, only return found pointer if it is a linked ID. Used to prevent linked data to point to local IDs.
Returns
the new address of the given ID pointer, or null if not found.

Definition at line 5731 of file readfile.cc.

References BlendLibReader::fd, and newlibadr().

Referenced by lib_link_cb().

◆ BLO_read_get_new_id_address_from_session_uid()

ID * BLO_read_get_new_id_address_from_session_uid ( BlendLibReader * reader,
uint session_uid )

Search for the new address of the ID for the given session_uid.

Only IDs existing in the newly read Main will be returned. If no matching session_uid in new main can be found, nullptr is returned.

This expected to be used during library-linking and/or 'undo_preserve' processes in undo case (i.e. memfile reading), typically to find a valid value (or nullptr) for ID pointers values coming from the previous, existing Main data, when it is preserved in newly read Main. See e.g. the scene_undo_preserve code-path.

Definition at line 5739 of file readfile.cc.

References BKE_main_idmap_lookup_uid(), BlendLibReader::fd, and FileData::new_idmap_uid.

Referenced by scene_foreach_toolsettings_id_pointer_process().

◆ BLO_read_glob_list()

void BLO_read_glob_list ( BlendDataReader * reader,
ListBase * list )

Definition at line 5973 of file readfile.cc.

References BlendDataReader::fd, and link_glob_list().

Referenced by scene_blend_read_data().

◆ BLO_read_int16_array()

void BLO_read_int16_array ( BlendDataReader * reader,
const int64_t array_size,
int16_t ** ptr_p )

◆ BLO_read_int32_array()

◆ BLO_read_int8_array()

void BLO_read_int8_array ( BlendDataReader * reader,
const int64_t array_size,
int8_t ** ptr_p )

◆ BLO_read_lib_get_main()

Main * BLO_read_lib_get_main ( BlendLibReader * reader)

◆ BLO_read_lib_is_undo()

bool BLO_read_lib_is_undo ( BlendLibReader * reader)

◆ BLO_read_lib_reports()

BlendFileReadReport * BLO_read_lib_reports ( BlendLibReader * reader)

◆ BLO_read_pointer_array()

◆ blo_read_shared_impl()

◆ BLO_read_string() [1/2]

void BLO_read_string ( BlendDataReader * reader,
char ** ptr_p )

Definition at line 5828 of file readfile.cc.

References BLI_assert_msg, BLO_read_data_address, len, MEM_allocN_len, and str.

Referenced by BKE_asset_catalog_path_list_blend_read_data(), BKE_asset_metadata_read(), BKE_asset_weak_reference_read(), BKE_constraint_blend_read_data(), BKE_fcurve_blend_read_data(), BKE_keyingsets_blend_read_data(), BKE_paint_blend_read_data(), BKE_preferences_extension_repo_read_data(), BKE_viewer_path_blend_read_data(), blender::bke::AttributeStorage::blend_read(), blender::blend_read(), blender::nodes::BakeItemsAccessor::blend_read_data_item(), blender::nodes::CaptureAttributeItemsAccessor::blend_read_data_item(), blender::nodes::ClosureInputItemsAccessor::blend_read_data_item(), blender::nodes::ClosureOutputItemsAccessor::blend_read_data_item(), blender::nodes::CombineBundleItemsAccessor::blend_read_data_item(), blender::nodes::EvaluateClosureInputItemsAccessor::blend_read_data_item(), blender::nodes::EvaluateClosureOutputItemsAccessor::blend_read_data_item(), blender::nodes::FieldToGridItemsAccessor::blend_read_data_item(), blender::nodes::FileOutputItemsAccessor::blend_read_data_item(), blender::nodes::ForeachGeometryElementGenerationItemsAccessor::blend_read_data_item(), blender::nodes::ForeachGeometryElementInputItemsAccessor::blend_read_data_item(), blender::nodes::ForeachGeometryElementMainItemsAccessor::blend_read_data_item(), blender::nodes::FormatStringItemsAccessor::blend_read_data_item(), blender::nodes::GeoViewerItemsAccessor::blend_read_data_item(), blender::nodes::MenuSwitchItemsAccessor::blend_read_data_item(), blender::nodes::RepeatItemsAccessor::blend_read_data_item(), blender::nodes::SeparateBundleItemsAccessor::blend_read_data_item(), blender::nodes::SimulationItemsAccessor::blend_read_data_item(), BLO_read_string(), camera_blend_read_data(), curve_blend_read_data(), curves_blend_read_data(), direct_link_id_override_property(), blender::bke::direct_link_node_socket(), direct_link_panel_list(), blender::bke::node_interface::item_types::item_read_data(), mesh_blend_read_data(), blender::nodes::node_composite_file_output_cc::node_blend_read(), blender::nodes::node_fn_input_string_cc::node_blend_read(), blender::bke::node_blend_read_data_storage(), blender::bke::node_tree_blend_read_data(), read_layer(), read_layer_tree_group(), read_ui_data(), blender::ed::asset::shelf::settings_blend_read_data(), blender::ed::spreadsheet::spreadsheet_blend_read_data(), blender::ed::spreadsheet::spreadsheet_column_blend_read(), blender::ed::spreadsheet::spreadsheet_column_id_blend_read(), blender::ed::spreadsheet::spreadsheet_table_id_blend_read(), blender::seq::strip_read_data_cb(), and text_blend_read_data().

◆ BLO_read_string() [2/2]

void BLO_read_string ( BlendDataReader * reader,
char *const * ptr_p )

Definition at line 5847 of file readfile.cc.

References BLO_read_string().

◆ BLO_read_struct_array_with_size()

void * BLO_read_struct_array_with_size ( BlendDataReader * reader,
const void * old_address,
size_t expected_size )

The 'main' read function and helper macros for non-basic data types.

NOTE: Currently the usage of the type info is very minimal/basic, it merely does a lose check on the data size.

Definition at line 5711 of file readfile.cc.

References blo_verify_data_address(), BlendDataReader::fd, and newdataadr().

Referenced by blender::nodes::socket_items::blend_read_data(), BLO_read_char_array(), BLO_read_double_array(), BLO_read_float_array(), BLO_read_int16_array(), BLO_read_int32_array(), BLO_read_int8_array(), BLO_read_struct_by_name_array(), BLO_read_struct_list_with_size(), BLO_read_uint32_array(), and BLO_read_uint8_array().

◆ BLO_read_struct_by_name_array()

void * BLO_read_struct_by_name_array ( BlendDataReader * reader,
const char * struct_name,
int64_t items_num,
const void * old_address )

◆ BLO_read_struct_list_with_size()

void BLO_read_struct_list_with_size ( BlendDataReader * reader,
const size_t expected_elem_size,
ListBase * list )

◆ BLO_read_uint32_array()

void BLO_read_uint32_array ( BlendDataReader * reader,
const int64_t array_size,
uint32_t ** ptr_p )

◆ BLO_read_uint8_array()

void BLO_read_uint8_array ( BlendDataReader * reader,
const int64_t array_size,
uint8_t ** ptr_p )

◆ BLO_readfile_id_runtime_data_free()

void BLO_readfile_id_runtime_data_free ( ID & id)

Free the ID_Readfile_Data of this ID. Does not deal with embedded IDs.

Definition at line 2220 of file readfile.cc.

References MEM_SAFE_FREE.

Referenced by BKE_libblock_free_runtime_data(), and BLO_readfile_id_runtime_data_free_all().

◆ BLO_readfile_id_runtime_data_free_all()

void BLO_readfile_id_runtime_data_free_all ( Main & bmain)

Free the ID_Readfile_Data of all IDs in this bmain and all their embedded IDs.

This is typically called at the end of the versioning process, as after that ID.runtime.readfile_data should no longer be needed.

Definition at line 2225 of file readfile.cc.

References BLO_readfile_id_runtime_data_free(), FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, GS, bNodeTree::id, Collection::id, ID_SCE, ID::name, and blender::bke::node_tree_from_id().

Referenced by BKE_blendfile_append(), BKE_blendfile_link(), and setup_app_data().

◆ BLO_readfile_id_runtime_tags()

ID_Readfile_Data::Tags BLO_readfile_id_runtime_tags ( ID & id)

◆ BLO_readfile_id_runtime_tags_for_write()

ID_Readfile_Data::Tags & BLO_readfile_id_runtime_tags_for_write ( ID & id)

Create the readfile_data if needed, and return id->runtime->readfile_data->tags.

Use it instead of BLO_readfile_id_runtime_tags when tags need to be set.

Definition at line 2214 of file readfile.cc.

References readfile_id_runtime_data_ensure().

Referenced by blo_do_versions_pre250(), expand_main(), lib_link_all(), read_libblock_undo_restore_at_old_address(), and read_library_linked_id().

◆ blo_readfile_invalidate()

void blo_readfile_invalidate ( FileData * fd,
Main * bmain,
const char * message )

◆ BLO_reportf_wrap()

◆ blo_split_main()

void blo_split_main ( Main * bmain,
bool do_split_packed_ids = true )

Split a single main into a vector of Mains, each containing only IDs from a given library.

The vector is accessible in all of the split mains through the shared pointer Main::split_mains.

The first Main of the vector is the same as the given main, and contains local IDs.

If do_split_packed_ids is false, packed linked IDs remain in the local (first) main as well.

Definition at line 415 of file readfile.cc.

References blender::Vector< T, InlineBufferCapacity, Allocator >::append(), BKE_main_idmap_destroy(), BKE_main_lists_get(), BKE_main_namemap_clear(), BKE_main_new(), BLENDER_FILE_SUBVERSION, BLENDER_FILE_VERSION, BLI_assert, BLI_listbase_is_empty(), Main::colorspace, Main::curlib, ListBase::first, GS, Main::has_forward_compatibility_issues, i, ID_LI, Main::id_map, Main::is_asset_edit_file, lib, Main::libraries, LIBRARY_FLAG_IS_ARCHIVE, LIBRARY_IS_ASSET_EDIT_FILE, MAIN_VERSION_FILE_OLDER_OR_EQUAL, ID::name, split_libdata(), Main::split_mains, Main::subversionfile, and Main::versionfile.

Referenced by BLO_main_validate_libraries(), blo_read_file_internal(), BLO_read_from_memfile(), library_link_begin(), and library_link_end().

◆ BLO_thumbnail_from_file()

BlendThumbnail * BLO_thumbnail_from_file ( const char * filepath)

Does a very light reading of given .blend file to extract its stored thumbnail.

Parameters
filepathThe path of the file to extract thumbnail from.
Returns
The raw thumbnail (MEM-allocated, as stored in file, use BKE_main_thumbnail_to_imbuf() to convert it to ImBuf image).

Definition at line 1456 of file readfile.cc.

References BLEN_THUMB_MEMSIZE, BLEN_THUMB_MEMSIZE_FILE, BLEN_THUMB_MEMSIZE_IS_VALID, BLI_assert, blo_filedata_free(), blo_filedata_from_file_minimal(), data, MEM_mallocN(), and read_file_thumbnail().

Referenced by imb_thumb_load_from_blendfile(), and uiTemplateRecentFiles_tooltip_func().

◆ blo_verify_data_address()

void * blo_verify_data_address ( FileData * fd,
void * new_address,
const void * ,
const size_t expected_size )
static

◆ BLO_version_from_file()

short BLO_version_from_file ( const char * filepath)

Does a very light reading of given .blend file to extract its version.

Parameters
filepathThe path of the blend file to extract version from.
Returns
The file version

Definition at line 1483 of file readfile.cc.

References blo_filedata_free(), blo_filedata_from_file_minimal(), and FileData::fileversion.

Referenced by file_draw_tooltip_custom_func(), and uiTemplateRecentFiles_tooltip_func().

◆ change_ID_link_filedata_get()

FileData * change_ID_link_filedata_get ( Main * bmain,
FileData * basefd )
static

◆ change_ID_pointer_to_real_ID_pointer()

void change_ID_pointer_to_real_ID_pointer ( FileData * basefd,
void * old,
void * newp )
static

◆ change_ID_pointer_to_real_ID_pointer_fd()

void change_ID_pointer_to_real_ID_pointer_fd ( FileData * fd,
const void * old,
void * newp )
static

◆ change_link_placeholder_to_real_ID_pointer()

void change_link_placeholder_to_real_ID_pointer ( FileData * basefd,
void * old,
void * newp )
static

◆ change_link_placeholder_to_real_ID_pointer_fd()

void change_link_placeholder_to_real_ID_pointer_fd ( FileData * fd,
const void * old,
void * newp )
static

◆ convert_pointer_array_32_to_64()

void convert_pointer_array_32_to_64 ( BlendDataReader * ,
const int64_t array_size,
const uint32_t * src,
uint64_t * dst )
static

Definition at line 5869 of file readfile.cc.

References i.

Referenced by BLO_read_pointer_array().

◆ convert_pointer_array_64_to_32()

void convert_pointer_array_64_to_32 ( BlendDataReader * reader,
const int64_t array_size,
const uint64_t * src,
uint32_t * dst )
static

◆ create_placeholder()

◆ direct_link_id()

◆ direct_link_id_common()

◆ direct_link_id_embedded_id()

◆ direct_link_id_override_property()

◆ direct_link_id_restore_recalc()

int direct_link_id_restore_recalc ( const FileData * fd,
const ID * id_target,
const ID * id_current,
const bool is_identical )
static

◆ direct_link_id_restore_recalc_exceptions()

int direct_link_id_restore_recalc_exceptions ( const ID * id_current)
static

◆ direct_link_keymapitem()

void direct_link_keymapitem ( BlendDataReader * reader,
wmKeyMapItem * kmi )
static

◆ direct_link_library()

◆ do_versions()

◆ do_versions_after_linking()

◆ do_versions_userdef()

void do_versions_userdef ( FileData * ,
BlendFileData * bfd )
static

Definition at line 3500 of file readfile.cc.

References blo_do_versions_userdef(), and BlendFileData::user.

Referenced by blo_read_file_internal().

◆ expand_cb()

◆ expand_doit_library()

◆ expand_main()

◆ filedata_new()

◆ find_bhead()

◆ find_bhead_from_code_name()

BHead * find_bhead_from_code_name ( FileData * fd,
const short idcode,
const char * name )
static

Definition at line 4500 of file readfile.cc.

References FileData::bhead_idname_map, BLI_strncpy(), MAX_ID_NAME, and name.

Referenced by find_bhead_from_idname(), and link_named_part().

◆ find_bhead_from_idname()

BHead * find_bhead_from_idname ( FileData * fd,
const char * idname )
static

◆ find_previous_lib()

BHead * find_previous_lib ( FileData * fd,
BHead * bhead )
static

Definition at line 4450 of file readfile.cc.

References blo_bhead_prev(), BHead::code, FD_FLAGS_IS_MEMFILE, FileData::flags, and ID_LI.

Referenced by expand_doit_library().

◆ fix_relpaths_library()

void fix_relpaths_library ( const char * basepath,
Main * main )
static

Definition at line 2569 of file readfile.cc.

References BLI_path_is_rel(), BLI_path_rel(), lib, LISTBASE_FOREACH, main, and STRNCPY().

Referenced by blo_read_file_internal(), and library_link_end().

◆ get_alloc_name()

const char * get_alloc_name ( FileData * fd,
BHead * bh,
const char * blockname,
const int id_type_index = INDEX_ID_NULL )
static

Generate the final allocation string reference for read blocks of data. If blockname is given, use it as 'owner block' info, otherwise use the id type index to get that info.

Note
These strings are stored until Blender exits

Definition at line 1776 of file readfile.cc.

References intern::memutil::alloc_string_storage_get(), BKE_idtype_get_info_from_idtype_index(), BLI_assert, intern::memutil::AllocStringStorage< keyT, hashT >::contains(), DNA_struct_identifier(), FileData::filesdna, intern::memutil::AllocStringStorage< keyT, hashT >::find(), INDEX_ID_MAX, INDEX_ID_NULL, intern::memutil::AllocStringStorage< keyT, hashT >::insert(), IDTypeInfo::name, BHead::nr, BHead::SDNAnr, FileData::storage_handle, UNLIKELY, and UNUSED_VARS_NDEBUG.

Referenced by read_libblock(), and read_struct().

◆ get_bhead()

◆ has_linked_ids_to_read()

int has_linked_ids_to_read ( Main * mainvar)
static

◆ is_minversion_older_than_blender()

bool is_minversion_older_than_blender ( FileData * fd,
ReportList * reports )
static

◆ lib_link_all()

◆ lib_link_cb()

◆ lib_link_scenes_check_set()

void lib_link_scenes_check_set ( Main * bmain)
static

◆ library_filedata_release()

void library_filedata_release ( Library * lib)
static

◆ library_id_is_yet_read()

ID * library_id_is_yet_read ( FileData * fd,
Main * mainvar,
BHead * bhead )
static

◆ library_id_is_yet_read_deep_hash()

ID * library_id_is_yet_read_deep_hash ( FileData * fd,
BHead * bhead )
static

◆ library_id_is_yet_read_main()

◆ library_link_begin()

◆ library_link_end()

◆ library_parent_filepath()

const char * library_parent_filepath ( Library * lib)
static

Definition at line 241 of file readfile.cc.

References lib.

Referenced by read_library_file_data(), and read_library_linked_id().

◆ link_glob_list()

void link_glob_list ( FileData * fd,
ListBase * lb )
static

◆ link_global()

◆ link_named_part()

◆ long_id_names_ensure_unique_id_names()

void long_id_names_ensure_unique_id_names ( Main * bmain)
static

ID names are truncated to their maximum allowed length at a very low level of the readfile code (see read_id_struct).

However, ensuring they remain unique can only be done once all IDs have been read and put in Main.

Note
BKE_main_namemap_validate_and_fix could also be used here - but it is designed for a more general usage, where names are typically expected to be valid, and would generate noisy logs in this case, where names are expected to not be valid.

Definition at line 964 of file readfile.cc.

References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add_new(), BKE_id_new_name_validate(), BLI_assert, CLOG_DEBUG, blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::contains(), FOREACH_MAIN_LISTBASE_BEGIN, FOREACH_MAIN_LISTBASE_END, ID_IS_LINKED, LISTBASE_FOREACH_MUTABLE, LOG, and RenameExistingNever.

Referenced by blo_read_file_internal().

◆ long_id_names_process_action_slots_identifiers()

void long_id_names_process_action_slots_identifiers ( Main * bmain)
static

Iterate all IDs from Actions and look for non-null terminated ActionSlot.identifier. Also handle slot users (in Action constraint, AnimData, and NLA strips).

This is for forward compatibility, if the blendfile was saved from a version allowing larger MAX_ID_NAME value than the current one (introduced when switching from MAX_ID_NAME = 66 to MAX_ID_NAME = 258).

Definition at line 1006 of file readfile.cc.

References ATTR_FALLTHROUGH, BKE_animdata_from_id(), BLI_str_utf8_truncate_at_size(), BLI_uniquename_cb(), bPose::chanbase, CLOG_DEBUG, CONSTRAINT_TYPE_ACTION, Object::constraints, FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, blender::bke::nla::foreach_strip_adt(), GS, i, ID_AC, ID_OB, ActionSlot::identifier, AnimData::last_slot_identifier, bActionConstraint::last_slot_identifier, NlaStrip::last_slot_identifier, LISTBASE_FOREACH, LOG, MAX_ID_NAME, ID::name, name, Object::pose, bAction::slot_array, bAction::slot_array_num, and AnimData::tmp_last_slot_identifier.

Referenced by blo_read_file_internal().

◆ newdataadr()

◆ newdataadr_no_us()

void * newdataadr_no_us ( FileData * fd,
const void * adr )
static

Definition at line 1507 of file readfile.cc.

References FileData::datamap, and oldnewmap_lookup_and_inc().

Referenced by BLO_read_get_new_data_address_no_us().

◆ newlibadr()

void * newlibadr ( FileData * fd,
ID * ,
const bool is_linked_only,
const void * adr )
static

◆ oldnewmap_clear()

◆ oldnewmap_free()

void oldnewmap_free ( OldNewMap * onm)
static

Definition at line 334 of file readfile.cc.

Referenced by blo_filedata_free(), and read_library_file_data().

◆ oldnewmap_insert()

bool oldnewmap_insert ( OldNewMap * onm,
const void * oldaddr,
void * newaddr,
const int nr )
static
Returns
true if the oldaddr key has been successfully added to the onm, and no existing entry was overwritten.

Definition at line 272 of file readfile.cc.

References Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add_overwrite(), and OldNewMap::map.

Referenced by blo_do_versions_oldnewmap_insert(), BLO_read_data_globmap_add(), link_glob_list(), oldnewmap_lib_insert(), and read_data_into_datamap().

◆ oldnewmap_lib_insert()

void oldnewmap_lib_insert ( FileData * fd,
const void * oldaddr,
ID * newaddr,
const int id_code )
static

◆ oldnewmap_liblookup()

void * oldnewmap_liblookup ( OldNewMap * onm,
const void * addr,
const bool is_linked_only )
static

Definition at line 307 of file readfile.cc.

References ID_IS_LINKED, and oldnewmap_lookup_and_inc().

Referenced by newlibadr().

◆ oldnewmap_lookup_and_inc()

void * oldnewmap_lookup_and_inc ( OldNewMap * onm,
const void * addr,
const bool increase_users )
static

◆ oldnewmap_new()

OldNewMap * oldnewmap_new ( )
static

Definition at line 263 of file readfile.cc.

Referenced by filedata_new(), and read_library_file_data().

◆ peek_struct_undo()

const void * peek_struct_undo ( FileData * fd,
BHead * bhead )
static

◆ placeholders_ensure_valid()

void placeholders_ensure_valid ( Main * bmain)
static

◆ read_blender_header()

◆ read_data_into_datamap()

BHead * read_data_into_datamap ( FileData * fd,
BHead * bhead,
const char * allocname,
const int id_type_index )
static

◆ read_file_bhead_idname_map_create()

◆ read_file_dna()

◆ read_file_thumbnail()

◆ read_file_version_and_colorspace()

◆ read_global()

◆ read_id_in_lib()

◆ read_id_struct()

ID * read_id_struct ( FileData * fd,
BHead * bh,
const char * blockname,
const int id_type_index )
static

◆ read_libblock()

◆ read_libblock_is_identical()

bool read_libblock_is_identical ( FileData * fd,
BHead * bhead )
static

◆ read_libblock_undo_restore()

◆ read_libblock_undo_restore_at_old_address()

◆ read_libblock_undo_restore_identical()

◆ read_libblock_undo_restore_library()

bool read_libblock_undo_restore_library ( FileData * fd,
const ID * id,
ID * id_old,
BHead * bhead )
static

◆ read_libblock_undo_restore_linked()

bool read_libblock_undo_restore_linked ( FileData * fd,
Main * libmain,
const ID * id,
ID ** r_id_old,
BHead * bhead )
static

◆ read_libraries()

◆ read_libraries_report_invalid_id_names()

void read_libraries_report_invalid_id_names ( FileData * fd,
ReportList * reports,
const bool has_forward_compatibility_issues,
const char * filepath )
static

◆ read_library_clear_weak_links()

◆ read_library_file_data()

◆ read_library_linked_id()

◆ read_library_linked_ids()

◆ read_struct()

◆ read_undo_move_libmain_data()

◆ read_undo_remap_noundo_data()

◆ read_undo_remap_noundo_data_cb()

◆ read_undo_reuse_noundo_local_ids()

◆ read_userdef()

◆ readfile_id_runtime_data_ensure()

void readfile_id_runtime_data_ensure ( ID & id)
static

Definition at line 2198 of file readfile.cc.

References MEM_callocN().

Referenced by BLO_readfile_id_runtime_tags_for_write(), and direct_link_id_common().

◆ sort_bhead_old_map()

◆ split_libdata()

void split_libdata ( ListBase * lb_src,
blender::Vector< Main * > & lib_main_array,
const bool do_split_packed_ids )
static

◆ split_main_newid()

◆ verg_bheadsort()

int verg_bheadsort ( const void * v1,
const void * v2 )
static

Definition at line 4411 of file readfile.cc.

References BHeadSort::old, and v2.

Referenced by find_bhead(), and sort_bhead_old_map().

Variable Documentation

◆ LOG

CLG_LogRef LOG = {"blend.readfile"}
static

Definition at line 182 of file readfile.cc.

◆ LOG_UNDO