Ignore:
Timestamp:
Oct 7, 2021, 2:13:46 PM (2 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
804bf677
Parents:
0f781fb8
Message:

String hybrid has working separated sharing contexts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/collections/string-ctx-manage.cfa

    r0f781fb8 r4b3b352  
    11#include <string.hfa>
    22#include <string_sharectx.hfa>
     3#include <string_res.hfa>
    34
    4 // The functionality for these tests isn't written yet.
    5 // But its interface compiles and the cases it drives are detected.
     5void baseline() {
     6    string x = "hi";
    67
    7 void failEagerCopy() {
     8    string y = x; // construct y in same context, no write yet => no copy yet
     9    assert( y.inner->Handle.s == x.inner->Handle.s);
     10    sout | y; // hi
     11
     12    x = "bye";
     13    y = x; // y in same context, no write yet => no copy yet
     14    assert( y.inner->Handle.s == x.inner->Handle.s);
     15    sout | y; // bye
     16}
     17
     18void eagerCopy() {
    819    string x = "hi";
    9     string_sharectx c = { NO_SHARING };
     20    string_sharectx c = { NEW_SHARING };
    1021
    11     // want: implied forced eager copy
    12     // got: assertion failure, "need to implement context crossing"
    13     string y = x;
     22    string y = x; // construct y in different context => eager copy
     23    assert( y.inner->Handle.s != x.inner->Handle.s);
     24    sout | y; // hi
     25
     26    x = "bye";                                                     //.... Bookmark 9/30 shallow:  surprisingly this step failed
     27    y = x; // y was already in different context => eager copy
     28    assert( y.inner->Handle.s != x.inner->Handle.s);
     29    sout | y; // bye
    1430}
    1531
     
    2642
    2743int main() {
     44    baseline();
     45    eagerCopy();
    2846    if (showFail) {
    29         failEagerCopy();
    3047        failSoloAlloc();
    3148    }
Note: See TracChangeset for help on using the changeset viewer.