GNOME Bugzilla – Bug 704165
GLib.IOChannel read_unichar() fails
Last modified: 2015-02-07 16:58:00 UTC
There appears to be a problem with gobject introspection for GLib read_unichar (g_io_channel_read_unichar). This code: ios = ioc.read_unichar(theChar); Produces this error: Expected type gunichar for Argument 'thechar' but got type 'undefined' (nil) This code works properly: ios = ioc.write_unichar(contents[i]); The gir looks inconsistent to me. <method name="read_unichar" <parameter name="thechar" transfer-ownership="none"> <type name="gunichar" c:type="gunichar*"/> <method name="write_unichar" <parameter name="thechar" transfer-ownership="none"> <type name="gunichar" c:type="gunichar"/> From the glib doc: GIOStatus g_io_channel_read_unichar (GIOChannel *channel, gunichar *thechar, GError **error); From the gir: <method name="read_unichar" c:identifier="g_io_channel_read_unichar" throws="1"> <doc xml:whitespace="preserve">Reads a Unicode character from @channel. This function cannot be called on a channel with %NULL encoding.</doc> <return-value transfer-ownership="none"> <doc xml:whitespace="preserve">a #GIOStatus</doc> <type name="IOStatus" c:type="GIOStatus"/> </return-value> <parameters> <parameter name="thechar" transfer-ownership="none"> <doc xml:whitespace="preserve">a location to return a character</doc> <type name="gunichar" c:type="gunichar*"/> </parameter> </parameters> </method> From the glib doc: GIOStatus g_io_channel_write_unichar (GIOChannel *channel, gunichar thechar, GError **error); From the glib gir: <method name="write_unichar" c:identifier="g_io_channel_write_unichar" throws="1"> <doc xml:whitespace="preserve">Writes a Unicode character to @channel. This function cannot be called on a channel with %NULL encoding.</doc> <return-value transfer-ownership="none"> <doc xml:whitespace="preserve">a #GIOStatus</doc> <type name="IOStatus" c:type="GIOStatus"/> </return-value> <parameters> <parameter name="thechar" transfer-ownership="none"> <doc xml:whitespace="preserve">a character</doc> <type name="gunichar" c:type="gunichar"/> </parameter> </parameters> </method> Extract of the code that fails running under gjs. I have duplicated the failure under Fedora 18 GS3.6 and Fedora 19 GS3.8. The following is the code extracted from functions in my javascript source. Fails... try { let contents = ''; let theChar; let ioc = GLib.IOChannel.new_file(this._path, 'r'); if(ioc == null) throw new Error(_("Could not open")); while(true) { ios = ioc.read_unichar(theChar); if(ios == GLib.IOStatus.EOF) break; if(ios != GLib.IOStatus.NORMAL) throw new Error(_("Could not read")); contents = contents + theChar; } } catch(e) { let message = e.message + ' : ' + this._path; this._showError(message, null); return null; } return(contents); Works... try { let contents = ''; let ioc = GLib.IOChannel.new_file(this._path, 'w'); if(ioc == null) throw new Error(_("Could not open")); for(let key in array) { let value = array[key]; if(value == '=') value = key; else value = key + '=' + value; contents = contents + value + '\n'; } let ios; for (let i = 0; i < contents.length; i++) { ios = ioc.write_unichar(contents[i]); if(ios != GLib.IOStatus.NORMAL) throw new Error(_("Could not write")); } ioc.flush(); } catch(e) { let message = e.message + ' : ' + this._path; this._showError(message, null); return false; } return true; I tried assigning a value to theChar such as let theChar = 'AA'; The result is a core dump. It seems to me that <type name="gunichar" c:type="gunichar*"/> cannot equal <type name="gunichar" c:type="gunichar"/> without some work. If this is not a bug please provide a working example of read_unichar(). If the bug has already been reported I could not find it.
Created attachment 251775 [details] [review] giochannel: Add an out annotation for g_io_channel_read_unichar() Since it's an output variable.
Review of attachment 251775 [details] [review]: OK.
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]