mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
New API PyErr_NewException(name, base, dict) to create simple new exceptions.
This commit is contained in:
parent
0474832d9c
commit
7617e05a9b
1 changed files with 31 additions and 0 deletions
|
@ -318,3 +318,34 @@ PyErr_Format(exception, format, va_alist)
|
||||||
PyErr_SetString(exception, buffer);
|
PyErr_SetString(exception, buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
PyErr_NewException(name, base, dict)
|
||||||
|
char *name;
|
||||||
|
PyObject *base;
|
||||||
|
PyObject *dict;
|
||||||
|
{
|
||||||
|
PyObject *nname = PyString_InternFromString(name);
|
||||||
|
PyObject *ndict = NULL;
|
||||||
|
PyObject *nbases = NULL;
|
||||||
|
PyObject *result = NULL;
|
||||||
|
if (nname == NULL)
|
||||||
|
return NULL;
|
||||||
|
if (dict == NULL) {
|
||||||
|
dict = ndict = PyDict_New();
|
||||||
|
if (dict == NULL)
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
if (base == NULL)
|
||||||
|
base = PyExc_Exception;
|
||||||
|
nbases = Py_BuildValue("(O)", base);
|
||||||
|
if (nbases == NULL)
|
||||||
|
goto failure;
|
||||||
|
result = PyClass_New(nbases, dict, nname);
|
||||||
|
failure:
|
||||||
|
Py_XDECREF(nbases);
|
||||||
|
Py_XDECREF(ndict);
|
||||||
|
Py_XDECREF(nname);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue