diff options
author | Sjoerd Mullender <sjoerd@acm.org> | 1993-10-11 12:54:31 (GMT) |
---|---|---|
committer | Sjoerd Mullender <sjoerd@acm.org> | 1993-10-11 12:54:31 (GMT) |
commit | a9c3c22c33762699b362e7598268442fd2df9eb6 (patch) | |
tree | 7ff6bdfb7228abf0a566b6d3215a383796bd5cbf /Objects | |
parent | 35fe6ec4cf6e192829a5bd28c080761157258e3e (diff) | |
download | cpython-a9c3c22c33762699b362e7598268442fd2df9eb6.zip cpython-a9c3c22c33762699b362e7598268442fd2df9eb6.tar.gz cpython-a9c3c22c33762699b362e7598268442fd2df9eb6.tar.bz2 |
* Extended X interface: pixmap objects, colormap objects visual objects,
image objects, and lots of new methods.
* Added counting of allocations and deallocations of builtin types if
COUNT_ALLOCS is defined. Had to move calls to NEWREF down in some
files.
* Bug fix in sorting lists.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/floatobject.c | 2 | ||||
-rw-r--r-- | Objects/intobject.c | 2 | ||||
-rw-r--r-- | Objects/listobject.c | 4 | ||||
-rw-r--r-- | Objects/object.c | 40 | ||||
-rw-r--r-- | Objects/stringobject.c | 8 | ||||
-rw-r--r-- | Objects/tupleobject.c | 2 |
6 files changed, 47 insertions, 11 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 9994523..d3a2c77 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -60,9 +60,9 @@ newfloatobject(fval) register floatobject *op = (floatobject *) malloc(sizeof(floatobject)); if (op == NULL) return err_nomem(); - NEWREF(op); op->ob_type = &Floattype; op->ob_fval = fval; + NEWREF(op); return (object *) op; } diff --git a/Objects/intobject.c b/Objects/intobject.c index 3021873..816a411 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -87,9 +87,9 @@ newintobject(ival) } v = free_list; free_list = *(intobject **)free_list; - NEWREF(v); v->ob_type = &Inttype; v->ob_ival = ival; + NEWREF(v); return (object *) v; } diff --git a/Objects/listobject.c b/Objects/listobject.c index 38829e2..67a6185 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -58,11 +58,11 @@ newlistobject(size) return err_nomem(); } } - NEWREF(op); op->ob_type = &Listtype; op->ob_size = size; for (i = 0; i < size; i++) op->ob_item[i] = NULL; + NEWREF(op); return (object *) op; } @@ -520,7 +520,7 @@ cmp(v, w) return cmpobject(* (object **) v, * (object **) w); /* Call the user-supplied comparison function */ - t = mkvalue("OO", v, w); + t = mkvalue("OO", * (object **) v, * (object **) w); if (t == NULL) return 0; res = call_object(cmpfunc, t); diff --git a/Objects/object.c b/Objects/object.c index a469797..a20b24d 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -34,6 +34,36 @@ long ref_total; These are used by the individual routines for object creation. Do not call them otherwise, they do not initialize the object! */ +#ifdef COUNT_ALLOCS +static typeobject *type_list; + +void +dump_counts() +{ + typeobject *tp; + + for (tp = type_list; tp; tp = tp->tp_next) + printf("%s %d %d %d\n", tp->tp_name, tp->tp_alloc, tp->tp_free, + tp->tp_maxalloc); +} + +void +inc_count(tp) + typeobject *tp; +{ + if (tp->tp_alloc == 0) { + /* first time; hang in linked list */ + if (tp->tp_next != NULL) /* sanity check */ + abort(); + tp->tp_next = type_list; + type_list = tp; + } + tp->tp_alloc++; + if (tp->tp_alloc - tp->tp_free > tp->tp_maxalloc) + tp->tp_maxalloc = tp->tp_alloc - tp->tp_free; +} +#endif + object * newobject(tp) typeobject *tp; @@ -41,8 +71,8 @@ newobject(tp) object *op = (object *) malloc(tp->tp_basicsize); if (op == NULL) return err_nomem(); - NEWREF(op); op->ob_type = tp; + NEWREF(op); return op; } @@ -55,9 +85,9 @@ newvarobject(tp, size) malloc(tp->tp_basicsize + size * tp->tp_itemsize); if (op == NULL) return (varobject *)err_nomem(); - NEWREF(op); op->ob_type = tp; op->ob_size = size; + NEWREF(op); return op; } @@ -301,6 +331,9 @@ NEWREF(op) op->_ob_prev = &refchain; refchain._ob_next->_ob_prev = op; refchain._ob_next = op; +#ifdef COUNT_ALLOCS + inc_count(op->ob_type); +#endif } UNREF(op) @@ -335,6 +368,9 @@ DELREF(op) object *op; { UNREF(op); +#ifdef COUNT_ALLOCS + op->ob_type->tp_free++; +#endif (*(op)->ob_type->tp_dealloc)(op); op->ob_type = NULL; } diff --git a/Objects/stringobject.c b/Objects/stringobject.c index cba8c92..a3043d4 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -35,9 +35,9 @@ newsizedstringobject(str, size) malloc(sizeof(stringobject) + size * sizeof(char)); if (op == NULL) return err_nomem(); - NEWREF(op); op->ob_type = &Stringtype; op->ob_size = size; + NEWREF(op); if (str != NULL) memcpy(op->ob_sval, str, size); op->ob_sval[size] = '\0'; @@ -53,9 +53,9 @@ newstringobject(str) malloc(sizeof(stringobject) + size * sizeof(char)); if (op == NULL) return err_nomem(); - NEWREF(op); op->ob_type = &Stringtype; op->ob_size = size; + NEWREF(op); strcpy(op->ob_sval, str); return (object *) op; } @@ -187,9 +187,9 @@ string_concat(a, bb) malloc(sizeof(stringobject) + size * sizeof(char)); if (op == NULL) return err_nomem(); - NEWREF(op); op->ob_type = &Stringtype; op->ob_size = size; + NEWREF(op); memcpy(op->ob_sval, a->ob_sval, (int) a->ob_size); memcpy(op->ob_sval + a->ob_size, b->ob_sval, (int) b->ob_size); op->ob_sval[size] = '\0'; @@ -216,9 +216,9 @@ string_repeat(a, n) malloc(sizeof(stringobject) + size * sizeof(char)); if (op == NULL) return err_nomem(); - NEWREF(op); op->ob_type = &Stringtype; op->ob_size = size; + NEWREF(op); for (i = 0; i < size; i += a->ob_size) memcpy(op->ob_sval+i, a->ob_sval, (int) a->ob_size); op->ob_sval[size] = '\0'; diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index faf46d5..fae9386 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -40,11 +40,11 @@ newtupleobject(size) malloc(sizeof(tupleobject) + size * sizeof(object *)); if (op == NULL) return err_nomem(); - NEWREF(op); op->ob_type = &Tupletype; op->ob_size = size; for (i = 0; i < size; i++) op->ob_item[i] = NULL; + NEWREF(op); return (object *) op; } |