summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-03-12 19:43:17 (GMT)
committerGuido van Rossum <guido@python.org>1999-03-12 19:43:17 (GMT)
commit3fce8839223bf387257f3fd30545d796ba38f1fe (patch)
tree33b64133e524ad8865c09edb0bec620984b42b29 /Objects/floatobject.c
parent4edf656402ad396fc9aed6009ba85c77a4978d79 (diff)
downloadcpython-3fce8839223bf387257f3fd30545d796ba38f1fe.zip
cpython-3fce8839223bf387257f3fd30545d796ba38f1fe.tar.gz
cpython-3fce8839223bf387257f3fd30545d796ba38f1fe.tar.bz2
Vladimir has restructured his code somewhat so that the blocks are now
represented by an explicit structure. (There are still too many casts in the code, but that may be unavoidable.) Also added code so that with -vv it is very chatty about what it does.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c75
1 files changed, 50 insertions, 25 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index c11f8f7..34fd317 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -94,24 +94,33 @@ double (*_Py_math_funcs_hack[])() = {
#endif
/* 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 BHEAD_SIZE 8 /* Hope this is enough alignment */
+#define BHEAD_SIZE 8 /* Enough for a 64-bit pointer */
#define N_FLOATOBJECTS ((BLOCK_SIZE - BHEAD_SIZE) / sizeof(PyFloatObject))
+
#define PyMem_MALLOC malloc
#define PyMem_FREE free
+struct _floatblock {
+ struct _floatblock *next;
+ PyFloatObject objects[N_FLOATOBJECTS];
+};
+
+typedef struct _floatblock PyFloatBlock;
+
+static PyFloatBlock *block_list = NULL;
+static PyFloatObject *free_list = NULL;
+
static PyFloatObject *
fill_free_list()
{
PyFloatObject *p, *q;
- p = (PyFloatObject *)PyMem_MALLOC(BLOCK_SIZE);
+ p = (PyFloatObject *)PyMem_MALLOC(sizeof(PyFloatBlock));
if (p == NULL)
return (PyFloatObject *)PyErr_NoMemory();
- *(PyFloatObject **)p = block_list;
- block_list = p;
- p = (PyFloatObject *)((char *)p + BHEAD_SIZE);
+ ((PyFloatBlock *)p)->next = block_list;
+ block_list = (PyFloatBlock *)p;
+ p = &((PyFloatBlock *)p)->objects[0];
q = p + N_FLOATOBJECTS;
while (--q > p)
q->ob_type = (struct _typeobject *)(q-1);
@@ -611,7 +620,8 @@ PyTypeObject PyFloat_Type = {
void
PyFloat_Fini()
{
- PyFloatObject *p, *list;
+ PyFloatObject *p;
+ PyFloatBlock *list, *next;
int i;
int bc, bf; /* block count, number of freed blocks */
int frem, fsum; /* remaining unfreed floats per block, total */
@@ -622,36 +632,51 @@ PyFloat_Fini()
list = block_list;
block_list = NULL;
while (list != NULL) {
- p = list;
- p = (PyFloatObject *)((char *)p + BHEAD_SIZE);
+ p = &list->objects[0];
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;
+ next = list->next;
if (frem) {
- *(PyFloatObject **)p = block_list;
- block_list = p;
+ list->next = block_list;
+ block_list = list;
}
else {
- PyMem_FREE(p);
+ PyMem_FREE(list);
bf++;
}
fsum += frem;
+ list = next;
}
- 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");
+ if (!Py_VerboseFlag)
+ return;
+ 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");
+ }
+ if (Py_VerboseFlag > 1) {
+ list = block_list;
+ while (list != NULL) {
+ p = &list->objects[0];
+ for (i = 0; i < N_FLOATOBJECTS; i++, p++) {
+ if (PyFloat_Check(p) && p->ob_refcnt != 0) {
+ char buf[100];
+ PyFloat_AsString(buf, p);
+ fprintf(stderr,
+ "# <float object at %lx, refcnt=%d, val=%s>\n",
+ p, p->ob_refcnt, buf);
+ }
+ }
+ list = list->next;
}
}
}