Skip to content

Commit

Permalink
Revert "in unsafe_ref, special case Any to fix #2458"
Browse files Browse the repository at this point in the history
This reverts commit e8d6ba3.
  • Loading branch information
JeffBezanson committed Mar 6, 2013
1 parent 98f57c3 commit ede8b47
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 2 additions & 8 deletions base/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,21 @@ convert(::Type{Ptr{Uint8}}, s::ByteString) = convert(Ptr{Uint8}, s.data)

pointer{T}(::Type{T}, x::Uint) = convert(Ptr{T}, x)
pointer{T}(::Type{T}, x::Ptr) = convert(Ptr{T}, x)
pointer(::Type{Any}, x::Uint) = convert(Ptr{Ptr{Any}}, x)
pointer(::Type{Any}, x::Ptr) = convert(Ptr{Ptr{Any}}, x)
# note: these definitions don't mean any AbstractArray is convertible to
# pointer. they just map the array element type to the pointer type for
# convenience in cases that work.
pointer{T}(x::AbstractArray{T}) = convert(Ptr{T},x)
pointer(x::AbstractArray{Any}) = convert(Ptr{Ptr{Any}},x)
pointer{T}(x::AbstractArray{T}, i::Int) = convert(Ptr{T},x) + (i-1)*sizeof(T)
pointer{T}(x::AbstractArray{Any}, i::Int) = convert(Ptr{Ptr{Any}},x) + (i-1)*sizeof(T)

# unsafe pointer to array conversions
pointer_to_array(p, dims) = pointer_to_array(p, dims, false)
function pointer_to_array{T,N}(p::Ptr{T}, dims::NTuple{N,Int}, own::Bool)
ccall(:jl_ptr_to_array, Array{T,N}, (Any, Ptr{T}, Any, Int32),
Array{T,N}, p, dims, own)
end
unsafe_ref(p::Ptr, i::Integer) = pointerref(p, int(i))
unsafe_ref(p::Ptr{Ptr{Any}}, i::Integer) = pointerref(pointerref(p, int(i)), 1)
unsafe_ref(p::Ptr,i::Integer) = pointerref(p, int(i))
unsafe_ref(p::Ptr) = unsafe_ref(p, 1)
unsafe_assign(p::Ptr{Any}, x, i::Integer) = error("cannot unsafe_assign to contents of type Any")
unsafe_assign(p::Ptr{Ptr{Any}}, x::ANY, i::Integer) = pointerset(convert(Ptr{Any},p), x, int(i))
unsafe_assign(p::Ptr{Any}, x::ANY, i::Integer) = pointerset(p, x, int(i))
unsafe_assign{T}(p::Ptr{T}, x, i::Integer) = pointerset(p, convert(T, x), int(i))
unsafe_assign{T}(p::Ptr{T}, x) = unsafe_assign(p, convert(T,x), 1)

Expand Down
4 changes: 3 additions & 1 deletion src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ static Value *emit_pointerref(jl_value_t *e, jl_value_t *i, jl_codectx_t *ctx)
Value *im1 = builder.CreateSub(idx, ConstantInt::get(T_size, 1));
if (!jl_is_bitstype(ety)) {
if (ety == (jl_value_t*)jl_any_type)
return builder.CreateGEP(builder.CreateBitCast(thePtr, jl_pvalue_llvmt), im1);
return builder.CreateLoad(builder.CreateGEP(
builder.CreateBitCast(thePtr, jl_ppvalue_llvmt),
im1));
if (!jl_is_structtype(ety) || jl_is_array_type(ety) || !jl_is_leaf_type(ety))
jl_error("pointerref: invalid pointer type");
uint64_t size = ((jl_datatype_t*)ety)->size;
Expand Down

0 comments on commit ede8b47

Please sign in to comment.