summaryrefslogtreecommitdiffstats
path: root/Python/errors.c
diff options
context:
space:
mode:
authorRichard Jones <richard@commonground.com.au>2006-05-27 12:29:24 (GMT)
committerRichard Jones <richard@commonground.com.au>2006-05-27 12:29:24 (GMT)
commit7b9558d37dc7f2c6ae984cf25d16b9bf5e532b77 (patch)
tree70f313905c1ef84f4ba281cab615c32e06820460 /Python/errors.c
parent1fcdc232dbfbd05b92eaed42bf9f779d27c55a92 (diff)
downloadcpython-7b9558d37dc7f2c6ae984cf25d16b9bf5e532b77.zip
cpython-7b9558d37dc7f2c6ae984cf25d16b9bf5e532b77.tar.gz
cpython-7b9558d37dc7f2c6ae984cf25d16b9bf5e532b77.tar.bz2
Conversion of exceptions over from faked-up classes to new-style C types.
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/Python/errors.c b/Python/errors.c
index e0ce833..f7a1c08 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -557,9 +557,6 @@ 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;
if (PyTuple_Check(base)) {
bases = base;
/* INCREF as we create a new ref in the else branch */
@@ -569,7 +566,9 @@ PyErr_NewException(char *name, PyObject *base, PyObject *dict)
if (bases == NULL)
goto failure;
}
- result = PyClass_New(bases, dict, classname);
+ /* Create a real new-style class. */
+ result = PyObject_CallFunction((PyObject *)&PyType_Type, "sOO",
+ dot+1, bases, dict);
failure:
Py_XDECREF(bases);
Py_XDECREF(mydict);
@@ -590,8 +589,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);
@@ -641,15 +643,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);
@@ -677,18 +675,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);
@@ -709,7 +703,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();