Skip to content

Commit 993425c

Browse files
committed
in macro body, use ccall function over macro
1 parent df1af1f commit 993425c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/libSparse/wrappers.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,17 @@ macro generateDemangled(jlName, cName, param, retType, jlArgTypes...)
248248
Expr(:(::), esc(Symbol("arg$i")), T)
249249
end
250250
local jlCall = Expr(:(::), Expr(:call, esc(jlName), jlArgExprs...), retTypeWParam)
251-
local cArgExprs = [Expr(:(::), Symbol("arg$i"), T) for (i,T) in enumerate(cArgTypesWParams)]
251+
# Build ccall directly instead of using @ccall macro to avoid variable name conflicts
252+
local cArgNames = [Symbol("arg$i") for i in 1:length(cArgTypesWParams)]
252253
local LIBSPARSE = "/System/Library/Frameworks/Accelerate.framework/Versions"*
253254
"/A/Frameworks/vecLib.framework/libSparse.dylib"
254-
local funcAndLibrary = Expr(:(.), LIBSPARSE, esc(cName))
255-
local cCall = Expr(:(::), Expr(:call, funcAndLibrary, cArgExprs...), retTypeWParam)
256-
local ccallMarco = Expr(:macrocall, Symbol("@ccall"), :(LineNumberNode(@__LINE__, @__FILE__)), cCall)
257-
return Expr(Symbol("="), jlCall, ccallMarco)
255+
# Construct ccall((:cName, LIBSPARSE), retType, (argTypes...), args...)
256+
local cCallExpr = Expr(:call, :ccall,
257+
Expr(:tuple, esc(cName), LIBSPARSE),
258+
retTypeWParam,
259+
Expr(:tuple, cArgTypesWParams...),
260+
cArgNames...)
261+
return Expr(Symbol("="), jlCall, cCallExpr)
258262
end
259263

260264
# sparse * (dense matrix)

0 commit comments

Comments
 (0)