* 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.
diff --git a/Include/object.h b/Include/object.h
index 2a6b170..ab270f8 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -198,6 +198,13 @@
 	/* More standard operations (at end for binary compatibility) */
 
 	long (*tp_hash) FPROTO((object *));
+#ifdef COUNT_ALLOCS
+	/* these must be last */
+	int tp_alloc;
+	int tp_free;
+	int tp_maxalloc;
+	struct _typeobject *tp_next;
+#endif
 } typeobject;
 
 extern typeobject Typetype; /* The type of type objects */
@@ -253,15 +260,27 @@
 #endif
 
 #ifndef TRACE_REFS
+#ifdef COUNT_ALLOCS
+#define DELREF(op) ((op)->ob_type->tp_free++, (*(op)->ob_type->tp_dealloc)((object *)(op)))
+#else
 #define DELREF(op) (*(op)->ob_type->tp_dealloc)((object *)(op))
+#endif
 #define UNREF(op) /*empty*/
 #endif
 
+#ifdef COUNT_ALLOCS
+extern void inc_count PROTO((typeobject *));
+#endif
+
 #ifdef REF_DEBUG
 extern long ref_total;
 #ifndef TRACE_REFS
+#ifdef COUNT_ALLOCS
+#define NEWREF(op) (inc_count((op)->ob_type), ref_total++, (op)->ob_refcnt = 1)
+#else
 #define NEWREF(op) (ref_total++, (op)->ob_refcnt = 1)
 #endif
+#endif
 #define INCREF(op) (ref_total++, (op)->ob_refcnt++)
 #define DECREF(op) \
 	if (--ref_total, --(op)->ob_refcnt > 0) \
@@ -269,7 +288,11 @@
 	else \
 		DELREF(op)
 #else
+#ifdef COUNT_ALLOCS
+#define NEWREF(op) (inc_count((op)->ob_type), (op)->ob_refcnt = 1)
+#else
 #define NEWREF(op) ((op)->ob_refcnt = 1)
+#endif
 #define INCREF(op) ((op)->ob_refcnt++)
 #define DECREF(op) \
 	if (--(op)->ob_refcnt > 0) \