Modify marshalling (extern.c) to not mutate the heap.

Instead of the "trail", use an explicit hashtable of forwarding
pointers.