summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-10-03 19:50:55 (GMT)
committerGuido van Rossum <guido@python.org>1997-10-03 19:50:55 (GMT)
commit2ac650f3859738c58fc9ac8cbf3dc8b574f37ea8 (patch)
tree0a1c41b3500984ca12e6562c0f885bce72ba59fc
parent999e5e921e0da9251d235de6fc7916d349e2bfe4 (diff)
downloadcpython-2ac650f3859738c58fc9ac8cbf3dc8b574f37ea8.zip
cpython-2ac650f3859738c58fc9ac8cbf3dc8b574f37ea8.tar.gz
cpython-2ac650f3859738c58fc9ac8cbf3dc8b574f37ea8.tar.bz2
New version of PyErr_NewException() that is compatible with -X option.
-rw-r--r--Python/errors.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 7b8c03f..2a45f03 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -330,30 +330,51 @@ PyErr_Format(exception, format, va_alist)
PyObject *
PyErr_NewException(name, base, dict)
- char *name;
+ char *name; /* modulename.classname */
PyObject *base;
PyObject *dict;
{
- PyObject *nname = PyString_InternFromString(name);
- PyObject *ndict = NULL;
- PyObject *nbases = NULL;
+ char *dot;
+ PyObject *modulename = NULL;
+ PyObject *classname = NULL;
+ PyObject *mydict = NULL;
+ PyObject *bases = NULL;
PyObject *result = NULL;
- if (nname == NULL)
+ dot = strrchr(name, '.');
+ if (dot == NULL) {
+ PyErr_SetString(PyExc_SystemError,
+ "PyErr_NewException: name must be module.class");
return NULL;
+ }
+ if (base == NULL)
+ base = PyExc_Exception;
+ if (!PyClass_Check(base)) {
+ /* Must be using string-based standard exceptions (-X) */
+ return PyString_FromString(name);
+ }
if (dict == NULL) {
- dict = ndict = PyDict_New();
+ dict = mydict = PyDict_New();
if (dict == NULL)
goto failure;
}
- if (base == NULL)
- base = PyExc_Exception;
- nbases = Py_BuildValue("(O)", base);
- if (nbases == NULL)
+ if (PyDict_GetItemString(dict, "__module__") == NULL) {
+ modulename = PyString_FromStringAndSize(name, (int)(dot-name));
+ if (modulename == NULL)
+ goto failure;
+ if (PyDict_SetItemString(dict, "__module__", modulename) != 0)
+ goto failure;
+ }
+ classname = PyString_FromString(dot+1);
+ if (classname == NULL)
+ goto failure;
+ bases = Py_BuildValue("(O)", base);
+ if (bases == NULL)
goto failure;
- result = PyClass_New(nbases, dict, nname);
+ result = PyClass_New(bases, dict, classname);
failure:
- Py_XDECREF(nbases);
- Py_XDECREF(ndict);
- Py_XDECREF(nname);
+ Py_XDECREF(bases);
+ Py_XDECREF(mydict);
+ Py_XDECREF(classname);
+ Py_XDECREF(modulename);
return result;
}