diff options
author | Fred Drake <fdrake@acm.org> | 2000-09-23 03:24:27 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2000-09-23 03:24:27 (GMT) |
commit | 9e2851566c0dd1d27d29ead8988f4cc3ae295ca1 (patch) | |
tree | 0e35fe3b2d9b2ccbc82acdc1b41ea445580c3b66 /Python/modsupport.c | |
parent | f84fb660cbd7f66bacf2e58dbafd950f43f6e216 (diff) | |
download | cpython-9e2851566c0dd1d27d29ead8988f4cc3ae295ca1.zip cpython-9e2851566c0dd1d27d29ead8988f4cc3ae295ca1.tar.gz cpython-9e2851566c0dd1d27d29ead8988f4cc3ae295ca1.tar.bz2 |
Andrew Kuchling <akuchlin@mems-exchange.org>:
Add three new convenience functions to the PyModule_*() family:
PyModule_AddObject(), PyModule_AddIntConstant(), PyModule_AddStringConstant().
This closes SourceForge patch #101233.
Diffstat (limited to 'Python/modsupport.c')
-rw-r--r-- | Python/modsupport.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Python/modsupport.c b/Python/modsupport.c index c87f994..9c2dc18 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -459,3 +459,30 @@ PyEval_CallMethod(PyObject *obj, char *methodname, char *format, ...) return res; } + +int +PyModule_AddObject(PyObject *m, char *name, PyObject *o) +{ + PyObject *dict; + if (!PyModule_Check(m) || o == NULL) + return -1; + dict = PyModule_GetDict(m); + if (dict == NULL) + return -1; + if (PyDict_SetItemString(dict, name, o)) + return -1; + Py_DECREF(o); + return 0; +} + +int +PyModule_AddIntConstant(PyObject *m, char *name, long value) +{ + return PyModule_AddObject(m, name, PyInt_FromLong(value)); +} + +int +PyModule_AddStringConstant(PyObject *m, char *name, char *value) +{ + return PyModule_AddObject(m, name, PyString_FromString(value)); +} |