[Python-checkins] CVS: python/dist/src/Modules xxmodule.c,2.25,2.26 xxsubtype.c,2.12,2.13
Fred L. Drake
fdrake@users.sourceforge.net
Tue, 12 Mar 2002 13:49:46 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv8771
Modified Files:
xxmodule.c xxsubtype.c
Log Message:
Change the example code to prefer PyModule_Add*() instead of using the
module dictionary directly. Also, be more careful about not re-initializing
globals in the event of re-initialization of a C extension.
Index: xxmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/xxmodule.c,v
retrieving revision 2.25
retrieving revision 2.26
diff -C2 -d -r2.25 -r2.26
*** xxmodule.c 8 Dec 2001 18:02:58 -0000 2.25
--- xxmodule.c 12 Mar 2002 21:49:44 -0000 2.26
***************
*** 232,237 ****
/* Add some symbolic constants to the module */
! d = PyModule_GetDict(m);
! ErrorObject = PyErr_NewException("xx.error", NULL, NULL);
! PyDict_SetItemString(d, "error", ErrorObject);
}
--- 232,241 ----
/* Add some symbolic constants to the module */
! if (ErrorObject == NULL) {
! ErrorObject = PyErr_NewException("xx.error", NULL, NULL);
! if (ErrorObject == NULL)
! return;
! }
! Py_INCREF(ErrorObject);
! PyModule_AddObject(d, "error", ErrorObject);
}
Index: xxsubtype.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/xxsubtype.c,v
retrieving revision 2.12
retrieving revision 2.13
diff -C2 -d -r2.12 -r2.13
*** xxsubtype.c 17 Dec 2001 18:26:19 -0000 2.12
--- xxsubtype.c 12 Mar 2002 21:49:44 -0000 2.13
***************
*** 239,243 ****
initxxsubtype(void)
{
! PyObject *m, *d;
/* Fill in deferred data addresses. This must be done before
--- 239,243 ----
initxxsubtype(void)
{
! PyObject *m;
/* Fill in deferred data addresses. This must be done before
***************
*** 264,279 ****
return;
- d = PyModule_GetDict(m);
- if (d == NULL)
- return;
-
Py_INCREF(&spamlist_type);
! if (PyDict_SetItemString(d, "spamlist",
! (PyObject *) &spamlist_type) < 0)
return;
Py_INCREF(&spamdict_type);
! if (PyDict_SetItemString(d, "spamdict",
! (PyObject *) &spamdict_type) < 0)
return;
}
--- 264,275 ----
return;
Py_INCREF(&spamlist_type);
! if (PyModule_AddObject(m, "spamlist",
! (PyObject *) &spamlist_type) < 0)
return;
Py_INCREF(&spamdict_type);
! if (PyModule_AddObject(m, "spamdict",
! (PyObject *) &spamdict_type) < 0)
return;
}