• Kevin Modzelewski's avatar
    Add RewriterVar::replaceAttr() · 27b94e48
    Kevin Modzelewski authored
    Previously, to replace a refcounted object in memory, we would do something like
    
    array->getAttr(offset)->setType(OWNED);
    array->setAttr(offset, new_val);
    
    The problem is that this ends up emitting something like
    x = array[offset];
    Py_DECREF(x);
    array[offset] = new_val;
    
    which is not safe, since x can have a destructor that runs.
    In this particular case, the destructor changed the value of array[offset].
    
    It's actually pretty hard to get the right behavior (decref after setting the
    new value) from outside the rewriter class, so add a new replaceAttr that does
    these steps.
    27b94e48
rewriter.cpp 80.1 KB