From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr 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 5F2CD80176 for ; Wed, 21 Jun 2017 18:07:14 +0200 (CEST) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=rich@annexia.org; spf=Pass smtp.mailfrom=rich@annexia.org; spf=Pass smtp.helo=postmaster@annexia.org Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of rich@annexia.org) identity=pra; client-ip=80.68.91.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of rich@annexia.org designates 80.68.91.176 as permitted sender) identity=mailfrom; client-ip=80.68.91.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of postmaster@annexia.org designates 80.68.91.176 as permitted sender) identity=helo; client-ip=80.68.91.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="postmaster@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" IronPort-PHdr: =?us-ascii?q?9a23=3Ar3Q+5Rfw83PN0KY2TuAbiI1vlGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxcu+Yh7h7PlgxGXEQZ/co6odzbGH7Oa4ASQp2tWoiDg6aptCVhsI24?= =?us-ascii?q?09vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7?= =?us-ascii?q?Ovr6GpLIj8Swyuu+54Dfbx9GiTe5Y75+Ngm6oRnMvcQKnIVuLbo8xAHUqXVSYe?= =?us-ascii?q?RWwm1oJVOXnxni48q74YBu/SdNtf8/7sBMSar1cbg2QrxeFzQmLns65Nb3uhnZ?= =?us-ascii?q?TAuA/WUTX2MLmRdVGQfF7RX6XpDssivms+d2xSeXMdHqQb0yRD+v9LlgRgP2hy?= =?us-ascii?q?gbNj456GDXhdJ2jKJHuxKquhhzz5fJbI2JKPZye6XQds4YS2VcRMZcTyJPDIOi?= =?us-ascii?q?YYUSDOQBM+lXoJXgqFUBrxSxCxKhBP/sxzJSmnP6wbc33uYnHArb3AIgBdUOsH?= =?us-ascii?q?HModn7KKkSUPy6zKnSwjXZcvxdxDfy5JLPfBw7vPqCWbVwcczPxkk0GQ/Ok1Kd?= =?us-ascii?q?qZbkPzyJ1uQAqHKU7+xmVe2xhG8nqht+riKoxsc2hYnEn4QYwU3H+yVh2Is4Js?= =?us-ascii?q?G0RFR6bNOnCpddszyWO5FrTs4gQmxlvjsxxKcctp6hZicKzYwqxx7BZPyDdIiF?= =?us-ascii?q?+gjsVOCXIThmi3Nleaiwiwy18Ui6xe3wTsi00FBUoSpZitTBtWwB2wbS58WEUP?= =?us-ascii?q?dw+lqt1SyS2w3R6+xIOUU0mrDaK54lzL4wjJ0TsUHbEy/smUX5kK+We14+9eiu?= =?us-ascii?q?7eTofLrnpp6GOINujQH+KKsultSlAeskKggOQ3Sb+eOk2bL/50L5RbFKguQykq?= =?us-ascii?q?nYq5DaOd8WprW5Ag9QyoYs8QyzDzag0NQCnHkINkhJeBydj9uhB1abAvf4C7+A?= =?us-ascii?q?g1WwkTFk2/fAdunjBZXLBnPEkLr7cLBh5FRV0AoyxssZ7JUSF7JXc9zpXUqk/u?= =?us-ascii?q?bZBR8wKQD8/KDCTp1f0YUTQijHVrWYO6P6uFmO6/IuKq+LfoBD62W1EOQs+/O7?= =?us-ascii?q?1SxxolQaZ6T8mMJPMH0=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0A6AgBcmUpZ/7BbRFBdGgEBAQECAQEBA?= =?us-ascii?q?QgBAQEBFQEBAQECAQEBAQgBAQEBgy2FEEuaQQEBAQEBAQaBKJgJhiQCgnRDFAE?= =?us-ascii?q?BAQEBAQEBAQEBaiiCMyQBgkEBBSMPAUYQCxgCAgUTDgICDwUoIYoyEaoTgiaLV?= =?us-ascii?q?AELJoELhRs9gWqDJId8gmEFnmICk1OSG5URNiGBCoEBCEmHED+KIAEBAQ?= X-IPAS-Result: =?us-ascii?q?A0A6AgBcmUpZ/7BbRFBdGgEBAQECAQEBAQgBAQEBFQEBAQE?= =?us-ascii?q?CAQEBAQgBAQEBgy2FEEuaQQEBAQEBAQaBKJgJhiQCgnRDFAEBAQEBAQEBAQEBa?= =?us-ascii?q?iiCMyQBgkEBBSMPAUYQCxgCAgUTDgICDwUoIYoyEaoTgiaLVAELJoELhRs9gWq?= =?us-ascii?q?DJId8gmEFnmICk1OSG5URNiGBCoEBCEmHED+KIAEBAQ?= X-IronPort-AV: E=Sophos;i="5.39,369,1493676000"; d="scan'208";a="229173991" Received: from annexia.org ([80.68.91.176]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 21 Jun 2017 18:06:56 +0200 Received: from rich by annexia.org with local (Exim 4.84_2) (envelope-from ) id 1dNi9f-0006C5-DJ; Wed, 21 Jun 2017 17:06:55 +0100 Date: Wed, 21 Jun 2017 17:06:55 +0100 From: "Richard W.M. Jones" To: John Whitington Cc: caml-list@inria.fr Message-ID: <20170621160655.GT8764@annexia.org> References: <20170603064431.GL28111@annexia.org> <20170621153902.GM28111@annexia.org> <47446BCC-CCDC-4DD0-A07C-349589DD3FE5@coherentgraphics.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <47446BCC-CCDC-4DD0-A07C-349589DD3FE5@coherentgraphics.co.uk> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [Caml-list] Matching exceptions in C code On Wed, Jun 21, 2017 at 04:50:06PM +0100, John Whitington wrote: > >> retv = Extract_exception (retv); > >> exn_name = String_val (Field (Field (retv, 0), 0)); > >> if (strcmp (exn_name, "Unix.Unix_error") == 0) { > >> int errcode = code_of_unix_error (Field (retv, 1)); > > > > So I found out today that this doesn't work for every exception. > > > > 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 “internal” in some sense. Perhaps this is the cause? Actually it's not a random pointer, it's a pointer made of ASCII characters. In other words it seems there is one less indirection. This code works for me: if (Tag_val (Field (exn, 0)) == String_tag) exn_name = String_val (Field (exn, 0)); // for End_of_file else exn_name = String_val (Field (Field (exn, 0), 0)); // for others but I feel like I'm well outside the bounds of valid, supportable use of the OCaml VM here. Rich.