Justin Erenkrantz wrote:
--On Wednesday, April 30, 2003 10:24 AM +0200 Gunter Coelle
<[EMAIL PROTECTED]> wrote:
You're right, it would also be the better alternative.
I already did this as a fix in my apps and other hashtable
implementations are mostly using this technique too.
But I'm not sure of the apr-'policy'. AFAIK public structs are
avoided wherever possible in the headers.
Yes, they are avoided, but this might be a case where exposure is
warranted.
Since I'm not exactly clear what was suggested, if you could submit a
patch that does this (and works for you), it'd be appreciated.
-- justin
following patch just moves some declaraions from apr_hash.c to apr_hash.h.
With this I can add a function (apr_hash_first_hi) in my apps,
which takes an address of the iterator as an argument.
This function might also go into apr_hash.c.
- gunter
Index: apr/include/apr_hash.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_hash.h,v
retrieving revision 1.40
diff -u -r1.40 apr_hash.h
--- apr/include/apr_hash.h 5 Mar 2003 21:22:26 -0000 1.40
+++ apr/include/apr_hash.h 2 May 2003 11:01:34 -0000
@@ -93,10 +93,26 @@
*/
typedef struct apr_hash_t apr_hash_t;
+typedef struct apr_hash_entry_t apr_hash_entry_t ;
+
/**
* Abstract type for scanning hash tables.
*/
typedef struct apr_hash_index_t apr_hash_index_t;
+
+/*
+ * Data structure for iterating through a hash table.
+ *
+ * We keep a pointer to the next hash entry here to allow the current
+ * hash entry to be freed or otherwise mangled between calls to
+ * apr_hash_next().
+ */
+struct apr_hash_index_t {
+ apr_hash_t *ht;
+ apr_hash_entry_t *this, *next;
+ unsigned int index;
+};
+
/**
* Create a hash table.
Index: apr/tables/apr_hash.c
===================================================================
RCS file: /home/cvspublic/apr/tables/apr_hash.c,v
retrieving revision 1.35
diff -u -r1.35 apr_hash.c
--- apr/tables/apr_hash.c 13 Jan 2003 18:52:07 -0000 1.35
+++ apr/tables/apr_hash.c 2 May 2003 11:01:34 -0000
@@ -80,7 +80,6 @@
* isn't too bad given that pools have a low allocation overhead.
*/
-typedef struct apr_hash_entry_t apr_hash_entry_t;
struct apr_hash_entry_t {
apr_hash_entry_t *next;
@@ -90,18 +89,6 @@
const void *val;
};
-/*
- * Data structure for iterating through a hash table.
- *
- * We keep a pointer to the next hash entry here to allow the current
- * hash entry to be freed or otherwise mangled between calls to
- * apr_hash_next().
- */
-struct apr_hash_index_t {
- apr_hash_t *ht;
- apr_hash_entry_t *this, *next;
- unsigned int index;
-};
/*
* The size of the array is always a power of two. We use the maximum
apr_hash_index_t* apr_hash_first_hi (apr_hash_index_t* hi, apr_hash_t *ht)
{
hi->ht = ht;
hi->index = 0;
hi->this = NULL;
hi->next = NULL;
return apr_hash_next(hi);
}