Passing a GObjectClass into a function (with GooCanvas2)

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

Passing a GObjectClass into a function (with GooCanvas2)

Zakariyya Mughal
Hello folks,

I am trying to use a function that takes a GObjectClass as an argument
and I'm not sure how to get that using Glib::Object::Introspection.

In particular, I am trying to use the class method
`goo_canvas_item_class_list_child_properties()`
<https://developer.gnome.org/goocanvas2/stable/GooCanvasItem.html#goo-canvas-item-class-list-child-properties>.

It doesn't work if I pass it an instance:

    0:main
    $ GooCanvas2::CanvasItem::class_list_child_properties( GooCanvas2::CanvasTable->new )
    (process:23169): GooCanvas-CRITICAL **: goo_canvas_item_class_list_child_properties: assertion 'G_IS_OBJECT_CLASS (iclass)' failed
    []

Or if I pass it the type name of the instance class or the derived GObjectClass

    0:main
    $ GooCanvas2::CanvasItem::class_list_child_properties( 'GooCanvas2::CanvasTable' )
    Runtime error: need a hash ref to convert to struct of type ObjectClass at (eval 438) line 5.
    0:main
    $ GooCanvas2::CanvasItem::class_list_child_properties( 'GooCanvas2::CanvasTableClass' )
    Runtime error: need a hash ref to convert to struct of type ObjectClass at (eval 440) line 5.

I noticed that the Python GIR bindings are able to work by doing

    In [2]: from gi.repository import GooCanvas; GooCanvas.CanvasItem.class_list_child_properties( GooCanvas.CanvasTable )
    Out[2]:
    [<GParamDouble 'left-padding'>,
     <GParamDouble 'right-padding'>,
     <GParamDouble 'top-padding'>,
     <GParamDouble 'bottom-padding'>,
     <GParamDouble 'x-align'>,
     <GParamDouble 'y-align'>,
     <GParamUInt 'row'>,
     <GParamUInt 'column'>,
     <GParamUInt 'rows'>,
     <GParamUInt 'columns'>,
     <GParamBoolean 'x-expand'>,
     <GParamBoolean 'x-fill'>,
     <GParamBoolean 'x-shrink'>,
     <GParamBoolean 'y-expand'>,
     <GParamBoolean 'y-fill'>,
     <GParamBoolean 'y-shrink'>]


I noticed that Gtk3.pm has overrides for a similar class method in
`Gtk3::ContainerClass::list_child_properties` <https://developer.gnome.org/gtk3/stable/GtkContainer.html#gtk-container-class-list-child-properties>,
<https://metacpan.org/source/XAOC/Gtk3-0.032/lib/Gtk3.pm#L993>,
but that works fine with the name of the container class.

    0:main
    $ 0 + @{ Gtk3::ContainerClass::list_child_properties( 'Gtk3::Table' ) }
    8

In case it helps, I noticed that that GIR XML differs in that
`gtk_container_class_list_child_properties` specifies a <method> but
`goo_canvas_item_class_list_child_properties` specifies a <function>.

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

Re: Passing a GObjectClass into a function (with GooCanvas2)

"Torsten Schönfeld"
On 01.10.2017 23:12, Zakariyya Mughal wrote:
> In case it helps, I noticed that that GIR XML differs in that
> `gtk_container_class_list_child_properties` specifies a <method> but
> `goo_canvas_item_class_list_child_properties` specifies a <function>.

That case was indeed not handled.  gtk+ represents the class struct
function as a method of the class struct, whereas goocanvas uses a
function of the object/interface from the class struct.

Please try again with this change:
<https://git.gnome.org/browse/perl-Glib-Object-Introspection/commit/?id=ac5409fff68705e144a16f973cce0e180dae1f6a>.
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Passing a GObjectClass into a function (with GooCanvas2)

Zakariyya Mughal
On 2017-10-02 at 14:03:33 +0200, Torsten Schoenfeld wrote:

> On 01.10.2017 23:12, Zakariyya Mughal wrote:
> > In case it helps, I noticed that that GIR XML differs in that
> > `gtk_container_class_list_child_properties` specifies a <method> but
> > `goo_canvas_item_class_list_child_properties` specifies a <function>.
>
> That case was indeed not handled.  gtk+ represents the class struct
> function as a method of the class struct, whereas goocanvas uses a
> function of the object/interface from the class struct.
>
> Please try again with this change:
> <https://git.gnome.org/browse/perl-Glib-Object-Introspection/commit/?id=ac5409fff68705e144a16f973cce0e180dae1f6a>.

This change does fix the issue, but seems to have uncovered another
issue:

Using `GooCanvas2::CanvasItem::class_list_child_properties` works:

    perl -MGlib::Object::Introspection -MData::Dumper \
        -E 'Glib::Object::Introspection->setup( basename => "GooCanvas", version => "2.0", package => "GooCanvas2" );
        my @p = GooCanvas2::CanvasItem::class_list_child_properties( "GooCanvas2::CanvasTable" );
        say Dumper @p'

