1
1

Compare commits

...

15 Commits

11 changed files with 537 additions and 30 deletions

View File

@@ -35,6 +35,9 @@
* - 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.
*
* \attention ONLY USE THIS KIND OF VERSIONING WHEN
* DOING IT WITH `dna_rename_defs.h` ISN'T SUFFICIENT.
*/
void blo_do_versions_dna(SDNA *sdna, const int versionfile, const int subversionfile)
{

View File

@@ -109,4 +109,6 @@ bool DNA_sdna_patch_struct(
bool DNA_sdna_patch_struct_member(
struct SDNA *sdna, const char *struct_name, const char *elem_old, const char *elem_new);
void DNA_sdna_alias_runtime_ensure(struct SDNA *sdna);
#endif /* __DNA_GENFILE_H__ */

View File

@@ -64,6 +64,14 @@ typedef struct SDNA {
/** Temporary memory currently only used for version patching DNA. */
struct MemArena *mem_arena;
/** Runtime versions of data stored in DNA, lazy initialized,
* only different when renaming is done. */
struct {
/** Aligned with #SDNA.names, same pointers when unchanged. */
const char **names;
/** Aligned with #SDNA.types, same pointers when unchanged. */
const char **types;
} runtime;
} SDNA;
#

View File

@@ -35,7 +35,11 @@ blender_include_dirs(
set(SRC
dna_utils.c
makesdna.c
../../blenlib/intern/BLI_ghash.c
../../blenlib/intern/BLI_ghash_utils.c
../../blenlib/intern/BLI_memarena.c
../../blenlib/intern/BLI_mempool.c
../../blenlib/intern/hash_mm2a.c # needed by 'BLI_ghash_utils.c', not used directly.
../../../../intern/guardedalloc/intern/mallocn.c
../../../../intern/guardedalloc/intern/mallocn_guarded_impl.c
../../../../intern/guardedalloc/intern/mallocn_lockfree_impl.c

View File

@@ -156,6 +156,9 @@ void DNA_sdna_free(SDNA *sdna)
BLI_memarena_free(sdna->mem_arena);
}
MEM_SAFE_FREE(sdna->runtime.names);
MEM_SAFE_FREE(sdna->runtime.types);
MEM_freeN(sdna);
}
@@ -311,6 +314,9 @@ static bool init_structDNA(
#endif
sdna->mem_arena = NULL;
/* Lazy initialize. */
memset(&sdna->runtime, 0, sizeof(sdna->runtime));
/* Struct DNA ('SDNA') */
if (*data != MAKE_ID('S', 'D', 'N', 'A')) {
*r_error_message = "SDNA error in SDNA file";
@@ -1444,3 +1450,117 @@ bool DNA_sdna_patch_struct_member(
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Versioning (Forward Compatible)
*
* Versioning that allows new names.
* \{ */
/**
* Names are shared between structs which causes problems renaming.
* Make sure every struct member gets it's own name so renaming only ever impacts a single struct.
*
* The resulting SDNA is never written to disk.
*/
static void sdna_alias_runtime_expand_names(SDNA *sdna)
{
int names_expand_len = 0;
for (int struct_nr = 0; struct_nr < sdna->nr_structs; struct_nr++) {
const short *sp = sdna->structs[struct_nr];
names_expand_len += sp[1];
}
const char **names_expand = MEM_mallocN(sizeof(*names_expand) * names_expand_len, __func__);
int names_expand_index = 0;
for (int struct_nr = 0; struct_nr < sdna->nr_structs; struct_nr++) {
/* We can't edit this memory 'sdna->structs' points to (readonly datatoc file). */
const short *sp = sdna->structs[struct_nr];
short *sp_expand = BLI_memarena_alloc(sdna->mem_arena, sizeof(short[2]) * (1 + sp[1]));
memcpy(sp_expand, sp, sizeof(short[2]) * (1 + sp[1]));
sdna->structs[struct_nr] = sp_expand;
const int names_len = sp[1];
sp += 2;
sp_expand += 2;
for (int i = 0; i < names_len; i++, sp += 2, sp_expand += 2) {
names_expand[names_expand_index] = sdna->names[sp[1]];
BLI_assert(names_expand_index < SHRT_MAX);
sp_expand[1] = names_expand_index;
names_expand_index++;
}
}
MEM_freeN((void *)sdna->names);
sdna->names = names_expand;
sdna->nr_names = names_expand_len;
}
static const char *dna_sdna_alias_runtime_from_static_elem_full(
SDNA *sdna, GHash *elem_map_runtime_from_static,
const char *struct_name_static, const char *elem_static_full)
{
const int elem_static_full_len = strlen(elem_static_full);
char *elem_static = alloca(elem_static_full_len + 1);
const int elem_static_len = DNA_elem_id_strip_copy(elem_static, elem_static_full);
const char *str_pair[2] = {struct_name_static, elem_static};
const char *elem_runtime = BLI_ghash_lookup(elem_map_runtime_from_static, str_pair);
if (elem_runtime) {
return DNA_elem_id_rename(
sdna->mem_arena,
elem_static, elem_static_len,
elem_runtime, strlen(elem_runtime),
elem_static_full, elem_static_full_len,
DNA_elem_id_offset_start(elem_static_full));
}
return NULL;
}
void DNA_sdna_alias_runtime_ensure(SDNA *sdna)
{
if (sdna->mem_arena == NULL) {
sdna->mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
}
GHash *struct_map_runtime_from_static;
GHash *elem_map_runtime_from_static;
DNA_alias_maps(
DNA_VERSION_RUNTIME_FROM_STATIC,
&struct_map_runtime_from_static,
&elem_map_runtime_from_static);
if (sdna->runtime.types == NULL) {
sdna->runtime.types = MEM_mallocN(sizeof(*sdna->runtime.types) * sdna->nr_types, __func__);
for (int type_nr = 0; type_nr < sdna->nr_types; type_nr++) {
const char *str = sdna->types[type_nr];
sdna->runtime.types[type_nr] = BLI_ghash_lookup_default(
struct_map_runtime_from_static, str, (void *)str);
}
}
if (sdna->runtime.names == NULL) {
sdna_alias_runtime_expand_names(sdna);
sdna->runtime.names = MEM_mallocN(sizeof(*sdna->runtime.names) * sdna->nr_names, __func__);
for (int struct_nr = 0; struct_nr < sdna->nr_structs; struct_nr++) {
const short *sp = sdna->structs[struct_nr];
const char *struct_name_static = sdna->types[sp[0]];
const int dna_struct_names_len = sp[1];
sp += 2;
for (int a = 0; a < dna_struct_names_len; a++, sp += 2) {
const char *elem_runtime_full = dna_sdna_alias_runtime_from_static_elem_full(
sdna, elem_map_runtime_from_static, struct_name_static, sdna->names[sp[1]]);
if (elem_runtime_full != NULL) {
sdna->runtime.names[sp[1]] = elem_runtime_full;
}
else {
sdna->runtime.names[sp[1]] = sdna->names[sp[1]];
}
}
}
}
BLI_ghash_free(struct_map_runtime_from_static, NULL, NULL);
BLI_ghash_free(elem_map_runtime_from_static, MEM_freeN, NULL);
}
/** \} */

View File

@@ -0,0 +1,57 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
* DNA handling
*/
/** \file \ingroup DNA
*
* Defines in this header are only used to define blend file storage.
* This allows us to rename variables & structs without breaking compatibility.
*
* - When renaming the member of a struct which has it's self been renamed
* refer to the newer name, not the original.
*
* - Changes here only change generated code for `makesdna.c` and `makesrna.c`
* without impacting Blender's run-time, besides allowing us to use the new names.
*
* - Renaming something that has already been renamed can be done by editing the existing rename macro.
* All references to the previous destination name can be removed since they're
* never written to disk.
*
* \see versioning_dna.c for a actual version patching.
*/
/* No include guard (intentional). */
/* *********************
* NOTE FOR PATCH REVIEW
* *********************
*
* (these won't be committed, just a test to see it works)
*/
DNA_STRUCT_RENAME(Lamp, Light)
DNA_STRUCT_RENAME(SpaceOops, SpaceOutliner)
DNA_STRUCT_RENAME_ELEM(Camera, YF_dofdist, dof_distance)
DNA_STRUCT_RENAME_ELEM(Camera, clipend, clip_end)
DNA_STRUCT_RENAME_ELEM(Camera, clipsta, clip_start)
DNA_STRUCT_RENAME_ELEM(Light, clipend, clip_end)
DNA_STRUCT_RENAME_ELEM(Light, clipsta, clip_start)
DNA_STRUCT_RENAME_ELEM(LightProbe, clipend, clip_end)
DNA_STRUCT_RENAME_ELEM(LightProbe, clipsta, clip_start)
DNA_STRUCT_RENAME_ELEM(Object, parentinv, parent_inverse_matrix)
DNA_STRUCT_RENAME_ELEM(Object, dup_group, instance_collection)

View File

@@ -23,9 +23,12 @@
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_sys_types.h"
#include "BLI_utildefines.h"
#include "BLI_assert.h"
#include "BLI_ghash.h"
#include "BLI_memarena.h"
@@ -156,32 +159,124 @@ char *DNA_elem_id_rename(
struct MemArena *mem_arena,
const char *elem_src, const int elem_src_len,
const char *elem_dst, const int elem_dst_len,
const char *elem_full_src, const int elem_full_src_len,
const uint elem_full_offset_start)
const char *elem_src_full, const int elem_src_full_len,
const uint elem_src_full_offset_len)
{
BLI_assert(strlen(elem_src) == elem_src_len);
BLI_assert(strlen(elem_dst) == elem_dst_len);
BLI_assert(strlen(elem_full_src) == elem_full_src_len);
BLI_assert(DNA_elem_id_offset_start(elem_full_src) == elem_full_offset_start);
BLI_assert(strlen(elem_src_full) == elem_src_full_len);
BLI_assert(DNA_elem_id_offset_start(elem_src_full) == elem_src_full_offset_len);
UNUSED_VARS_NDEBUG(elem_src);
const int elem_final_len = (elem_full_src_len - elem_src_len) + elem_dst_len;
char *elem_full_dst = BLI_memarena_alloc(mem_arena, elem_final_len + 1);
const int elem_final_len = (elem_src_full_len - elem_src_len) + elem_dst_len;
char *elem_dst_full = BLI_memarena_alloc(mem_arena, elem_final_len + 1);
uint i = 0;
if (elem_full_offset_start != 0) {
memcpy(elem_full_dst, elem_full_src, elem_full_offset_start);
i = elem_full_offset_start;
if (elem_src_full_offset_len != 0) {
memcpy(elem_dst_full, elem_src_full, elem_src_full_offset_len);
i = elem_src_full_offset_len;
}
memcpy(&elem_full_dst[i], elem_dst, elem_dst_len + 1);
memcpy(&elem_dst_full[i], elem_dst, elem_dst_len + 1);
i += elem_dst_len;
uint elem_full_offset_end = elem_full_offset_start + elem_src_len;
if (elem_full_src[elem_full_offset_end] != '\0') {
const int elem_full_tail_len = (elem_full_src_len - elem_full_offset_end);
memcpy(&elem_full_dst[i], &elem_full_src[elem_full_offset_end], elem_full_tail_len + 1);
uint elem_src_full_offset_end = elem_src_full_offset_len + elem_src_len;
if (elem_src_full[elem_src_full_offset_end] != '\0') {
const int elem_full_tail_len = (elem_src_full_len - elem_src_full_offset_end);
memcpy(&elem_dst_full[i], &elem_src_full[elem_src_full_offset_end], elem_full_tail_len + 1);
i += elem_full_tail_len;
}
BLI_assert((strlen(elem_full_dst) == elem_final_len) && (i == elem_final_len));
return elem_full_dst;
BLI_assert((strlen(elem_dst_full) == elem_final_len) && (i == elem_final_len));
return elem_dst_full;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Versioning
* \{ */
static uint strhash_pair_p(const void *ptr)
{
const char * const *pair = ptr;
return (BLI_ghashutil_strhash_p(pair[0]) ^
BLI_ghashutil_strhash_p(pair[1]));
}
static bool strhash_pair_cmp(const void *a, const void *b)
{
const char * const *pair_a = a;
const char * const *pair_b = b;
return (STREQ(pair_a[0], pair_b[0]) &&
STREQ(pair_a[1], pair_b[1])) ? false : true;
}
void DNA_alias_maps(
enum eDNAVersionDir version_dir,
GHash **r_struct_map, GHash **r_elem_map)
{
GHash *struct_map_local = NULL;
if (r_struct_map) {
const char *data[][2] = {
#define DNA_STRUCT_RENAME(old, new) {#old, #new},
#define DNA_STRUCT_RENAME_ELEM(struct_name, old, new)
#include "dna_rename_defs.h"
#undef DNA_STRUCT_RENAME
#undef DNA_STRUCT_RENAME_ELEM
};
int elem_key, elem_val;
if (version_dir == DNA_VERSION_RUNTIME_FROM_STATIC) {
elem_key = 0;
elem_val = 1;
}
else {
elem_key = 1;
elem_val = 0;
}
GHash *struct_map = BLI_ghash_str_new_ex(__func__, ARRAY_SIZE(data));
for (int i = 0; i < ARRAY_SIZE(data); i++) {
BLI_ghash_insert(struct_map, (void *)data[i][elem_key], (void *)data[i][elem_val]);
}
*r_struct_map = struct_map;
/* We know the direction of this, for local use. */
struct_map_local = BLI_ghash_str_new_ex(__func__, ARRAY_SIZE(data));
for (int i = 0; i < ARRAY_SIZE(data); i++) {
BLI_ghash_insert(struct_map_local, (void *)data[i][1], (void *)data[i][0]);
}
}
if (r_elem_map != NULL) {
const char *data[][3] = {
#define DNA_STRUCT_RENAME(old, new)
#define DNA_STRUCT_RENAME_ELEM(struct_name, old, new) {#struct_name, #old, #new},
#include "dna_rename_defs.h"
#undef DNA_STRUCT_RENAME
#undef DNA_STRUCT_RENAME_ELEM
};
int elem_key, elem_val;
if (version_dir == DNA_VERSION_RUNTIME_FROM_STATIC) {
elem_key = 1;
elem_val = 2;
}
else {
elem_key = 2;
elem_val = 1;
}
GHash *elem_map = BLI_ghash_new_ex(strhash_pair_p, strhash_pair_cmp, __func__, ARRAY_SIZE(data));
for (int i = 0; i < ARRAY_SIZE(data); i++) {
const char **str_pair = MEM_mallocN(sizeof(char *) * 2, __func__);
str_pair[0] = BLI_ghash_lookup_default(struct_map_local, data[i][0], (void *)data[i][0]);
str_pair[1] = data[i][elem_key],
BLI_ghash_insert(elem_map, str_pair, (void *)data[i][elem_val]);
}
*r_elem_map = elem_map;
}
if (struct_map_local) {
BLI_ghash_free(struct_map_local, NULL, NULL);
}
}
#undef DNA_MAKESDNA
/** \} */

View File

@@ -21,6 +21,7 @@
#define __DNA_UTILS_H__
struct MemArena;
struct GHash;
int DNA_elem_array_size(const char *str);
@@ -39,4 +40,13 @@ char *DNA_elem_id_rename(
const char *elem_full_src, const int elem_full_src_len,
const uint elem_full_offset_start);
/* When requesting version info, support both directions. */
enum eDNAVersionDir {
DNA_VERSION_STATIC_FROM_RUNTIME = -1,
DNA_VERSION_RUNTIME_FROM_STATIC = 1,
};
void DNA_alias_maps(
enum eDNAVersionDir version_dir,
struct GHash **r_struct_map, struct GHash **r_elem_map);
#endif /* __DNA_UTILS_H__ */

View File

@@ -43,11 +43,15 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "MEM_guardedalloc.h"
#include "BLI_sys_types.h" /* for intptr_t support */
#include "BLI_utildefines.h"
#include "BLI_alloca.h"
#include "BLI_ghash.h"
#include "BLI_memarena.h"
#include "BLI_sys_types.h" /* for intptr_t support */
#include "dna_utils.h"
@@ -157,6 +161,14 @@ static short *typelens_64;
* sp[1] is amount of elements
* sp[2] sp[3] is typenr, namenr (etc) */
static short **structs, *structdata;
/** Versioning data */
static struct {
GHash *struct_map_runtime_from_static;
GHash *struct_map_static_from_runtime;
GHash *elem_map_static_from_runtime;
} g_version_data = {NULL};
/**
* Variable to control debug output of makesdna.
* debugSDNA:
@@ -171,10 +183,8 @@ static int additional_slen_offset;
#define DEBUG_PRINTF(debug_level, ...) \
{ if (debugSDNA > debug_level) { printf(__VA_ARGS__); } } ((void)0)
/* stub for BLI_abort() */
#ifndef NDEBUG
void BLI_system_backtrace(FILE *fp);
void BLI_system_backtrace(FILE *fp)
{
(void)fp;
@@ -242,6 +252,44 @@ void printStructLengths(void);
* Make DNA string (write to file).
* \{ */
static const char *version_struct_static_from_runtime(const char *str)
{
const char *str_test = BLI_ghash_lookup(g_version_data.struct_map_static_from_runtime, str);
if (str_test != NULL) {
return str_test;
}
return str;
}
static const char *version_struct_runtime_from_static(const char *str)
{
const char *str_test = BLI_ghash_lookup(g_version_data.struct_map_runtime_from_static, str);
if (str_test != NULL) {
return str_test;
}
return str;
}
static const char *version_elem_static_from_runtime(
const int strct, const char *elem_runtime_full)
{
const uint elem_runtime_full_len = strlen(elem_runtime_full);
char *elem_runtime = alloca(elem_runtime_full_len + 1);
const int elem_runtime_len = DNA_elem_id_strip_copy(elem_runtime, elem_runtime_full);
const char *str_pair[2] = {types[strct], elem_runtime};
const char *elem_static = BLI_ghash_lookup(g_version_data.elem_map_static_from_runtime, str_pair);
if (elem_static != NULL) {
return DNA_elem_id_rename(
mem_arena,
elem_runtime, elem_runtime_len,
elem_static, strlen(elem_static),
elem_runtime_full, elem_runtime_full_len,
DNA_elem_id_offset_start(elem_runtime_full));
}
return elem_runtime_full;
}
static int add_type(const char *str, int len)
{
int nr;
@@ -257,6 +305,8 @@ static int add_type(const char *str, int len)
return -1;
}
str = version_struct_static_from_runtime(str);
/* search through type array */
for (nr = 0; nr < nr_types; nr++) {
if (strcmp(str, types[nr]) == 0) {
@@ -676,8 +726,7 @@ static int convert_include(const char *filename)
if (md1[slen - 1] == ';') {
md1[slen - 1] = 0;
name = add_name(md1);
name = add_name(version_elem_static_from_runtime(strct, md1));
slen += additional_slen_offset;
sp[0] = type;
sp[1] = name;
@@ -693,8 +742,7 @@ static int convert_include(const char *filename)
break;
}
name = add_name(md1);
name = add_name(version_elem_static_from_runtime(strct, md1));
slen += additional_slen_offset;
sp[0] = type;
@@ -1008,6 +1056,16 @@ static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offs
typelens_64 = MEM_callocN(sizeof(short) * maxnr, "typelens_64");
structs = MEM_callocN(sizeof(short *) * maxnr, "structs");
/* Build versioning data */
DNA_alias_maps(
DNA_VERSION_RUNTIME_FROM_STATIC,
&g_version_data.struct_map_runtime_from_static,
NULL);
DNA_alias_maps(
DNA_VERSION_STATIC_FROM_RUNTIME,
&g_version_data.struct_map_static_from_runtime,
&g_version_data.elem_map_static_from_runtime);
/**
* Insertion of all known types.
*
@@ -1190,12 +1248,36 @@ static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offs
for (i = 0; i < nr_structs; i++) {
const short *structpoin = structs[i];
const int structtype = structpoin[0];
fprintf(file_offsets, "\t_SDNA_TYPE_%s = %d,\n", types[structtype], i);
fprintf(file_offsets, "\t_SDNA_TYPE_%s = %d,\n", version_struct_runtime_from_static(types[structtype]), i);
}
fprintf(file_offsets, "\tSDNA_TYPE_MAX = %d,\n", nr_structs);
fprintf(file_offsets, "};\n");
}
/* Check versioning errors which could cause duplicate names,
* do last because names are stripped. */
{
GSet *names_unique = BLI_gset_str_new_ex(__func__, 512);
for (int struct_nr = 0; struct_nr < nr_structs; struct_nr++) {
sp = structs[struct_nr];
const char *struct_name = types[sp[0]];
const int len = sp[1];
sp += 2;
for (int a = 0; a < len; a++, sp += 2) {
char *name = names[sp[1]];
DNA_elem_id_strip(name);
if (!BLI_gset_add(names_unique, name)) {
fprintf(stderr, "Error: duplicate name found '%s.%s', "
"likely cause is 'dna_rename_defs.h'\n",
struct_name, name);
return 1;
}
}
BLI_gset_clear(names_unique, NULL);
}
BLI_gset_free(names_unique, NULL);
}
MEM_freeN(structdata);
MEM_freeN(names);
MEM_freeN(types);
@@ -1206,6 +1288,10 @@ static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offs
BLI_memarena_free(mem_arena);
BLI_ghash_free(g_version_data.struct_map_runtime_from_static, NULL, NULL);
BLI_ghash_free(g_version_data.struct_map_static_from_runtime, NULL, NULL);
BLI_ghash_free(g_version_data.elem_map_static_from_runtime, MEM_freeN, NULL);
DEBUG_PRINTF(0, "done.\n");
return 0;

View File

@@ -58,6 +58,12 @@
BlenderDefRNA DefRNA = {NULL, {NULL, NULL}, {NULL, NULL}, NULL, 0, 0, 0, 1, 1};
#ifndef RNA_RUNTIME
static struct {
GHash *struct_map_static_from_runtime;
} g_version_data;
#endif
/* Duplicated code since we can't link in blenkernel or blenlib */
/* pedantic check for final '.', note '...' are allowed though. */
@@ -354,7 +360,23 @@ static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *
const short *sp;
int a, b, structnr, totmember, cmp;
structnr = DNA_struct_find_nr(sdna, structname);
if (!DefRNA.preprocess) {
fprintf(stderr, "%s: only during preprocessing.\n", __func__);
return 0;
}
#ifndef RNA_RUNTIME
{
const char *structname_maybe_static = BLI_ghash_lookup_default(
g_version_data.struct_map_static_from_runtime, structname, (void *)structname);
structnr = DNA_struct_find_nr(sdna, structname_maybe_static);
}
#else
/* Quiet warning only, this is only for the proprocessor. */
BLI_assert(0);
structnr = -1;
#endif
if (structnr == -1)
return 0;
@@ -363,12 +385,11 @@ static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *
sp += 2;
for (a = 0; a < totmember; a++, sp += 2) {
dnaname = sdna->names[sp[1]];
dnaname = sdna->runtime.names[sp[1]];
cmp = rna_member_cmp(dnaname, membername);
if (cmp == 1) {
smember->type = sdna->types[sp[0]];
smember->type = sdna->runtime.types[sp[0]];
smember->name = dnaname;
if (strstr(membername, "["))
@@ -389,7 +410,7 @@ static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *
smember->arraylength = 0;
membername = strstr(membername, ".") + strlen(".");
rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
rna_find_sdna_member(sdna, sdna->runtime.types[sp[0]], membername, smember);
return 1;
}
@@ -400,7 +421,7 @@ static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *
smember->arraylength = 0;
membername = strstr(membername, "->") + strlen("->");
rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
rna_find_sdna_member(sdna, sdna->runtime.types[sp[0]], membername, smember);
return 1;
}
@@ -572,6 +593,16 @@ BlenderRNA *RNA_create(void)
DefRNA.error = 1;
}
/* We need both runtime and static (on-disk) DNA names. */
DNA_sdna_alias_runtime_ensure(DefRNA.sdna);
#ifndef RNA_RUNTIME
DNA_alias_maps(
DNA_VERSION_STATIC_FROM_RUNTIME,
&g_version_data.struct_map_static_from_runtime,
NULL);
#endif
return brna;
}
@@ -705,6 +736,12 @@ void RNA_free(BlenderRNA *brna)
RNA_struct_free(brna, srna);
}
}
#ifndef RNA_RUNTIME
BLI_ghash_free(g_version_data.struct_map_static_from_runtime, NULL, NULL);
g_version_data.struct_map_static_from_runtime = NULL;
#endif
}
static size_t rna_property_type_sizeof(PropertyType type)

85
version_update_D4342_utility.py Executable file
View File

@@ -0,0 +1,85 @@
#!/usr/bin/env python3
# Run from Blender's root DIR
SOURCE_DIRS = (
"source",
)
USE_MULTIPROCESS = True
replace_all = (
("Lamp", "Light"),
("SpaceOops", "SpaceOutliner"),
("YF_dofdist", "dof_distance"),
("clipend", "clip_end"),
("clipsta", "clip_start"),
("parentinv", "parent_inverse_matrix"),
("dup_group", "instance_collection"),
)
replace_tables = (
replace_all,
)
replace_tables_re = [
[(src, dst) for src, dst in table]
for table in replace_tables
]
def replace_all(fn, data_src):
import re
data_dst = data_src
for table in replace_tables_re:
for src_re, dst in table:
data_dst = re.sub(src_re, dst, data_dst)
return data_dst
operation = replace_all
import os
def source_files(path):
for dirpath, dirnames, filenames in os.walk(path):
dirnames[:] = [d for d in dirnames if not d.startswith(".")]
for filename in filenames:
if filename.startswith("."):
continue
ext = os.path.splitext(filename)[1]
# XXX weak, don't touch this!
if filename.endswith("dna_rename_defs.h"):
continue
if ext.lower() in {".c", ".cc", ".cxx", ".cpp", ".h", ".hxx", ".hpp"}:
yield os.path.join(dirpath, filename)
def operation_wrap(fn):
with open(fn, "r", encoding="utf-8") as f:
data_src = f.read()
data_dst = operation(fn, data_src)
if data_dst is None or (data_src == data_dst):
return
with open(fn, "w", encoding="utf-8") as f:
f.write(data_dst)
def main():
if USE_MULTIPROCESS:
args = [fn for DIR in SOURCE_DIRS for fn in source_files(DIR)]
import multiprocessing
job_total = multiprocessing.cpu_count()
pool = multiprocessing.Pool(processes=job_total * 2)
pool.map(operation_wrap, args)
else:
for fn in source_files(SOURCE_DIR):
operation_wrap(fn)
if __name__ == "__main__":
main()