diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-01-01 10:43:33 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-01-01 10:43:33 +0000 |
commit | 25f1b45d3acbb0e47b95c1c3239000f7b6c8084f (patch) | |
tree | e8b9f3b5bbfcf5a34913c1eb76bdc3a5b3e2b654 | |
parent | 3313204a24a621bb6bb5c0099d8b5e150640cb95 (diff) | |
download | python-numpy-25f1b45d3acbb0e47b95c1c3239000f7b6c8084f.tar.gz python-numpy-25f1b45d3acbb0e47b95c1c3239000f7b6c8084f.tar.bz2 python-numpy-25f1b45d3acbb0e47b95c1c3239000f7b6c8084f.zip |
Added capability to add docstrings to new types and builtin functions or methods after compilation. Doc strings can be moved from C-code into a separate Python module and added as needed.
-rw-r--r-- | scipy/base/src/_compiled_base.c | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/scipy/base/src/_compiled_base.c b/scipy/base/src/_compiled_base.c index cd6740e86..73637203f 100644 --- a/scipy/base/src/_compiled_base.c +++ b/scipy/base/src/_compiled_base.c @@ -47,7 +47,6 @@ monotonic_ (double * a, int lena) } -static char arr_bincount__doc__[] = ""; static intp mxx (intp *i , intp len) @@ -141,7 +140,6 @@ arr_bincount(PyObject *self, PyObject *args, PyObject *kwds) return NULL; } -static char arr_digitize__doc__[] = ""; static PyObject * arr_digitize(PyObject *self, PyObject *args, PyObject *kwds) @@ -337,14 +335,58 @@ arr_insert(PyObject *self, PyObject *args, PyObject *kwdict) return NULL; } +/* Can only be called if doc is currently NULL +*/ +static PyObject * +arr_add_docstring(PyObject *dummy, PyObject *args) +{ + PyObject *obj; + PyObject *str; + + if (!PyArg_ParseTuple(args, "OO!", &obj, &PyString_Type, &str)) + return NULL; + + if (obj->ob_type == &PyCFunction_Type) { + if (!((PyCFunctionObject *)obj)->m_ml->ml_doc) { + ((PyCFunctionObject *)obj)->m_ml->ml_doc = \ + PyString_AS_STRING(str); + Py_INCREF(str); + } + else { + PyErr_Format(PyExc_RuntimeError, \ + "%s method already has a docstring", + ((PyCFunctionObject *)obj) \ + ->m_ml->ml_name); + return NULL; + } + } + else if (obj->ob_type == &PyType_Type) { + if (!((PyTypeObject *)obj)->tp_doc) { + ((PyTypeObject *)obj)->tp_doc = \ + PyString_AS_STRING(str); + Py_INCREF(str); + } + else { + PyErr_Format(PyExc_RuntimeError, \ + "%s type already has a docstring", + ((PyTypeObject *)obj)->tp_name); + return NULL; + } + } + + Py_INCREF(Py_None); + return Py_None; +} static struct PyMethodDef methods[] = { {"_insert", (PyCFunction)arr_insert, METH_VARARGS | METH_KEYWORDS, arr_insert__doc__}, {"bincount", (PyCFunction)arr_bincount, - METH_VARARGS | METH_KEYWORDS, arr_bincount__doc__}, + METH_VARARGS | METH_KEYWORDS, NULL}, {"digitize", (PyCFunction)arr_digitize, METH_VARARGS | METH_KEYWORDS, - arr_digitize__doc__}, + NULL}, + {"add_docstring", (PyCFunction)arr_add_docstring, METH_VARARGS, + NULL}, {NULL, NULL} /* sentinel */ }; |