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 7CE1D8009A for ; Sat, 3 Dec 2016 15:01:20 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=ilitzroth@gmail.com; spf=Pass smtp.mailfrom=ilitzroth@gmail.com; spf=None smtp.helo=postmaster@mail-io0-f179.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of ilitzroth@gmail.com) identity=pra; client-ip=209.85.223.179; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ilitzroth@gmail.com"; x-sender="ilitzroth@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of ilitzroth@gmail.com designates 209.85.223.179 as permitted sender) identity=mailfrom; client-ip=209.85.223.179; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ilitzroth@gmail.com"; x-sender="ilitzroth@gmail.com"; 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@mail-io0-f179.google.com) identity=helo; client-ip=209.85.223.179; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ilitzroth@gmail.com"; x-sender="postmaster@mail-io0-f179.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AcK+kGROyXq4cxC7YtzUl6mtUPXoX/o7sNwtQ0KIM?= =?us-ascii?q?zox0Iv3yrarrMEGX3/hxlliBBdydsKMfzbaL+Pq9EUU7or+5+EgYd5JNUxJXwe?= =?us-ascii?q?43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRp?= =?us-ascii?q?OOv1BpTSj8Oq3Oyu5pHfeQtFiT6zbL9oIxi7rQrdutcWjIB/Nqs/1xzFr2dSde?= =?us-ascii?q?9L321oP1WTnxj95se04pFu9jlbtuwi+cBdT6j0Zrw0QrNEAjsoNWA1/9DrugLY?= =?us-ascii?q?TQST/HscU34ZnQRODgPY8Rz1RJbxsi/9tupgxCmXOND9QL4oVTi+6apgVQTlgz?= =?us-ascii?q?kbOTEn7G7Xi9RwjKNFrxKnuxx/2JPfbIWMOPZjYq/RYdYWSGxcVchTSiNBGJux?= =?us-ascii?q?YIkBD+QBM+hWrJTzqUUSohalHwagGPnixyVUinPq36A31fkqHwHc3AwnGtIDqH?= =?us-ascii?q?XUrNDwNKgIV+C10bfHzTHeZPNS2Df99InJcgomofGQXbJ7bM3cyUgrFwPEklWR?= =?us-ascii?q?qJblPzSJ1uQNqGWb4O9gWviui24jsQ1+vj+vxsI1h4TPm4kbxFfE9SBjz4Y0I9?= =?us-ascii?q?21UEF7Yd+4EJtQqiGVLJF6Td8lQ2Ftvisx174IuYajcSQU1JgqwwTTZv+HfoSS?= =?us-ascii?q?/B7vSuicLS1liH9nfL+ygQu5/1K6xe3mTMa01U5HripbndnIsXAAzxnT5dKGSv?= =?us-ascii?q?t550uh2DGP2xzK5uFKPEw5l67WJ4Quwr43kZoTvkDDETHslErqi6+Wc10o+umu?= =?us-ascii?q?6+v5frXrvoGQO5Nwhw3kMakjmtazDfomPgUARWSX5Oax2bn78U38WrpKj/k2kq?= =?us-ascii?q?fDsJDdIMQWvq+5AwtU0oY/6he/FTCm0MgYnXQcI1JFfQiIj4ntO13UPP/4CvK/?= =?us-ascii?q?j0y2kDh33/DGIqHhApLVI3ffirjheLJ951dYyAoy1tBf+4lZCqoBIfL2Qk/+rs?= =?us-ascii?q?bUDh4/MwyuwuboEs9x1o0EWTHHPqjMepnTul+B/O5nHK+pIsc3vzDwMLJts+Tv?= =?us-ascii?q?hn8RkFkbcLmo1N0Qcn/uTdp8JEDMYH/pi9EcHGNCugsiXvbtlF3KBT9XZmqgRa?= =?us-ascii?q?Ug5hk0DYunCcHIQYX70+/J5zuyApADPjMOMVuLC3q9MtzcA/o=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0A6AAC4z0JYf7PfVdFdGgEBAQECAQEBA?= =?us-ascii?q?QgBAQEBFQEBAQECAQEBAQgBAQEBgw0BAQEBAXkyVAeNQJcLiGSHToRLgggrhXc?= =?us-ascii?q?CghYHPxQBAQEBAQEBAQEBARIBAQkLCwkbMoIzGgGCGgEBAQMBIx0BGx0BAwELB?= =?us-ascii?q?gUEBw0qAgIiAREBBQEcBhMbiDkBAw8IDqEKP4t9ggQFAR+DDQWDXwoZJw1UgyI?= =?us-ascii?q?BAQEBAQEEAQEBAQEBAQEXAgEFEoYshFuEdYJXgl0FlHyFaoZLikyQPUmNOYJIF?= =?us-ascii?q?B6BEx+BcxGCbSyCCT00igABAQE?= X-IPAS-Result: =?us-ascii?q?A0A6AAC4z0JYf7PfVdFdGgEBAQECAQEBAQgBAQEBFQEBAQE?= =?us-ascii?q?CAQEBAQgBAQEBgw0BAQEBAXkyVAeNQJcLiGSHToRLgggrhXcCghYHPxQBAQEBA?= =?us-ascii?q?QEBAQEBARIBAQkLCwkbMoIzGgGCGgEBAQMBIx0BGx0BAwELBgUEBw0qAgIiARE?= =?us-ascii?q?BBQEcBhMbiDkBAw8IDqEKP4t9ggQFAR+DDQWDXwoZJw1UgyIBAQEBAQEEAQEBA?= =?us-ascii?q?QEBAQEXAgEFEoYshFuEdYJXgl0FlHyFaoZLikyQPUmNOYJIFB6BEx+BcxGCbSy?= =?us-ascii?q?CCT00igABAQE?= X-IronPort-AV: E=Sophos;i="5.33,735,1477954800"; d="scan'208,217";a="202708249" Received: from mail-io0-f179.google.com ([209.85.223.179]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 03 Dec 2016 15:01:19 +0100 Received: by mail-io0-f179.google.com with SMTP id c21so484338636ioj.1 for ; Sat, 03 Dec 2016 06:01:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=8x16iNhzTil7yi3u4sTrAidsE81eyrZraCUIACMSCd0=; b=G3IfjnyBvhWX3+PjCdSrq3jMaF67lLMzvqiQ2CUhjnTrzd+AvHXgXWf+P9GQdLX04T C2s3Uw9ckXQDgqxBh50ADc3Ao67n+eKiBW18gUNtTGJdpdWi5AvYM5P8+JNHafMER68P nizgSle+lXq6fBvsUeyigKAHGHpBDE3dpV68Ofcg0G7DVFz3WW4HsM0ORrEjd4nrdMjM YOoFcC8KDZalpllPC01rcOdh9CX79DOyrPbvEmxFNg1+sHKDoT3drBva9QSrrsIxt/bA IfOtYFgNBH4e3A15vw4TRYLkODE9Z2wsPUl5A9qwH4uu40ZsPwD2Rz6qfNZ+F4bWTqnE k/yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=8x16iNhzTil7yi3u4sTrAidsE81eyrZraCUIACMSCd0=; b=QPZau/bURR5cN1j7Y/i6wnNwE7xarIozlpGpVVRKaxKIqaDrZb/vJo9hNECZN3B9BQ gSmfgInqdXvVj0UH9UW2EZHUZK7LG1KEXN4SEwfVHZ0FdI1CBqaT2CSUwQoqv4waCXkl NJGvnfXWXpoCdibNim9KNuCoTN45TSuHJBflAUsqwHfVgGCj1m54ZpDOG6oGgH2jaorp p1tGEKgKafw5JiQRMUp3o0TVhzQhtGuNeQEmU6eyP/cBpYDvOaLN4u0Jm0b1QbszPC9m fNcG0QT6a5VKP0fpTntq1/iTZrAs7fyeQnPlvwzx8nY7KwFwSqRaxxLH4JgWZmyvrWbu uFRw== X-Gm-Message-State: AKaTC02/gz4QMxKFwQdg2aqYPsw4bUXsgc16c7PLWQ17UK99jugqRA7g0qS9AZsLE81tSZeVlhb0tpHikbnHJA== X-Received: by 10.107.174.142 with SMTP id n14mr41937460ioo.205.1480773677821; Sat, 03 Dec 2016 06:01:17 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.184.85 with HTTP; Sat, 3 Dec 2016 06:00:57 -0800 (PST) In-Reply-To: <20161203132028.GA28111@annexia.org> References: <20161203132028.GA28111@annexia.org> From: immanuel litzroth Date: Sat, 3 Dec 2016 15:00:57 +0100 Message-ID: To: "Richard W.M. Jones" Cc: OCaML List Mailing Content-Type: multipart/alternative; boundary=001a1144822e0f321a0542c17d12 Subject: Re: [Caml-list] Raising invalid_argument with a constructed string. --001a1144822e0f321a0542c17d12 Content-Type: text/plain; charset=UTF-8 Yes, I've used that solution too, keeping a static fixed string around, it's just not very nice and will break if it's ever multithreaded. Immanuel On Sat, Dec 3, 2016 at 2:20 PM, Richard W.M. Jones wrote: > On Mon, Nov 28, 2016 at 03:39:05PM +0100, immanuel litzroth wrote: > > caml_invalid_argument(str) is no return and does not free it's > > argument. > > So calling it with a string constructed dynamically will mean it'll never > > get freed. > > I could construct an ocaml string and pass that to caml_raise_with_arg, > > but I don't seem to be able to get to the caml_exn_Invalid_argument from > > c. Am I missing something? > > We have the same problem in libguestfs in a few places. The solution > is to use an allocation on the C stack, either a fixed size buffer or > [although we don't currently use this] a variable sized one using > alloca. The string is freed when the stack is unwound. Examples: > > https://github.com/libguestfs/libguestfs/blob/master/ > builder/yajl-c.c#L108-L114 > https://github.com/libguestfs/libguestfs/blob/master/v2v/ > domainxml-c.c#L120 > > Be nice to have a "freeing" version of caml_raise* I suppose. > > Rich. > --001a1144822e0f321a0542c17d12 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Yes, I've used that solution too, keeping a static fix= ed string around,
it's just not very nice and will break if it'= s ever multithreaded.
Immanuel

On Sat, Dec 3, 2016 at 2:20 PM, Richard = W.M. Jones <rich@annexia.org> wrote:
On Mon, Nov 28, 2016 at 03:39:05PM +0100, immanu= el litzroth wrote:
> caml_invalid_argument(str) is no return and does not free it's
> argument.
> So calling it with a string constructed dynamically will mean it'l= l never
> get freed.
> I could construct an ocaml string and pass that to caml_raise_with_arg= ,
> but I don't seem to be able to get to the caml_exn_Invalid_argumen= t from
> c. Am I missing something?

We have the same problem in libguestfs in a few places.=C2=A0 The so= lution
is to use an allocation on the C stack, either a fixed size buffer or
[although we don't currently use this] a variable sized one using
alloca.=C2=A0 The string is freed when the stack is unwound.=C2=A0 Examples= :

https://github.com/li= bguestfs/libguestfs/blob/master/builder/yajl-c.c#L108-L114
https://github.com/libgue= stfs/libguestfs/blob/master/v2v/domainxml-c.c#L120

Be nice to have a "freeing" version of caml_raise* I suppose.

Rich.

--001a1144822e0f321a0542c17d12--