[Python-checkins] r46376 - in python/branches/sreifschneider-newnewexcept: Objects/exceptions.c Python/errors.c
richard.jones
python-checkins at python.org
Fri May 26 20:13:38 CEST 2006
Author: richard.jones
Date: Fri May 26 20:13:38 2006
New Revision: 46376
Modified:
python/branches/sreifschneider-newnewexcept/Objects/exceptions.c
python/branches/sreifschneider-newnewexcept/Python/errors.c
Log:
StopIteration as singleton
Modified: python/branches/sreifschneider-newnewexcept/Objects/exceptions.c
==============================================================================
--- python/branches/sreifschneider-newnewexcept/Objects/exceptions.c (original)
+++ python/branches/sreifschneider-newnewexcept/Objects/exceptions.c Fri May 26 20:13:38 2006
@@ -16,18 +16,21 @@
PyObject *message;
} BaseExceptionObject;
-/* GB: - I don't know, but it may be that the exceptions
- have to be GC objects
- - If you want to allow normal attribute access,
- I think you can use PyObject_GenericGetAttr etc.
- in the tp_getattr... slots.
-*/
+static PyTypeObject _PyExc_StopIteration;
+PyObject *PyExc_StopIterationInst;
static PyObject *
BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
BaseExceptionObject *self;
+ /* Make StopIteration be a singleton as often as we can */
+ if ((args == NULL || PyTuple_GET_SIZE(args) == 0) &&
+ PyExc_StopIterationInst != NULL &&
+ type == &_PyExc_StopIteration) {
+ return PyExc_StopIterationInst;
+ }
+
self = (BaseExceptionObject *)type->tp_alloc(type, 0);
self->args = self->message = self->dict = NULL;
@@ -1965,6 +1968,9 @@
*/
PyObject *PyExc_MemoryErrorInst=NULL;
+/* Make StopIteration be a singleton as often as we can */
+PyObject *PyExc_StopIterationInst=NULL;
+
/* module global functions */
static PyMethodDef functions[] = {
/* Sentinel */
@@ -1984,13 +1990,6 @@
{
PyObject *m, *bltinmod, *bdict;
- bltinmod = PyImport_ImportModule("__builtin__");
- if (bltinmod == NULL)
- Py_FatalError("exceptions bootstrapping error.");
- bdict = PyModule_GetDict(bltinmod);
- if (bdict == NULL)
- Py_FatalError("exceptions bootstrapping error.");
-
PRE_INIT(BaseException)
PRE_INIT(Exception)
PRE_INIT(StandardError)
@@ -2048,6 +2047,13 @@
m = Py_InitModule("exceptions", functions);
if (m == NULL) return;
+ bltinmod = PyImport_ImportModule("__builtin__");
+ if (bltinmod == NULL)
+ Py_FatalError("exceptions bootstrapping error.");
+ bdict = PyModule_GetDict(bltinmod);
+ if (bdict == NULL)
+ Py_FatalError("exceptions bootstrapping error.");
+
POST_INIT(BaseException)
POST_INIT(Exception)
POST_INIT(StandardError)
@@ -2106,6 +2112,11 @@
if (!PyExc_MemoryErrorInst)
Py_FatalError("Cannot pre-allocate MemoryError instance\n");
+ PyExc_StopIterationInst = BaseException_new(&_PyExc_StopIteration, NULL,
+ NULL);
+ if (!PyExc_StopIterationInst)
+ Py_FatalError("Cannot pre-allocate StopIteration instance\n");
+
Py_DECREF(bdict);
Py_DECREF(bltinmod);
}
Modified: python/branches/sreifschneider-newnewexcept/Python/errors.c
==============================================================================
--- python/branches/sreifschneider-newnewexcept/Python/errors.c (original)
+++ python/branches/sreifschneider-newnewexcept/Python/errors.c Fri May 26 20:13:38 2006
@@ -567,7 +567,7 @@
goto failure;
}
/*result = PyClass_New(bases, dict, classname);*/
- result = PyObject_CallFunction(&PyType_Type, "sOO",
+ result = PyObject_CallFunction((PyObject *)&PyType_Type, "sOO",
dot+1, bases, dict);
failure:
Py_XDECREF(bases);
More information about the Python-checkins
mailing list