Re: [Vala] Invalid C code in Interfaces
- From: Jan Hudec <bulb ucw cz>
- To: Abderrahim Kitouni <a kitouni gmail com>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Invalid C code in Interfaces
- Date: Mon, 4 Oct 2010 15:44:55 +0200
On Mon, Oct 04, 2010 at 12:00:44 +0100, Abderrahim Kitouni wrote:
Hi,
في ح، 03-10-2010 عند 19:30 -0400 ، كتب tecywiz121:
Hello again!
I seem to have run into a case where valac generates incorrect C code.
I'm sure what I am doing is wrong, but I assume that valac should emit
the error and not gcc.
Definitely, the rule of thumb is : if valac generates invalid C code
it's a bug, either in valac or (more likely) in the bindings.
When I try to compile this snippet,
public interface IFace<G> : Object
{
public G[] foobar()
{
G[] storage = new G[2];
return storage[0:1];
}
}
void main(){}
I get this error from gcc:
In function ‘iface_foobar’:
generic.vala.c:54: error: dereferencing pointer to incomplete type
The relevant C code is:
The problem is in self->priv->g_dup_func, interfaces cannot have fields,
but the codegen is assuming otherwise. If you make your interface an
abstract class, it works. Maybe this should be replaced with a property
access (using g_object_get) at least in interfaces.
This is internally generated field for generics. That means that generic
interfaces simply don't work yet.
Generic interfaces need a bit of special treatment. Since you don't
instantiate the interface but rather a class implementing it and the class
specifies for which type it supports the interface. So the dup_func and other
functions for handling generic argument should be for generic interfaces
replaced by autogenerated abstract functions in the interface. The class
implementing the interface would then implement them either by calling
similar generic handler it has or by calling appropriate function for
specific type.
So
public interface IFace<G> : Object
would automatically get
G g_dup_func(G x);
method and
public class Concrete : Object, IFace<Object>
would automatically imlpement as (using C for the body)
Object g_dup_func(Object x) { return g_object_ref(x); }
while
public class Generic<H> : Object, IFace<H>
would automatically implement as (using C for the body)
H g_dup_func(H x) { return self->priv->h_dup_func(x); }
--
Jan 'Bulb' Hudec <bulb ucw cz>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]