Macro that uses ccall in julia-0.6.0


#1

I have the following macro:

macro xprs_ccall(func, args...)

    f = "XPRS$(func)"
    args = map(esc,args)

    is_unix() && return quote
        ccall(($f,xprs), $(args...))
    end
    is_windows() && return quote
        ccall(($f,xprs), stdcall, $(args...))
    end
end

where xprs is a const previously defined.

when I try:
@xprs_ccall(getversion, Cint, ( Ptr{Cchar}, ) , out)
I get:
ERROR: syntax: ccall argument types must be a tuple; try "(T,)"

I tested:

julia> macroexpand( :(@xprs_ccall(getversion, Cint, ( Ptr{Cchar}, ) , out)))
quote  # REPL[5], line 10:
    ccall(("XPRSgetversion", Main.xprs), Main.stdcall, Cint, (Ptr{Cchar},), out)

end

It seems to be a tuple…

When I remove the word stdcall from the macro:

macro xprs_ccall(func, args...)

    f = "XPRS$(func)"
    args = map(esc,args)

    is_unix() && return quote
        ccall(($f,xprs), $(args...))
    end
    is_windows() && return quote
        ccall(($f,xprs), $(args...))
    end
end

Everything works just fine.

Any Ideas why?


#2

Actually, both work:
ccall((:XPRSgetversion, xprs), Cint, ( Ptr{Cchar}, ) , out)

ccall((:XPRSgetversion, xprs), stdcall, Cint, ( Ptr{Cchar}, ) , out)

So it is something in that macro…


#3

As shown in your macro expansion result, you need to escape the stdcall.


#4

Is this what you mean?

macro xprs_ccall(func, args...)

    f = "XPRS$(func)"
    args = map(esc,args)

    is_unix() && return quote
        ccall(($f,xprs), $(args...))
    end
    is_windows() && return quote
        ccall(($f,xprs), esc(stdcall), $(args...))
    end
end

Because it returns the same error…


#5

This works:

macro xprs_ccall(func, args...)
    f = "XPRS$(func)"
    args = map(esc,args)

    is_unix() && return quote
        ccall(($f,xprs), $(args...))
    end
    is_windows() && return quote
        ccall(($f,xprs), $(esc(:stdcall)), $(args...))
    end
end

thanks!


#6

This last example does not work properly on julia-0.5.0 (and 0.5.1), it returns:

ERROR: syntax: ccall argument types must be a tuple; try "(T,)"