One more Gobject Introspection issue

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

One more Gobject Introspection issue

Stefan Salewski-2
GtkIconSize type is reported as plain gint, but it is an enum.

For this function all is correct, see last line of code segment:

      <method name="set_icon_size" c:identifier="gtk_toolbar_set_icon_size">
        <doc xml:space="preserve">This function sets the size of stock icons in the toolbar. You
can call it both before you add the icons and after they’ve been
added. The size you set will override user preferences for the default
icon size.

This should only be used for special-purpose toolbars, normal
application toolbars should respect the user preferences for the
size of icons.</doc>
        <return-value transfer-ownership="none">
          <type name="none" c:type="void"/>
        </return-value>
        <parameters>
          <instance-parameter name="toolbar" transfer-ownership="none">
            <doc xml:space="preserve">A #GtkToolbar</doc>
            <type name="Toolbar" c:type="GtkToolbar*"/>
          </instance-parameter>
          <parameter name="icon_size" transfer-ownership="none">
            <doc xml:space="preserve">The #GtkIconSize that stock icons in the toolbar shall have.</doc>
            <type name="IconSize" c:type="GtkIconSize"/>

But here, again see last line of code segment:

      <constructor name="new_from_icon_name"
                   c:identifier="gtk_image_new_from_icon_name"
                   version="2.6">
        <doc xml:space="preserve">Creates a #GtkImage displaying an icon from the current icon theme.