gives

    $VAR1 = [
              bless( {
                       'type' => 'Glib::Double',
                       'owner_type' => 'GooCanvas2::CanvasTable',
                       'flags' => bless( do{\(my $o = 3)}, 'Glib::ParamFlags' ),
                       'name' => 'left-padding',
                       'descr' => 'Extra space to add to the left of the item'
                     }, 'Glib::Param::Double' ),
    [...snip...]

but using `GooCanvas2::CanvasItemModel::class_list_child_properties` does
not:

    perl -MGlib::Object::Introspection -MData::Dumper \
        -E 'Glib::Object::Introspection->setup( basename => "GooCanvas", version => "2.0", package => "GooCanvas2" );
        my @p = GooCanvas2::CanvasItemModel::class_list_child_properties( "GooCanvas2::CanvasTableModel" );
        say Dumper @p'

gives

    GLib-GObject-CRITICAL **: g_param_spec_ref: assertion 'G_IS_PARAM_SPEC (pspec)' failed at /home/zaki/perl5/perlbrew/perls/perl-5.20.3/lib/site_perl/5.20.3/x86_64-linux/Glib/Object/Introspection.pm line 67.
    GLib-GObject-CRITICAL **: g_param_spec_sink: assertion 'G_IS_PARAM_SPEC (pspec)' failed at /home/zaki/perl5/perlbrew/perls/perl-5.20.3/lib/site_perl/5.20.3/x86_64-linux/Glib/Object/Introspection.pm line 67.
    GLib-GObject-CRITICAL **: g_param_spec_get_name: assertion 'G_IS_PARAM_SPEC (pspec)' failed at /home/zaki/perl5/perlbrew/perls/perl-5.20.3/lib/site_perl/5.20.3/x86_64-linux/Glib/Object/Introspection.pm line 67.
    GLib-GObject-CRITICAL **: g_param_spec_get_blurb: assertion 'G_IS_PARAM_SPEC (pspec)' failed at /home/zaki/perl5/perlbrew/perls/perl-5.20.3/lib/site_perl/5.20.3/x86_64-linux/Glib/Object/Introspection.pm line 67.
    unhandled paramspec type (null), falling back to Glib::ParamSpec at /home/zaki/perl5/perlbrew/perls/perl-5.20.3/lib/site_perl/5.20.3/x86_64-linux/Glib/Object/Introspection.pm line 67.
    [...snip...]
    Bus error


I think it has to do with a possible bug in the GooCanvas annotations
where they specify the return type of `GParamSpec**` as having
`(element-type GObject.ParamSpec)` despite the return type not using a
container type like `GSList*`. To compare, see:

- `goo_canvas_item_class_list_child_properties` <https://git.gnome.org/browse/goocanvas/tree/src/goocanvasitem.c?id=cd1ad0f66ded84901f77519434191ae108dadace#n2377>

- `goo_canvas_item_model_class_list_child_properties` <https://git.gnome.org/browse/goocanvas/tree/src/goocanvasitemmodel.c?id=cd1ad0f66ded84901f77519434191ae108dadace#n1155>

I recompiled GooCanvas without the `element-type` annotation on
`goo_canvas_item_model_class_list_child_properties` and the error
goes away. Perhaps the semantics of using `element-type` need to be
restricted or clarified?

Regards,
- Zaki Mughal

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

Re: Passing a GObjectClass into a function (with GooCanvas2)

"Torsten Schönfeld"
On 03.10.2017 00:46, Zakariyya Mughal wrote:

> I think it has to do with a possible bug in the GooCanvas annotations
> where they specify the return type of `GParamSpec**` as having
> `(element-type GObject.ParamSpec)` despite the return type not using a
> container type like `GSList*`. To compare, see:
>
> - `goo_canvas_item_class_list_child_properties` <https://git.gnome.org/browse/goocanvas/tree/src/goocanvasitem.c?id=cd1ad0f66ded84901f77519434191ae108dadace#n2377>
>
> - `goo_canvas_item_model_class_list_child_properties` <https://git.gnome.org/browse/goocanvas/tree/src/goocanvasitemmodel.c?id=cd1ad0f66ded84901f77519434191ae108dadace#n1155>
>
> I recompiled GooCanvas without the `element-type` annotation on
> `goo_canvas_item_model_class_list_child_properties` and the error
> goes away. Perhaps the semantics of using `element-type` need to be
> restricted or clarified?

Yes, the annotation seems to be incorrect.  It makes
gobject-introspection think that the returned value is a flat array of
GParamSpec structs, while in fact it is an array of pointers to
GParamSpec structs.  In the *.gir file, the difference is:

  <type name="GObject.ParamSpec"/>

versus

  <type name="GObject.ParamSpec" c:type="GParamSpec*"/>

Can you bring this to the attention of the GooCanvas developers?

While you're at it, please also mention that the ownership annotation
for the return value of goo_canvas_item_class_list_child_properties
seems to be incorrect.  It currently says "transfer full" (which means
the array elements and the array itself can be freed), but the
implementation suggests that "transfer container" would be correct.
(goo_canvas_item_model_class_list_child_properties gets this right.)
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list