Skip to content

Commit

Permalink
Merge remote-tracking branch 'b/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
youle31 committed Apr 16, 2024
2 parents 44d4c37 + 3d59514 commit dc7f39d
Show file tree
Hide file tree
Showing 115 changed files with 1,941 additions and 1,118 deletions.
12 changes: 9 additions & 3 deletions build_files/cmake/cmake_static_check_cppcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,21 @@ def cppcheck_generate_summary(
source_dir_source = os.path.join(source_dir, "source") + os.sep
source_dir_intern = os.path.join(source_dir, "intern") + os.sep

filter_line_prefix = (source_dir_source, source_dir_intern)

source_dir_prefix_len = len(source_dir.rstrip(os.sep))

# Avoids many duplicate lines generated by headers.
lines_unique = set()

category: Dict[str, List[str]] = {}
re_match = re.compile(".* \\[([a-zA-Z_]+)\\]")
re_match = re.compile(".* \\[([a-zA-Z_]+)\\]$")
for line in log_fh:
if not ((source_dir_source in line) or (source_dir_intern in line)):
if not line.startswith(filter_line_prefix):
continue

# Print a relative directory from `SOURCE_DIR`,
# less visual noise and makes it possible to compare reports from different systems.
line = "." + line[source_dir_prefix_len:]
if (m := re_match.match(line)) is None:
continue
g = m.group(1)
Expand Down
31 changes: 20 additions & 11 deletions intern/guardedalloc/MEM_guardedalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ extern size_t (*MEM_get_peak_memory)(void) ATTR_WARN_UNUSED_RESULT;
} while (0)
#endif

/* overhead for lockfree allocator (use to avoid slop-space) */
/** Overhead for lockfree allocator (use to avoid slop-space). */
#define MEM_SIZE_OVERHEAD sizeof(size_t)
#define MEM_SIZE_OPTIMAL(size) ((size)-MEM_SIZE_OVERHEAD)

Expand Down Expand Up @@ -242,22 +242,26 @@ void MEM_use_memleak_detection(bool enabled);
*/
void MEM_enable_fail_on_memleak(void);

/* Switch allocator to fast mode, with less tracking.
/**
* Switch allocator to fast mode, with less tracking.
*
* Use in the production code where performance is the priority, and exact details about allocation
* is not. This allocator keeps track of number of allocation and amount of allocated bytes, but it
* does not track of names of allocated blocks.
*
* NOTE: The switch between allocator types can only happen before any allocation did happen. */
* \note The switch between allocator types can only happen before any allocation did happen.
*/
void MEM_use_lockfree_allocator(void);

/* Switch allocator to slow fully guarded mode.
/**
* Switch allocator to slow fully guarded mode.
*
* Use for debug purposes. This allocator contains lock section around every allocator call, which
* makes it slow. What is gained with this is the ability to have list of allocated blocks (in an
* addition to the tracking of number of allocations and amount of allocated bytes).
*
* NOTE: The switch between allocator types can only happen before any allocation did happen. */
* \note The switch between allocator types can only happen before any allocation did happen.
*/
void MEM_use_guarded_allocator(void);

#ifdef __cplusplus
Expand All @@ -270,9 +274,11 @@ void MEM_use_guarded_allocator(void);
# include <type_traits>
# include <utility>

/* Conservative value of memory alignment returned by non-aligned OS-level memory allocation
/**
* Conservative value of memory alignment returned by non-aligned OS-level memory allocation
* functions. For alignments smaller than this value, using non-aligned versions of allocator API
* functions is okay, allowing use of calloc, for example. */
* functions is okay, allowing use of `calloc`, for example.
*/
# define MEM_MIN_CPP_ALIGNMENT \
(__STDCPP_DEFAULT_NEW_ALIGNMENT__ < alignof(void *) ? __STDCPP_DEFAULT_NEW_ALIGNMENT__ : \
alignof(void *))
Expand Down Expand Up @@ -307,7 +313,7 @@ template<typename T> inline void MEM_delete(const T *ptr)
/* Support #ptr being null, because C++ `delete` supports that as well. */
return;
}
/* C++ allows destruction of const objects, so the pointer is allowed to be const. */
/* C++ allows destruction of `const` objects, so the pointer is allowed to be `const`. */
ptr->~T();
MEM_freeN(const_cast<T *>(ptr));
}
Expand Down Expand Up @@ -354,7 +360,7 @@ template<typename T> inline T *MEM_cnew(const char *allocation_name, const T &ot
return new_object;
}

