Skip to content

Commit

Permalink
ccall: fix vararg count computation (#33123)
Browse files Browse the repository at this point in the history
(cherry picked from commit a9d4eac)
  • Loading branch information
vtjnash authored and Kristoffer Carlsson committed Sep 5, 2019
1 parent 8c51a52 commit 46d0822
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@
`(block
,.(reverse! stmts)
(foreigncall ,name ,RT (call (core svec) ,@(reverse! T))
,(if isseq (- (length F) 1) 0) ; 0 or number of arguments before ... in definition
,(if isseq (- (length atypes) 1) 0) ; 0 or number of arguments before ... in definition
',cconv
,.(reverse! C)
,@GC)) ; GC root ordering is arbitrary
Expand Down
12 changes: 12 additions & 0 deletions test/ccall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ const libccalltest = "libccalltest"
const verbose = false
ccall((:set_verbose, libccalltest), Cvoid, (Int32,), verbose)

@eval function cvarargs()
strp = Ref{Ptr{Cchar}}(0)
fmt = "%3.1f"
len = ccall(:asprintf, Cint, (Ptr{Ptr{Cchar}}, Cstring, Cfloat...), strp, fmt, 0.1)
str = unsafe_string(strp[], len)
Libc.free(strp[])
return str
end
@test cvarargs() == "0.1"


# test multiple-type vararg handling (there's no syntax for this currently)
@eval function foreign_varargs()
strp = Ref{Ptr{Cchar}}(0)
Expand All @@ -30,6 +41,7 @@ ccall((:set_verbose, libccalltest), Cvoid, (Int32,), verbose)
end
@test foreign_varargs() == "hi+1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-1.1-2.2-3.3-4.4-5.5-6.6-7.7-8.8-9.9\n"


# Test for proper argument register truncation
ccall_test_func(x) = ccall((:testUcharX, libccalltest), Int32, (UInt8,), x % UInt8)
@test ccall_test_func(3) == 1
Expand Down

0 comments on commit 46d0822

Please sign in to comment.