Skip to content
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
3 changes: 3 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
- os: macOS-latest
arch: aarch64
version: 1
- os: ubuntu-latest
arch: x86
version: 1
steps:
- uses: actions/checkout@v5
- uses: julia-actions/setup-julia@v2
Expand Down
12 changes: 6 additions & 6 deletions src/lazy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ StructUtils.nulllike(::StructUtils.StructStyle, x::LazyValues) = gettype(x) == J

# core method that detects what JSON value is at the current position
# and immediately returns an appropriate LazyValue instance
function _lazy(buf, pos, len, b, opts, isroot=false)
function _lazy(buf, pos::Int, len, b, opts, isroot=false)
Copy link
Member

Choose a reason for hiding this comment

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

This isn't necessary, right? (prefer to remove from a code style perspective)

if opts.jsonlines
return LazyValue(buf, pos, JSONTypes.ARRAY, opts, isroot)
elseif b == UInt8('{')
Expand Down Expand Up @@ -256,7 +256,7 @@ end
# returns a `pos` value that notes the next position where parsing should continue
# this is essentially the `StructUtils.applyeach` implementation for LazyValues w/ type OBJECT
function applyobject(keyvalfunc, x::LazyValues)
pos = getpos(x)
pos::Int = getpos(x)
buf = getbuf(x)
len = getlength(buf)
opts = getopts(x)
Expand Down Expand Up @@ -356,7 +356,7 @@ end
# returns a `pos` value that notes the next position where parsing should continue
# this is essentially the `StructUtils.applyeach` implementation for LazyValues w/ type ARRAY
function applyarray(keyvalfunc, x::LazyValues)
pos = getpos(x)
pos::Int = getpos(x)
buf = getbuf(x)
len = getlength(buf)
opts = getopts(x)
Expand Down Expand Up @@ -544,7 +544,7 @@ isbigfloat(x::NumberResult) = x.tag == BIGFLOAT

@inline function parsenumber(x::LazyValue)
buf = getbuf(x)
pos = getpos(x)
pos::Int = getpos(x)
len = getlength(buf)
opts = getopts(x)
b = getbyte(buf, pos)
Expand Down Expand Up @@ -627,14 +627,14 @@ isbigfloat(x::NumberResult) = x.tag == BIGFLOAT
# if we overflowed, then let's try BigFloat
bres = Parsers.xparse2(BigFloat, buf, startpos, len)
if !Parsers.invalid(bres.code)
return NumberResult(bres.val), startpos + bres.tlen
return NumberResult(bres.val), startpos + Int(bres.tlen)
end
end
if Parsers.invalid(res.code)
error = InvalidNumber
@goto invalid
end
return NumberResult(res.val), startpos + res.tlen
return NumberResult(res.val), Int(startpos + res.tlen)
Copy link
Contributor

Choose a reason for hiding this comment

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

Somewhat tangential: but what if this overflows to a negative position? I guess this means that on 32-bit systems we can't read files larger than 2 GB?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but with the current design, the whole file needs to be loaded into memory before parsing.

Though maybe pos should always be Int64 to avoid needing to worry about overflow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Doing the Int(startpos + res.tlen) will throw an InexactError. Maybe ignore for now. Someone reading a massive file on a 32-bit system is asking for trouble anyway.

else
if overflow
return NumberResult(isneg ? -bval : bval), pos
Expand Down
4 changes: 2 additions & 2 deletions src/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ parse!(x::LazyValue, obj::T; dicttype::Type{O}=DEFAULT_OBJECT_TYPE, null=nothing
# for LazyValue, if x started at the beginning of the JSON input,
# then we want to ensure that the entire input was consumed
# and error if there are any trailing invalid JSON characters
function checkendpos(x::LazyValue, ::Type{T}, pos) where {T}
function checkendpos(x::LazyValue, ::Type{T}, pos::Int) where {T}
Copy link
Member

Choose a reason for hiding this comment

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

remove

buf = getbuf(x)
len = getlength(buf)
if pos <= len
Expand Down Expand Up @@ -427,7 +427,7 @@ end
@generated function StructUtils.maketuple(st::StructStyle, ::Type{T}, x::LazyValues) where {T<:Tuple}
N = fieldcount(T)
ex = quote
pos = getpos(x)
pos::Int = getpos(x)
buf = getbuf(x)
len = getlength(buf)
opts = getopts(x)
Expand Down
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ include(joinpath(dirname(pathof(JSON)), "../test/object.jl"))
include(joinpath(dirname(pathof(JSON)), "../test/lazy.jl"))
include(joinpath(dirname(pathof(JSON)), "../test/parse.jl"))
include(joinpath(dirname(pathof(JSON)), "../test/json.jl"))
include(joinpath(dirname(pathof(JSON)), "../test/arrow.jl"))
# Arrow.jl is broken on 32 bit systems for now :(
if Sys.WORD_SIZE == 64
include(joinpath(dirname(pathof(JSON)), "../test/arrow.jl"))
end

function tar_files(tarball::String)
data = Dict{String, Vector{UInt8}}()
Expand Down
Loading