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 UnbufferedCharStream in the Swift runtime. #2092

Merged
merged 1 commit into from
Nov 4, 2017

Conversation

ewanmellor
Copy link
Contributor

The call to stream.read needs to use buffer.count, not buffer.capacity,
as the maxLength. Otherwise, some bytes get dropped on the floor and the
stream is corrupted.

Remove the code to pad self.data back to up to its previous capacity when
copying data at the end of release. This came over from the Java port, but
I don't think it makes sense in Swift, given the copy-on-write Array
value semantics. Instead, just copy the tail of the buffer if there is
anything left to read (i.e. self.data gets smaller) and when there is nothing
in the buffer to read, reset to the specified bufferSize (i.e. self.data
goes back to the specified self.bufferSize.

Remove debug print statement that was accidentally left in.

The call to stream.read needs to use buffer.count, not buffer.capacity,
as the maxLength.  Otherwise, some bytes get dropped on the floor and the
stream is corrupted.

Remove the code to pad self.data back to up to its previous capacity when
copying data at the end of release.  This came over from the Java port, but
I don't think it makes sense in Swift, given the copy-on-write Array
value semantics.  Instead, just copy the tail of the buffer if there is
anything left to read (i.e. self.data gets smaller) and when there is nothing
in the buffer to read, reset to the specified bufferSize (i.e. self.data
goes back to the specified self.bufferSize.

Remove debug print statement that was accidentally left in.
@ewanmellor ewanmellor changed the title Fix UnbufferedCharStream. Fix UnbufferedCharStream in the Swift runtime. Oct 31, 2017
@parrt parrt modified the milestones: 4.7.1, 4.7 Nov 4, 2017
@parrt parrt merged commit 85aaf1b into antlr:master Nov 4, 2017
@ewanmellor ewanmellor deleted the swift-fix-unbufferedcharstream branch November 4, 2017 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants