Skip to content

Commit

Permalink
const CSTR_STRING() and CHARS_STRING().
Browse files Browse the repository at this point in the history
  • Loading branch information
rbehrends committed Sep 20, 2018
1 parent 8c99ad8 commit e482ed5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/listfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Obj FuncAPPEND_LIST_INTR (
SET_LEN_STRING(list1, len1 + len2);
CLEAR_FILTS_LIST(list1);
// copy data, including terminating zero byte
memcpy(CHARS_STRING(list1) + len1, CHARS_STRING(list2), len2 + 1);
memcpy(CHARS_STRING(list1) + len1, CONST_CHARS_STRING(list2), len2 + 1);
return (Obj) 0;
}

Expand Down
8 changes: 4 additions & 4 deletions src/stringobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,12 +724,12 @@ Int EqString (
Obj listR )
{
UInt lL, lR;
UInt1 *pL, *pR;
const UInt1 *pL, *pR;
lL = GET_LEN_STRING(listL);
lR = GET_LEN_STRING(listR);
if (lR != lL) return 0;
pL = CHARS_STRING(listL);
pR = CHARS_STRING(listR);
pL = CONST_CHARS_STRING(listL);
pR = CONST_CHARS_STRING(listR);
return memcmp(pL, pR, lL) == 0;
}

Expand Down Expand Up @@ -937,7 +937,7 @@ Obj ElmsString (
}

/* select the element */
elm = CHARS_STRING(list)[pos-1];
elm = CONST_CHARS_STRING(list)[pos-1];

/* assign the element into <elms> */
CHARS_STRING(elms)[i-1] = elm;
Expand Down
12 changes: 12 additions & 0 deletions src/stringobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,24 @@ static inline Char * CSTR_STRING(Obj list)
return (Char *)ADDR_OBJ(list) + sizeof(UInt);
}

static inline const Char * CONST_CSTR_STRING(Obj list)
{
GAP_ASSERT(IS_STRING_REP(list));
return (const Char *)CONST_ADDR_OBJ(list) + sizeof(UInt);
}

static inline UChar * CHARS_STRING(Obj list)
{
GAP_ASSERT(IS_STRING_REP(list));
return (UChar *)ADDR_OBJ(list) + sizeof(UInt);
}

static inline const UChar * CONST_CHARS_STRING(Obj list)
{
GAP_ASSERT(IS_STRING_REP(list));
return (const UChar *)CONST_ADDR_OBJ(list) + sizeof(UInt);
}

/****************************************************************************
**
*F GET_LEN_STRING( <list> ) . . . . . . . . . . . . . . length of a string
Expand Down

0 comments on commit e482ed5

Please sign in to comment.