Skip to content

bbruntime: per-BlitzType release dispatch (re-enables testEmbeddedLists)#56

Merged
CoreyRDean merged 1 commit into
developfrom
fix/per-blitztype-release-dispatch
May 24, 2026
Merged

bbruntime: per-BlitzType release dispatch (re-enables testEmbeddedLists)#56
CoreyRDean merged 1 commit into
developfrom
fix/per-blitztype-release-dispatch

Conversation

@CoreyRDean
Copy link
Copy Markdown
Collaborator

Summary

Closes the long-standing deferred finding: reference_map stored only a refcount, and _bbRelease(ptr, label) trusted the caller-supplied label for the destructor dispatch:

if (label == "BBCustom") _bbObjDelete(ptr as BBObj*);
else if (label == "BBList") _bbVectorFree(ptr);

_bbVectorRelease (fired when an element is removed from a BBList, or when an outer list iterates its elements during _bbVectorFree) hardcoded the label as "BBCustom" — it had no way to recover the element's static type once it lived as an int inside std::vector<int>. So:

  • For BBObj-only lists (the common case) it worked.
  • For lists holding inner BBLists, the outer free called _bbRelease(innerPtr, "BBCustom"). Refcount hit zero, dispatch ran _bbObjDelete on a std::vector<int>* — read+write into arbitrary heap. testEmbeddedLists was disabled because of this.

Change

  • reference_map becomes map<int, RefSlot> where RefSlot { int count; const char *type; } — the type label is a const char* to a static literal (never copied, never freed).
  • New _bbReferenceTyped(ptr, type) runtime helper for sites that know the static type at registration time.
  • _bbNewVector stamps "BBList" at creation via _bbReferenceTyped.
  • _bbRelease prefers the stamped type when present and falls back to the caller's label otherwise — BBObj entries that never went through _bbReferenceTyped keep working with the codegen's "BBCustom" label.

Test plan

  • Re-enabled testEmbeddedLists in tests/ListTest.bb.
  • Full BlitzForge test.bat suite passes (all 14 .bb test files).
  • rcce2 test.bat (the consumer's server-module suite) passes against this build.
  • CI build + macOS smoke.

🤖 Generated with Claude Code

reference_map stored only a refcount, and `_bbRelease(ptr, label)`
trusted the caller-supplied label for the destructor dispatch:

   if (label == "BBCustom") _bbObjDelete(ptr as BBObj*)
   else if (label == "BBList") _bbVectorFree(ptr)

`_bbVectorRelease` (called when an element is removed from a BBList,
or when an outer list iterates its elements during _bbVectorFree)
hardcoded the label as "BBCustom" because it had no way to recover
the static type after the value went through the type-erased
`std::vector<int>`. So:

  - For BBObj-only lists (the common case) it worked.
  - For lists holding inner BBLists, the outer free called
    _bbRelease(innerPtr, "BBCustom"), refcount hit zero, dispatch
    ran _bbObjDelete on a `std::vector<int>*` -- read+write into
    arbitrary heap. testEmbeddedLists was disabled because of this.

Change reference_map to `map<int, RefSlot>` where RefSlot carries
both count and a const-char* type label stamped at object-creation
time. Add `_bbReferenceTyped(ptr, type)` for sites that know the
static type at registration; `_bbNewVector` now calls it with "BBList".
`_bbRelease` uses the stamped type when present, falls back to the
caller's label otherwise -- BBObj entries that never went through
`_bbReferenceTyped` keep working with the codegen's "BBCustom" label.

Re-enables testEmbeddedLists; full BlitzForge suite + rcce2 server-
module tests pass against this build.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CoreyRDean CoreyRDean requested a review from a team as a code owner May 24, 2026 23:18
@CoreyRDean CoreyRDean merged commit 927760a into develop May 24, 2026
4 checks passed
@CoreyRDean CoreyRDean deleted the fix/per-blitztype-release-dispatch branch May 24, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant