From 9e2851566c0dd1d27d29ead8988f4cc3ae295ca1 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Sat, 23 Sep 2000 03:24:27 +0000 Subject: Andrew Kuchling : Add three new convenience functions to the PyModule_*() family: PyModule_AddObject(), PyModule_AddIntConstant(), PyModule_AddStringConstant(). This closes SourceForge patch #101233. --- Include/modsupport.h | 4 ++++ Python/modsupport.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Include/modsupport.h b/Include/modsupport.h index a678257..54c7add 100644 --- a/Include/modsupport.h +++ b/Include/modsupport.h @@ -18,6 +18,10 @@ extern DL_IMPORT(PyObject *) Py_BuildValue(char *, ...); extern DL_IMPORT(int) PyArg_VaParse(PyObject *, char *, va_list); extern DL_IMPORT(PyObject *) Py_VaBuildValue(char *, va_list); +extern DL_IMPORT(int) PyModule_AddObject(PyObject *, char *, PyObject *); +extern DL_IMPORT(int) PyModule_AddIntConstant(PyObject *, char *, long); +extern DL_IMPORT(int) PyModule_AddStringConstant(PyObject *, char *, char *); + #define PYTHON_API_VERSION 1009 #define PYTHON_API_STRING "1009" /* The API version is maintained (independently from the Python version) 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)); +} -- cgit v0.12