Commit dde3f8ac authored by Kevin Modzelewski's avatar Kevin Modzelewski

More ref fixes

parent c02c4901
......@@ -475,6 +475,7 @@ extern "C" PyObject* PyObject_Str(PyObject* v) noexcept {
}
extern "C" PyObject* PyObject_SelfIter(PyObject* obj) noexcept {
Py_INCREF(obj);
return obj;
}
......
......@@ -505,6 +505,7 @@ public:
llvm::Value* ptr = emitter.getBuilder()->CreateConstGEP1_32(unpacked, i);
llvm::Value* val = emitter.getBuilder()->CreateLoad(ptr);
assert(val->getType() == g.llvm_value_type_ptr);
emitter.setType(val, RefType::OWNED);
rtn.push_back(new ConcreteCompilerVariable(UNKNOWN, val));
}
......
......@@ -601,6 +601,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
// TODO might be more efficient to do post-call safepoints?
generator->doSafePoint(block->body[0]);
} else if (entry_descriptor && block == entry_descriptor->backedge->target) {
assert(0 && "check refcounting");
assert(block->predecessors.size() > 1);
assert(osr_entry_block);
assert(phis);
......@@ -618,8 +619,13 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
// printf("For %s, given %s, analyzed for %s\n", p.first.c_str(), p.second->debugName().c_str(),
// analyzed_type->debugName().c_str());
assert(0 && "check refcounting");
llvm::PHINode* phi = emitter->getBuilder()->CreatePHI(analyzed_type->llvmType(),
block->predecessors.size() + 1, p.first.s());
if (analyzed_type->getBoxType() == analyzed_type) {
assert(0 && "check refcounting");
irstate->getRefcounts()->setType(phi, RefType::OWNED);
}
ConcreteCompilerVariable* var = new ConcreteCompilerVariable(analyzed_type, phi);
generator->giveLocalSymbol(p.first, var);
(*phis)[p.first] = std::make_pair(analyzed_type, phi);
......@@ -657,7 +663,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
ConcreteCompilerType* type = getTypeAtBlockStart(types, s, block);
llvm::PHINode* phi
= emitter->getBuilder()->CreatePHI(type->llvmType(), block->predecessors.size(), s.s());
if (phi->getType() == g.llvm_value_type_ptr)
if (type->getBoxType() == type)
irstate->getRefcounts()->setType(phi, RefType::OWNED);
ConcreteCompilerVariable* var = new ConcreteCompilerVariable(type, phi);
generator->giveLocalSymbol(s, var);
......@@ -758,7 +764,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
// printf("block %d: adding phi for %s from pred %d\n", block->idx, name.c_str(), pred->idx);
llvm::PHINode* phi = emitter->getBuilder()->CreatePHI(cv->getType()->llvmType(),
block->predecessors.size(), name.s());
if (phi->getType() == g.llvm_value_type_ptr)
if (cv->getType()->getBoxType() == cv->getType())
irstate->getRefcounts()->setType(phi, RefType::OWNED);
// emitter->getBuilder()->CreateCall(g.funcs.dump, phi);
ConcreteCompilerVariable* var = new ConcreteCompilerVariable(cv->getType(), phi);
......@@ -864,8 +870,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
llvm_phi->addIncoming(v->getValue(), llvm_exit_blocks[b->predecessors[j]]);
if (v->getType()->getBoxType() == v->getType()) {
// llvm::outs() << *v->getValue() << " is getting consumed by phi " << *llvm_phi << '\n';
irstate->getRefcounts()->setType(llvm_phi, RefType::OWNED);
//llvm::outs() << *v->getValue() << " is getting consumed by phi " << *llvm_phi << '\n';
assert(llvm::isa<llvm::BranchInst>(terminator));
irstate->getRefcounts()->refConsumed(v->getValue(), terminator);
}
......
......@@ -28,13 +28,13 @@ static Box* memberGet(BoxedMemberDescriptor* self, Box* inst, Box* owner) {
RELEASE_ASSERT(self->cls == member_descriptor_cls, "");
if (inst == None)
return self;
return incref(self);
if (self->type == BoxedMemberDescriptor::OBJECT) {
Box* rtn = *(Box**)(((char*)inst) + self->offset);
if (!rtn)
rtn = None;
return rtn;
return incref(rtn);
}
Py_FatalError("unimplemented");
......@@ -57,8 +57,10 @@ static void propertyDocCopy(BoxedProperty* prop, Box* fget) {
if (get_doc) {
if (prop->cls == property_cls) {
Py_XDECREF(prop->prop_doc);
prop->prop_doc = get_doc;
} else {
AUTO_DECREF(get_doc);
/* If this is a property subclass, put __doc__
in dict of the subclass instance instead,
otherwise it gets shadowed by __doc__ in the
......@@ -75,10 +77,10 @@ static Box* propertyInit(Box* _self, Box* fget, Box* fset, Box** args) {
Box* doc = args[1];
BoxedProperty* self = static_cast<BoxedProperty*>(_self);
self->prop_get = fget == None ? NULL : fget;
self->prop_set = fset == None ? NULL : fset;
self->prop_del = fdel == None ? NULL : fdel;
self->prop_doc = doc;
self->prop_get = fget == None ? NULL : incref(fget);
self->prop_set = fset == None ? NULL : incref(fset);
self->prop_del = fdel == None ? NULL : incref(fdel);
self->prop_doc = xincref(doc);
self->getter_doc = false;
/* if no docstring given and the getter has one, use that one */
......@@ -94,7 +96,7 @@ static Box* propertyGet(Box* self, Box* obj, Box* type) {
BoxedProperty* prop = static_cast<BoxedProperty*>(self);
if (obj == NULL || obj == None) {
return self;
return incref(self);
}
if (prop->prop_get == NULL) {
......@@ -124,7 +126,7 @@ static Box* propertySet(Box* self, Box* obj, Box* val) {
} else {
runtimeCall(func, ArgPassSpec(2), obj, val, NULL, NULL, NULL);
}
return None;
return incref(None);
}
static Box* propertyDel(Box* self, Box* obj) {
......@@ -190,7 +192,7 @@ static Box* staticmethodInit(Box* _self, Box* f) {
BoxedStaticmethod* self = static_cast<BoxedStaticmethod*>(_self);
self->sm_callable = f;
return None;
return incref(None);
}
static Box* staticmethodGet(Box* self, Box* obj, Box* type) {
......@@ -202,7 +204,7 @@ static Box* staticmethodGet(Box* self, Box* obj, Box* type) {
raiseExcHelper(RuntimeError, "uninitialized staticmethod object");
}
return sm->sm_callable;
return incref(sm->sm_callable);
}
extern "C" PyObject* PyClassMethod_New(PyObject* callable) noexcept {
......@@ -212,9 +214,9 @@ extern "C" PyObject* PyClassMethod_New(PyObject* callable) noexcept {
static Box* classmethodInit(Box* _self, Box* f) {
RELEASE_ASSERT(isSubclass(_self->cls, classmethod_cls), "");
BoxedClassmethod* self = static_cast<BoxedClassmethod*>(_self);
self->cm_callable = f;
self->cm_callable = incref(f);
return None;
return incref(None);
}
static Box* classmethodGet(Box* self, Box* obj, Box* type) {
......@@ -390,14 +392,6 @@ Box* BoxedMethodDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args, A
RELEASE_ASSERT(0, "0x%x", call_flags);
}
if (!rtn)
throwCAPIException();
if (rewrite_args) {
rewrite_args->rewriter->checkAndThrowCAPIException(rewrite_args->out_rtn);
rewrite_args->out_success = true;
}
if (paramspec.totalReceived() >= 1)
Py_DECREF(arg1);
if (paramspec.totalReceived() >= 2)
......@@ -407,6 +401,14 @@ Box* BoxedMethodDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args, A
for (int i = 0; i < paramspec.totalReceived() - 3; i++)
Py_DECREF(oargs[i]);
if (!rtn)
throwCAPIException();
if (rewrite_args) {
rewrite_args->rewriter->checkAndThrowCAPIException(rewrite_args->out_rtn);
rewrite_args->out_success = true;
}
return rtn;
}
static Box* methodGetName(Box* b, void*) {
......@@ -414,14 +416,14 @@ static Box* methodGetName(Box* b, void*) {
const char* s = static_cast<BoxedMethodDescriptor*>(b)->method->ml_name;
if (s)
return boxString(s);
return None;
return incref(None);
}
static Box* methodGetDoc(Box* b, void*) {
assert(b->cls == method_cls);
const char* s = static_cast<BoxedMethodDescriptor*>(b)->method->ml_doc;
if (s)
return boxString(s);
return None;
return incref(None);
}
static Box* methodRepr(Box* _o) {
......@@ -445,7 +447,7 @@ Box* BoxedMethodDescriptor::descr_get(BoxedMethodDescriptor* self, Box* inst, Bo
Py_FatalError("unimplemented");
if (inst == NULL)
return self;
return incref(self);
else
return boxInstanceMethod(inst, self, self->type);
}
......@@ -554,7 +556,7 @@ Box* BoxedWrapperDescriptor::descr_get(Box* _self, Box* inst, Box* owner) noexce
BoxedWrapperDescriptor* self = static_cast<BoxedWrapperDescriptor*>(_self);
if (inst == NULL)
return self;
return incref(self);
if (!isSubclass(inst->cls, self->type)) {
PyErr_Format(TypeError, "Descriptor '' for '%s' objects doesn't apply to '%s' object",
......@@ -690,8 +692,8 @@ Box* BoxedWrapperDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args,
break;
}
checkAndThrowCAPIException();
assert(rtn && "should have set + thrown an exception!");
if (!rtn)
throwCAPIException();
return rtn;
}
......@@ -764,8 +766,8 @@ Box* BoxedWrapperObject::__call__(BoxedWrapperObject* self, Box* args, Box* kwds
RELEASE_ASSERT(0, "%d", flags);
}
checkAndThrowCAPIException();
assert(rtn && "should have set + thrown an exception!");
if (!rtn)
throwCAPIException();
return rtn;
}
......
......@@ -96,7 +96,7 @@ Box* dictItems(BoxedDict* self) {
rtn->ensure(self->d.size());
for (const auto& p : *self) {
BoxedTuple* t = BoxedTuple::create({ p.first, p.second });
listAppendInternal(rtn, t);
listAppendInternalStolen(rtn, t);
}
return rtn;
......
......@@ -32,6 +32,7 @@ extern "C" Box* createTuple(int64_t nelts, Box** elts) {
}
Box* _tupleSlice(BoxedTuple* self, i64 start, i64 stop, i64 step, i64 length) {
assert(0 && "check refcounting");
i64 size = self->size();
assert(step != 0);
......@@ -114,6 +115,7 @@ extern "C" int _PyTuple_Resize(PyObject** pv, Py_ssize_t newsize) noexcept {
}
int BoxedTuple::Resize(BoxedTuple** pv, size_t newsize) noexcept {
assert(0 && "check refcounting");
assert((*pv)->cls == tuple_cls);
BoxedTuple* t = static_cast<BoxedTuple*>(*pv);
......@@ -162,6 +164,7 @@ Box* tupleAdd(BoxedTuple* self, Box* rhs) {
if (!PyTuple_Check(rhs)) {
return incref(NotImplemented);
}
assert(0 && "check refcounting");
BoxedTuple* _rhs = static_cast<BoxedTuple*>(rhs);
......@@ -172,6 +175,7 @@ Box* tupleAdd(BoxedTuple* self, Box* rhs) {
}
Box* tupleMulInt(BoxedTuple* self, int n) {
assert(0 && "check refcounting");
int s = self->size();
if (n < 0)
......@@ -199,7 +203,7 @@ Box* tupleMul(BoxedTuple* self, Box* rhs) {
throwCAPIException();
return tupleMulInt(self, n);
} else {
return NotImplemented;
return incref(NotImplemented);
}
}
......@@ -386,6 +390,7 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
}
extern "C" int PyTuple_SetItem(PyObject* op, Py_ssize_t i, PyObject* newitem) noexcept {
assert(0 && "check refcounting");
RELEASE_ASSERT(PyTuple_Check(op), "");
BoxedTuple* t = static_cast<BoxedTuple*>(op);
......@@ -398,6 +403,7 @@ extern "C" int PyTuple_SetItem(PyObject* op, Py_ssize_t i, PyObject* newitem) no
}
extern "C" PyObject* PyTuple_Pack(Py_ssize_t n, ...) noexcept {
assert(0 && "check refcounting");
va_list vargs;
va_start(vargs, n);
......
# import functools
# partial = functools.partial
def partial(func, *args):
def inner(*a, **kw):
return func(*(args + a), **kw)
return inner
def g():
f = partial(lambda *args: args, 1, 23)
print f("hello")
g()
f = partial(lambda *args: args, 1, 23)
print f("hello")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment