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