Commit 0682ccb0 authored by Kevin Modzelewski's avatar Kevin Modzelewski

More fixes

parent 8e87df72
......@@ -429,7 +429,7 @@ extern "C" PyCodeObject* PyAST_Compile(struct _mod* _mod, const char* filename,
return NULL;
}
return (PyCodeObject*)md->getCode();
return (PyCodeObject*)incref(md->getCode());
} catch (ExcInfo e) {
setCAPIException(e);
return NULL;
......
......@@ -534,6 +534,8 @@ void instanceSetattroInternal(Box* _inst, Box* _attr, STOLEN(Box*) value, Setatt
}
}
AUTO_DECREF(value);
static BoxedString* setattr_str = getStaticString("__setattr__");
if (rewrite_args) {
......@@ -572,10 +574,6 @@ void instanceSetattroInternal(Box* _inst, Box* _attr, STOLEN(Box*) value, Setatt
}
}
void instanceSetattr(Box* _inst, Box* _attr, Box* value) {
instanceSetattroInternal(_inst, _attr, value, NULL);
}
Box* instanceDelattr(Box* _inst, Box* _attr) {
RELEASE_ASSERT(_inst->cls == instance_cls, "");
BoxedInstance* inst = static_cast<BoxedInstance*>(_inst);
......@@ -611,10 +609,10 @@ Box* instanceDelattr(Box* _inst, Box* _attr) {
return None;
}
int instance_setattro(Box* cls, Box* attr, Box* value) noexcept {
int instance_setattro(Box* inst, Box* attr, Box* value) noexcept {
try {
if (value) {
instanceSetattr(cls, attr, value);
instanceSetattroInternal(inst, attr, value, NULL);
return 0;
} else {
RELEASE_ASSERT(0, "");
......@@ -1833,8 +1831,6 @@ void setupClassobj() {
instance_cls->giveAttr("__getattribute__", new BoxedFunction(FunctionMetadata::create(
(void*)instanceGetattroInternal<CXX>, UNKNOWN, 2)));
instance_cls->giveAttr("__setattr__",
new BoxedFunction(FunctionMetadata::create((void*)instanceSetattr, UNKNOWN, 3)));
instance_cls->giveAttr("__delattr__",
new BoxedFunction(FunctionMetadata::create((void*)instanceDelattr, UNKNOWN, 2)));
instance_cls->giveAttr("__str__", new BoxedFunction(FunctionMetadata::create((void*)instanceStr, UNKNOWN, 1)));
......
......@@ -91,10 +91,6 @@ Box* BoxedCode::flags(Box* b, void*) {
return boxInt(flags);
}
Box* codeForFunction(BoxedFunction* f) {
return f->md->getCode();
}
FunctionMetadata* metadataFromCode(Box* code) {
assert(code->cls == code_cls);
return static_cast<BoxedCode*>(code)->f;
......
......@@ -2379,9 +2379,10 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew
throwCAPIException();
if (rewrite_args) {
RewriterVar* r_rtn = rewrite_args->rewriter->call(
true, (void*)local_get, r_val, rewrite_args->rewriter->loadConst(0, Location::forArg(1)),
rewrite_args->obj);
RewriterVar* r_rtn
= rewrite_args->rewriter->call(true, (void*)local_get, r_val,
rewrite_args->rewriter->loadConst(0, Location::forArg(1)),
rewrite_args->obj)->setType(RefType::OWNED);
// rewrite_args->rewriter->checkAndThrowCAPIException(rewrite_args->out_rtn);
rewrite_args->setReturn(r_rtn, ReturnConvention::CAPI_RETURN);
}
......
......@@ -1536,7 +1536,7 @@ static void funcSetName(Box* b, Box* v, void*) {
raiseExcHelper(TypeError, "__name__ must be set to a string object");
}
func->name = static_cast<BoxedString*>(v);
func->name = incref(static_cast<BoxedString*>(v));
}
static Box* builtinFunctionOrMethodName(Box* b, void*) {
......@@ -1548,13 +1548,13 @@ static Box* builtinFunctionOrMethodName(Box* b, void*) {
assert(b->cls == builtin_function_or_method_cls);
BoxedBuiltinFunctionOrMethod* func = static_cast<BoxedBuiltinFunctionOrMethod*>(b);
assert(func->name);
return func->name;
return incref(func->name);
}
static Box* functionCode(Box* self, void*) {
assert(self->cls == function_cls);
BoxedFunction* func = static_cast<BoxedFunction*>(self);
return codeForFunction(func);
return incref(func->md->getCode());
}
extern "C" PyObject* PyFunction_GetCode(PyObject* func) noexcept {
......@@ -1689,11 +1689,11 @@ Box* instancemethodGet(BoxedInstanceMethod* self, Box* obj, Box* type) {
RELEASE_ASSERT(self->cls == instancemethod_cls, "");
if (self->obj != NULL) {
return self;
return incref(self);
}
if (!PyObject_IsSubclass(type, self->im_class)) {
return self;
return incref(self);
}
if (obj == None)
......@@ -1731,6 +1731,7 @@ static Box* instancemethodRepr(Box* b) {
static BoxedString* name_str = getStaticString("__name__");
funcname = getattrInternal<CXX>(func, name_str);
AUTO_XDECREF(funcname);
if (funcname != NULL) {
if (!PyString_Check(funcname)) {
......@@ -1751,12 +1752,14 @@ static Box* instancemethodRepr(Box* b) {
}
}
}
AUTO_XDECREF(klassname);
if (self == NULL)
result = PyString_FromFormat("<unbound method %s.%s>", sklassname, sfuncname);
else {
// This was a CPython comment: /* XXX Shouldn't use repr() here! */
Box* selfrepr = repr(self);
AUTO_DECREF(selfrepr);
assert(PyString_Check(selfrepr));
result = PyString_FromFormat("<bound method %s.%s of %s>", sklassname, sfuncname, PyString_AS_STRING(selfrepr));
}
......@@ -3354,7 +3357,7 @@ void dealloc_null(Box* box) {
static Box* getsetGet(Box* self, Box* obj, Box* type) {
// TODO: should call the full descr_check instead
if (obj == NULL || obj == None)
return self;
return incref(self);
BoxedGetsetDescriptor* getset_descr = static_cast<BoxedGetsetDescriptor*>(self);
......@@ -3383,12 +3386,12 @@ static Box* getsetSet(Box* self, Box* obj, Box* val) {
if (isSubclass(self->cls, pyston_getset_cls)) {
getset_descr->set(obj, val, getset_descr->closure);
return None;
return incref(None);
} else {
RELEASE_ASSERT(isSubclass(self->cls, capi_getset_cls), "");
getset_descr->set(obj, val, getset_descr->closure);
checkAndThrowCAPIException();
return None;
return incref(None);
}
}
......
......@@ -1261,8 +1261,6 @@ AST* unboxAst(Box* b);
// are supposed to add one themselves. type_cls and function_cls do this, for example.
extern Box* dict_descr;
Box* codeForFunction(BoxedFunction*);
Box* codeForFunctionMetadata(FunctionMetadata*);
FunctionMetadata* metadataFromCode(Box* code);
Box* getFrame(FrameInfo* frame_info);
......
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