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

Bad file descriptor #4091

Closed
vicuna opened this issue Aug 28, 2006 · 1 comment
Closed

Bad file descriptor #4091

vicuna opened this issue Aug 28, 2006 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Aug 28, 2006

Original bug ID: 4091
Reporter: Christoph Bauer
Status: closed (set by @damiendoligez on 2006-08-29T14:29:58Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 3.09.2
Category: ~DO NOT USE (was: OCaml general)

Bug description

Here is an example for an Bug.
It should write the string "hello" in a file but raises an error.
Objective Caml version 3.09.2

(* Helper function *)

let with_out_channel filename f =

let ch = open_out filename in
  try
    let result = f ch in
    close_out ch;
    result
with exc ->
  close_out ch;
  raise exc          ;;

val with_out_channel : string -> (out_channel -> 'a) -> 'a =

(* f should do the hard work *)

let f ch s = output_string ch s;;

val f : out_channel -> string -> unit =

(* checking the type *)

with_out_channel "/tmp/t.txt" f;;

  • : string -> unit =

(* looks good. apply *)

with_out_channel "/tmp/t.txt" f "test";;

Exception: Sys_error "Bad file descriptor".

(* working workaround *)

with_out_channel "/tmp/t.txt" (fun ch -> f ch "test");;

  • : unit = ()
@vicuna
Copy link
Author

vicuna commented Aug 28, 2006

Comment author: Christoph Bauer

Please ignore this bug report. It's correct, that the channel is closed before f is called.

@vicuna vicuna closed this as completed Aug 29, 2006
@vicuna vicuna added the bug label Mar 19, 2019
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

1 participant