Cleanup: BLI: Delete r-value iterator from Map #129880

Merged
Jacques Lucke merged 3 commits from mod_moder/blender:fix_map_r_value_iterator into main 2024-11-14 10:55:08 +01:00

Map iterators cannot extend lifetime of the Map. For this reason, temporal Map will might be deleted while its iterator is used.

With this change, such code will cause such error:

static Map<int, int> data()
{
  return {};
}

...
  for (const auto item : data().keys()) {
    printf("AAA\n");
  }
error C2280: 'blender::Map<int,int,4,blender::DefaultProbingStrategy,blender::DefaultHash<int32_t>,blender::DefaultEquality<Key>,blender::SimpleMapSlot<Key,Value>,blender::GuardedAllocator>::KeyIterator blender::Map<Key,Value,4,blender::DefaultProbingStrategy,blender::DefaultHash<int32_t>,blender::DefaultEquality<Key>,blender::SimpleMapSlot<Key,Value>,blender::GuardedAllocator>::keys(void) &&': attempting to reference a deleted function
        with
        [
            Key=int,
            Value=int
        ]
F:\Blender_build\first\blender\source\blender\blenlib\BLI_map.hh(842): note: see declaration of 'blender::Map<int,int,4,blender::DefaultProbingStrategy,blender::DefaultHash<int32_t>,blender::DefaultEquality<Key>,blender::SimpleMapSlot<Key,Value>,blender::GuardedAllocator>::keys'
        with
        [
            Key=int,
            Value=int
        ]
F:\Blender_build\first\blender\source\blender\blenlib\BLI_map.hh(842): note: 'blender::Map<int,int,4,blender::DefaultProbingStrategy,blender::DefaultHash<int32_t>,blender::DefaultEquality<Key>,blender::SimpleMapSlot<Key,Value>,blender::GuardedAllocator>::KeyIterator blender::Map<Key,Value,4,blender::DefaultProbingStrategy,blender::DefaultHash<int32_t>,blender::DefaultEquality<Key>,blender::SimpleMapSlot<Key,Value>,blender::GuardedAllocator>::keys(void) &&': function was explicitly deleted
        with
        [
            Key=int,
            Value=int
        ]
Map iterators cannot extend lifetime of the Map. For this reason, temporal Map will might be deleted while its iterator is used. With this change, such code will cause such error: ```Cpp static Map<int, int> data() { return {}; } ... for (const auto item : data().keys()) { printf("AAA\n"); } ``` ``` error C2280: 'blender::Map<int,int,4,blender::DefaultProbingStrategy,blender::DefaultHash<int32_t>,blender::DefaultEquality<Key>,blender::SimpleMapSlot<Key,Value>,blender::GuardedAllocator>::KeyIterator blender::Map<Key,Value,4,blender::DefaultProbingStrategy,blender::DefaultHash<int32_t>,blender::DefaultEquality<Key>,blender::SimpleMapSlot<Key,Value>,blender::GuardedAllocator>::keys(void) &&': attempting to reference a deleted function with [ Key=int, Value=int ] F:\Blender_build\first\blender\source\blender\blenlib\BLI_map.hh(842): note: see declaration of 'blender::Map<int,int,4,blender::DefaultProbingStrategy,blender::DefaultHash<int32_t>,blender::DefaultEquality<Key>,blender::SimpleMapSlot<Key,Value>,blender::GuardedAllocator>::keys' with [ Key=int, Value=int ] F:\Blender_build\first\blender\source\blender\blenlib\BLI_map.hh(842): note: 'blender::Map<int,int,4,blender::DefaultProbingStrategy,blender::DefaultHash<int32_t>,blender::DefaultEquality<Key>,blender::SimpleMapSlot<Key,Value>,blender::GuardedAllocator>::KeyIterator blender::Map<Key,Value,4,blender::DefaultProbingStrategy,blender::DefaultHash<int32_t>,blender::DefaultEquality<Key>,blender::SimpleMapSlot<Key,Value>,blender::GuardedAllocator>::keys(void) &&': function was explicitly deleted with [ Key=int, Value=int ] ```
Iliya Katushenock added 1 commit 2024-11-05 20:43:45 +01:00
Iliya Katushenock added this to the Module: Core project 2024-11-05 20:43:49 +01:00
Iliya Katushenock requested review from Jacques Lucke 2024-11-05 20:43:56 +01:00
Member

It's tricky because there are cases where it's fine, Just with range-based for loops it doesn't work, because the lifetime of the Map is not extended. I did hear somewhere that this will be changed at some point, but not sure right now.

Overall seems reasonable. It seems like this patch mixes cleanup with bug fixes.

It's tricky because there are cases where it's fine, Just with range-based for loops it doesn't work, because the lifetime of the Map is not extended. I did hear somewhere that this will be changed at some point, but not sure right now. Overall seems reasonable. It seems like this patch mixes cleanup with bug fixes.
Iliya Katushenock added 1 commit 2024-11-09 20:45:20 +01:00
Author
Member

Cleaned up that\

Cleaned up that\
Jacques Lucke added 1 commit 2024-11-13 17:57:20 +01:00
improve comment
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
1566617a17
Member

@blender-bot build

@blender-bot build
Jacques Lucke merged commit 65abb1ef93 into main 2024-11-14 10:55:08 +01:00
Iliya Katushenock deleted branch fix_map_r_value_iterator 2024-11-14 11:15:19 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
FBX
Interest
Freestyle
Interest
Geometry Nodes
Interest
glTF
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#129880
No description provided.