Commit fb2009bb authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix some attrwrapper behavior

parent 64a7ab2a
...@@ -724,7 +724,8 @@ void dictMergeFromSeq2(BoxedDict* self, Box* other) { ...@@ -724,7 +724,8 @@ void dictMergeFromSeq2(BoxedDict* self, Box* other) {
int idx = 0; int idx = 0;
// raises if not iterable // raises if not iterable
for (const auto& element : other->pyElements()) { for (Box* element : other->pyElements()) {
AUTO_DECREF(element);
// should this check subclasses? anyway to check if something is iterable... // should this check subclasses? anyway to check if something is iterable...
if (element->cls == list_cls) { if (element->cls == list_cls) {
...@@ -782,7 +783,7 @@ Box* dictUpdate(BoxedDict* self, BoxedTuple* args, BoxedDict* kwargs) { ...@@ -782,7 +783,7 @@ Box* dictUpdate(BoxedDict* self, BoxedTuple* args, BoxedDict* kwargs) {
if (args->size()) { if (args->size()) {
Box* arg = args->elts[0]; Box* arg = args->elts[0];
static BoxedString* keys_str = getStaticString("keys"); static BoxedString* keys_str = getStaticString("keys");
if (autoDecref(getattrInternal<ExceptionStyle::CXX>(arg, keys_str))) { if (autoXDecref(getattrInternal<ExceptionStyle::CXX>(arg, keys_str))) {
dictMerge(self, arg); dictMerge(self, arg);
} else { } else {
dictMergeFromSeq2(self, arg); dictMergeFromSeq2(self, arg);
......
...@@ -2535,17 +2535,17 @@ public: ...@@ -2535,17 +2535,17 @@ public:
static Box* iterkeys(Box* _self) { static Box* iterkeys(Box* _self) {
Box* r = AttrWrapper::keys(_self); Box* r = AttrWrapper::keys(_self);
return getiter(r); return getiter(autoDecref(r));
} }
static Box* itervalues(Box* _self) { static Box* itervalues(Box* _self) {
Box* r = AttrWrapper::values(_self); Box* r = AttrWrapper::values(_self);
return getiter(r); return getiter(autoDecref(r));
} }
static Box* iteritems(Box* _self) { static Box* iteritems(Box* _self) {
Box* r = AttrWrapper::items(_self); Box* r = AttrWrapper::items(_self);
return getiter(r); return getiter(autoDecref(r));
} }
static Box* copy(Box* _self) { static Box* copy(Box* _self) {
...@@ -2648,7 +2648,7 @@ public: ...@@ -2648,7 +2648,7 @@ public:
// Hopefully this does not happen very often. // Hopefully this does not happen very often.
if (!PyDict_Check(_container)) { if (!PyDict_Check(_container)) {
BoxedDict* new_container = new BoxedDict(); BoxedDict* new_container = new BoxedDict();
dictUpdate(new_container, autoDecref(BoxedTuple::create({ _container })), NULL); autoDecref(dictUpdate(new_container, autoDecref(BoxedTuple::create({ _container })), NULL));
_container = new_container; _container = new_container;
} else { } else {
Py_INCREF(_container); Py_INCREF(_container);
...@@ -2727,7 +2727,7 @@ Box* AttrWrapperIter::next(Box* _self) { ...@@ -2727,7 +2727,7 @@ Box* AttrWrapperIter::next(Box* _self) {
assert(self->it != self->hcls->getStrAttrOffsets().end()); assert(self->it != self->hcls->getStrAttrOffsets().end());
Box* r = self->it->first; Box* r = self->it->first;
++self->it; ++self->it;
return r; return incref(r);
} }
Box* AttrWrapperIter::next_capi(Box* _self) noexcept { Box* AttrWrapperIter::next_capi(Box* _self) noexcept {
...@@ -2739,7 +2739,7 @@ Box* AttrWrapperIter::next_capi(Box* _self) noexcept { ...@@ -2739,7 +2739,7 @@ Box* AttrWrapperIter::next_capi(Box* _self) noexcept {
return NULL; return NULL;
Box* r = self->it->first; Box* r = self->it->first;
++self->it; ++self->it;
return r; return incref(r);
} }
void Box::giveAttrDescriptor(const char* attr, Box* (*get)(Box*, void*), void (*set)(Box*, Box*, void*)) { void Box::giveAttrDescriptor(const char* attr, Box* (*get)(Box*, void*), void (*set)(Box*, Box*, void*)) {
...@@ -3992,19 +3992,9 @@ int HCAttrs::traverse(visitproc visit, void* arg) noexcept { ...@@ -3992,19 +3992,9 @@ int HCAttrs::traverse(visitproc visit, void* arg) noexcept {
void AttrWrapperIter::dealloc(Box* _o) noexcept { void AttrWrapperIter::dealloc(Box* _o) noexcept {
AttrWrapperIter* o = (AttrWrapperIter*)_o; AttrWrapperIter* o = (AttrWrapperIter*)_o;
Py_FatalError("unimplemented?");
o->cls->tp_free(o); o->cls->tp_free(o);
} }
int AttrWrapperIter::traverse(Box* _o, visitproc visit, void* arg) noexcept {
AttrWrapperIter* o = (AttrWrapperIter*)_o;
Py_FatalError("unimplemented?");
return 0;
}
void BoxedClosure::dealloc(Box* _o) noexcept { void BoxedClosure::dealloc(Box* _o) noexcept {
BoxedClosure* o = (BoxedClosure*)_o; BoxedClosure* o = (BoxedClosure*)_o;
...@@ -4361,9 +4351,8 @@ void setupRuntime() { ...@@ -4361,9 +4351,8 @@ void setupRuntime() {
classmethod_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedClassmethod), false, "classmethod", classmethod_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedClassmethod), false, "classmethod",
true, BoxedClassmethod::dealloc, NULL, true, BoxedClassmethod::traverse, true, BoxedClassmethod::dealloc, NULL, true, BoxedClassmethod::traverse,
BoxedClassmethod::clear); BoxedClassmethod::clear);
attrwrapperiter_cls attrwrapperiter_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(AttrWrapperIter), false,
= BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(AttrWrapperIter), false, "attrwrapperiter", true, "attrwrapperiter", true, AttrWrapperIter::dealloc, NULL, false);
AttrWrapperIter::dealloc, NULL, true, AttrWrapperIter::traverse, NOCLEAR);
pyston_getset_cls->giveAttr("__get__", pyston_getset_cls->giveAttr("__get__",
new BoxedFunction(FunctionMetadata::create((void*)getsetGet, UNKNOWN, 3), { None })); new BoxedFunction(FunctionMetadata::create((void*)getsetGet, UNKNOWN, 3), { None }));
......
def f():
pass
f.a = 1
f.b = 2
i = iter(f.__dict__)
del f
print list(i)
# expected: reffail
import sys import sys
......
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