Repository navigation
Commit 415efad
io: IO::Buffer transfer/locked/bitwise-bang + IO#advise (core/io +59) (#600)
* io: IO::Buffer transfer/locked/bitwise-bang/for-writability + size validation (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>
* io: IO#advise as a validated no-op (core/io advise_spec 0->13)
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>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 94c8a1e commit 415efad
4 files changed
Lines changed: 345 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
816 | 816 | | |
817 | 817 | | |
818 | 818 | | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
819 | 849 | | |
820 | 850 | | |
821 | 851 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
0 commit comments