You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by dg...@hyperreal.org on 1998/01/24 20:00:28 UTC

cvs commit: apachen/src/modules/standard mod_cgi.c mod_env.c mod_include.c mod_negotiation.c mod_setenvif.c

dgaudet     98/01/24 11:00:28

  Modified:    src      CHANGES
               src/main alloc.c alloc.h
               src/modules/standard mod_cgi.c mod_env.c mod_include.c
                        mod_negotiation.c mod_setenvif.c
  Log:
  Clean up the usage of the table API.  There have always been enough
  routines in alloc.h to treat table as an opaque type, however even we
  got lazy at times and didn't do the right thing.  This change causes
  compile time errors for folks who aren't treating table as an opaque type.
  It was built as part of my table hashing patch, but the hashing has all
  been removed (since it didn't appear to be a win).
  
  Reviewed by:	Paul Sutton
  
  Revision  Changes    Path
  1.595     +8 -0      apachen/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/CHANGES,v
  retrieving revision 1.594
  retrieving revision 1.595
  diff -u -r1.594 -r1.595
  --- CHANGES	1998/01/24 16:27:53	1.594
  +++ CHANGES	1998/01/24 19:00:18	1.595
  @@ -1,5 +1,13 @@
   Changes with Apache 1.3b4
   
  +  *) "typedef array_header table" removed from alloc.h, folks should have
  +     been writing to use table as if it were an opaque type, but even
  +     some standard modules got this wrong.  By changing the definition
  +     to "typedef struct table table" module authors will receive compile
  +     time warnings that they're doing the wrong thing.  This change
  +     facilitates future changes with more sophisticated table
  +     structures.  [Dean Gaudet]
  +
     *) Rename new_connection() to ap__new_connection() to avoid namespace
        collision with LDAP library routines.  The "ap__" prefix means
        it's a private non-API interface, as opposed to "ap_".
  
  
  
  1.68      +75 -43    apachen/src/main/alloc.c
  
  Index: alloc.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/main/alloc.c,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -r1.67 -r1.68
  --- alloc.c	1998/01/07 16:45:59	1.67
  +++ alloc.c	1998/01/24 19:00:21	1.68
  @@ -584,10 +584,8 @@
    * The 'array' functions...
    */
   
  -API_EXPORT(array_header *) make_array(pool *p, int nelts, int elt_size)
  +static void make_array_core(array_header *res, pool *p, int nelts, int elt_size)
   {
  -    array_header *res = (array_header *) palloc(p, sizeof(array_header));
  -
       if (nelts < 1)
   	nelts = 1;		/* Assure sanity if someone asks for
   				 * array of zero elts.
  @@ -599,7 +597,13 @@
       res->elt_size = elt_size;
       res->nelts = 0;		/* No active elements yet... */
       res->nalloc = nelts;	/* ...but this many allocated */
  +}
  +
  +API_EXPORT(array_header *) make_array(pool *p, int nelts, int elt_size)
  +{
  +    array_header *res = (array_header *) palloc(p, sizeof(array_header));
   
  +    make_array_core(res, p, nelts, elt_size);
       return res;
   }
   
  @@ -658,17 +662,21 @@
    * overhead of the full copy only where it is really needed.
    */
   
  -API_EXPORT(array_header *) copy_array_hdr(pool *p, const array_header *arr)
  +static ap_inline void copy_array_hdr_core(array_header *res,
  +    const array_header *arr)
   {
  -    array_header *res = (array_header *) palloc(p, sizeof(array_header));
  -
       res->elts = arr->elts;
  -
  -    res->pool = p;
       res->elt_size = arr->elt_size;
       res->nelts = arr->nelts;
       res->nalloc = arr->nelts;	/* Force overflow on push */
  +}
  +
  +API_EXPORT(array_header *) copy_array_hdr(pool *p, const array_header *arr)
  +{
  +    array_header *res = (array_header *) palloc(p, sizeof(array_header));
   
  +    res->pool = p;
  +    copy_array_hdr_core(res, arr);
       return res;
   }
   
  @@ -690,35 +698,50 @@
    * The "table" functions.
    */
   
  +/* XXX: if you tweak this you should look at is_empty_table() and table_elts()
  + * in alloc.h */
  +struct table {
  +    /* This has to be first to promote backwards compatibility with
  +     * older modules which cast a table * to an array_header *...
  +     * they should use the table_elts() function for most of the
  +     * cases they do this for.
  +     */
  +    array_header a;
  +};
  +
  +
   API_EXPORT(table *) make_table(pool *p, int nelts)
   {
  -    return make_array(p, nelts, sizeof(table_entry));
  +    table *t = palloc(p, sizeof(table));
  +
  +    make_array_core(&t->a, p, nelts, sizeof(table_entry));
  +    return t;
   }
   
   API_EXPORT(table *) copy_table(pool *p, const table *t)
   {
  -    return copy_array(p, t);
  -}
  +    table *new = palloc(p, sizeof(table));
   
  -API_EXPORT(void) clear_table(table *t)
  -{
  -    t->nelts = 0;
  +    make_array_core(&new->a, p, t->a.nalloc, sizeof(table_entry));
  +    memcpy(new->a.elts, t->a.elts, t->a.nelts * sizeof(table_entry));
  +    new->a.nelts = t->a.nelts;
  +    return new;
   }
   
  -API_EXPORT(array_header *) table_elts(table *t)
  +API_EXPORT(void) clear_table(table *t)
   {
  -    return t;
  +    t->a.nelts = 0;
   }
   
   API_EXPORT(char *) table_get(const table *t, const char *key)
   {
  -    table_entry *elts = (table_entry *) t->elts;
  +    table_entry *elts = (table_entry *) t->a.elts;
       int i;
   
       if (key == NULL)
   	return NULL;
   
  -    for (i = 0; i < t->nelts; ++i)
  +    for (i = 0; i < t->a.nelts; ++i)
   	if (!strcasecmp(elts[i].key, key))
   	    return elts[i].val;
   
  @@ -728,22 +751,22 @@
   API_EXPORT(void) table_set(table *t, const char *key, const char *val)
   {
       register int i, j, k;
  -    table_entry *elts = (table_entry *) t->elts;
  +    table_entry *elts = (table_entry *) t->a.elts;
       int done = 0;
   
  -    for (i = 0; i < t->nelts; ) {
  +    for (i = 0; i < t->a.nelts; ) {
   	if (!strcasecmp(elts[i].key, key)) {
   	    if (!done) {
  -		elts[i].val = pstrdup(t->pool, val);
  +		elts[i].val = pstrdup(t->a.pool, val);
   		done = 1;
   		++i;
   	    }
   	    else {		/* delete an extraneous element */
  -		for (j = i, k = i + 1; k < t->nelts; ++j, ++k) {
  +		for (j = i, k = i + 1; k < t->a.nelts; ++j, ++k) {
   		    elts[j].key = elts[k].key;
   		    elts[j].val = elts[k].val;
   		}
  -		--t->nelts;
  +		--t->a.nelts;
   	    }
   	}
   	else {
  @@ -752,18 +775,18 @@
       }
   
       if (!done) {
  -	elts = (table_entry *) push_array(t);
  -	elts->key = pstrdup(t->pool, key);
  -	elts->val = pstrdup(t->pool, val);
  +	elts = (table_entry *) push_array(&t->a);
  +	elts->key = pstrdup(t->a.pool, key);
  +	elts->val = pstrdup(t->a.pool, val);
       }
   }
   
   API_EXPORT(void) table_unset(table *t, const char *key)
   {
       register int i, j, k;
  -    table_entry *elts = (table_entry *) t->elts;
  +    table_entry *elts = (table_entry *) t->a.elts;
   
  -    for (i = 0; i < t->nelts; ) {
  +    for (i = 0; i < t->a.nelts;) {
   	if (!strcasecmp(elts[i].key, key)) {
   
   	    /* found an element to skip over
  @@ -771,11 +794,11 @@
   	     * a contiguous block of memory.  I've chosen one that
   	     * doesn't do a memcpy/bcopy/array_delete, *shrug*...
   	     */
  -	    for (j = i, k = i + 1; k < t->nelts; ++j, ++k) {
  +	    for (j = i, k = i + 1; k < t->a.nelts; ++j, ++k) {
   		elts[j].key = elts[k].key;
   		elts[j].val = elts[k].val;
   	    }
  -	    --t->nelts;
  +	    --t->a.nelts;
   	}
   	else {
   	    ++i;
  @@ -785,32 +808,41 @@
   
   API_EXPORT(void) table_merge(table *t, const char *key, const char *val)
   {
  -    table_entry *elts = (table_entry *) t->elts;
  +    table_entry *elts = (table_entry *) t->a.elts;
       int i;
   
  -    for (i = 0; i < t->nelts; ++i)
  +    for (i = 0; i < t->a.nelts; ++i) {
   	if (!strcasecmp(elts[i].key, key)) {
  -	    elts[i].val = pstrcat(t->pool, elts[i].val, ", ", val, NULL);
  +	    elts[i].val = pstrcat(t->a.pool, elts[i].val, ", ", val, NULL);
   	    return;
   	}
  +    }
   
  -    elts = (table_entry *) push_array(t);
  -    elts->key = pstrdup(t->pool, key);
  -    elts->val = pstrdup(t->pool, val);
  +    elts = (table_entry *) push_array(&t->a);
  +    elts->key = pstrdup(t->a.pool, key);
  +    elts->val = pstrdup(t->a.pool, val);
   }
   
   API_EXPORT(void) table_add(table *t, const char *key, const char *val)
   {
  -    table_entry *elts = (table_entry *) t->elts;
  +    table_entry *elts = (table_entry *) t->a.elts;
   
  -    elts = (table_entry *) push_array(t);
  -    elts->key = pstrdup(t->pool, key);
  -    elts->val = pstrdup(t->pool, val);
  +    elts = (table_entry *) push_array(&t->a);
  +    elts->key = pstrdup(t->a.pool, key);
  +    elts->val = pstrdup(t->a.pool, val);
   }
   
   API_EXPORT(table *) overlay_tables(pool *p, const table *overlay, const table *base)
   {
  -    return append_arrays(p, overlay, base);
  +    table *res;
  +
  +    res = palloc(p, sizeof(table));
  +    /* behave like append_arrays */
  +    res->a.pool = p;
  +    copy_array_hdr_core(&res->a, &overlay->a);
  +    array_cat(&res->a, &base->a);
  +
  +    return res;
   }
   
   /* And now for something completely abstract ...
  @@ -840,7 +872,7 @@
   {
       va_list vp;
       char *argp;
  -    table_entry *elts = (table_entry *) t->elts;
  +    table_entry *elts = (table_entry *) t->a.elts;
       int rv, i;
   
       va_start(vp, t);
  @@ -848,7 +880,7 @@
       argp = va_arg(vp, char *);
   
       do {
  -	for (rv = 1, i = 0; rv && (i < t->nelts); ++i) {
  +	for (rv = 1, i = 0; rv && (i < t->a.nelts); ++i) {
   	    if (elts[i].key && (!argp || !strcasecmp(elts[i].key, argp))) {
   		rv = (*comp) (rec, elts[i].key, elts[i].val);
   	    }
  
  
  
  1.41      +21 -17    apachen/src/main/alloc.h
  
  Index: alloc.h
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/main/alloc.h,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- alloc.h	1998/01/21 19:17:35	1.40
  +++ alloc.h	1998/01/24 19:00:21	1.41
  @@ -109,13 +109,13 @@
    * Common enough to want common support code ...
    */
   
  -     typedef struct {
  -	 pool *pool;
  -	 int elt_size;
  -	 int nelts;
  -	 int nalloc;
  -	 char *elts;
  -     } array_header;
  +typedef struct {
  +    pool *pool;
  +    int elt_size;
  +    int nelts;
  +    int nalloc;
  +    char *elts;
  +} array_header;
   
   API_EXPORT(array_header *) make_array(pool *p, int nelts, int elt_size);
   API_EXPORT(void *) push_array(array_header *);
  @@ -141,14 +141,14 @@
    * currently being used...
    */
   
  -     typedef array_header table;
  +typedef struct table table;
   
  -     typedef struct {
  -	 char *key;		/* maybe NULL in future;
  -				 * check when iterating thru table_elts
  -				 */
  -	 char *val;
  -     } table_entry;
  +typedef struct {
  +    char *key;		/* maybe NULL in future;
  +			 * check when iterating thru table_elts
  +			 */
  +    char *val;
  +} table_entry;
   
   API_EXPORT(table *) make_table(pool *p, int nelts);
   API_EXPORT(table *) copy_table(pool *p, const table *);
  @@ -163,9 +163,13 @@
   
   API_EXPORT(table *) overlay_tables(pool *p, const table *overlay, const table *base);
   
  -API_EXPORT(array_header *) table_elts(table *);
  -
  -#define is_empty_table(t) (((t) == NULL)||((t)->nelts == 0))
  +/* XXX: these know about the definition of struct table in alloc.c.  That
  + * definition is not here because it is supposed to be private, and by not
  + * placing it here we are able to get compile-time diagnostics from modules
  + * written which assume that a table is the same as an array_header. -djg
  + */
  +#define table_elts(t) ((array_header *)(t))
  +#define is_empty_table(t) (((t) == NULL)||(((array_header *)(t))->nelts == 0))
   
   /* routines to remember allocation of other sorts of things...
    * generic interface first.  Note that we want to have two separate
  
  
  
  1.67      +2 -2      apachen/src/modules/standard/mod_cgi.c
  
  Index: mod_cgi.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/modules/standard/mod_cgi.c,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- mod_cgi.c	1998/01/20 15:17:39	1.66
  +++ mod_cgi.c	1998/01/24 19:00:23	1.67
  @@ -190,7 +190,7 @@
   static int log_script(request_rec *r, cgi_server_conf * conf, int ret,
   		  char *dbuf, char *sbuf, BUFF *script_in, BUFF *script_err)
   {
  -    table *hdrs_arr = r->headers_in;
  +    array_header *hdrs_arr = table_elts(r->headers_in);
       table_entry *hdrs = (table_entry *) hdrs_arr->elts;
       char argsbuffer[HUGE_STRING_LEN];
       FILE *f;
  @@ -227,7 +227,7 @@
       }
   
       fputs("%response\n", f);
  -    hdrs_arr = r->err_headers_out;
  +    hdrs_arr = table_elts(r->err_headers_out);
       hdrs = (table_entry *) hdrs_arr->elts;
   
       for (i = 0; i < hdrs_arr->nelts; ++i) {
  
  
  
  1.19      +4 -2      apachen/src/modules/standard/mod_env.c
  
  Index: mod_env.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/modules/standard/mod_env.c,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- mod_env.c	1998/01/07 16:46:48	1.18
  +++ mod_env.c	1998/01/24 19:00:24	1.19
  @@ -124,6 +124,7 @@
   
       table *new_table;
       table_entry *elts;
  +    array_header *arr;
   
       int i;
       const char *uenv, *unset;
  @@ -140,9 +141,10 @@
   
       new_table = copy_table(p, base->vars);
   
  -    elts = (table_entry *) add->vars->elts;
  +    arr = table_elts(add->vars);
  +    elts = (table_entry *)arr->elts;
   
  -    for (i = 0; i < add->vars->nelts; ++i) {
  +    for (i = 0; i < arr->nelts; ++i) {
           table_set(new_table, elts[i].key, elts[i].val);
       }
   
  
  
  
  1.65      +3 -2      apachen/src/modules/standard/mod_include.c
  
  Index: mod_include.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/modules/standard/mod_include.c,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- mod_include.c	1998/01/16 14:23:32	1.64
  +++ mod_include.c	1998/01/24 19:00:24	1.65
  @@ -2030,14 +2030,15 @@
   {
       char tag[MAX_STRING_LEN];
       char *tag_val;
  -    table_entry *elts = (table_entry *) r->subprocess_env->elts;
  +    array_header *arr = table_elts(r->subprocess_env);
  +    table_entry *elts = (table_entry *) arr->elts;
       int i;
   
       if (!(tag_val = get_tag(r->pool, in, tag, sizeof(tag), 1))) {
           return 1;
       }
       else if (!strcmp(tag, "done")) {
  -        for (i = 0; i < r->subprocess_env->nelts; ++i) {
  +        for (i = 0; i < arr->nelts; ++i) {
               rvputs(r, elts[i].key, "=", elts[i].val, "\n", NULL);
           }
           return 0;
  
  
  
  1.64      +1 -1      apachen/src/modules/standard/mod_negotiation.c
  
  Index: mod_negotiation.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/modules/standard/mod_negotiation.c,v
  retrieving revision 1.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- mod_negotiation.c	1998/01/07 16:46:54	1.63
  +++ mod_negotiation.c	1998/01/24 19:00:25	1.64
  @@ -1811,7 +1811,7 @@
       int vary_by_language = 0;
       int vary_by_charset = 0;
       int vary_by_encoding = 0;
  -    array_header *hdrs;
  +    table *hdrs;
   
       /* Put headers into err_headers_out, new send_http_header()
        * outputs both headers_out and err_headers_out */
  
  
  
  1.12      +3 -2      apachen/src/modules/standard/mod_setenvif.c
  
  Index: mod_setenvif.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/modules/standard/mod_setenvif.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- mod_setenvif.c	1998/01/07 16:46:56	1.11
  +++ mod_setenvif.c	1998/01/24 19:00:26	1.12
  @@ -302,9 +302,10 @@
           }
   
           if (!regexec(b->preg, val, 0, NULL, 0)) {
  -            elts = (table_entry *) b->features->elts;
  +	    array_header *arr = table_elts(b->features);
  +            elts = (table_entry *) arr->elts;
   
  -            for (j = 0; j < b->features->nelts; ++j) {
  +            for (j = 0; j < arr->nelts; ++j) {
                   if (!strcmp(elts[j].val, "!")) {
                       table_unset(r->subprocess_env, elts[j].key);
                   }