8000 IO::Buffer improvements and documentation. (#9329) · github/ruby@37753f1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 37753f1

Browse files
authored
IO::Buffer improvements and documentation. (ruby#9329)
* Restore experimental warnings. * Documentation and code structure improvements. * Improved validation of flags, clarified documentation of argument handling. * Remove inconsistent use of `Example:` and add example to `null?`. * Expose `IO::Buffer#private?` and add test.
1 parent 61289d9 commit 37753f1

File tree

4 files changed

+402
-182
lines changed

4 files changed

+402
-182
lines changed

include/ruby/fiber/scheduler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ VALUE rb_fiber_scheduler_get(void);
9797
* current thread will call scheduler's `#close` method on finalisation
9898
* (allowing the scheduler to properly manage all non-finished fibers).
9999
* `scheduler` can be an object of any class corresponding to
100-
* `Fiber::SchedulerInterface`. Its implementation is up to the user.
100+
* `Fiber::Scheduler` interface. Its implementation is up to the user.
101101
*
102102
* @param[in] scheduler The scheduler to set.
103103
* @exception rb_eArgError `scheduler` does not conform the interface.

include/ruby/io/buffer.h

Lines changed: 15 additions & 2 deletions
C1CF
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ RBIMPL_SYMBOL_EXPORT_BEGIN()
2323

2424
#define RUBY_IO_BUFFER_VERSION 2
2525

26+
// The `IO::Buffer` class.
2627
RUBY_EXTERN VALUE rb_cIOBuffer;
28+
29+
// The operating system page size.
2730
RUBY_EXTERN size_t RUBY_IO_BUFFER_PAGE_SIZE;
31+
32+
// The default buffer size, usually a (small) multiple of the page size.
33+
// Can be overridden by the RUBY_IO_BUFFER_DEFAULT_SIZE environment variable.
2834
RUBY_EXTERN size_t RUBY_IO_BUFFER_DEFAULT_SIZE;
2935

36+
// Represents the internal state of the buffer.
37+
// More than one flag can be set at a time.
3038
enum rb_io_buffer_flags {
3139
// The memory in the buffer is owned by someone else.
3240
// More specifically, it means that someone else owns the buffer and we shouldn't try to resize it.
@@ -49,10 +57,12 @@ enum rb_io_buffer_flags {
4957
RB_IO_BUFFER_PRIVATE = 64,
5058

5159
// The buffer is read-only and cannot be modified.
52-
RB_IO_BUFFER_READONLY = 128
60+
RB_IO_BUFFER_READONLY = 128,
5361
};
5462

63+
// Represents the endian of the data types.
5564
enum rb_io_buffer_endian {
65+
// The least significant units are put first.
5666
RB_IO_BUFFER_LITTLE_ENDIAN = 4,
5767
RB_IO_BUFFER_BIG_ENDIAN = 8,
5868

@@ -79,7 +89,10 @@ int rb_io_buffer_try_unlock(VALUE self);
7989
VALUE rb_io_buffer_free(VALUE self);
8090
VALUE rb_io_buffer_free_locked(VALUE self);
8191

82-
int rb_io_buffer_get_bytes(VALUE self, void **base, size_t *size);
92+
// Access the internal buffer and flags. Validates the pointers.
93+
// The points may not remain valid if the source buffer is manipulated.
94+
// Consider using rb_io_buffer_lock if needed.
95+
enum rb_io_buffer_flags rb_io_buffer_get_bytes(VALUE self, void **base, size_t *size);
8396
void rb_io_buffer_get_bytes_for_reading(VALUE self, const void **base, size_t *size);
8497
void rb_io_buffer_get_bytes_for_writing(VALUE self, void **base, size_t *size);
8598

0 commit comments

Comments
 (0)
0