Commit ea75b225 authored by Michael Droettboom's avatar Michael Droettboom

Refactor pythonexc2js

parent a83e98b7
......@@ -6,6 +6,11 @@
#include "jsproxy.h"
#include "pyproxy.h"
static PyObject* tbmod = NULL;
static int
_python2js_unicode(PyObject* x);
int
pythonexc2js()
{
......@@ -27,16 +32,20 @@ pythonexc2js()
goto exit;
}
PyObject* tbmod = PyImport_ImportModule("traceback");
if (tbmod == NULL) {
tbmod = PyImport_ImportModule("traceback");
if (tbmod == NULL) {
PyObject* repr = PyObject_Repr(value);
if (repr == NULL) {
excval = hiwire_string_ascii((int)"Could not get repr for exception");
} else {
excval = python2js(repr);
excval = _python2js_unicode(repr);
Py_DECREF(repr);
}
} else {
goto exit;
}
}
PyObject* format_exception;
if (traceback == NULL || traceback == Py_None) {
no_traceback = 1;
......@@ -63,29 +72,21 @@ pythonexc2js()
PyErr_Clear();
goto exit;
} else {
PyObject* newline = PyUnicode_FromString("");
PyObject* pystr = PyUnicode_Join(newline, pylines);
PyObject* empty = PyUnicode_FromString("");
PyObject* pystr = PyUnicode_Join(empty, pylines);
printf("Python exception:\n");
printf("%s\n", PyUnicode_AsUTF8(pystr));
excval = python2js(pystr);
excval = _python2js_unicode(pystr);
Py_DECREF(pystr);
Py_DECREF(newline);
Py_DECREF(empty);
Py_DECREF(pylines);
}
Py_DECREF(format_exception);
}
Py_DECREF(tbmod);
}
exit:
Py_XDECREF(type);
Py_XDECREF(value);
Py_XDECREF(traceback);
PyErr_Clear();
hiwire_throw_error(excval);
return HW_ERROR;
}
......
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