Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: bluestorm <bluestorm.dylc@gmail.com>
Cc: Kaustuv Chaudhuri <kaustuv.chaudhuri@inria.fr>,
	caml-list caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Converting variants with only constant constructors  to integers
Date: Tue, 8 Jun 2010 23:37:14 +0900	[thread overview]
Message-ID: <AANLkTilJ6R6MPCY7d2E7IcjFzITMIJipHd2yyH-02TfD@mail.gmail.com> (raw)
In-Reply-To: <AANLkTimcF7VHWskWk3ZINn_ySH4oxIHFvFP1mXmqtw1x@mail.gmail.com>

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 <bluestorm.dylc@gmail.com> 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


  reply	other threads:[~2010-06-08 14:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-07 18:07 Török Edwin
2010-06-07 18:25 ` [Caml-list] " W Dan Meyer
2010-06-07 18:45   ` bluestorm
     [not found] ` <87sk4y7lc7.fsf@gmail.com>
     [not found]   ` <4C0D3B0F.4060502@gmail.com>
2010-06-07 18:32     ` Török Edwin
2010-06-07 18:50       ` W Dan Meyer
2010-06-07 18:48 ` David Allsopp
2010-06-07 19:46   ` Török Edwin
2010-06-07 19:56     ` bluestorm
2010-06-07 22:51       ` W Dan Meyer
2010-06-08  7:42         ` David Allsopp
2010-06-08  7:59           ` bluestorm
2010-06-08  9:14             ` David Allsopp
2010-06-08  9:36               ` Luc Maranget
2010-06-08  9:45                 ` David Allsopp
2010-06-08  9:51                   ` Luc Maranget
2010-06-08 10:21                     ` David Allsopp
2010-06-08 10:21                   ` Dario Teixeira
2010-06-08 11:28       ` Kaustuv Chaudhuri
2010-06-08 11:40         ` bluestorm
2010-06-08 14:37           ` Jacques Garrigue [this message]
2010-06-08 18:22             ` Kaustuv Chaudhuri
2010-06-09  1:34               ` Jacques Garrigue
2010-08-23 14:36               ` Damien Doligez

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=AANLkTilJ6R6MPCY7d2E7IcjFzITMIJipHd2yyH-02TfD@mail.gmail.com \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=bluestorm.dylc@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=kaustuv.chaudhuri@inria.fr \
    /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