From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 0A1B4BC57 for ; Tue, 8 Jun 2010 13:41:01 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiECAGfJDUzRVaE0mGdsb2JhbACeOQgVAQEBAQEICQwHESKrfYIChVsuiE8BAQMFglOCPgSODg X-IronPort-AV: E=Sophos;i="4.53,384,1272837600"; d="scan'208";a="52666543" Received: from mail-fx0-f52.google.com ([209.85.161.52]) by mail2-smtp-roc.national.inria.fr with ESMTP; 08 Jun 2010 13:41:00 +0200 Received: by fxm19 with SMTP id 19so2471107fxm.39 for ; Tue, 08 Jun 2010 04:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:sender:received :in-reply-to:references:from:date:x-google-sender-auth:message-id :subject:to:cc:content-type; bh=mHZDcfQH3WFISREpRHnCW7oWGnVJjmJRvIhXVREGUwk=; b=v0+GERreNtH1us1WV8jpJYXwoz2xFS43sVz1wNDDGVxl1O04dtgp4NucW9GRGAX9gw 3HYiDMd95+JXqktGRfHaMYbYQkX6nFNkU1IAw89Nd3VXbAfpJ7b5/1dCbhtzDJ9nULc3 zMEV4k9YxHqTKl5boVXbeL7BTFU7BC2srUeu4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; b=W5Ay7iV2KW8YXql241vwB9rF71YML2H5LtDU6i93Ur0yQwH4QEqkbn9xBIaOI/3/Hu xhrhAlLMG51v4SSI1lqNtAJDHkbkXhVpjZsk+KarfuT8WicyTzutso8UQoTGtbMnckBC udrWdwjDA9zguDs+sB/RHfcktcMmkDLzoO7jA= Received: by 10.204.79.204 with SMTP id q12mr7727550bkk.118.1275997260236; Tue, 08 Jun 2010 04:41:00 -0700 (PDT) MIME-Version: 1.0 Sender: gabriel.scherer@gmail.com Received: by 10.204.112.14 with HTTP; Tue, 8 Jun 2010 04:40:40 -0700 (PDT) In-Reply-To: References: <4C0D3557.1020200@gmail.com> <010d01cb0672$09f3eb90$1ddbc2b0$@romulus.metastack.com> <4C0D4C88.4070102@gmail.com> From: bluestorm Date: Tue, 8 Jun 2010 13:40:40 +0200 X-Google-Sender-Auth: d50uMxDWj_lvmUYVlMtr_qtyTZw Message-ID: Subject: Re: [Caml-list] Converting variants with only constant constructors to integers To: Kaustuv Chaudhuri Cc: caml-list caml-list Content-Type: multipart/alternative; boundary=0016e6d7e90d6e51820488834371 X-Spam: no; 0.00; variants:01 constructors:01 integers:01 segfault:01 segfaults:01 ocaml:01 runtime:01 val:01 segfault:01 segfaults:01 ocaml:01 runtime:01 val:01 caml-list:01 int:01 --0016e6d7e90d6e51820488834371 Content-Type: text/plain; charset=ISO-8859-1 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 --0016e6d7e90d6e51820488834371 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable You're right : that's true in the "int" case and I hadn&#= 39;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 =3D "%identit= y";;
external floatify : 'a -> float =3D "%ident= ity"
# floatify 0;;
Segmentation fault

Also there are other problems with "intify" t= hat may be worse than segfaults : your application running with nonsense da= ta 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/run= time will never check this), you get strange behavior with those integers-w= ich-are-not-integers :

# let x =3D intify (1,2);;
val x : int = =3D 70246988845964
# x * 1 - x;;
- : int =3D= 1
--0016e6d7e90d6e51820488834371--