Commit 1d99af8d authored by Tim Peters's avatar Tim Peters

Changed the #-of-arenas counters to uints -- no need to be insane about

this.  But added an overflow check just in case there is.

Got rid of the ushort macro.  It wasn't used anymore (it was only used
in the no-longer-exists off_t macro), and there's no plausible use for it.
parent 8deda70b
...@@ -213,9 +213,6 @@ ...@@ -213,9 +213,6 @@
#undef uchar #undef uchar
#define uchar unsigned char /* assuming == 8 bits */ #define uchar unsigned char /* assuming == 8 bits */
#undef ushort
#define ushort unsigned short /* assuming >= 16 bits */
#undef uint #undef uint
#define uint unsigned int /* assuming >= 16 bits */ #define uint unsigned int /* assuming >= 16 bits */
...@@ -235,7 +232,7 @@ struct pool_header { ...@@ -235,7 +232,7 @@ struct pool_header {
block *freeblock; /* pool's free list head */ block *freeblock; /* pool's free list head */
struct pool_header *nextpool; /* next pool of this size class */ struct pool_header *nextpool; /* next pool of this size class */
struct pool_header *prevpool; /* previous pool "" */ struct pool_header *prevpool; /* previous pool "" */
ulong arenaindex; /* index into arenas of base adr */ uint arenaindex; /* index into arenas of base adr */
uint szidx; /* block size class index */ uint szidx; /* block size class index */
uint capacity; /* pool capacity in # of blocks */ uint capacity; /* pool capacity in # of blocks */
}; };
...@@ -312,8 +309,8 @@ static poolp freepools = NULL; /* free list for cached pools */ ...@@ -312,8 +309,8 @@ static poolp freepools = NULL; /* free list for cached pools */
* to the OS. * to the OS.
*/ */
static uptr *arenas = NULL; static uptr *arenas = NULL;
static ulong narenas = 0; static uint narenas = 0;
static ulong maxarenas = 0; static uint maxarenas = 0;
/* Number of pools still available to be allocated in the current arena. */ /* Number of pools still available to be allocated in the current arena. */
static uint nfreepools = 0; static uint nfreepools = 0;
...@@ -330,7 +327,7 @@ dumpem(void *ptr) ...@@ -330,7 +327,7 @@ dumpem(void *ptr)
{ {
if (ptr) if (ptr)
printf("inserted new arena at %08x\n", ptr); printf("inserted new arena at %08x\n", ptr);
printf("# arenas %d\n", narenas); printf("# arenas %u\n", narenas);
printf("was mine %lu wasn't mine %lu\n", wasmine, wasntmine); printf("was mine %lu wasn't mine %lu\n", wasmine, wasntmine);
} }
#define INCMINE ++wasmine #define INCMINE ++wasmine
...@@ -403,8 +400,12 @@ new_arena(void) ...@@ -403,8 +400,12 @@ new_arena(void)
* XXX until after the PyMem_FREE(oldarenas) below completes. * XXX until after the PyMem_FREE(oldarenas) below completes.
*/ */
uptr *oldarenas; uptr *oldarenas;
int newmax = maxarenas + (maxarenas >> 1); uptr *p;
uptr *p = (uptr *)PyMem_MALLOC(newmax * sizeof(*arenas)); uint newmax = maxarenas + (maxarenas >> 1);
if (newmax <= maxarenas) /* overflow */
goto error;
p = (uptr *)PyMem_MALLOC(newmax * sizeof(*arenas));
if (p == NULL) if (p == NULL)
goto error; goto error;
memcpy(p, arenas, narenas * sizeof(*arenas)); memcpy(p, arenas, narenas * sizeof(*arenas));
...@@ -417,7 +418,7 @@ new_arena(void) ...@@ -417,7 +418,7 @@ new_arena(void)
/* Append the new arena address to arenas. */ /* Append the new arena address to arenas. */
assert(narenas < maxarenas); assert(narenas < maxarenas);
arenas[narenas] = (uptr)bp; arenas[narenas] = (uptr)bp;
++narenas; ++narenas; /* can't overflow, since narenas < maxarenas before */
dumpem(bp); dumpem(bp);
return bp; return bp;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment