Browse thread
Unsafe features
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-09-03 (11:59) |
From: | Jon Harrop <jon@f...> |
Subject: | Re: [Caml-list] Unsafe features |
On Saturday 03 September 2005 10:40, Florian Weimer wrote: > * Damien Bobillot: > >> The C language interface falls into this category. Are there any > >> other problematic areas? > > > > The Obj.magic function. I don't know exactly what it does, but I > > think it does arbitrary type conversions. > > Apparently, it creates a bit-wise copy of a value and assigns it a new > type. > > I discovered that there are also a couple of undocumented unsafe_* > functions, such as String.unsafe_set, which behave the way their names > imply (no bound schecks). Yes, there is also the "-unsafe" command line option to turn off bounds checking. There is never any need to use Obj (although the alternatives can be quite tedious or inefficient). The marshalled format is likely to change between compiler versions in the future so it should only be used for short-term storage anyway. The C interface is very error prone and is (in general and IMHO) the most likely cause of unsafeness. Programmers writing OCaml-only programs can happily stick to the safe core of the language. However, programmers wishing to use external libraries are likely to encounter problems. I have had segfaults with code using LablGL and the FFTW bindings, for example. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists