Commit ef93c2d8 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Get rid of the broken and troublesome exceptionNew methods

exceptionNew just calls __new__, but some exceptions have
important __init__ methods that need to be called.

Well, I think those exceptions might be broken (they should probably
set that data in __init__) but this is still a good anyway.
parent 83f0f43b
......@@ -592,10 +592,6 @@ Box* PyExc_RecursionErrorInst;
Box* PyExc_MemoryErrorInst;
}
Box* exceptionNew1(BoxedClass* cls) {
return exceptionNew(cls, EmptyTuple);
}
class BoxedException : public Box {
public:
HCAttrs attrs;
......@@ -609,10 +605,6 @@ public:
}
};
Box* exceptionNew2(BoxedClass* cls, Box* message) {
return exceptionNew(cls, new BoxedTuple({ message }));
}
Box* exceptionNew(BoxedClass* cls, BoxedTuple* args) {
if (!isSubclass(cls->cls, type_cls))
raiseExcHelper(TypeError, "exceptions.__new__(X): X is not a type object (%s)", getTypeName(cls));
......
......@@ -56,7 +56,7 @@ Box* sysExcClear() {
static Box* sysExit(Box* arg) {
assert(arg);
Box* exc = exceptionNew2(SystemExit, arg);
Box* exc = runtimeCall(SystemExit, ArgPassSpec(1), arg, NULL, NULL, NULL, NULL);
// TODO this should be handled by the SystemExit constructor
exc->giveAttr("code", arg);
......
......@@ -126,7 +126,7 @@ Box* generatorThrow(Box* s, BoxedClass* e) {
assert(s->cls == generator_cls);
assert(isSubclass(e, Exception));
BoxedGenerator* self = static_cast<BoxedGenerator*>(s);
Box* ex = exceptionNew1(e);
Box* ex = runtimeCall(e, ArgPassSpec(0), NULL, NULL, NULL, NULL, NULL);
self->exception = ExcInfo(ex->cls, ex, None);
return generatorSend(self, None);
}
......
......@@ -117,7 +117,7 @@ void raiseExc(Box* exc_obj) {
// Have a special helper function for syntax errors, since we want to include the location
// of the syntax error in the traceback, even though it is not part of the execution:
void raiseSyntaxError(const char* msg, int lineno, int col_offset, const std::string& file, const std::string& func) {
Box* exc = exceptionNew2(SyntaxError, boxStrConstant(msg));
Box* exc = runtimeCall(SyntaxError, ArgPassSpec(1), boxStrConstant(msg), NULL, NULL, NULL, NULL);
auto tb = getTraceback();
// TODO: push the syntax error line back on it:
......@@ -253,10 +253,10 @@ void raiseExcHelper(BoxedClass* cls, const char* msg, ...) {
va_end(ap);
BoxedString* message = boxStrConstant(buf);
Box* exc_obj = exceptionNew2(cls, message);
Box* exc_obj = runtimeCall(cls, ArgPassSpec(1), message, NULL, NULL, NULL, NULL);
raiseExc(exc_obj);
} else {
Box* exc_obj = exceptionNew1(cls);
Box* exc_obj = runtimeCall(cls, ArgPassSpec(0), NULL, NULL, NULL, NULL, NULL);
raiseExc(exc_obj);
}
}
......
......@@ -612,9 +612,6 @@ public:
extern "C" void boxGCHandler(GCVisitor* v, Box* b);
Box* exceptionNew1(BoxedClass* cls);
Box* exceptionNew2(BoxedClass* cls, Box* message);
Box* exceptionNew(BoxedClass* cls, BoxedTuple* args);
Box* objectNewNoArgs(BoxedClass* cls);
extern "C" BoxedClass* Exception, *AssertionError, *AttributeError, *TypeError, *NameError, *KeyError, *IndexError,
......
import gc
import select
for k in sorted(dir(select)):
......@@ -20,3 +21,9 @@ try:
print p.poll(10)
finally:
f.close()
gc.collect()
try:
p.unregister(f)
except Exception:
# We don't generate the write exception here, but we shouldn't abort
pass
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