Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/check_misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ jobs:
- name: Check if date in man pages is up-to-date
run: |
git fetch origin --depth=1 "${GITHUB_OLD_SHA}"
git diff --exit-code --name-only "${GITHUB_OLD_SHA}" HEAD -- man ||
make V=1 GIT=git BASERUBY=ruby update-man-date
make V=1 GIT=git BASERUBY=ruby update-man-date \
MANPAGES_TO_UPDATE="$(git diff --exit-code --name-only "${GITHUB_OLD_SHA}" HEAD -- man)"
git diff --color --no-ext-diff --ignore-submodules --exit-code -- man
env:
GITHUB_OLD_SHA: ${{ github.event.pull_request.base.sha }}
Expand Down
11 changes: 8 additions & 3 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2029,9 +2029,14 @@ sudo-precheck: PHONY

update-man-date: PHONY
$(Q) $(BASERUBY) -I"$(tooldir)/lib" -rvcs -i -p \
-e 'BEGIN{@vcs=VCS.detect(ARGV.shift)}' \
-e '$$_.sub!(/^(\.Dd ).*/){$$1+@vcs.author_date(@vcs.relative_to(ARGF.path)).strftime("%B %d, %Y")}' \
"$(srcdir)" "$(srcdir)"/man/*.1
-C "$(srcdir)" \
-e 'BEGIN{@vcs=VCS.detect; ARGV.replace(Dir.glob(ARGV))}' \
-e '$$_.sub!(/^\.Dd \K.*/){' \
-e 'STDOUT.puts "Updating #{ARGF.path}"' \
-e '@vcs.author_date(@vcs.relative_to(ARGF.path)).strftime("%B %d, %Y")' \
-e '}' \
$(MANPAGES_TO_UPDATE)
MANPAGES_TO_UPDATE = man/*.1

.PHONY: ChangeLog
ChangeLog:
Expand Down
19 changes: 19 additions & 0 deletions ext/-test-/io_buffer/io_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,23 @@ io_buffer_free_locked(VALUE self, VALUE buffer)
return rb_io_buffer_free_locked(buffer);
}

static VALUE
io_buffer_get_bytes_flags(VALUE self, VALUE buffer)
{
void *base;
size_t size;
return UINT2NUM(rb_io_buffer_get_bytes(buffer, &base, &size));
}

static VALUE
io_buffer_get_bytes_address(VALUE self, VALUE buffer)
{
void *base;
size_t size;
rb_io_buffer_get_bytes(buffer, &base, &size);
return PTR2NUM(base);
}

void
Init_io_buffer(void)
{
Expand All @@ -229,4 +246,6 @@ Init_io_buffer(void)
rb_define_singleton_method(mIOBuffer, "unlock", io_buffer_unlock, 1);
rb_define_singleton_method(mIOBuffer, "new_locked", io_buffer_new_locked, 1);
rb_define_singleton_method(mIOBuffer, "free_locked", io_buffer_free_locked, 1);
rb_define_singleton_method(mIOBuffer, "get_bytes_flags", io_buffer_get_bytes_flags, 1);
rb_define_singleton_method(mIOBuffer, "get_bytes_address", io_buffer_get_bytes_address, 1);
}
98 changes: 70 additions & 28 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2401,39 +2401,53 @@ rb_file_file_p(VALUE obj, VALUE fname)
}

/*
* :markup: markdown

* call-seq:
* File.empty?(object) -> true or false
* File.zero?(object) -> true or false
* File.empty?(object) -> true or false
*
* Returns whether the given +object+ exists and has size zero.
* Returns whether the given `object` exists and has size zero.
*
* The given +object+ may be the path to a directory (possibly non-existent):
* The given `object` may be the path to a file:
*
* dirpath = 'foo'
* File.empty?(dirpath) # => false # Directory does not exist.
* dir = Dir.mkdir(dirpath)
* # The directory size is filesystem-dependent;
* # for a directory with no children, may or may not be zero.
* File.size(dirpath) # => 4096
* File.empty?(dirpath) # => false
* ```ruby
* filepath = '/tmp/t.tmp'
* File.write(filepath, 'foo') # File has non-zero size.
* File.zero?(filepath) # => false
* File.truncate(filepath, 0) # File has zero size.
* File.zero?(filepath) # => true
* File.delete(filepath) # Clean up.
* ```
*
* The given +object+ may be the path to a file (possibly non-existent):
* The given `object` may be the path to a directory:
*
* filepath = File.join(dirpath, 't.tmp')
* File.empty?(filepath) # => false # File does not exist.
* File.write(filepath, '')
* File.size(filepath) # => 0
* File.empty?(filepath) # => true # File exists; size zero.
* File.size(dirpath) # => 4096
* File.empty?(dirpath) # => false
* File.write(filepath, 'bar')
* File.size(filepath) # => 3
* File.empty?(filepath) # => false # File exists; size non-zero.
* FileUtils.rm_rf(dirpath) # Clean up.
* ```ruby
* dirpath = '/tmp/foo'
* Dir.mkdir(dirpath)
* Dir.new(dirpath).children.size # => 0
* # Size is filesystem-dependent; may or may not be zero.
* File.size(dirpath) # => 4096
* File.zero?(dirpath) # => false
* filepath = '/tmp/foo/t.tmp' # => "/tmp/foo/t.tmp"
* File.write(filepath, 'foo') # Add a child.
* Dir.new(dirpath).children.size # => 1
* File.size(dirpath) # => 4096
* File.zero?(dirpath) # => false
* FileUtils.rm_rf(dirpath) # Clean up.
* ```
*
* The given `object` may be an IO object:
*
* The given +object+ may be an IO object:
* ```ruby
* File.zero?($stdin) # => true
* ```
*
* File.empty?($stdin) # => true
* The given object may be none of the above:
*
* ```ruby
* File.zero?('nosuch') # => false
* ```
*
*/

