Skip to content

Commit

Permalink
Make structural copy handle Blists properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevelinton authored and fingolfin committed Jul 20, 2017
1 parent 5287c41 commit b0b4223
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions src/blister.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,34 @@ Obj DoCopyBlist(Obj list, Int mut) {

}

Obj CopyBlistImm(Obj list, Int mut)
{
GAP_ASSERT(!IS_MUTABLE_OBJ(list));
return list;
}

Obj CopyBlist (
Obj list,
Int mut )
{

/* don't change immutable objects */
if ( ! IS_MUTABLE_OBJ(list) ) {
return list;
}

return DoCopyBlist(list, mut);
Obj copy;
Obj tmp;

/* immutable objects should never end up here, because
* they have their own handler defined above
*/
GAP_ASSERT(IS_MUTABLE_OBJ(list));

copy = DoCopyBlist(list, mut);
/* leave a forwarding pointer */
tmp = NEW_PLIST( T_PLIST, 2 );
SET_LEN_PLIST( tmp, 2 );
SET_ELM_PLIST( tmp, 1, ADDR_OBJ(list)[0] );
SET_ELM_PLIST( tmp, 2, copy );
ADDR_OBJ(list)[0] = tmp;
CHANGED_BAG(list);
RetypeBag( list, TNUM_OBJ(list) + COPYING );
return copy;
}

Obj ShallowCopyBlist ( Obj list)
Expand All @@ -308,11 +325,9 @@ Obj ShallowCopyBlist ( Obj list)
**
*F CopyBlistCopy( <list>, <mut> ) . . . . . . . copy a already copied blist
*/
Obj CopyBlistCopy (
Obj list,
Int mut )
Obj CopyBlistCopy(Obj list, Int mut)
{
return ADDR_OBJ(list)[0];
return ELM_PLIST(ADDR_OBJ(list)[0], 2);
}


Expand All @@ -330,14 +345,13 @@ void CleanBlist (
**
*F CleanBlistCopy( <list> ) . . . . . . . . . . . . . clean a copied blist
*/
void CleanBlistCopy (
Obj list )
void CleanBlistCopy(Obj list)
{
/* remove the forwarding pointer */
ADDR_OBJ(list)[0] = ADDR_OBJ( ADDR_OBJ(list)[0] )[0];
/* remove the forwarding pointer */
ADDR_OBJ(list)[0] = ELM_PLIST(ADDR_OBJ(list)[0], 1);

/* now it is cleaned */
RetypeBag( list, TNUM_OBJ(list) - COPYING );
/* now it is cleaned */
RetypeBag(list, TNUM_OBJ(list) - COPYING);
}


Expand Down Expand Up @@ -2670,7 +2684,7 @@ static Int InitKernel (
/* install the copy functions */
for ( t1 = T_BLIST; t1 <= T_BLIST_SSORT; t1 += 2 ) {
CopyObjFuncs [ t1 ] = CopyBlist;
CopyObjFuncs [ t1 +IMMUTABLE ] = CopyBlist;
CopyObjFuncs [ t1 +IMMUTABLE ] = CopyBlistImm;
CopyObjFuncs [ t1 +COPYING ] = CopyBlistCopy;
CopyObjFuncs [ t1 +IMMUTABLE +COPYING ] = CopyBlistCopy;
CleanObjFuncs[ t1 ] = CleanBlist;
Expand Down

0 comments on commit b0b4223

Please sign in to comment.