You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-cvs@httpd.apache.org by jo...@apache.org on 2003/04/19 11:42:09 UTC

cvs commit: httpd-apreq-2/t Makefile.am env.c tables.c

joes        2003/04/19 02:42:09

  Modified:    .        Makefile.am
               env      Makefile.am
               src      apreq.c apreq_tables.c apreq_tables.h
               t        Makefile.am env.c tables.c
  Log:
  Fixed bugs in apreq_tables exposed by t/tables.c test.
  
  Revision  Changes    Path
  1.5       +1 -1      httpd-apreq-2/Makefile.am
  
  Index: Makefile.am
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/Makefile.am,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Makefile.am	17 Apr 2003 19:19:39 -0000	1.4
  +++ Makefile.am	19 Apr 2003 09:42:08 -0000	1.5
  @@ -1,6 +1,6 @@
   AUTOMAKE_OPTIONS = foreign
   SUBDIRS = src env t
  -EXTRA_DIST = README
  +EXTRA_DIST = INSTALL
   
   test: check
   	t/testall
  
  
  
  1.6       +1 -1      httpd-apreq-2/env/Makefile.am
  
  Index: Makefile.am
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/env/Makefile.am,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Makefile.am	17 Apr 2003 21:23:13 -0000	1.5
  +++ Makefile.am	19 Apr 2003 09:42:08 -0000	1.6
  @@ -1,4 +1,4 @@
  -INCLUDES = -I@APACHE2_INCLUDES@ -I../src
  +INCLUDES = -I../src -I@APACHE2_INCLUDES@
   
   lib_LIBRARIES = libapreq_cgi.a
   noinst_LTLIBRARIES = mod_apreq.la
  
  
  
  1.12      +1 -1      httpd-apreq-2/src/apreq.c
  
  Index: apreq.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- apreq.c	15 Apr 2003 21:47:23 -0000	1.11
  +++ apreq.c	19 Apr 2003 09:42:08 -0000	1.12
  @@ -509,7 +509,7 @@
           memcpy(d,a[0]->data,a[0]->size);
           d += a[0]->size;
   
  -        for (j = 0; j < n ; ++j) {
  +        for (j = 1; j < n ; ++j) {
               memcpy(d, sep, slen);
               d += slen;
               memcpy(d, a[j]->data, a[j]->size);
  
  
  
  1.12      +54 -28    httpd-apreq-2/src/apreq_tables.c
  
  Index: apreq_tables.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_tables.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- apreq_tables.c	18 Apr 2003 20:15:50 -0000	1.11
  +++ apreq_tables.c	19 Apr 2003 09:42:08 -0000	1.12
  @@ -152,16 +152,16 @@
                                 (t)->ghosts--; } while (0)
   
   /* NEVER KILL AN ENTRY THAT'S STILL WITHIN THE FOREST */
  -#define IN_FOREST(t,idx) ( (idx)[o].tree[PARENT] >= 0 || \
  -                           (idx) == t->root[TABLE_HASH((idx)[o].key)] )
  +#define IN_FOREST(t,idx) ( (idx)[o].tree[PARENT] >= 0 || ( !DEAD(idx) && \
  +                           (idx) == t->root[TABLE_HASH((idx)[o].key)] ) )
   
   /********************* (internal) tree operations ********************/
   
   
  -/* MUST ensure n's parent exists before using LR(n) */
  +/* MUST ensure n's parent exists (>=0) before using LR(n) */
   #define LR(n) (  ( (n)[o].tree[PARENT][o].tree[LEFT] == (n) ) ? LEFT : RIGHT  )
   
  -#define PROMOTE(o,r,p)  do rotate(o,r,p,!LR(p)); while (o[p].tree[PARENT] >= 0)
  +#define PROMOTE(o,r,p)  do rotate(o,r,o[p].tree[PARENT],!LR(p)); while (o[p].tree[PARENT] >= 0)
   
   static APR_INLINE void rotate(apreq_table_entry_t *o, 
                                 int *root,
  @@ -427,24 +427,45 @@
                      apreq_table_entry_t *o, int a, 
                      int b, const int n)
   {
  -    if (a < 0)
  -        return b;
  -    else if (b < 0)
  +    int left = b[o+n].tree[LEFT];
  +    int right = b[o+n].tree[RIGHT];
  +    int next;
  +
  +    if (b < 0)
           return a;
  -    else {
  +
  +    for( next = b+n; next[o].tree[NEXT] >= 0; next = next[o].tree[NEXT])
  +        next[o].tree[NEXT] += n;
  +
  +    if (a >= 0) {
  +        int rv = a;
           int parent = a[o].tree[PARENT];
  -        int left = b[o].tree[LEFT] + n;
  -        int right = b[o].tree[RIGHT] + n;
  -        parent[o].tree[LR(a)] = b;
  -        a[o].tree[PARENT] = -1;
  -        b = insert(cmp,o,&a,b,b+o,TREE_PUSH);
  -        if (a != b)
  -            PROMOTE(o,&a,b);
  -        b[o].tree[PARENT] = parent;
  -        b[o].tree[LEFT]  = combine(cmp, o, b[o].tree[LEFT],  left,  n);
  -        b[o].tree[RIGHT] = combine(cmp, o, b[o].tree[RIGHT], right, n);
  -        return b;
  +        if (parent >= 0) {
  +            parent[o].tree[LR(a)] = b+n;
  +            a[o].tree[PARENT] = -1;
  +        }
  +
  +        if (insert(cmp,o,&a,a,b+o+n, TREE_PUSH) < 0)
  +            rv = b + n;
  +
  +        if (b[o+n].tree[PARENT] >= 0)
  +            PROMOTE(o,&a,b+n);
  +
  +        b[o+n].tree[PARENT] = parent;
  +        b[o+n].tree[LEFT]  = combine(cmp, o, b[o+n].tree[LEFT],  left,  n);
  +        b[o+n].tree[RIGHT] = combine(cmp, o, b[o+n].tree[RIGHT], right, n);
  +
  +        return rv;
  +    }
  +    else {
  +        if (b[o+n].tree[PARENT] >= 0)
  +            b[o+n].tree[PARENT] += n;
  +        b[o+n].tree[LEFT]  = combine(cmp, o, -1,  left,  n);
  +        b[o+n].tree[RIGHT] = combine(cmp, o, -1, right, n);
  +
  +        return b + n;
       }
  +
   }
   
   
  @@ -660,7 +681,7 @@
           t->flags &= ~TF_BALANCE;
       }
   }
  -
  +#include <stdio.h>
   APREQ_DECLARE(apr_status_t) apreq_table_normalize(apreq_table_t *t)
   {
       if (t->flags & TF_MERGE) {
  @@ -673,7 +694,8 @@
           
           for (idx = 0; idx < t->a.nelts; ++idx) {
               int j = idx[o].tree[NEXT];
  -
  +/*            printf("GOT HERE(%d:%d:%d): %s\n", j, idx, arr.nelts, idx[o].key);
  + */
               if ( j >= 0 && IN_FOREST(t,idx) ) {
                   apreq_value_t *v;
   
  @@ -884,7 +906,8 @@
           e->key = key;
           e->val = val;
           e->tree[NEXT] = -1;
  -        insert(t->cmp, o,&t->root[TABLE_HASH(key)],idx,e,TREE_PUSH);
  +        insert(t->cmp,(apreq_table_entry_t *)t->a.elts,
  +               &t->root[TABLE_HASH(key)],idx,e,TREE_PUSH);
       }
   }
   
  @@ -959,7 +982,8 @@
           e->key = val->name;
           e->val = val;
           e->tree[NEXT] = -1;
  -        insert(t->cmp,o,&t->root[TABLE_HASH(key)],idx,e,TREE_PUSH);
  +        insert(t->cmp,(apreq_table_entry_t *)t->a.elts,
  +               &t->root[TABLE_HASH(key)],idx,e,TREE_PUSH);
       }
       return val->status;
   }
  @@ -990,7 +1014,7 @@
           elt->key = val->name;
           elt->val = val;
           elt->tree[NEXT] = -1;
  -        insert(t->cmp, o, root, *root, elt,TREE_PUSH);
  +        insert(t->cmp, o, root, *root, elt, TREE_PUSH);
           return APR_SUCCESS;
       }
   
  @@ -1012,9 +1036,10 @@
   {
       const int n = t->a.nelts;
       int idx;
  -    apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
  +    apreq_table_entry_t *o;
   
       apr_array_cat(&t->a, &s->a);
  +    o = (apreq_table_entry_t *)t->a.elts;
   
       LOCK_TABLE(t);
   
  @@ -1132,10 +1157,10 @@
       }
   
       apreq_table_cat(a, b);
  +    a->flags |= TF_MERGE;
   
       if (flags == APR_OVERLAP_TABLES_SET) {
           apreq_value_merge_t *f = a->merge;
  -
           a->merge = collapse;
           s = apreq_table_normalize(a);
           a->merge = f;
  @@ -1149,7 +1174,8 @@
   
   /********************* iterators ********************/
   
  -APREQ_DECLARE(apr_status_t) APR_INLINE apreq_table_fetch(apreq_table_iter_t *ti, int idx)
  +APREQ_DECLARE(apr_status_t) APR_INLINE apreq_table_fetch(
  +                                       apreq_table_iter_t *ti, int idx)
   {
       const apreq_table_t *t = ti->t;
       apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
  @@ -1172,9 +1198,9 @@
           ti->i = idx;
   
       ti->v = idx[o].val;
  -
       return APR_SUCCESS;
   }
  +
   
   APREQ_DECLARE(apr_status_t) APR_INLINE apreq_table_next(apreq_table_iter_t *ti)
   {
  
  
  
  1.10      +3 -2      httpd-apreq-2/src/apreq_tables.h
  
  Index: apreq_tables.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_tables.h,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- apreq_tables.h	18 Apr 2003 20:15:50 -0000	1.9
  +++ apreq_tables.h	19 Apr 2003 09:42:08 -0000	1.10
  @@ -354,12 +354,13 @@
   /** Iterator API */
   
   typedef struct apreq_table_iter_t {
  -    const apreq_table_t *t;
       const apreq_value_t *v;
  +    const apreq_table_t *t;
       int                  i;
   } apreq_table_iter_t;
   
  -APREQ_DECLARE(apr_status_t) APR_INLINE apreq_table_fetch(apreq_table_iter_t *ti, int idx);
  +APREQ_DECLARE(apr_status_t) APR_INLINE apreq_table_fetch(apreq_table_iter_t *ti,
  +                                                         int idx);
   #define apreq_table_first(ti) apreq_table_fetch(ti,0)
   #define apreq_table_last(ti) apreq_table_fetch(ti,apreq_table_nelts((ti)->t)-1)
   
  
  
  
  1.3       +3 -3      httpd-apreq-2/t/Makefile.am
  
  Index: Makefile.am
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/Makefile.am,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Makefile.am	17 Apr 2003 21:08:02 -0000	1.2
  +++ Makefile.am	19 Apr 2003 09:42:08 -0000	1.3
  @@ -1,5 +1,5 @@
  -INCLUDES = -I@APACHE2_INCLUDES@ -I../src
  -LIBS = -L@APACHE2_LIBS@
  +INCLUDES = -I../src -I@APACHE2_INCLUDES@
  +LIBS = -L../src
   
   noinst_LIBRARIES = libapreq_tests.a
   libapreq_tests_a_SOURCES = CuTest.c env.c tables.c
  @@ -7,7 +7,7 @@
   
   check_PROGRAMS = testall
   testall_LDADD =  libapreq_tests.a
  -testall_LINK = @APACHE2_APXS@ -c -p -o testall
  +testall_LINK = @APACHE2_APXS@ -c -p -l apreq -o testall
   
   test:	check
   	./testall
  
  
  
  1.2       +1 -6      httpd-apreq-2/t/env.c
  
  Index: env.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/env.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- env.c	17 Apr 2003 19:39:25 -0000	1.1
  +++ env.c	19 Apr 2003 09:42:08 -0000	1.2
  @@ -137,11 +137,6 @@
   }
   
   
  -APREQ_LOG(env_log)
  -{
  -
  -}
  -
   const struct apreq_env APREQ_ENV =
   {
       env_name,
  @@ -152,6 +147,6 @@
       env_jar,
       env_request,
       env_cfg,
  -    env_log
  +    NULL
    };
   
  
  
  
  1.2       +81 -69    httpd-apreq-2/t/tables.c
  
  Index: tables.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/tables.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- tables.c	17 Apr 2003 19:19:40 -0000	1.1
  +++ tables.c	19 Apr 2003 09:42:08 -0000	1.2
  @@ -52,12 +52,10 @@
    * <http://www.apache.org/>.
    */
   
  -#include "test_apr.h"
  -#include "apr.h"
  -#include "apr_strings.h"
  -#include "apr_general.h"
  -#include "apr_pools.h"
  -#include "apr_tables.h"
  +#include "apreq_env.h"
  +#include "test_apreq.h"
  +#include "apreq.h"
  +#include "apreq_tables.h"
   #if APR_HAVE_STDIO_H
   #include <stdio.h>
   #endif
  @@ -68,11 +66,14 @@
   #include <string.h>
   #endif
   
  -static apr_table_t *t1 = NULL;
  +static apreq_table_t *t1 = NULL;
  +
  +
  +#define V(k,v) apreq_make_value(p,k,strlen(k),v,strlen(v))
   
   static void table_make(CuTest *tc)
   {
  -    t1 = apr_table_make(p, 5);
  +    t1 = apreq_make_table(p, 5);
       CuAssertPtrNotNull(tc, t1);
   }
   
  @@ -80,111 +81,122 @@
   {
       const char *val;
   
  -    apr_table_set(t1, "foo", "bar");
  -    val = apr_table_get(t1, "foo");
  -    CuAssertStrEquals(tc, val, "bar");
  +    apreq_table_set(t1, V("foo","bar"));
  +    val = apreq_table_get(t1,"foo");
  +    CuAssertStrEquals(tc,"bar",val);
  +
   }
   
   static void table_set(CuTest *tc)
   {
       const char *val;
   
  -    apr_table_set(t1, "setkey", "bar");
  -    apr_table_set(t1, "setkey", "2ndtry");
  -    val = apr_table_get(t1, "setkey");
  -    CuAssertStrEquals(tc, val, "2ndtry");
  +    apreq_table_set(t1, V("setkey","bar"));
  +    apreq_table_set(t1, V("setkey","2ndtry"));
  +    val = apreq_table_get(t1,"setkey");
  +    CuAssertStrEquals(tc,"2ndtry",val);
  +
   }
   
   static void table_getnotthere(CuTest *tc)
   {
       const char *val;
   
  -    val = apr_table_get(t1, "keynotthere");
  -    CuAssertPtrEquals(tc, NULL, (void *)val);
  +    val = apreq_table_get(t1, "keynotthere");
  +    CuAssertPtrEquals(tc, NULL,val);
   }
   
   static void table_add(CuTest *tc)
   {
       const char *val;
   
  -    apr_table_add(t1, "addkey", "bar");
  -    apr_table_add(t1, "addkey", "foo");
  -    val = apr_table_get(t1, "addkey");
  -    CuAssertStrEquals(tc, val, "bar");
  +    apreq_table_add(t1, V("addkey", "bar"));
  +    apreq_table_add(t1, V("addkey", "foo"));
  +     val = apreq_table_get(t1, "addkey");
  +    CuAssertStrEquals(tc, "bar", val);
   
   }
   
   static void table_nelts(CuTest *tc)
   {
       const char *val;
  -    apr_table_t *t = apr_table_make(p, 1);
  +    apreq_table_t *t = apreq_table_make(p, 1);
   
  -    apr_table_set(t, "abc", "def");
  -    apr_table_set(t, "def", "abc");
  -    apr_table_set(t, "foo", "zzz");
  -    val = apr_table_get(t, "foo");
  +
  +    apreq_table_set(t, V("abc", "def"));
  +    apreq_table_set(t, V("def", "abc"));
  +    apreq_table_set(t, V("foo", "zzz"));
  +    val = apreq_table_get(t, "foo");
       CuAssertStrEquals(tc, val, "zzz");
  -    val = apr_table_get(t, "abc");
  +
  +    val = apreq_table_get(t, "abc");
       CuAssertStrEquals(tc, val, "def");
  -    val = apr_table_get(t, "def");
  +    val = apreq_table_get(t, "def");
       CuAssertStrEquals(tc, val, "abc");
  -    CuAssertIntEquals(tc, 3, apr_table_elts(t)->nelts);
  +    CuAssertIntEquals(tc, 3, apreq_table_nelts(t));
   }
   
   static void table_clear(CuTest *tc)
   {
  -    apr_table_clear(t1);
  -    CuAssertIntEquals(tc, 0, apr_table_elts(t1)->nelts);
  +    apreq_table_clear(t1);
  +    CuAssertIntEquals(tc, 0, apreq_table_nelts(t1));
   }
   
   static void table_unset(CuTest *tc)
   {
       const char *val;
  -    apr_table_t *t = apr_table_make(p, 1);
  +    apreq_table_t *t;
   
  -    apr_table_set(t, "a", "1");
  -    apr_table_set(t, "b", "2");
  -    apr_table_unset(t, "b");
  -    CuAssertIntEquals(tc, 1, apr_table_elts(t)->nelts);
  -    val = apr_table_get(t, "a");
  +    t = apreq_table_make(p, 1);
  +    apreq_table_set(t, V("a", "1"));
  +    apreq_table_set(t, V("b", "2"));
  +    apreq_table_unset(t, "b");
  +    CuAssertIntEquals(tc, 1, apreq_table_nelts(t));
  +    val = apreq_table_get(t, "a");
       CuAssertStrEquals(tc, val, "1");
  -    val = apr_table_get(t, "b");
  -    CuAssertPtrEquals(tc, (void *)val, (void *)NULL);
  +    val = apreq_table_get(t, "b");
  +    CuAssertPtrEquals(tc, NULL, val);
   }
   
   static void table_overlap(CuTest *tc)
   {
       const char *val;
  -    apr_table_t *t1 = apr_table_make(p, 1);
  -    apr_table_t *t2 = apr_table_make(p, 1);
  -
  -    apr_table_addn(t1, "a", "0");
  -    apr_table_addn(t1, "g", "7");
  -    apr_table_addn(t2, "a", "1");
  -    apr_table_addn(t2, "b", "2");
  -    apr_table_addn(t2, "c", "3");
  -    apr_table_addn(t2, "b", "2.0");
  -    apr_table_addn(t2, "d", "4");
  -    apr_table_addn(t2, "e", "5");
  -    apr_table_addn(t2, "b", "2.");
  -    apr_table_addn(t2, "f", "6");
  -    apr_table_overlap(t1, t2, APR_OVERLAP_TABLES_SET);
  -    
  -    CuAssertIntEquals(tc, apr_table_elts(t1)->nelts, 7);
  -    val = apr_table_get(t1, "a");
  -    CuAssertStrEquals(tc, val, "1");
  -    val = apr_table_get(t1, "b");
  -    CuAssertStrEquals(tc, val, "2");
  -    val = apr_table_get(t1, "c");
  -    CuAssertStrEquals(tc, val, "3");
  -    val = apr_table_get(t1, "d");
  -    CuAssertStrEquals(tc, val, "4");
  -    val = apr_table_get(t1, "e");
  -    CuAssertStrEquals(tc, val, "5");
  -    val = apr_table_get(t1, "f");
  -    CuAssertStrEquals(tc, val, "6");
  -    val = apr_table_get(t1, "g");
  -    CuAssertStrEquals(tc, val, "7");
  +    apreq_table_t *t1 = apreq_table_make(p, 1);
  +    apreq_table_t *t2 = apreq_table_make(p, 1);
  +    apr_status_t s;
  +
  +    apreq_table_add(t1, V("a", "0"));
  +    apreq_table_add(t1, V("g", "7"));
  +
  +    apreq_table_add(t2, V("a", "1"));
  +    apreq_table_add(t2, V("b", "2"));
  +    apreq_table_add(t2, V("c", "3"));
  +    apreq_table_add(t2, V("b", "2.0"));
  +    apreq_table_add(t2, V("d", "4"));
  +    apreq_table_add(t2, V("e", "5"));
  +    apreq_table_add(t2, V("b", "2."));
  +    apreq_table_add(t2, V("f", "6"));
  +
  +    /* APR_OVERLAP_TABLES_SET had funky semantics, so we ignore it here */
  +    s = apreq_table_overlap(t1, t2, APR_OVERLAP_TABLES_MERGE);
  +    CuAssertIntEquals(tc, APR_SUCCESS, s);
  +    CuAssertIntEquals(tc, 7, apreq_table_nelts(t1));
  +    CuAssertIntEquals(tc, 3, apreq_table_ghosts(t1));
  +
  +    val = apreq_table_get(t1, "a");
  +    CuAssertStrEquals(tc, "0, 1",val);
  +    val = apreq_table_get(t1, "b");
  +    CuAssertStrEquals(tc, "2, 2.0, 2.",val);
  +    val = apreq_table_get(t1, "c");
  +    CuAssertStrEquals(tc, "3",val);
  +    val = apreq_table_get(t1, "d");
  +    CuAssertStrEquals(tc, "4",val);
  +    val = apreq_table_get(t1, "e");
  +    CuAssertStrEquals(tc, "5",val);
  +    val = apreq_table_get(t1, "f");
  +    CuAssertStrEquals(tc, "6",val);
  +    val = apreq_table_get(t1, "g");
  +    CuAssertStrEquals(tc, "7",val);
   }
   
   CuSuite *testtable(void)