| Age | Commit message (Collapse) | Author |
|
This struct is used for addition not only for multiplication, so
remove the word `mul`, and make the member names more descriptive.
|
|
Previously, warned only in `new` and `map`, but not `for` and
`string`.
|
|
https://hackerone.com/reports/3437743
|
|
At least, `string` in `io_buffer_set_string` can be different from
`argv[0]` after `rb_str_to_str` call. The other cases may not be
necessary.
|
|
If we don't have uint128, then rb_int128_to_numeric emits a strict
aliasing warning:
numeric.c:3641:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
3641 | return rb_uint128_to_numeric(*(rb_uint128_t*)&n);
| ^~~~~~~~~~~~~~~~~
|
|
The following warnings are emitted. We can use type punning to prevent
strict aliasing violations.
io_buffer.c:1935:23: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
1935 | rb_uint128_t u = *(rb_uint128_t*)&x;
| ^~~~~~~~~~~~~~~~~
io_buffer.c:1937:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
1937 | return *(rb_int128_t*)&swapped;
|
|
|
(#15399)
|
|
The method incorrectly ignored its first argument and treated the second argument as offset and the third as count.
This change makes the first argument be treated as offset and the second as count.
Also fix incorrect block parameter in comments.
|
|
- Buffer's size did not account for offset when mapping the file, leading to possible crashes.
- Size and offset were not checked properly, leading to many situations raising EINVAL errors with generic messages.
- Documentation was wrong.
|
|
Previously on our mark_and_move we were calling rb_gc_mark, which isn't
safe to call at compaction time.
Co-authored-by: Luke Gruber <luke.gru@gmail.com>
|
|
The `source` field in IO::Buffer can have a String or an IO::Buffer
object, if not nil.
- When the `source` is a String object. The `base` field points to the
memory location of the String content, which can be embedded in
RSTRING, and in that case, GC compaction can move the memory region
along with the String object.
Thus, IO::Buffer needs to pin the `source` object to prevent `base`
pointer from becoming invalid.
- When the `source` is an IO::Buffer, then `base` is a pointer to a
malloced or mmapped memory region, managed by the source IO::Buffer.
In this case, we don't need to pin the source IO::Buffer object,
since the referred memory region won't get moved by GC.
Closes: [Bug #21210]
Notes:
Merged: https://github.com/ruby/ruby/pull/13033
|
|
This reverts commit 6012145299cfa4ab561360c78710c7f2941a7e9d.
Notes:
Merged: https://github.com/ruby/ruby/pull/13033
|
|
in that case
Notes:
Merged: https://github.com/ruby/ruby/pull/13615
|
|
`fiber_interrupt` hook. (#12839)
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
They are not used outside of io_buffer.c, so we can make them static.
Notes:
Merged: https://github.com/ruby/ruby/pull/13022
|
|
allowing them to support compaction and be moved.
Notes:
Merged: https://github.com/ruby/ruby/pull/13018
|
|
The allocated buffers may be consecutive memory addresses. This will mean
that `b->base == a->base + a->size` even though `a` and `b` are separate
buffers.
Notes:
Merged: https://github.com/ruby/ruby/pull/12284
|
|
Use PR_SET_VMA_ANON_NAME to set human-readable names for anonymous
virtual memory areas mapped by `mmap()` when compiled and run on Linux
5.17 or higher. This makes it convenient for developers to debug mmap.
Notes:
Merged: https://github.com/ruby/ruby/pull/12119
|
|
[Feature #20902]
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
#set_string (#11640)
The current implementation of `IO::Buffer#copy` and `#set_string` has
an undefined behavior when the source and destination memory overlaps,
due to the underlying use of the `memcpy` C function.
This patch guarantees the methods to be safe even when copying between
overlapping buffers by replacing `memcpy` with `memmove`,
Fixes: [Bug #20745]
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
This does not change any actual behaviour, but provides a choke point for blocking IO operations.
* Update `IO::Buffer` to use `rb_io_blocking_region`.
* Update `File` to use `rb_io_blocking_region`.
* Update `IO` to use `rb_io_blocking_region`.
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
Update documentation.
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/11738
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/11735
|
|
|
|
|
|
|
|
(#9532)
This makes the behaviour of IO::Buffer.new(0) and IO::Buffer.new.slice(0, 0) consistent.
Fixes https://bugs.ruby-lang.org/issues/19542 and https://bugs.ruby-lang.org/issues/18805.
|
|
* Don't return early.
* Add missing `mapping` assignment.
* Make debug logs conditional.
|
|
* Avoiding using `Tempfile` which was retaining the file preventing it from unlinking.
|
|
* 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.
|
|
|
|
|
|
Benchmark:
```
require "benchmark"
puts(Benchmark.measure do
ary = 1_000_000.times.map { IO::Buffer.for("") }
10.times { GC.start(full_mark: false) }
end)
```
Before:
```
14.330119 0.051497 14.381616 ( 14.445106)
```
After:
```
7.481152 0.040166 7.521318 ( 7.535209)
```
|
|
Since IO::Buffer is allocated using TypedData_Make_Struct, it must use
xfree to free the buffer otherwise it will cause more major GC to run.
Example:
```
10.times do
1_000_000.times { IO::Buffer.new(0) }
puts "oldmalloc_increase_bytes: #{GC.stat(:oldmalloc_increase_bytes)}, major_gc_count: #{GC.stat(:major_gc_count)}"
end
```
Before:
```
oldmalloc_increase_bytes: 14904176, major_gc_count: 3
oldmalloc_increase_bytes: 2399424, major_gc_count: 5
oldmalloc_increase_bytes: 5204640, major_gc_count: 6
oldmalloc_increase_bytes: 2199936, major_gc_count: 7
oldmalloc_increase_bytes: 34199936, major_gc_count: 7
oldmalloc_increase_bytes: 24223360, major_gc_count: 8
oldmalloc_increase_bytes: 5967616, major_gc_count: 9
oldmalloc_increase_bytes: 37967616, major_gc_count: 9
oldmalloc_increase_bytes: 9689792, major_gc_count: 10
oldmalloc_increase_bytes: 41689792, major_gc_count: 10
```
After:
```
oldmalloc_increase_bytes: 117392, major_gc_count: 2
oldmalloc_increase_bytes: 26128, major_gc_count: 2
oldmalloc_increase_bytes: 71600, major_gc_count: 2
oldmalloc_increase_bytes: 117072, major_gc_count: 2
oldmalloc_increase_bytes: 17296, major_gc_count: 2
oldmalloc_increase_bytes: 62768, major_gc_count: 2
oldmalloc_increase_bytes: 108240, major_gc_count: 2
oldmalloc_increase_bytes: 153712, major_gc_count: 2
oldmalloc_increase_bytes: 53936, major_gc_count: 2
oldmalloc_increase_bytes: 99408, major_gc_count: 2
```
|
|
`map`. (#9131)
|
|
* Fix `io_buffer_get_string` default length computation.
When an offset bigger than the size is given, the resulting length will be
computed incorrectly. Raise an argument error in this case.
* Validate all arguments.
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
* Documentation consistency.
* Improve consistency of `pread`/`pwrite` implementation when given length.
* Remove HAVE_PREAD / HAVE_PWRITE - it is no longer optional.
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
- Fix IO::Buffer `read`/`write` to use a minimum length.
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
* Skip test if non-blocking file IO is not supported.
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
`#resize(0)` on an IO::Buffer with internal buffer allocated will
result in calling `realloc(data->base, 0)`. The behavior of `realloc`
with size = 0 is implementation-defined (glibc frees the object
and returns NULL, while BSDs return an inaccessible object). And
thus such usage is deprecated in standard C (upcoming C23 will make it
UB).
To avoid this problem, just `free`s the memory when the new size is zero.
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
Notes:
Merged-By: k0kubun <takashikkbn@gmail.com>
|
|
|
|
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|
|
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
|