Changeset 31

Show
Ignore:
Timestamp:
02/08/06 01:35:49 (3 years ago)
Author:
krobillard
Message:

Overflow of the quick hold stack is now caught.

Location:
trunk/orca
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/orca/TODO

    r25 r31  
    2525Thune Backport 
    2626 
    27   * Words are stored in single string. 
    2827  * UCell union 
    2928  * Value structure hidden more using macros (ur_int(), etc.) 
  • trunk/orca/console.c

    r27 r31  
    8989    else 
    9090    { 
    91         printf( "ORCA-Core %s (%s)\n", VERSION_STR, __DATE__ ); 
     91        printf( "ORCA %s (%s)\n", VERSION_STR, __DATE__ ); 
    9292halt: 
    9393        while( 1 ) 
  • trunk/orca/context.c

    r26 r31  
    245245{ 
    246246    ctx->wblkN = orBlockN( orMakeBlock( size ) ); 
     247 
     248    // Assuming caller checks orRefAvail. 
    247249    orRefPush( OT_BLOCK, ctx->wblkN ); 
    248250    ctx->vblkN = orBlockN( orMakeBlock( size ) ); 
     
    293295    int wcount; 
    294296 
     297 
     298    if( ! orRefAvail( 4 ) ) 
     299        return 0; 
    295300 
    296301    wcount = 0; 
     
    424429 
    425430 
     431    if( ! orRefAvail( 3 ) ) 
     432        return -1; 
     433 
    426434    orRefPush( OT_BLOCK, blkN ); 
    427435 
     
    740748 
    741749 
     750    orRefAvailErr( 2 ) 
    742751    orRefPush( OT_BLOCK, a2->index ); 
    743752 
     
    810819    // Still, 'foreach is faster than 'forall (probably because using paths 
    811820    // is so slow). 
     821 
     822    orRefAvailErr( 4 ) 
    812823 
    813824    // Must hold body & a2 in case orMakeContext() or orCopyBlock() trigger 
     
    10361047    OIndex bi   = (a1 + 2)->series.it; 
    10371048    OValue saveA1; 
     1049 
     1050 
     1051    orRefAvailErr( 2 ) 
    10381052 
    10391053    if( a1->type == OT_BLOCK ) 
  • trunk/orca/gc.c

    r26 r31  
    530530    checkCallStack(); 
    531531 
    532     checkHolds( orEnv->quickHolds, orEnv->quickHoldsTop ); 
     532    checkHolds( orEnv->quickHolds, 
     533                orEnv->quickHolds + orEnv->quickHoldsUsed ); 
    533534 
    534535    if( orEnv->holds.used ) 
  • trunk/orca/ovalue.c

    r27 r31  
    304304    env->secure    = 0; 
    305305 
    306     // TODO: Do something about quickHolds stack overflow. Just use orHold()? 
    307     env->quickHolds    = memAlloc( sizeof(OHold) * 256 ); 
    308     env->quickHoldsTop = env->quickHolds; 
     306    env->quickHolds     = memAlloc( sizeof(OHold) * OR_MAX_QHOLDS ); 
     307    env->quickHoldsUsed = 0; 
    309308 
    310309    // NOTE: The data & call stacks are never resized so that it is safe 
     
    535534    env->callStack.used = 0; 
    536535    env->dataStack.used = 0; 
    537     env->quickHoldsTop = env->quickHolds; 
     536    env->quickHoldsUsed = 0; 
    538537    env->error = 0;      //orErrorClear; 
    539538} 
     
    13401339        OValue fileVal = *a1; 
    13411340 
     1341        orRefAvailErr( 2 ); 
    13421342        orRefPush( OT_FILE, a1->index ); 
    13431343        // Need to ref args? 
     
    16481648    OIndex bi   = (a1 + 1)->series.it; 
    16491649 
     1650    orRefAvailErr( 2 ) 
    16501651    orRefPush( OT_BLOCK, cond ); 
    16511652    orRefPush( OT_BLOCK, body ); 
     
    28872888        int vi; 
    28882889 
     2890        orRefAvailErr( 3 ) 
    28892891        orRefPush( OT_BLOCK, a1->index ); 
    28902892        rblk = orMakeBlock(0); 
     
    30533055    int reti; 
    30543056 
     3057    /* Check if 2 are free because there is an orRefPush in orEval() 
     3058       and we can save a check there by doing it here. 
     3059       This is the only check which will catch an endlessly recursive does. 
     3060     */ 
     3061    orRefAvailErr( 2 ) 
    30553062    orRefPush( OT_BLOCK, blkN ); 
    30563063 
     
    42394246 
    42404247 
     4248    orRefAvailErr( 4 ) 
    42414249    orRefPush( OT_BLOCK, a1->index ); 
    42424250    orRefPush( OT_BLOCK, a2->index ); 
  • trunk/orca/ovalue.h

    r27 r31  
    118118 
    119119#define OR_INVALID_HOLD -1 
     120#define OR_MAX_QHOLDS   256 
    120121 
    121122 
     
    358359 
    359360    OHold*      quickHolds; 
    360     OHold*      quickHoldsTop; 
     361    int         quickHoldsUsed; 
    361362 
    362363#ifdef OR_CONFIG_NUMBER_ARRAYS 
     
    497498#define orIsNumber(t)   ((t == OT_INTEGER) || (t == OT_DECIMAL)) 
    498499 
     500#define orRefAvail(n) \ 
     501    (((OR_MAX_QHOLDS - 1) - orEnv->quickHoldsUsed) > n) 
     502 
     503#define orRefAvailErr(n) \ 
     504    if( ! orRefAvail(n) ) { \ 
     505        orErrorT(OR_ERROR_INTERNAL, "Hold stack overflow"); \ 
     506        return; } 
     507 
    499508#define orRefPush(type,index) \ 
    500     orEnv->quickHoldsTop->dataType = type; \ 
    501     orEnv->quickHoldsTop->which = index; \ 
    502     ++orEnv->quickHoldsTop 
    503  
    504 #define orRefPop(count)         orEnv->quickHoldsTop -= count 
     509    orEnv->quickHolds[ orEnv->quickHoldsUsed ].dataType = type; \ 
     510    orEnv->quickHolds[ orEnv->quickHoldsUsed ].which = index; \ 
     511    ++orEnv->quickHoldsUsed 
     512 
     513#define orRefPop(count)         orEnv->quickHoldsUsed -= count 
    505514 
    506515#define orWordVal(wv,blk,val) \ 
  • trunk/orca/tokenize.c

    r1 r31  
    279279    int  get_mode = 0; 
    280280    int  state = ST_START; 
     281    OIndex hold; 
    281282    OValue* prev = 0; 
    282283 
     
    287288        return orBLOCKS + blk_stack[0]; 
    288289 
    289     orRefPush( OT_BLOCK, blk_stack[0] ); 
     290    hold = orHold( OT_BLOCK, blk_stack[0] ); 
    290291 
    291292    str_term = '}'; 
     
    10601061    } 
    10611062 
    1062     orRefPop( 1 ); 
     1063    orRelease( hold ); 
    10631064    return BLK_STACK(0); 
    10641065 
    10651066fail: 
    10661067 
    1067     orRefPop( 1 ); 
     1068    orRelease( hold ); 
    10681069    return 0; 
    10691070}