ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:108697] [Ruby master Bug#18805] IO::Buffer is inconsistent when returning a string from an empty buffer
@ 2022-05-25 12:45 procmarco (Marco Concetto Rudilosso)
  2023-08-30 20:08 ` [ruby-core:114597] " jeremyevans0 (Jeremy Evans) via ruby-core
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: procmarco (Marco Concetto Rudilosso) @ 2022-05-25 12:45 UTC (permalink / raw)
  To: ruby-core

Issue #18805 has been reported by procmarco (Marco Concetto Rudilosso).

----------------------------------------
Bug #18805: IO::Buffer is inconsistent when returning a string from an empty buffer
https://bugs.ruby-lang.org/issues/18805

* Author: procmarco (Marco Concetto Rudilosso)
* Status: Open
* Priority: Normal
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
I’ve been using `IO::Buffer` and I found it to be slightly inconsistent when it comes to returning empty string for empty buffers.
for example, a slice of an allocated buffer with `size = 0`, returns `""` with `get_string`, as an example:

```ruby
buffer = IO::Buffer.new(5)
empty_buffer = buffer.slice(0,0)
puts empty_buffer.size # this prints 0
empty_buffer.get_string # this returns ""
```

but, if you create a buffer with IO::Buffer.new(0) then it stops working

```ruby
empty_buffer = IO::Buffer.new(0)
puts empty_buffer.size # this prints 0
empty_buffer.get_string # this raises The buffer is not allocated! (IO::Buffer::AllocationError)
```

Is this working as intended? It would be good I think to have a consistent experience where the base case (buffer with size 0) always returns an empty string.
I have a prototype of a possible patch I could send upstream to fix it, which would check the size of the buffer and if 0 it would always return an empty string.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:114597] [Ruby master Bug#18805] IO::Buffer is inconsistent when returning a string from an empty buffer
  2022-05-25 12:45 [ruby-core:108697] [Ruby master Bug#18805] IO::Buffer is inconsistent when returning a string from an empty buffer procmarco (Marco Concetto Rudilosso)
@ 2023-08-30 20:08 ` jeremyevans0 (Jeremy Evans) via ruby-core
  2023-12-26 13:38 ` [ruby-core:115908] " ioquatix (Samuel Williams) via ruby-core
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2023-08-30 20:08 UTC (permalink / raw)
  To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)

Issue #18805 has been updated by jeremyevans0 (Jeremy Evans).

Assignee set to ioquatix (Samuel Williams)

@ioquatix Is this expected behavior or a bug?

----------------------------------------
Bug #18805: IO::Buffer is inconsistent when returning a string from an empty buffer
https://bugs.ruby-lang.org/issues/18805#change-104413

* Author: procmarco (Marco Concetto Rudilosso)
* Status: Open
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
I’ve been using `IO::Buffer` and I found it to be slightly inconsistent when it comes to returning empty string for empty buffers.
for example, a slice of an allocated buffer with `size = 0`, returns `""` with `get_string`, as an example:

```ruby
buffer = IO::Buffer.new(5)
empty_buffer = buffer.slice(0,0)
puts empty_buffer.size # this prints 0
empty_buffer.get_string # this returns ""
```

but, if you create a buffer with IO::Buffer.new(0) then it stops working

```ruby
empty_buffer = IO::Buffer.new(0)
puts empty_buffer.size # this prints 0
empty_buffer.get_string # this raises The buffer is not allocated! (IO::Buffer::AllocationError)
```

Is this working as intended? It would be good I think to have a consistent experience where the base case (buffer with size 0) always returns an empty string.
I have a prototype of a possible patch I could send upstream to fix it, which would check the size of the buffer and if 0 it would always return an empty string.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:115908] [Ruby master Bug#18805] IO::Buffer is inconsistent when returning a string from an empty buffer
  2022-05-25 12:45 [ruby-core:108697] [Ruby master Bug#18805] IO::Buffer is inconsistent when returning a string from an empty buffer procmarco (Marco Concetto Rudilosso)
  2023-08-30 20:08 ` [ruby-core:114597] " jeremyevans0 (Jeremy Evans) via ruby-core
@ 2023-12-26 13:38 ` ioquatix (Samuel Williams) via ruby-core
  2024-01-14  2:59 ` [ruby-core:116195] " ioquatix (Samuel Williams) via ruby-core
  2024-01-14 21:49 ` [ruby-core:116206] " ioquatix (Samuel Williams) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: ioquatix (Samuel Williams) via ruby-core @ 2023-12-26 13:38 UTC (permalink / raw)
  To: ruby-core; +Cc: ioquatix (Samuel Williams)

Issue #18805 has been updated by ioquatix (Samuel Williams).


This is currently working as intended but we could consider changing the behaviour. I understand the use case.

----------------------------------------
Bug #18805: IO::Buffer is inconsistent when returning a string from an empty buffer
https://bugs.ruby-lang.org/issues/18805#change-105866

* Author: procmarco (Marco Concetto Rudilosso)
* Status: Open
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
I’ve been using `IO::Buffer` and I found it to be slightly inconsistent when it comes to returning empty string for empty buffers.
for example, a slice of an allocated buffer with `size = 0`, returns `""` with `get_string`, as an example:

```ruby
buffer = IO::Buffer.new(5)
empty_buffer = buffer.slice(0,0)
puts empty_buffer.size # this prints 0
empty_buffer.get_string # this returns ""
```

but, if you create a buffer with IO::Buffer.new(0) then it stops working

```ruby
empty_buffer = IO::Buffer.new(0)
puts empty_buffer.size # this prints 0
empty_buffer.get_string # this raises The buffer is not allocated! (IO::Buffer::AllocationError)
```

Is this working as intended? It would be good I think to have a consistent experience where the base case (buffer with size 0) always returns an empty string.
I have a prototype of a possible patch I could send upstream to fix it, which would check the size of the buffer and if 0 it would always return an empty string.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:116195] [Ruby master Bug#18805] IO::Buffer is inconsistent when returning a string from an empty buffer
  2022-05-25 12:45 [ruby-core:108697] [Ruby master Bug#18805] IO::Buffer is inconsistent when returning a string from an empty buffer procmarco (Marco Concetto Rudilosso)
  2023-08-30 20:08 ` [ruby-core:114597] " jeremyevans0 (Jeremy Evans) via ruby-core
  2023-12-26 13:38 ` [ruby-core:115908] " ioquatix (Samuel Williams) via ruby-core
@ 2024-01-14  2:59 ` ioquatix (Samuel Williams) via ruby-core
  2024-01-14 21:49 ` [ruby-core:116206] " ioquatix (Samuel Williams) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: ioquatix (Samuel Williams) via ruby-core @ 2024-01-14  2:59 UTC (permalink / raw)
  To: ruby-core; +Cc: ioquatix (Samuel Williams)

Issue #18805 has been updated by ioquatix (Samuel Williams).


As a 2nd issue was created about the similar issue, I think it's worth improving.

See https://github.com/ruby/ruby/pull/9532 for the proposed changes.

----------------------------------------
Bug #18805: IO::Buffer is inconsistent when returning a string from an empty buffer
https://bugs.ruby-lang.org/issues/18805#change-106211

* Author: procmarco (Marco Concetto Rudilosso)
* Status: Open
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
I’ve been using `IO::Buffer` and I found it to be slightly inconsistent when it comes to returning empty string for empty buffers.
for example, a slice of an allocated buffer with `size = 0`, returns `""` with `get_string`, as an example:

```ruby
buffer = IO::Buffer.new(5)
empty_buffer = buffer.slice(0,0)
puts empty_buffer.size # this prints 0
empty_buffer.get_string # this returns ""
```

but, if you create a buffer with IO::Buffer.new(0) then it stops working

```ruby
empty_buffer = IO::Buffer.new(0)
puts empty_buffer.size # this prints 0
empty_buffer.get_string # this raises The buffer is not allocated! (IO::Buffer::AllocationError)
```

Is this working as intended? It would be good I think to have a consistent experience where the base case (buffer with size 0) always returns an empty string.
I have a prototype of a possible patch I could send upstream to fix it, which would check the size of the buffer and if 0 it would always return an empty string.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:116206] [Ruby master Bug#18805] IO::Buffer is inconsistent when returning a string from an empty buffer
  2022-05-25 12:45 [ruby-core:108697] [Ruby master Bug#18805] IO::Buffer is inconsistent when returning a string from an empty buffer procmarco (Marco Concetto Rudilosso)
                   ` (2 preceding siblings ...)
  2024-01-14  2:59 ` [ruby-core:116195] " ioquatix (Samuel Williams) via ruby-core
@ 2024-01-14 21:49 ` ioquatix (Samuel Williams) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: ioquatix (Samuel Williams) via ruby-core @ 2024-01-14 21:49 UTC (permalink / raw)
  To: ruby-core; +Cc: ioquatix (Samuel Williams)

Issue #18805 has been updated by ioquatix (Samuel Williams).

Status changed from Open to Closed

Fixed in https://github.com/ruby/ruby/commit/c5cf4d4e129f64cb69aaf0a829aed068ef1943c4

----------------------------------------
Bug #18805: IO::Buffer is inconsistent when returning a string from an empty buffer
https://bugs.ruby-lang.org/issues/18805#change-106225

* Author: procmarco (Marco Concetto Rudilosso)
* Status: Closed
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
I’ve been using `IO::Buffer` and I found it to be slightly inconsistent when it comes to returning empty string for empty buffers.
for example, a slice of an allocated buffer with `size = 0`, returns `""` with `get_string`, as an example:

```ruby
buffer = IO::Buffer.new(5)
empty_buffer = buffer.slice(0,0)
puts empty_buffer.size # this prints 0
empty_buffer.get_string # this returns ""
```

but, if you create a buffer with IO::Buffer.new(0) then it stops working

```ruby
empty_buffer = IO::Buffer.new(0)
puts empty_buffer.size # this prints 0
empty_buffer.get_string # this raises The buffer is not allocated! (IO::Buffer::AllocationError)
```

Is this working as intended? It would be good I think to have a consistent experience where the base case (buffer with size 0) always returns an empty string.
I have a prototype of a possible patch I could send upstream to fix it, which would check the size of the buffer and if 0 it would always return an empty string.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-14 21:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-25 12:45 [ruby-core:108697] [Ruby master Bug#18805] IO::Buffer is inconsistent when returning a string from an empty buffer procmarco (Marco Concetto Rudilosso)
2023-08-30 20:08 ` [ruby-core:114597] " jeremyevans0 (Jeremy Evans) via ruby-core
2023-12-26 13:38 ` [ruby-core:115908] " ioquatix (Samuel Williams) via ruby-core
2024-01-14  2:59 ` [ruby-core:116195] " ioquatix (Samuel Williams) via ruby-core
2024-01-14 21:49 ` [ruby-core:116206] " ioquatix (Samuel Williams) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).