Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ccall: WARNING: convert{T}(p::Type{Ptr{T}},a::Array) is deprecated, use convert(p,pointer(a)) instead. #7694

Closed
kmsquire opened this issue Jul 22, 2014 · 4 comments

Comments

@kmsquire
Copy link
Member

I'm getting this when I call ccall with an Array is passed in where a pointer is expected, specifically when the Array type does not match the pointer type. When the types match, no warning is given.

julia> ccall(:strchr, Ptr{Uint8}, (Ptr{Uint8}, Cint), "alpha".data, 'a')
Ptr{Uint8} @0x00000000030caaf0

julia> x = [0x3232326168706c61]
1-element Array{Uint64,1}:
 0x3232326168706c61

julia> ccall(:strchr, Ptr{Uint8}, (Ptr{Uint8}, Cint), x, 'a')
WARNING: convert{T}(p::Type{Ptr{T}},a::Array) is deprecated, use convert(p,pointer(a)) instead.
 in convert at deprecated.jl:26
 in cconvert at base.jl:33
 in anonymous at no file
Ptr{Uint8} @0x0000000005c93830

This is behavior is probably partially correct, but

  1. the error message is misleading
  2. there are use cases where calling ccall with an array of a different type than the pointer is valid.

For 2, specifically, I'm calling a function in libavutil which expects a Ptr{Picture}, but you can (and often do) pass a Ptr{AVFrame} because the initial layout is identical.

Converting the array to a pointer first fixes this, and is an easy solution, except that it goes against the recommendation that one not make ccalls with pointers.

The only question here I think is how to fix this:

  1. Fix the warning (but still warn when the types don't match)
  2. Allow (and therefore undeprecate) convert(::Ptr{T}, ::Array{S}) when S!=T

Thoughts?

@JeffBezanson
Copy link
Member

I don't think we should allow silently converting to a mismatched pointer type. Yes, this warning is not perfect, but I'm ok with it --- ccall uses convert, and this ccall relies on a deprecated conversion.

@StefanKarpinski
Copy link
Member

I think we badly need a system for pattern matching on warnings and showing more helpful errors and warnings. This was suggested by someone (@ivarne maybe) regarding certain method missing errors but could be very useful more generally. It should be done upon displaying the error, not generating it, since it's effectively a presentation-level concern.

@kmsquire
Copy link
Member Author

Yes, this warning is not perfect, but I'm ok with it --- ccall uses convert, and this ccall relies on a deprecated conversion.

My main issue with it is that, while I suspected something like this issue, it took me a bit of hunting and poking at generated code to find. I'm not sure pattern matching would help here.

@ivarne
Copy link
Member

ivarne commented Jul 23, 2014

Ref: #7512

Pattern matching on method errors can anyway only help after the depreciation is removed. Now we will just need to improve the warning message so that people understand what and why.

srp added a commit to srp/PostgreSQL.jl that referenced this issue Aug 1, 2014
The unit tests were causing the following warning to be printed:

WARNING: convert{T}(p::Type{Ptr{T}},a::Array) is deprecated, use convert(p,pointer(a)) instead.
 in convert at deprecated.jl:26
 in PQexecPrepared at /home/srp/.julia/PostgreSQL/src/libpq_common.jl:4
 in executemany at /home/srp/.julia/PostgreSQL/src/dbi.jl:211
 in test_dbi at /home/srp/.julia/PostgreSQL/test/dbi.jl:91
 in include at ./boot.jl:245
 in include_from_node1 at ./loading.jl:128
 in include at ./boot.jl:245
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354

This fixes that.

See JuliaLang/julia#7694 for more info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants