[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.154,2.155

Barry A. Warsaw python-dev@python.org
Tue, 2 May 2000 15:24:09 -0400 (EDT)


Update of /projects/cvsroot/python/dist/src/Python
In directory anthem:/home/bwarsaw/projects/python/Python

Modified Files:
	bltinmodule.c 
Log Message:
initerrors(): Remove this function.  String-based standard exceptions
are no longer supported (i.e. -X option is removed).

_PyBuiltin_Init_1(): Don't call initerrors().  This does mean that it
is possible to raise an ImportError before that exception has been
initialized, say because exceptions.py can't be found, or contains
bogosity.  See changes to errors.c for how this is handled.

_PyBuiltin_Init_2(): Don't test Py_UseClassExceptionsFlag, just go
ahead and initialize the class-based standard exceptions.  If this
fails, we throw a Py_FatalError.


Index: bltinmodule.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.154
retrieving revision 2.155
diff -C2 -r2.154 -r2.155
*** bltinmodule.c	2000/04/13 02:42:50	2.154
--- bltinmodule.c	2000/05/02 19:24:06	2.155
***************
*** 2545,2632 ****
  }
  
- static void
- initerrors(dict)
- 	PyObject *dict;
- {
- 	int i, j;
- 	int exccnt = 0;
- 	for (i = 0; bltin_exc[i].name; i++, exccnt++) {
- 		Py_XDECREF(*bltin_exc[i].exc);
- 		if (bltin_exc[i].leaf_exc)
- 			*bltin_exc[i].exc =
- 				newstdexception(dict, bltin_exc[i].name);
- 	}
- 
- 	/* This is kind of bogus because we special case the some of the
- 	 * new exceptions to be nearly forward compatible.  But this means
- 	 * we hard code knowledge about exceptions.py into C here.  I don't
- 	 * have a better solution, though.
- 	 */
- 	PyExc_LookupError = PyTuple_New(2);
- 	Py_INCREF(PyExc_IndexError);
- 	PyTuple_SET_ITEM(PyExc_LookupError, 0, PyExc_IndexError);
- 	Py_INCREF(PyExc_KeyError);
- 	PyTuple_SET_ITEM(PyExc_LookupError, 1, PyExc_KeyError);
- 	PyDict_SetItemString(dict, "LookupError", PyExc_LookupError);
- 
- 	PyExc_ArithmeticError = PyTuple_New(3);
- 	Py_INCREF(PyExc_OverflowError);
- 	PyTuple_SET_ITEM(PyExc_ArithmeticError, 0, PyExc_OverflowError);
- 	Py_INCREF(PyExc_ZeroDivisionError);
- 	PyTuple_SET_ITEM(PyExc_ArithmeticError, 1, PyExc_ZeroDivisionError);
- 	Py_INCREF(PyExc_FloatingPointError);
- 	PyTuple_SET_ITEM(PyExc_ArithmeticError, 2, PyExc_FloatingPointError);
- 	PyDict_SetItemString(dict, "ArithmeticError", PyExc_ArithmeticError);
- 
- 	PyExc_EnvironmentError = PyTuple_New(2);
- 	Py_INCREF(PyExc_IOError);
- 	PyTuple_SET_ITEM(PyExc_EnvironmentError, 0, PyExc_IOError);
- 	Py_INCREF(PyExc_OSError);
- 	PyTuple_SET_ITEM(PyExc_EnvironmentError, 1, PyExc_OSError);
- 	PyDict_SetItemString(dict, "EnvironmentError", PyExc_EnvironmentError);
- 
- 	/* Make UnboundLocalError an alias for NameError */
- 	Py_INCREF(PyExc_NameError);
- 	Py_DECREF(PyExc_UnboundLocalError);
- 	PyExc_UnboundLocalError = PyExc_NameError;
- 	if (PyDict_SetItemString(dict, "UnboundLocalError",
- 				 PyExc_NameError) != 0)
- 		Py_FatalError("Cannot create string-based exceptions");
  
- 	/* Make UnicodeError an alias for ValueError */
- 	Py_INCREF(PyExc_ValueError);
- 	Py_DECREF(PyExc_UnicodeError);
- 	PyExc_UnicodeError = PyExc_ValueError;
- 	if (PyDict_SetItemString(dict, "UnicodeError",
- 				 PyExc_ValueError) != 0)
- 		Py_FatalError("Cannot create string-based exceptions");
- 
- 	/* missing from the StandardError tuple: Exception, StandardError,
- 	 * and SystemExit
- 	 */
- 	PyExc_StandardError = PyTuple_New(exccnt-3);
- 	for (i = 2, j = 0; bltin_exc[i].name; i++) {
- 		PyObject *exc = *bltin_exc[i].exc;
- 		/* SystemExit is not an error, but it is an exception */
- 		if (exc != PyExc_SystemExit) {
- 			Py_INCREF(exc);
- 			PyTuple_SET_ITEM(PyExc_StandardError, j++, exc);
- 		}
- 	}
- 	PyDict_SetItemString(dict, "StandardError", PyExc_StandardError);
- 
- 	/* Exception is a 2-tuple */
- 	PyExc_Exception = PyTuple_New(2);
- 	Py_INCREF(PyExc_SystemExit);
- 	PyTuple_SET_ITEM(PyExc_Exception, 0, PyExc_SystemExit);
- 	Py_INCREF(PyExc_StandardError);
- 	PyTuple_SET_ITEM(PyExc_Exception, 1, PyExc_StandardError);
- 	PyDict_SetItemString(dict, "Exception", PyExc_Exception);
- 	
- 	if (PyErr_Occurred())
- 	      Py_FatalError("Could not initialize built-in string exceptions");
- }
- 
- 
  static void
  finierrors()
--- 2545,2549 ----
***************
*** 2655,2659 ****
  		return NULL;
  	dict = PyModule_GetDict(mod);
- 	initerrors(dict);
  	if (PyDict_SetItemString(dict, "None", Py_None) < 0)
  		return NULL;
--- 2572,2575 ----
***************
*** 2671,2686 ****
  	PyObject *dict;
  {
! 	/* if Python was started with -X, initialize the class exceptions */
! 	if (Py_UseClassExceptionsFlag) {
! 		if (!init_class_exc(dict)) {
! 			/* class based exceptions could not be
! 			 * initialized. Fall back to using string based
! 			 * exceptions.
! 			 */
! 			PySys_WriteStderr(
! 			"Warning!  Falling back to string-based exceptions\n");
! 			initerrors(dict);
! 		}
! 	}
  }
  
--- 2587,2594 ----
  	PyObject *dict;
  {
! 	if (!init_class_exc(dict))
! 		/* class based exceptions could not be initialized. */
! 		Py_FatalError("Standard exceptions could not be initialized.");
! 	/* does not return */
  }