Changeset 3477 for trunk/src/kash/memalloc.c
- Timestamp:
- Sep 17, 2020, 11:52:16 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/memalloc.c
r3462 r3477 43 43 #include <stdlib.h> 44 44 #include <stddef.h> 45 #include <assert.h>46 45 47 46 #include "shell.h" … … 332 331 size_t nbytes = (size_t)(end - pstart); 333 332 334 assert((uintptr_t)end >= (uintptr_t)pstart);335 /* assert(end[-1] == '\0'); - not if it's followed by ungrabstrackstr(), sigh. */336 assert(SHELL_ALIGN((uintptr_t)pstart) == (uintptr_t)pstart);337 assert(stackblocksize(psh) - psh->sstrnleft >= nbytes);333 kHlpAssert((uintptr_t)end >= (uintptr_t)pstart); 334 /*kHlpAssert(end[-1] == '\0'); - not if it's followed by ungrabstrackstr(), sigh. */ 335 kHlpAssert(SHELL_ALIGN((uintptr_t)pstart) == (uintptr_t)pstart); 336 kHlpAssert(stackblocksize(psh) - psh->sstrnleft >= nbytes); 338 337 339 338 nbytes = SHELL_ALIGN(nbytes); 340 339 psh->stacknxt += nbytes; 341 340 psh->stacknleft -= (int)nbytes; 342 assert(psh->stacknleft >= 0);341 kHlpAssert(psh->stacknleft >= 0); 343 342 344 343 return pstart; … … 348 347 ungrabstackstr(shinstance *psh, char *s, char *p) 349 348 { 350 assert((size_t)(psh->stacknxt - p) <= SHELL_SIZE);351 assert((uintptr_t)s >= (uintptr_t)&psh->stackp->space[0]);352 assert((uintptr_t)p >= (uintptr_t)s);349 kHlpAssert((size_t)(psh->stacknxt - p) <= SHELL_SIZE); 350 kHlpAssert((uintptr_t)s >= (uintptr_t)&psh->stackp->space[0]); 351 kHlpAssert((uintptr_t)p >= (uintptr_t)s); 353 352 354 353 psh->stacknleft += (int)(psh->stacknxt - s); … … 374 373 while ((top = pst->top) != &pst->first) { 375 374 pst->top = top->prev; 376 assert(pst->top);375 kHlpAssert(pst->top); 377 376 top->prev = NULL; 378 377 sh_free(psh, top); … … 393 392 void pstackpop(shinstance *psh, unsigned target) 394 393 { 395 assert(target <= psh->pstacksize);394 kHlpAssert(target <= psh->pstacksize); 396 395 while (target < psh->pstacksize) { 397 396 unsigned idx = --psh->pstacksize; … … 414 413 if (psh->curpstack == psh->pstack[i]) 415 414 break; 416 assert(i < psh->pstacksize);415 kHlpAssert(i < psh->pstacksize); 417 416 } 418 417 # endif … … 423 422 { 424 423 unsigned refs = sh_atomic_inc(&pst->refs); 425 assert(refs > 1);426 assert(refs < 256 /* bogus, but useful */);424 kHlpAssert(refs > 1); 425 kHlpAssert(refs < 256 /* bogus, but useful */); 427 426 return refs; 428 427 } … … 533 532 size_t blocksize; 534 533 535 assert(pst->avail < nbytes); /* only called when we need more space */536 assert(tocopy <= pst->avail);534 kHlpAssert(pst->avail < nbytes); /* only called when we need more space */ 535 kHlpAssert(tocopy <= pst->avail); 537 536 538 537 /* Double the size used thus far and add some fudge and alignment. Make … … 562 561 char const * const copysrc = pst->nextbyte; 563 562 pstallocnewblock(psh, pst, nbytes); 564 assert(pst->avail >= nbytes);565 assert(pst->avail >= tocopy);563 kHlpAssert(pst->avail >= nbytes); 564 kHlpAssert(pst->avail >= tocopy); 566 565 memcpy(pst->nextbyte, copysrc, tocopy); 567 566 } … … 646 645 size_t const len = end - pst->nextbyte; 647 646 648 assert(pst->avail - pst->strleft == len);647 kHlpAssert(pst->avail - pst->strleft == len); 649 648 TRACE2((psh, "pstmakestrspace: len=%u minbytes=%u (=> %u)\n", len, minbytes, len + minbytes)); 650 649 … … 657 656 size_t const len = end - stackblock(psh); 658 657 659 assert(stackblocksize(psh) - psh->sstrnleft == len);658 kHlpAssert(stackblocksize(psh) - psh->sstrnleft == len); 660 659 TRACE2((psh, "pstmakestrspace: len=%u minbytes=%u (=> %u)\n", len, minbytes, len + minbytes)); 661 660 … … 676 675 pst->strleft++; /* PSTPUTC() already incremented it. */ 677 676 end = pstmakestrspace(psh, 1, end); 678 assert(pst->strleft > 0);677 kHlpAssert(pst->strleft > 0); 679 678 pst->strleft--; 680 679 #else 681 680 psh->sstrnleft++; /* PSTPUTC() already incremented it. */ 682 681 end = pstmakestrspace(psh, 1, end); 683 assert(psh->sstrnleft > 0);682 kHlpAssert(psh->sstrnleft > 0); 684 683 psh->sstrnleft--; 685 684 #endif … … 696 695 size_t nbytes = (size_t)(end - pstart); 697 696 698 assert((uintptr_t)end > (uintptr_t)pstart);699 assert(end[-1] == '\0');700 assert(SHELL_ALIGN((uintptr_t)pstart) == (uintptr_t)pstart);701 assert(pst->avail - pst->strleft >= nbytes);697 kHlpAssert((uintptr_t)end > (uintptr_t)pstart); 698 kHlpAssert(end[-1] == '\0'); 699 kHlpAssert(SHELL_ALIGN((uintptr_t)pstart) == (uintptr_t)pstart); 700 kHlpAssert(pst->avail - pst->strleft >= nbytes); 702 701 703 702 nbytes = SHELL_ALIGN(nbytes); /** @todo don't align strings, align the other allocations. */ … … 712 711 size_t nbytes = (size_t)(end - pstart); 713 712 714 assert((uintptr_t)end > (uintptr_t)pstart);715 assert(end[-1] == '\0');716 assert(SHELL_ALIGN((uintptr_t)pstart) == (uintptr_t)pstart);717 assert(stackblocksize(psh) - psh->sstrnleft >= nbytes);713 kHlpAssert((uintptr_t)end > (uintptr_t)pstart); 714 kHlpAssert(end[-1] == '\0'); 715 kHlpAssert(SHELL_ALIGN((uintptr_t)pstart) == (uintptr_t)pstart); 716 kHlpAssert(stackblocksize(psh) - psh->sstrnleft >= nbytes); 718 717 719 718 nbytes = SHELL_ALIGN(nbytes); /** @todo don't align strings, align the other allocations. */
Note:
See TracChangeset
for help on using the changeset viewer.