Expand Down Expand Up @@ -7410,12 +7424,40 @@ rb_stat_f(VALUE obj)
}

/*
* call-seq:
* stat.zero? -> true or false
* :markup: markdown
*
* call-seq:
* zero? -> true or false
*
* Returns whether the entry at the path in `self` has size zero.
*
* The entry may be a file:
*
* ```ruby
* filepath = '/tmp/t.tmp'
* File.write(filepath, 'foo')
* File.stat(filepath).zero? # => false
* File.truncate(filepath, 0)
* File.stat(filepath).zero? # => true
* File.delete(filepath) # Clean up.
* ```
*
* Returns +true+ if <i>stat</i> is a zero-length file; +false+ otherwise.
* The entry may be a directory:
*
* File.stat("testfile").zero? #=> false
* ```ruby
* dirpath = '/tmp/foo'
* Dir.mkdir(dirpath)
* stat = File.stat(dirpath)
* # Size is filesystem-dependent; may or may not be zero.
* stat.size # => 4096
* stat.zero? # => false
* filepath = File.join(dirpath, 't.tmp') # => "/tmp/foo/t.tmp"
* File.write(filepath, 'foo')
* stat = File.stat(dirpath)
* stat.size # => 4096
* stat.zero? # => false
* FileUtils.rm_rf(dirpath) # Clean up.
* ```
*
*/

Expand Down
5 changes: 3 additions & 2 deletions include/ruby/io/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ VALUE rb_io_buffer_free(VALUE self);
// not exactly one.
VALUE rb_io_buffer_free_locked(VALUE self);

// Access the internal buffer and flags. Validates the pointers. If the returned
// base is NULL, the returned size is always zero.
// Access the buffer and flags. Validates the pointers. READONLY reflects both
// the view's own restriction and its source's current permissions. If the
// returned base is NULL, the returned size is always zero.
// The pointers may not remain valid if the source buffer is manipulated.
// Consider using rb_io_buffer_lock if needed.
enum rb_io_buffer_flags rb_io_buffer_get_bytes(VALUE self, void **base, size_t *size);
Expand Down
Loading