OSSP CVS Repository

ossp - Check-in [2577]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2577
Date: 2002-Oct-14 17:26:04 (local)
2002-Oct-14 15:26:04 (UTC)
User:mlelstv
Branch:
Comment: INSERT/REMOVE didn't maintain list header test code

PR: Submitted by: Reviewed by: Approved by: Obtained from:

Tickets:
Inspections:
Files:
ossp-pkg/sio/al.c      1.5 -> 1.6     32 inserted, 9 deleted
ossp-pkg/sio/al_test.c      1.3 -> 1.4     14 inserted, 5 deleted

ossp-pkg/sio/al.c 1.5 -> 1.6

--- 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 <assert.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef TEST
+#include <stdio.h>
+#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 <stdio.h>
+#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);
             }
 
         }


ossp-pkg/sio/al_test.c 1.3 -> 1.4

--- 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);
 
 

CVSTrac 2.0.1