After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 52811 - Need encoding conversion for GIOChannel
Need encoding conversion for GIOChannel
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
1.3.x
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
patch proposed
: 52907 54903 (view as bug list)
Depends on:
Blocks: 53764
 
 
Reported: 2001-04-03 04:46 UTC by Owen Taylor
Modified: 2011-02-18 15:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
conbined patch for set_encoding, error checks, buffering, blocking vs non blocking (46.89 KB, patch)
2001-04-18 01:49 UTC, Hidetoshi Tajima
none Details | Review
testcase (10.97 KB, text/plain)
2001-04-19 16:52 UTC, Hidetoshi Tajima
  Details
makefile for gio_test.c testcase (153 bytes, text/plain)
2001-04-19 16:53 UTC, Hidetoshi Tajima
  Details
patch mentioned above (8.07 KB, patch)
2001-04-29 04:50 UTC, Ron Steinke
none Details | Review
patch with dynamic buffers (57.40 KB, patch)
2001-05-16 00:21 UTC, Ron Steinke
none Details | Review
g_io_channel_fill_buffer messy hack patch (1.29 KB, patch)
2001-05-18 16:59 UTC, Ron Steinke
none Details | Review
thread safety patch (11.10 KB, patch)
2001-05-18 17:03 UTC, Ron Steinke
none Details | Review
bug fix patch (8.63 KB, patch)
2001-05-27 15:57 UTC, Ron Steinke
none Details | Review
documentation patch (10.62 KB, patch)
2001-05-27 16:05 UTC, Ron Steinke
none Details | Review
new combined patch (74.51 KB, patch)
2001-06-08 15:38 UTC, Ron Steinke
none Details | Review
fill buffer patch (1.12 KB, patch)
2001-06-08 15:41 UTC, Ron Steinke
none Details | Review
corrected combined patch (71.55 KB, patch)
2001-06-10 15:45 UTC, Ron Steinke
none Details | Review
new version of patch (89.20 KB, patch)
2001-06-27 21:23 UTC, Ron Steinke
none Details | Review
test case source (3.82 KB, text/plain)
2001-06-27 21:26 UTC, Ron Steinke
  Details
(hopefully) unmangled patch (89.20 KB, patch)
2001-06-28 17:00 UTC, Ron Steinke
none Details | Review
small API patch (32.86 KB, patch)
2001-07-04 21:41 UTC, Ron Steinke
none Details | Review
finalize API and error handling patch (73.47 KB, patch)
2001-07-15 18:37 UTC, Ron Steinke
none Details | Review
sample iochannel-test-infile (62 bytes, text/plain)
2001-07-15 18:50 UTC, Ron Steinke
  Details

Description Owen Taylor 2001-04-03 04:46:23 UTC
(May be a duplicate, can't find the original though)

Conversion from external encodings to UTF-8 will be a fundamental
operation with GTK+-2.0, and we need to make it convenient

http://mail.gnome.org/archives/gtk-devel-list/2001-March/msg00399.html
Comment 1 Hidetoshi Tajima 2001-04-18 01:49:32 UTC
Created attachment 471 [details] [review]
conbined patch for set_encoding, error checks, buffering, blocking vs non blocking
Comment 2 Hidetoshi Tajima 2001-04-18 02:10:50 UTC
created an attachment as a proposed patch, giochannel.h has a set of
new g_io_channel functions to address those issues discussed on
the gtk-devel-list, containg:
	* charset code conversion at read/write, read/write by chars
	* buffering 
	* blocking vs non-blocking (controled by *set_flags/get_flags)
	* Reading a file a line at a time, Reading a whole file at once
	* error handling with more error feedbacks

Both API design and implementation are to be carefully reviewed. 
We really want someone of win32 to review and test the giowin32
backend
specifically, look at the errors returned by
g_io_win32_msg_[read,write] and 
give some sort of comments on what they should be.

Also, please advise me if I should post this patch on the mailing list
to
attract more people to review it.

Comment 3 Hidetoshi Tajima 2001-04-19 16:52:14 UTC
Created attachment 480 [details]
testcase
Comment 4 Hidetoshi Tajima 2001-04-19 16:53:06 UTC
Created attachment 481 [details]
makefile for gio_test.c testcase
Comment 5 Ron Steinke 2001-04-29 04:49:03 UTC
  I'm adding a small diff relative to the patch above
which:

1. Cleans up the handling of the backward compatibility
   of G_IO_ERROR a little.

2. Makes the character buffer arguments of the various
   write functions of type const gchar* instead of
   gchar*, fixing bug 52907.
Comment 6 Ron Steinke 2001-04-29 04:50:39 UTC
Created attachment 504 [details] [review]
patch mentioned above
Comment 7 Ron Steinke 2001-05-16 00:18:55 UTC
    This is a new version of the patch with some fairly extensive
changes. It now has it using dynamic buffering with GString, so
channel->buf_size ends up being more of a recomendation
than a fixed size. The buffer still won't get longer
than channel->buf_size + (size of the longest line in the file)
unless you have a lot of read/write errors.
    The dynamic buffering fixes several errors/issues.
Some of the improved functionality is:

1) It is possible in the new version to change the encoding type or
        buffer size in the middle of reading/writing.
