Cstring as ccall return value

138 views
Skip to first unread message

maleadt

unread,
Nov 13, 2015, 8:28:13 AM11/13/15
to julia-dev
Does it make sense to use Cstring as the return value type when ccall'ing methods returning a char* string? I know the type is mainly intended to avoid converting Julia strings containing \0 to C strings, but I thought it would also make sense to use it as the ccall return type because it makes the code more readable (i.e. "this code returns a string" rather than "it's just a pointer").

However, I'm afraid there might be a gotcha:
julia> Ptr{UInt8}(0x0) == C_NULL
true

julia
> Cstring(Ptr{UInt8}(0x0)) == C_NULL
false
Is this intended? Some API's (for example tempnam) return NULL upon failure, so that would break when using Cstring as ccall's return value type and subsequently comparing against C_NULL.


Stefan Karpinski

unread,
Nov 13, 2015, 9:37:10 AM11/13/15
to juli...@googlegroups.com
That comparison should really either return true or fail. Could you open an issue?

maleadt

unread,
Nov 13, 2015, 10:00:27 AM11/13/15
to julia-dev
Done, see issue #13974.

Op vrijdag 13 november 2015 15:37:10 UTC+1 schreef Stefan Karpinski:
Reply all
Reply to author
Forward
0 new messages