Use PyModule_AddObject() instead of accessing the module dict directly.

This commit is contained in:
Fred Drake 2002-02-14 07:11:23 +00:00
parent cca657b8fe
commit 78f6c867ae
2 changed files with 14 additions and 10 deletions

View file

@ -1502,16 +1502,18 @@ static PyMethodDef struct_methods[] = {
DL_EXPORT(void)
initstruct(void)
{
PyObject *m, *d;
PyObject *m;
/* Create the module and add the functions */
m = Py_InitModule4("struct", struct_methods, struct__doc__,
(PyObject*)NULL, PYTHON_API_VERSION);
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
StructError = PyErr_NewException("struct.error", NULL, NULL);
if (StructError == NULL)
return;
PyDict_SetItemString(d, "error", StructError);
if (StructError == NULL) {
StructError = PyErr_NewException("struct.error", NULL, NULL);
if (StructError == NULL)
return;
}
Py_INCREF(StructError);
PyModule_AddObject(d, "error", StructError);
}