Skip to content

io_buffer: Reimplement dcompact for IO::Buffer#13033

Merged
byroot merged 2 commits intoruby:masterfrom
hanazuki:io-buffer-compaction
Jun 17, 2025
Merged

io_buffer: Reimplement dcompact for IO::Buffer#13033
byroot merged 2 commits intoruby:masterfrom
hanazuki:io-buffer-compaction

Conversation

@hanazuki
Copy link
Contributor

@hanazuki hanazuki commented Apr 1, 2025

Proposed patch for [Bug #21210]

@hanazuki hanazuki force-pushed the io-buffer-compaction branch from c727a32 to a2847dc Compare April 1, 2025 20:15
@launchable-app

This comment has been minimized.

The `source` field in IO::Buffer can have a String or an IO::Buffer
object, if not nil.

- When the `source` is a String object. The `base` field points to the
  memory location of the String content, which can be embedded in
  RSTRING, and in that case, GC compaction can move the memory region
  along with the String object.

  Thus, IO::Buffer needs to pin the `source` object to prevent `base`
  pointer from becoming invalid.

- When the `source` is an IO::Buffer, then `base` is a pointer to a
  malloced or mmapped memory region, managed by the source IO::Buffer.
  In this case, we don't need to pin the source IO::Buffer object,
  since the referred memory region won't get moved by GC.

Closes: [Bug #21210]
@hanazuki hanazuki force-pushed the io-buffer-compaction branch from a2847dc to b3a47c2 Compare April 1, 2025 20:49
@byroot
Copy link
Member

byroot commented Jun 17, 2025

FYI @eightbitraptor I'll merge this given it's a bug.

@byroot byroot merged commit 8aac19d into ruby:master Jun 17, 2025
74 of 75 checks passed
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.

2 participants