Skip to content

Commit

Permalink
Fix counting of SizeAllBags in ResizeBag
Browse files Browse the repository at this point in the history
also use memmove in one place
  • Loading branch information
stevelinton committed Oct 31, 2017
1 parent 23cefea commit 2be5f06
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/gasman.c
Original file line number Diff line number Diff line change
Expand Up @@ -1251,9 +1251,9 @@ UInt ResizeBag (
#ifdef COUNT_BAGS
/* update the statistics */
InfoBags[type].sizeLive += new_size - old_size;
InfoBags[type].sizeAll += new_size - old_size;
// InfoBags[type].sizeAll += new_size - old_size;
#endif
SizeAllBags += new_size - old_size;
// SizeAllBags += new_size - old_size;

const Int diff = WORDS_BAG(new_size) - WORDS_BAG(old_size);

Expand Down Expand Up @@ -1303,6 +1303,13 @@ UInt ResizeBag (
YoungBags += diff;
AllocBags += diff;

/* In this case we increase the total amount allocated by the
difference */
#ifdef COUNT_BAGS
InfoBags[type].sizeAll += new_size - old_size;
#endif
SizeAllBags += new_size - old_size;

ADD_CANARY();

header->size = new_size;
Expand Down Expand Up @@ -1335,6 +1342,12 @@ UInt ResizeBag (
newHeader->flags = flags;
newHeader->size = new_size;

#ifdef COUNT_BAGS
InfoBags[type].sizeAll += new_size;
#endif
SizeAllBags += new_size;


CANARY_DISABLE_VALGRIND();
/* if the bag is already on the changed bags list, keep it there */
if ( header->link != bag ) {
Expand All @@ -1354,15 +1367,12 @@ UInt ResizeBag (
CANARY_ENABLE_VALGRIND();

/* set the masterpointer */
Bag * src = DATA(header);
Bag * end = src + WORDS_BAG(old_size);
Bag * dst = DATA(newHeader);
SET_PTR_BAG(bag, dst);

/* copy the contents of the bag */
while ( src < end )
*dst++ = *src++;

memmove((void *)dst, (void *)DATA(header),
sizeof(Obj) * WORDS_BAG(old_size));
}

/* return success */
Expand Down

0 comments on commit 2be5f06

Please sign in to comment.