From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 45699BC57 for ; Tue, 8 Jun 2010 16:37:17 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AggCAGryDUzRVaA0kGdsb2JhbACePAgVAQEBAQkJDAcRAx+vQYVIiH0BAQMFglOCPgSDRYpJ X-IronPort-AV: E=Sophos;i="4.53,384,1272837600"; d="scan'208";a="51980907" Received: from mail-pw0-f52.google.com ([209.85.160.52]) by mail3-smtp-sop.national.inria.fr with ESMTP; 08 Jun 2010 16:37:16 +0200 Received: by pwi10 with SMTP id 10so1833102pwi.39 for ; Tue, 08 Jun 2010 07:37:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type; bh=8ApsvkAX0iGCjmzsstLYTQDbIS9M7ve6iZm6/b8JYNI=; b=EYpDieqWD8/7rqnquaWqf3w685LnOfzUYI11EZ5ez7JYGFpvgbnAW9SmMwUl5Y8CNR RaGDyHoU1ynBMlHAf/Gaj6r1XxSKm3ZvsP8JpLRdD7GLmBtZKjQovcw2afx3JxqdOF31 UqRokqICeyP6D8azpdP24L6Zw4EeTvIUEEMus= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=pm9nixm6n4cqTBshtAl2KmUO8UGfZIdNhIjwlRt3mBjbrMKbYziX7c9//5lg91lA9J 0fb4Y+iv5O4e7uoQBcLqipLIzVXXg+OfeGRdXokb85mwIjIr1PVwef5QQrs2Td33u7c3 Pob/G9+C08yJF/yh23qSWLE/YrIjCEUek7/PY= MIME-Version: 1.0 Received: by 10.140.82.6 with SMTP id f6mr445319rvb.74.1276007835279; Tue, 08 Jun 2010 07:37:15 -0700 (PDT) Sender: jacques.garrigue@gmail.com Received: by 10.220.74.130 with HTTP; Tue, 8 Jun 2010 07:37:14 -0700 (PDT) In-Reply-To: References: <4C0D3557.1020200@gmail.com> <010d01cb0672$09f3eb90$1ddbc2b0$@romulus.metastack.com> <4C0D4C88.4070102@gmail.com> Date: Tue, 8 Jun 2010 23:37:14 +0900 X-Google-Sender-Auth: oQAOX7TClKo4QXUqNSOXVrwAvu8 Message-ID: Subject: Re: [Caml-list] Converting variants with only constant constructors to integers From: Jacques Garrigue To: bluestorm Cc: Kaustuv Chaudhuri , caml-list caml-list Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; variants:01 constructors:01 integers:01 segfault:01 segfaults:01 ocaml:01 runtime:01 val:01 1.0:98 1.0:98 wrote:01 caml-list:01 int:01 int:01 arbitrary:02 Of course intify can cause a segmentation fault! # let arr = Array.of_list [intify 1.0; 0];; Segmentation fault You can even have one with Obj.repr. # let arr = Array.of_list [Obj.repr 1.0; Obj.repr 1];; Segmentation fault Only use these things once you understand the details of internal representations... Jacques Garrigue On Tue, Jun 8, 2010 at 8:40 PM, bluestorm wrote: > You're right : that's true in the "int" case and I hadn't considered it. > But if you use the same trick for ('a -> float) or other types you can get a > segfault : > # external floatify : 'a -> float = "%identity";; > external floatify : 'a -> float = "%identity" > # floatify 0;; > Segmentation fault > Also there are other problems with "intify" that may be worse than segfaults > : your application running with nonsense data and failing at an arbitrary > later point. Though ocaml doesn't fail (in the current implementation, it > would be unwise to assume that the GC/runtime will never check this), you > get strange behavior with those integers-wich-are-not-integers : > # let x = intify (1,2);; > val x : int = 70246988845964 > # x * 1 - x;; > - : int = 1