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 737978 - g_iconv() should not be introspectable
g_iconv() should not be introspectable
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: i18n
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-10-06 07:35 UTC by Mikhail Zabaluev
Modified: 2015-10-06 15:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Added function g_iconv_convert() (5.49 KB, patch)
2014-10-06 07:37 UTC, Mikhail Zabaluev
none Details | Review
Make g_iconv() non-introspectable (1.08 KB, patch)
2014-10-06 07:37 UTC, Mikhail Zabaluev
none Details | Review
Bikeshed the order of parameters on g_iconv_convert() (3.67 KB, patch)
2014-10-06 17:58 UTC, Mikhail Zabaluev
none Details | Review
Make g_iconv() non-introspectable (1.03 KB, patch)
2014-10-07 23:40 UTC, Mikhail Zabaluev
none Details | Review

Description Mikhail Zabaluev 2014-10-06 07:35:34 UTC
The parameter signature of g_iconv(), if annotated to reflect the intended usage, would make almost every binding generator cringe and touch a few unspecified corners of GObject introspection (like the ownership transfer question discussed in bug #630788). It would seem better to make g_iconv() non-introspectable and provide another wrapper function to disentangle input and output parameters.
Comment 1 Mikhail Zabaluev 2014-10-06 07:37:20 UTC
Created attachment 287813 [details] [review]
Added function g_iconv_convert()

This might be easier to generate bindings for than g_iconv().
Comment 2 Mikhail Zabaluev 2014-10-06 07:37:27 UTC
Created attachment 287814 [details] [review]
Make g_iconv() non-introspectable

To introspect the parameters of g_iconv() with any pretense of
accurateness, one would have to use Christmas tree annotations
like (inout) (nullable) (optional) (array length=inbytes_left),
and solve the riddle of ownership transfer modes as applied to
inout parameters. That would make binding generators flee in panic.

Now saner, cuter, g_iconv_convert() is provided instead.
Comment 3 Mikhail Zabaluev 2014-10-06 07:47:32 UTC
(In reply to comment #1)
> Created an attachment (id=287813) [details] [review]
> Added function g_iconv_convert()

The parameters could be reshuffled so that each output parameter follows its respective array parameters, if that order looks better.
Comment 4 Mikhail Zabaluev 2014-10-06 17:58:11 UTC
Created attachment 287873 [details] [review]
Bikeshed the order of parameters on g_iconv_convert()

It's perhaps more intuitive if each output parameter follows
its respective array parameters.
Comment 5 Allison Karlitskaya (desrt) 2014-10-07 12:49:22 UTC
Do you have a specific usecase for iconv from a bound language?

These days I've found this 'full strength' iconv API to be pretty much only used for:

 - conversion to/from the user's locale and utf8 (which is 99%
   of the time a no-op)

 - transliteration from utf8 to ascii (which we have better APIs to cover now)

Even at a stretch, we are probably only ever converting between utf8 and some other locale.

In pretty much every use case, as well, we only want to do this in one shot (ie: we don't need the streaming API).

Maybe we could benefit from creating a more constrained API.
Comment 6 Colin Walters 2014-10-07 12:59:51 UTC
(In reply to comment #5)
> Do you have a specific usecase for iconv from a bound language?

One of the many neat things about Rust is you can use it in a freestanding #[no_std] mode - it would be possible to write a library which was a hybrid of C and Rust, with the Rust code calling C for everything beyond pure computation/data structures, and not having any external dependencies.

Beyond that, I'm guessing Rust's libstd doesn't have iconv?

> In pretty much every use case, as well, we only want to do this in one shot
> (ie: we don't need the streaming API).

We do also have GCharsetConverter which can be used for streaming (albeit, this is all pretty heavyweight).
 
> Maybe we could benefit from creating a more constrained API.

Probably in addition?
Comment 7 Mikhail Zabaluev 2014-10-07 20:41:49 UTC
(In reply to comment #5)
> Do you have a specific usecase for iconv from a bound language?

No specific need for iconv. I want to ultimately generate Rust bindings for the entire GIR of the GLib libraries, so I'd like to avoid generation of wrong or unusable APIs with as little manual intervention as possible. The main problem is that many things get automatically mistyped as UTF-8 (Rust's built-in strings are UTF-8, so ultimately fast no-validation value transfer is possible from GLib to Rust as long as the string types are annotated correctly), and/or have no proper annotation for out parameters, nullability, and the like. I'm combing through GLib code to prepare a larger set of annotation patches to submit later (the WIP branch is meanwhile available at https://github.com/mzabaluev/glib/commits/wip/annotations).

g_iconv() just happens to be so weird that it's better not introspected at all, but it felt wrong to make the functionality inaccessible when there is an easy workaround. I lack the insight to tell if no other language binding would have a need for it. Rust certainly can have a more idiomatic direct binding for iconv any day someone wants to create it, and it's easy to do. So it's totally OK for the time being to live without introspectable GLib iconv access as far as I'm concerned.
Comment 8 Allison Karlitskaya (desrt) 2014-10-07 22:31:01 UTC
I'd prefer to just mark the API as non-introspectable then.  Colin: thoughts?
Comment 9 Mikhail Zabaluev 2014-10-07 23:40:16 UTC
Created attachment 288019 [details] [review]
Make g_iconv() non-introspectable

Erased the mention of g_iconv_convert() so that the patch can be
applied alone.
Comment 10 Mikhail Zabaluev 2015-10-06 15:40:00 UTC
I have now submitted a more thorough fix in bug #756128.