[pulseaudio-commits] r1262 - in /trunk/src/pulsecore: idxset.c idxset.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Fri Aug 18 12:42:15 PDT 2006


Author: lennart
Date: Fri Aug 18 21:42:14 2006
New Revision: 1262

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1262&root=pulseaudio&view=rev
Log:
cleanup idxset.[ch] a little: define proper types for the hash/compare funcs, do ptr->int/int->ptr conversions with clean macros

Modified:
    trunk/src/pulsecore/idxset.c
    trunk/src/pulsecore/idxset.h

Modified: trunk/src/pulsecore/idxset.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/idxset.c?rev=1262&root=pulseaudio&r1=1261&r2=1262&view=diff
==============================================================================
--- trunk/src/pulsecore/idxset.c (original)
+++ trunk/src/pulsecore/idxset.c Fri Aug 18 21:42:14 2006
@@ -42,8 +42,8 @@
 } idxset_entry;
 
 struct pa_idxset {
-    unsigned (*hash_func) (const void *p);
-    int (*compare_func)(const void *a, const void *b);
+    pa_hash_func_t hash_func;
+    pa_compare_func_t compare_func;
     
     unsigned hash_table_size, n_entries;
     idxset_entry **hash_table, **array, *iterate_list_head, *iterate_list_tail;
@@ -65,21 +65,21 @@
 }
 
 unsigned pa_idxset_trivial_hash_func(const void *p) {
-    return (unsigned) (long) p;
+    return PA_PTR_TO_UINT(p);
 }
 
 int pa_idxset_trivial_compare_func(const void *a, const void *b) {
     return a != b;
 }
 
-pa_idxset* pa_idxset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b)) {
+pa_idxset* pa_idxset_new(pa_hash_func_t hash_func, pa_compare_func_t compare_func) {
     pa_idxset *s;
 
     s = pa_xnew(pa_idxset, 1);
     s->hash_func = hash_func ? hash_func : pa_idxset_trivial_hash_func;
     s->compare_func = compare_func ? compare_func : pa_idxset_trivial_compare_func;
     s->hash_table_size = 127;
-    s->hash_table = pa_xmalloc0(sizeof(idxset_entry*)*s->hash_table_size);
+    s->hash_table = pa_xnew0(idxset_entry*, s->hash_table_size);
     s->array = NULL;
     s->array_size = 0;
     s->index = 0;

Modified: trunk/src/pulsecore/idxset.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/idxset.h?rev=1262&root=pulseaudio&r1=1261&r2=1262&view=diff
==============================================================================
--- trunk/src/pulsecore/idxset.h (original)
+++ trunk/src/pulsecore/idxset.h Fri Aug 18 21:42:14 2006
@@ -41,10 +41,18 @@
 unsigned pa_idxset_string_hash_func(const void *p);
 int pa_idxset_string_compare_func(const void *a, const void *b);
 
+#define PA_PTR_TO_UINT(p) ((unsigned int) (unsigned long) (p))
+#define PA_UINT_TO_PTR(u) ((void*) (unsigned long) (u))
+#define PA_PTR_TO_UINT32(p) ((uint32_t) PA_PTR_TO_UINT(p))
+#define PA_UINT32_TO_PTR(u) PA_UINT_TO_PTR(u)
+
+typedef unsigned (*pa_hash_func_t)(const void *p);
+typedef int (*pa_compare_func_t)(const void *a, const void *b);
+
 typedef struct pa_idxset pa_idxset;
 
 /* Instantiate a new idxset with the specified hash and comparison functions */
-pa_idxset* pa_idxset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b));
+pa_idxset* pa_idxset_new(pa_hash_func_t hash_func, pa_compare_func_t compare_func);
 
 /* Free the idxset. When the idxset is not empty the specified function is called for every entry contained */
 void pa_idxset_free(pa_idxset *s, void (*free_func) (void *p, void *userdata), void *userdata);




More information about the pulseaudio-commits mailing list