Extended interface for IO::Buffer & documentation.

This commit is contained in:
Samuel Williams 2021-12-22 10:57:34 +13:00 committed by GitHub
parent b86a7ba492
commit e30920354f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
Notes: git 2021-12-22 06:58:08 +09:00
Merged: https://github.com/ruby/ruby/pull/5314

Merged-By: ioquatix <samuel@codeotaku.com>
5 changed files with 765 additions and 86 deletions

View File

@ -7586,6 +7586,7 @@ io_buffer.$(OBJEXT): {$(VPATH)}config.h
io_buffer.$(OBJEXT): {$(VPATH)}defines.h
io_buffer.$(OBJEXT): {$(VPATH)}encoding.h
io_buffer.$(OBJEXT): {$(VPATH)}intern.h
io_buffer.$(OBJEXT): {$(VPATH)}internal.h
io_buffer.$(OBJEXT): {$(VPATH)}internal/anyargs.h
io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic.h
io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/char.h

View File

@ -69,12 +69,12 @@ VALUE rb_io_buffer_map(VALUE io, size_t size, off_t offset, enum rb_io_buffer_fl
VALUE rb_io_buffer_lock(VALUE self);
VALUE rb_io_buffer_unlock(VALUE self);
int rb_io_buffer_try_unlock(VALUE self);
VALUE rb_io_buffer_free(VALUE self);
int rb_io_buffer_readonly_p(VALUE self);
void rb_io_buffer_get(VALUE self, void **base, size_t *size);
void rb_io_buffer_get_readonly(VALUE self, const void **base, size_t *size);
int rb_io_buffer_get_bytes(VALUE self, void **base, size_t *size);
void rb_io_buffer_get_bytes_for_reading(VALUE self, const void **base, size_t *size);
void rb_io_buffer_get_bytes_for_writing(VALUE self, void **base, size_t *size);
VALUE rb_io_buffer_transfer(VALUE self);
void rb_io_buffer_resize(VALUE self, size_t size);

File diff suppressed because it is too large Load Diff

View File

@ -60,17 +60,17 @@ class TestIOBuffer < Test::Unit::TestCase
buffer = IO::Buffer.new(128, IO::Buffer::INTERNAL|IO::Buffer::READONLY)
assert buffer.readonly?
assert_raise IO::Buffer::MutationError do
assert_raise IO::Buffer::AccessError do
buffer.set_string("")
end
assert_raise IO::Buffer::MutationError do
assert_raise IO::Buffer::AccessError do
buffer.set_string("!", 1)
end
end
def test_file_mapped
buffer = File.open(__FILE__) {|file| IO::Buffer.map(file)}
buffer = File.open(__FILE__) {|file| IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)}
contents = buffer.get_string
assert_include contents, "Hello World"

20
update.rb Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env ruby
RESULT = / * #(.*?)/
CODE = / * (.*?)/
ARGV.each do |path|
lines = File.readlines(path)
lines.each do |line|
if line =~ /\/\*/
last = nil
elsif match = line.match(RESULT)
line.replace(" * \# => #{last}")
elsif match = line.match(CODE)
last = eval(match[1])
end
end
puts lines
end