[Python-checkins] python/dist/src/Objects obmalloc.c,2.42,2.43

tim_one@sourceforge.net tim_one@sourceforge.net
2002年4月18日 15:25:05 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv31559/python/Objects
Modified Files:
	obmalloc.c 
Log Message:
_PyObject_DebugMallocStats(): Added some potentially expensive internal
consistency checks, enabled only in a debug (Py_DEBUG) build. Note that
this never gets called automatically unless PYMALLOC_DEBUG is #define'd
too, and the envar PYTHONMALLOCSTATS exists.
Index: obmalloc.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/obmalloc.c,v
retrieving revision 2.42
retrieving revision 2.43
diff -C2 -d -r2.42 -r2.43
*** obmalloc.c	18 Apr 2002 21:58:56 -0000	2.42
--- obmalloc.c	18 Apr 2002 22:25:03 -0000	2.43
***************
*** 909,912 ****
--- 909,937 ----
 }
 
+ #ifdef Py_DEBUG
+ /* Is target in the list? The list is traversed via the nextpool pointers.
+ * The list may be NULL-terminated, or circular. Return 1 if target is in
+ * list, else 0.
+ */
+ static int
+ pool_is_in_list(const poolp target, poolp list)
+ {
+ 	poolp origlist = list;
+ 	assert(target != NULL);
+ 	if (list == NULL)
+ 		return 0;
+ 	do {
+ 		if (target == list)
+ 			return 1;
+ 		list = list->nextpool;
+ 	} while (list != NULL && list != origlist);
+ 	return 0;
+ }
+ 
+ #else
+ #define pool_is_in_list(X, Y) 1
+ 
+ #endif	/* Py_DEBUG */
+ 
 /* The debug malloc asks for 16 extra bytes and fills them with useful stuff,
 here calling the underlying malloc's result p:
***************
*** 1201,1205 ****
 }
 
! /* Print summary info to stderr about the state of pymalloc's structures. */
 void
 _PyObject_DebugMallocStats(void)
--- 1226,1233 ----
 }
 
! /* Print summary info to stderr about the state of pymalloc's structures.
! * In Py_DEBUG mode, also perform some expensive internal consistency
! * checks.
! */
 void
 _PyObject_DebugMallocStats(void)
***************
*** 1263,1275 ****
 		for (j = 0; j < poolsinarena; ++j, base += POOL_SIZE) {
 			poolp p = (poolp)base;
 			if (p->ref.count == 0) {
 				/* currently unused */
 				++numfreepools;
 				continue;
 			}
! 			++numpools[p->szidx];
! 			numblocks[p->szidx] += p->ref.count;
! 			numfreeblocks[p->szidx] += NUMBLOCKS(p->szidx) -
! 						 p->ref.count;
 		}
 	}
--- 1291,1311 ----
 		for (j = 0; j < poolsinarena; ++j, base += POOL_SIZE) {
 			poolp p = (poolp)base;
+ 			const uint sz = p->szidx;
+ 			uint freeblocks;
+ 
 			if (p->ref.count == 0) {
 				/* currently unused */
 				++numfreepools;
+ 				assert(pool_is_in_list(p, freepools));
 				continue;
 			}
! 			++numpools[sz];
! 			numblocks[sz] += p->ref.count;
! 			freeblocks = NUMBLOCKS(sz) - p->ref.count;
! 			numfreeblocks[sz] += freeblocks;
! #ifdef Py_DEBUG
! 			if (freeblocks > 0)
! 				assert(pool_is_in_list(p, usedpools[sz + sz]));
! #endif
 		}
 	}

AltStyle によって変換されたページ (->オリジナル) /