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

Fixes for position with nested NoopStreams #203

Merged
merged 7 commits into from
Apr 6, 2024
Merged

Conversation

nhz2
Copy link
Member

@nhz2 nhz2 commented Apr 3, 2024

With this PR the basic fuzzing tests for position while reading finally pass.

elseif mode === :write
return position(stream.stream) + buffersize(stream.buffer1)
elseif mode === :read
else # read
return position(stream.stream) - buffersize(stream.buffer1)
Copy link
Member Author

Choose a reason for hiding this comment

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

If buffer1 is shared by stream.stream and stream this would double count buffersize

elseif mode === :idle
return 0
elseif has_sharedbuf(stream)
return position(stream.stream)
Copy link
Member Author

Choose a reason for hiding this comment

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

Here I treat the buffer as being "owned" by the underlying stream even though it is being shared. This is also why I need to add special cases for writing to a NoopStream that shares its buffer with the underlying stream. The underlying stream must be notified to change from :idle to :write mode before its buffer1 is changed.

@nhz2 nhz2 marked this pull request as ready for review April 3, 2024 02:48
@nhz2 nhz2 requested review from mkitti and jakobnissen April 3, 2024 14:13
@@ -53,16 +53,18 @@ Note that this method may return a wrong position when
- some data have been inserted by `TranscodingStreams.unread`, or
- the position of the wrapped stream has been changed outside of this package.
"""
function Base.position(stream::NoopStream)
function Base.position(stream::NoopStream)::Int64
Copy link
Member

Choose a reason for hiding this comment

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

I'm trying to decide if this should be Int64 or Int. The latter varies based on the system word size.

$ julia +1.10~x86 -E "typeof(0)"
Int32

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, I didn't know juliaup had 32-bit julia.

This should be Int64 to support large files.

src/noop.jl Outdated Show resolved Hide resolved
changemode!(stream, :write)
if has_sharedbuf(stream)
# directly write data to the underlying stream
n = Int(write(stream.stream, b))
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need the explicit cast to Int here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I need this to fix the stats function for NoopStream, but that's for a future PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now the cast isn't doing anything.

changemode!(stream, :write)
if has_sharedbuf(stream)
# directly write data to the underlying stream
n = Int(unsafe_write(stream.stream, input, nbytes))
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need the explicit cast to Int here?

src/noop.jl Outdated Show resolved Hide resolved
@nhz2 nhz2 requested a review from mkitti April 5, 2024 21:27
@nhz2 nhz2 merged commit 182b14f into master Apr 6, 2024
25 checks passed
@nhz2 nhz2 deleted the nz/basic-position-fixes branch April 6, 2024 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants