Ignore:
Timestamp:
Sep 17, 2020, 11:52:16 PM (5 years ago)
Author:
bird
Message:

kash: Use kHlpAssert instead of assert.h (debugger stops on the assertion rather than at exit process code).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/memalloc.c

    r3462 r3477  
    4343#include <stdlib.h>
    4444#include <stddef.h>
    45 #include <assert.h>
    4645
    4746#include "shell.h"
     
    332331        size_t nbytes = (size_t)(end - pstart);
    333332
    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);
    338337
    339338        nbytes = SHELL_ALIGN(nbytes);
    340339        psh->stacknxt += nbytes;
    341340        psh->stacknleft -= (int)nbytes;
    342         assert(psh->stacknleft >= 0);
     341        kHlpAssert(psh->stacknleft >= 0);
    343342
    344343        return pstart;
     
    348347ungrabstackstr(shinstance *psh, char *s, char *p)
    349348{
    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);
    353352
    354353        psh->stacknleft += (int)(psh->stacknxt - s);
     
    374373                        while ((top = pst->top) != &pst->first) {
    375374                                pst->top = top->prev;
    376                                 assert(pst->top);
     375                                kHlpAssert(pst->top);
    377376                                top->prev = NULL;
    378377                                sh_free(psh, top);
     
    393392void pstackpop(shinstance *psh, unsigned target)
    394393{
    395         assert(target <= psh->pstacksize);
     394        kHlpAssert(target <= psh->pstacksize);
    396395        while (target < psh->pstacksize) {
    397396                unsigned idx = --psh->pstacksize;
     
    414413                        if (psh->curpstack == psh->pstack[i])
    415414                                break;
    416                 assert(i < psh->pstacksize);
     415                kHlpAssert(i < psh->pstacksize);
    417416        }
    418417# endif
     
    423422{
    424423        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 */);
    427426        return refs;
    428427}
     
    533532        size_t blocksize;
    534533
    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);
    537536
    538537        /* Double the size used thus far and add some fudge and alignment.  Make
     
    562561                char const * const copysrc = pst->nextbyte;
    563562                pstallocnewblock(psh, pst, nbytes);
    564                 assert(pst->avail >= nbytes);
    565                 assert(pst->avail >= tocopy);
     563                kHlpAssert(pst->avail >= nbytes);
     564                kHlpAssert(pst->avail >= tocopy);
    566565                memcpy(pst->nextbyte, copysrc, tocopy);
    567566        }
     
    646645        size_t const len = end - pst->nextbyte;
    647646
    648         assert(pst->avail - pst->strleft == len);
     647        kHlpAssert(pst->avail - pst->strleft == len);
    649648        TRACE2((psh, "pstmakestrspace: len=%u minbytes=%u (=> %u)\n", len, minbytes, len + minbytes));
    650649
     
    657656        size_t const len = end - stackblock(psh);
    658657
    659         assert(stackblocksize(psh) - psh->sstrnleft == len);
     658        kHlpAssert(stackblocksize(psh) - psh->sstrnleft == len);
    660659        TRACE2((psh, "pstmakestrspace: len=%u minbytes=%u (=> %u)\n", len, minbytes, len + minbytes));
    661660
     
    676675        pst->strleft++;         /* PSTPUTC() already incremented it. */
    677676        end = pstmakestrspace(psh, 1, end);
    678         assert(pst->strleft > 0);
     677        kHlpAssert(pst->strleft > 0);
    679678        pst->strleft--;
    680679#else
    681680        psh->sstrnleft++;       /* PSTPUTC() already incremented it. */
    682681        end = pstmakestrspace(psh, 1, end);
    683         assert(psh->sstrnleft > 0);
     682        kHlpAssert(psh->sstrnleft > 0);
    684683        psh->sstrnleft--;
    685684#endif
     
    696695        size_t nbytes = (size_t)(end - pstart);
    697696
    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);
    702701
    703702        nbytes = SHELL_ALIGN(nbytes); /** @todo don't align strings, align the other allocations. */
     
    712711        size_t nbytes = (size_t)(end - pstart);
    713712
    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);
    718717
    719718        nbytes = SHELL_ALIGN(nbytes); /** @todo don't align strings, align the other allocations. */
Note: See TracChangeset for help on using the changeset viewer.