aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-18 08:24:49 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-18 08:24:49 +0000
commit89b4f06a596e993a82630913f085a82265cb499c (patch)
tree0395f1dbd574c3422177d2fbdc9f045608fb77f4 /io.c
parentf7bdac01c245ed85e97655bb48f279183bf03557 (diff)
downloadruby-89b4f06a596e993a82630913f085a82265cb499c.tar.gz
* io.c (clear_readconv): extracted from rb_io_fptr_finalize.
(mode_enc): call clear_readconv. (io_set_encoding): ditto. (argf_next_argv): ditto. (io_encoding_set): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/io.c b/io.c
index 18eefb2474..92db7be8e2 100644
--- a/io.c
+++ b/io.c
@@ -2894,6 +2894,19 @@ rb_io_fptr_cleanup(rb_io_t *fptr, int noraise)
}
}
+static void
+clear_readconv(rb_io_t *fptr)
+{
+ if (fptr->readconv) {
+ rb_econv_close(fptr->readconv);
+ fptr->readconv = NULL;
+ }
+ if (fptr->crbuf) {
+ free(fptr->crbuf);
+ fptr->crbuf = NULL;
+ }
+}
+
int
rb_io_fptr_finalize(rb_io_t *fptr)
{
@@ -2913,14 +2926,7 @@ rb_io_fptr_finalize(rb_io_t *fptr)
free(fptr->wbuf);
fptr->wbuf = 0;
}
- if (fptr->readconv) {
- rb_econv_close(fptr->readconv);
- fptr->readconv = NULL;
- }
- if (fptr->crbuf) {
- free(fptr->crbuf);
- fptr->crbuf = NULL;
- }
+ clear_readconv(fptr);
free(fptr);
return 1;
}
@@ -3529,6 +3535,7 @@ mode_enc(rb_io_t *fptr, const char *estr)
fptr->enc = 0;
fptr->enc2 = 0;
+ clear_readconv(fptr);
p0 = strrchr(estr, ':');
if (!p0) p1 = estr;
@@ -4258,6 +4265,7 @@ io_set_encoding(VALUE io, VALUE opt)
GetOpenFile(io, fptr);
fptr->enc = 0;
fptr->enc2 = 0;
+ clear_readconv(fptr);
if (!NIL_P(encoding)) {
rb_warn("Ignoring encoding parameter '%s': external_encoding is used",
RSTRING_PTR(encoding));
@@ -5604,6 +5612,7 @@ argf_next_argv(VALUE argf)
GetOpenFile(current_file, fptr);
fptr->enc = argf_enc;
fptr->enc2 = argf_enc2;
+ clear_readconv(fptr);
}
}
else {
@@ -6331,11 +6340,13 @@ io_encoding_set(rb_io_t *fptr, int argc, VALUE v1, VALUE v2)
if (argc == 2) {
fptr->enc2 = rb_to_encoding(v1);
fptr->enc = rb_to_encoding(v2);
+ clear_readconv(fptr);
}
else if (argc == 1) {
if (NIL_P(v1)) {
fptr->enc = 0;
fptr->enc2 = 0;
+ clear_readconv(fptr);
}
else {
VALUE tmp = rb_check_string_type(v1);
@@ -6345,6 +6356,7 @@ io_encoding_set(rb_io_t *fptr, int argc, VALUE v1, VALUE v2)
else {
fptr->enc = rb_to_encoding(v1);
fptr->enc2 = 0;
+ clear_readconv(fptr);
}
}
}