Skip to content

Commit

Permalink
Fix JuliaLang#17219: conditionally lower ccall first arg
Browse files Browse the repository at this point in the history
Without this compile step, ccall uses the first slotted version of the variable
regardless of whether it has been reassigned in the function body.

Fixes JuliaLang#17219
Fixes JuliaInterop/JavaCall.jl#37

See https://groups.google.com/forum/#!msg/julia-users/DyTQmsQaQl4/KmxQHSqACQAJ
  • Loading branch information
ihnorton committed Jul 2, 2016
1 parent a66ace6 commit 054b7e7
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 @@ -570,6 +570,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 054b7e7

Please sign in to comment.