From: "mar...@saepia.net" <mar...@saepia.net>
 Sent: Sunday, 12 June 2016, 18:39
 Subject: [Vala] How to set custom free function for an array?
   
I am struggling to properly handle jack_get_ports (
http://jackaudio.org/files/docs/html/group__PortSearching.html).

It returns const char **, but has to be freed by a dedicated jack_free
function instead of generic vala free func for arrays.

How can I handle this properly in Vala?



I would try:
[CCode(array_null_terminated = true, free_function = "jack_free")]public 
string[] get_ports( string port_name, string type_name, long flags )
This is untested, so I would like to know if it works. I am slowly updating the 
bindings docs and I had the same question.
My reasoning is as follows:
Under https://wiki.gnome.org/Projects/Vala/LegacyBindings#Arrays it states "For 
a return value, the CCode attribute of the method controls the array's 
binding." So that is why the array_null_terminated = true goes where it does. 
By extension the attribute detail for the free function should go in the same 
place.
A few days ago I added a "Memory Management Binding Needed?" column to the 
table in 
https://wiki.gnome.org/action/recall/Projects/Vala/LegacyBindings#Binding_to_C_Heap_Handlers
 Previously the table just said "Array - Singly Owned", so I made a logical 
leap and thought the attribute detail would be "free_function" like a singly 
owned class. It would be good to have confirmation of this. If it is not then 
it probably means digging in the Vala source to see if there is anything 
already there before submitting a bug report and at a later date a patch.
I hope that works,
Al


   
 
_______________________________________________
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to