From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p7GG78rg024134 for ; Tue, 16 Aug 2011 18:07:08 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuQBABqVSk4SB0QlnGdsb2JhbABBqDcUAQEBAQEICwkJFCWBQAEBBAF5BQsLGC5XBhOHcLBPiH+GSASkIw X-IronPort-AV: E=Sophos;i="4.68,234,1312149600"; d="scan'208";a="105604249" Received: from dmz-mailsec-scanner-8.mit.edu ([18.7.68.37]) by mail4-smtp-sop.national.inria.fr with ESMTP; 16 Aug 2011 18:07:02 +0200 X-AuditID: 12074425-b7b15ae000000f71-c8-4e4a9572e9a2 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id F0.A8.03953.2759A4E4; Tue, 16 Aug 2011 12:06:10 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id p7GG700S028621; Tue, 16 Aug 2011 12:07:00 -0400 Received: from localhost (CONTENTS-VNDER-PRESSVRE.MIT.EDU [18.9.64.11]) (authenticated bits=0) (User authenticated as jfc@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p7GG6wR9029895; Tue, 16 Aug 2011 12:06:59 -0400 (EDT) Message-Id: <201108161606.p7GG6wR9029895@outgoing.mit.edu> To: "Richard W.M. Jones" cc: Caml List In-reply-to: <20110816152550.GA21081@annexia.org> References: <20110816152550.GA21081@annexia.org> Comments: In-reply-to "Richard W.M. Jones" message dated "Tue, 16 Aug 2011 16:25:50 +0100." X-Mailer: MH-E 8.2; nmh 1.3; GNU Emacs 23.1.1 Date: Tue, 16 Aug 2011 12:06:58 -0400 From: John Carr X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrBIsWRmVeSWpSXmKPExsUixG6nrls01cvP4MMfTYtPOzawWOy80c/u wORxamYHu8ekF4dYApiiuGxSUnMyy1KL9O0SuDKadhgUtLNXdGx5wdTAuIq1i5GTQ0LARGJt 10UWCFtM4sK99WxdjFwcQgL7GCUmb7vJBJIQEtjAKLH2ZzlEooFJYvKxXrBuXgEricdtG9hA bBEBbYn5z/rZuxg5OJgFlCQebJUDMYUFLCXe/tEAqeAUMJTYd+oPM8TIUolZ3ReYIKqLJGYt tYA4QVfi46KZ7CA2i4CqRNOTE2DlbAKyEo/auxgnMPIvYGRYxSibklulm5uYmVOcmqxbnJyY l5dapGuhl5tZopeaUrqJERxALqo7GCccUjrEKMDBqMTD+7PHy0+INbGsuDL3EKMkB5OSKG/n FKAQX1J+SmVGYnFGfFFpTmrxIUYJDmYlEV7GNKAcb0piZVVqUT5MSpqDRUmc9/UOBz8hgfTE ktTs1NSC1CKYrAwHh5IE72mQoYJFqempFWmZOSUIaSYOTpDhPEDD94PU8BYXJOYWZ6ZD5E8x KkqJ8y4DSQiAJDJK8+B6YRH+ilEc6BVh3mMgVTzA5ADX/QpoMBPQ4Fu7PEAGlyQipKQaGHdM fbngQeDeZ37dAt0G1lbZu5tYpmf8SWU7xP1EWG17sNy7ndPWZXL/n7VIccK8L1pLFE1/u6w8 mf90D6PUgSzVwmVnPnvsvG84b6lhoYbdpV/zNfbkZe87WKC4p5P1xc/myuNdDM8Ypz57ks3g dP/VhqxVQcsD3JJk1LcVBTEc89uxvndqxkMlluKMREMt5qLiRACl1kz8ywIAAA== Subject: Re: [Caml-list] Interfacing with C: bad practice Richard W.M. Jones wrote: > On Tue, Aug 16, 2011 at 11:37:03AM +0400, Dmitry Bely wrote: > > C compiler first puts "list" pointer on stack and then calls > > caml_copy_string(*s), potentially invalidating "list". Of course, the > > stack copy of "list" is not registered as a global root so wrp_ml_cons > > gets an invalid value. > > I think this must be a bug in your C compiler. The address of list is > stashed in the roots struct, so the C compiler should know that list > can be changed by the call to caml_copy_string. The call f(g(), x) can behave as either temp1 = g() temp2 = x f(temp1, temp2) or temp1 = x temp2 = g() f(temp2, temp1) The order does not need to be deterministic. If the call to g() changes x, the second order results in the function f() receiving the "wrong" value. --John Carr (jfc@mit.edu)