[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.160,2.161
Barry Warsaw
python-dev@python.org
Thu, 25 May 2000 16:15:07 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory slayer.i.sourceforge.net:/tmp/cvs-serv25212
Modified Files:
bltinmodule.c
Log Message:
All the exception building related stuff has been moved out of this
module and into _exceptions.c. This includes all the PyExc_* globals,
the bltin_exc table, init_class_exc(), fini_instances(),
finierrors().
Renamed _PyBuiltin_Init_1() to _PyBuiltin_Init() since the two phase
initializations are necessary any more.
Removed as obsolete _PyBuiltin_Init_2(), _PyBuiltin_Fini_1() and
_PyBuiltin_Fini_2().
Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.160
retrieving revision 2.161
diff -C2 -r2.160 -r2.161
*** bltinmodule.c 2000/05/25 03:18:53 2.160
--- bltinmodule.c 2000/05/25 23:15:05 2.161
***************
*** 2357,2525 ****
};
- /* Predefined exceptions */
-
- PyObject *PyExc_Exception;
- PyObject *PyExc_StandardError;
- PyObject *PyExc_ArithmeticError;
- PyObject *PyExc_LookupError;
-
- PyObject *PyExc_AssertionError;
- PyObject *PyExc_AttributeError;
- PyObject *PyExc_EOFError;
- PyObject *PyExc_FloatingPointError;
- PyObject *PyExc_EnvironmentError;
- PyObject *PyExc_IOError;
- PyObject *PyExc_OSError;
- PyObject *PyExc_ImportError;
- PyObject *PyExc_IndexError;
- PyObject *PyExc_KeyError;
- PyObject *PyExc_KeyboardInterrupt;
- PyObject *PyExc_MemoryError;
- PyObject *PyExc_NameError;
- PyObject *PyExc_OverflowError;
- PyObject *PyExc_RuntimeError;
- PyObject *PyExc_NotImplementedError;
- PyObject *PyExc_SyntaxError;
- PyObject *PyExc_SystemError;
- PyObject *PyExc_SystemExit;
- PyObject *PyExc_UnboundLocalError;
- PyObject *PyExc_UnicodeError;
- PyObject *PyExc_TypeError;
- PyObject *PyExc_ValueError;
- PyObject *PyExc_ZeroDivisionError;
- #ifdef MS_WINDOWS
- PyObject *PyExc_WindowsError;
- #endif
-
- PyObject *PyExc_MemoryErrorInst;
-
- static struct
- {
- char* name;
- PyObject** exc;
- }
- bltin_exc[] = {
- {"Exception", &PyExc_Exception},
- {"StandardError", &PyExc_StandardError},
- {"ArithmeticError", &PyExc_ArithmeticError},
- {"LookupError", &PyExc_LookupError},
- {"AssertionError", &PyExc_AssertionError},
- {"AttributeError", &PyExc_AttributeError},
- {"EOFError", &PyExc_EOFError},
- {"FloatingPointError", &PyExc_FloatingPointError},
- {"EnvironmentError", &PyExc_EnvironmentError},
- {"IOError", &PyExc_IOError},
- {"OSError", &PyExc_OSError},
- {"ImportError", &PyExc_ImportError},
- {"IndexError", &PyExc_IndexError},
- {"KeyError", &PyExc_KeyError},
- {"KeyboardInterrupt", &PyExc_KeyboardInterrupt},
- {"MemoryError", &PyExc_MemoryError},
- {"NameError", &PyExc_NameError},
- {"OverflowError", &PyExc_OverflowError},
- {"RuntimeError", &PyExc_RuntimeError},
- {"NotImplementedError",&PyExc_NotImplementedError},
- {"SyntaxError", &PyExc_SyntaxError},
- {"SystemError", &PyExc_SystemError},
- {"SystemExit", &PyExc_SystemExit},
- {"UnboundLocalError", &PyExc_UnboundLocalError},
- {"UnicodeError", &PyExc_UnicodeError},
- {"TypeError", &PyExc_TypeError},
- {"ValueError", &PyExc_ValueError},
- #ifdef MS_WINDOWS
- {"WindowsError", &PyExc_WindowsError},
- #endif
- {"ZeroDivisionError", &PyExc_ZeroDivisionError},
- {NULL, NULL}
- };
-
-
- /* Import exceptions module to extract class exceptions. On success,
- * return 1. On failure return 0 which signals _PyBuiltin_Init_2 to
- * issue a fatal error.
- */
- static int
- init_class_exc(dict)
- PyObject *dict;
- {
- int i;
- PyObject *m = PyImport_ImportModule("exceptions");
- PyObject *args = NULL;
- PyObject *d = NULL;
-
- /* make sure we got the module and its dictionary */
- if (m == NULL ||
- (d = PyModule_GetDict(m)) == NULL)
- {
- PySys_WriteStderr("'import exceptions' failed\n");
- goto finally;
- }
- for (i = 0; bltin_exc[i].name; i++) {
- /* dig the exception out of the module */
- PyObject *exc = PyDict_GetItemString(d, bltin_exc[i].name);
- if (!exc) {
- PySys_WriteStderr(
- "Built-in exception class not found: %s. Library mismatch?\n",
- bltin_exc[i].name);
- goto finally;
- }
- /* free the old-style exception string object */
- Py_XDECREF(*bltin_exc[i].exc);
-
- /* squirrel away a pointer to the exception */
- Py_INCREF(exc);
- *bltin_exc[i].exc = exc;
-
- /* and insert the name in the __builtin__ module */
- if (PyDict_SetItemString(dict, bltin_exc[i].name, exc)) {
- PySys_WriteStderr(
- "Cannot insert exception into __builtin__: %s\n",
- bltin_exc[i].name);
- goto finally;
- }
- }
-
- /* we need one pre-allocated instance */
- args = Py_BuildValue("()");
- if (!args ||
- !(PyExc_MemoryErrorInst =
- PyEval_CallObject(PyExc_MemoryError, args)))
- {
- PySys_WriteStderr("Cannot pre-allocate MemoryError instance\n");
- goto finally;
- }
- Py_DECREF(args);
-
- /* we're done with the exceptions module */
- Py_DECREF(m);
- return 1;
-
- finally:
- Py_XDECREF(m);
- Py_XDECREF(args);
- PyErr_Clear();
- return 0;
- }
-
-
- static void
- fini_instances()
- {
- Py_XDECREF(PyExc_MemoryErrorInst);
- PyExc_MemoryErrorInst = NULL;
- }
-
-
- static void
- finierrors()
- {
- int i;
- for (i = 0; bltin_exc[i].name; i++) {
- PyObject *exc = *bltin_exc[i].exc;
- Py_XDECREF(exc);
- *bltin_exc[i].exc = NULL;
- }
- }
-
static char builtin_doc[] =
"Built-in functions, exceptions, and other objects.\n\
--- 2357,2360 ----
***************
*** 2528,2532 ****
PyObject *
! _PyBuiltin_Init_1()
{
PyObject *mod, *dict;
--- 2363,2367 ----
PyObject *
! _PyBuiltin_Init()
{
PyObject *mod, *dict;
***************
*** 2547,2574 ****
return mod;
}
-
- void
- _PyBuiltin_Init_2(dict)
- PyObject *dict;
- {
- if (!init_class_exc(dict))
- /* class based exceptions could not be initialized. */
- Py_FatalError("Standard exceptions could not be initialized.");
- }
-
-
- void
- _PyBuiltin_Fini_1()
- {
- fini_instances();
- }
-
-
- void
- _PyBuiltin_Fini_2()
- {
- finierrors();
- }
-
/* Helper for filter(): filter a tuple through a function */
--- 2382,2385 ----