Hello colleagues,

i'm trying to use unsafe_wrap from a pointer from an external call 
(cfunction) to an array access.
Looks like i have type problems:



function read_from_stream_callback(s::IO, buf::Ptr{UInt8}, len::UInt32)

    #b1 = zeros(UInt8,len)
    #nb = readbytes!(s,b1,len)
    
    #for i=1:len
    #    unsafe_store!(buf,b1[i],i)
    #end

    b1 = zeros(UInt8,len)
    unsafe_wrap(b1,buf,len)
    nb = readbytes!(s,b1,len)

    @compat(Int32(0))
end

               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.5.0-rc2+0 (2016-08-12 11:25 UTC)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |  x86_64-linux-gnu

julia> include("png_stream.jl")
ERROR: LoadError: MethodError: no method matching 
unsafe_wrap(::Array{UInt8,1}, ::Ptr{UInt8}, ::UInt32)
Closest candidates are:
  unsafe_wrap(::Type{String}, ::Union{Ptr{Int8},Ptr{UInt8}}, ::Integer) at 
pointer.jl:86
  unsafe_wrap(::Type{String}, ::Union{Ptr{Int8},Ptr{UInt8}}, ::Integer, 
::Bool) at pointer.jl:86
  unsafe_wrap{T}(::Union{Type{Array{T,1}},Type{Array{T,N}},Type{Array}}, 
::Ptr{T}, ::Integer) at pointer.jl:57
  ...
 in read_from_stream_callback(::Base.AbstractIOBuffer{Array{UInt8,1}}, 
::Ptr{UInt8}, ::UInt32) at /home/lobi/juliarepo/png_stream.jl:16
 in read_png_from_stream(::Base.AbstractIOBuffer{Array{UInt8,1}}) at 
/home/lobi/juliarepo/png_stream.jl:26
 in include_from_node1(::String) at ./loading.jl:426
while loading /home/lobi/juliarepo/png_stream.jl, in expression starting on 
line 55

to which i somehow disagree (as long as UInt32 is an Integer).

the commented code runs correctly (copy to but UInt8 seq.)

A better explaination of the error?

Wishing a happy day,
        Andreas


Reply via email to