2) It is also possible in the new version to have a file open
        for both reading and writing, while still using
        buffering.
3) Buffering is now safe for binary data (as long as you only use
        g_io_channel_read_chars, g_io_channel_write_chars, and
        g_io_channel_read_to_end).

I also added a function g_io_channel_seek_position to do
buffer-aware seeking. If anyone can think of a better name
for this function, I'd I'd be happy to hear it.
    One bit of functionality that I removed was the
ability to do unbuffered reads/writes which are encoded with
g_convert. Due to the possible presence of partial characters
in the input, I can't see a pratical way of doing encodng
on unbuffered data and still handling the errors sanely.
Fortunately, unbuffered read/write is probably most
useful for binary data, which doesn't need to be encoded
anyway. Setting the encoding to G_IO_CHANNEL_ENCODE_RAW
does raw read/write which is unbuffered, with two exceptions:

1) If you switch to G_IO_CHANNEL_ENCODE_RAW from another
        encoding in midstream, any data already in the
        buffer is handled before raw read/write to
        the channel begins.
2) The function g_io_channel_read_to_end still uses
        the buffer to read in the file contents. If
        an error occurs, any data already read in
        is left in the buffer.

Also, g_io_channel_read_line is unusable when the
encoding is G_IO_CHANNEL_ENCODE_RAW (as you would
expect for an encoding intended for binary data).
    The main work that needs to be done on this
functionality is still in giowin32.c. The new
code in that file has not even been compiled,
much less tested. The function stubs and whatnot
have been set up in such a way that, with luck,
everything will still compile on the first pass.
The things that need to be looked at are:

1) The conversion of the read, write, and seek
        functions from GIOError to GError. If
        there aren't any typos in the changes,
        the old API g_io_channel_[read,write,seek]
        should still work. The issue is making
        sure that the GError error message are
        sufficiently varied before the new API is
        set in stone. Since g_io_win32_fd_[read,write,seek]
        use errno, they are probably fine. Similarly,
        g_io_win32_no_seek should obviously return
        G_CHANNEL_ERROR_SPIPE (seeking not allowed on
        this kind of channel). For sockets,
        g_io_win32_sock_[read,write] look like
        they have errors that map 1 to 1 into
        errno, but it would be good to get confirmation
        on this from someone who knows something
        about windows. Something like g_channel_error_from_errno
        for WSAError (or whatever these are called)
        and use of the appropriate function analogus to
        strerror would also be nice. The real issue
        is with g_io_msg_[read,write]. The literal
        GIOError to GChannelError conversion I made is
        probably not really correct, so it would be
        good to find out what these errors really are.
2) Implementation of the backend for g_io_channel_new_from_file
        and g_io_channel_[set,get]_flags. At this point,
        they're compilation stubs.

Any feedback would be greatly appreciated.
Comment 8 Ron Steinke 2001-05-16 00:21:13 UTC
Created attachment 539 [details] [review]
patch with dynamic buffers
Comment 9 Ron Steinke 2001-05-18 16:57:18 UTC
    The next patch fixes up an ugly hack in
g_io_channel_fill_buffer. It depends on the
GString patch in bug 54903.
Comment 10 Ron Steinke 2001-05-18 16:59:04 UTC
Created attachment 545 [details] [review]
g_io_channel_fill_buffer messy hack patch
Comment 11 Ron Steinke 2001-05-18 17:02:10 UTC
    The next patch attempts to add some thread safety
to the buffering of GIOChannel. Attempting to read/write
the same channel from different threads will still
probably give you garbage, but at least now you
shouldn't hit any of the g_assert() calls in the code.
I don't really know anything about threads, so I
would appreciate it if someone could look this over.
The idea is to keep the internal state of the buffer
sane.
Comment 12 Ron Steinke 2001-05-18 17:03:10 UTC
Created attachment 546 [details] [review]
thread safety patch
Comment 13 Ron Steinke 2001-05-27 15:55:42 UTC
  This next patch fixes a few bugs and does some
cleanups to the online documentation.
Comment 14 Ron Steinke 2001-05-27 15:57:42 UTC
Created attachment 567 [details] [review]
bug fix patch
Comment 15 Ron Steinke 2001-05-27 16:01:49 UTC
    This next patch edits files in glib/docs/reference/glib,
