file_desc

View: New views
4 Messages — Rating Filter:   Alert me  

file_desc

by Robert Fischer-8 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is there a way to convert a file_descr to/from an int in OCaml?  The type is abstract, and there
doesn't seem to be an obvious answer.

Alternatively, is there a way to get at an inherited file_descr from a process I execv'd into?

~~ Robert.

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Re: file_desc

by Serp-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Robert Fischer wrote:

> Is there a way to convert a file_descr to/from an int in OCaml?  The type is abstract, and there
> doesn't seem to be an obvious answer.
>
> Alternatively, is there a way to get at an inherited file_descr from a process I execv'd into?
>
> ~~ Robert.
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>  
Obj.magic is a single way to do this.

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Re: file_desc

by Mark Shinwell-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Jul 01, 2008 at 09:35:53AM -0500, Robert Fischer wrote:
> Is there a way to convert a file_descr to/from an int in OCaml?  The type is
> abstract, and there doesn't seem to be an obvious answer.
>
> Alternatively, is there a way to get at an inherited file_descr from a
> process I execv'd into?

Not in the default standard library, I don't think.  Jane Street's core
library <http://ocaml.janestcapital.com/?q=node/13> contains such a
function, however.  It is implemented as:

    external file_descr_of_int : int -> file_descr = "%identity"

Another approach is to write something like:

    let file_descr_of_int fd =
      assert (fd >= 0);
      assert (Obj.is_int (Obj.repr Unix.stdin));
      ((Obj.magic fd) : Unix.file_descr)

Mark

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Re: file_desc

by Dave Benjamin-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Robert Fischer wrote:
> Is there a way to convert a file_descr to/from an int in OCaml?  The type is abstract, and there
> doesn't seem to be an obvious answer.

If you don't want to use Obj.magic, there is also the Netsys module from
Ocamlnet, which defines these two functions as C extensions:

     val int_of_file_descr : Unix.file_descr -> int
     val file_descr_of_int : int -> Unix.file_descr

Dave

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
LightInTheBox - Buy quality products at wholesale price