summaryrefslogtreecommitdiff
path: root/python/renderlayer.py
diff options
context:
space:
mode:
authorMark Rowe <mark@vector35.com>2025-07-07 22:25:22 -0700
committerMark Rowe <mark@vector35.com>2025-07-08 23:32:41 -0700
commitf628cc695c680469c441394511a72b3b3912dd7f (patch)
tree75979a44e4506170043b38693bf304866576ce12 /python/renderlayer.py
parent3228382c8f96a162d34dd20ce6f7ba0f235c179a (diff)
[ObjC] Avoid leaking SymbolQueue
`SymbolQueue`'s lifetime was being managed via `new` / `delete`. This was error-prone in the face of code that can a) throw exceptions, or b) return early. Typically the solution would be to move to `std::unique_ptr` and call it a day, but nothing is ever easy. The `SymbolQueue`s created by `ObjCProcessor` are intended to live for the duration of `ProcessObjCData` and `ProcessCFStrings` methods. Since they are used multiple levels down the call tree, the active `SymbolQueue` is stored as a member variable on `ObjCProcessor`. Switching to `std::unique_ptr` would ensure that the `SymbolQueue` is destroyed, but would leave a dangling pointer in the member variable. To address this I'm introducing a `ScopedSingleton` class that provides a thread-local singleton whose lifetime is controlled by a guard object. `ProcessObjCData` / `ProcessCFStrings` call `ScopedSymbolQueue::Make` and store the returned guard object in a local. Code that accesses the symbol queue uses `ScopedSymbolQueue::Get` to retrieve the current instance. The guard object ensures the `SymbolQueue` is deleted and the `current` pointer is cleared no matter how the scope is exited. A better longer-term design is to introduce a class for processing the Objective-C runtime metadata and a class for processing constants such as `CFString`s. These could directly own the symbol queue so it would be accessible to any member functions that define symbols. This is a more involved refactoring than I have time for right now.
Diffstat (limited to 'python/renderlayer.py')
0 files changed, 0 insertions, 0 deletions