Generated free function for array of struct has name containing space
This issue came up on the mailing list back in 2014, and as far as I can tell, it is still a problem. I checked the relevant code in current git, and it hasn't changed since 2010, so I will quote Jeremy Slater's excellent description from the mailing list in 2014 (unfortunately, Abderrahim Kitouni's full reply to Jeremy's original mail is not available in the archive):
On Sun, Oct 12, 2014 at 11:38 AM, Abderrahim Kitouni wrote:
Le 12 oct. 2014 15:04, "Jeremy Slater" wrote:
I'm having an issue with the way vala generates names for functions like
callback wrappers and struct array free routines. I am writing a vapi for
a library that does not typedef structures, so in my vapi I have to set the
cname to include struct, i.e. cname="struct some_structure". This results
in the generated free for an array of some_structure being generated as
"_vala_struct some_structure_array_free".
You should use lower_case_cname as well. (not sure of the spelling though, take a look at other vapid)
lower_case_cprefix (I assume is what you meant) appears to only be
used for the direct struct methods like destroy and copy. the
array_free method for freeing the array of structs, is only
constructed directly from the cname. The relevant code,
append_struct_array_free, appears to be around
valaccodearraymodule.vala:205.
I am having exactly the same problem trying to wrap the GNU getopt_long
function, one of whose arguments is struct option *
. My binding looks like this:
[Compact]
[CCode (cname = "struct option", destroy_function = "")]
public struct Option {
string name;
int has_arg;
int *flag;
int val;
}
[CCode (has_target = false, has_type_id = false)]
public int getopt_long ([CCode (array_length_pos = 0)] string[] args,
string shortopts,
[CCode (array_length = false, array_null_terminated = true)] Option[] longopts, out int longind);
The call to getopt_long
itself seems to be correctly generated. However, when I construct an array of struct option
and pass it, I get errors like this:
src/main.c:1455:14: error: '_vala_struct' undeclared (first use in this function); did you mean '__locale_struct'?
1455 | longopts = (_vala_struct option_array_free (longopts, longopts_length1), NULL);
As you can see, valac has generated the name _vala_struct option_array_free
, which contains a space.
I tried valac 0.48.11 and 0.50.1 nightly from the PPAs.
Apologies in advance if I've overlooked another relevant issue; I couldn't find one, though I see there are several about code generation for arrays.