[WIP] improve lifetime management of C funcs

This is a WIP as I have to investigate related Dispatcher changes. Tests should pass, though. Comments welcome.