Cleanup: sync minor changes from D4342
Use naming conventions from the patch so they match when it's applied.
This commit is contained in:
parent
d132c44652
commit
925b202641
|
@ -16,8 +16,7 @@
|
|||
|
||||
/** \file \ingroup blenloader
|
||||
*
|
||||
* Apply edits to DNA at load time
|
||||
* to behave as if old files were written new names.
|
||||
* Apply edits to DNA at load time to behave as if old files were written with new names.
|
||||
*/
|
||||
|
||||
#include "BLI_compiler_attrs.h"
|
||||
|
@ -33,8 +32,9 @@
|
|||
* Manipulates SDNA before calling #DNA_struct_get_compareflags,
|
||||
* allowing us to rename structs and struct members.
|
||||
*
|
||||
* \attention Changes here will cause breakages in forward compatbility,
|
||||
* Use this only in the _rare_ cases when migrating to new naming is needed.
|
||||
* - This means older versions of Blender won't have access to this data **USE WITH CARE**.
|
||||
*
|
||||
* - These changes are applied on file load (run-time), similar to versioning for compatibility.
|
||||
*/
|
||||
void blo_do_versions_dna(SDNA *sdna, const int versionfile, const int subversionfile)
|
||||
{
|
||||
|
|
|
@ -107,6 +107,6 @@ int DNA_elem_type_size(const eSDNA_Type elem_nr);
|
|||
bool DNA_sdna_patch_struct(
|
||||
struct SDNA *sdna, const char *struct_name_old, const char *struct_name_new);
|
||||
bool DNA_sdna_patch_struct_member(
|
||||
struct SDNA *sdna, const char *struct_name, const char *member_old, const char *member_new);
|
||||
struct SDNA *sdna, const char *struct_name, const char *elem_old, const char *elem_new);
|
||||
|
||||
#endif /* __DNA_GENFILE_H__ */
|
||||
|
|
|
@ -1395,44 +1395,43 @@ bool DNA_sdna_patch_struct(
|
|||
|
||||
/* Make public if called often with same struct (avoid duplicate look-ups). */
|
||||
static bool DNA_sdna_patch_struct_member_nr(
|
||||
SDNA *sdna, const int struct_name_nr, const char *member_old, const char *member_new)
|
||||
SDNA *sdna, const int struct_name_nr, const char *elem_old, const char *elem_new)
|
||||
{
|
||||
const int member_old_len = strlen(member_old);
|
||||
const int member_new_len = strlen(member_new);
|
||||
BLI_assert(member_new != NULL);
|
||||
const int elem_old_len = strlen(elem_old);
|
||||
const int elem_new_len = strlen(elem_new);
|
||||
BLI_assert(elem_new != NULL);
|
||||
const short *sp = sdna->structs[struct_name_nr];
|
||||
for (int member_iter = sp[1]; member_iter > 0; member_iter--, sp += 2) {
|
||||
const char *elem_full_old = sdna->names[sp[1]];
|
||||
/* Start & end offsets in 'elem_full_old'. */
|
||||
uint elem_full_offset_start;
|
||||
if (DNA_elem_id_match(member_old, member_old_len, elem_full_old, &elem_full_offset_start)) {
|
||||
for (int elem_index = sp[1]; elem_index > 0; elem_index--, sp += 2) {
|
||||
const char *elem_old_full = sdna->names[sp[1]];
|
||||
/* Start & end offsets in 'elem_old_full'. */
|
||||
uint elem_old_full_offset_start;
|
||||
if (DNA_elem_id_match(elem_old, elem_old_len, elem_old_full, &elem_old_full_offset_start)) {
|
||||
if (sdna->mem_arena == NULL) {
|
||||
sdna->mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
|
||||
}
|
||||
const int elem_full_old_len = strlen(elem_full_old);
|
||||
const char *elem_full_new = DNA_elem_id_rename(
|
||||
const char *elem_new_full = DNA_elem_id_rename(
|
||||
sdna->mem_arena,
|
||||
member_old, member_old_len,
|
||||
member_new, member_new_len,
|
||||
elem_full_old, elem_full_old_len,
|
||||
elem_full_offset_start);
|
||||
elem_old, elem_old_len,
|
||||
elem_new, elem_new_len,
|
||||
elem_old_full, strlen(elem_old_full),
|
||||
elem_old_full_offset_start);
|
||||
|
||||
sdna->names[sp[1]] = elem_full_new;
|
||||
sdna->names[sp[1]] = elem_new_full;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Replace \a member_old with \a member_new for struct \a struct_name
|
||||
* Replace \a elem_old with \a elem_new for struct \a struct_name
|
||||
* handles search & replace, maintaining surrounding non-identifier characters such as pointer & array size.
|
||||
*/
|
||||
bool DNA_sdna_patch_struct_member(
|
||||
SDNA *sdna, const char *struct_name, const char *member_old, const char *member_new)
|
||||
SDNA *sdna, const char *struct_name, const char *elem_old, const char *elem_new)
|
||||
{
|
||||
const int struct_name_nr = DNA_struct_find_nr(sdna, struct_name);
|
||||
if (struct_name_nr != -1) {
|
||||
return DNA_sdna_patch_struct_member_nr(sdna, struct_name_nr, member_old, member_new);
|
||||
return DNA_sdna_patch_struct_member_nr(sdna, struct_name_nr, elem_old, elem_new);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -107,22 +107,24 @@ uint DNA_elem_id_offset_end(const char *elem_full)
|
|||
/**
|
||||
* \a elem_dst must be at least the size of \a elem_src.
|
||||
*/
|
||||
void DNA_elem_id_strip_copy(char *elem_dst, const char *elem_src)
|
||||
uint DNA_elem_id_strip_copy(char *elem_dst, const char *elem_src)
|
||||
{
|
||||
const uint elem_src_offset = DNA_elem_id_offset_start(elem_src);
|
||||
const char *elem_src_trim = elem_src + elem_src_offset;
|
||||
const uint elem_src_trim_len = DNA_elem_id_offset_end(elem_src_trim);
|
||||
memcpy(elem_dst, elem_src_trim, elem_src_trim_len);
|
||||
elem_dst[elem_src_trim_len] = '\0';
|
||||
return elem_src_trim_len;
|
||||
}
|
||||
|
||||
void DNA_elem_id_strip(char *elem)
|
||||
uint DNA_elem_id_strip(char *elem)
|
||||
{
|
||||
const uint elem_offset = DNA_elem_id_offset_start(elem);
|
||||
const char *elem_trim = elem + elem_offset;
|
||||
const uint elem_trim_len = DNA_elem_id_offset_end(elem_trim);
|
||||
memmove(elem, elem_trim, elem_trim_len);
|
||||
elem[elem_trim_len] = '\0';
|
||||
return elem_trim_len;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,8 +26,8 @@ int DNA_elem_array_size(const char *str);
|
|||
|
||||
uint DNA_elem_id_offset_start(const char *elem_full);
|
||||
uint DNA_elem_id_offset_end(const char *elem_full);
|
||||
void DNA_elem_id_strip_copy(char *elem_dst, const char *elem_src);
|
||||
void DNA_elem_id_strip(char *elem);
|
||||
uint DNA_elem_id_strip_copy(char *elem_dst, const char *elem_src);
|
||||
uint DNA_elem_id_strip(char *elem);
|
||||
bool DNA_elem_id_match(
|
||||
const char *elem_search, const int elem_search_len,
|
||||
const char *elem_full,
|
||||
|
|
Loading…
Reference in New Issue