# Interpolation using $ with @cfunction in a macro reported as a closure, thus won't work on Apple Silicon

**URL:** <https://discourse.julialang.org/t/interpolation-using-with-cfunction-in-a-macro-reported-as-a-closure-thus-wont-work-on-apple-silicon/75984>\
**Category:** General Usage\
**Tags:** question\
**Created:** [February 8, 2022, 1:12am UTC](https://discourse.julialang.org/t/interpolation-using-with-cfunction-in-a-macro-reported-as-a-closure-thus-wont-work-on-apple-silicon/75984 "2022-02-08T01:12:43Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 8, 2022, 1:58am UTC](https://discourse.julialang.org/t/interpolation-using-with-cfunction-in-a-macro-reported-as-a-closure-thus-wont-work-on-apple-silicon/75984/2 "2022-02-08T01:58:11Z")

</div>

The ArchGDAL.jl package is apparently using this for the [`GDALProgressFunc`](https://gdal.org/api/cpl.html#_CPPv416GDALProgressFunc) callback API.

It seems like the solution is to change the Julia package to use the `void*` argument (`pProgressArg`) to pass the closure argument, rather than [forcing Julia to compile a new callback](https://julialang.org/blog/2013/05/callback/#the_problem_with_closures) for every `progressfunc` argument it wants to handle (which apparently isn’t supported on M1). That is, they should define something like:

```julia
function progressfunc_wrapper(dfComplete::Cdouble, pszMessage::Ptr{UInt8}, pProgressArg::Any)::Cint
    pszMessage == C_NULL && return pProgressArg(dfComplete)
    return pProgressArg(dfComplete, unsafe_string(pszMessage))
end
const progressfunc_wrapper_c = @cfunction(progressfunc_wrapper, Cint, (Cdouble, Cstring, Any))

```

and then, any place you actually want to pass a `progressfunc`, you instead pass `progressfunc_wrapper_c` as the callback function and `progressfunc` as the callback-data argument.

In APIs that support a callback-data argument, like this one, the above is the [approach I would recommend](https://julialang.org/blog/2013/05/callback/#passing_closures_via_pass-through_pointers). It puts a lot fewer demands on the compiler.

(Also, then their `progresscallback` functions are simpler and more Julian. They are passed a Julia `String` as their optional “message” argument rather than a pointer, and can return `true` or `false` instead of a `Cint`, since `progressfunc_wrapper` handles the conversions.)

---

_[View the full topic](https://discourse.julialang.org/t/interpolation-using-with-cfunction-in-a-macro-reported-as-a-closure-thus-wont-work-on-apple-silicon/75984)._
