[Vala] Feature suggestion for VAPIs



Hello

Say there is a structure defined in vapi file like this:

namespace FooLib
{       [CCode (destroy_function = "foo_destroy", cname = "foo_t", cprefix =
"foo_")]
        public struct Foo
        {       public Foo();
        }
}

When such structure is assigned to another variable, Vala duplicates it
with function called "foo_copy", where "foo_" is specified cprefix. Vala
thinks that this function is defined by underlying C library and has
exactly the following signature:

void foo_copy(foo_t &copy_from, foo_t &copy_to);

Usually there is some function(s) for copying structures in almost all
libraries, but rarely they fit what Vala expects.

To implement wrapper around copy_function in vapi file there's no need
to embed parts of C program, because Vala can generate C by itself.

namespace FooLib
{       [CCode (destroy_function = "foo_destroy", cname = "foo_t", cprefix =
"foo_")]
        public struct Foo
        {
                public Foo();
                
                [CCode (cname = "foo_copy")]
                private inline static void foo_copy(Foo from, Foo to)
                {
                }
        }
}

Theoretically this must produce function called "foo_copy", which Vala
will happily using. But actually this function is eliminated by valac in
case it's not called from inside program (which uses this vapi).

I'm quite new in Vala and possibly i'm missing some good solution. A
kind of solution that i expect to be in Vala is something like this:

namespace FooLib
{       [CCode (destroy_function = "foo_destroy", cname = "foo_t", cprefix =
"foo_")]
        public struct Foo
        {
                public Foo();
                
                [CCode (is_copy_function = true)]
                private inline static void foo_copy(Foo from, Foo to)
                {
                }
        }
}

The same way it'd be great to have is_init_function, etc.

Regards




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