summaryrefslogtreecommitdiffstats
path: root/Python/errors.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 2ae062f..c391d33 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -536,6 +536,7 @@ PyErr_Format(PyObject *exception, const char *format, ...)
}
+
PyObject *
PyErr_NewException(char *name, PyObject *base, PyObject *dict)
{
@@ -565,14 +566,18 @@ PyErr_NewException(char *name, PyObject *base, PyObject *dict)
if (PyDict_SetItemString(dict, "__module__", modulename) != 0)
goto failure;
}
- classname = PyString_FromString(dot+1);
- if (classname == NULL)
- goto failure;
- bases = PyTuple_Pack(1, base);
- if (bases == NULL)
- goto failure;
- result = PyObject_CallFunction((PyObject *) (base->ob_type),
- "OOO", classname, bases, dict);
+ if (PyTuple_Check(base)) {
+ bases = base;
+ /* INCREF as we create a new ref in the else branch */
+ Py_INCREF(bases);
+ } else {
+ bases = PyTuple_Pack(1, base);
+ if (bases == NULL)
+ goto failure;
+ }
+ /* Create a real new-style class. */
+ result = PyObject_CallFunction((PyObject *)&PyType_Type, "sOO",
+ dot+1, bases, dict);
failure:
Py_XDECREF(bases);
Py_XDECREF(mydict);
@@ -593,8 +598,11 @@ PyErr_WriteUnraisable(PyObject *obj)
PyFile_WriteString("Exception ", f);
if (t) {
char* className = PyExceptionClass_Name(t);
- PyObject* moduleName =
- PyObject_GetAttrString(t, "__module__");
+ PyObject* moduleName;
+ char *dot = strrchr(className, '.');
+ if (dot != NULL)
+ className = dot+1;
+ moduleName = PyObject_GetAttrString(t, "__module__");
if (moduleName == NULL)
PyFile_WriteString("<unknown>", f);
@@ -644,15 +652,11 @@ PyErr_Warn(PyObject *category, char *message)
return 0;
}
else {
- PyObject *args, *res;
+ PyObject *res;
if (category == NULL)
category = PyExc_RuntimeWarning;
- args = Py_BuildValue("(sO)", message, category);
- if (args == NULL)
- return -1;
- res = PyEval_CallObject(func, args);
- Py_DECREF(args);
+ res = PyObject_CallFunction(func, "sO", message, category);
if (res == NULL)
return -1;
Py_DECREF(res);
@@ -680,18 +684,14 @@ PyErr_WarnExplicit(PyObject *category, const char *message,
return 0;
}
else {
- PyObject *args, *res;
+ PyObject *res;
if (category == NULL)
category = PyExc_RuntimeWarning;
if (registry == NULL)
registry = Py_None;
- args = Py_BuildValue("(sOsizO)", message, category,
- filename, lineno, module, registry);
- if (args == NULL)
- return -1;
- res = PyEval_CallObject(func, args);
- Py_DECREF(args);
+ res = PyObject_CallFunction(func, "sOsizO", message, category,
+ filename, lineno, module, registry);
if (res == NULL)
return -1;
Py_DECREF(res);
@@ -712,7 +712,8 @@ PyErr_SyntaxLocation(const char *filename, int lineno)
/* add attributes for the line number and filename for the error */
PyErr_Fetch(&exc, &v, &tb);
PyErr_NormalizeException(&exc, &v, &tb);
- /* XXX check that it is, indeed, a syntax error */
+ /* XXX check that it is, indeed, a syntax error. It might not
+ * be, though. */
tmp = PyInt_FromLong(lineno);
if (tmp == NULL)
PyErr_Clear();
@@ -788,7 +789,7 @@ PyErr_ProgramText(const char *filename, int lineno)
break;
/* fgets read *something*; if it didn't get as
far as pLastChar, it must have found a newline
- or hit the end of the file; if pLastChar is \n,
+ or hit the end of the file; if pLastChar is \n,
it obviously found a newline; else we haven't
yet seen a newline, so must continue */
} while (*pLastChar != '\0' && *pLastChar != '\n');