Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,16 @@ end
# one-liner suggested from ScottPJones
consumeBOM(buf, pos) = (length(buf) >= 3 && buf[pos] == 0xef && buf[pos + 1] == 0xbb && buf[pos + 2] == 0xbf) ? pos + 3 : pos

if isdefined(Base,:wrap)
__wrap(x,pos) = Base.wrap(Array,x,pos)
if isdefined(Base, :Memory)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you get rid of this entire function and just make it use view

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i want view(x::Array) return x, and view(x::Memory) does not work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or do you mean in the function getbytebuffer itself?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this function only has one use and now that view isn't a new name from base you can just use it without the check.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Julia 1.11 also has Base.Memory (but not the recent wrap rename) - Will this PR be backwards compatible?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the wrap->view will be back-ported to 1.11

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems rude to break people on the current RC. Can we put in appropriate checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add an extra if for the case that Memory and wrap is defined

if isdefined(Base,:wrap)
__wrap(x) = Base.wrap(Array,x,length(x))
__wrap(x::Array) = x
else
__wrap(x) = view(x,Base.OneTo(length(x)))
__wrap(x::Array) = x
end
else
__wrap(x,pos) = x
__wrap(x) = x
end

# whatever input is given, turn it into an AbstractVector{UInt8} we can parse with
Expand All @@ -267,7 +273,7 @@ end
x = x.data
return parent(x), first(x.indices), last(x.indices), tfile
else #support from IOBuffer containing Memory
y = __wrap(x.data,length(x.data)) #generates a Vector{UInt8} from Memory{UInt8}
y = __wrap(x.data) #generates a Vector{UInt8} from Memory{UInt8}, if available.
return y, x.ptr, x.size, tfile
end
elseif x isa Cmd || x isa IO
Expand Down