Commit c02c4901 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Some fixes for 'super'

parent 3d9217f1
...@@ -3549,10 +3549,8 @@ Box* _callattrEntry(Box* obj, BoxedString* attr, CallattrFlags flags, Box* arg1, ...@@ -3549,10 +3549,8 @@ Box* _callattrEntry(Box* obj, BoxedString* attr, CallattrFlags flags, Box* arg1,
rewrite_args.arg2 = rewriter->getArg(4)->setType(RefType::BORROWED); rewrite_args.arg2 = rewriter->getArg(4)->setType(RefType::BORROWED);
if (npassed_args >= 3) if (npassed_args >= 3)
rewrite_args.arg3 = rewriter->getArg(5)->setType(RefType::BORROWED); rewrite_args.arg3 = rewriter->getArg(5)->setType(RefType::BORROWED);
if (npassed_args >= 4) { if (npassed_args >= 4)
assert(0 && "hmm need to figure out vrefs for this");
rewrite_args.args = rewriter->getArg(6); rewrite_args.args = rewriter->getArg(6);
}
rtn = callattrInternal<S, REWRITABLE>(obj, attr, scope, &rewrite_args, argspec, arg1, arg2, arg3, args, rtn = callattrInternal<S, REWRITABLE>(obj, attr, scope, &rewrite_args, argspec, arg1, arg2, arg3, args,
keyword_names); keyword_names);
...@@ -4893,7 +4891,7 @@ static Box* runtimeCallEntry(Box* obj, ArgPassSpec argspec, Box* arg1, Box* arg2 ...@@ -4893,7 +4891,7 @@ static Box* runtimeCallEntry(Box* obj, ArgPassSpec argspec, Box* arg1, Box* arg2
if (npassed_args >= 3) if (npassed_args >= 3)
rewrite_args.arg3 = rewriter->getArg(4)->setType(RefType::BORROWED); rewrite_args.arg3 = rewriter->getArg(4)->setType(RefType::BORROWED);
if (npassed_args >= 4) if (npassed_args >= 4)
rewrite_args.args = rewriter->getArg(5)->setType(RefType::BORROWED); rewrite_args.args = rewriter->getArg(5);
rtn = runtimeCallInternal<S, REWRITABLE>(obj, &rewrite_args, argspec, arg1, arg2, arg3, args, keyword_names); rtn = runtimeCallInternal<S, REWRITABLE>(obj, &rewrite_args, argspec, arg1, arg2, arg3, args, keyword_names);
if (!rewrite_args.out_success) { if (!rewrite_args.out_success) {
......
...@@ -32,15 +32,32 @@ public: ...@@ -32,15 +32,32 @@ public:
Box* obj; // "the instance invoking super(); make be None" Box* obj; // "the instance invoking super(); make be None"
BoxedClass* obj_type; // "the type of the instance invoking super(); may be None" BoxedClass* obj_type; // "the type of the instance invoking super(); may be None"
BoxedSuper(BoxedClass* type, Box* obj, BoxedClass* obj_type) : type(type), obj(obj), obj_type(obj_type) {} BoxedSuper(BoxedClass* type, Box* obj, BoxedClass* obj_type) : type(type), obj(obj), obj_type(obj_type) {
Py_INCREF(type);
Py_INCREF(obj);
Py_INCREF(obj_type);
}
DEFAULT_CLASS(super_cls); DEFAULT_CLASS(super_cls);
static void dealloc(Box* b) noexcept { static void dealloc(Box* b) noexcept {
Py_FatalError("unimplemented"); BoxedSuper* self = (BoxedSuper*)b;
_PyObject_GC_UNTRACK(self);
Py_XDECREF(self->obj);
Py_XDECREF(self->type);
Py_XDECREF(self->obj_type);
Py_TYPE(self)->tp_free(self);
} }
static int traverse(Box* self, visitproc visit, void *arg) noexcept { static int traverse(Box* self, visitproc visit, void *arg) noexcept {
Py_FatalError("unimplemented"); BoxedSuper* su = (BoxedSuper*)self;
Py_VISIT(su->obj);
Py_VISIT(su->type);
Py_VISIT(su->obj_type);
return 0;
} }
}; };
...@@ -151,7 +168,7 @@ Box* superRepr(Box* _s) { ...@@ -151,7 +168,7 @@ Box* superRepr(Box* _s) {
// Ported from the CPython version: // Ported from the CPython version:
template <ExceptionStyle S> BoxedClass* superCheck(BoxedClass* type, Box* obj) noexcept(S == CAPI) { template <ExceptionStyle S> BORROWED(BoxedClass*) superCheck(BoxedClass* type, Box* obj) noexcept(S == CAPI) {
if (PyType_Check(obj) && isSubclass(static_cast<BoxedClass*>(obj), type)) if (PyType_Check(obj) && isSubclass(static_cast<BoxedClass*>(obj), type))
return static_cast<BoxedClass*>(obj); return static_cast<BoxedClass*>(obj);
...@@ -209,11 +226,11 @@ Box* superInit(Box* _self, Box* _type, Box* obj) { ...@@ -209,11 +226,11 @@ Box* superInit(Box* _self, Box* _type, Box* obj) {
if (obj != NULL) if (obj != NULL)
obj_type = superCheck<CXX>(type, obj); obj_type = superCheck<CXX>(type, obj);
self->type = type; self->type = incref(type);
self->obj = obj; self->obj = incref(obj);
self->obj_type = obj_type; self->obj_type = incref(obj_type);
return None; return incref(None);
} }
void setupSuper() { void setupSuper() {
......
...@@ -1099,7 +1099,9 @@ class BoxedStaticmethod : public Box { ...@@ -1099,7 +1099,9 @@ class BoxedStaticmethod : public Box {
public: public:
Box* sm_callable; Box* sm_callable;
BoxedStaticmethod(Box* callable) : sm_callable(callable) {} BoxedStaticmethod(Box* callable) : sm_callable(callable) {
Py_INCREF(sm_callable);
}
DEFAULT_CLASS_SIMPLE(staticmethod_cls, true); DEFAULT_CLASS_SIMPLE(staticmethod_cls, true);
......
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