[Vala] Implicit array size for function allocating an array
Hello, I'm trying to bind a C function which has the following prototype: int sos_addresses_to_string(const struct sos_address *addresses, char ***string_addresses, int nb); It's job is to convert an array of addresses, into an array of their string representation. So both the addresses array (in input) and the string_addresses array will have the same size which is nb. So in output, string_addresses will point to an allocated array of allocated char buffers. I tried to bind it this way: namespace Sos { public struct Address { ... public static int array_to_string([CCode (array_length_pos = 3)] Address addresses[], [CCode (array_length = false] out string[] string_addresses); } } and to use it with the following minimal code example: public static int main(string[] args) { string[] strings; Sos.Address[] addrs; // the following call just populates the initial addrs array Sos.Server.get_server_addresses(mambo, out addrs); Sos.Address.array_to_string(addrs, out strings); stdout.printf(@str_addr: $(strings[0])\n); return Posix.EXIT_SUCCESS; } This approach works, but valgrind complains that the pointed string, in the returned array, isn't freed. In fact, in the generated code, _vala_array_free is called with an array length of -1, so only the array is freed, not the pointed addresses. I tried to add array_length_cexpr = addresses.length but it didn't do anything, unless I remove 'array_length = false', but in this case, an extra parameter is added and the code doesn't compile any-more. What would be the best solution to this issue in your opinion ? Thank you in advance. ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Implicit array size for function allocating an array
On 16/12/2014 10:52, Nicolas CARRIER wrote: Hello, I'm trying to bind a C function which has the following prototype: int sos_addresses_to_string(const struct sos_address *addresses, char ***string_addresses, int nb); It's job is to convert an array of addresses, into an array of their string representation. So both the addresses array (in input) and the string_addresses array will have the same size which is nb. So in output, string_addresses will point to an allocated array of allocated char buffers. I tried to bind it this way: namespace Sos { public struct Address { ... public static int array_to_string([CCode (array_length_pos = 3)] Address addresses[], [CCode (array_length = false] out string[] string_addresses); } } and to use it with the following minimal code example: public static int main(string[] args) { string[] strings; Sos.Address[] addrs; // the following call just populates the initial addrs array Sos.Server.get_server_addresses(mambo, out addrs); Sos.Address.array_to_string(addrs, out strings); stdout.printf(@str_addr: $(strings[0])\n); return Posix.EXIT_SUCCESS; } This approach works, but valgrind complains that the pointed string, in the returned array, isn't freed. In fact, in the generated code, _vala_array_free is called with an array length of -1, so only the array is freed, not the pointed addresses. I tried to add array_length_cexpr = addresses.length but it didn't do anything, unless I remove 'array_length = false', but in this case, an extra parameter is added and the code doesn't compile any-more. What would be the best solution to this issue in your opinion ? After the array_to_string call, do strings.length = addrs.length; ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
[Vala] Cairo matrix multiply vapi question
Hi, Not sure if I've found a bug or am simply thick. I'm going with the latter :D At: https://git.gnome.org/browse/vala/plain/vapi/cairo.vapi Down near the end, under the public struct Matrix, look for: public void multiply (Matrix a, Matrix b); In the Cairo C docs, it looks like this: void cairo_matrix_multiply ( cairo_matrix_t *result, const cairo_matrix_t *a, const cairo_matrix_t *b); So, there's an initial arg that is a ref in which to receive the new matrix. Is the vapi missing something? \d ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Cairo matrix multiply vapi question
On 16/12/2014 10:58, Donn wrote: Hi, Not sure if I've found a bug or am simply thick. I'm going with the latter :D At: https://git.gnome.org/browse/vala/plain/vapi/cairo.vapi Down near the end, under the public struct Matrix, look for: public void multiply (Matrix a, Matrix b); In the Cairo C docs, it looks like this: void cairo_matrix_multiply ( cairo_matrix_t *result, const cairo_matrix_t *a, const cairo_matrix_t *b); So, there's an initial arg that is a ref in which to receive the new matrix. Is the vapi missing something? .multiply() is a method of Mmatrix. Therefore you call multiply on an instance of Matrix which is the one that will get modified. ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Cairo matrix multiply vapi question
On 16/12/2014 12:01, Luca Bruno wrote: .multiply() is a method of Mmatrix. Therefore you call multiply on an instance of Matrix which is the one that will get modified. Ah, thanks Luca. \d ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list