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

Fix CSV.Chunks crashing due to finalized buffer #763

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/chunks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ end

function Base.iterate(x::Chunks, i=1)
i >= length(x.ranges) && return nothing
f = File(x.h; startingbyteposition=x.ranges[i], endingbyteposition=(x.ranges[i + 1] - (i != length(x.ranges))), threaded=x.threaded, typemap=x.typemap, tasks=x.tasks, debug=x.debug)
f = File(x.h; finalizebuffer=false, startingbyteposition=x.ranges[i], endingbyteposition=(x.ranges[i + 1] - (i != length(x.ranges))), threaded=x.threaded, typemap=x.typemap, tasks=x.tasks, debug=x.debug)
return f, i + 1
end

Expand Down
3 changes: 2 additions & 1 deletion src/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ function File(source;
end

function File(h::Header;
finalizebuffer=true,
startingbyteposition=nothing,
endingbyteposition=nothing,
limit::Union{Integer, Nothing}=nothing,
Expand Down Expand Up @@ -344,7 +345,7 @@ function File(h::Header;
lookup = Dict(k => v for (k, v) in zip(h.names, columns))
# for windows, it's particularly finicky about throwing errors when you try to modify an mmapped file
# so we just want to make sure we finalize the input buffer so users don't run into surprises
if Sys.iswindows() && ncols > 0 && !lazystrings(flags[1])
if finalizebuffer && Sys.iswindows() && ncols > 0 && !lazystrings(flags[1])
finalize(buf)
end
return File{something(threaded, false)}(h.name, h.names, types, finalrows, ncols, columns, lookup)
Expand Down
2 changes: 1 addition & 1 deletion src/header.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Checks whether a character or string is valid for use as a delimiter. If
Throws an error if `delim` is invalid.
"""
function checkvaliddelim(delim)
delim != nothing && !isvaliddelim(delim) &&
delim !== nothing && !isvaliddelim(delim) &&
throw(ArgumentError("invalid delim argument = '$(escape_string(string(delim)))', "*
"the following delimiters are invalid: '\\r', '\\n', '\\0'"))
end
Expand Down