From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA03397; Wed, 12 Jun 2002 15:09:06 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA03457 for ; Wed, 12 Jun 2002 15:09:05 +0200 (MET DST) Received: from waco.inria.fr (waco.inria.fr [128.93.25.2]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g5CD94b01421; Wed, 12 Jun 2002 15:09:04 +0200 (MET DST) Received: (from verlyck@localhost) by waco.inria.fr (8.11.1/8.11.1) id g5CD94Y09969; Wed, 12 Jun 2002 15:09:04 +0200 Date: Wed, 12 Jun 2002 15:09:04 +0200 Message-Id: <200206121309.g5CD94Y09969@waco.inria.fr> X-Authentication-Warning: waco.inria.fr: verlyck set sender to Bruno.Verlyck@inria.fr using -f To: basile.starynkevitch@cea.fr CC: xavier.leroy@inria.fr, caml-list@inria.fr In-reply-to: <15622.64332.518339.259345@is002254.saclay.cea.fr> (basile.starynkevitch@cea.fr) Subject: Re: [Caml-list] Unix.file_descr -> int ??? From: Bruno.Verlyck@inria.fr References: <20020611213158.A680@max.home> <20020611174527.A14450@pauillac.inria.fr> <15622.64332.518339.259345@is002254.saclay.cea.fr> Mime-Version: 1.0 (generated by tm-edit 7.106) Content-Type: text/plain; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Date: Wed, 12 Jun 2002 09:42:04 +0200 From: Basile STARYNKEVITCH For example, I will very soon add in my program (opensource GPL-ed, see www.poesia-filter.org and its CVS repository PoesiaSoft/PoesiaMonIcap) some code which 1. Create three pipes (using the pipe(2) system call) I O and C 2. Fork(2) a child process 3. in the child process execve(2) a program passing it the file descriptors of I (read-end, i.e. the first file descriptor returned by pipe) O (write-end, i.e. the second file descriptor returned by pipe) and C (read-end). For instance, it may execve a program /usr/libexec/poesiafilter/nlp_italian and passes it as arguments arg[0] = "nlp_italian" arg[1] = "-i" arg[2] = "5" arg[3] = "-o" arg[4] = "7" arg[5] = "-c" arg[6] = "8" arg[7] = "-C" arg[8] = "/etc/poesia/nlp_italian_config" arg[9] is the null pointer and the 5, 7, and 8 are file descriptors number. This seems a legitimate use of file descriptors (there are some Unix programs which does that). The program (which I call the Poesia monitor) which does this Unix-pecular stuff is coded in Ocaml. Obviously it requires a conversion from Unix.file_descr to either integer or strings. If the child program where coded in Ocaml (and some might be), they will need a mean to convert a numerical string arguments (like above arg[4] = "7") to a Unix.file_descr Basile, you should definitely have a look at Cash. Your programs are exactly of the kind Cash was made for. You can easily do everything you told us above, and more (e.g. here, you use any file_descr attached to your pipe, but don't try to force it on file descriptor 3), .. We really need something like val ugly_filedescr_of_int: int -> Unix.file_descr val ugly_int_of_filedescr: Unix.file_descr -> int and I'll guess that in practice they both could be (in that very precise case, for a Unix plateform) defined as Obj.magic suitably "casted". .. and with a much less ugly interface than this. Check around `Channel mapping machinery' in the documentation for detailed explanations. The most important debate is: should Ocaml give access to all Unix ugliness (and dirty tricks)? I don't believe the interface has to be ugly. But then, it can't be as simple as the one you propose :-). There's a real abstraction clash between those little file descriptors and channels, and not only at the typing level. Cash brings you a clean bridge between both. Bruno. ------------------- 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