Commit 8d247e34 authored by Kevin Modzelewski's avatar Kevin Modzelewski

A number of random changes from trying to run tester.py

parent 4413b634
...@@ -1028,6 +1028,11 @@ void setupBuiltins() { ...@@ -1028,6 +1028,11 @@ void setupBuiltins() {
PendingDeprecationWarning = makeBuiltinException(Warning, "PendingDeprecationWarning"); PendingDeprecationWarning = makeBuiltinException(Warning, "PendingDeprecationWarning");
EOFError = makeBuiltinException(StandardError, "EOFError"); EOFError = makeBuiltinException(StandardError, "EOFError");
BaseException->giveAttr("__reduce__",
new BoxedFunction(boxRTFunction((void*)BoxedException::__reduce__, UNKNOWN, 1)));
EnvironmentError->giveAttr("__reduce__",
new BoxedFunction(boxRTFunction((void*)BoxedEnvironmentError::__reduce__, UNKNOWN, 1)));
EnvironmentError->gc_visit = BoxedEnvironmentError::gcHandler; EnvironmentError->gc_visit = BoxedEnvironmentError::gcHandler;
EnvironmentError->giveAttr( EnvironmentError->giveAttr(
"__init__", new BoxedFunction(boxRTFunction((void*)BoxedEnvironmentError::__init__, NONE, 4, 3, false, false), "__init__", new BoxedFunction(boxRTFunction((void*)BoxedEnvironmentError::__init__, NONE, 4, 3, false, false),
......
...@@ -619,6 +619,14 @@ Box* fileClose(BoxedFile* self) { ...@@ -619,6 +619,14 @@ Box* fileClose(BoxedFile* self) {
return sts; return sts;
} }
Box* fileFileno(BoxedFile* self) {
assert(self->cls == file_cls);
if (!self->f_fp)
raiseExcHelper(IOError, "file is closed");
return boxInt(fileno(self->f_fp));
}
Box* fileEnter(BoxedFile* self) { Box* fileEnter(BoxedFile* self) {
assert(self->cls == file_cls); assert(self->cls == file_cls);
return self; return self;
...@@ -1067,6 +1075,7 @@ void setupFile() { ...@@ -1067,6 +1075,7 @@ void setupFile() {
file_cls->giveAttr("flush", new BoxedFunction(boxRTFunction((void*)fileFlush, NONE, 1))); file_cls->giveAttr("flush", new BoxedFunction(boxRTFunction((void*)fileFlush, NONE, 1)));
file_cls->giveAttr("write", new BoxedFunction(boxRTFunction((void*)fileWrite, NONE, 2))); file_cls->giveAttr("write", new BoxedFunction(boxRTFunction((void*)fileWrite, NONE, 2)));
file_cls->giveAttr("close", new BoxedFunction(boxRTFunction((void*)fileClose, NONE, 1))); file_cls->giveAttr("close", new BoxedFunction(boxRTFunction((void*)fileClose, NONE, 1)));
file_cls->giveAttr("fileno", new BoxedFunction(boxRTFunction((void*)fileFileno, BOXED_INT, 1)));
file_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)fileRepr, STR, 1))); file_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)fileRepr, STR, 1)));
......
...@@ -109,6 +109,18 @@ static uint64_t asUnsignedLong(BoxedLong* self) { ...@@ -109,6 +109,18 @@ static uint64_t asUnsignedLong(BoxedLong* self) {
} }
extern "C" unsigned long PyLong_AsUnsignedLong(PyObject* vv) noexcept { extern "C" unsigned long PyLong_AsUnsignedLong(PyObject* vv) noexcept {
assert(vv);
if (vv->cls == int_cls) {
long val = PyInt_AsLong(vv);
if (val < 0) {
PyErr_SetString(PyExc_OverflowError, "can't convert negative value "
"to unsigned long");
return (unsigned long)-1;
}
return val;
}
RELEASE_ASSERT(PyLong_Check(vv), ""); RELEASE_ASSERT(PyLong_Check(vv), "");
BoxedLong* l = static_cast<BoxedLong*>(vv); BoxedLong* l = static_cast<BoxedLong*>(vv);
......
...@@ -1710,7 +1710,8 @@ extern "C" bool nonzero(Box* obj) { ...@@ -1710,7 +1710,8 @@ extern "C" bool nonzero(Box* obj) {
if (func == NULL) { if (func == NULL) {
ASSERT(isUserDefined(obj->cls) || obj->cls == classobj_cls || obj->cls == type_cls ASSERT(isUserDefined(obj->cls) || obj->cls == classobj_cls || obj->cls == type_cls
|| isSubclass(obj->cls, Exception) || obj->cls == file_cls || obj->cls == traceback_cls, || isSubclass(obj->cls, Exception) || obj->cls == file_cls || obj->cls == traceback_cls
|| obj->cls == instancemethod_cls,
"%s.__nonzero__", "%s.__nonzero__",
getTypeName(obj)); // TODO getTypeName(obj)); // TODO
// TODO should rewrite these? // TODO should rewrite these?
......
...@@ -233,3 +233,17 @@ def f13(): ...@@ -233,3 +233,17 @@ def f13():
print sys.exc_info()[0] print sys.exc_info()[0]
f13() f13()
def f14():
try:
1/0
except Exception:
a, b, c = sys.exc_info()
for i in xrange(5):
try:
(i)[0]
except Exception:
pass
raise a, b, c
f14()
...@@ -2,3 +2,5 @@ import sys ...@@ -2,3 +2,5 @@ import sys
sys.stdout.write("hello world\n") sys.stdout.write("hello world\n")
print >>sys.stdout, "hello world" print >>sys.stdout, "hello world"
print sys.stdout.fileno()
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