| 748 | } |
| 749 | |
| 750 | Space* |
| 751 | Space::_clone(void) { |
| 752 | if (failed()) |
| 753 | throw SpaceFailed("Space::clone"); |
| 754 | if (!stable()) |
| 755 | throw SpaceNotStable("Space::clone"); |
| 756 | |
| 757 | // Copy all data structures (which in turn will invoke the constructor) |
| 758 | Space* c = copy(); |
| 759 | |
| 760 | if (c->d_fst != &Actor::sentinel) |
| 761 | throw SpaceNotCloned("Space::clone"); |
| 762 | |
| 763 | // Setup array for actor disposal in c |
| 764 | { |
| 765 | unsigned int n = static_cast<unsigned int>(d_cur - d_fst); |
| 766 | if (n == 0) { |
| 767 | // No actors |
| 768 | c->d_fst = c->d_cur = c->d_lst = nullptr; |
| 769 | } else { |
| 770 | // Leave one entry free |
| 771 | c->d_fst = c->alloc<Actor*>(n+1); |
| 772 | c->d_cur = c->d_fst; |
| 773 | c->d_lst = c->d_fst+n+1; |
| 774 | for (Actor** d_fst_iter = d_fst; d_fst_iter != d_cur; d_fst_iter++) { |
| 775 | ptrdiff_t m; |
| 776 | Actor* a = static_cast<Actor*>(Support::ptrsplit(*d_fst_iter,m)); |
| 777 | if (a->prev()) |
| 778 | *(c->d_cur++) = Actor::cast(static_cast<ActorLink*> |
| 779 | (Support::ptrjoin(a->prev(),m))); |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | // Update variables without indexing structure |
| 785 | VarImp<NoIdxVarImpConf>* x = |
| 786 | static_cast<VarImp<NoIdxVarImpConf>*>(c->pc.c.vars_noidx); |
| 787 | while (x != nullptr) { |
| 788 | VarImp<NoIdxVarImpConf>* n = x->next(); |
| 789 | x->b.base = nullptr; x->u.idx[0] = 0; |
| 790 | if (sizeof(ActorLink**) > sizeof(unsigned int)) |
| 791 | *(1+&x->u.idx[0]) = 0; |
| 792 | x = n; |
| 793 | } |
| 794 | // Update variables with indexing structure |
| 795 | c->update(static_cast<ActorLink**>(c->mm.subscriptions())); |
| 796 | |
| 797 | // Re-establish prev links (reset forwarding information) |
| 798 | { |
| 799 | ActorLink* p_a = &pl; |
| 800 | ActorLink* c_a = p_a->next(); |
| 801 | // First update propagators and advisors |
| 802 | while (c_a != &pl) { |
| 803 | Propagator* p = Propagator::cast(c_a); |
| 804 | if (p->u.advisors != nullptr) { |
| 805 | ActorLink* a = p->u.advisors; |
| 806 | p->u.advisors = nullptr; |
| 807 | do { |