Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (revision 54668) +++ Python/pythonrun.c (working copy) @@ -189,7 +189,8 @@ if (!_PyInt_Init()) Py_FatalError("Py_Initialize: can't init ints"); - _PyFloat_Init(); + if (!_PyFloat_Init()) + Py_FatalError("Py_Initialize: can't init floats"); interp->modules = PyDict_New(); if (interp->modules == NULL) Index: Include/pythonrun.h =================================================================== --- Include/pythonrun.h (revision 54668) +++ Include/pythonrun.h (working copy) @@ -122,7 +122,7 @@ PyAPI_FUNC(void) _PyImportHooks_Init(void); PyAPI_FUNC(int) _PyFrame_Init(void); PyAPI_FUNC(int) _PyInt_Init(void); -PyAPI_FUNC(void) _PyFloat_Init(void); +PyAPI_FUNC(int) _PyFloat_Init(void); /* Various internal finalizers */ PyAPI_FUNC(void) _PyExc_Fini(void); Index: Objects/floatobject.c =================================================================== --- Objects/floatobject.c (revision 54668) +++ Objects/floatobject.c (working copy) @@ -27,6 +27,7 @@ static PyFloatBlock *block_list = NULL; static PyFloatObject *free_list = NULL; +static PyFloatObject *zero_float = NULL; static PyFloatObject * fill_free_list(void) @@ -50,6 +51,10 @@ PyFloat_FromDouble(double fval) { register PyFloatObject *op; + if (fval == 0.0) { + Py_INCREF(zero_float); + return (PyObject *)zero_float; + } if (free_list == NULL) { if ((free_list = fill_free_list()) == NULL) return NULL; @@ -1205,7 +1210,7 @@ float_new, /* tp_new */ }; -void +int _PyFloat_Init(void) { /* We attempt to determine if this machine is using IEEE @@ -1253,6 +1258,15 @@ double_format = detected_double_format; float_format = detected_float_format; + + /* Initialize zero_float */ + if (!free_list && (free_list = fill_free_list()) == NULL) + return 0; + /* PyObject_New is inlined */ + zero_float = free_list; + free_list = (PyFloatObject *)zero_float->ob_type; + PyObject_INIT(zero_float, &PyFloat_Type); + zero_float->ob_fval = 0.0; } void @@ -1264,6 +1278,9 @@ int bc, bf; /* block count, number of freed blocks */ int frem, fsum; /* remaining unfreed floats per block, total */ + Py_XDECREF(zero_float); + zero_float = NULL; + bc = 0; bf = 0; fsum = 0;