Repository navigation
io: IO::Buffer transfer/locked/bitwise-bang + IO#advise (core/io +59) - #600
Merged
Merged
Conversation
…lidation (core/io +46)
Advance IO::Buffer conformance against MRI 4.0.x. References read: MRI
io_buffer.c (io_buffer_transfer, io_buffer_locked, io_buffer_and/or/xor/not!,
io_buffer_for, io_buffer_initialize/resize, io_buffer_valid_p) and ruby/spec
core/io/buffer/{and,or,xor,not,transfer,locked,valid,resize,for,null,
initialize}_spec.rb. Every value below verified byte-for-byte against
ruby 4.0.5.
New / fixed:
- Exceptions IO::Buffer::LockedError / InvalidatedError / AllocationError
(all RuntimeError subclasses).
- In-place bitwise operators #and!/#or!/#xor!/#not! (mutate the receiver,
return self; AccessError on a read-only buffer). The binary &/|/^ argument
type error now reads "wrong argument type X (expected IO::Buffer)"
(nil/true/false lower-cased), matching MRI.
- #transfer: moves memory and kind (external/read-only/slice) to a fresh
buffer and nullifies the source; refused while locked with LockedError.
- #locked / #locked?: locks the buffer for the block, #resize and #transfer
raise LockedError inside, re-entry raises "Buffer already locked!"; the lock
does not propagate to or from slices.
- IO::Buffer.for over a *mutable* String (with a block) now aliases the
String's bytes and is writable (writes propagate); a frozen source or the
no-block form stays a read-only copy.
- .new / #resize size validation: non-Integer -> TypeError "not an Integer",
negative -> ArgumentError "Size can't be negative!"; #resize(0) frees the
buffer, and a freed external buffer may be re-grown into an internal one.
- #valid? now reports slice invalidation: a slice invalidates when its source
is freed, transferred, or resized out from under it, but a slice of a
String-backed buffer stays valid after the buffer is freed; operations on an
invalidated slice raise InvalidatedError "Buffer has been invalidated!".
core/io: pass 1090->1136, fail 180->168, error 159->125. Full whitebox
coverage (100% on io_buffer.go); go build/test ./..., wasip1 build, and
gofmt all clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Reference: MRI io.c rb_io_advise + advice_arg_check, and ruby/spec core/io/advise_spec.rb. rbgo has no posix_fadvise (as MRI on a platform without it), so #advise validates its arguments and returns nil. Checks, in MRI's order and verified byte-for-byte against ruby 4.0.5 on darwin: - a non-Symbol advice raises TypeError "advice must be a Symbol"; - an unrecognized advice raises NotImplementedError "Unsupported advice: :sym" (recognized: :normal :sequential :random :willneed :dontneed :noreuse); - a closed stream raises IOError "closed stream"; - offset and len are coerced as off_t (reusing ioOfftArg): a non-Integer raises TypeError, a too-large Bignum RangeError; - wrong arity (0 or >3 args) raises ArgumentError. advise_spec: 13 examples now all pass (was 6 error + 7 fail). Whitebox test covers every branch; io.go stays at 100% coverage, gofmt clean, wasip1 builds. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 8, 2026
…602) Wave-21 merged three bibliography-first conformance PRs: - #600 core/io: IO::Buffer transfer/locked/and!/or!/xor!/not!/for/resize/valid?, IO#advise validated no-op — +59. - #601 core/file+dir: File.lutime, File.utime nil (UTIME_NOW), Dir.chroot — +10. - #599 core/kernel: Kernel#loop StopIteration rescue + infinite Enumerator, Kernel#fail alias of raise — +7. Measured total on merged main: 19993 passing. Local measure at TIMEOUT=25; CI runs TIMEOUT=60 so its total is >= this floor. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wave-21 IO conformance against MRI Ruby 4.0.x. Two self-contained clusters in the IO layer, each verified byte-for-byte against
ruby 4.0.5and backed by whitebox tests at 100% coverage.IO::Buffer (
internal/vm/io_buffer.go)References: MRI
io_buffer.c(io_buffer_transfer,io_buffer_locked,io_buffer_and/or/xor/not!,io_buffer_for,io_buffer_initialize/resize,io_buffer_valid_p) andruby/speccore/io/buffer/{and,or,xor,not,transfer,locked,valid,resize,for,null,initialize}_spec.rb.IO::Buffer::LockedError/InvalidatedError/AllocationError(RuntimeError subclasses).#and!/#or!/#xor!/#not!(mutate the receiver, return self;AccessErroron a read-only buffer). The binary&/|/^argument-type error now readswrong argument type X (expected IO::Buffer)(nil/true/false lower-cased), matching MRI.#transfer: moves memory and kind (external/read-only/slice) to a fresh buffer and nullifies the source; refused while locked.#locked/#locked?: locks the buffer for the block;#resize/#transferraiseLockedErrorinside, re-entry raisesBuffer already locked!; the lock does not propagate to or from slices.IO::Buffer.forover a mutable String (with a block) now aliases the String's bytes and is writable; a frozen source or the no-block form stays a read-only copy..new/#resizesize validation: non-Integer ->TypeError "not an Integer", negative ->ArgumentError "Size can't be negative!";#resize(0)frees the buffer, and a freed external buffer may be re-grown.#valid?now reports slice invalidation (freed/transferred/resized-out source), while a slice of a String-backed buffer stays valid after the buffer is freed; operations on an invalidated slice raiseInvalidatedError "Buffer has been invalidated!".IO#advise (
internal/vm/io.go)References: MRI
io.crb_io_advise+advice_arg_check,ruby/speccore/io/advise_spec.rb. rbgo has noposix_fadvise(as MRI on a platform without it), so#advisevalidates its arguments and returns nil: non-Symbol ->TypeError; unrecognized ->NotImplementedError "Unsupported advice: :sym"; closed stream ->IOError; offset/len coerced as off_t (TypeError/RangeError); wrong arity ->ArgumentError.advise_specgoes 0 -> 13.Measured delta (core/io ruby/spec)
Gates
go build ./...andGOWORK=off go test ./...green (pre-existing 127.0.0.1:1 network tests excluded).io_buffer.goandio.go(go tool cover -funcshows nothing below 100 introduced).gofmt -l internal/vm/empty; wasip1 build clean.io.go,io_buffer.go) plus new_test.go; FLOOR untouched.🤖 Generated with Claude Code