apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@locus.apache.org
Subject cvs commit: apr/misc/unix start.c
Date Wed, 29 Nov 2000 00:21:15 GMT
rbb         00/11/28 16:21:15

  Modified:    include  apr_hash.h apr_pools.h
               misc/unix start.c
  Log:
  Make apr_pool_t's use hashes instead of the hacked up datastruct that
  it currently uses.
  Submitted by:	Jon Travis <jtravis@covalent.net>
  Reviewed by:	Ryan Bloom
  
  Revision  Changes    Path
  1.15      +0 -5      apr/include/apr_hash.h
  
  Index: apr_hash.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_hash.h,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- apr_hash.h	2000/10/16 12:32:42	1.14
  +++ apr_hash.h	2000/11/29 00:21:13	1.15
  @@ -82,11 +82,6 @@
   #define APR_HASH_KEY_STRING     (-1)
   
   /*
  - * Abstract type for hash tables.
  - */
  -typedef struct apr_hash_t apr_hash_t;
  -
  -/*
    * Abstract type for scanning hash tables.
    */
   typedef struct apr_hash_index_t apr_hash_index_t;
  
  
  
  1.33      +2 -1      apr/include/apr_pools.h
  
  Index: apr_pools.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_pools.h,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- apr_pools.h	2000/11/26 03:00:02	1.32
  +++ apr_pools.h	2000/11/29 00:21:13	1.33
  @@ -107,6 +107,7 @@
    * @package APR memory allocation
    */
   typedef struct apr_pool_t apr_pool_t;
  +typedef struct apr_hash_t apr_hash_t;
   
   /** The memory allocation structure
    */
  @@ -143,7 +144,7 @@
       int (*apr_abort)(int retcode);
       /** A place to hand user data associated with this pool 
        *  @defvar datastruct *prog_data */
  -    struct datastruct *prog_data;
  +    apr_hash_t *prog_data;
   };
   
   /* pools have nested lifetimes -- sub_pools are destroyed when the
  
  
  
  1.40      +15 -44    apr/misc/unix/start.c
  
  Index: start.c
  ===================================================================
  RCS file: /home/cvs/apr/misc/unix/start.c,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- start.c	2000/11/27 21:32:14	1.39
  +++ start.c	2000/11/29 00:21:14	1.40
  @@ -55,6 +55,7 @@
   #include "misc.h"
   #include "locks.h"
   #include "apr_strings.h"
  +#include "apr_hash.h"
   
   static int initialized=0;
   
  @@ -81,59 +82,29 @@
   }
   
   apr_status_t apr_set_userdata(const void *data, const char *key,
  -                            apr_status_t (*cleanup) (void *),
  -                            apr_pool_t *cont)
  +			      apr_status_t (*cleanup) (void *),
  +			      apr_pool_t *cont)
   {
  -    datastruct *dptr = NULL, *dptr2 = NULL;
  +    int keylen = strlen(key);
   
  -    /* ### replace with an apr_hash_t */
  +    if (!cont->prog_data)
  +        cont->prog_data = apr_make_hash(cont);
   
  -    dptr = cont->prog_data;
  -    while (dptr) {
  -        if (!strcmp(dptr->key, key))
  -            break;
  -        dptr2 = dptr;
  -        dptr = dptr->next;
  -    }
  -    if (dptr == NULL) {
  -        dptr = apr_pcalloc(cont, sizeof(datastruct));
  -        dptr->next = dptr->prev = NULL;
  -        dptr->key = apr_pstrdup(cont, key);
  -        if (dptr2) {
  -            dptr2->next = dptr;
  -            dptr->prev = dptr2;
  -        }
  -        else {
  -            cont->prog_data = dptr;
  -        }
  +    if (apr_hash_get(cont->prog_data, key, keylen) == NULL){
  +        char *new_key = apr_pstrdup(cont, key);
  +        apr_hash_set(cont->prog_data, new_key, keylen, data);
  +    } 
  +    else {
  +        apr_hash_set(cont->prog_data, key, keylen, data);
       }
  -    dptr->data = data;
  -    apr_register_cleanup(cont, dptr->data, cleanup, cleanup);
  +
  +    apr_register_cleanup(cont, data, cleanup, cleanup);
       return APR_SUCCESS;
   }
   
   apr_status_t apr_get_userdata(void **data, const char *key, apr_pool_t *cont)
   {
  -    datastruct *dptr = NULL;
  -
  -    /* ### replace with an apr_hash_t */
  -
  -    dptr = cont->prog_data;
  -    while (dptr) {
  -        if (!strcmp(dptr->key, key)) {
  -            break;
  -        }
  -        dptr = dptr->next;
  -    }
  -    if (dptr) {
  -        /* ->data is const because we never change it. however, we want to
  -           cast because the caller may want to change the contents (and
  -           it knows whether it can). */
  -        (*data) = (void *)dptr->data;
  -    }
  -    else {
  -        (*data) = NULL;
  -    }
  +    (*data) = apr_hash_get(cont->prog_data, key, strlen(key));
       return APR_SUCCESS;
   }
   
  
  
  

Mime
View raw message