Changeset 0ca15b7


Ignore:
Timestamp:
Oct 19, 2021, 9:55:27 PM (3 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
2b30370
Parents:
fe18b46
Message:

String hybrid testing and fixing the overwrite cases

Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/containers/string_res.cfa

    rfe18b46 r0ca15b7  
    405405
    406406    verify( shareEditSetEndPeer->Handle.s >= shareEditSetStartPeer->Handle.s );
    407     size_t editSetLength = shareEditSetEndPeer->Handle.s + shareEditSetEndPeer->Handle.lnth - shareEditSetStartPeer->Handle.s;
    408     verify( editSetLength >= this.Handle.lnth );
     407    size_t origEditSetLength = shareEditSetEndPeer->Handle.s + shareEditSetEndPeer->Handle.lnth - shareEditSetStartPeer->Handle.s;
     408    verify( origEditSetLength >= this.Handle.lnth );
    409409
    410410    if ( this.shareEditSet_owns_ulink ) {                 // assigning to private context
     
    418418        if ( char * oldBytes = VbyteTryAdjustLast( *this.Handle.ulink, delta ) ) {
    419419            // growing: copy from old to new
    420             char * dest = VbyteAlloc( *this.Handle.ulink, editSetLength );
     420            char * dest = VbyteAlloc( *this.Handle.ulink, origEditSetLength + delta );
    421421            char *destCursor = dest;  memcpy(destCursor, prefixStartOrig, prefixLen);
    422422            destCursor += prefixLen;  memcpy(destCursor, buffer         , bsize    );
     
    424424            assignEditSet(this, shareEditSetStartPeer, shareEditSetEndPeer,
    425425                dest,
    426                 editSetLength,
     426                origEditSetLength + delta,
    427427                0p, bsize);
    428428            free( oldBytes );
     
    434434            assignEditSet(this, shareEditSetStartPeer, shareEditSetEndPeer,
    435435                shareEditSetStartPeer->Handle.s,
    436                 editSetLength,
     436                origEditSetLength + delta,
    437437                0p, bsize);
    438438        }
    439439
    440440    } else if (                                           // assigning to shared context
    441         this.Handle.lnth == editSetLength &&              // overwriting entire run of SES
     441        this.Handle.lnth == origEditSetLength &&          // overwriting entire run of SES
    442442        & valSrc &&                                       // sourcing from a managed string
    443443        valSrc.Handle.ulink == this.Handle.ulink  ) {     // sourcing from same heap
  • tests/collections/string-overwrite.cfa

    rfe18b46 r0ca15b7  
    11#include <containers/string.hfa>
     2#include <string_sharectx.hfa>
    23
    34/*
     
    1112WE = witness end
    1213
    13 The dest does:
     14The test does:
    1415  starts with the entire string being, initially, the alphabet; prints this entire alphabet
    1516  sets up modifier and witness as ranges within it, and prints a visualization of those ranges
     
    2425This API's convention has Start positions being inclusive and end positions being exclusive.
    2526
     27                                v Case number in output
    2628With 1 equivalence class:
    2729MS = ME = WS = WE               1
     
    118120    struct { int ms; int me; int ws; int we; char *replaceWith; char *label; } cases[] = {
    119121        { 12, 14, 10, 20, "xxxxx", "warmup" },
    120 //        { 12, 14, 12, 14, "xxxxx", ""       },  // the bug that got me into this test (should be a dup with case 6)
    121122        { 10, 10, 10, 10, "=====", "1"      },
    122123        { 10, 10, 10, 10, "=="   , ""       },
     
    223224        { 12, 14, 10, 16, "="    , ""       },
    224225        { 12, 14, 10, 16, ""     , ""       },
    225 /*
    226         { , , , , "=====", "NN"     },
    227         {  "=="   , ""       },
    228         {  "="    , ""       },
    229         {  ""     , ""       },
    230 */
    231226    };
    232227    for ( i; sizeof(cases)/sizeof(cases[0]) ) {
     
    238233
    239234
    240 // void f( string & s, string & toEdit ) {
    241 
    242 //     sout | s | "|" | toEdit | "|";
    243 
    244 //     s(14, 16) = "-";
    245 //     sout | s | "|" | toEdit | "|";
    246 // }
    247 
    248235int main() {
     236
     237    #ifdef STRING_SHARING_OFF
     238    string_sharectx c = { NO_SHARING };
     239    #endif
     240
     241
    249242    //          0         1         2
    250243    //          01234567890123456789012345
Note: See TracChangeset for help on using the changeset viewer.