From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.6 required=5.0 tests=AWL,DNS_FROM_RFC_POST, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr 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 4FB50BC37 for ; Thu, 18 Jun 2009 18:47:37 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoQHAKAMOkrRVditcmdsb2JhbACYJj8BDAoJCRGoDZBuAQMCBIQEBYcj X-IronPort-AV: E=Sophos;i="4.42,245,1243807200"; d="scan'208";a="29776290" Received: from mail-px0-f173.google.com ([209.85.216.173]) by mail3-smtp-sop.national.inria.fr with ESMTP; 18 Jun 2009 18:47:36 +0200 Received: by pxi3 with SMTP id 3so1028939pxi.1 for ; Thu, 18 Jun 2009 09:47:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:from:date:x-google-sender-auth:message-id:subject:to :content-type:content-transfer-encoding; bh=VLMFAp5XPReCJTq3QyLTuM+zu7f/ivnksLsMYOSCqMo=; b=IAUPVDc/FxAbwra5YYKSjxDlijjTBUjausOUA540HOXo4NHa0rtCDyHCxcfO2DE683 l6oEFYawTj0VGehigkG2EXouVELs2lEtrRDOYY4XE0WjGMaNiiL6amnonS2oEqT6dUiP g1jqXcE3olZS4M+76AGHABOmichCP5kfA7RNI= 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:content-type :content-transfer-encoding; b=QmBB3cmPGYCRhJJ015yQDvSykmZjhoBz+KtxtQBTf/UCQkoVgrenkAWyxJK0N/eEkD zhWJ3UcbVAvsCeFNXb584ud97C/mEB6SMX+bilVHFFS3f//9Ev8NX2Ai6wMK3gTal/DC XDxrPt81AkfVwX3S5g7V6DsVObIpHPGukjiQg= MIME-Version: 1.0 Sender: jake.donham@gmail.com Received: by 10.142.242.11 with SMTP id p11mr1045989wfh.199.1245343655079; Thu, 18 Jun 2009 09:47:35 -0700 (PDT) In-Reply-To: <53c655920906180741m71893536he6ea5960c124dddf@mail.gmail.com> References: <200906181416.39314.toots@rastageeks.org> <4A3A3E58.1040300@glondu.net> <53c655920906180741m71893536he6ea5960c124dddf@mail.gmail.com> From: Jake Donham Date: Thu, 18 Jun 2009 09:47:15 -0700 X-Google-Sender-Auth: 488723b2ceb31bfd Message-ID: Subject: Re: [Caml-list] Uncaught Unix_error. To: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; uncaught:01 runtime:01 statically:01 ocaml:01 -dlambda:01 abstraction:01 complained:01 bytecode:01 toplevel:01 ocaml:01 2009:98 wrote:01 binaries:01 unix:01 unix:01 On Thu, Jun 18, 2009 at 7:41 AM, David Baelde wrote: > Also, note that the call to read that raises the error is from the > same module that tries to catch the exception. > > I'm lost, I'd like to understand when the exception is registered: at > runtime initialization? In this case, only one should ever be > registered (at least it seems easy to enforce). Or is it statically > registered somehow? There are two things going on: First, exception tags in OCaml aren't registered; they consist only of a block containing a distinguished string. You can see this if you compile unix.ml with -dlambda: (let (Unix_error/197 (makeblock 0 "Unix.Unix_error")) (Enforcing that there is only one of these seems a little bit delicate with respect to module abstraction.) Second, exceptions raised from C use Callback.register_exception, which registers the exception (that is, the block containing the distinguished string) globally. If you link Unix twice, loading the second one overwrites the registration of the first. Now an exception raised from C, by either Unix, cannot be caught by the first Unix but only by the second. I complained about this a while back and suggested that the bytecode linker prevent you from linking the same module twice, but it occurs to me now that it's necessary to allow this for the toplevel. (Still perhaps there could be a flag for strict checking.) I think the best solution is to be sure you have not linked Unix twice. The objinfo tool (under tools/ in the OCaml distribution) is useful for checking libraries; for linked binaries it's probably easiest just to check the link command. Jake