Commit f0dd5232 authored by Kevin Modzelewski's avatar Kevin Modzelewski

A bunch of small fixes

parent 605702a7
......@@ -490,7 +490,10 @@ extern "C" int PyObject_GenericSetAttr(PyObject* obj, PyObject* name, PyObject*
PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", Py_TYPE(name)->tp_name);
return -1;
}
} else {
Py_INCREF(name);
}
AUTO_DECREF(name);
BoxedString* str = static_cast<BoxedString*>(name);
incref(str);
......
......@@ -853,14 +853,15 @@ Box* map(Box* f, BoxedTuple* args) {
}
Box* reduce(Box* f, Box* container, Box* initial) {
assert(0 && "check refcounting");
Box* current = initial;
Box* current = xincref(initial);
for (Box* e : container->pyElements()) {
assert(e);
if (current == NULL) {
current = e;
} else {
AUTO_DECREF(current);
AUTO_DECREF(e);
current = runtimeCall(f, ArgPassSpec(2), current, e, NULL, NULL, NULL);
}
}
......@@ -1588,7 +1589,6 @@ static PyObject* builtin_reload(PyObject* self, PyObject* v) noexcept {
}
Box* getreversed(Box* o) {
assert(0 && "check refcounting");
static BoxedString* reversed_str = getStaticString("__reversed__");
// common case:
......
......@@ -1791,8 +1791,15 @@ int BoxedInstance::traverse(Box* o, visitproc visit, void* arg) noexcept {
return 0;
}
int BoxedInstance::clear(Box* self) noexcept {
Py_FatalError("unimplemented");
int BoxedInstance::clear(Box* o) noexcept {
BoxedInstance* self = static_cast<BoxedInstance*>(o);
self->attrs.clearForDealloc();
// I think it is ok to not clear this:
// Py_CLEAR(self->inst_cls);
return 0;
}
void BoxedClassobj::dealloc(Box* b) noexcept {
......@@ -1800,14 +1807,14 @@ void BoxedClassobj::dealloc(Box* b) noexcept {
BoxedClassobj* cl = static_cast<BoxedClassobj*>(b);
Py_DECREF(cl->bases);
Py_DECREF(cl->name);
if (cl->weakreflist)
PyObject_ClearWeakRefs(cl);
cl->clearAttrsForDealloc();
Py_DECREF(cl->bases);
Py_DECREF(cl->name);
cl->cls->tp_free(cl);
}
......@@ -1821,7 +1828,15 @@ int BoxedClassobj::traverse(Box* o, visitproc visit, void* arg) noexcept {
}
int BoxedClassobj::clear(Box* self) noexcept {
Py_FatalError("unimplemented");
BoxedClassobj* cl = static_cast<BoxedClassobj*>(self);
cl->attrs.clearForDealloc();
// I think it is ok to not clear these:
// Py_CLEAR(cl->bases);
// Py_CLEAR(cl->name);
return 0;
}
void setupClassobj() {
......
......@@ -940,7 +940,7 @@ Box* intRPow(BoxedInt* lhs, Box* rhs, Box* mod) {
}
Box* rtn = pow_i64_i64(rhs_int->n, lhs->n, mod);
if (PyLong_Check(rtn))
return longInt(rtn);
return longInt(autoDecref(rtn));
return rtn;
}
......@@ -1304,6 +1304,8 @@ template <ExceptionStyle S> Box* intNew(Box* _cls, Box* val, Box* base) noexcept
if (cls == int_cls)
return n;
Py_DECREF(n);
if (S == CAPI) {
PyErr_SetString(OverflowError, "Python int too large to convert to C long");
return NULL;
......
......@@ -3610,6 +3610,7 @@ extern "C" i64 unboxedLen(Box* obj) {
assert(lobj->cls == int_cls);
i64 rtn = lobj->n;
Py_DECREF(lobj);
if (rewriter.get()) {
assert(0 && "how do we know this will return an int?");
......
......@@ -3054,7 +3054,7 @@ static PyObject* import_copyreg(void) noexcept {
if (!copyreg_str) {
// this is interned in cpython:
copyreg_str = PyString_FromString("copy_reg");
copyreg_str = getStaticString("copy_reg");
if (copyreg_str == NULL)
return NULL;
}
......
# expected: reffail
# This test could really benefit from defined/settable OSR limits
def f(x):
......
# expected: reffail
# can't try large numbers yet due to lack of long
for i in xrange(1, 100):
for j in xrange(1, 100):
......@@ -83,6 +82,8 @@ print int("0b101", 2), int("0b101", 0)
print 1 << 63, 1 << 64, -1 << 63, -1 << 64, 2 << 63
print type(1 << 63), type(1 << 64), type(-1 << 63), type(-1 << 64), type(2 << 63)
# TODO: enable this once intmethods_exceptions is working
'''
for b in range(26):
try:
print int('123', b)
......@@ -92,6 +93,7 @@ for b in range(26):
print int(u'123', b)
except ValueError as e:
print e
'''
class I(int):
......
# expected: reffail
# - throws exceptions out of ICs
# TODO: move this back to intmethods.py once this is working
for b in range(26):
try:
print int('123', b)
except ValueError as e:
print e
try:
print int(u'123', b)
except ValueError as e:
print e
# expected: reffail
import itertools
its = []
......
# expected: reffail
class A(object):
def foo(self):
print "foo"
......
# expected: reffail
o = object()
r = o.__reduce__()
print type(r), len(r)
......
# expected: reffail
# Simple optparse test, taken from the optparse.py docstring:
from optparse import OptionParser
......
# expected: reffail
#
# currently broken:
......
# expected: reffail
import operator
print reduce(operator.add, range(50))
......@@ -23,3 +22,8 @@ try:
print reduce(f, [])
except TypeError, e:
print e
try:
print reduce(lambda x, y: x / y, range(-10, 10))
except Exception as e:
print e
# expected: reffail
print list(reversed("hello"))
print list(reversed(""))
......
# expected: reffail
class MyDescr(object):
def __set__(self, inst, val):
print type(self), type(inst), val
......
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