connection: allow NULL implementation and listener in wl_closure_invoke

In practice, not all callbacks defined by a wl_interface are needed by
every client or server. For instance, a client may only care about a
subset of events on an object and leave the rest unhandled.

Previously, a NULL implementation or a NULL listener function for a
specific opcode would cause a fatal wl_abort(), forcing users to
provide stub callbacks for every opcode even when they had nothing
to do. This made code unnecessarily verbose.

Downgrade the abort to a wl_log() warning and return early after
cleaning up file descriptors. This allows partial interface
implementations, simplifying user code while still logging a
diagnostic message for debugging.

Signed-off-by: Jie Liu <liujie01@kylinos.cn>
This commit is contained in:
Jie Liu 2026-04-02 10:31:22 +08:00
parent e647f6304d
commit a4f861a49a

View file

@ -1232,13 +1232,16 @@ wl_closure_invoke(struct wl_closure *closure, uint32_t flags,
implementation = target->implementation;
if (!implementation) {
wl_abort("Implementation of resource %d of %s is NULL\n",
wl_log("Implementation of resource %d of %s is NULL\n",
target->id, target->interface->name);
return wl_closure_clear_fds(closure);
}
if (!implementation[opcode]) {
wl_abort("listener function for opcode %u of %s is NULL\n",
wl_log("listener function for opcode %u of %s is NULL\n",
opcode, target->interface->name);
return wl_closure_clear_fds(closure);
}
ffi_call(&cif, implementation[opcode], NULL, ffi_args);