Skip to content

Commit

Permalink
Revert "only convert Array{T} to Ptr{T} or Ptr{Void} (fix #6073)"
Browse files Browse the repository at this point in the history
This reverts commit 97582fb.
  • Loading branch information
stevengj committed Mar 7, 2014
1 parent 97582fb commit 20c92f8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
4 changes: 0 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ New language features
Library improvements
--------------------

* `convert(Ptr{T1}, x::Array{T2})` is now only defined if `T1 == T2`
or if `T1 == None` ([#6073]). (You can still explicitly `convert`
one pointer type into another if needed.)

* Well-behaved floating-point ranges ([#2333], [#5636]).
Introduced the `FloatRange` type for floating-point ranges with a step,
which will give intuitive/correct results for classically problematic
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ end
### These offsets should be reconfigured to be less error-prone in matches
const chm_com_offsets = Array(Int, length(ChmCommon.types))
ccall((:jl_cholmod_common_offsets, :libsuitesparse_wrapper),
Void, (Ptr{Int},), chm_com_offsets)
Void, (Ptr{Uint8},), chm_com_offsets)
const chm_final_ll_inds = (1:4) + chm_com_offsets[7]
const chm_prt_inds = (1:4) + chm_com_offsets[13]
const chm_ityp_inds = (1:4) + chm_com_offsets[18]
Expand Down
4 changes: 1 addition & 3 deletions base/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ convert{T}(::Type{Ptr{T}}, p::Ptr) = box(Ptr{T}, unbox(Ptr,p))
# object to pointer
convert(::Type{Ptr{Uint8}}, x::Symbol) = ccall(:jl_symbol_name, Ptr{Uint8}, (Any,), x)
convert(::Type{Ptr{Int8}}, x::Symbol) = ccall(:jl_symbol_name, Ptr{Int8}, (Any,), x)
convert{T}(::Type{Ptr{T}}, a::Array) = ccall(:jl_array_ptr, Ptr{T}, (Any,), a)
convert(::Type{Ptr{Uint8}}, s::ByteString) = convert(Ptr{Uint8}, s.data)
convert(::Type{Ptr{Int8}}, s::ByteString) = convert(Ptr{Int8}, s.data)

convert{T}(::Type{Ptr{T}}, a::Array{T}) = ccall(:jl_array_ptr, Ptr{T}, (Any,), a)
convert(::Type{Ptr{None}}, a::Array) = ccall(:jl_array_ptr, Ptr{None}, (Any,), a)

pointer{T}(::Type{T}, x::Uint) = convert(Ptr{T}, x)
pointer{T}(::Type{T}, x::Ptr) = convert(Ptr{T}, x)
# note: these definitions don't mean any AbstractArray is convertible to
Expand Down
14 changes: 6 additions & 8 deletions doc/manual/calling-c-and-fortran-code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,12 @@ When a scalar value is passed with ``&`` as an argument of type
Array conversions
~~~~~~~~~~~~~~~~~

When an ``Array{T}`` is passed to C as a ``Ptr{T}`` or ``Ptr{Void}``
argument, it is "converted" simply by taking the address of the first
element. This is done in order to avoid copying arrays unnecessarily.
To pass an array ``A`` as a pointer of a different type (for example,
passing a ``Float64`` array to a function that operates on
uninterpreted bytes), you can either declare the argument as
``Ptr{Void}`` or you can explicitly call ``convert(Ptr{T},
pointer(A))``.
When an ``Array`` is passed to C as a ``Ptr`` argument, it is
"converted" simply by taking the address of the first element. This is
done in order to avoid copying arrays unnecessarily, and to tolerate the
slight mismatches in pointer types that are often encountered in C APIs
(for example, passing a ``Float64`` array to a function that operates on
uninterpreted bytes).

Therefore, if an ``Array`` contains data in the wrong format, it will
have to be explicitly converted using a call such as ``int32(a)``.
Expand Down

0 comments on commit 20c92f8

Please sign in to comment.