On Thu, Jul 10, 2008 at 7:29 PM, Andreas Sliwka
<[EMAIL PROTECTED]> wrote:
> On Wed, Jul 9, 2008 at 6:37 PM, Michael Lawrence <[EMAIL PROTECTED]> wrote:
>> Maybe something like object.get_type().class_peek()? But perhaps there's a
>> shorter way...
> Doesn't work for me:
>
> $ cat <<END_OF_SOURCE >list_prop.vala ; valac list_prop.vala && ./list_prop
> /* list_prop.vala */
> using GLib;
> public class Foo : Object {
>   public string name ;
>   public int count;
>   static void main (string[] args) {
>       Object foo = new Foo();
>       var typ = foo.get_type();
>       stdout.printf( "type = %s\n", typ.qname().to_string());
>       var cls = typ.class_peek();
>       var obj = (ObjectClass)cls ;
>       foreach (var prp in obj.list_properties()) {
>           stdout.printf( "  prp = %p\n" , prp);
>       }
>   }
> }
> END_OF_SOURCE
>
> list_prop.c: In function 'foo_main':
> list_prop.c:29: warning: passing argument 1 of 'g_type_class_ref'
> makes integer from pointer without a cast
> list_prop.c:31: warning: passing argument 1 of 'g_type_class_ref'
> makes integer from pointer without a cast
> type = Foo
>
> (process:1160): GLib-GObject-WARNING **: cannot retrieve class for
> invalid (unclassed) type `(null)'
>
> (process:1160): GLib-GObject-CRITICAL **:
> g_object_class_list_properties: assertion `G_IS_OBJECT_CLASS (class)'
> failed
>
> So is this a bug in vala? Or rather a missing functionality in GLib/GTK+ ?

It seems like that is a bug in Vala. In the glib bindings
(glib-2.0.vapi), TypeClass's ref function is given as
g_type_class_ref, which doesn't work because (quite unusually)
g_type_class_ref takes a Type argument, not a TypeClass.

I can't see any workaround for this. Perhaps it would be useful to
have a new method in Object, something like

public class Object : TypeInstance {
    ...

    [CCode (cname = "G_OBJECT_GET_CLASS")]
    ObjectClass get_class ();

    ...
}

You should report this in Bugzilla. In general, any incorrect code
should produce error/warning messages in valac, not gcc, so if you
ever see gcc messages then there is probably a bug in valac.

>
> Be seeing you,
>
> Andreas Sliwka
> _______________________________________________
> Vala-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/vala-list
>
>
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to