/* Allocation functions (for C++ only). */
/** Allocation functions (for C++ only). */
# define MEM_CXX_CLASS_ALLOC_FUNCS(_id) \
public: \
void *operator new(size_t num_bytes) \
Expand Down Expand Up @@ -389,8 +395,11 @@ template<typename T> inline T *MEM_cnew(const char *allocation_name, const T &ot
{ \
return ptr; \
} \
/* This is the matching delete operator to the placement-new operator above. Both parameters \
* will have the same value. Without this, we get the warning C4291 on windows. */ \
/** \
* This is the matching delete operator to the placement-new operator above. \
* Both parameters \
* will have the same value. Without this, we get the warning C4291 on windows. \
*/ \
void operator delete(void * /*ptr_to_free*/, void * /*ptr*/) {}

#endif /* __cplusplus */
Expand Down
15 changes: 10 additions & 5 deletions intern/guardedalloc/intern/mallocn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@

#include "MEM_guardedalloc.h"

/* to ensure strict conversions */
/* To ensure strict conversions. */
#include "../../source/blender/blenlib/BLI_strict_flags.h"

#include <cassert>

#include "mallocn_intern.h"

#ifdef WITH_JEMALLOC_CONF
/* If JEMALLOC is used, it reads this global variable and enables background
/**
* If JEMALLOC is used, it reads this global variable and enables background
* threads to purge dirty pages. Otherwise we release memory too slowly or not
* at all if the thread that did the allocation stays inactive. */
* at all if the thread that did the allocation stays inactive.
*/
const char *malloc_conf =
"background_thread:true,dirty_decay_ms:4000,thp:always,metadata_thp:always";
#endif

/* NOTE: Keep in sync with MEM_use_lockfree_allocator(). */

size_t (*MEM_allocN_len)(const void *vmemh) = MEM_lockfree_allocN_len;
void (*MEM_freeN)(void *vmemh) = MEM_lockfree_freeN;
void *(*MEM_dupallocN)(const void *vmemh) = MEM_lockfree_dupallocN;
Expand Down Expand Up @@ -92,10 +95,12 @@ void aligned_free(void *ptr)
#endif
}

