CMake: add WITH_STRSIZE_DEBUG option, RNA support #107602

Closed
Campbell Barton wants to merge 1 commits from ideasman42/blender:pr-debug-strsize into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
4 changed files with 20 additions and 18 deletions

View File

@ -651,6 +651,12 @@ if(WIN32)
set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
endif()
option(WITH_STRSIZE_DEBUG "\
Ensure string operations on fixed size buffers \
(works well with with \"WITH_COMPILER_ASAN\" & valgrind to detect incorrect buffer size arguments)"
OFF)
mark_as_advanced(WITH_STRSIZE_DEBUG)

Do you think we could enable this in build_files/cmake/config/blender_developer.cmake?

There is a performance impact, but if ASAN is on as well it's not a big deal I guess.

I'd even consider just always enabling this when ASAN is used, and not even having a CMake option.

Do you think we could enable this in `build_files/cmake/config/blender_developer.cmake`? There is a performance impact, but if ASAN is on as well it's not a big deal I guess. I'd even consider just always enabling this when ASAN is used, and not even having a CMake option.

Enabled in blender_developer.cmake, I'd rather keep it a separate option though for a couple of reasons.

  • Buffer overruns within a struct don't generate errors with ASAN, so it's useful to be able to turn it off to check if a corruption was caused by data being written past the string but within a struct.
  • This can be used with valgrind too.
Enabled in `blender_developer.cmake`, I'd rather keep it a separate option though for a couple of reasons. - Buffer overruns within a struct don't generate errors with ASAN, so it's useful to be able to turn it off to check if a corruption was caused by data being written past the string but within a struct. - This can be used with valgrind too.
# Compiler tool-chain.
if(UNIX)
if(CMAKE_COMPILER_IS_GNUCC)

View File

@ -12,6 +12,7 @@ set(WITH_BUILDINFO OFF CACHE BOOL "" FORCE)
# developer profile for now.
if(NOT WIN32)
set(WITH_COMPILER_ASAN ON CACHE BOOL "" FORCE)
set(WITH_STRSIZE_DEBUG ON CACHE BOOL "" FORCE)
endif()
set(WITH_CYCLES_NATIVE_ONLY ON CACHE BOOL "" FORCE)
set(WITH_DOC_MANPAGE OFF CACHE BOOL "" FORCE)

View File

@ -726,18 +726,13 @@ static char *rna_def_property_get_func(
switch (prop->type) {
case PROP_STRING: {
StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
(void)sprop; /* Only used in debug mode. */
fprintf(f, "void %s(PointerRNA *ptr, char *value)\n", func);
fprintf(f, "{\n");
if (manualfunc) {
fprintf(f, " %s(ptr, value);\n", manualfunc);
}
else {
const PropertySubType subtype = prop->subtype;
const char *string_copy_func =
ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME, PROP_BYTESTRING) ?
"BLI_strncpy" :
"BLI_strncpy_utf8";
rna_print_data_get(f, dp);
if (dp->dnapointerlevel == 1) {
@ -746,28 +741,24 @@ static char *rna_def_property_get_func(
fprintf(f, " *value = '\\0';\n");
fprintf(f, " return;\n");
fprintf(f, " }\n");
fprintf(f,
" %s(value, data->%s, strlen(data->%s) + 1);\n",
string_copy_func,
dp->dnaname,
dp->dnaname);
fprintf(f, " strcpy(value, data->%s);\n", dp->dnaname);
}
else {
/* Handle char array properties. */
#ifndef NDEBUG /* Assert lengths never exit their maximum expected value. */
if (sprop->maxlength) {
fprintf(f,
" %s(value, data->%s, %d);\n",
string_copy_func,
dp->dnaname,
sprop->maxlength);
fprintf(f, " BLI_assert(strlen(data->%s) < %d);\n", dp->dnaname, sprop->maxlength);
}
else {
fprintf(f,
" %s(value, data->%s, sizeof(data->%s));\n",
string_copy_func,
" BLI_assert(strlen(data->%s) < sizeof(data->%s));\n",
dp->dnaname,
dp->dnaname);
}
#endif
fprintf(f, " strcpy(value, data->%s);\n", dp->dnaname);
}
}
fprintf(f, "}\n\n");

View File

@ -26,6 +26,10 @@ if(HAVE_FEENABLEEXCEPT)
add_definitions(-DHAVE_FEENABLEEXCEPT)
endif()
if(WITH_STRSIZE_DEBUG)
add_definitions(-DDEBUG_STRSIZE)
endif()
if(WITH_TBB)
# Force TBB libraries to be in front of MKL (part of `OpenImageDenoise`), so
# that it is initialized before MKL and static library initialization order issues are avoided.