Commit abbbbf48 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add instance.tp_setattro

parent 5767d26e
......@@ -250,6 +250,8 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
RELEASE_ASSERT(_attr->cls == str_cls, "");
BoxedString* attr = static_cast<BoxedString*>(_attr);
assert(value);
// These are special cases in CPython as well:
if (attr->s[0] == '_' && attr->s[1] == '_') {
if (attr->s == "__dict__")
......@@ -276,6 +278,20 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
return None;
}
static int instance_setattro(Box* cls, Box* attr, Box* value) noexcept {
try {
if (value) {
instanceSetattr(cls, attr, value);
return 0;
} else {
RELEASE_ASSERT(0, "");
}
} catch (ExcInfo e) {
setCAPIException(e);
return -1;
}
}
Box* instanceRepr(Box* _inst) {
RELEASE_ASSERT(_inst->cls == instance_cls, "");
BoxedInstance* inst = static_cast<BoxedInstance*>(_inst);
......@@ -454,5 +470,6 @@ void setupClassobj() {
instance_cls->freeze();
instance_cls->tp_getattro = instance_getattro;
instance_cls->tp_setattro = instance_setattro;
}
}
......@@ -549,14 +549,17 @@ Box* Box::getattr(const std::string& attr, GetattrRewriteArgs* rewrite_args) {
if (rewrite_args)
rewrite_args->obj->addAttrGuard(BOX_CLS_OFFSET, (intptr_t)cls);
// if (attr == "__setattr__" && !rewrite_args)
// printf("");
#if 0
if (attr[0] == '_' && attr[1] == '_') {
std::string per_name_stat_name = "slowpath_box_getattr." + std::string(attr);
int id = Stats::getStatId(per_name_stat_name);
Stats::log(id);
// Only do this logging for potentially-avoidable cases:
if (!rewrite_args && cls != classobj_cls) {
if (attr == "__setattr__")
printf("");
std::string per_name_stat_name = "slowpath_box_getattr." + std::string(attr);
int id = Stats::getStatId(per_name_stat_name);
Stats::log(id);
}
}
#endif
box_getattr_slowpath.log();
......
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