diff options
author | Guido van Rossum <guido@python.org> | 1999-03-11 01:47:00 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-03-11 01:47:00 (GMT) |
commit | a060fb2598d3cebbf6c6459c39eeffa6913eceb3 (patch) | |
tree | f6844d77e7a6776f119165a8efdb7d6ba6a46d48 /Objects | |
parent | 881928f7ab710ca24ec7179244e951ca0f141e36 (diff) | |
download | cpython-a060fb2598d3cebbf6c6459c39eeffa6913eceb3.zip cpython-a060fb2598d3cebbf6c6459c39eeffa6913eceb3.tar.gz cpython-a060fb2598d3cebbf6c6459c39eeffa6913eceb3.tar.bz2 |
Alas, Vladimir's patch caused a bus error (probably double
alignment?), and I didn't test it. Withdrawing it for now.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/floatobject.c | 63 |
1 files changed, 7 insertions, 56 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index f8da205..070e83d 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -95,27 +95,20 @@ double (*_Py_math_funcs_hack[])() = { /* Special free list -- see comments for same code in intobject.c. */ static PyFloatObject *free_list = NULL; -static PyFloatObject *block_list = NULL; #define BLOCK_SIZE 1000 /* 1K less typical malloc overhead */ -#define N_FLOATOBJECTS ((BLOCK_SIZE - sizeof(PyFloatObject *)) / \ - sizeof(PyFloatObject)) -#define PyMem_MALLOC malloc -#define PyMem_FREE free +#define N_FLOATOBJECTS (BLOCK_SIZE / sizeof(PyFloatObject)) static PyFloatObject * fill_free_list() { PyFloatObject *p, *q; - p = (PyFloatObject *)PyMem_MALLOC(BLOCK_SIZE); + p = PyMem_NEW(PyFloatObject, N_FLOATOBJECTS); if (p == NULL) return (PyFloatObject *)PyErr_NoMemory(); - *(PyFloatObject **)p = block_list; - block_list = p; - p = (PyFloatObject *)((char *)p + sizeof(PyFloatObject *)); q = p + N_FLOATOBJECTS; while (--q > p) - q->ob_type = (struct _typeobject *)(q-1); - q->ob_type = NULL; + *(PyFloatObject **)q = q-1; + *(PyFloatObject **)q = NULL; return p + N_FLOATOBJECTS - 1; } @@ -133,7 +126,7 @@ PyFloat_FromDouble(fval) return NULL; } op = free_list; - free_list = (PyFloatObject *)op->ob_type; + free_list = *(PyFloatObject **)free_list; op->ob_type = &PyFloat_Type; op->ob_fval = fval; _Py_NewReference(op); @@ -144,7 +137,7 @@ static void float_dealloc(op) PyFloatObject *op; { - op->ob_type = (struct _typeobject *)free_list; + *(PyFloatObject **)op = free_list; free_list = op; } @@ -611,47 +604,5 @@ PyTypeObject PyFloat_Type = { void PyFloat_Fini() { - PyFloatObject *p, *list; - int i; - int bc, bf; /* block count, number of freed blocks */ - int frem, fsum; /* remaining unfreed floats per block, total */ - - bc = 0; - bf = 0; - fsum = 0; - list = block_list; - block_list = NULL; - while (list != NULL) { - p = list; - p = (PyFloatObject *)((char *)p + sizeof(PyFloatObject *)); - bc++; - frem = 0; - for (i = 0; i < N_FLOATOBJECTS; i++, p++) { - if (PyFloat_Check(p) && p->ob_refcnt != 0) - frem++; - } - p = list; - list = *(PyFloatObject **)p; - if (frem) { - *(PyFloatObject **)p = block_list; - block_list = p; - } - else { - PyMem_FREE(p); - bf++; - } - fsum += frem; - } - if (Py_VerboseFlag) { - fprintf(stderr, "# cleanup floats"); - if (!fsum) { - fprintf(stderr, "\n"); - } - else { - fprintf(stderr, - ": %d unfreed float%s in %d out of %d block%s\n", - fsum, fsum == 1 ? "" : "s", - bc - bf, bc, bc == 1 ? "" : "s"); - } - } + /* XXX Alas, the free list is not easily and safely freeable */ } |