Skip to content

Commit

Permalink
Merge pull request JuliaLang#17224 from ihnorton/fix17219
Browse files Browse the repository at this point in the history
Fix JuliaLang#17219: conditionally lower ccall first arg
  • Loading branch information
ihnorton authored Jul 2, 2016
2 parents e5b5a09 + 054b7e7 commit 34fbf83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3018,8 +3018,12 @@ f(x) = yt(x)
((call new)
(let* ((ccall? (and (eq? (car e) 'call) (equal? (cadr e) '(core ccall))))
(args (if ccall?
;; NOTE: first 3 arguments of ccall must be left in place
(append (list-head (cdr e) 4)
;; NOTE: 2nd and 3rd arguments of ccall must be left in place
;; the 1st should be compiled if an atom.
(append (list (cadr e))
(cond (atom? (caddr e) (compile-args (list (caddr e)) break-labels))
(else (caddr e)))
(list-head (cdddr e) 2)
(compile-args (list-tail e 5) break-labels))
(compile-args (cdr e) break-labels)))
(callex (cons (car e) args)))
Expand Down
7 changes: 7 additions & 0 deletions test/ccall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,13 @@ foo13031(x,y,z) = z
foo13031p = cfunction(foo13031, Cint, (Ref{Tuple{}},Ref{Tuple{}},Cint))
ccall(foo13031p, Cint, (Ref{Tuple{}},Ref{Tuple{}},Cint), (), (), 8)

# issue 17219
function ccall_reassigned_ptr(ptr::Ptr{Void})
ptr = Libdl.dlsym(Libdl.dlopen(libccalltest), "test_echo_p")
ccall(ptr, Any, (Any,), "foo")
end
@test ccall_reassigned_ptr(C_NULL) == "foo"

# @threadcall functionality
threadcall_test_func(x) =
@threadcall((:testUcharX, libccalltest), Int32, (UInt8,), x % UInt8)
Expand Down

0 comments on commit 34fbf83

Please sign in to comment.