Abstract string properties with getter/setter functions



Hi there,

While implementing abstract properties in Vala we encountered a problem
regarding string properties with getter and setter functions:

public interface Test.MyIface {
	public abstract string text { get; }
}

A getter function of an abstract string property looks like:
char* test_my_iface_get_text (TestMyIface* self) {
        char* value;
        g_object_get (G_OBJECT (self), "text", &value, NULL);
        return value;
}

Property accessors in Vala always return weak references. This leads to
a memory leak in the calling function of the getter.

We want property accessors to return weak references so just redefine
the accessors to return a strong reference is only a last-resort-option.

Since we do not see a way around this (yet) and we could not find an
example with strings in another project. I'm asking here if there is a
nice way around this.

BTW: There are equal issues with properties returning objects only there
you can add a hack into the getter unrefing the object before returning
it. This is not applicable with strings.

cheers,
Raffaele




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]