@@ -1668,21 +1668,6 @@ static PyMethodDef builtin_methods[] = {
16681668 {NULL , NULL },
16691669};
16701670
1671- static PyObject * builtin_mod ;
1672- static PyObject * builtin_dict ;
1673-
1674- PyObject *
1675- PyBuiltin_GetModule ()
1676- {
1677- return builtin_mod ;
1678- }
1679-
1680- PyObject *
1681- PyBuiltin_GetDict ()
1682- {
1683- return builtin_dict ;
1684- }
1685-
16861671/* Predefined exceptions */
16871672
16881673PyObject * PyExc_AccessError ;
@@ -1707,54 +1692,90 @@ PyObject *PyExc_ValueError;
17071692PyObject * PyExc_ZeroDivisionError ;
17081693
17091694static PyObject *
1710- newstdexception (name )
1695+ newstdexception (dict , name )
1696+ PyObject * dict ;
17111697 char * name ;
17121698{
17131699 PyObject * v = PyString_FromString (name );
1714- if (v == NULL || PyDict_SetItemString (builtin_dict , name , v ) != 0 )
1700+ if (v == NULL || PyDict_SetItemString (dict , name , v ) != 0 )
17151701 Py_FatalError ("no mem for new standard exception" );
17161702 return v ;
17171703}
17181704
17191705static void
1720- initerrors ()
1706+ initerrors (dict )
1707+ PyObject * dict ;
17211708{
1722- PyExc_AccessError = newstdexception ("AccessError" );
1723- PyExc_AssertionError = newstdexception ("AssertionError" );
1724- PyExc_AttributeError = newstdexception ("AttributeError" );
1725- PyExc_EOFError = newstdexception ("EOFError" );
1726- PyExc_FloatingPointError = newstdexception ("FloatingPointError" );
1727- PyExc_IOError = newstdexception ("IOError" );
1728- PyExc_ImportError = newstdexception ("ImportError" );
1729- PyExc_IndexError = newstdexception ("IndexError" );
1730- PyExc_KeyError = newstdexception ("KeyError" );
1731- PyExc_KeyboardInterrupt = newstdexception ("KeyboardInterrupt" );
1732- PyExc_MemoryError = newstdexception ("MemoryError" );
1733- PyExc_NameError = newstdexception ("NameError" );
1734- PyExc_OverflowError = newstdexception ("OverflowError" );
1735- PyExc_RuntimeError = newstdexception ("RuntimeError" );
1736- PyExc_SyntaxError = newstdexception ("SyntaxError" );
1737- PyExc_SystemError = newstdexception ("SystemError" );
1738- PyExc_SystemExit = newstdexception ("SystemExit" );
1739- PyExc_TypeError = newstdexception ("TypeError" );
1740- PyExc_ValueError = newstdexception ("ValueError" );
1741- PyExc_ZeroDivisionError = newstdexception ("ZeroDivisionError" );
1709+ PyExc_AccessError = newstdexception (dict , "AccessError" );
1710+ PyExc_AssertionError = newstdexception (dict , "AssertionError" );
1711+ PyExc_AttributeError = newstdexception (dict , "AttributeError" );
1712+ PyExc_EOFError = newstdexception (dict , "EOFError" );
1713+ PyExc_FloatingPointError = newstdexception (dict , "FloatingPointError" );
1714+ PyExc_IOError = newstdexception (dict , "IOError" );
1715+ PyExc_ImportError = newstdexception (dict , "ImportError" );
1716+ PyExc_IndexError = newstdexception (dict , "IndexError" );
1717+ PyExc_KeyError = newstdexception (dict , "KeyError" );
1718+ PyExc_KeyboardInterrupt = newstdexception (dict , "KeyboardInterrupt" );
1719+ PyExc_MemoryError = newstdexception (dict , "MemoryError" );
1720+ PyExc_NameError = newstdexception (dict , "NameError" );
1721+ PyExc_OverflowError = newstdexception (dict , "OverflowError" );
1722+ PyExc_RuntimeError = newstdexception (dict , "RuntimeError" );
1723+ PyExc_SyntaxError = newstdexception (dict , "SyntaxError" );
1724+ PyExc_SystemError = newstdexception (dict , "SystemError" );
1725+ PyExc_SystemExit = newstdexception (dict , "SystemExit" );
1726+ PyExc_TypeError = newstdexception (dict , "TypeError" );
1727+ PyExc_ValueError = newstdexception (dict , "ValueError" );
1728+ PyExc_ZeroDivisionError = newstdexception (dict , "ZeroDivisionError" );
1729+ }
1730+
1731+ static void
1732+ finierrors ()
1733+ {
1734+ Py_XDECREF (PyExc_AccessError ); PyExc_AccessError = NULL ;
1735+ Py_XDECREF (PyExc_AssertionError ); PyExc_AssertionError = NULL ;
1736+ Py_XDECREF (PyExc_AttributeError ); PyExc_AttributeError = NULL ;
1737+ Py_XDECREF (PyExc_EOFError ); PyExc_EOFError = NULL ;
1738+ Py_XDECREF (PyExc_FloatingPointError ); PyExc_FloatingPointError = NULL ;
1739+ Py_XDECREF (PyExc_IOError ); PyExc_IOError = NULL ;
1740+ Py_XDECREF (PyExc_ImportError ); PyExc_ImportError = NULL ;
1741+ Py_XDECREF (PyExc_IndexError ); PyExc_IndexError = NULL ;
1742+ Py_XDECREF (PyExc_KeyError ); PyExc_KeyError = NULL ;
1743+ Py_XDECREF (PyExc_KeyboardInterrupt ); PyExc_KeyboardInterrupt = NULL ;
1744+ Py_XDECREF (PyExc_MemoryError ); PyExc_MemoryError = NULL ;
1745+ Py_XDECREF (PyExc_NameError ); PyExc_NameError = NULL ;
1746+ Py_XDECREF (PyExc_OverflowError ); PyExc_OverflowError = NULL ;
1747+ Py_XDECREF (PyExc_RuntimeError ); PyExc_RuntimeError = NULL ;
1748+ Py_XDECREF (PyExc_SyntaxError ); PyExc_SyntaxError = NULL ;
1749+ Py_XDECREF (PyExc_SystemError ); PyExc_SystemError = NULL ;
1750+ Py_XDECREF (PyExc_SystemExit ); PyExc_SystemExit = NULL ;
1751+ Py_XDECREF (PyExc_TypeError ); PyExc_TypeError = NULL ;
1752+ Py_XDECREF (PyExc_ValueError ); PyExc_ValueError = NULL ;
1753+ Py_XDECREF (PyExc_ZeroDivisionError ); PyExc_ZeroDivisionError = NULL ;
1754+ }
1755+
1756+ PyObject *
1757+ _PyBuiltin_Init ()
1758+ {
1759+ PyObject * mod , * dict ;
1760+ mod = Py_InitModule ("__builtin__" , builtin_methods );
1761+ if (mod == NULL )
1762+ return NULL ;
1763+ dict = PyModule_GetDict (mod );
1764+ initerrors (dict );
1765+ if (PyDict_SetItemString (dict , "None" , Py_None ) < 0 )
1766+ return NULL ;
1767+ if (PyDict_SetItemString (dict , "Ellipsis" , Py_Ellipsis ) < 0 )
1768+ return NULL ;
1769+ if (PyDict_SetItemString (dict , "__debug__" ,
1770+ PyInt_FromLong (Py_OptimizeFlag == 0 )) < 0 )
1771+ return NULL ;
1772+ return mod ;
17421773}
17431774
17441775void
1745- PyBuiltin_Init ()
1776+ _PyBuiltin_Fini ()
17461777{
1747- builtin_mod = Py_InitModule ("__builtin__" , builtin_methods );
1748- builtin_dict = PyModule_GetDict (builtin_mod );
1749- Py_INCREF (builtin_dict );
1750- initerrors ();
1751- (void ) PyDict_SetItemString (builtin_dict , "None" , Py_None );
1752- (void ) PyDict_SetItemString (builtin_dict , "Ellipsis" , Py_Ellipsis );
1753- (void ) PyDict_SetItemString (builtin_dict , "__debug__" ,
1754- PyInt_FromLong (Py_OptimizeFlag == 0 ));
1755- if (PyErr_Occurred ())
1756- Py_FatalError (
1757- "error creating None/Ellipsis/__debug__ in __builtin__" );
1778+ finierrors ();
17581779}
17591780
17601781
0 commit comments