diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-08-13 09:36:12 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-08-13 09:36:12 +0000 |
commit | 96d7c07e497e7be5296de10511788eb9aa3e114b (patch) | |
tree | 9edc45180b9d17da2c1061de78d31d5c55ce77b5 /ext/stringio/stringio.c | |
parent | 2bf3c6b6315fa8839ff66c502ee5116711d242f1 (diff) | |
download | ruby-96d7c07e497e7be5296de10511788eb9aa3e114b.tar.gz |
* ext/stringio/stringio.c (strio_set_string): disallow nil.
http://www.rubyist.net/~nobu/t/20050811.html#c05
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/stringio/stringio.c')
-rw-r--r-- | ext/stringio/stringio.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 55678f71d8..60333a1ff9 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -96,9 +96,9 @@ get_strio(self) #define StringIO(obj) get_strio(obj) -#define CLOSED(ptr) NIL_P((ptr)->string) -#define READABLE(ptr) (!CLOSED(ptr) && ((ptr)->flags & FMODE_READABLE)) -#define WRITABLE(ptr) (!CLOSED(ptr) && ((ptr)->flags & FMODE_WRITABLE)) +#define CLOSED(ptr) (!((ptr)->flags & FMODE_READWRITE)) +#define READABLE(ptr) ((ptr)->flags & FMODE_READABLE) +#define WRITABLE(ptr) ((ptr)->flags & FMODE_WRITABLE) static struct StringIO* readable(ptr) @@ -361,10 +361,8 @@ strio_set_string(self, string) if (!OBJ_TAINTED(self)) rb_secure(4); ptr->flags &= ~FMODE_READWRITE; - if (!NIL_P(string)) { - StringValue(string); - ptr->flags = OBJ_FROZEN(string) ? FMODE_READABLE : FMODE_READWRITE; - } + StringValue(string); + ptr->flags = OBJ_FROZEN(string) ? FMODE_READABLE : FMODE_READWRITE; ptr->pos = 0; ptr->lineno = 0; return ptr->string = string; @@ -382,7 +380,7 @@ strio_close(self) VALUE self; { struct StringIO *ptr = StringIO(self); - if (CLOSED(ptr) || !(ptr->flags & FMODE_READWRITE)) { + if (CLOSED(ptr)) { rb_raise(rb_eIOError, "closed stream"); } ptr->flags &= ~FMODE_READWRITE; |