mirror of
https://github.com/KhronosGroup/Vulkan-Utility-Libraries.git
synced 2025-05-15 01:08:39 +00:00
safe_struct: Make FreePnextChain() non-recursive
This commit is contained in:
parent
741921e408
commit
07759f0479
2 changed files with 612 additions and 616 deletions
|
@ -330,20 +330,23 @@ void *SafePnextCopy(const void *pNext, PNextCopyState* copy_state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreePnextChain(const void *pNext) {
|
void FreePnextChain(const void *pNext) {
|
||||||
if (!pNext) return;
|
// The pNext parameter is const for convenience, since it is called by code
|
||||||
|
// for many structures where the pNext field is const.
|
||||||
|
void *current = const_cast<void*>(pNext);
|
||||||
|
while (current) {
|
||||||
|
auto header = reinterpret_cast<VkBaseOutStructure *>(current);
|
||||||
|
void *next = header->pNext;
|
||||||
|
// prevent destructors from recursing behind our backs.
|
||||||
|
header->pNext = nullptr;
|
||||||
|
|
||||||
auto header = reinterpret_cast<const VkBaseOutStructure *>(pNext);
|
switch (header->sType) {
|
||||||
|
// Special-case Loader Instance Struct passed to/from layer in pNext chain
|
||||||
switch (header->sType) {
|
|
||||||
// Special-case Loader Instance Struct passed to/from layer in pNext chain
|
|
||||||
case VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO:
|
case VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO:
|
||||||
FreePnextChain(header->pNext);
|
delete reinterpret_cast<VkLayerInstanceCreateInfo *>(current);
|
||||||
delete reinterpret_cast<const VkLayerInstanceCreateInfo *>(pNext);
|
|
||||||
break;
|
break;
|
||||||
// Special-case Loader Device Struct passed to/from layer in pNext chain
|
// Special-case Loader Device Struct passed to/from layer in pNext chain
|
||||||
case VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO:
|
case VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO:
|
||||||
FreePnextChain(header->pNext);
|
delete reinterpret_cast<VkLayerDeviceCreateInfo *>(current);
|
||||||
delete reinterpret_cast<const VkLayerDeviceCreateInfo *>(pNext);
|
|
||||||
break;
|
break;
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
@ -351,7 +354,7 @@ void FreePnextChain(const void *pNext) {
|
||||||
safe_name = self.convertName(struct.name)
|
safe_name = self.convertName(struct.name)
|
||||||
out.extend(guard_helper.add_guard(struct.protect))
|
out.extend(guard_helper.add_guard(struct.protect))
|
||||||
out.append(f' case {struct.sType}:\n')
|
out.append(f' case {struct.sType}:\n')
|
||||||
out.append(f' delete reinterpret_cast<const {safe_name} *>(header);\n')
|
out.append(f' delete reinterpret_cast<{safe_name} *>(header);\n')
|
||||||
out.append(' break;\n')
|
out.append(' break;\n')
|
||||||
out.extend(guard_helper.add_guard(None))
|
out.extend(guard_helper.add_guard(None))
|
||||||
|
|
||||||
|
@ -360,18 +363,13 @@ void FreePnextChain(const void *pNext) {
|
||||||
// If sType is in custom list, free custom struct memory and clean up
|
// If sType is in custom list, free custom struct memory and clean up
|
||||||
for (auto item : custom_stype_info) {
|
for (auto item : custom_stype_info) {
|
||||||
if (item.first == static_cast<uint32_t>(header->sType)) {
|
if (item.first == static_cast<uint32_t>(header->sType)) {
|
||||||
if (header->pNext) {
|
free(current);
|
||||||
FreePnextChain(header->pNext);
|
|
||||||
}
|
|
||||||
free(const_cast<void *>(pNext));
|
|
||||||
pNext = nullptr;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pNext) {
|
|
||||||
FreePnextChain(header->pNext);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
current = next;
|
||||||
}
|
}
|
||||||
}''')
|
}''')
|
||||||
out.append('// clang-format on\n')
|
out.append('// clang-format on\n')
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue