From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA08906 for caml-redistribution; Sun, 19 Dec 1999 22:44:23 +0100 (MET) 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 TAA25267 for ; Sat, 18 Dec 1999 19:56:42 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id TAA00533; Sat, 18 Dec 1999 19:56:35 +0100 (MET) Received: (from vouillon@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA15720; Sat, 18 Dec 1999 19:56:35 +0100 (MET) Message-ID: <19991218195635.35263@pauillac.inria.fr> Date: Sat, 18 Dec 1999 19:56:35 +0100 From: Jerome Vouillon To: John Prevost , Xavier Leroy Cc: caml-list@inria.fr Subject: Re: Internals details for cmmgen.ml References: <87emcv5i5d.fsf@isil.maya.com> <19991211190908.14090@pauillac.inria.fr> <87d7s5rs09.fsf@isil.maya.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Mailer: Mutt 0.89.1 In-Reply-To: <87d7s5rs09.fsf@isil.maya.com>; from John Prevost on Fri, Dec 17, 1999 at 07:51:02PM -0500 Sender: weis On Fri, Dec 17, 1999 at 07:51:02PM -0500, John Prevost wrote: > > If you're really into high-performance stuff, you could fold the > > permission check and the bounds check in one "checkbound" instruction. > > Just arrange the "write enable" flag to be (the Caml integer) 0 if > > write is allowed, and -1 if it is not. Then, generate something like You could also probably make the permission check only once, when the region is created, and use the type system to enforce safety. For instance, the interface could look something like this: type 'a perms type 'a t val read_only : perms val write_only : perms val read_write : perms val create : Unix.file_desc -> 'a perms -> int -> int -> 'a t val unsafe_get : t -> int -> char val unsafe_set : t -> int -> char -> unit val get : t -> int -> char val set : t -> int -> char -> unit The implementation would then be something like this: type 'a perms = int type 'a t = 'a string * int let read_only = 1 let write_only = 2 let read_write = 3 let region_create fd perms offset count = (* Check that "fd" permissions and "perms" matches *) (* Mmap the region and returns it *) let check_bound n i = if i < 0 || i >= n then raise ... let unsafe_get (r, _) i = String.unsafe_get r i let unsafe_set (r, _) i v = String.unsafe_set r i v let get (r, n) i = check_bound n i; String.unsafe_get r i let set (r, n) i v = check_bound n i; String.unsafe_set r i v > (How does -unsafe work, by the way? Does it make the C-- "checkbound" > stuff work differently?) No, this flag is taken into account much earlier: it makes the parser translate "e.(e')" as "Array.unsafe_get e e'" rather than "Array.get e e'" (similarly, it makes use of the unsafe variant instead of the safe one for the other array and string operations). > Hmm. What do you mean by "a more portable implementation"? One which > doesn't require compiler modifications, or one which works with > bytecode? I believe that with bytecode, the C functions are > sufficient. He probably means an implementation that does not require compiler modifications. > As for unsafe string access: but doesn't the pointer point to an > O'Caml block, which includes a tag and length information? The pointer points to the beginning of the data, just after the header. Moreover, this header is ignored for the unsafe string access. -- Jérôme