If the icon name isn’t known, a “broken image” icon will be
displayed instead.  If the current icon theme is changed, the icon
will be updated appropriately.</doc>
        <return-value transfer-ownership="none">
          <doc xml:space="preserve">a new #GtkImage displaying the themed icon</doc>
          <type name="Widget" c:type="GtkWidget*"/>
        </return-value>
        <parameters>
          <parameter name="icon_name"
                     transfer-ownership="none"
                     nullable="1"
                     allow-none="1">
            <doc xml:space="preserve">an icon name or %NULL</doc>
            <type name="utf8" c:type="const gchar*"/>
          </parameter>
          <parameter name="size" transfer-ownership="none">
            <doc xml:space="preserve">a stock icon size (#GtkIconSize)</doc>
            <type name="gint" c:type="GtkIconSize"/>

So ctype is GtkIconSize, but due to name="gint" I get from gobject-
introspection only plain gint=int32. Unfortunately there exists a few
functions with that bug, and it is some work fixing it manually. I will
investigate if there is a way to get the ctype from gobject-
introspection, but I think that that is not possible.

I think the problem is in the C header files, I have seen something
like (type int) for some function parameters with GtkIconSize data
type.

_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: One more Gobject Introspection issue

Phil Clayton-2
Have a look at
https://bugzilla.gnome.org/show_bug.cgi?id=601425

On 14/09/17 21:12, Stefan Salewski wrote:

> GtkIconSize type is reported as plain gint, but it is an enum.
>
> For this function all is correct, see last line of code segment:
>
>        <method name="set_icon_size" c:identifier="gtk_toolbar_set_icon_size">
>          <doc xml:space="preserve">This function sets the size of stock icons in the toolbar. You
> can call it both before you add the icons and after they’ve been
> added. The size you set will override user preferences for the default
> icon size.
>
> This should only be used for special-purpose toolbars, normal
> application toolbars should respect the user preferences for the
> size of icons.</doc>
>          <return-value transfer-ownership="none">
>            <type name="none" c:type="void"/>
>          </return-value>
>          <parameters>
>            <instance-parameter name="toolbar" transfer-ownership="none">
>              <doc xml:space="preserve">A #GtkToolbar</doc>
>              <type name="Toolbar" c:type="GtkToolbar*"/>
>            </instance-parameter>
>            <parameter name="icon_size" transfer-ownership="none">
>              <doc xml:space="preserve">The #GtkIconSize that stock icons in the toolbar shall have.</doc>
>              <type name="IconSize" c:type="GtkIconSize"/>
>
> But here, again see last line of code segment:
>
>        <constructor name="new_from_icon_name"
>                     c:identifier="gtk_image_new_from_icon_name"
>                     version="2.6">
>          <doc xml:space="preserve">Creates a #GtkImage displaying an icon from the current icon theme.
> If the icon name isn’t known, a “broken image” icon will be
> displayed instead.  If the current icon theme is changed, the icon
> will be updated appropriately.</doc>
>          <return-value transfer-ownership="none">
>            <doc xml:space="preserve">a new #GtkImage displaying the themed icon</doc>
>            <type name="Widget" c:type="GtkWidget*"/>
>          </return-value>
>          <parameters>
>            <parameter name="icon_name"
>                       transfer-ownership="none"
>                       nullable="1"
>                       allow-none="1">
>              <doc xml:space="preserve">an icon name or %NULL</doc>
>              <type name="utf8" c:type="const gchar*"/>
>            </parameter>
>            <parameter name="size" transfer-ownership="none">
>              <doc xml:space="preserve">a stock icon size (#GtkIconSize)</doc>
>              <type name="gint" c:type="GtkIconSize"/>
>
> So ctype is GtkIconSize, but due to name="gint" I get from gobject-
> introspection only plain gint=int32. Unfortunately there exists a few
> functions with that bug, and it is some work fixing it manually. I will
> investigate if there is a way to get the ctype from gobject-
> introspection, but I think that that is not possible.
>
> I think the problem is in the C header files, I have seen something
> like (type int) for some function parameters with GtkIconSize data
> type.
>
> _______________________________________________
> gtk-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-list
>

_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: One more Gobject Introspection issue

Stefan Salewski-2
On Fri, 2017-09-15 at 09:57 +0100, Phil Clayton wrote:
> Have a look at
> https://bugzilla.gnome.org/show_bug.cgi?id=601425

Great, thanks.

I had looked only into the list of gobject-introspection bugs mentioned
at the bottom of this page:

https://wiki.gnome.org/action/show/Projects/GObjectIntrospection?action=show&redirect=GObjectIntrospection


_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: One more Gobject Introspection issue

Emmanuele Bassi
In reply to this post by Stefan Salewski-2
On 14 September 2017 at 21:12, Stefan Salewski <[hidden email]> wrote:
> GtkIconSize type is reported as plain gint, but it is an enum.

It's an "extensible" enumeration, like GtkResponseType for GtkDialog:
the API accepts an integer, because app and library developers can
register their own icon sizes, but GTK+ provides default icon sizes
out of the box.

It's a relatively unused functionality, these days.

> But here, again see last line of code segment:

>           <parameter name="size" transfer-ownership="none">
>             <doc xml:space="preserve">a stock icon size (#GtkIconSize)</doc>
>             <type name="gint" c:type="GtkIconSize"/>

All API that takes a GtkIconSize should have a `type int` annotation.
How you handle the translation between an enumeration value and an
integer is entirely up to your language binding; the Perl bindings,
for instance, have additional code that allows transforming strings
(and array of strings, for bitmasks) into integer values, whereas the
Python bindings simply turn enumeration names into integers after
resolving their name from "Namespace.TypeName.VALUE" to
"NAMESPACE_TYPENAME_VALUE". In both cases, integers are passed through
as they are, given that enumeration values in C are by definition
integers.

Ciao,
 Emmanuele.

--
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: One more Gobject Introspection issue

Stefan Salewski-2
On Fri, 2017-09-15 at 10:28 +0100, Emmanuele Bassi wrote:
> All API that takes a GtkIconSize should have a `type int` annotation.

Thanks. I learned that already from the reply of Mr. Phil Clayton.

Seems that some functions like gtk_toolbar_set_icon_size() do not yet
have a `type int` annotation.

Passing ints as parameters have the disadvantages, that people may try
to pass true size like 64 and wonder why it does not work. I can
remember someone who has done that indeed.

And gtk-icon-size-register()

https://developer.gnome.org/gtk3/stable/gtk3-Themeable-Stock-Images.html#gtk-icon-size-register

seems to be deprecated now.

I have a customer who is porting his GTK2 application to Nim GTK3 high
level GTK API -- he reported that issue. Currently he has to convert
the Nim enums to int when passing the parameters like IconSize.menu.ord
where .ord does the conversion to int. I think I will let it as it is
for now, thanks.

_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list