arteymix / numeric-glib

Numeric data types for GLib via GCC extensions
GNU Lesser General Public License v3.0
9 stars 2 forks source link

Can't use decimal128 for properties in a class inheriting from GLib.Object #14

Open jtrees opened 4 years ago

jtrees commented 4 years ago

It seems decimal128 can't be used for properties in classes inheriting from GLib.Object.

Failing Code

public class Foo : GLib.Object {
    public Numeric.decimal128 bar {
        get { return 0; }
    }
}

Error Output

numeric-glib-1.0.vapi:131.2-131.25: error: The type `Numeric.decimal128` doesn't declare a GValue set function
    public struct decimal128

Working Code

public class Foo {
    public Numeric.decimal128 bar {
        get { return 0; }
    }
}
arteymix commented 4 years ago

It's a boxed type, so it should work. It might be missing CCode attributes in the VAPI.

arteymix commented 4 years ago

We have to set set_value_function to g_boxed_set_value. However, they are declared as value types, which means we need to tell Vala to use a reference. I'll figure this out.

arteymix commented 4 years ago

It turns out to be more complicated than I expected because Vala view those types as value-type so it does not take a reference or indirect a pointer around GValue get/set calls.

For types that fit in a pointer (8 bytes or less), we can do a very nice trick of storing the value in the boxed pointer.

For 80 and 128 bit types, it's going to be trickier because we can't make a copy without leaking memory. I think it can be done with some macro tricks.

I'll add numeric_value_get_{type} and numeric_value_set_{type} definitions to mimic GValue API but for numeric types.

arteymix commented 4 years ago

I still want to address the memory leak and the pointer optimization.