So I have recently realized translate-c generates methods on translated opaque structs (realized way too late because ZLS currently does not show them and I rely way too much on LSP). And it is very nice, because it also provides short names where the struct name prefix is stripped.
But I noticed that it seems really inconsistent. Some functions are arbitrarily missing, or have the name different than expected.
Example 1
Look at this translated libnl3 nl_cache_mngr
pub const struct_nl_cache_mngr = opaque {
pub const nl_cache_mngr_add = __root.nl_cache_mngr_add;
pub const nl_cache_mngr_add_cache = __root.nl_cache_mngr_add_cache;
pub const nl_cache_mngr_add_cache_v2 = __root.nl_cache_mngr_add_cache_v2;
pub const nl_cache_mngr_get_fd = __root.nl_cache_mngr_get_fd;
pub const nl_cache_mngr_poll = __root.nl_cache_mngr_poll;
pub const nl_cache_mngr_data_ready = __root.nl_cache_mngr_data_ready;
pub const nl_cache_mngr_info = __root.nl_cache_mngr_info;
pub const nl_cache_mngr_free = __root.nl_cache_mngr_free;
pub const add = __root.nl_cache_mngr_add;
pub const add_cache = __root.nl_cache_mngr_add_cache;
pub const add_cache_v2 = __root.nl_cache_mngr_add_cache_v2;
pub const get_fd = __root.nl_cache_mngr_get_fd;
pub const data_ready = __root.nl_cache_mngr_data_ready;
pub const info = __root.nl_cache_mngr_info;
};
pub extern fn nl_cache_mngr_alloc(?*struct_nl_sock, c_int, c_int, [*c]?*struct_nl_cache_mngr) c_int;
pub extern fn nl_cache_mngr_add(?*struct_nl_cache_mngr, [*c]const u8, change_func_t, ?*anyopaque, [*c]?*struct_nl_cache) c_int;
pub extern fn nl_cache_mngr_add_cache(mngr: ?*struct_nl_cache_mngr, cache: ?*struct_nl_cache, cb: change_func_t, data: ?*anyopaque) c_int;
pub extern fn nl_cache_mngr_add_cache_v2(mngr: ?*struct_nl_cache_mngr, cache: ?*struct_nl_cache, cb: change_func_v2_t, data: ?*anyopaque) c_int;
pub extern fn nl_cache_mngr_get_fd(?*struct_nl_cache_mngr) c_int;
pub extern fn nl_cache_mngr_poll(?*struct_nl_cache_mngr, c_int) c_int;
pub extern fn nl_cache_mngr_data_ready(?*struct_nl_cache_mngr) c_int;
pub extern fn nl_cache_mngr_info(?*struct_nl_cache_mngr, [*c]struct_nl_dump_params) void;
pub extern fn nl_cache_mngr_free(?*struct_nl_cache_mngr) void;
You can see the short names are really nice for consumer side to just call mgr.free() instead of c.nl_cache_mngr_free(mgr). But mgr.poll(x) is missing. Why?
Example 2
This is much abbreviated translation of BoringSSL BIO_METHOD
pub const struct_bio_method_st = opaque {
// Abbreviated full function names
pub const BIO_meth_get_create = __root.BIO_meth_get_create;
pub const BIO_meth_set_create = __root.BIO_meth_set_create;
// All shortcuts, not abbreviated
pub const new = __root.BIO_new;
pub const write = __root.BIO_meth_get_write;
pub const ex = __root.BIO_meth_get_write_ex;
pub const read = __root.BIO_meth_get_read;
pub const gets = __root.BIO_meth_get_gets;
pub const ctrl = __root.BIO_meth_get_ctrl;
pub const create = __root.BIO_meth_get_create;
pub const destroy = __root.BIO_meth_get_destroy;
};
// Abbreviated function declarations
pub extern fn BIO_meth_get_create(bion: ?*const BIO_METHOD) ?*const fn (?*BIO) callconv(.c) c_int;
pub extern fn BIO_meth_set_create(biom: ?*BIO_METHOD, create: ?*const fn (?*BIO) callconv(.c) c_int) c_int;
Here you can see there is a create shortcut. But there are BIO_meth_get_create and BIO_meth_set_create methods. I expected get_create and set_create shortcuts. Is this a bug, or a feature?
The ex shortcut seems even more arbitrary.