Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Unix.file_descr -> int ???
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] Unix.file_descr -> int ???
From: Damien Doligez <damien.doligez@inria.fr>
> >Windows version:
> >
> >let dump_handle (h : Unix.file_descr) =
> >  let obj = Obj.repr h in
> >  if Obj.is_block obj && Obj.tag obj = Obj.custom_tag then
> >    Nativeint.format "%x" (Obj.obj obj)
> >  else invalid_arg "dump_handle"
> 
> This does not work.  You are printing the address of the custom block
> that contains the handle, but this address can change during program
> execution.

Indeed, this is buggy. But you could have given the right answer :-)

let dump_handle (h : Unix.file_descr) =
  let obj = Obj.repr h in
  if Obj.is_block obj && Obj.tag obj = Obj.custom_tag then
    Nativeint.format "%x" (Obj.obj (Obj.field obj 1))
  else invalid_arg "dump_handle"

Jacques Garrigue
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners