Skip to content

Conversation

@runarorama
Copy link
Contributor

@runarorama runarorama commented Aug 16, 2025

This PR ties up loose ends in the implementation of several I/O buffer operations by adding proper length parameters and bounds checking, making them safer and more consistent with established patterns.

Namely:

  • Updated IO.fillBuf.impland IO.getBufSome.impl to accept a length parameter: Handle → PinnedByteArray g → Nat → {IO} Nat. Added bounds checking. This is to make these operations more flexible and useful in practice. I realized that making the primitive operations only ever completely fill the buffer makes it hard/dangerous to write abstractions on top of these.
  • Fixed withMutableByteArrayContents helper function to properly use PA.keepAlive with the mutable array instead of just its pointer. Using just the pointer is the same as doing nothing, since it is not a GC root.
  • Added comprehensive tests covering fillBuf, putBuf, and getBufSome operations.

@runarorama runarorama requested a review from dolio August 16, 2025 03:05
Copy link
Member

@pchiusano pchiusano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎👍

@runarorama runarorama merged commit 84a0aa9 into trunk Aug 16, 2025
31 checks passed
@runarorama runarorama deleted the runarorama/getBufBytes branch August 16, 2025 21:35
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.

3 participants