On Sun, 2016-09-11 at 16:30 +0000, Gergely Polonkai wrote:
Should not that be (Descriptor instance, ulong port, double? dataLocation) instead? Using asterisk in Vala seems unnatural to me…
In general, you shouldn't use pointers in Vala. In general if you're using a pointer you're doing it wrong. The major use case for pointers is when you want to opt-out of Vala's automatic memory management, typically because the C API is too weird for Vala to handle automatically. That's why you see lots of pointers in libxml2. In general, marking a parameter as nullable (?) or as a reference (ref) or output (out) is the right way to go, but usually even that isn't necessary. Everything except SimpleType structs are passed as pointers anyways, so usually you only need to use ?/ref/out to describe the semantics of the parameter (i.e., can the value be null, or is it an in/out or out parameter). That said, LADSPA looks like somewhere a pointer would actually be appropriate, though not where you used it. The LADSPA_Handle instances should probably be a pointer because there is no way to tell Vala how to free it (you need to do something like `descriptor.cleanup(instance)`). Anyways, I would probably bind this as something like [Compact, CCode (cname = "void")] public class Handle { // ... } [CCode (has_target = false)] public delegate LADSPA.Handle* DescriptorInstantiate( Descriptor descriptor, ulong sample_rate); public struct Descriptor { [CCode (cname = "UniqueID")] public ulong unique_id; [CCode (cname = "Label")] public unowned string label; // ... public LADSPA.DescriptorInstantiate instantiate; } Note that the string is unowned; AFAICT they should all be. That means you don't need to do anything special for the copy and destroy functions.
On Sun, Sep 11, 2016, 18:09 Victor Aurélio Santos < victoraur santos gmail com> wrote:What I've tried: [CCode (copy_function="", destroy_function="")] public struct Descriptor { public ulong UniqueID; public const char[] Label; public Properties Properties; public const char[] Name; public const char[] Maker; public const char[] Copyright; public ulong PortCount; public const PortDescriptor[] PortDescriptors; public const char[,] PortNames; public const PortRangeHint[] PortRangeHints; public void[] ImplementationData; public Descriptor instantiate(Descriptor* descriptor, ulong sampleRate); [CCode (has_target = false)] public delegate void connect_port(Descriptor* instance, ulong port, double* dataLocation); public void activate(Descriptor* instance); public void run(Descriptor* instance, ulong sampleCount); public void run_adding(Descriptor* instance, ulong sampleCount); public void set_run_adding_gain(Descriptor* instance, Data gain); public void deactivate(Descriptor* instance); public void cleanup(Descriptor* instance); } The valac complaints: LADSPA.vapi:52.9-52.41: error: unexpected declaration public delegate void connect_port(Descriptor* instance, ulong port, double* dataLocation); 2016-09-10 20:18 GMT-03:00 Al Thomas <astavale yahoo co uk>:From: Victor Aurélio Santos <victoraur santos gmail com> Sent: Saturday, 10 September 2016, 23:57 Subject: Re: [Vala] LADSPA bindingsI'm trying to use plugins from vala, not to write! I'm stuck at writing the vapi file, most specifically at the Descriptorstruct.Take a look athttps://wiki.gnome.org/Projects/Vala/LegacyBindings#Binding_a_C_Str uct.27s_FieldsThe function pointers are targetless delegates. There is no memory handling for the struct so I don't think it should be bound as a compact class.-- Victor Aurélio Santos _______________________________________________ vala-list mailing list vala-list gnome org https://mail.gnome.org/mailman/listinfo/vala-list_______________________________________________ vala-list mailing list vala-list gnome org https://mail.gnome.org/mailman/listinfo/vala-list
Attachment:
signature.asc
Description: This is a digitally signed message part