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 704165 - GLib.IOChannel read_unichar() fails
GLib.IOChannel read_unichar() fails
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
1.36.x
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2013-07-13 19:10 UTC by Norman Smith
Modified: 2015-02-07 16:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
giochannel: Add an out annotation for g_io_channel_read_unichar() (873 bytes, patch)
2013-08-15 22:25 UTC, Colin Walters
accepted-commit_now Details | Review

Description Norman Smith 2013-07-13 19:10:14 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.
Comment 1 Colin Walters 2013-08-15 22:25:28 UTC
Created attachment 251775 [details] [review]
giochannel: Add an out annotation for g_io_channel_read_unichar()

Since it's an output variable.
Comment 2 Jasper St. Pierre (not reading bugmail) 2013-08-15 23:43:35 UTC
Review of attachment 251775 [details] [review]:

OK.
Comment 3 André Klapper 2015-02-07 16:58:00 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]