FYI: I am off to do a yacht delivery tomorrow sometime.
I expect to be away at least a week, maybe more.
i will have no internet access.

Mike Maul has full admin access to the repository and can
accept a merge request.

A note on adding test cases: you have to add src/test/regress/rt/*.fdoc,
then run make gentest. Do NOT add test cases directly
to the directory test, even though its in the repo, it will be clobbered.


On 01/04/2013, at 8:55 AM, Wim Lewis wrote:

> I've been messing around with Felix lately. (My interest is in a
> language with lightweight concurrency, a modern-ish type system, and
> good interfacing with existing C codebases.)

Felix is certainly intended to satisfy precisely those goals.

> Looking at Felix's Judy-based garbage collector, I noticed it would be
> pretty simple to model the foreign object using a Felix shape_t and
> track the pointer using Felix's GC, so that the foreign library's
> finalizer is called appropriately when the object becomes unreachable. I
> implemented this, and it seems to work pretty well with only small
> changes to the Felix runtime:
> 
> I added an add_foreign() call to src/gc/flx_collector.cpp (and a
> corresponding remove_foreign(), although I haven't had a need for it).

Thanks! I was always going to provide this, just one of a long list
of things. It's slightly tricky as you note. There are several cases:

1.  Transfer of ownership.

You know for sure the object was allocated with malloc AND
the foreign library provides a finaliser function that does NOT
delete the object (or doesn't provide a finaliser at all). 

The library transfers control to you, so you're expected to delete
the object.

In this case, provided you have the length of the object
so you can make a shape for it, Felix can take control of the
object entirely and you can forget about it.

This works because Felix itself uses malloc as its allocator.

2. Stewardship.

This method can be used when the library provides a delete
function which both finalises the store and (perhaps) deletes the
associated memory. 

So Felix must NOT delete the memory using "free", but you want
Felix to call the finaliser. 

This appears to be the case you have implemented below:

> impl_add_foreign() is essentially the same as impl_allocate() without
> the call to allocator->allocate().  And in impl_finalise(), I avoid
> calling post_delete() if the shape's flags include gc_flags_persistent.
> The rest was just a bunch of plumbing so that "requires property
> "gc_persistent"" on a type will set the corresponding flag on a type's
> shape, and to expose add_foreign in flx.gc. A few foreign types will
> need a custom scanner, but many won't.

This all seems perfect.

> I think this is a useful addition to Felix, and would like a little
> feedback on the idea. Is gc_persistent the right flag to use for this
> behavior? Is there a reason not to use the Felix GC to track pointers
> that were not originally allocated by it?

Well, the spelling "persistent" is suggestive of a bit more than 
"don't delete".  The finaliser may actually free the object so actually
it isn't persistent. But this is a spelling nit and Felix already has quite
a few such nits .. :)

However there's also a related interface you might as well add
at the same time:

        acquire_foreign().

This is the same as add_foreign() except it does NOT set the
persistent flag. This is a full scale take over of the object.

=============


[BTW: you may notice serialisation is hacked. It cannot work for Judy
or  any other types with custom scanners (in fact it will crash the system).
It needs to be changed to use a more complex callback that fits in with
how scanners work instead of the testing hack it uses of just using a cast]

--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Own the Future-Intel® Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game 
on Steam. $5K grand prize plus 10 genre and skill prizes. 
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to