Mailing List Archive

python/dist/src/Objects obmalloc.c,2.33,2.34
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv14060/python/Objects

Modified Files:
obmalloc.c
Log Message:
SF bug 542181: Realloc behavior
The bug report pointed out a bogosity in the comment block explaining
thread safety for arena management. Repaired that comment, repaired a
couple others while I was at it, and added an assert.

_PyMalloc_DebugRealloc: If this needed to get more memory, but couldn't,
it erroneously freed the original memory. Repaired that.

This is for 2.3 only (unless we decide to backport the new pymalloc).


Index: obmalloc.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/obmalloc.c,v
retrieving revision 2.33
retrieving revision 2.34
diff -C2 -d -r2.33 -r2.34
*** obmalloc.c 6 Apr 2002 01:45:35 -0000 2.33
--- obmalloc.c 11 Apr 2002 06:36:45 -0000 2.34
***************
*** 322,332 ****

So long as a pool is in the used state, we're certain there *is* a block
! available for allocating. If pool->freeblock is NULL then, that means we
! simply haven't yet gotten to one of the higher-address blocks. The offset
! from the pool_header to the start of "the next" virgin block is stored in
! the pool_header nextoffset member, and the largest value of nextoffset that
! makes sense is stored in the maxnextoffset member when a pool is initialized.
! All the blocks in a pool have been passed out at least once when and only
! when nextoffset > maxnextoffset.


--- 322,333 ----

So long as a pool is in the used state, we're certain there *is* a block
! available for allocating, and pool->freeblock is not NULL. If pool->freeblock
! points to the end of the free list before we've carved the entire pool into
! blocks, that means we simply haven't yet gotten to one of the higher-address
! blocks. The offset from the pool_header to the start of "the next" virgin
! block is stored in the pool_header nextoffset member, and the largest value
! of nextoffset that makes sense is stored in the maxnextoffset member when a
! pool is initialized. All the blocks in a pool have been passed out at least
! once when and only when nextoffset > maxnextoffset.


***************
*** 468,473 ****
}
else if (narenas == maxarenas) {
! /* Grow arenas. Don't use realloc: if this fails, we
! * don't want to lose the base addresses we already have.
*
* Exceedingly subtle: Someone may be calling the pymalloc
--- 469,473 ----
}
else if (narenas == maxarenas) {
! /* Grow arenas.
*
* Exceedingly subtle: Someone may be calling the pymalloc
***************
*** 591,594 ****
--- 591,595 ----
++pool->ref.count;
bp = pool->freeblock;
+ assert(bp != NULL);
if ((pool->freeblock = *(block **)bp) != NULL) {
UNLOCK();
***************
*** 1058,1067 ****
}

/* More memory is needed: get it, copy over the first original_nbytes
of the original data, and free the original memory. */
fresh = _PyMalloc_DebugMalloc(nbytes);
! if (fresh != NULL && original_nbytes > 0)
! memcpy(fresh, p, original_nbytes);
! _PyMalloc_DebugFree(p);
return fresh;
}
--- 1059,1071 ----
}

+ assert(nbytes != 0);
/* More memory is needed: get it, copy over the first original_nbytes
of the original data, and free the original memory. */
fresh = _PyMalloc_DebugMalloc(nbytes);
! if (fresh != NULL) {
! if (original_nbytes > 0)
! memcpy(fresh, p, original_nbytes);
! _PyMalloc_DebugFree(p);
! }
return fresh;
}