* [ruby-core:41340] [ruby-trunk - Feature #5678][Open] StringIO#to_str
@ 2011-11-28 0:52 Martin Bosslet
2011-11-28 1:51 ` [ruby-core:41345] [ruby-trunk - Feature #5678][Feedback] StringIO#to_str Nobuyoshi Nakada
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Martin Bosslet @ 2011-11-28 0:52 UTC (permalink / raw
To: ruby-core
Issue #5678 has been reported by Martin Bosslet.
----------------------------------------
Feature #5678: StringIO#to_str
http://redmine.ruby-lang.org/issues/5678
Author: Martin Bosslet
Status: Open
Priority: Normal
Assignee: Nobuyoshi Nakada
Category: ext
Target version: 2.0.0
The following raises an error currently:
require 'stringio'
require 'openssl'
io = StringIO.new(OpenSSL::ASN1::Integer.new(1).to_der)
asn = OpenSSL::ASN1.decode io
The reason is that ossl_obj2bio[1] looks for a
T_FILE first, and then it tries to coerce the
input to a String using StringValue. StringValue
itself again expects the presence of to_str,
which is currently missing for StringIO, but
could be easily provided by aliasing
StringIO#string.
I could imagine that the heuristic of ossl_obj2bio
is quite common when working on binary data in a
C extension. Would it therefore be OK to add
StringIO#to_str? Patch attached.
[1] https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bio.c#L17
--
http://redmine.ruby-lang.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:41345] [ruby-trunk - Feature #5678][Feedback] StringIO#to_str
2011-11-28 0:52 [ruby-core:41340] [ruby-trunk - Feature #5678][Open] StringIO#to_str Martin Bosslet
@ 2011-11-28 1:51 ` Nobuyoshi Nakada
2011-11-28 2:16 ` [ruby-core:41347] [ruby-trunk - Feature #5678] StringIO#to_str Martin Bosslet
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Nobuyoshi Nakada @ 2011-11-28 1:51 UTC (permalink / raw
To: ruby-core
Issue #5678 has been updated by Nobuyoshi Nakada.
Status changed from Open to Feedback
Martin Bosslet wrote:
> The following raises an error currently:
>
> require 'stringio'
> require 'openssl'
>
> io = StringIO.new(OpenSSL::ASN1::Integer.new(1).to_der)
> asn = OpenSSL::ASN1.decode io
Why do you need to pass `io', not io.string or the result of to_der?
----------------------------------------
Feature #5678: StringIO#to_str
http://redmine.ruby-lang.org/issues/5678
Author: Martin Bosslet
Status: Feedback
Priority: Normal
Assignee: Nobuyoshi Nakada
Category: ext
Target version: 2.0.0
The following raises an error currently:
require 'stringio'
require 'openssl'
io = StringIO.new(OpenSSL::ASN1::Integer.new(1).to_der)
asn = OpenSSL::ASN1.decode io
The reason is that ossl_obj2bio[1] looks for a
T_FILE first, and then it tries to coerce the
input to a String using StringValue. StringValue
itself again expects the presence of to_str,
which is currently missing for StringIO, but
could be easily provided by aliasing
StringIO#string.
I could imagine that the heuristic of ossl_obj2bio
is quite common when working on binary data in a
C extension. Would it therefore be OK to add
StringIO#to_str? Patch attached.
[1] https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bio.c#L17
--
http://redmine.ruby-lang.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:41347] [ruby-trunk - Feature #5678] StringIO#to_str
2011-11-28 0:52 [ruby-core:41340] [ruby-trunk - Feature #5678][Open] StringIO#to_str Martin Bosslet
2011-11-28 1:51 ` [ruby-core:41345] [ruby-trunk - Feature #5678][Feedback] StringIO#to_str Nobuyoshi Nakada
@ 2011-11-28 2:16 ` Martin Bosslet
2011-11-28 6:16 ` [ruby-core:41352] " Yukihiro Matsumoto
2011-11-28 9:50 ` [ruby-core:41354] [ruby-trunk - Feature #5678][Closed] StringIO#to_str Martin Bosslet
2011-11-28 19:12 ` [ruby-core:41378] [ruby-trunk - Feature #5678] StringIO#to_str Martin Bosslet
3 siblings, 1 reply; 8+ messages in thread
From: Martin Bosslet @ 2011-11-28 2:16 UTC (permalink / raw
To: ruby-core
Issue #5678 has been updated by Martin Bosslet.
Nobuyoshi Nakada wrote:
> Martin Bosslet wrote:
> > The following raises an error currently:
> >
> > require 'stringio'
> > require 'openssl'
> >
> > io = StringIO.new(OpenSSL::ASN1::Integer.new(1).to_der)
> > asn = OpenSSL::ASN1.decode io
>
> Why do you need to pass `io', not io.string or the result of to_der?
I don't really need to, it's just that I am working on making
ASN1.decode streaming-aware. So I wanted it to work with any
IO or IO-like object and additionally with Strings. That's why
I thought if someone passes a StringIO, they would be surprised
if an error was raised - they passed an IO-like object after all
and there is no apparent reason why this shouldn't work.
I could, however, call StringIO#string as you suggested, but
I would prefer to use StringValue, as a more generic way
of coercing things into Strings. And it would potentially work
for a wider variety of objects, not only limited to StringIO.
Do you see any negative aspects when adding StringIO#to_str?
----------------------------------------
Feature #5678: StringIO#to_str
http://redmine.ruby-lang.org/issues/5678
Author: Martin Bosslet
Status: Feedback
Priority: Normal
Assignee: Nobuyoshi Nakada
Category: ext
Target version: 2.0.0
The following raises an error currently:
require 'stringio'
require 'openssl'
io = StringIO.new(OpenSSL::ASN1::Integer.new(1).to_der)
asn = OpenSSL::ASN1.decode io
The reason is that ossl_obj2bio[1] looks for a
T_FILE first, and then it tries to coerce the
input to a String using StringValue. StringValue
itself again expects the presence of to_str,
which is currently missing for StringIO, but
could be easily provided by aliasing
StringIO#string.
I could imagine that the heuristic of ossl_obj2bio
is quite common when working on binary data in a
C extension. Would it therefore be OK to add
StringIO#to_str? Patch attached.
[1] https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bio.c#L17
--
http://redmine.ruby-lang.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:41352] Re: [ruby-trunk - Feature #5678] StringIO#to_str
2011-11-28 2:16 ` [ruby-core:41347] [ruby-trunk - Feature #5678] StringIO#to_str Martin Bosslet
@ 2011-11-28 6:16 ` Yukihiro Matsumoto
2011-11-28 9:57 ` [ruby-core:41355] " Nikolai Weibull
0 siblings, 1 reply; 8+ messages in thread
From: Yukihiro Matsumoto @ 2011-11-28 6:16 UTC (permalink / raw
To: ruby-core
Hi,
In message "Re: [ruby-core:41347] [ruby-trunk - Feature #5678] StringIO#to_str"
on Mon, 28 Nov 2011 11:16:33 +0900, Martin Bosslet <Martin.Bosslet@googlemail.com> writes:
|Do you see any negative aspects when adding StringIO#to_str?
Yes, to_str should be implemented for objects that have (almost) same
method signature as strings, which is not true for StringIO.
matz.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:41354] [ruby-trunk - Feature #5678][Closed] StringIO#to_str
2011-11-28 0:52 [ruby-core:41340] [ruby-trunk - Feature #5678][Open] StringIO#to_str Martin Bosslet
2011-11-28 1:51 ` [ruby-core:41345] [ruby-trunk - Feature #5678][Feedback] StringIO#to_str Nobuyoshi Nakada
2011-11-28 2:16 ` [ruby-core:41347] [ruby-trunk - Feature #5678] StringIO#to_str Martin Bosslet
@ 2011-11-28 9:50 ` Martin Bosslet
2011-11-28 10:04 ` [ruby-core:41356] " Yukihiro Matsumoto
2011-11-28 19:12 ` [ruby-core:41378] [ruby-trunk - Feature #5678] StringIO#to_str Martin Bosslet
3 siblings, 1 reply; 8+ messages in thread
From: Martin Bosslet @ 2011-11-28 9:50 UTC (permalink / raw
To: ruby-core
Issue #5678 has been updated by Martin Bosslet.
Status changed from Feedback to Closed
Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: [ruby-core:41347] [ruby-trunk - Feature #5678] StringIO#to_str"
> on Mon, 28 Nov 2011 11:16:33 +0900, Martin Bosslet <Martin.Bosslet@googlemail.com> writes:
>
> |Do you see any negative aspects when adding StringIO#to_str?
>
> Yes, to_str should be implemented for objects that have (almost) same
> method signature as strings, which is not true for StringIO.
>
> matz.
OK, thank you for clarifying this! I will use StringIO#string then.
----------------------------------------
Feature #5678: StringIO#to_str
http://redmine.ruby-lang.org/issues/5678
Author: Martin Bosslet
Status: Closed
Priority: Normal
Assignee: Nobuyoshi Nakada
Category: ext
Target version: 2.0.0
The following raises an error currently:
require 'stringio'
require 'openssl'
io = StringIO.new(OpenSSL::ASN1::Integer.new(1).to_der)
asn = OpenSSL::ASN1.decode io
The reason is that ossl_obj2bio[1] looks for a
T_FILE first, and then it tries to coerce the
input to a String using StringValue. StringValue
itself again expects the presence of to_str,
which is currently missing for StringIO, but
could be easily provided by aliasing
StringIO#string.
I could imagine that the heuristic of ossl_obj2bio
is quite common when working on binary data in a
C extension. Would it therefore be OK to add
StringIO#to_str? Patch attached.
[1] https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bio.c#L17
--
http://redmine.ruby-lang.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:41355] Re: [ruby-trunk - Feature #5678] StringIO#to_str
2011-11-28 6:16 ` [ruby-core:41352] " Yukihiro Matsumoto
@ 2011-11-28 9:57 ` Nikolai Weibull
0 siblings, 0 replies; 8+ messages in thread
From: Nikolai Weibull @ 2011-11-28 9:57 UTC (permalink / raw
To: ruby-core
On Mon, Nov 28, 2011 at 07:16, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
> In message "Re: [ruby-core:41347] [ruby-trunk - Feature #5678] StringIO#to_str"
> on Mon, 28 Nov 2011 11:16:33 +0900, Martin Bosslet <Martin.Bosslet@googlemail.com> writes:
>
> |Do you see any negative aspects when adding StringIO#to_str?
> Yes, to_str should be implemented for objects that have (almost) same
> method signature as strings, which is not true for StringIO.
How about implementing #to_s instead?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:41356] Re: [ruby-trunk - Feature #5678][Closed] StringIO#to_str
2011-11-28 9:50 ` [ruby-core:41354] [ruby-trunk - Feature #5678][Closed] StringIO#to_str Martin Bosslet
@ 2011-11-28 10:04 ` Yukihiro Matsumoto
0 siblings, 0 replies; 8+ messages in thread
From: Yukihiro Matsumoto @ 2011-11-28 10:04 UTC (permalink / raw
To: ruby-core
Hi,
In message "Re: [ruby-core:41354] [ruby-trunk - Feature #5678][Closed] StringIO#to_str"
on Mon, 28 Nov 2011 18:50:12 +0900, Martin Bosslet <Martin.Bosslet@googlemail.com> writes:
|OK, thank you for clarifying this! I will use StringIO#string then.
At the same time, having ASN1.decode to treat T_FILE but not StringIO
is against duck typing. I think it is better if we can do something.
But I don't have a good idea yet. #to_io does not work here. #to_str
is not appropriate.
matz.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:41378] [ruby-trunk - Feature #5678] StringIO#to_str
2011-11-28 0:52 [ruby-core:41340] [ruby-trunk - Feature #5678][Open] StringIO#to_str Martin Bosslet
` (2 preceding siblings ...)
2011-11-28 9:50 ` [ruby-core:41354] [ruby-trunk - Feature #5678][Closed] StringIO#to_str Martin Bosslet
@ 2011-11-28 19:12 ` Martin Bosslet
3 siblings, 0 replies; 8+ messages in thread
From: Martin Bosslet @ 2011-11-28 19:12 UTC (permalink / raw
To: ruby-core
Issue #5678 has been updated by Martin Bosslet.
Yukihiro Matsumoto wrote:
> Hi,
> In message "Re: [ruby-core:41354] [ruby-trunk - Feature #5678][Closed] StringIO#to_str"
> on Mon, 28 Nov 2011 18:50:12 +0900, Martin Bosslet <Martin.Bosslet@googlemail.com> writes:
>
> At the same time, having ASN1.decode to treat T_FILE but not StringIO
> is against duck typing. I think it is better if we can do something.
> But I don't have a good idea yet. #to_io does not work here. #to_str
> is not appropriate.
>
> matz.
We could handle StringIO exceptionally by trying to call #string on the
object passed. But that's not too elegant and will probably only work in
the very specific case of StringIO. Implementing #to_s like Nikolai
suggested could be another solution? Then we could apply the following
heuristic that should cover almost any (valid) case:
1. check for T_FILE
2. try #to_str
3. try #to_s ?
----------------------------------------
Feature #5678: StringIO#to_str
http://redmine.ruby-lang.org/issues/5678
Author: Martin Bosslet
Status: Closed
Priority: Normal
Assignee: Nobuyoshi Nakada
Category: ext
Target version: 2.0.0
The following raises an error currently:
require 'stringio'
require 'openssl'
io = StringIO.new(OpenSSL::ASN1::Integer.new(1).to_der)
asn = OpenSSL::ASN1.decode io
The reason is that ossl_obj2bio[1] looks for a
T_FILE first, and then it tries to coerce the
input to a String using StringValue. StringValue
itself again expects the presence of to_str,
which is currently missing for StringIO, but
could be easily provided by aliasing
StringIO#string.
I could imagine that the heuristic of ossl_obj2bio
is quite common when working on binary data in a
C extension. Would it therefore be OK to add
StringIO#to_str? Patch attached.
[1] https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bio.c#L17
--
http://redmine.ruby-lang.org
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-11-28 19:26 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-28 0:52 [ruby-core:41340] [ruby-trunk - Feature #5678][Open] StringIO#to_str Martin Bosslet
2011-11-28 1:51 ` [ruby-core:41345] [ruby-trunk - Feature #5678][Feedback] StringIO#to_str Nobuyoshi Nakada
2011-11-28 2:16 ` [ruby-core:41347] [ruby-trunk - Feature #5678] StringIO#to_str Martin Bosslet
2011-11-28 6:16 ` [ruby-core:41352] " Yukihiro Matsumoto
2011-11-28 9:57 ` [ruby-core:41355] " Nikolai Weibull
2011-11-28 9:50 ` [ruby-core:41354] [ruby-trunk - Feature #5678][Closed] StringIO#to_str Martin Bosslet
2011-11-28 10:04 ` [ruby-core:41356] " Yukihiro Matsumoto
2011-11-28 19:12 ` [ruby-core:41378] [ruby-trunk - Feature #5678] StringIO#to_str Martin Bosslet
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 read-only IMAP folder(s) and NNTP newsgroup(s).