Skip to content

Commit

Permalink
More ADDR_OBJ -> CONST_ADDR_OBJ changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Sep 14, 2017
1 parent 410eed6 commit 42a48ea
Show file tree
Hide file tree
Showing 25 changed files with 229 additions and 230 deletions.
66 changes: 32 additions & 34 deletions src/blister.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void SaveBlist (
UInt * ptr;

/* logical length */
SaveSubObj(ADDR_OBJ(bl)[0]);
SaveSubObj(CONST_ADDR_OBJ(bl)[0]);
ptr = BLOCKS_BLIST(bl);
for (i = 1; i <= NUMBER_BLOCKS_BLIST( bl ); i++ )
SaveUInt(*ptr++);
Expand Down Expand Up @@ -256,10 +256,10 @@ void LoadBlist (
** 'CleanBlist' is the function in 'CleanObjFuncs' for boolean lists.
*/

Obj DoCopyBlist(Obj list, Int mut) {
Obj copy;
UInt *l;
UInt *c;
Obj DoCopyBlist(Obj list, Int mut)
{
Obj copy;

/* make a copy */
if ( mut ) {
copy = NewBag( MUTABLE_TNUM(TNUM_OBJ(list)), SIZE_OBJ(list) );
Expand All @@ -268,11 +268,9 @@ Obj DoCopyBlist(Obj list, Int mut) {
copy = NewBag( IMMUTABLE_TNUM( TNUM_OBJ(list) ), SIZE_OBJ(list) );
}


/* copy the subvalues */
l = (UInt*)(ADDR_OBJ(list));
c = (UInt*)(ADDR_OBJ(copy));
memcpy((void *)c, (void *)l, sizeof(UInt)*(1+NUMBER_BLOCKS_BLIST(list)));
memcpy(ADDR_OBJ(copy), CONST_ADDR_OBJ(list),
sizeof(UInt)*(1+NUMBER_BLOCKS_BLIST(list)));

/* return the copy */
return copy;
Expand Down Expand Up @@ -301,7 +299,7 @@ Obj CopyBlist (
/* 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, 1, CONST_ADDR_OBJ(list)[0] );
SET_ELM_PLIST( tmp, 2, copy );
ADDR_OBJ(list)[0] = tmp;
CHANGED_BAG(list);
Expand All @@ -322,7 +320,7 @@ Obj ShallowCopyBlist ( Obj list)
*/
Obj CopyBlistCopy(Obj list, Int mut)
{
return ELM_PLIST(ADDR_OBJ(list)[0], 2);
return ELM_PLIST(CONST_ADDR_OBJ(list)[0], 2);
}


Expand All @@ -343,7 +341,7 @@ void CleanBlist (
void CleanBlistCopy(Obj list)
{
/* remove the forwarding pointer */
ADDR_OBJ(list)[0] = ELM_PLIST(ADDR_OBJ(list)[0], 1);
ADDR_OBJ(list)[0] = ELM_PLIST(CONST_ADDR_OBJ(list)[0], 1);

/* now it is cleaned */
RetypeBag(list, TNUM_OBJ(list) - COPYING);
Expand Down Expand Up @@ -1257,7 +1255,7 @@ Obj FuncBLIST_LIST (
UInt block; /* one block of boolean list */
UInt bit; /* one bit of block */
Int lenList; /* logical length of the list */
Obj * ptrSub; /* pointer to the sublist */
const Obj * ptrSub; /* pointer to the sublist */
UInt lenSub; /* logical length of sublist */
UInt i, j, k = 0, l; /* loop variables */
long s, t; /* elements of a range */
Expand Down Expand Up @@ -1316,7 +1314,7 @@ Obj FuncBLIST_LIST (
blist = NewBag( T_BLIST, SIZE_PLEN_BLIST( lenList ) );
ADDR_OBJ(blist)[0] = INTOBJ_INT(lenList);
ptrBlist = BLOCKS_BLIST(blist);
ptrSub = ADDR_OBJ(sub);
ptrSub = CONST_ADDR_OBJ(sub);

/* loop over <sub> and set the corresponding entries to 'true' */
s = INT_INTOBJ( GET_ELM_RANGE( list, 1 ) );
Expand Down Expand Up @@ -1368,21 +1366,21 @@ Obj FuncBLIST_LIST (

/* run over the elements of <sub> and search for the elements */
for ( l = 1; l <= LEN_LIST(sub); l++ ) {
if ( ADDR_OBJ(sub)[l] != 0 ) {
if ( CONST_ADDR_OBJ(sub)[l] != 0 ) {

/* perform the binary search to find the position */
i = 0; k = lenList+1;
while ( i+1 < k ) {
j = (i + k) / 2;
if ( LT(ADDR_OBJ(list)[j],ADDR_OBJ(sub)[l]) )
if ( LT(CONST_ADDR_OBJ(list)[j],CONST_ADDR_OBJ(sub)[l]) )
i = j;
else
k = j;
}

/* set bit if <sub>[<l>] was found at position k */
if ( k <= lenList
&& EQ( ADDR_OBJ(list)[k], ADDR_OBJ(sub)[l] ) )
&& EQ( CONST_ADDR_OBJ(list)[k], CONST_ADDR_OBJ(sub)[l] ) )
SET_ELM_BLIST( blist, k, True);
}
}
Expand Down Expand Up @@ -1410,12 +1408,12 @@ Obj FuncBLIST_LIST (

/* test if <list>[<l>] is in <sub> */
while ( k <= lenSub
&& LT(ADDR_OBJ(sub)[k],ADDR_OBJ(list)[l]) )
&& LT(CONST_ADDR_OBJ(sub)[k],CONST_ADDR_OBJ(list)[l]) )
k++;

/* if <list>[<k>] is in <sub> set the current bit in block */
if ( k <= lenSub
&& EQ(ADDR_OBJ(sub)[k],ADDR_OBJ(list)[l]) ) {
&& EQ(CONST_ADDR_OBJ(sub)[k],CONST_ADDR_OBJ(list)[l]) ) {
block |= bit;
k++;
}
Expand Down Expand Up @@ -1455,16 +1453,16 @@ Obj FuncBLIST_LIST (
for ( l = 1; l <= lenList; l++ ) {

/* test if <list>[<l>] is in <sub> */
if ( l == 1 || LT(ADDR_OBJ(list)[l-1],ADDR_OBJ(list)[l]) ){
if ( l == 1 || LT(CONST_ADDR_OBJ(list)[l-1],CONST_ADDR_OBJ(list)[l]) ){
while ( k <= lenSub
&& LT(ADDR_OBJ(sub)[k],ADDR_OBJ(list)[l]) )
&& LT(CONST_ADDR_OBJ(sub)[k],CONST_ADDR_OBJ(list)[l]) )
k++;
}
else {
i = 0; k = LEN_PLIST(sub) + 1;
while ( i+1 < k ) {
j = (i + k) / 2;
if ( LT( ADDR_OBJ(sub)[j], ADDR_OBJ(list)[l] ) )
if ( LT( CONST_ADDR_OBJ(sub)[j], CONST_ADDR_OBJ(list)[l] ) )
i = j;
else
k = j;
Expand All @@ -1473,7 +1471,7 @@ Obj FuncBLIST_LIST (

/* if <list>[<k>] is in <sub> set the current bit in the block */
if ( k <= lenSub
&& EQ( ADDR_OBJ(sub)[k], ADDR_OBJ(list)[l] ) ) {
&& EQ( CONST_ADDR_OBJ(sub)[k], CONST_ADDR_OBJ(list)[l] ) ) {
block |= bit;
k++;
}
Expand Down Expand Up @@ -1801,7 +1799,7 @@ Obj FuncUNITE_BLIST_LIST (
UInt block; /* one block of boolean list */
UInt bit; /* one bit of block */
Int lenList; /* logical length of the list */
Obj * ptrSub; /* pointer to the sublist */
const Obj * ptrSub; /* pointer to the sublist */
UInt lenSub; /* logical length of sublist */
UInt i, j, k = 0, l; /* loop variables */
long s, t; /* elements of a range */
Expand Down Expand Up @@ -1880,7 +1878,7 @@ Obj FuncUNITE_BLIST_LIST (

lenSub = LEN_LIST( sub );
ptrBlist = BLOCKS_BLIST(blist);
ptrSub = ADDR_OBJ(sub);
ptrSub = CONST_ADDR_OBJ(sub);

/* loop over <sub> and set the corresponding entries to 'true' */
s = INT_INTOBJ( GET_ELM_RANGE( list, 1 ) );
Expand Down Expand Up @@ -1934,21 +1932,21 @@ Obj FuncUNITE_BLIST_LIST (

/* run over the elements of <sub> and search for the elements */
for ( l = 1; l <= LEN_LIST(sub); l++ ) {
if ( ADDR_OBJ(sub)[l] != 0 ) {
if ( CONST_ADDR_OBJ(sub)[l] != 0 ) {

/* perform the binary search to find the position */
i = 0; k = lenList+1;
while ( i+1 < k ) {
j = (i + k) / 2;
if ( LT(ADDR_OBJ(list)[j],ADDR_OBJ(sub)[l]) )
if ( LT(CONST_ADDR_OBJ(list)[j],CONST_ADDR_OBJ(sub)[l]) )
i = j;
else
k = j;
}

/* set bit if <sub>[<l>] was found at position k */
if ( k <= lenList
&& EQ( ADDR_OBJ(list)[k], ADDR_OBJ(sub)[l] ) )
&& EQ( CONST_ADDR_OBJ(list)[k], CONST_ADDR_OBJ(sub)[l] ) )
SET_ELM_BLIST( blist, k, True);
}
}
Expand All @@ -1972,12 +1970,12 @@ Obj FuncUNITE_BLIST_LIST (

/* test if <list>[<l>] is in <sub> */
while ( k <= lenSub
&& LT(ADDR_OBJ(sub)[k],ADDR_OBJ(list)[l]) )
&& LT(CONST_ADDR_OBJ(sub)[k],CONST_ADDR_OBJ(list)[l]) )
k++;

/* if <list>[<k>] is in <sub> set the current bit in block */
if ( k <= lenSub
&& EQ(ADDR_OBJ(sub)[k],ADDR_OBJ(list)[l]) ) {
&& EQ(CONST_ADDR_OBJ(sub)[k],CONST_ADDR_OBJ(list)[l]) ) {
block |= bit;
k++;
}
Expand Down Expand Up @@ -2024,16 +2022,16 @@ Obj FuncUNITE_BLIST_LIST (
for ( l = 1; l <= lenList; l++ ) {

/* test if <list>[<l>] is in <sub> */
if ( l == 1 || LT(ADDR_OBJ(list)[l-1],ADDR_OBJ(list)[l]) ){
if ( l == 1 || LT(CONST_ADDR_OBJ(list)[l-1],CONST_ADDR_OBJ(list)[l]) ){
while ( k <= lenSub
&& LT(ADDR_OBJ(sub)[k],ADDR_OBJ(list)[l]) )
&& LT(CONST_ADDR_OBJ(sub)[k],CONST_ADDR_OBJ(list)[l]) )
k++;
}
else {
i = 0; k = LEN_PLIST(sub) + 1;
while ( i+1 < k ) {
j = (i + k) / 2;
if ( LT( ADDR_OBJ(sub)[j], ADDR_OBJ(list)[l] ) )
if ( LT( CONST_ADDR_OBJ(sub)[j], CONST_ADDR_OBJ(list)[l] ) )
i = j;
else
k = j;
Expand All @@ -2042,7 +2040,7 @@ Obj FuncUNITE_BLIST_LIST (

/* if <list>[<k>] is in <sub> set the current bit in the block */
if ( k <= lenSub
&& EQ( ADDR_OBJ(sub)[k], ADDR_OBJ(list)[l] ) ) {
&& EQ( CONST_ADDR_OBJ(sub)[k], CONST_ADDR_OBJ(list)[l] ) ) {
block |= bit;
k++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/blister.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static inline Int SIZE_PLEN_BLIST(Int plen)
static inline Int LEN_BLIST(Obj list)
{
GAP_ASSERT(IS_BLIST_REP_WITH_COPYING(list));
return INT_INTOBJ(ADDR_OBJ(list)[0]);
return INT_INTOBJ(CONST_ADDR_OBJ(list)[0]);
}


Expand Down
9 changes: 4 additions & 5 deletions src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,7 @@ void CodeIntExpr (
else {
expr = NewExpr( T_INT_EXPR, sizeof(UInt) + SIZE_OBJ(val) );
((UInt *)ADDR_EXPR(expr))[0] = (UInt)TNUM_OBJ(val);
memcpy((void *)((UInt *)ADDR_EXPR(expr)+1), (void *)ADDR_OBJ(val), (size_t)SIZE_OBJ(val));
memcpy(((UInt *)ADDR_EXPR(expr)+1), CONST_ADDR_OBJ(val), (size_t)SIZE_OBJ(val));
}

/* push the expression */
Expand Down Expand Up @@ -1754,7 +1754,7 @@ void CodeLongIntExpr (
else {
expr = NewExpr( T_INT_EXPR, sizeof(UInt) + SIZE_OBJ(val) );
((UInt *)ADDR_EXPR(expr))[0] = (UInt)TNUM_OBJ(val);
memcpy((void *)((UInt *)ADDR_EXPR(expr)+1), (void *)ADDR_OBJ(val), (size_t)SIZE_OBJ(val));
memcpy((void *)((UInt *)ADDR_EXPR(expr)+1), CONST_ADDR_OBJ(val), (size_t)SIZE_OBJ(val));
}

/* push the expression */
Expand Down Expand Up @@ -1955,7 +1955,7 @@ void CodeStringExpr (
string = NewExpr( T_STRING_EXPR, SIZEBAG_STRINGLEN(GET_LEN_STRING(str)) );

/* copy the string */
memcpy( (void *)ADDR_EXPR(string), ADDR_OBJ(str),
memcpy( (void *)ADDR_EXPR(string), CONST_ADDR_OBJ(str),
SIZEBAG_STRINGLEN(GET_LEN_STRING(str)) );

/* push the string */
Expand Down Expand Up @@ -3444,8 +3444,7 @@ void CodeAssertEnd3Args ( void )
void SaveBody ( Obj body )
{
UInt i;
UInt *ptr;
ptr = (UInt *) ADDR_OBJ(body);
const UInt *ptr = (const UInt *) CONST_ADDR_OBJ(body);
/* Save the new inforation in the body */
for (i =0; i < sizeof(BodyHeader)/sizeof(Obj); i++)
SaveSubObj((Obj)(*ptr++));
Expand Down
6 changes: 2 additions & 4 deletions src/funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,7 @@ Obj DoExecFuncXargs (

#ifdef HPCGAP

void LockFuncArgs (
Obj func,
Obj * args )
static void LockFuncArgs(Obj func, const Obj * args)
{
Int nargs = NARG_FUNC(func);
Int i;
Expand Down Expand Up @@ -1411,7 +1409,7 @@ Obj DoExecFuncXargsL (
PLAIN_LIST( args );
}

LockFuncArgs(func, ADDR_OBJ(args) + 1);
LockFuncArgs(func, CONST_ADDR_OBJ(args) + 1);

/* switch to a new values bag */
SWITCH_TO_NEW_LVARS( func, len, NLOC_FUNC(func), oldLvars );
Expand Down
2 changes: 1 addition & 1 deletion src/hpc/aobjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static inline Obj ATOMIC_SET_ELM_PLIST_ONCE(Obj list, UInt index, Obj value) {

static inline Obj ATOMIC_ELM_PLIST(Obj list, UInt index) {
#ifndef WARD_ENABLED
Obj *contents = ADDR_OBJ(list);
const Obj *contents = CONST_ADDR_OBJ(list);
Obj result;
result = contents[index];
MEMBAR_READ(); /* matching memory barrier. */
Expand Down
2 changes: 1 addition & 1 deletion src/intfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ Int HASHKEY_MEM_NC(const void * ptr, UInt4 seed, Int read)

Int HASHKEY_BAG_NC(Obj obj, UInt4 seed, Int skip, int read)
{
return HASHKEY_MEM_NC((const void *)((UChar *)ADDR_OBJ(obj) + skip), seed,
return HASHKEY_MEM_NC((const UChar *)CONST_ADDR_OBJ(obj) + skip, seed,
read);
}

Expand Down
2 changes: 1 addition & 1 deletion src/macfloat.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef double Double;
#endif

static inline Double VAL_MACFLOAT(Obj obj)
{ Double __val; memcpy(&__val,ADDR_OBJ(obj),sizeof(Double)); return __val; }
{ Double __val; memcpy(&__val,CONST_ADDR_OBJ(obj),sizeof(Double)); return __val; }
static inline void SET_VAL_MACFLOAT(Obj obj, Double val)
{ Double __val = (val); memcpy(ADDR_OBJ(obj),&__val,sizeof(Double)); }

Expand Down
Loading

0 comments on commit 42a48ea

Please sign in to comment.