gcrypt's `random_bytes_secure` fails to compile due to too many arguments.
This seems to be caused by a missing array_length = false
[CCode (cname = "gcry_random_bytes", array_length = false)]
public static uchar[] random_bytes (size_t nbytes, Level level = Level.VERY_STRONG);
[CCode (cname = "gcry_random_bytes_secure")]
public static uchar[] random_bytes_secure (size_t nbytes, Level level = Level.VERY_STRONG);
Steps to Reproduce:
- Create random.vala:
using GCrypt.Random;
int main() {
uint random_number = uint.from_pointer(random_bytes_secure(sizeof(uint), Level.VERY_STRONG))%100;
print(@"$random_number\n");
return(0);
}
- Compile with:
valac -o random -X "$(pkg-config --libs libgcrypt)" --vapidir ./vala-extra-vapis --pkg gcrypt ./random.vala
- You should get the following error:
/tmp/random.vala.c: In function '_vala_main':
/tmp/random.vala.c:24:18: error: too many arguments to function 'gcry_random_bytes_secure'
24 | _tmp1_ = gcry_random_bytes_secure ((gsize) sizeof (guint), GCRY_VERY_STRONG_RANDOM, &_tmp0_);
| ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /tmp/random.vala.c:5:
/usr/include/gcrypt.h:1697:7: note: declared here
1697 | void *gcry_random_bytes_secure (size_t nbytes, enum gcry_random_level level)
| ^~~~~~~~~~~~~~~~~~~~~~~~
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)
As you can see, due to the missing array_length = false
, vala incorrectly passes &_tmp0_
to tell the function the size of the array.