From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 64E8FBDDB for ; Sat, 3 Sep 2005 13:59:17 +0200 (CEST) Received: from pih-relay06.plus.net (fuzznuts.plus.net [212.159.14.133] (may be forged)) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j83BxGJR000322 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Sat, 3 Sep 2005 13:59:17 +0200 Received: from [80.229.56.224] (helo=chetara) by pih-relay06.plus.net with esmtp (Exim) id 1EBWfr-0007qp-M1 for caml-list@yquem.inria.fr; Sat, 03 Sep 2005 12:59:07 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Unsafe features Date: Sat, 3 Sep 2005 12:19:42 +0100 User-Agent: KMail/1.7.2 References: <87slwny8xs.fsf@mid.deneb.enyo.de> <2D13837B-0BDC-4E14-86DE-ADCCE2E3BC78@m4x.org> <87y86elcb2.fsf@mid.deneb.enyo.de> In-Reply-To: <87y86elcb2.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200509031219.42582.jon@ffconsultancy.com> X-Miltered: at nez-perce with ID 43199014.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 florian:01 damien:01 -unsafe:01 compiler:01 ocaml-only:01 segfaults:01 lablgl:01 bindings:01 ocaml:01 frog:98 wrote:01 arbitrary:01 imho:01 functions:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 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