@@ -924,61 +924,77 @@ for (t, v) in ((Complex{Int32}, :ci32), (Complex{Int64}, :ci64),
924924 @test b === c
925925 let cf = @cfunction ($ fname1, Ref{$ t}, (Ref{$ t},))
926926 b = ccall (cf, Ref{$ t}, (Ref{$ t},), a)
927+ verbose && println (" C: " , b)
928+ @test b == $ v
929+ @test b === a
930+ @test b === c
927931 end
928- verbose && println (" C: " , b)
929- @test b == $ v
930- @test b === a
931- @test b === c
932932 let cf = @cfunction ($ fname, $ t, ($ t,))
933933 b = ccall (cf, $ t, ($ t,), a)
934- end
935- verbose && println ( " C: " ,b)
936- @test b == $ v
937- if ismutable ( $ v )
938- @test ! (b === c )
939- @test ! (b === a)
934+ verbose && println ( " C: " ,b)
935+ @test b == $ v
936+ if ismutable ( $ v)
937+ @test ! (b === c )
938+ @test ! (b === a )
939+ end
940940 end
941941 let cf = @cfunction ($ fname1, $ t, (Ref{$ t},))
942942 b = ccall (cf, $ t, (Ref{$ t},), a)
943- end
944- verbose && println ( " C: " ,b)
945- @test b == $ v
946- if ismutable ( $ v )
947- @test ! (b === c )
948- @test ! (b === a)
943+ verbose && println ( " C: " ,b)
944+ @test b == $ v
945+ if ismutable ( $ v)
946+ @test ! (b === c )
947+ @test ! (b === a )
948+ end
949949 end
950950 let cf = @cfunction ($ fname, Ref{$ t}, ($ t,))
951951 b = ccall (cf, Ref{$ t}, ($ t,), a)
952- end
953- verbose && println ( " C: " ,b)
954- @test b == $ v
955- @test b === c
956- if ismutable ( $ v )
957- @test ! (b === a)
952+ verbose && println ( " C: " ,b)
953+ @test b == $ v
954+ @test b === c
955+ if ismutable ( $ v)
956+ @test ! (b === a )
957+ end
958958 end
959959 let cf = @cfunction ($ fname, Any, (Ref{$ t},))
960960 b = ccall (cf, Any, (Ref{$ t},), $ v)
961- end
962- verbose && println ( " C: " ,b)
963- @test b == $ v
964- @test b === c
965- if ismutable ( $ v )
966- @test ! (b === a)
961+ verbose && println ( " C: " ,b)
962+ @test b == $ v
963+ @test b === c
964+ if ismutable ( $ v)
965+ @test ! (b === a )
966+ end
967967 end
968968 let cf = @cfunction ($ fname, Any, (Ref{Any},))
969969 b = ccall (cf, Any, (Ref{Any},), $ v)
970+ @test b == $ v
971+ @test b === c
972+ if ismutable ($ v)
973+ @test ! (b === a)
974+ end
970975 end
971- @test b == $ v
972- @test b === c
973- if ismutable ($ v)
974- @test ! (b === a)
976+ a isa Complex && let cf = @cfunction ($ fname, Ref{Complex}, (Ref{Any},))
977+ b = ccall (cf, Ref{Complex}, (Ref{Any},), $ v)
978+ @test b == $ v
979+ @test b === c
980+ if ismutable ($ v)
981+ @test ! (b === a)
982+ end
975983 end
976984 let cf = @cfunction ($ fname, Ref{AbstractString}, (Ref{Any},))
977985 @test_throws TypeError ccall (cf, Any, (Ref{Any},), $ v)
978986 end
979- let cf = @cfunction ($ fname, AbstractString, (Ref{Any},))
987+ let cf = @cfunction ($ fname, Ref{Ptr}, (Ref{Any},))
988+ @test_throws TypeError ccall (cf, Any, (Ref{Any},), $ v)
989+ end
990+ let cf = @cfunction ($ fname, Ref{Complex{UInt32}}, (Ref{Any},))
980991 @test_throws TypeError ccall (cf, Any, (Ref{Any},), $ v)
981992 end
993+ if a isa Complex
994+ local mkcb (:: Type{T} ) where {T} = @cfunction ($ fname, Ref{Complex{T}}, (Ref{Any},))
995+ @test ccall (mkcb (typeof (a. re)), Any, (Ref{Any},), $ v) === $ v
996+ end
997+ # FIXME : @test_throws TypeError ccall(mkcb(UInt32), Any, (Ref{Any},), $v)
982998 end
983999end
9841000
@@ -1484,7 +1500,21 @@ end
14841500@test_throws (TypeError, @eval if false ; ccall (:fn , Some. var, ()); end )
14851501@test_throws (TypeError, @eval if false ; ccall (:fn , Cvoid, (Some. var,), Some (0 )); end )
14861502@test_throws (ErrorException (" ccall method definition: Vararg not allowed for argument list" ),
1487- @eval ccall (+ , Int, (Vararg{Int},), 1 ))
1503+ @eval ccall (:fn , Int, (Vararg{Int},), 1 ))
1504+ @test_throws (ErrorException (" ccall method definition: argument 1 type doesn't correspond to a C type" ),
1505+ @eval ccall (:fn , Int, (Integer,), 1 ))
1506+ @test_throws (ErrorException (" ccall method definition: argument 1 type doesn't correspond to a C type" ),
1507+ @eval ccall (:fn , Int, (Ptr,), C_NULL ))
1508+ @test_throws (ErrorException (" ccall method definition: return type doesn't correspond to a C type" ),
1509+ @eval ccall (:fn , Integer, (Integer,), 1 ))
1510+ @test_throws (ErrorException (" ccall method definition: return type doesn't correspond to a C type" ),
1511+ @eval ccall (:fn , Ptr, ()))
1512+ # This is hard to test: @test_throws(ErrorException("ccall argument 1 type doesn't correspond to a C type"),
1513+ # @eval ccall(:fn, Int, (Union{},), 1))
1514+ @test_throws (ErrorException (" ccall argument 1 type doesn't correspond to a C type" ),
1515+ @eval ccall (:fn , Int, (Nothing,), nothing ))
1516+ @test_throws (ErrorException (" ccall return type struct fields cannot contain a reference" ),
1517+ @eval ccall (:fn , typeof (Ref (" " )), ()))
14881518
14891519# test for malformed syntax errors
14901520@test Expr (:error , " more arguments than types for ccall" ) == Meta. lower (@__MODULE__ , :(ccall (:fn , A, (), x)))
@@ -1525,10 +1555,22 @@ evalf_callback_19805(ci::callinfos_19805{FUNC_FT}) where {FUNC_FT} = ci.f(0.5)::
15251555 @eval () -> @cfunction (+ , Int, (Ref{T}, Ref{T})) where T)
15261556@test_throws (ErrorException (" could not evaluate cfunction return type (it might depend on a local variable)" ),
15271557 @eval () -> @cfunction (+ , Ref{T}, (Int, Int)) where T)
1528- @test_throws (ErrorException (" cfunction argument 2 doesn't correspond to a C type" ),
1558+ @test_throws (ErrorException (" cfunction argument 2 type doesn't correspond to a C type" ),
15291559 @eval @cfunction (+ , Int, (Int, Nothing)))
1560+ @test_throws (ErrorException (" cfunction argument 2 type doesn't correspond to a C type" ),
1561+ @eval @cfunction (+ , Int, (Int, Union{})))
15301562@test_throws (ErrorException (" cfunction return type Ref{Any} is invalid. Use Any or Ptr{Any} instead." ),
15311563 @eval @cfunction (+ , Ref{Any}, (Int, Int)))
1564+ @test_throws (ErrorException (" cfunction method definition: argument 1 type doesn't correspond to a C type" ),
1565+ @eval @cfunction (+ , Int, (Integer, Integer)))
1566+ @test_throws (ErrorException (" cfunction method definition: argument 1 type doesn't correspond to a C type" ),
1567+ @eval @cfunction (+ , Int, (Ptr,)))
1568+ @test_throws (ErrorException (" cfunction method definition: return type doesn't correspond to a C type" ),
1569+ @eval @cfunction (+ , Integer, (Int, Int)))
1570+ @test_throws (ErrorException (" cfunction method definition: return type doesn't correspond to a C type" ),
1571+ @eval @cfunction (+ , Ptr, (Int, Int)))
1572+ @test_throws (ErrorException (" cfunction return type struct fields cannot contain a reference" ),
1573+ @eval @cfunction (+ , typeof (Ref (" " )), ()))
15321574
15331575# test Ref{abstract_type} calling parameter passes a heap box
15341576abstract type Abstract22734 end
0 commit comments