rev 741 - in trunk: . include/prothon src
SVN User <[email protected]> Fri, 16 Jul 2004 01:16:01 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-07-16 01:15:58 -0400 (Fri, 16 Jul 2004)
New Revision: 741
Modified:
trunk/STATUS.txt
trunk/include/prothon/prothon.h
trunk/src/builtins-list.c
trunk/src/builtins-tuple.c
trunk/src/prlist.h
trunk/src/prmalloc.c
Log:
fixed a bug in list creation
Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt 2004-07-15 20:34:43 UTC (rev 740)
+++ trunk/STATUS.txt 2004-07-16 05:15:58 UTC (rev 741)
@@ -6,6 +6,7 @@
--- check all PEPs
--- revisit all methods to change list returns into generators
+--- change methods into properties
--- bug in simple instantiation in the console in 710
Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h 2004-07-15 20:34:43 UTC (rev 740)
+++ trunk/include/prothon/prothon.h 2004-07-16 05:15:58 UTC (rev 741)
@@ -67,7 +67,7 @@
#define DEBUG_THREADS
// These should NOT be defined for releases
-#define DEBUG_PRMALLOC
+//#define DEBUG_PRMALLOC
//#define DEBUG_MEM_MGR
//#define PROSIST_DEBUG
Modified: trunk/src/builtins-list.c
===================================================================
--- trunk/src/builtins-list.c 2004-07-15 20:34:43 UTC (rev 740)
+++ trunk/src/builtins-list.c 2004-07-16 05:15:58 UTC (rev 741)
@@ -162,7 +162,8 @@
wrlock_rtrn(list_obj) NULL;
lstp = list_obj->data.ptr;
if(lstplen(lstp) == lstpsize(lstp)) {
- lstpsetsize(lstp, lstpsize(lstp) * LIST_GROWTH_FACTOR);
+ int size = max(lstpsize(lstp), 1) * LIST_GROWTH_FACTOR;
+ lstpsetsize(lstp, size);
lstp = pr_realloc(lstp, list_sizeof(lstpsize(lstp)));
list_obj->data.ptr = lstp;
}
Modified: trunk/src/builtins-tuple.c
===================================================================
--- trunk/src/builtins-tuple.c 2004-07-15 20:34:43 UTC (rev 740)
+++ trunk/src/builtins-tuple.c 2004-07-16 05:15:58 UTC (rev 741)
@@ -232,14 +232,14 @@
DEF(Tuple, mul_, FORM_RPARAM){
obj_p res;
list_p lstp, selfp = (list_p)(self->data.ptr);
- int i, size, times, len = (int) list_len(ist, self);
+ int i, total_len, times, len = (int) list_len(ist, self);
BIN_CONTENT_CHK(Tuple);
if (!has_proto(ist, parms[1], OBJ(INT_PROTO))) {
raise_exception(ist, OBJ(TYPE_EXC), "multiply times parameter must be an integer");
return NULL;
}
times = (int)parms[1]->data.i64;
- size = len*times;
+ total_len = len*times;
if(times == 0) {
obj_p res = NEW_TUPLE(0);
res ->immutable = TRUE;
@@ -247,14 +247,14 @@
}
if(times == 1) return self;
res = NEW_OBJ(OBJ(TUPLE_PROTO));
- lstp = res->data.ptr = pr_malloc(list_sizeof(size));
+ lstp = res->data.ptr = pr_malloc(list_sizeof(total_len));
if(!lstp) {
raise_exception(ist, OBJ(OUTOFMEMORY_EXC), "memory allocation failed for tuple multiplication");
return NULL;
}
SET_TYPE_IF_EXC(Tuple_OBJ, res, DATA_TYPE_DATAPTR) return NULL;
- lstpsetsize(lstp, size);
- lstplen(lstp) = size;
+ lstpsetsize(lstp, total_len);
+ lstplen(lstp) = total_len;
for(i=0; i < times; i++)
memcpy(lstp->item+(i*len), selfp->item, len*sizeof(obj_p));
return res;
Modified: trunk/src/prlist.h
===================================================================
--- trunk/src/prlist.h 2004-07-15 20:34:43 UTC (rev 740)
+++ trunk/src/prlist.h 2004-07-16 05:15:58 UTC (rev 741)
@@ -59,7 +59,7 @@
#define list_sizeof(n) ((data_size_t)(sizeof(list_hdr_t)+((n)*sizeof(obj_p))))
typedef struct {
- data_size_t size;
+ data_size_t list_size;
size_t len;
} list_hdr_t;
@@ -70,8 +70,8 @@
typedef list_t* list_p;
-#define lstpsetsize(list_ptr,n) ((((list_p)(list_ptr))->hdr.size)=list_sizeof(n))
-#define lstpsize(list_ptr) (((((list_p)(list_ptr))->hdr.size)-sizeof(list_hdr_t))/sizeof(obj_p))
+#define lstpsetsize(list_ptr,n) ((((list_p)(list_ptr))->hdr.list_size)=list_sizeof(n))
+#define lstpsize(list_ptr) (((((list_p)(list_ptr))->hdr.list_size)-sizeof(list_hdr_t))/sizeof(obj_p))
#define lstplen(list_ptr) (((list_p)(list_ptr))->hdr.len)
#define lstpitem(list_ptr,i) (((list_p)(list_ptr))->item[i])
Modified: trunk/src/prmalloc.c
===================================================================
--- trunk/src/prmalloc.c 2004-07-15 20:34:43 UTC (rev 740)
+++ trunk/src/prmalloc.c 2004-07-16 05:15:58 UTC (rev 741)
@@ -92,7 +92,7 @@
*
* For small requests we have the following table:
*
- * Request in bytes Size of allocated block Size class idx
+ * Request in bytes Size of allocated uchar Size class idx
* ----------------------------------------------------------------
* 1-8 8 0
* 9-16 16 1
@@ -142,21 +142,9 @@
* it is recommended that SMALL_REQUEST_THRESHOLD is set to a power of 2.
*/
-/*
- * For Python compiled on systems with 32 bit pointers and integers,
- * a value of 64 (= 8 * 8) is a reasonable speed/space tradeoff for
- * the object allocator. To adjust automatically this threshold for
- * systems with 64 bit pointers, we make this setting depend on a
- * Python-specific attr size unit = sizeof(long) + sizeof(void *),
- * which is expected to be 8, 12 or 16 bytes.
- */
+#define NB_SMALL_SIZE_CLASSES (SIZEOF_LONG + SIZEOF_VOID_P) // N
+#define SMALL_REQUEST_THRESHOLD (NB_SMALL_SIZE_CLASSES * ALIGNMENT)
-#define _PYOBJECT_THRESHOLD ((SIZEOF_LONG + SIZEOF_VOID_P) * ALIGNMENT)
-
-#define SMALL_REQUEST_THRESHOLD _PYOBJECT_THRESHOLD /* must be N * ALIGNMENT */
-
-#define NB_SMALL_SIZE_CLASSES (SMALL_REQUEST_THRESHOLD / ALIGNMENT)
-
/*
* The system's VMM page size can be obtained on most unices with a
* getpagesize() call or deduced from various header files. To make
@@ -241,33 +229,30 @@
*/
#undef uchar
-#define uchar unsigned char /* assuming == 8 bits */
+#define uchar u8_t /* assuming == 8 bits */
#undef ushort
-#define ushort unsigned short /* assuming >= 16 bits */
+#define ushort u16_t /* assuming >= 16 bits */
#undef uint
-#define uint unsigned int /* assuming >= 16 bits */
+#define uint u32_t /* assuming >= 16 bits */
#undef ulong
-#define ulong unsigned long /* assuming >= 32 bits */
+#define ulong u32_t /* assuming >= 32 bits */
#undef off_t
-#define off_t size_t /* 16 bits <= off_t <= 64 bits */ /* was uint - mch */
+#define off_t size_t /* 16 bits <= off_t <= 64 bits */ /* was uint - mch */
-/* When you say memory, my mind reasons in terms of (pointers to) blocks */
-typedef uchar block;
-
/* Pool for small blocks */
struct pool_header {
- union { block *__padding;
+ union { uchar *pad;
uint count; } ref; /* number of allocated blocks */
- block *freeblock; /* pool's free list head */
+ uchar *freeblock; /* pool's free list head */
struct pool_header *nextpool; /* next pool of this size class */
struct pool_header *prevpool; /* previous pool "" */
struct pool_header *pooladdr; /* pool address (always aligned) */
uint magic; /* pool magic number */
- uint szidx; /* block size class index */
+ uint szidx; /* uchar size class index */
uint capacity; /* pool capacity in # of blocks */
};
@@ -291,7 +276,7 @@
/*
* Pool table -- doubly linked lists of partially used pools
*/
-#define PTA(x) ((poolp )((uchar *)&(usedpools[2*(x)]) - 2*sizeof(block *)))
+#define PTA(x) ((poolp )((uchar*)&(usedpools[2*(x)]) - 2*sizeof(uchar*)))
#define PT(x) PTA(x), PTA(x)
static poolp usedpools[2 * ((NB_SMALL_SIZE_CLASSES + 7) / 8) * 8] = {
@@ -321,71 +306,76 @@
#ifdef DEBUG_PRMALLOC
-typedef union {
- int num;
- void* ptr;
-} dlist_item_t;
-
typedef struct {
- int space;
- int len;
- dlist_item_t* items;
+ int space;
+ int len;
+ void* *ptrs;
} dlist_t;
typedef dlist_t* dlist_p;
-static dlist_p malloc_list = NULL;
+static dlist_p ptr_list = NULL;
dlist_p new_dlist(int initial_size){
dlist_p list;
- void* items;
+ void* ptrs;
list = malloc(sizeof(dlist_t));
- items = malloc(initial_size*sizeof(dlist_item_t));
+ ptrs = malloc(initial_size*sizeof(void*));
list->space = initial_size;
list->len = 0;
- list->items = items;
+ list->ptrs = ptrs;
return list;
}
-int dlist_in(dlist_p list, void* item) {
+int dlist_in(dlist_p list, void* ptr) {
int i;
for(i=0; i < list->len; i++)
- if (list->items[i].ptr == item) return TRUE;
+ if (list->ptrs[i] == ptr) return TRUE;
return FALSE;
}
-dlist_p dlist_append(dlist_p list, void* item) {
+dlist_p dlist_append(dlist_p list, void* ptr) {
if (list->len == list->space) {
list->space *= 2;
- list->items = realloc(list->items, list->space * sizeof(dlist_item_t));
+ list->ptrs = realloc(list->ptrs, list->space * sizeof(void*));
}
- list->items[list->len++].ptr = item;
+ list->ptrs[list->len++] = ptr;
return list;
}
-int dlist_pop_item(dlist_p list, void* item) {
+int dlist_pop_ptr(dlist_p list, void* ptr) {
int i;
for(i=list->len-1; i >= 0; i--)
- if (list->items[i].ptr == item) {
+ if (list->ptrs[i] == ptr) {
if (i < list->len-1)
- memmove( list->items+i, list->items+i+1,
- (list->len-1 - i) * sizeof(dlist_item_t) );
+ memmove( list->ptrs+i, list->ptrs+i+1,
+ (list->len-1 - i) * sizeof(void*) );
list->len--;
return FALSE;
}
return TRUE;
}
-#define debug_add(ptr) \
-do { \
- if (!malloc_list) \
- malloc_list = new_dlist(1000); \
- if (dlist_in(malloc_list, ptr)) pr_exit(1); \
- dlist_append(malloc_list, ptr); \
-} while(FALSE)
+#define tgt ((void*)0x00a0d0f8)
+//#define tgt ((void*)0x00a19de0)
-#define debug_del(ptr) if (dlist_pop_item(malloc_list, ptr)) pr_exit(1)
+void debug_add(void* ptr) {
+ if (ptr == tgt)
+ ptr = tgt;
+ if (!ptr_list)
+ ptr_list = new_dlist(1000);
+ if (dlist_in(ptr_list, ptr))
+ pr_exit(1);
+ dlist_append(ptr_list, ptr);
+}
+void debug_del(void* ptr) {
+ if (ptr == tgt)
+ ptr = tgt;
+ if (dlist_pop_ptr(ptr_list, ptr))
+ pr_exit(1);
+}
+
#endif // #ifdef DEBUG_PRMALLOC
/*
@@ -399,8 +389,8 @@
static uint arenacnt = 0; /* number of allocated arenas */
static uint watermark = ARENA_NB_POOLS; /* number of pools allocated from
the current arena */
-static block *arenalist = NULL; /* list of allocated arenas */
-static block *arenaproto = NULL; /* free space start address in
+static uchar *arenalist = NULL; /* list of allocated arenas */
+static uchar *arenaproto = NULL; /* free space start address in
current arena */
/*
@@ -421,14 +411,14 @@
* The basic blocks are ordered by decreasing execution frequency,
* which minimizes the number of jumps in the most common cases,
* improves branching prediction and instruction scheduling (small
- * block allocations typically result in a couple of instructions).
+ * uchar allocations typically result in a couple of instructions).
* Unless the optimizer reorders everything, being too smart...
*/
void *
_THIS_MALLOC(size_t nbytes)
{
- block *bp;
+ uchar *bp;
poolp pool;
poolp next;
uint size;
@@ -451,11 +441,11 @@
if (pool != pool->nextpool) {
/*
* There is a used pool for this size class.
- * Pick up the head block of its free list.
+ * Pick up the head uchar of its free list.
*/
++pool->ref.count;
bp = pool->freeblock;
- if ((pool->freeblock = *(block **)bp) != NULL) {
+ if ((pool->freeblock = *(uchar**)bp) != NULL) {
#ifdef DEBUG_PRMALLOC
debug_add(bp);
#endif
@@ -467,14 +457,13 @@
*/
if (pool->ref.count < pool->capacity) {
/*
- * There is room for another block
+ * There is room for another uchar
*/
size++;
- size <<= ALIGNMENT_SHIFT; /* block size */
- pool->freeblock = (block *)pool + \
- POOL_OVERHEAD + \
- pool->ref.count * size;
- *(block **)(pool->freeblock) = NULL;
+ size <<= ALIGNMENT_SHIFT; /* uchar size */
+ pool->freeblock = (uchar*)pool + POOL_OVERHEAD +
+ pool->ref.count * size;
+ *(uchar**)(pool->freeblock) = NULL;
#ifdef DEBUG_PRMALLOC
debug_add(bp);
#endif
@@ -520,7 +509,7 @@
* and free list are already initialized.
*/
bp = pool->freeblock;
- pool->freeblock = *(block **)bp;
+ pool->freeblock = *(uchar**)bp;
#ifdef DEBUG_PRMALLOC
debug_add(bp);
#endif
@@ -529,14 +518,14 @@
}
/*
* Initialize the pool header and free list
- * then return the first block.
+ * then return the first uchar.
*/
pool->szidx = size;
size++;
- size <<= ALIGNMENT_SHIFT; /* block size */
- bp = (block *)pool + POOL_OVERHEAD;
+ size <<= ALIGNMENT_SHIFT; /* uchar size */
+ bp = (uchar*)pool + POOL_OVERHEAD;
pool->freeblock = bp + size;
- *(block **)(pool->freeblock) = NULL;
+ *(uchar**)(pool->freeblock) = NULL;
pool->capacity = (POOL_SIZE - POOL_OVERHEAD) / size;
#ifdef DEBUG_PRMALLOC
debug_add(bp);
@@ -544,9 +533,9 @@
UNLOCK();
return (void *)bp;
}
- /*
- * Allocate new pool
- */
+ /*
+ * Allocate new pool
+ */
if (watermark < ARENA_NB_POOLS) {
/* commit malloc(POOL_SIZE) from the current arena */
commit_pool:
@@ -558,9 +547,9 @@
pool->szidx = DUMMY_SIZE_IDX;
goto init_pool;
}
- /*
- * Allocate new arena
- */
+ /*
+ * Allocate new arena
+ */
#ifdef WITH_MEMORY_LIMITS
if (!(arenacnt < MAX_ARENAS)) {
UNLOCK();
@@ -571,7 +560,7 @@
* With malloc, we can't avoid loosing one page address space
* per arena due to the required alignment on page boundaries.
*/
- bp = (block *)_SYSTEM_MALLOC(ARENA_SIZE + SYSTEM_PAGE_SIZE);
+ bp = (uchar*)_SYSTEM_MALLOC(ARENA_SIZE + SYSTEM_PAGE_SIZE);
if (bp == NULL) {
UNLOCK();
goto redirect;
@@ -582,7 +571,7 @@
* word is never used, no matter whether the returned address
* is page-aligned or not, so we safely store a pointer in it.
*/
- *(block **)bp = arenalist;
+ *(uchar**)bp = arenalist;
arenalist = bp;
arenacnt++;
watermark = 0;
@@ -592,7 +581,7 @@
goto commit_pool;
}
- /* The small block allocator ends here. */
+ /* The small uchar allocator ends here. */
redirect:
@@ -638,7 +627,7 @@
#endif
offset = (off_t )p & POOL_SIZE_MASK;
- pool = (poolp )((block *)p - offset);
+ pool = (poolp )((uchar*)p - offset);
if (pool->pooladdr != pool || pool->magic != (uint )POOL_MAGIC) {
_SYSTEM_FREE(p);
return;
@@ -649,11 +638,11 @@
/*
* At this point, the pool is not empty
*/
- if ((*(block **)p = pool->freeblock) == NULL) {
+ if ((*(uchar**)p = pool->freeblock) == NULL) {
/*
* Pool was full
*/
- pool->freeblock = (block *)p;
+ pool->freeblock = (uchar*)p;
--pool->ref.count;
/*
* Frontlink to used pools
@@ -674,7 +663,7 @@
/*
* Pool was not full
*/
- pool->freeblock = (block *)p;
+ pool->freeblock = (uchar*)p;
if (--pool->ref.count != 0) {
UNLOCK();
return;
@@ -702,7 +691,7 @@
void *
_THIS_REALLOC(void *p, size_t nbytes)
{
- block *bp;
+ uchar *bp;
poolp pool;
size_t size;
@@ -716,9 +705,9 @@
LOCK();
/* realloc(p, 0) on big blocks is redirected. */
- pool = (poolp )((block *)p - ((off_t )p & POOL_SIZE_MASK));
+ pool = (poolp )((uchar*)p - ((off_t )p & POOL_SIZE_MASK));
if (pool->pooladdr != pool || pool->magic != (uint )POOL_MAGIC) {
- /* We haven't allocated this block */
+ /* We haven't allocated this uchar */
if (!(nbytes > SMALL_REQUEST_THRESHOLD) && nbytes) {
/* small request */
size = nbytes;
@@ -727,14 +716,14 @@
#ifdef DEBUG_PRMALLOC
debug_del(p);
#endif
- bp = (block *)_SYSTEM_REALLOC(p, nbytes);
+ bp = (uchar*)_SYSTEM_REALLOC(p, nbytes);
#ifdef DEBUG_PRMALLOC
debug_add(bp);
#endif
}
else {
- /* We're in charge of this block */
- size = (pool->szidx + 1) << ALIGNMENT_SHIFT; /* block size */
+ /* We're in charge of this uchar */
+ size = (pool->szidx + 1) << ALIGNMENT_SHIFT; /* uchar size */
if (size >= nbytes) {
/* Don't bother if a smaller size was requested
if_exc_return for realloc(p, 0) == free(p), ret NULL */
@@ -745,12 +734,12 @@
bp = NULL;
}
else
- bp = (block *)p;
+ bp = (uchar*)p;
}
else {
malloc_copy_free:
UNLOCK();
- bp = (block *)_THIS_MALLOC(nbytes);
+ bp = (uchar*)_THIS_MALLOC(nbytes);
if (bp != NULL) {
memcpy(bp, p, size);
_THIS_FREE(p);