summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-09-09 02:27:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-09-09 02:27:01 +0000
commit23fb79a290a4d7e2232546db2fc25663d0220de5 (patch)
tree61db75d6c34359bc92dd37baf5443d5db14eb8ab
parent73d4f4b0bbe7918134fc2d687298af0181a5030d (diff)
* ext/stringio/stringio.c (strio_set_string): reinitialize
properly. * ext/stringio/stringio.c (strio_become): added self-assign check and experimental auto-conversion to StringIO. * ext/stringio/stringio.c (strio_reopen): added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog11
-rw-r--r--ext/stringio/stringio.c36
2 files changed, 36 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 447240ceb3b..59cb71ba02f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Mon Sep 9 11:21:04 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
+
+ * ext/stringio/stringio.c (strio_set_string): reinitialize
+ properly.
+
+ * ext/stringio/stringio.c (strio_become): added self-assign check
+ and experimental auto-conversion to StringIO.
+
+ * ext/stringio/stringio.c (strio_reopen): added.
+
+
Sun Sep 8 21:29:25 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* time.c (time_free): prototype; struct time_object -> void *.
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 4f682b3a201..73148642a73 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -217,7 +217,7 @@ strio_initialize(argc, argv, self)
StringValue(string);
if (!(m = RSTRING(mode)->ptr)) m = "";
ptr->flags = rb_io_mode_flags(m);
- if (ptr->flags & FMODE_WRITABLE && OBJ_FROZEN(string)) {
+ if ((ptr->flags & FMODE_WRITABLE) && OBJ_FROZEN(string)) {
errno = EACCES;
rb_sys_fail(0);
}
@@ -317,13 +317,13 @@ strio_set_string(self, string)
{
struct StringIO *ptr = StringIO(self);
- if (NIL_P(string)) {
- ptr->flags &= ~FMODE_READWRITE;
- }
- else {
+ ptr->flags &= ~FMODE_READWRITE;
+ if (!NIL_P(string)) {
StringValue(string);
- ptr->flags |= FMODE_READWRITE;
+ ptr->flags = OBJ_FROZEN(string) ? FMODE_READABLE : FMODE_READWRITE;
}
+ ptr->pos = 0;
+ ptr->lineno = 0;
return ptr->string = string;
}
@@ -408,10 +408,13 @@ static VALUE
strio_become(copy, orig)
VALUE copy, orig;
{
- struct StringIO *ptr = StringIO(orig);
+ struct StringIO *ptr;
- if (DATA_PTR(copy)) {
- strio_free(DATA_PTR(ptr));
+ orig = rb_convert_type(orig, T_DATA, "StringIO", "to_strio");
+ if (copy == orig) return copy;
+ ptr = StringIO(orig);
+ if (check_strio(copy)) {
+ strio_free(DATA_PTR(copy));
}
DATA_PTR(copy) = ptr;
++ptr->count;
@@ -435,8 +438,6 @@ strio_set_lineno(self, lineno)
#define strio_binmode strio_self
-#define strio_reopen strio_unimpl
-
#define strio_fcntl strio_unimpl
#define strio_flush strio_self
@@ -444,6 +445,19 @@ strio_set_lineno(self, lineno)
#define strio_fsync strio_0
static VALUE
+strio_reopen(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ rb_secure(4);
+ if (argc == 1 && TYPE(*argv) != T_STRING) {
+ return strio_become(self, *argv);
+ }
+ return strio_initialize(argc, argv, self);
+}
+
+static VALUE
strio_get_pos(self)
VALUE self;
{