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

convert(::Type{Ptr{T1}}, x::Array{T2}) should fail if T1 != T2 #6073

Closed
stevengj opened this issue Mar 6, 2014 · 5 comments · Fixed by #6079
Closed

convert(::Type{Ptr{T1}}, x::Array{T2}) should fail if T1 != T2 #6073

stevengj opened this issue Mar 6, 2014 · 5 comments · Fixed by #6079
Labels
breaking This change will break code needs decision A decision on this change is needed

Comments

@stevengj
Copy link
Member

stevengj commented Mar 6, 2014

Right now, Julia will happily do:

julia> convert(Ptr{Int}, [1.0])
Ptr{Int64} @0x000000010367e470

This is an invitation for bugs; I just ran into this today with a student who was doing ccall(:foo, Void, (Ptr{Cint},), x) and didn't understand why it was failing for x = [1,2,3] or x = [4.0, 5.0].

My preference would be to throw an error in this case. We can still allow convert(::Type{Ptr{T1}}, x::Ptr{T2}) to work, so if you want to do an explicit cast from one pointer type to another you can still do so.

@ivarne
Copy link
Member

ivarne commented Mar 6, 2014

+1

We have reinterpret when you want to do this. Should we keep convert(Ptr{None}, [1,2]) as a special case?

@JeffBezanson
Copy link
Member

Yes I think this is reasonable along with a special case for Ptr{None}.

stevengj added a commit that referenced this issue Mar 7, 2014
@stevengj stevengj reopened this Mar 7, 2014
@stevengj
Copy link
Member Author

stevengj commented Mar 7, 2014

Whoops, this breaks a bunch of the tests (sorry, I though I had run make testall before pushing); need to add some more fixes first.

@stevengj
Copy link
Member Author

stevengj commented Mar 7, 2014

And if it breaks several places in Base (exposing some bugs, actually), it will probably break packages as well, so we'll need to deprecate the old behavior.

@meggart
Copy link
Contributor

meggart commented Apr 29, 2014

Thanks for this change, it made me discover a bug in the NetCDF package, too. Is there a way to get a more meaningful (error?)-message than the deprecation warning? Or will the warning persist for julia 0.3 and an error be generated for julia 0.4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code needs decision A decision on this change is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants