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

Zinc streams' #skip: does nothing for negative arguments #11150

Closed
daniels220 opened this issue Apr 22, 2022 · 3 comments · Fixed by #14815
Closed

Zinc streams' #skip: does nothing for negative arguments #11150

daniels220 opened this issue Apr 22, 2022 · 3 comments · Fixed by #14815

Comments

@daniels220
Copy link
Contributor

Bug description

The majority of Zinc-provided Stream classes, e.g. ZnBuffered{Read|Write}Stream, ZnEncodedStream, use an implementation of #skip: that silently does nothing when given a negative argument. Some of them have good reasons for not supporting skipping backwards, but effectively ignoring the call can introduce subtle, difficult-to-debug issues. I would at minimum expect an error if the stream is asked to do something it cannot do, and in some cases there would be little or no difficulty implementing backwards #skip:, at least within a limited range.

To Reproduce
Steps to reproduce the behavior:

  1. Open a file for reading, e.g. 'foo.txt' asFileReference readStream.
  2. Attempt to skip backwards in the stream, e.g. after an upTo: in order to not actually consume the delimiter.
  3. Wonder why there are missing characters in your output because the stream didn't actually skip back.

Expected behavior
Either correctly skipping backwards (this would be preferable for file streams in particular), or an Error if the stream cannot practically support skipping or you ask for a skip that goes back too far (reasonable for socket streams). A correct skip-backwards for variable-width encoded streams (UTF-8), in particular, is a further complication. I'd be happy in that case with a correct skip-backwards-by-one only—an implementation of PositionableStream>>back rather than a generalized negative #skip:.

Version information:

  • OS: Any
  • Version: Any
  • Pharo Version: 8, but unless this has changed dramatically in 9 I imagine it applies to all versions.

Expected development cost
Adding a simple count < 0 ifTrue: [self error: 'Cannot skip backwards'] or the like to the top of the relevant implementations would be trivial, and I'd be happy to do so if this is the preferred resolution. Correctly implementing skip-backwards for those streams that could practically support it isn't much more work, but I would want anything I did reviewed by someone familiar with their internals to make sure it covers all edge cases.

@Ducasse
Copy link
Member

Ducasse commented Apr 23, 2022

@svenvc

@svenvc
Copy link
Contributor

svenvc commented Sep 28, 2023

@daniels220
Copy link
Contributor Author

Thanks, good to have the gotcha taken care of. I did make a follow-up issue for implementing at least #skip: -1/#back, as this is a very useful capability in conjunction with methods like #upTo:.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants