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.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user