Skip to content

Report allocation failures in fixed size PayloadBuffers (2.1.6) - #29

Open
dallison wants to merge 1 commit into
mainfrom
asil
Open

dallison wants to merge 1 commit into
mainfrom
asil

Conversation

@dallison

@dallison dallison commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Summary

A fixed size PayloadBuffer that runs out of space now reports the failure and keeps its existing contents. Phaser uses this to build messages in caller-provided buffers without writing past their end.

  • Allocate, Realloc, SetString, AllocateMainMessage and NewMessage return nullptr. AllocateString returns an empty span. AllocateMetadata, VectorPush, VectorReserve and VectorResize return false.
  • The magic word records the failure in kAllocationFailedFlag, which AllocationFailed() reports. IsValidMagic and IsMoveable ignore the flag. Readers that check the magic with kBitMapMask see the buffer as invalid.
  • A small block that has no room for a new bitmap run comes from the free list, so small fixed buffers can use all of their space.
  • VectorResize sets the elements it adds to zero. Before this change, previously reserved capacity and elements removed by shrinking kept stale values.

Version 2.1.6.

Testing

  • bazelisk test //...: all tests pass, including new payload_buffer_test cases for exhausted buffers, the free-list fallback (SmallBlockUsesFreeListWhenRunDoesNotFit) and zeroing on resize (VectorResizeZeroesNewElements).
  • Built and tested through phaser and Subspace with Bazel and CMake.

A fixed size buffer that runs out of space now reports it and keeps its
existing contents:

- Allocate, Realloc, SetString, AllocateMainMessage and NewMessage return
  nullptr, AllocateString returns an empty span, and AllocateMetadata,
  VectorPush, VectorReserve and VectorResize return false.
- The magic word records the failure in kAllocationFailedFlag, reported by
  AllocationFailed().  IsValidMagic and IsMoveable ignore the flag, and
  readers that check the magic with kBitMapMask see the buffer as invalid.
- A small block that has no room for a new bitmap run comes from the free
  list, so small fixed buffers can use all of their space.
- VectorResize sets the elements it adds to zero.  Previously reserved
  capacity and elements removed by shrinking kept stale values.
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