Preserve circular buffer item semantics - #93
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the circular buffer implementation so that operations consistently treat the underlying storage as item-sized records (not bytes), improving correctness for non-item_size == 1 buffers while keeping FIFO behavior unchanged.
Changes:
- Added input validation in
circular_buffer_push/circular_buffer_getto ignore invalid buffer/item pointers and zero-sized configurations. - Fixed indexed removal (
circular_buffer_pop) to shift whole items to preserve item semantics. - Fixed iteration to pass item-aligned pointers to callbacks.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
59bfc5f to
ab1fb35
Compare
|
Minor, the commit title "Circular buffer: Remove indexed items" doesn't make much sense, could you improve it? Besides that looks good now. |
ab1fb35 to
2cd1ed0
Compare
|
should be all set now. sorry about the amount of churn, doing my best |
|
No worries, thanks for the patience, I think it's good to maintain a readable history. FWIW I prefer a bit more descriptive commit titles overall (not too much though), but this is good enough 😁 |
Fix two independent circular-buffer behaviors.
circular_buffer_iterate()previously used an item index as a byte offset. For buffers containing multi-byte records, callbacks after the first could therefore receive pointers inside another record. The index is now multiplied byitem_sizeso each callback receives a complete item. This fixes the experimental recorder plotting path, which iterates overSamplerecords.Following review feedback,
circular_buffer_pop()now implements a conventional FIFO pop: its unused index argument was removed, it copies the item at the tail, and then advances the tail. There are currently no callers requiring migration.The defensive argument guards and indexed-item shifting from earlier revisions were removed following review feedback.