Commit a230632b authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #521 from kmod/sys_excepthook

Fix "sys.excepthook is missing" warnings
parents 06f5410d 4189f25f
......@@ -20,6 +20,7 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "capi/types.h"
#include "codegen/unwinding.h"
#include "core/types.h"
#include "gc/collector.h"
......@@ -381,6 +382,23 @@ extern "C" const char* Py_GetPlatform() noexcept {
#endif
}
static PyObject* sys_excepthook(PyObject* self, PyObject* args) noexcept {
PyObject* exc, *value, *tb;
if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb))
return NULL;
PyErr_Display(exc, value, tb);
Py_INCREF(Py_None);
return Py_None;
}
PyDoc_STRVAR(excepthook_doc, "excepthook(exctype, value, traceback) -> None\n"
"\n"
"Handle an exception by displaying it with a traceback on sys.stderr.\n");
static PyMethodDef sys_methods[] = {
{ "excepthook", sys_excepthook, METH_VARARGS, excepthook_doc },
};
void setupSys() {
sys_modules_dict = new BoxedDict();
gc::registerPermanentRoot(sys_modules_dict);
......@@ -482,6 +500,10 @@ void setupSys() {
sys_flags_cls->tp_mro = BoxedTuple::create({ sys_flags_cls, object_cls });
sys_flags_cls->freeze();
for (auto& md : sys_methods) {
sys_module->giveAttr(md.ml_name, new BoxedCApiFunction(md.ml_flags, sys_module, md.ml_name, md.ml_meth));
}
sys_module->giveAttr("flags", new BoxedSysFlags());
}
......
......@@ -87,7 +87,7 @@ extern BoxedClass* object_cls, *type_cls, *bool_cls, *int_cls, *long_cls, *float
*none_cls, *instancemethod_cls, *list_cls, *slice_cls, *module_cls, *dict_cls, *tuple_cls, *file_cls,
*enumerate_cls, *xrange_cls, *member_descriptor_cls, *method_cls, *closure_cls, *generator_cls, *complex_cls,
*basestring_cls, *property_cls, *staticmethod_cls, *classmethod_cls, *attrwrapper_cls, *pyston_getset_cls,
*capi_getset_cls, *builtin_function_or_method_cls, *set_cls, *frozenset_cls, *code_cls;
*capi_getset_cls, *builtin_function_or_method_cls, *set_cls, *frozenset_cls, *code_cls, *frame_cls;
}
#define unicode_cls (&PyUnicode_Type)
#define memoryview_cls (&PyMemoryView_Type)
......
......@@ -11,3 +11,9 @@ print type(sys.maxsize)
print sys.stdout is sys.__stdout__
print sys.stderr is sys.__stderr__
print sys.stdin is sys.__stdin__
try:
1/0
except ZeroDivisionError:
# Our tester won't check the output of this, but at least we can make sure it exists and runs:
sys.excepthook(*sys.exc_info())
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