I'm now writing code that, given a pointer to an object (or several) finds the
transitive closure of all pointers.

The idea is the encoder routine is given a pointer and finds the transitive
closure then serialises all those objects (into a single string).

The decoder deserialises them, keeping track of the new object pointer
for each old pointer, then afterwards it runs through all the objects,
resetting all the pointers in them from old ones to the corresponding
new ones.

However I've snookered myself! Originally the shape object pointed
to an array of offsets into the object where pointers were located.

However this only works for Felix objects. It would not work for, say,
an STL vector of addresses. It would not work for a Judy array either.

So to fix this I changed it to use (lambda) abstraction.
The old pointer to the offsets got changed to a void *.
A new slot got added to the shape, in which one stores
a pointer to a C function that can do the scanning: this
function gets passed the client_data, as well as the
collector, shape, etc.

Then the old method got put into a C function "scan_by_offsets",
which the compiler puts there unless the programmer specifies
a different scanner. Here's an example, for a Judy1Array:

  private type J1Array_ = "void*"
    requires 
      scanner "::flx::gc::generic::Judy1_scanner",
      header '#include "flx_judy_scanner.hpp"',
      finaliser '_j1free',
      j1free
  ;

The actual C type of a scanner is:

typedef void *scanner_t(collector_t*, gc_shape_t*, void *, unsigned long, int);

The void* there is the client data, the unsigned long is a varray used slot 
repeat
count, and the trailing int is a recursion limiter.

So here's the problem: these scanners do this:

        collector->register_pointer(q, reclimit);

with a pointer q, when they find one. 

And therein lies the problem. We want to collect all the pointers,
but instead the GC is grabbing them :)

To fix this .. I will have to make  the scanner accept another pair
of arguments: a callback function with a client pointer. This function
will normally say:

        void process_pointer (void *client_data, void *pointer, int reclimit) 
        {
                collector_t *collector = (collector_t*)client_data;
                collector -> register_pointer (pointer, reclimit);
        }

however now we can retrieve the scanner for any object, make
our own callback, pass that to the scanner, and have it do
something else, like add the pointers to a list.

Messy!

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




------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to