Changeset bf1ee05 for src


Ignore:
Timestamp:
May 17, 2016, 6:34:14 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
21995bc
Parents:
19de7b70
Message:

test with single copy from return

Location:
src/examples/wrapper/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/examples/wrapper/src/main.c

    r19de7b70 rbf1ee05  
    33int main(int argc, char const *argv[])
    44{
    5         wrapper_t p;
     5        wrapper_t p = wrap(6);
    66        return 0;
    77}
  • src/examples/wrapper/src/pointer.h

    r19de7b70 rbf1ee05  
    3838}
    3939
    40 void ?{}(content_t* this)
    41 {
    42         sout | "Constructing content" | endl;
    43         this->count = 0;
    44 }
    45 
    4640void ^?{}(content_t* this)
    4741{
     
    5751};
    5852
    59 wrapper_t wrap(int val)
     53void ?{}(wrapper_t* this)
    6054{
    61         wrapper_t w;
    62         content_t* c = malloc;
    63         c{};
    64         c->value = val;
    65         reset(&w, c);
    66         return w;
     55        sout | "Constructing empty ref pointer" | endl;
     56        this->ptr = NULL;
    6757}
    6858
    69 void ?{}(wrapper_t* this)
     59void ?{}(wrapper_t* this, wrapper_t rhs)
    7060{
    71         this->ptr = new();
     61        sout | "Constructing ref pointer from copy" | endl;
     62        this->ptr = rhs.ptr;
    7263        this->ptr->count++;
    73         sout | "Constructing empty ref pointer" | endl;
    7464}
    7565
    7666void ^?{}(wrapper_t* this)
    7767{
     68        if(this->ptr)
    7869        {
     70                sout | "Destroying ref pointer" | endl;
    7971                this->ptr->count--;
     72                sout | "Reference is " | (int)this->ptr->count | endl;
    8073                if(!this->ptr->count) delete(this->ptr);
    81                 sout | "Destroying ref pointer" | endl;
    82                 sout | "Reference is " | this->ptr->count | endl;
    8374        }
    8475        else
     
    9182{
    9283        this->ptr = c;
     84        this->ptr->count++;
    9385        sout | "Setting ref pointer" | endl;
    9486        sout | "Reference is " | this->ptr->count | endl;
    9587}
     88
     89wrapper_t wrap(int val)
     90{
     91        wrapper_t w;
     92        content_t* c = malloc();
     93        c{};
     94        c->value = val;
     95        set(&w, c);
     96        return w;
     97}
Note: See TracChangeset for help on using the changeset viewer.