From 1ff027aa2ddb2fa3c6adf12c5a3fa1717c5ce25a Mon Sep 17 00:00:00 2001 From: Ron Steinke Date: Fri, 3 Aug 2001 20:42:06 +0000 Subject: [PATCH] Modified Files: glib/ChangeLog glib/glib/giochannel.c Modified Files: glib/ChangeLog glib/glib/giochannel.c glib/tests/iochannel-test.c * glib/giochannel.c: Fixed g_io_channel_seek_position() so that G_SEEK_CUR can be used with UTF-8 encoding * glib/giochannel.c: Changed test to decide whether use_buf is encoded_read_buf or read_buf from "if (channel->do_encode)" to "if (channel->encoding)" to fix bug 58472 * tests/iochannel-test.c: Fixed so it doesn't output double newlines * glib/giochannel.c: Fixed g_io_channel_fill_buffer() so that encoded_read_buf is created for UTF-8 encoding --- ChangeLog | 16 ++++++++++++++++ ChangeLog.pre-2-0 | 16 ++++++++++++++++ ChangeLog.pre-2-10 | 16 ++++++++++++++++ ChangeLog.pre-2-12 | 16 ++++++++++++++++ ChangeLog.pre-2-2 | 16 ++++++++++++++++ ChangeLog.pre-2-4 | 16 ++++++++++++++++ ChangeLog.pre-2-6 | 16 ++++++++++++++++ ChangeLog.pre-2-8 | 16 ++++++++++++++++ glib/giochannel.c | 34 +++++++++++++++++++++++----------- tests/iochannel-test.c | 12 +----------- 10 files changed, 152 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index d8929d1..2d7822c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2001-08-03 Ron Steinke + + * glib/giochannel.c: Fixed g_io_channel_seek_position() + so that G_SEEK_CUR can be used with UTF-8 encoding + + * glib/giochannel.c: Changed test to decide whether + use_buf is encoded_read_buf or read_buf from + "if (channel->do_encode)" to "if (channel->encoding)" to + fix bug 58472 + + * tests/iochannel-test.c: Fixed so it doesn't output + double newlines + + * glib/giochannel.c: Fixed g_io_channel_fill_buffer() + so that encoded_read_buf is created for UTF-8 encoding + 2001-08-03 Darin Adler * tests/strfunc-test.c: (strv_check), (main): diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index d8929d1..2d7822c 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,19 @@ +2001-08-03 Ron Steinke + + * glib/giochannel.c: Fixed g_io_channel_seek_position() + so that G_SEEK_CUR can be used with UTF-8 encoding + + * glib/giochannel.c: Changed test to decide whether + use_buf is encoded_read_buf or read_buf from + "if (channel->do_encode)" to "if (channel->encoding)" to + fix bug 58472 + + * tests/iochannel-test.c: Fixed so it doesn't output + double newlines + + * glib/giochannel.c: Fixed g_io_channel_fill_buffer() + so that encoded_read_buf is created for UTF-8 encoding + 2001-08-03 Darin Adler * tests/strfunc-test.c: (strv_check), (main): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index d8929d1..2d7822c 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,19 @@ +2001-08-03 Ron Steinke + + * glib/giochannel.c: Fixed g_io_channel_seek_position() + so that G_SEEK_CUR can be used with UTF-8 encoding + + * glib/giochannel.c: Changed test to decide whether + use_buf is encoded_read_buf or read_buf from + "if (channel->do_encode)" to "if (channel->encoding)" to + fix bug 58472 + + * tests/iochannel-test.c: Fixed so it doesn't output + double newlines + + * glib/giochannel.c: Fixed g_io_channel_fill_buffer() + so that encoded_read_buf is created for UTF-8 encoding + 2001-08-03 Darin Adler * tests/strfunc-test.c: (strv_check), (main): diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index d8929d1..2d7822c 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,19 @@ +2001-08-03 Ron Steinke + + * glib/giochannel.c: Fixed g_io_channel_seek_position() + so that G_SEEK_CUR can be used with UTF-8 encoding + + * glib/giochannel.c: Changed test to decide whether + use_buf is encoded_read_buf or read_buf from + "if (channel->do_encode)" to "if (channel->encoding)" to + fix bug 58472 + + * tests/iochannel-test.c: Fixed so it doesn't output + double newlines + + * glib/giochannel.c: Fixed g_io_channel_fill_buffer() + so that encoded_read_buf is created for UTF-8 encoding + 2001-08-03 Darin Adler * tests/strfunc-test.c: (strv_check), (main): diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index d8929d1..2d7822c 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,19 @@ +2001-08-03 Ron Steinke + + * glib/giochannel.c: Fixed g_io_channel_seek_position() + so that G_SEEK_CUR can be used with UTF-8 encoding + + * glib/giochannel.c: Changed test to decide whether + use_buf is encoded_read_buf or read_buf from + "if (channel->do_encode)" to "if (channel->encoding)" to + fix bug 58472 + + * tests/iochannel-test.c: Fixed so it doesn't output + double newlines + + * glib/giochannel.c: Fixed g_io_channel_fill_buffer() + so that encoded_read_buf is created for UTF-8 encoding + 2001-08-03 Darin Adler * tests/strfunc-test.c: (strv_check), (main): diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index d8929d1..2d7822c 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,19 @@ +2001-08-03 Ron Steinke + + * glib/giochannel.c: Fixed g_io_channel_seek_position() + so that G_SEEK_CUR can be used with UTF-8 encoding + + * glib/giochannel.c: Changed test to decide whether + use_buf is encoded_read_buf or read_buf from + "if (channel->do_encode)" to "if (channel->encoding)" to + fix bug 58472 + + * tests/iochannel-test.c: Fixed so it doesn't output + double newlines + + * glib/giochannel.c: Fixed g_io_channel_fill_buffer() + so that encoded_read_buf is created for UTF-8 encoding + 2001-08-03 Darin Adler * tests/strfunc-test.c: (strv_check), (main): diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index d8929d1..2d7822c 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,19 @@ +2001-08-03 Ron Steinke + + * glib/giochannel.c: Fixed g_io_channel_seek_position() + so that G_SEEK_CUR can be used with UTF-8 encoding + + * glib/giochannel.c: Changed test to decide whether + use_buf is encoded_read_buf or read_buf from + "if (channel->do_encode)" to "if (channel->encoding)" to + fix bug 58472 + + * tests/iochannel-test.c: Fixed so it doesn't output + double newlines + + * glib/giochannel.c: Fixed g_io_channel_fill_buffer() + so that encoded_read_buf is created for UTF-8 encoding + 2001-08-03 Darin Adler * tests/strfunc-test.c: (strv_check), (main): diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index d8929d1..2d7822c 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,19 @@ +2001-08-03 Ron Steinke + + * glib/giochannel.c: Fixed g_io_channel_seek_position() + so that G_SEEK_CUR can be used with UTF-8 encoding + + * glib/giochannel.c: Changed test to decide whether + use_buf is encoded_read_buf or read_buf from + "if (channel->do_encode)" to "if (channel->encoding)" to + fix bug 58472 + + * tests/iochannel-test.c: Fixed so it doesn't output + double newlines + + * glib/giochannel.c: Fixed g_io_channel_fill_buffer() + so that encoded_read_buf is created for UTF-8 encoding + 2001-08-03 Darin Adler * tests/strfunc-test.c: (strv_check), (main): diff --git a/glib/giochannel.c b/glib/giochannel.c index 01f7416..7f4c5c2 100644 --- a/glib/giochannel.c +++ b/glib/giochannel.c @@ -94,7 +94,7 @@ g_io_channel_unref (GIOChannel *channel) if (channel->ref_count == 0) { if (channel->close_on_unref) - g_io_channel_close (channel); + g_io_channel_shutdown (channel, TRUE, NULL); else g_io_channel_purge (channel); g_free (channel->encoding); @@ -408,7 +408,7 @@ g_io_channel_purge (GIOChannel *channel) g_string_truncate (channel->read_buf, 0); if (channel->write_buf) g_string_truncate (channel->write_buf, 0); - if (channel->do_encode) + if (channel->encoding) { if (channel->encoded_read_buf) g_string_truncate (channel->encoded_read_buf, 0); @@ -931,7 +931,7 @@ g_io_channel_set_encoding (GIOChannel *channel, /* Make sure the encoded buffers are empty */ - g_return_val_if_fail (!channel->encoded_read_buf || + g_return_val_if_fail (!channel->do_encode || !channel->encoded_read_buf || channel->encoded_read_buf->len == 0, G_IO_STATUS_ERROR); g_return_val_if_fail (channel->partial_write_buf[0] == '\0', G_IO_STATUS_ERROR); @@ -1015,6 +1015,19 @@ g_io_channel_set_encoding (GIOChannel *channel, if (channel->write_cd != (GIConv) -1) g_iconv_close (channel->write_cd); + if (channel->encoded_read_buf && channel->encoded_read_buf->len > 0) + { + g_assert (!did_encode); /* Encoding UTF-8, NULL doesn't use encoded_read_buf */ + + /* This is just validated UTF-8, so we can copy it back into read_buf + * so it can be encoded in whatever the new encoding is. + */ + + g_string_prepend_len (channel->read_buf, channel->encoded_read_buf->str, + channel->encoded_read_buf->len); + g_string_truncate (channel->encoded_read_buf, 0); + } + channel->read_cd = read_cd; channel->write_cd = write_cd; @@ -1087,16 +1100,16 @@ g_io_channel_fill_buffer (GIOChannel *channel, if (channel->encoded_read_buf) oldlen = channel->encoded_read_buf->len; else - oldlen = 0; + { + oldlen = 0; + channel->encoded_read_buf = g_string_sized_new (channel->buf_size); + } if (channel->do_encode) { size_t errnum, inbytes_left, outbytes_left; gchar *inbuf, *outbuf; - if (!channel->encoded_read_buf) - channel->encoded_read_buf = g_string_sized_new (channel->buf_size); - reencode: inbytes_left = channel->read_buf->len; @@ -1247,7 +1260,7 @@ g_io_channel_read_line (GIOChannel *channel, { GString *use_buf; - if (channel->do_encode) + if (channel->encoding) use_buf = channel->encoded_read_buf; else use_buf = channel->read_buf; @@ -1301,7 +1314,7 @@ g_io_channel_read_line_string (GIOChannel *channel, { GString *use_buf; - if (channel->do_encode) + if (channel->encoding) use_buf = channel->encoded_read_buf; else use_buf = channel->read_buf; @@ -1385,8 +1398,7 @@ read_again: { *length = 0; - if (channel->do_encode && channel->read_buf->len != 0) - /* using GIConv conversion, unconverted chars */ + if (channel->encoding && channel->read_buf->len != 0) { g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT, diff --git a/tests/iochannel-test.c b/tests/iochannel-test.c index 2b048d9..8678f31 100644 --- a/tests/iochannel-test.c +++ b/tests/iochannel-test.c @@ -87,17 +87,7 @@ gint main (gint argc, gchar * argv[]) if (length_out < buffer->len) g_warning ("Only wrote part of the line."); - do - status = g_io_channel_write_chars (gio_w, line_term, - line_term_len, &length_out, &gerr); - while (status == G_IO_STATUS_AGAIN); - if (status != G_IO_STATUS_NORMAL) - break; - - if (length_out < line_term_len) - g_warning ("Only wrote part of the line term."); - - g_print (": %s\n", buffer->str); + g_print ("%s", buffer->str); g_string_truncate (buffer, 0); } -- 2.7.4