Commit 4db15e2a authored by Kevin Modzelewski's avatar Kevin Modzelewski

lots more fixes

parent fbff808d
......@@ -1112,7 +1112,7 @@ Value ASTInterpreter::visit_makeFunction(AST_MakeFunction* mkfn) {
for (int i = decorators.size() - 1; i >= 0; i--) {
if (jit)
func.var = jit->emitRuntimeCall(NULL, decorators[i], ArgPassSpec(1), { func }, NULL);
func.o = runtimeCall(decorators[i].o, ArgPassSpec(1), func.o, 0, 0, 0, 0);
func.o = runtimeCall(autoDecref(decorators[i].o), ArgPassSpec(1), autoDecref(func.o), 0, 0, 0, 0);
}
return func;
}
......
......@@ -115,15 +115,15 @@ BoxedString* SourceInfo::getName() {
switch (ast->type) {
case AST_TYPE::ClassDef:
return ast_cast<AST_ClassDef>(ast)->name;
return incref(ast_cast<AST_ClassDef>(ast)->name.getBox());
case AST_TYPE::FunctionDef:
return ast_cast<AST_FunctionDef>(ast)->name;
return incref(ast_cast<AST_FunctionDef>(ast)->name.getBox());
case AST_TYPE::Lambda:
return lambda_name;
return incref(lambda_name);
case AST_TYPE::Module:
case AST_TYPE::Expression:
case AST_TYPE::Suite:
return module_name;
return incref(module_name);
default:
RELEASE_ASSERT(0, "%d", ast->type);
}
......
......@@ -22,6 +22,7 @@
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/StringRef.h"
#include "Python.h"
#include "core/common.h"
......@@ -61,7 +62,7 @@ public:
InternedString() : _str(NULL) {}
#endif
BoxedString* getBox() const {
BORROWED(BoxedString*) getBox() const {
assert(this->_str);
return _str;
}
......
......@@ -70,6 +70,8 @@ private:
public:
BoxedXrangeIterator(BoxedXrange* xrange, bool reversed) : xrange(xrange) {
Py_INCREF(xrange);
int64_t start = xrange->start;
step = xrange->step;
......@@ -132,10 +134,13 @@ public:
}
static void dealloc(Box* b) noexcept {
Py_FatalError("unimplemented");
BoxedXrangeIterator* self = static_cast<BoxedXrangeIterator*>(b);
Py_DECREF(self->xrange);
}
static int traverse(Box* self, visitproc visit, void *arg) noexcept {
Py_FatalError("unimplemented");
static int traverse(Box* s, visitproc visit, void *arg) noexcept {
BoxedXrangeIterator* self = static_cast<BoxedXrangeIterator*>(s);
Py_VISIT(self->xrange);
return 0;
}
};
......@@ -177,6 +182,7 @@ Box* xrange(Box* cls, Box* start, Box* stop, Box** args) {
Box* xrangeIterIter(Box* self) {
assert(self->cls == xrange_iterator_cls);
Py_INCREF(self);
return self;
}
......@@ -237,9 +243,10 @@ Box* xrangeReduce(Box* self) {
return None;
}
BoxedXrange* r = static_cast<BoxedXrange*>(self);
BoxedTuple* range = BoxedTuple::create({ boxInt(r->start), boxInt(r->stop), boxInt(r->step) });
BoxedTuple* range = BoxedTuple::create(
{ autoDecref(boxInt(r->start)), autoDecref(boxInt(r->stop)), autoDecref(boxInt(r->step)) });
return BoxedTuple::create({ r->cls, range });
return BoxedTuple::create({ r->cls, autoDecref(range) });
}
void setupXrange() {
......
......@@ -50,7 +50,12 @@ public:
}
}
Box* getValue() override { return value; }
Box* getValue() override {
Box* r = value;
assert(r);
value = NULL;
return r;
}
bool isSame(const BoxIteratorImpl* _rhs) override {
const BoxIteratorGeneric* rhs = (const BoxIteratorGeneric*)_rhs;
......
......@@ -543,9 +543,11 @@ static inline void listSetitemSliceInt64(BoxedList* self, i64 start, i64 stop, i
int remaining_elts = self->size - stop;
self->ensure(delts);
// XXX should make a copy here in case a destructor gets run
for (int i = start; i < step; i++) {
Py_CLEAR(self->elts->elts[i]);
Box** removed_elts = NULL;
if (stop > start) {
removed_elts = (Box**)PyMem_MALLOC((stop - start) * sizeof(Box*));
RELEASE_ASSERT(removed_elts, "");
memcpy(removed_elts, self->elts->elts + start, (stop - start) * sizeof(Box*));
}
memmove(self->elts->elts + start + v_size, self->elts->elts + stop, remaining_elts * sizeof(Box*));
......@@ -557,6 +559,12 @@ static inline void listSetitemSliceInt64(BoxedList* self, i64 start, i64 stop, i
self->size += delts;
for (int i = 0; i < stop - start; i++) {
Py_DECREF(removed_elts[i]);
}
if (removed_elts)
PyMem_FREE(removed_elts);
Py_XDECREF(v_as_seq);
}
......@@ -1108,7 +1116,8 @@ Box* listInit(BoxedList* self, Box* container) {
assert(PyList_Check(self));
if (container) {
listIAdd(self, container);
Box* r = listIAdd(self, container);
Py_DECREF(r);
}
Py_RETURN_NONE;
......
......@@ -4100,7 +4100,7 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe
Py_XDECREF(arg2);
Py_XDECREF(arg3);
for (int i = 0; i < num_output_args - 3; i++) {
Py_DECREF(oargs[i]);
Py_XDECREF(oargs[i]);
}
return res;
......
......@@ -793,7 +793,7 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
RewriterVar* r_ccls = NULL;
RewriterVar* r_new = NULL;
RewriterVar* r_init = NULL;
Box* init_attr = NULL;
BORROWED(Box*) init_attr = NULL;
if (rewrite_args) {
assert(!argspec.has_starargs);
assert(!argspec.has_kwargs);
......@@ -1154,7 +1154,6 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
Box* initrtn;
// If there's a Python-level __init__ function, try calling it.
if (init_attr && init_attr->cls == function_cls) {
assert(0 && "check refcounting");
if (rewrite_args) {
// We are going to rewrite as a call to cls.init:
assert(which_init == MAKES_CLS);
......@@ -1163,6 +1162,7 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
// Note: this code path includes the descriptor logic
if (rewrite_args) {
assert(0 && "check refcounting");
CallRewriteArgs srewrite_args(rewrite_args->rewriter, r_init, rewrite_args->destination);
srewrite_args.arg1 = r_made;
if (npassed_args >= 2)
......@@ -1197,11 +1197,11 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
if (S == CAPI) {
if (initrtn != None) {
PyErr_Format(TypeError, "__init__() should return None, not '%s'", getTypeName(initrtn));
PyErr_Format(TypeError, "__init__() should return None, not '%s'", getTypeName(autoDecref(initrtn)));
return NULL;
}
} else
assertInitNone(initrtn);
assertInitNone(autoDecref(initrtn));
} else {
// Otherwise, just call tp_init. This will work out well for extension classes, and no worse
// than failing the rewrite for Python non-extension non-functions (when does that happen?).
......
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