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

IO.from_in_channel doesn't catch End_of_file #16

Open
ygrek opened this issue Aug 29, 2015 · 0 comments
Open

IO.from_in_channel doesn't catch End_of_file #16

ygrek opened this issue Aug 29, 2015 · 0 comments
Assignees

Comments

@ygrek
Copy link
Owner

ygrek commented Aug 29, 2015

Originally reported on Google Code with ID 11

What steps will reproduce the problem?
1. Compile and run
let x = object
    method input s pos len = raise End_of_file
    method close_in () = ()
end

let () = 
  let input = IO.from_in_channel x in
  let _ = IO.read_all input in
  ()

What is the expected output? What do you see instead?

Expect read_all to return empty string.
Instead exception is raised:
Fatal error: exception End_of_file

What version of the product are you using? On what operating system?
1.5.1, WinXP, ocaml-3.11.0

Please provide any additional information below.

The code in question

let from_in_channel ch =
    let cbuf = String.create 1 in
    let read() =
        try
            if ch#input cbuf 0 1 = 0 then raise Sys_blocked_io;
            String.unsafe_get cbuf 0
        with
            End_of_file -> raise No_more_input
    in
    let input s p l =
        ch#input s p l
    in
    create_in
        ~read
        ~input
        ~close:ch#close_in

Looks like input should catch End_of_file and convert it to No_more_input

    try
        ch#input s p l
    with
      End_of_file -> raise No_more_input

The same goes for other methods. I could prepare a patch if you like.

Reported by ygrekheretix on 2009-07-16 11:58:53

@ygrek ygrek self-assigned this Aug 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant