[Python-checkins] python/dist/src/Python errors.c,2.75,2.76 pythonrun.c,2.177,2.178

mhammond@users.sourceforge.net mhammond@users.sourceforge.net
Tue, 18 Feb 2003 16:33:35 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv2094/Python

Modified Files:
	errors.c pythonrun.c 
Log Message:
Fix bug 683658 - PyErr_Warn may cause import deadlock.


Index: errors.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/errors.c,v
retrieving revision 2.75
retrieving revision 2.76
diff -C2 -d -r2.75 -r2.76
*** errors.c	11 Dec 2002 14:04:59 -0000	2.75
--- errors.c	19 Feb 2003 00:33:32 -0000	2.76
***************
*** 601,604 ****
--- 601,605 ----
  }
  
+ extern PyObject *PyModule_WarningsModule;
  
  /* Function to issue a warning message; may raise an exception. */
***************
*** 606,616 ****
  PyErr_Warn(PyObject *category, char *message)
  {
! 	PyObject *mod, *dict, *func = NULL;
  
! 	mod = PyImport_ImportModule("warnings");
! 	if (mod != NULL) {
! 		dict = PyModule_GetDict(mod);
  		func = PyDict_GetItemString(dict, "warn");
- 		Py_DECREF(mod);
  	}
  	if (func == NULL) {
--- 607,615 ----
  PyErr_Warn(PyObject *category, char *message)
  {
! 	PyObject *dict, *func = NULL;
  
! 	if (PyModule_WarningsModule != NULL) {
! 		dict = PyModule_GetDict(PyModule_WarningsModule);
  		func = PyDict_GetItemString(dict, "warn");
  	}
  	if (func == NULL) {

Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.177
retrieving revision 2.178
diff -C2 -d -r2.177 -r2.178
*** pythonrun.c	13 Feb 2003 22:07:59 -0000	2.177
--- pythonrun.c	19 Feb 2003 00:33:33 -0000	2.178
***************
*** 61,64 ****
--- 61,69 ----
  int _Py_QnewFlag = 0;
  
+ /* Reference to 'warnings' module, to avoid importing it
+    on the fly when the import lock may be held.  See 683658
+ */
+ PyObject *PyModule_WarningsModule = NULL;
+ 
  static int initialized = 0;
  
***************
*** 170,173 ****
--- 175,180 ----
  	_PyImportHooks_Init();
  
+ 	PyModule_WarningsModule = PyImport_ImportModule("warnings");
+ 
  	initsigs(); /* Signal handling stuff, including initintr() */
  
***************
*** 225,228 ****
--- 232,239 ----
  	/* Cleanup Codec registry */
  	_PyCodecRegistry_Fini();
+ 
+ 	/* drop module references we saved */
+ 	Py_XDECREF(PyModule_WarningsModule);
+ 	PyModule_WarningsModule = NULL;
  
  	/* Destroy all modules */