diff --git a/src/collectors.cc b/src/collectors.cc index 22845ed1b5..02cdfe882f 100644 --- a/src/collectors.cc +++ b/src/collectors.cc @@ -163,7 +163,7 @@ Obj WordVectorAndClear ( Obj type, Obj vv, Int num ) expm = (1UL << ebits) - 1; /* construct a new object */ - NEW_WORD( obj, type, num ); + obj = NewWord(type, num); /* clear */ ptr = DATA_WORD(obj); @@ -655,7 +655,7 @@ Int Solution( expm = (1UL << ebits) - 1; /* use as right argument for the collector */ - NEW_WORD( g, SC_DEFAULT_TYPE(sc), 1 ); + g = NewWord(SC_DEFAULT_TYPE(sc), 1); /* start clearing , storing the result in */ ptr = (Int*)(ADDR_OBJ(ww)+1); @@ -1471,7 +1471,7 @@ Obj ReducedPowerSmallInt ( /* return the trivial word if is zero */ if ( pow == 0 ) { - NEW_WORD( res, type, 0 ); + res = NewWord(type, 0); return res; } diff --git a/src/objfgelm.cc b/src/objfgelm.cc index 49ece98ea7..cb8e2aefd1 100644 --- a/src/objfgelm.cc +++ b/src/objfgelm.cc @@ -14,7 +14,7 @@ ** the family. Any object of this type looks like: ** ** +------+-----+-------+-------+-----+-----------+ -** | TYPE | len | g1/e1 | g2/e2 | ... | glen/elen | +** | TYPE | len | g1/e1 | g2/e2 | ... | glen/elen | ** +------+-----+-------+-------+-----+-----------+ ** ** where is a GAP integer object and / occupies 8, 16, or 32 @@ -29,16 +29,12 @@ ** of accessing these entries directly you should use the following macros. ** ** -** The file "objects.h" defines the following macros: +** The file "objfgelm.h" defines the following functions and macros: ** -** NEW_WORD( , , ) -** creates a new objects of type with room for +** NewWord(( , ) +** returns a new objects of type with room for ** generator/exponent pairs. ** -** RESIZE_WORD( , ) -** resizes the such that it will hold generator/exponent -** pairs. -** ** ** BITS_WORD( ) ** returns the number of bits as C integers @@ -86,6 +82,9 @@ extern "C" { #include "plist.h" #include "stringobj.h" +#ifdef HPCGAP +#include "hpc/guards.h" +#endif } // OverflowType is a type which is larger enough to detect @@ -97,6 +96,23 @@ template<> struct OverflowType { typedef Int type; }; template<> struct OverflowType { typedef Int8 type; }; +extern Obj NewWord(Obj type, UInt npairs) +{ + Obj word; +#ifdef HPCGAP + ReadGuard(type); +#endif + word = + NewBag(T_DATOBJ, 2 * sizeof(Obj) + npairs * BITS_WORDTYPE(type) / 8L); + ADDR_OBJ(word)[1] = INTOBJ_INT(npairs); + SetTypeDatObj(word, type); +#ifdef HPCGAP + MakeBagReadOnly(word); +#endif + return word; +} + + /**************************************************************************** ** *F FuncNBits_Equal( , , ) @@ -418,7 +434,7 @@ Obj FuncNBits_HeadByNumber ( return l; /* create a new word */ - NEW_WORD( obj, PURETYPE_WORD(l), sl ); + obj = NewWord(PURETYPE_WORD(l), sl); /* copy the part into the word */ po = DATA_WORD(obj); @@ -589,7 +605,7 @@ Obj FuncNBits_AssocWord ( /* construct a new object */ num = LEN_LIST(data)/2; - NEW_WORD( obj, type, num ); + obj = NewWord(type, num); ptr = DATA_WORD(obj); for ( i = 1; i <= num; i++, ptr++ ) { @@ -658,7 +674,7 @@ Obj FuncNBits_ObjByVector ( } /* construct a new object */ - NEW_WORD( obj, type, num ); + obj = NewWord(type, num); ptr = DATA_WORD(obj); for ( i = 1; i <= num; i++, ptr++, j++ ) { @@ -727,7 +743,7 @@ Obj FuncNBits_Power ( /* if is zero return the identity */ pow = INT_INTOBJ(r); if ( pow == 0 ) { - NEW_WORD( obj, PURETYPE_WORD(l), 0 ); + obj = NewWord(PURETYPE_WORD(l), 0); return obj; } @@ -737,7 +753,7 @@ Obj FuncNBits_Power ( /* if is minus one invert */ if ( pow == -1 ) { - NEW_WORD( obj, PURETYPE_WORD(l), nl ); + obj = NewWord(PURETYPE_WORD(l), nl); pl = CONST_DATA_WORD(l); pr = DATA_WORD(obj) + (nl-1); sl = nl; @@ -775,7 +791,7 @@ Obj FuncNBits_Power ( } /* copy into */ - NEW_WORD( obj, PURETYPE_WORD(l), nl ); + obj = NewWord(PURETYPE_WORD(l), nl); pl = CONST_DATA_WORD(l); pr = DATA_WORD(obj); sl = nl; @@ -806,7 +822,8 @@ Obj FuncNBits_Power ( /* create a new word */ apw = ( pow < 0 ) ? -pow : pow; - NEW_WORD( obj, PURETYPE_WORD(l), 2*(sl+1)+apw*(sr-sl-1)+(apw-1) ); + obj = NewWord(PURETYPE_WORD(l), + 2 * (sl + 1) + apw * (sr - sl - 1) + (apw - 1)); /* copy the beginning w * gj^x into */ pl = CONST_DATA_WORD(l); @@ -863,7 +880,7 @@ Obj FuncNBits_Power ( /* create a new word */ apw = ( pow < 0 ) ? -pow : pow; - NEW_WORD( obj, PURETYPE_WORD(l), 2*sl+apw*(sr-sl+1) ); + obj = NewWord(PURETYPE_WORD(l), 2 * sl + apw * (sr - sl + 1)); /* copy the beginning w * gj^x into */ pl = CONST_DATA_WORD(l); @@ -978,7 +995,7 @@ Obj FuncNBits_Product ( return TRY_NEXT_METHOD; } } - NEW_WORD( obj, PURETYPE_WORD(l), nl+(nr-sr)-over ); + obj = NewWord(PURETYPE_WORD(l), nl + (nr - sr) - over); /* copy the part into the word */ po = DATA_WORD(obj); @@ -1065,7 +1082,7 @@ Obj FuncNBits_Quotient ( return TRY_NEXT_METHOD; } } - NEW_WORD( obj, PURETYPE_WORD(l), nl+nr-over ); + obj = NewWord(PURETYPE_WORD(l), nl + nr - over); /* copy the part into the word */ po = DATA_WORD(obj); diff --git a/src/objfgelm.h b/src/objfgelm.h index ebd1f7fb7e..2ba8412031 100644 --- a/src/objfgelm.h +++ b/src/objfgelm.h @@ -12,11 +12,6 @@ #define GAP_OBJFGELM_H #include "objects.h" -#include "plist.h" - -#ifdef HPCGAP -#include "hpc/guards.h" -#endif /**************************************************************************** ** @@ -121,30 +116,12 @@ /**************************************************************************** ** -*F NEW_WORD( , , ) +*F NewWord( , ) ** -** 'NEW_WORD' creates a new object which has the given and room for -** pairs of generator number/exponent. The new word is return in -** . +** 'NewWord' returns a new object which has the given and room for +** pairs of generator number/exponent. */ -static inline Obj NewWord(Obj type, UInt npairs) { - Obj word; -#ifdef HPCGAP - ReadGuard(type); -#endif - word = NewBag(T_DATOBJ,2*sizeof(Obj)+npairs*BITS_WORDTYPE(type)/8L); - ADDR_OBJ(word)[1] = INTOBJ_INT(npairs); - SetTypeDatObj(word, type); -#ifdef HPCGAP - MakeBagReadOnly( word ); -#endif - return word; -} - -#define NEW_WORD(word, type, npairs) \ - do { \ - (word) = NewWord((type), (npairs)); \ - } while(0) +extern Obj NewWord(Obj type, UInt npairs); /****************************************************************************