caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Josh Berdine <josh@berdine.net>
To: "Martin R. Neuhäußer" <post@marneu.com>,
	"Török Edwin" <edwin+ml-ocaml@etorok.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Presumed bug in OCaml's garbage collector or in its Weak module...
Date: Sat, 18 Jun 2016 11:59:40 +0100	[thread overview]
Message-ID: <jk60iglh22iwyr.fsf@fb.com> (raw)
In-Reply-To: <01CFEDAE-C1CB-4968-9FDF-1EC004CC027A@marneu.com>

On Fri, Jun 17 2016, Martin R. Neuhäußer wrote:

> Thanks for the good point! And yes, the weak sets use Weak.get_copy internally.

I have also run into this when writing C bindings for a library with ref-counted memory management, where the OCaml finalizers decremented the C counts.  Since the functions in the structure passed to Weak.Make can be passed shallow copies of possibly-dead values, these functions need to be prepared for the underlying C values to have already been finalized.  That's tough to deal with.  (I ended up just letting Z3 hash-cons it's own terms, and kept pointers into Z3 out of my own hash-consed terms.)

> However, the exact semantics of Weak.get_copy is still a bit unclear to me. It creates a „shallow copy“ of a value that might independently be garbage collected. If that shallow copy can survive the finalization of its source, that might cause the problem. Are there any restrictions enforced on values obtained by Weak.get_copy? Or could this even be misused to create arbitrary copies of custom blocks that propagate anywhere?

If the functions passed to Weak.Make store the shallow copy into some global state, it seems that they could live on without constraint.

Cheers, Josh

  reply	other threads:[~2016-06-18 10:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-17 18:09 "Martin R. Neuhäußer"
2016-06-17 19:23 ` Gabriel Scherer
2016-06-18 15:15   ` "Martin R. Neuhäußer"
2016-06-17 19:41 ` Török Edwin
2016-06-17 20:29   ` "Martin R. Neuhäußer"
2016-06-18 10:59     ` Josh Berdine [this message]
2016-06-18 15:11   ` "Martin R. Neuhäußer"
2016-06-18 16:54   ` Leo White
2016-06-21 12:43     ` François Bobot
2016-06-21 19:37       ` Alain Frisch
2016-06-22  8:12         ` François Bobot
2016-06-18 17:39 ` "Martin R. Neuhäußer"
2016-06-21 11:55   ` François Bobot
2016-06-27 11:35     ` AW: " Neuhaeusser, Martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jk60iglh22iwyr.fsf@fb.com \
    --to=josh@berdine.net \
    --cc=caml-list@inria.fr \
    --cc=edwin+ml-ocaml@etorok.net \
    --cc=post@marneu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).