@@ -203,11 +203,11 @@ function exit_on_sigint(on::Bool)
203203 ccall (:jl_exit_on_sigint , Cvoid, (Cint,), on)
204204end
205205
206- function _ccallable (rt:: Type , sigt:: Type )
207- ccall (:jl_extern_c , Cvoid, (Any, Any) , rt, sigt)
206+ function _ccallable (name :: Union{Nothing, String} , rt:: Type , sigt:: Type )
207+ ccall (:jl_extern_c , Cvoid, (Any, Any, Any), name , rt, sigt)
208208end
209209
210- function expand_ccallable (rt, def)
210+ function expand_ccallable (name, rt, def)
211211 if isa (def,Expr) && (def. head === :(= ) || def. head === :function )
212212 sig = def. args[1 ]
213213 if sig. head === :(:: )
@@ -235,24 +235,30 @@ function expand_ccallable(rt, def)
235235 end
236236 return quote
237237 @__doc__ $ (esc (def))
238- _ccallable ($ (esc (rt)), $ (Expr (:curly , :Tuple , esc (f), map (esc, at)... )))
238+ _ccallable ($ name, $ (esc (rt)), $ (Expr (:curly , :Tuple , esc (f), map (esc, at)... )))
239239 end
240240 end
241241 end
242242 error (" expected method definition in @ccallable" )
243243end
244244
245245"""
246- @ccallable(def)
246+ @ccallable ["name"] function f(...)::RetType ... end
247247
248248Make the annotated function be callable from C using its name. This can, for example,
249- be used to expose functionality as a C-API when creating a custom Julia sysimage.
249+ be used to expose functionality as a C API when creating a custom Julia sysimage.
250+
251+ If the first argument is a string, it is used as the external name of the function.
250252"""
251253macro ccallable (def)
252- expand_ccallable (nothing , def)
254+ expand_ccallable (nothing , nothing , def)
253255end
254256macro ccallable (rt, def)
255- expand_ccallable (rt, def)
257+ if rt isa String
258+ expand_ccallable (rt, nothing , def)
259+ else
260+ expand_ccallable (nothing , rt, def)
261+ end
256262end
257263
258264# @ccall implementation
0 commit comments