[PATCH] ubus: add a private field to event handlers

Louis_Hampton at SERCOMM.COM Louis_Hampton at SERCOMM.COM
Wed Jul 14 09:18:59 PDT 2021


We use generated Rust bindings to libubus, and our own thread as opposed
to uloop. "container_of", quite aside from not being exported, violates
the strong types and memory safety rules we've previously been able to
uphold. This isn't an issue with callbacks from "ubus_invoke_fd", where
we can pass a pointer to some private (repr(C), for those who care) type
in "priv" and pick up context from that.

Since we don't have direct access to C macros at all, container_of is
far from ideal. This is the first instance where it has been required.

Do C++ libubus users make use of "container_of"?

~ Louis

Felix Fietkau writes:

> On 2021-07-13 13:57, Louis_Hampton at SERCOMM.COM wrote:
>> 
>> This is particularly useful in multithreaded non-C FFI, where
>> additional context from where the event handler was registered may be
>> critical to ensuring the output of the event is sent to the right
>> location.
>> 
>> Signed-off-by: Louis Hampton <louis_hampton at sercomm.com>
> In order to get the additional context, the normal solution is to embed
> struct ubus_event_handler into another data structure, which contains
> the extra context and can be accessed via container_of.
> Is there a reason why this can't be done in your code as well?
>
> - Felix




More information about the openwrt-devel mailing list