summaryrefslogtreecommitdiff
path: root/debian/patches/ihash-as-cache0001-libihash-fix-ill-devised-locp-lookup-interface.patch
blob: bc3309731a9ee0a948ec2d0b11d9e1e5415d4122 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
From 5aa7e263521b934c2e23e7fb795fd9163999219a Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Sat, 21 Nov 2015 16:12:53 +0100
Subject: [PATCH hurd 1/5] libihash: fix ill-devised locp lookup interface

* libihash/ihash.c (hurd_ihash_locp_find): Return both the item and the slot.
* libihash/ihash.h (hurd_ihash_locp_find): Adjust prototype.
(hurd_ihash_locp_value): Remove function.
---
 libihash/ihash.c | 19 +++++++++----------
 libihash/ihash.h | 31 ++++++-------------------------
 2 files changed, 15 insertions(+), 35 deletions(-)

diff --git a/libihash/ihash.c b/libihash/ihash.c
index 87d7abf..8b1ad1f 100644
--- a/libihash/ihash.c
+++ b/libihash/ihash.c
@@ -370,13 +370,9 @@ hurd_ihash_find (hurd_ihash_t ht, hurd_ihash_key_t key)
     }
 }
 
-/* Find the item in the hash table HT with key KEY.  If it is found,
-   return the location of its slot in the hash table.  If it is not
-   found, this function may still return a location.
-
-   This location pointer can always be safely accessed using
-   hurd_ihash_locp_value.  If the lookup is successful,
-   hurd_ihash_locp_value will return the value related to KEY.
+/* Find and return the item in the hash table HT with key KEY, or NULL
+   if it doesn't exist.  If it is not found, this function may still
+   return a location in SLOT.
 
    If the lookup is successful, the returned location can be used with
    hurd_ihash_locp_add to update the item, and with
@@ -387,8 +383,10 @@ hurd_ihash_find (hurd_ihash_t ht, hurd_ihash_key_t key)
 
    Note that returned location is only valid until the next insertion
    or deletion.  */
-hurd_ihash_locp_t
-hurd_ihash_locp_find (hurd_ihash_t ht, hurd_ihash_key_t key)
+hurd_ihash_value_t
+hurd_ihash_locp_find (hurd_ihash_t ht,
+		      hurd_ihash_key_t key,
+		      hurd_ihash_locp_t *slot)
 {
   int idx;
 
@@ -396,7 +394,8 @@ hurd_ihash_locp_find (hurd_ihash_t ht, hurd_ihash_key_t key)
     return NULL;
 
   idx = find_index (ht, key);
-  return &ht->items[idx].value;
+  *slot = &ht->items[idx].value;
+  return index_valid (ht, idx, key) ? ht->items[idx].value : NULL;
 }
 
 
diff --git a/libihash/ihash.h b/libihash/ihash.h
index 1dbc348..fdfc367 100644
--- a/libihash/ihash.h
+++ b/libihash/ihash.h
@@ -218,13 +218,9 @@ error_t hurd_ihash_locp_add (hurd_ihash_t ht, hurd_ihash_locp_t locp,
    if it doesn't exist.  */
 hurd_ihash_value_t hurd_ihash_find (hurd_ihash_t ht, hurd_ihash_key_t key);
 
-/* Find the item in the hash table HT with key KEY.  If it is found,
-   return the location of its slot in the hash table.  If it is not
-   found, this function may still return a location.
-
-   This location pointer can always be safely accessed using
-   hurd_ihash_locp_value.  If the lookup is successful,
-   hurd_ihash_locp_value will return the value related to KEY.
+/* Find and return the item in the hash table HT with key KEY, or NULL
+   if it doesn't exist.  If it is not found, this function may still
+   return a location in SLOT.
 
    If the lookup is successful, the returned location can be used with
    hurd_ihash_locp_add to update the item, and with
@@ -235,24 +231,9 @@ hurd_ihash_value_t hurd_ihash_find (hurd_ihash_t ht, hurd_ihash_key_t key);
 
    Note that returned location is only valid until the next insertion
    or deletion.  */
-hurd_ihash_locp_t hurd_ihash_locp_find (hurd_ihash_t ht,
-                                        hurd_ihash_key_t key);
-
-/* Given an hash table bucket location LOCP, return the value stored
-   there, or NULL if it is empty or LOCP is NULL.  */
-static inline void *
-hurd_ihash_locp_value (hurd_ihash_locp_t locp)
-{
-  struct _hurd_ihash_item *item = (struct _hurd_ihash_item *) locp;
-
-  if (item == NULL)
-    return NULL;
-
-  if (hurd_ihash_value_valid (item->value))
-    return item->value;
-
-  return NULL;
-}
+hurd_ihash_value_t hurd_ihash_locp_find (hurd_ihash_t ht,
+					 hurd_ihash_key_t key,
+					 hurd_ihash_locp_t *slot);
 
 /* Iterate over all elements in the hash table.  You use this macro
    with a block, for example like this:
-- 
2.1.4