feeley/gambit — pull request #60 by euccastro (2013-12-25 14:54:14+00:00)
Title: "Dependent" version of foreign pointers.

To use, you define a _dependent_ version of a pointer:

(c-define-type dependent-child (##dependent-pointer "child"))

and to link it to some other object you call:

(##register-foreign-dependency! child parent).

You can call this any number of times and dependencies will be accumulated in a list. You can get that list saying:

(##foreign-dependencies child).

Other than that, the pointer works like a regular one.

This interface was chosen to make good etiquette convenient. A determined user can always clobber the dependencies from C code if they really want. I didn't add a helper to remove a dependency because I couldn't think of a realistic use case for it. That can be added later if someone produces a compelling use case.

Everything is prefixed with ## because this is intended as a low level facility.

Since the main purpose of this is to help with memory management, I considered forcing these to be nonnull pointers. That would be harder for a user to work around, so I chose to lean on the side of not making this assumption.