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

Lwt_io.of_bytes + position don't work #636

Closed
NathanReb opened this issue Nov 20, 2018 · 2 comments
Closed

Lwt_io.of_bytes + position don't work #636

NathanReb opened this issue Nov 20, 2018 · 2 comments
Labels

Comments

@NathanReb
Copy link
Contributor

I you run the following in utop:

let ichan = Lwt_io.of_bytes ~mode:Lwt_io.input (Lwt_bytes.of_string "abcd") in
Lwt_io.position ichan;;

you get:

- : int64 = -4L

which obviously is a bug as you can't set_position on a negative value.

I'm not familiar with Lwt's internals but had a look and it appears of_bytes behaves inconsistently with the broader make.
Here, in make, max depends on the mode while here, in of_bytes, it doesn't.

I found it by writing tests for a function that is supposed to reset the position after processing the channel. I assume it should work on regular channels as if it wasn't, someone would probably have found out by now. Still I'll try it out and let you know.

I'm happy to submit a fix if this is indeed the issue here!

@aantron
Copy link
Collaborator

aantron commented Nov 20, 2018

Confirmed. The code in lwt_io.ml is definitely wrong. Not sure which is the most "right" way to fix it yet, but any reasonable fix is welcome :)

@aantron aantron added the bug label Nov 20, 2018
@NathanReb
Copy link
Contributor Author

Good! I'll give it a shot!

NathanReb pushed a commit to NathanReb/lwt that referenced this issue Nov 20, 2018
NathanReb pushed a commit to NathanReb/lwt that referenced this issue Nov 20, 2018
aantron pushed a commit that referenced this issue Nov 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants