From: Jerome Vouillon <Jerome.Vouillon@inria.fr>
To: John Prevost <prevost@maya.com>, Xavier Leroy <Xavier.Leroy@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: Internals details for cmmgen.ml
Date: Sat, 18 Dec 1999 19:56:35 +0100 [thread overview]
Message-ID: <19991218195635.35263@pauillac.inria.fr> (raw)
In-Reply-To: <87d7s5rs09.fsf@isil.maya.com>; from John Prevost on Fri, Dec 17, 1999 at 07:51:02PM -0500
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 : <read:unit> perms
val write_only : <write:unit> perms
val read_write : <read:unit;write:unit> perms
val create : Unix.file_desc -> 'a perms -> int -> int -> 'a t
val unsafe_get : <read:unit;..> t -> int -> char
val unsafe_set : <write:unit;..> t -> int -> char -> unit
val get : <read:unit;..> t -> int -> char
val set : <write:unit;..> 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
next prev parent reply other threads:[~1999-12-19 21:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-12-10 8:12 John Prevost
1999-12-11 18:09 ` Xavier Leroy
1999-12-18 0:51 ` John Prevost
1999-12-18 18:56 ` Jerome Vouillon [this message]
1999-12-23 5:26 ` John Prevost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=19991218195635.35263@pauillac.inria.fr \
--to=jerome.vouillon@inria.fr \
--cc=Xavier.Leroy@inria.fr \
--cc=caml-list@inria.fr \
--cc=prevost@maya.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).