Avoid an unnecessary std::function allocation in codegen (#59965)
We already need to manually create a C compatible function pointer and
heap allocated data, might as well do so directly without another
indirection through std::function.
Noticed the callback during
https://github.com/JuliaLang/julia/pull/59946. It does not need to be an
non static `extern "C"` function and could even be a lambda.