Commit 622e6664 authored by Kevin Modzelewski's avatar Kevin Modzelewski

more stuff

parent 7edfffe7
......@@ -642,14 +642,10 @@ public:
void setDict(BoxedDict* d);
// These functions won't consume any references.
// ie they will incref val
void setattr(BoxedString* attr, Box* val, SetattrRewriteArgs* rewrite_args);
// giveAttr consumes a reference to val and attr
void giveAttr(const char* attr, Box* val) { giveAttr(internStringMortal(attr), val); }
void giveAttr(BoxedString* attr, Box* val) {
assert(!this->hasattr(attr));
this->setattr(attr, val, NULL);
}
void giveAttr(BoxedString* attr, Box* val);
// for debugging mostly:
void clearAttrs();
......
......@@ -486,8 +486,10 @@ BoxedClass::BoxedClass(BoxedClass* base, gcvisit_func gc_visit, int attrs_offset
assert(tp_basicsize >= base->tp_basicsize);
}
if (base && cls && str_cls)
if (base && cls && str_cls) {
Py_INCREF(base);
giveAttr("__base__", base);
}
if (attrs_offset) {
assert(tp_basicsize >= attrs_offset + sizeof(HCAttrs));
......@@ -820,6 +822,13 @@ void Box::appendNewHCAttr(Box* new_attr, SetattrRewriteArgs* rewrite_args) {
attrs->attr_list->attrs[numattrs] = new_attr;
}
void Box::giveAttr(BoxedString* attr, Box* val) {
assert(!this->hasattr(attr));
this->setattr(attr, val, NULL);
Py_DECREF(val);
Py_DECREF(attr);
}
void Box::setattr(BoxedString* attr, Box* val, SetattrRewriteArgs* rewrite_args) {
assert(gc::isValidGCObject(val));
assert(attr->interned_state != SSTATE_NOT_INTERNED);
......
......@@ -373,6 +373,7 @@ BoxedString* internStringImmortal(llvm::StringRef s) {
// CPython returns mortal but in our current implementation they are inmortal
entry->interned_state = SSTATE_INTERNED_IMMORTAL;
}
Py_INCREF(entry);
return entry;
}
......
......@@ -382,11 +382,13 @@ extern "C" BoxedFunctionBase::BoxedFunctionBase(FunctionMetadata* md)
assert(md->source->scoping->areGlobalsFromModule());
Box* globals_for_name = md->source->parent_module;
assert(0 && "check the refcounting here");
static BoxedString* name_str = internStringImmortal("__name__");
this->modname = globals_for_name->getattr(name_str);
this->doc = md->source->getDocString();
} else {
this->modname = PyString_InternFromString("__builtin__");
Py_INCREF(None);
this->doc = None;
}
}
......@@ -424,6 +426,7 @@ extern "C" BoxedFunctionBase::BoxedFunctionBase(FunctionMetadata* md, std::initi
globals_for_name = md->source->parent_module;
}
assert(0 && "check the refcounting here");
static BoxedString* name_str = internStringImmortal("__name__");
if (globals_for_name->cls == module_cls) {
this->modname = globals_for_name->getattr(name_str);
......@@ -435,6 +438,7 @@ extern "C" BoxedFunctionBase::BoxedFunctionBase(FunctionMetadata* md, std::initi
this->doc = md->source->getDocString();
} else {
this->modname = PyString_InternFromString("__builtin__");
Py_INCREF(None);
this->doc = None;
}
}
......@@ -503,6 +507,13 @@ static void functionDtor(Box* b) {
BoxedFunctionBase* self = static_cast<BoxedFunctionBase*>(b);
self->dependent_ics.invalidateAll();
self->dependent_ics.~ICInvalidator();
Py_DECREF(self->doc);
Py_DECREF(self->modname);
Py_XDECREF(self->name);
Py_XDECREF(self->closure);
Py_XDECREF(self->globals);
Py_XDECREF(self->defaults);
}
std::string BoxedModule::name() {
......@@ -3716,10 +3727,15 @@ void setupRuntime() {
gc::enableGC();
// It wasn't safe to add __base__ attributes until object+type+str are set up, so do that now:
Py_INCREF(object_cls);
type_cls->giveAttr("__base__", object_cls);
Py_INCREF(object_cls);
basestring_cls->giveAttr("__base__", object_cls);
Py_INCREF(basestring_cls);
str_cls->giveAttr("__base__", basestring_cls);
Py_INCREF(object_cls);
none_cls->giveAttr("__base__", object_cls);
Py_INCREF(None);
object_cls->giveAttr("__base__", None);
// Not sure why CPython defines sizeof(PyTupleObject) to include one element,
......
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