[pypy-svn] r78848 - in pypy/branch/fast-forward/pypy/module/cpyext: . include src
afa at codespeak.net
afa at codespeak.net
Sun Nov 7 23:26:40 CET 2010
Author: afa
Date: Sun Nov 7 23:26:38 2010
New Revision: 78848
Modified:
pypy/branch/fast-forward/pypy/module/cpyext/api.py
pypy/branch/fast-forward/pypy/module/cpyext/include/pyerrors.h
pypy/branch/fast-forward/pypy/module/cpyext/src/pyerrors.c
Log:
PyErr_NewExceptionWithDoc, copied from CPython.
Modified: pypy/branch/fast-forward/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/cpyext/api.py (original)
+++ pypy/branch/fast-forward/pypy/module/cpyext/api.py Sun Nov 7 23:26:38 2010
@@ -308,7 +308,7 @@
'PyModule_AddObject', 'PyModule_AddIntConstant', 'PyModule_AddStringConstant',
'Py_BuildValue', 'Py_VaBuildValue', 'PyTuple_Pack',
- 'PyErr_Format', 'PyErr_NewException',
+ 'PyErr_Format', 'PyErr_NewException', 'PyErr_NewExceptionWithDoc',
'PyEval_CallFunction', 'PyEval_CallMethod', 'PyObject_CallFunction',
'PyObject_CallMethod', 'PyObject_CallFunctionObjArgs', 'PyObject_CallMethodObjArgs',
Modified: pypy/branch/fast-forward/pypy/module/cpyext/include/pyerrors.h
==============================================================================
--- pypy/branch/fast-forward/pypy/module/cpyext/include/pyerrors.h (original)
+++ pypy/branch/fast-forward/pypy/module/cpyext/include/pyerrors.h Sun Nov 7 23:26:38 2010
@@ -12,6 +12,7 @@
PyObject_IsSubclass((x), PyExc_BaseException)))
PyObject *PyErr_NewException(char *name, PyObject *base, PyObject *dict);
+PyObject *PyErr_NewExceptionWithDoc(char *name, char *doc, PyObject *base, PyObject *dict);
PyObject *PyErr_Format(PyObject *exception, const char *format, ...);
#ifdef __cplusplus
Modified: pypy/branch/fast-forward/pypy/module/cpyext/src/pyerrors.c
==============================================================================
--- pypy/branch/fast-forward/pypy/module/cpyext/src/pyerrors.c (original)
+++ pypy/branch/fast-forward/pypy/module/cpyext/src/pyerrors.c Sun Nov 7 23:26:38 2010
@@ -69,3 +69,37 @@
Py_XDECREF(modulename);
return result;
}
+
+/* Create an exception with docstring */
+PyObject *
+PyErr_NewExceptionWithDoc(char *name, char *doc, PyObject *base, PyObject *dict)
+{
+ int result;
+ PyObject *ret = NULL;
+ PyObject *mydict = NULL; /* points to the dict only if we create it */
+ PyObject *docobj;
+
+ if (dict == NULL) {
+ dict = mydict = PyDict_New();
+ if (dict == NULL) {
+ return NULL;
+ }
+ }
+
+ if (doc != NULL) {
+ docobj = PyString_FromString(doc);
+ if (docobj == NULL)
+ goto failure;
+ result = PyDict_SetItemString(dict, "__doc__", docobj);
+ Py_DECREF(docobj);
+ if (result < 0)
+ goto failure;
+ }
+
+ ret = PyErr_NewException(name, base, dict);
+ failure:
+ Py_XDECREF(mydict);
+ return ret;
+}
+
+
More information about the Pypy-commit
mailing list