Index: ossp-pkg/sio/al.c RCS File: /v/ossp/cvs/ossp-pkg/sio/Attic/al.c,v rcsdiff -q -kk '-r1.5' '-r1.6' -u '/v/ossp/cvs/ossp-pkg/sio/Attic/al.c,v' 2>/dev/null --- al.c 2002/10/14 13:45:47 1.5 +++ al.c 2002/10/14 15:26:04 1.6 @@ -1,6 +1,10 @@ +#include #include #include #include +#ifdef TEST +#include +#endif /****************************************************************************/ @@ -82,16 +86,24 @@ do { \ if (PREV(n,l)) \ NEXT(PREV(n,l),l) = NEXT(n,l); \ + else \ + HEAD(q,l) = NEXT(n,l); \ if (NEXT(n,l)) \ PREV(NEXT(n,l),l) = PREV(n,l); \ + else \ + TAIL(q,l) = PREV(n,l); \ + NEXT(n,l) = NULL; \ + PREV(n,l) = NULL; \ } while (0) #define INSERT(q,l,i,n) \ do { \ if (PREV(i,l)) { \ - PREV(n,l) = PREV(i,l); \ NEXT(PREV(i,l),l) = (n); \ + } else { \ + HEAD(q,l) = (n); \ } \ + PREV(n,l) = PREV(i,l); \ PREV(i,l) = (n); \ NEXT(n,l) = (i); \ } while (0) @@ -342,6 +354,8 @@ static void dispose_chunk(al_t *al, al_chunk_t *alc) { + assert(NEXT(alc,chunks) == NULL && PREV(alc,chunks) == NULL); + --alc->buf->usecount; if (alc->buf->usecount == 0) dispose_buffer(al,alc->buf); @@ -411,20 +425,24 @@ return AL_ERR_EOF; } -#if 0 -#include +#ifdef TEST static void dump(al_t *al) { al_chunk_t *cur; + size_t total; - printf("AL: %x\n", al); + printf("AL: %p\n", al); + total = 0; FOREACH(al,chunks,cur) { - printf(" C: %x (%d @ %x + %d < %d)\n", + printf(" C: %p (%d @ %p + %d < %d (use=%d))\n", cur, cur->buf->size,cur->buf->mem, - cur->begin,cur->end); + cur->begin,cur->end, + cur->buf->usecount); + total += AL_CHUNK_LEN(cur); } + printf("size = %d == %d\n",al->bytes,total); printf("--\n\n"); } #endif @@ -456,7 +474,11 @@ al->m.free = free; al->m.balloc = malloc; /* buffer allocation */ al->m.bfree = free; +#ifdef TEST + al->m.new_buffersize = 42; +#else al->m.new_buffersize = 4096; +#endif al->m.max_freechunks = 500; /* pass object to caller */ @@ -475,6 +497,7 @@ /* free chunks and backing store */ FOREACHD(al,chunks,cur,pred) { + REMOVE(al,chunks,cur); dispose_chunk(al,cur); } @@ -658,11 +681,11 @@ step = len; REMOVE(al, chunks, cur); al->bytes -= step; - if (tal != NULL) { + if (tal == NULL) { + dispose_chunk(al, cur); + } else { ADDTAIL(tal, chunks, cur); tal->bytes += step; - } else { - dispose_chunk(al, cur); } } Index: ossp-pkg/sio/al_test.c RCS File: /v/ossp/cvs/ossp-pkg/sio/Attic/al_test.c,v rcsdiff -q -kk '-r1.3' '-r1.4' -u '/v/ossp/cvs/ossp-pkg/sio/Attic/al_test.c,v' 2>/dev/null --- al_test.c 2002/10/14 13:34:25 1.3 +++ al_test.c 2002/10/14 15:26:04 1.4 @@ -76,7 +76,7 @@ free(buf); } -void checklen(al_t *al) +void checklen(const char *tag, al_t *al) { al_tx_t *tx; al_chunk_t *cur; @@ -93,7 +93,8 @@ total2 = al_bytes(al); if (total != total2) - printf("ERROR: al_bytes(%p): %d != %d\n",al,total,total2); + printf("ERROR: al_bytes(%s=%p): count %d != sum %d\n", + tag,al,total,total2); } int main() @@ -126,9 +127,9 @@ #endif printf("splice result: %d (%s)\n\n",rc,al_error(rc)); - checklen(al); - checklen(al2); - checklen(al3); + checklen("SPLICED",al); + checklen("BUFFER",al2); + checklen("REPLACEMENT",al3); DUMP("SPLICED",al); print("SPLICED", al); @@ -139,8 +140,16 @@ DUMP("REPLACEMENT", al3); print("REPLACEMENT", al3); + printf("free REPLACEMENT\n"); + fflush(stdout); al_destroy(al3); + + printf("free BUFFER\n"); + fflush(stdout); al_destroy(al2); + + printf("free SPLICED\n"); + fflush(stdout); al_destroy(al);