/* Perform assert checks on allocator type change.
/**
* Perform assert checks on allocator type change.
*
* Helps catching issues (in debug build) caused by an unintended allocator type change when there
* are allocation happened. */
* are allocation happened.
*/
static void assert_for_allocator_change(void)
{
/* NOTE: Assume that there is no "sticky" internal state which would make switching allocator
Expand Down
4 changes: 2 additions & 2 deletions intern/guardedalloc/intern/memory_usage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ size_t memory_usage_block_num()

/* Count the number of active blocks. */
int64_t blocks_num = global.blocks_num_outside_locals;
for (Local *local : global.locals) {
for (const Local *local : global.locals) {
blocks_num += local->blocks_num;
}
return size_t(blocks_num);
Expand All @@ -246,7 +246,7 @@ size_t memory_usage_current()

/* Count the memory that's currently in use. */
int64_t mem_in_use = global.mem_in_use_outside_locals;
for (Local *local : global.locals) {
for (const Local *local : global.locals) {
mem_in_use += local->mem_in_use;
}
return size_t(mem_in_use);
Expand Down
32 changes: 17 additions & 15 deletions scripts/startup/bl_operators/anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ class ANIM_OT_keying_set_export(Operator):
)

def execute(self, context):
from bpy.utils import escape_identifier

if not self.filepath:
raise Exception("Filepath not set")

f = open(self.filepath, "w")
f = open(self.filepath, "w", encoding="utf8")
if not f:
raise Exception("Could not open file")

Expand All @@ -61,16 +63,16 @@ def execute(self, context):

# Add KeyingSet and set general settings
f.write("# Keying Set Level declarations\n")
f.write("ks = scene.keying_sets.new(idname=\"%s\", name=\"%s\")\n"
"" % (ks.bl_idname, ks.bl_label))
f.write("ks = scene.keying_sets.new(idname=%r, name=%r)\n" % (ks.bl_idname, ks.bl_label))
f.write("ks.bl_description = %r\n" % ks.bl_description)

if not ks.is_path_absolute:
f.write("ks.is_path_absolute = False\n")
# TODO: this isn't editable, it should be possible to set this flag for `scene.keying_sets.new`.
# if not ks.is_path_absolute:
# f.write("ks.is_path_absolute = False\n")
f.write("\n")

f.write("ks.use_insertkey_needed = %s\n" % ks.use_insertkey_needed)
f.write("ks.use_insertkey_visual = %s\n" % ks.use_insertkey_visual)
f.write("ks.use_insertkey_needed = %r\n" % ks.use_insertkey_needed)
f.write("ks.use_insertkey_visual = %r\n" % ks.use_insertkey_visual)
f.write("\n")

# --------------------------------------------------------
Expand Down Expand Up @@ -99,14 +101,14 @@ def execute(self, context):

for mat in bpy.data.materials:
if mat.node_tree == ksp.id:
id_bpy_path = "bpy.data.materials[\"%s\"].node_tree" % (mat.name)
id_bpy_path = "bpy.data.materials[\"%s\"].node_tree" % escape_identifier(mat.name)
found = True
break

if not found:
for light in bpy.data.lights:
if light.node_tree == ksp.id:
id_bpy_path = "bpy.data.lights[\"%s\"].node_tree" % (light.name)
id_bpy_path = "bpy.data.lights[\"%s\"].node_tree" % escape_identifier(light.name)
found = True
break

Expand All @@ -119,16 +121,16 @@ def execute(self, context):
# Find compositor node-tree using this node tree.
for scene in bpy.data.scenes:
if scene.node_tree == ksp.id:
id_bpy_path = "bpy.data.scenes[\"%s\"].node_tree" % (scene.name)
id_bpy_path = "bpy.data.scenes[\"%s\"].node_tree" % escape_identifier(scene.name)
break
else:
self.report({'WARN'}, rpt_("Could not find scene using Compositor Node Tree - %s") % (ksp.id))
elif ksp.id.bl_rna.name == "Key":
# "keys" conflicts with a Python keyword, hence the simple solution won't work
id_bpy_path = "bpy.data.shape_keys[\"%s\"]" % (ksp.id.name)
id_bpy_path = "bpy.data.shape_keys[\"%s\"]" % escape_identifier(ksp.id.name)
else:
idtype_list = ksp.id.bl_rna.name.lower() + "s"
id_bpy_path = "bpy.data.%s[\"%s\"]" % (idtype_list, ksp.id.name)
id_bpy_path = "bpy.data.%s[\"%s\"]" % (idtype_list, escape_identifier(ksp.id.name))

# shorthand ID for the ID-block (as used in the script)
short_id = "id_%d" % len(id_to_paths_cache)
Expand All @@ -152,7 +154,7 @@ def execute(self, context):
id_bpy_path = id_to_paths_cache[ksp.id][0]
else:
id_bpy_path = "None" # XXX...
f.write("%s, '%s'" % (id_bpy_path, ksp.data_path))
f.write("%s, %r" % (id_bpy_path, ksp.data_path))

# array index settings (if applicable)
if ksp.use_entire_array:
Expand All @@ -164,10 +166,10 @@ def execute(self, context):
# NOTE: the current default is KEYINGSET, but if this changes,
# change this code too
if ksp.group_method == 'NAMED':
f.write(", group_method='%s', group_name=\"%s\"" %
f.write(", group_method=%r, group_name=%r" %
(ksp.group_method, ksp.group))
elif ksp.group_method != 'KEYINGSET':
f.write(", group_method='%s'" % ksp.group_method)
f.write(", group_method=%r" % ksp.group_method)

# finish off
f.write(")\n")
Expand Down
4 changes: 2 additions & 2 deletions scripts/startup/bl_ui/node_add_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
)


def add_node_type(layout, node_type, *, label=None, poll=None):
def add_node_type(layout, node_type, *, label=None, poll=None, search_weight=0.0):
"""Add a node type to a menu."""
bl_rna = bpy.types.Node.bl_rna_get_subclass(node_type)
if not label:
label = bl_rna.name if bl_rna else iface_("Unknown")

if poll is True or poll is None:
translation_context = bl_rna.translation_context if bl_rna else i18n_contexts.default
props = layout.operator("node.add_node", text=label, text_ctxt=translation_context)
props = layout.operator("node.add_node", text=label, text_ctxt=translation_context, search_weight=search_weight)
props.type = node_type
props.use_transform = True
return props
Expand Down
4 changes: 2 additions & 2 deletions scripts/startup/bl_ui/node_add_menu_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def draw(self, _context):
layout.menu("NODE_MT_geometry_node_GEO_GEOMETRY_OPERATIONS")
layout.separator()
node_add_menu.add_node_type(layout, "GeometryNodeGeometryToInstance")
node_add_menu.add_node_type(layout, "GeometryNodeJoinGeometry")
node_add_menu.add_node_type(layout, "GeometryNodeJoinGeometry", search_weight=1.0)
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)


Expand Down Expand Up @@ -216,7 +216,7 @@ def draw(self, _context):
node_add_menu.add_node_type(layout, "GeometryNodeDuplicateElements")
node_add_menu.add_node_type(layout, "GeometryNodeMergeByDistance")
node_add_menu.add_node_type(layout, "GeometryNodeSortElements")
node_add_menu.add_node_type(layout, "GeometryNodeTransform")
node_add_menu.add_node_type(layout, "GeometryNodeTransform", search_weight=1.0)
layout.separator()
node_add_menu.add_node_type(layout, "GeometryNodeSeparateComponents")
node_add_menu.add_node_type(layout, "GeometryNodeSeparateGeometry")
Expand Down

0 comments on commit dc7f39d

Please sign in to comment.