specifically glib-sections.txt and tmpl/iochannels.sgml,
to do the non-inline part of the documentation. This
includes marking the old functions g_io_channel_[read,write,seek]
depricated, as well as the documentation for
g_io_channel_new_file(), which is difficult to place
inline since it is defined in both giounix.c and giowin32.c.
All the other new functions are documented inline.
Comment 16 Ron Steinke 2001-05-27 16:05:18 UTC
Created attachment 568 [details] [review]
documentation patch
Comment 17 Ron Steinke 2001-06-08 15:37:06 UTC
This is a new combined patch which has everything above except
for the g_io_channel_fill_buffer() patch which depends
on changes to GString. It also includes the new functions
g_io_channel_get_encoding() and g_io_channel_get_use_fallback(),
to match the corresponding set functions.
Comment 18 Ron Steinke 2001-06-08 15:38:34 UTC
Created attachment 624 [details] [review]
new combined patch
Comment 19 Ron Steinke 2001-06-08 15:40:41 UTC
The next patch contains the changes to g_io_channel_fill_buffer()
which depend on the changes to GString in bug 54903.
This is fortunately a small patch, and is a code cleanup
instead of a bug fix.
Comment 20 Ron Steinke 2001-06-08 15:41:53 UTC
Created attachment 625 [details] [review]
fill buffer patch
Comment 21 Ron Steinke 2001-06-09 15:45:34 UTC
*** Bug 52907 has been marked as a duplicate of this bug. ***
Comment 22 Ron Steinke 2001-06-10 15:44:31 UTC
    This is a replacement for the previous combined patch,
which reversed some unrelated patches due to confusion
in my source tree.
Comment 23 Ron Steinke 2001-06-10 15:45:33 UTC
Created attachment 636 [details] [review]
corrected combined patch
Comment 24 Ron Steinke 2001-06-27 21:21:52 UTC
  This is a new version of the patch which addresses
the issues raised in
http://mail.gnome.org/archives/gtk-devel-list/2001-April/msg00360.html
The major issue remaining is the win32 implementation,
which is still in the same state (completely unimplemented).
Comment 25 Ron Steinke 2001-06-27 21:23:52 UTC
Created attachment 689 [details] [review]
new version of patch
Comment 26 Ron Steinke 2001-06-27 21:24:58 UTC
    This is an updated version of the test code for
the newest version of the patch.
Comment 27 Ron Steinke 2001-06-27 21:26:25 UTC
Created attachment 690 [details]
test case source
Comment 28 Ron Steinke 2001-06-27 21:30:12 UTC
*** Bug 54903 has been marked as a duplicate of this bug. ***
Comment 29 Owen Taylor 2001-06-28 14:42:14 UTC
The latest patch is malformed - seems to be missing large
chunks :-( - not sure if this is a CVS
problem or a problem uploading the patch. If the patch
you have locally matches the patch available for download,
you might want to try using 'diff -r' between two trees
rather than cvs diff.

I'll try to check over the patch as well as I can with
what is in the patch.
Comment 30 Ron Steinke 2001-06-28 16:59:17 UTC
   The patch got mangled on upload, here's another try.
Comment 31 Ron Steinke 2001-06-28 17:00:24 UTC
Created attachment 692 [details] [review]
(hopefully) unmangled patch
Comment 32 Ron Steinke 2001-06-28 17:03:03 UTC
  The patch is still messed up. I'll have to find some other way
to get it out.
Comment 33 Ron Steinke 2001-06-28 17:13:40 UTC
    There is now a copy of the patch at
http://www.elfhame.net/~rsteinke/giochannel-june-17.2.diff
Comment 34 Owen Taylor 2001-06-30 15:29:20 UTC
This patch is now in CVS. There are still a couple
of API issues to fix up and a lot of non-API issues
that could use a bit of improvement:

http://mail.gnome.org/archives/gtk-devel-list/2001-June/msg00522.html

Probably individual bugs should be filed to track the
more important non-API issues once we get the API
stuff settled.
Comment 35 Ron Steinke 2001-07-04 21:40:47 UTC
  This is a small patch to fix up the API and
(hopefully) get win32 compiling.
Comment 36 Ron Steinke 2001-07-04 21:41:43 UTC
Created attachment 715 [details] [review]
small API patch
Comment 37 Ron Steinke 2001-07-15 18:35:56 UTC
    Another patch against CVS. This one includes Owen's
requested fixes to the API, and much better error handling.
The test code now uses an input file internal to
the tree (glib/tests/iochannel-test-infile). I'm
posting a sample input file separately from the patch,
but any appropriate file included at the right position
in the tree will work.
Comment 38 Ron Steinke 2001-07-15 18:37:39 UTC
Created attachment 743 [details] [review]
finalize API and error handling patch
Comment 39 Ron Steinke 2001-07-15 18:45:28 UTC
Bugzilla messed up the patch again (does it have some sort
of problem with longer files?) You can find the patch
at http://www.elfhame.net/~rsteinke/giochannel-july-15.diff
Comment 40 Ron Steinke 2001-07-15 18:50:20 UTC
Created attachment 744 [details]
sample iochannel-test-infile
Comment 41 Ron Steinke 2001-07-17 22:17:00 UTC
Most remaining issues listed as new bugs. See bug 57689, bug 57690,
bug 57691, bug 57692, bug 57694, and bug 57695.
Comment 42 Ron Steinke 2001-07-19 20:41:45 UTC
Additional new bugs, bug 57771 and bug 57773.
Comment 43 Owen Taylor 2001-08-04 14:12:59 UTC
Patch is now in, remaining issues are in separate bugs.