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 sympa.inria.fr (Postfix) with ESMTPS id 88A8380161 for ; Wed, 21 Jun 2017 17:50:22 +0200 (CEST) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=john@coherentgraphics.co.uk; spf=PermError smtp.mailfrom=john@coherentgraphics.co.uk; spf=None smtp.helo=postmaster@smtp6.ukhost4u.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of john@coherentgraphics.co.uk) identity=pra; client-ip=188.64.186.150; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="john@coherentgraphics.co.uk"; x-sender="john@coherentgraphics.co.uk"; x-conformance=sidf_compatible Received-SPF: PermError (mail3-smtp-sop.national.inria.fr: cannot correctly interpret sender authenticity information from domain of john@coherentgraphics.co.uk) identity=mailfrom; client-ip=188.64.186.150; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="john@coherentgraphics.co.uk"; x-sender="john@coherentgraphics.co.uk"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@smtp6.ukhost4u.com) identity=helo; client-ip=188.64.186.150; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="john@coherentgraphics.co.uk"; x-sender="postmaster@smtp6.ukhost4u.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AR6HY7BaCArnh6iByoYygATL/LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZr8W4bnLW6fgltlLVR4KTs6sC0LuJ9fi4EUU7or+5+EgYd5JNUxJXwe?= =?us-ascii?q?43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRp?= =?us-ascii?q?OOv1BpTSj8Oq3Oyu5pHfeQtFiT6/bL9oMBm6sRjau9ULj4dlNqs/0AbCrG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AZiqRbiFY8bloruH0TzxVslMZ2tGIlmKF3r4dozCXO0DPnG8OMhkxx4D?= =?us-ascii?q?Vb7pdI8gyRCouxP9zfIzLO3U/AUTspLuztVz++LJnAky9DdvSc+alXyOGTIn1l?= =?us-ascii?q?gUTiM7ifgs6Xd2zU2OhO0h26RV?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BzAACylEpZfZa6QLxdGgEBAQECAQEBA?= =?us-ascii?q?QgBAQEBFQEBAQECAQEBAQgBAQEBgyplgQ0Hg2WLDJBpmAkuhXYCgnRDFAEBAQE?= =?us-ascii?q?BAQEBAQEBEgEBCxQIV4IzJAGCQAEBAQECASMdAQE3AQQLCxgCAiYCAlcGE4okD?= =?us-ascii?q?AELqRFrgiaDCAEBBYhFAQEBAQEFAQEBAQEBAQEYCIELh0IrgnmEaoMSMIIxnme?= =?us-ascii?q?HM40bgXKPMJBGhEs2YEuBBQRJEgGCaIIDghJ1AQGIWwGBDAEBAQ?= X-IPAS-Result: =?us-ascii?q?A0BzAACylEpZfZa6QLxdGgEBAQECAQEBAQgBAQEBFQEBAQE?= =?us-ascii?q?CAQEBAQgBAQEBgyplgQ0Hg2WLDJBpmAkuhXYCgnRDFAEBAQEBAQEBAQEBEgEBC?= =?us-ascii?q?xQIV4IzJAGCQAEBAQECASMdAQE3AQQLCxgCAiYCAlcGE4okDAELqRFrgiaDCAE?= =?us-ascii?q?BBYhFAQEBAQEFAQEBAQEBAQEYCIELh0IrgnmEaoMSMIIxnmeHM40bgXKPMJBGh?= =?us-ascii?q?Es2YEuBBQRJEgGCaIIDghJ1AQGIWwGBDAEBAQ?= X-IronPort-AV: E=Sophos;i="5.39,369,1493676000"; d="scan'208";a="229171970" Received: from smtp6.ukhost4u.com ([188.64.186.150]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jun 2017 17:50:21 +0200 Received: from bluechip4.ukhost4u.com ([188.64.184.40]) by mx2.ukhost4u.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86) (envelope-from ) id 1dNhta-00016K-Hi; Wed, 21 Jun 2017 16:50:20 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=coherentgraphics.co.uk; s=default; h=To:References:Message-Id: Content-Transfer-Encoding:Cc:Date:In-Reply-To:From:Subject:Mime-Version: Content-Type:Sender:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=8WZX74JnUe1NrZTDKo2aVoiRZt4Fe3G5AAGcDpmY5sE=; b=GGlAqLPyiwPqElZEzaRhvgJ9X G91DUFjpBvMW56M7l5QT1MWHk3nqQuNoO5p3MNBeOm8osSeFa8k5AQwz90cgcfsA0KvY+KJxF1lNa WDtNqKFFwU+1+AHL4+sNIU47qNmuDfVG9ifLUqLlFyfRVz+QrS2Y/JMe+Aq5BL6yA/zsle2KTC1oL Isr8lftR1EsyoF9Igt9dUoVWhP7LaOkyy/+5RLgUaCEAEoyyn4s3PRBcZlrr7R6xi5WBkD6wXrnPM 2hoE6pJ3nMHmJeLxmbelOPrq5NxlDOhmhcjq4oeYZ8bEVygTLVNm2VbkJmmH63v5URG04868FcCox ywD9GjAZA==; Received: from a89-154-74-127.cpe.netcabo.pt ([89.154.74.127]:61744 helo=gorge.home) by bluechip4.ukhost4u.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1dNhtZ-002ve2-PK; Wed, 21 Jun 2017 16:50:17 +0100 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) From: John Whitington In-Reply-To: <20170621153902.GM28111@annexia.org> Date: Wed, 21 Jun 2017 16:50:06 +0100 Cc: caml-list@inria.fr Content-Transfer-Encoding: quoted-printable Message-Id: <47446BCC-CCDC-4DD0-A07C-349589DD3FE5@coherentgraphics.co.uk> References: <20170603064431.GL28111@annexia.org> <20170621153902.GM28111@annexia.org> To: "Richard W.M. Jones" X-Mailer: Apple Mail (2.3273) X-AuthUser: john@coherentgraphics.co.uk X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bluechip4.ukhost4u.com X-AntiAbuse: Original Domain - X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - coherentgraphics.co.uk X-Get-Message-Sender-Via: bluechip4.ukhost4u.com: none X-Authenticated-Sender: bluechip4.ukhost4u.com: X-Source: X-Source-Args: X-Source-Dir: X-Originating-IP: 188.64.184.40 X-SpamExperts-Domain: bluechip4.ukhost4u.com X-SpamExperts-Username: 188.64.184.40 X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.12) X-Recommended-Action: accept X-Filter-ID: PqwsvolAWURa0gwxuN3S5YEa3T7JuZT23fGO2rGt3ZjWJUT/2OOhkltStP9eN9kAcVctYRKVHL7p 9GrHXbMbpr5A9Z+RyVGzMfgWDsOZRDBDaxzr0OuOIRF9vYzAM02GWT9beZ2GJHR+6iEW0wuEHl5q lWzHWpHauYzRctXNQtI6x0/KzIWoJKPdFsVMokbnGtSPdOOCJLEdLBGxAsSoQT3f9fQk57X11RKG mHECuYabUuVnV9G6jt6Nkm/S/5AJGNsB/1CRDQSXuT9gFcMPf3LAoPAMeZN+0MWGRUai4TeFwX+d C8kMR9u9r+iOotxy1eYCzSlPQSp2k0ov33y6O8B5O2k8s4y+Ezc/IjrJ8+i8n93Fzbup1FQYzCFL naR9dhYU7Mt2spHdB/k2vFuESSLgW8Z507f1SaPsbvB7tldaa40DxZPJuLUk3zkVKd8pCQ9vQ5sA kCRrE+rImF84Rm80MdtFCFhkQrHbgjUIi7DcgF/0t5rqsxFF4v9Qp7zQwHk7aTyzjL4TNz8iOsnz 6AoGstjtzxzqwD0gnz5PGWvQMLEQ0cIB6ZfJqnElUdaE9MeUABO8Yy/pti/3wQsT9TWCexnHHS0e Iel15PGPVa8OV6Iyx78I0iUXpdGhJFctEgjXIny51RJ3yyIOVX71wEukYspuIwswojsoiyB8OuXo nV+E7OMXRvgtdyMlnmWi5RfuxgcGWpxOSA9P2vmhldNDDFzUOSzyPLdeMeWmJgoc5R/MrCEE+1WN OsTP3uJpR4iUiD6sQooYyD6Ya+GlM9QQ/m4kaT5QcIUqpHJqQSlOy63023Cqb+OaOxRdnCTYBPtj 1xGKHgN63v7sRsfyc5ANWiYzDndSrWq4JdFdwp3i4zUOE7uN8+7B3wZgRt4tiDyVQ580cRApUogE gGaN6fY4ocfmWv3Fe9Iziczdq+A= X-Report-Abuse-To: spam@mx1.ukhost4u.com Subject: Re: [Caml-list] Matching exceptions in C code Hi. > On 21 Jun 2017, at 16:39, Richard W.M. Jones wrote: >=20 > On Sat, Jun 03, 2017 at 07:44:31AM +0100, Richard W.M. Jones wrote: >> I'm trying to catch a Unix_error exception in C code, and extract the >> errno from it. Getting the errno is fine, but the problem is matching >> on the Unix.Unix_error exception. >>=20 >> My original code used the documented method: >>=20 >> retv =3D caml_callbackN_exn (*cb, 4, args); >>=20 >> if (Is_exception_result (retv)) { >> retv =3D Extract_exception (retv); >> if (Field (retv, 0) =3D=3D *caml_named_value ("Unix.Unix_error")) >> ... >>=20 >> However the if statement never matched the exception. (I verified on >> the OCaml side that the correct exception is being thrown). >>=20 >> After reading: >>=20 >> http://caml.inria.fr/pub/ml-archives/caml-list/2006/05/097f63cfb39a8041= 8f95c70c3c520aa8.en.html >> http://caml.inria.fr/pub/ml-archives/caml-list/2009/06/797e2f797f57b8ea= 2a2c0e431a2df312.en.html >>=20 >> it seems I'm not the first person to have this problem. It may be >> that Unix is linked twice, but I'm not really sure about that. I'm >> using -output-obj with unix.cmxa linked into the object file, and also >> -lunix in the link step, which is the documented way to do things, but >> I don't know if that means the Unix module initializes itself twice. >>=20 >> Anyway, I modified the code to this, which *works* and is actually >> more convenient than the documented method (the real code matches on >> several other system exceptions as well): >>=20 >> ... >> retv =3D Extract_exception (retv); >> exn_name =3D String_val (Field (Field (retv, 0), 0)); >> if (strcmp (exn_name, "Unix.Unix_error") =3D=3D 0) { >> int errcode =3D code_of_unix_error (Field (retv, 1)); >=20 > So I found out today that this doesn't work for every exception. >=20 > For 'End_of_file' in particular, 'exn_name' ends up pointing to a bit > of random memory (unfortunately it's not NULL or otherwise easily > detectable), and so the program crashes in the strcmp. End_of_file, Invalid_argument, and Failure are not defined in pervasives.ml= , they are =E2=80=9Cinternal=E2=80=9D in some sense. Perhaps this is the ca= use? John --=20 John Whitington Director, Coherent Graphics Ltd