sorry forgot the first patch ...
Regards.

2015-12-29 13:29 GMT+00:00 Damiano Giorgi <[email protected]>:
> Sono fuori ufficio ed avrò accesso limitato alle mail.
>
> Risponderò al mio rientro in ufficio (l'11 Gennaio).
>
>
>
> Per problemi urgenti potete contattare i miei colleghi scrivendo
> all'indirizzo [email protected]
>
>
>
> ---
>
> Damiano Giorgi
>
> 7Pixel s.r.l.
>
> http://www.7pixel.it
>
> http://www.trovaprezzi.it
>
> http://www.shoppydoo.it
>
>
>
> tel. 02/90.09.06.34
>
> fax. 0382/17.22.025
>
>
>
> [ Ai sensi e per gli effetti della Legge sulla tutela della riservatezza
> personale (DLgs. 196/03 e collegate), questa mail è destinata unicamente
> alle persone sopra indicate e le informazioni in essa contenute sono da
> considerarsi strettamente riservate. E' proibito leggere, copiare, usare o
> diffondere il contenuto della presente mail senza autorizzazione. Se avete
> ricevuto questo messaggio per errore, siete pregati di rispedire la stessa
> al mittente. Grazie ]
From 778ac0a2b1ad4b41fb7c4a62aa3a50dc8683967e Mon Sep 17 00:00:00 2001
From: David Carlier <[email protected]>
Date: Tue, 29 Dec 2015 13:11:56 +0000
Subject: [PATCH 1/5] CLEANUP: ebtree: void pointers arithmetics removal

first patch which applies to the elastic binary tree functions.
---
 ebtree/ebimtree.h | 18 +++++++++++-------
 ebtree/ebmbtree.h | 48 ++++++++++++++++++++++++++++++------------------
 ebtree/ebtree.h   |  8 ++++----
 3 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/ebtree/ebimtree.h b/ebtree/ebimtree.h
index 99e7503..741aa37 100644
--- a/ebtree/ebimtree.h
+++ b/ebtree/ebimtree.h
@@ -47,6 +47,7 @@ __ebim_lookup(struct eb_root *root, const void *x, unsigned int len)
 {
 	struct ebpt_node *node;
 	eb_troot_t *troot;
+	unsigned char *pkey, *px;
 	int pos, side;
 	int node_bit;
 
@@ -58,17 +59,20 @@ __ebim_lookup(struct eb_root *root, const void *x, unsigned int len)
 		goto walk_down;
 
 	pos = 0;
+	px = (unsigned char *)x;
 	while (1) {
 		if (eb_gettag(troot) == EB_LEAF) {
 			node = container_of(eb_untag(troot, EB_LEAF),
 					    struct ebpt_node, node.branches);
-			if (memcmp(node->key + pos, x, len) != 0)
+			pkey = (unsigned char *)node->key;
+			if (memcmp(pkey + pos, px, len) != 0)
 				goto ret_null;
 			else
 				goto ret_node;
 		}
 		node = container_of(eb_untag(troot, EB_NODE),
 				    struct ebpt_node, node.branches);
+		pkey = (unsigned char *)node->key;
 
 		node_bit = node->node.bit;
 		if (node_bit < 0) {
@@ -76,7 +80,7 @@ __ebim_lookup(struct eb_root *root, const void *x, unsigned int len)
 			 * value, and we walk down left, or it's a different
 			 * one and we don't have our key.
 			 */
-			if (memcmp(node->key + pos, x, len) != 0)
+			if (memcmp(pkey + pos, px, len) != 0)
 				goto ret_null;
 			else
 				goto walk_left;
@@ -94,7 +98,7 @@ __ebim_lookup(struct eb_root *root, const void *x, unsigned int len)
 			 * be fine with 2.95 to 4.2.
 			 */
 			while (1) {
-				if (*(unsigned char*)(node->key + pos++) ^ *(unsigned char*)(x++))
+				if (*(pkey + pos++) ^ *(px++))
 					goto ret_null; /* more than one full byte is different */
 				if (--len == 0)
 					goto walk_left; /* return first node if all bytes matched */
@@ -109,8 +113,8 @@ __ebim_lookup(struct eb_root *root, const void *x, unsigned int len)
 		 *   - more than the last bit differs => return NULL
 		 *   - walk down on side = (x[pos] >> node_bit) & 1
 		 */
-		side = *(unsigned char *)x >> node_bit;
-		if (((*(unsigned char*)(node->key + pos) >> node_bit) ^ side) > 1)
+		side = *px >> node_bit;
+		if (((*(pkey + pos) >> node_bit) ^ side) > 1)
 			goto ret_null;
 		side &= 1;
 		troot = node->node.branches.b[side];
@@ -207,7 +211,7 @@ __ebim_insert(struct eb_root *root, struct ebpt_node *new, unsigned int len)
 			 * side. However we don't want to start to compare past the end.
 			 */
 			diff = 0;
-			if (((unsigned)bit >> 3) < len)
+			if (((unsigned int)bit >> 3) < len)
 				diff = cmp_bits(new->key, old->key, bit);
 
 			if (diff < 0) {
@@ -278,7 +282,7 @@ __ebim_insert(struct eb_root *root, struct ebpt_node *new, unsigned int len)
 			 * side. However we don't want to start to compare past the end.
 			 */
 			diff = 0;
-			if (((unsigned)bit >> 3) < len)
+			if (((unsigned int)bit >> 3) < len)
 				diff = cmp_bits(new->key, old->key, bit);
 
 			if (diff < 0) {
diff --git a/ebtree/ebmbtree.h b/ebtree/ebmbtree.h
index 5ab115d..706f1da 100644
--- a/ebtree/ebmbtree.h
+++ b/ebtree/ebmbtree.h
@@ -134,6 +134,7 @@ static forceinline struct ebmb_node *__ebmb_lookup(struct eb_root *root, const v
 {
 	struct ebmb_node *node;
 	eb_troot_t *troot;
+	unsigned char *pkey, *px;
 	int pos, side;
 	int node_bit;
 
@@ -145,17 +146,20 @@ static forceinline struct ebmb_node *__ebmb_lookup(struct eb_root *root, const v
 		goto walk_down;
 
 	pos = 0;
+	px = (unsigned char *)x;
 	while (1) {
 		if (eb_gettag(troot) == EB_LEAF) {
 			node = container_of(eb_untag(troot, EB_LEAF),
 					    struct ebmb_node, node.branches);
-			if (memcmp(node->key + pos, x, len) != 0)
+			pkey = (unsigned char *)node->key;
+			if (memcmp(pkey + pos, px, len) != 0)
 				goto ret_null;
 			else
 				goto ret_node;
 		}
 		node = container_of(eb_untag(troot, EB_NODE),
 				    struct ebmb_node, node.branches);
+		pkey = (unsigned char *)node->key;
 
 		node_bit = node->node.bit;
 		if (node_bit < 0) {
@@ -163,7 +167,7 @@ static forceinline struct ebmb_node *__ebmb_lookup(struct eb_root *root, const v
 			 * value, and we walk down left, or it's a different
 			 * one and we don't have our key.
 			 */
-			if (memcmp(node->key + pos, x, len) != 0)
+			if (memcmp(pkey + pos, px, len) != 0)
 				goto ret_null;
 			else
 				goto walk_left;
@@ -181,7 +185,7 @@ static forceinline struct ebmb_node *__ebmb_lookup(struct eb_root *root, const v
 			 * be fine with 2.95 to 4.2.
 			 */
 			while (1) {
-				if (node->key[pos++] ^ *(unsigned char*)(x++))
+				if (pkey[pos++] ^ *(px++))
 					goto ret_null;  /* more than one full byte is different */
 				if (--len == 0)
 					goto walk_left; /* return first node if all bytes matched */
@@ -196,8 +200,8 @@ static forceinline struct ebmb_node *__ebmb_lookup(struct eb_root *root, const v
 		 *   - more than the last bit differs => return NULL
 		 *   - walk down on side = (x[pos] >> node_bit) & 1
 		 */
-		side = *(unsigned char *)x >> node_bit;
-		if (((node->key[pos] >> node_bit) ^ side) > 1)
+		side = *px >> node_bit;
+		if (((pkey[pos] >> node_bit) ^ side) > 1)
 			goto ret_null;
 		side &= 1;
 		troot = node->node.branches.b[side];
@@ -325,7 +329,7 @@ __ebmb_insert(struct eb_root *root, struct ebmb_node *new, unsigned int len)
 	 * side. However we don't want to start to compare past the end.
 	 */
 	diff = 0;
-	if (((unsigned)bit >> 3) < len)
+	if (((unsigned int)bit >> 3) < len)
 		diff = cmp_bits(new->key, old->key, bit);
 
 	if (diff == 0) {
@@ -381,6 +385,7 @@ static forceinline struct ebmb_node *__ebmb_lookup_longest(struct eb_root *root,
 {
 	struct ebmb_node *node;
 	eb_troot_t *troot, *cover;
+	unsigned char *pkey, *px;
 	int pos, side;
 	int node_bit;
 
@@ -390,17 +395,20 @@ static forceinline struct ebmb_node *__ebmb_lookup_longest(struct eb_root *root,
 
 	cover = NULL;
 	pos = 0;
+	px = (unsigned char *)x;
 	while (1) {
 		if ((eb_gettag(troot) == EB_LEAF)) {
 			node = container_of(eb_untag(troot, EB_LEAF),
 					    struct ebmb_node, node.branches);
-			if (check_bits(x - pos, node->key, pos, node->node.pfx))
+			pkey = (unsigned char *)node->key;
+			if (check_bits(px - pos, pkey, pos, node->node.pfx))
 				goto not_found;
 
 			return node;
 		}
 		node = container_of(eb_untag(troot, EB_NODE),
 				    struct ebmb_node, node.branches);
+		pkey = (unsigned char *)node->key;
 
 		node_bit = node->node.bit;
 		if (node_bit < 0) {
@@ -408,7 +416,7 @@ static forceinline struct ebmb_node *__ebmb_lookup_longest(struct eb_root *root,
 			 * value, and we walk down left, or it's a different
 			 * one and we don't have our key.
 			 */
-			if (check_bits(x - pos, node->key, pos, node->node.pfx))
+			if (check_bits(px - pos, pkey, pos, node->node.pfx))
 				goto not_found;
 
 			troot = node->node.branches.b[EB_LEFT];
@@ -427,8 +435,8 @@ static forceinline struct ebmb_node *__ebmb_lookup_longest(struct eb_root *root,
 			 * be fine with 2.95 to 4.2.
 			 */
 			while (1) {
-				x++; pos++;
-				if (node->key[pos-1] ^ *(unsigned char*)(x-1))
+				px++; pos++;
+				if (pkey[pos-1] ^ *(px-1))
 					goto not_found; /* more than one full byte is different */
 				node_bit += 8;
 				if (node_bit >= 0)
@@ -441,8 +449,8 @@ static forceinline struct ebmb_node *__ebmb_lookup_longest(struct eb_root *root,
 		 *   - more than the last bit differs => data does not match
 		 *   - walk down on side = (x[pos] >> node_bit) & 1
 		 */
-		side = *(unsigned char *)x >> node_bit;
-		if (((node->key[pos] >> node_bit) ^ side) > 1)
+		side = *px >> node_bit;
+		if (((pkey[pos] >> node_bit) ^ side) > 1)
 			goto not_found;
 
 		if (!(node->node.bit & 1)) {
@@ -475,6 +483,7 @@ static forceinline struct ebmb_node *__ebmb_lookup_prefix(struct eb_root *root,
 {
 	struct ebmb_node *node;
 	eb_troot_t *troot;
+	unsigned char *pkey, *px;
 	int pos, side;
 	int node_bit;
 
@@ -483,19 +492,22 @@ static forceinline struct ebmb_node *__ebmb_lookup_prefix(struct eb_root *root,
 		return NULL;
 
 	pos = 0;
+	px = (unsigned char *)x;
 	while (1) {
 		if ((eb_gettag(troot) == EB_LEAF)) {
 			node = container_of(eb_untag(troot, EB_LEAF),
 					    struct ebmb_node, node.branches);
+			pkey = (unsigned char *)node->key;
 			if (node->node.pfx != pfx)
 				return NULL;
-			if (check_bits(x - pos, node->key, pos, node->node.pfx))
+			if (check_bits(px - pos, pkey, pos, node->node.pfx))
 				return NULL;
 			return node;
 		}
 		node = container_of(eb_untag(troot, EB_NODE),
 				    struct ebmb_node, node.branches);
 
+		pkey = (unsigned char *)node->key;
 		node_bit = node->node.bit;
 		if (node_bit < 0) {
 			/* We have a dup tree now. Either it's for the same
@@ -504,7 +516,7 @@ static forceinline struct ebmb_node *__ebmb_lookup_prefix(struct eb_root *root,
 			 */
 			if (node->node.pfx != pfx)
 				return NULL;
-			if (check_bits(x - pos, node->key, pos, node->node.pfx))
+			if (check_bits(px - pos, pkey, pos, node->node.pfx))
 				return NULL;
 
 			troot = node->node.branches.b[EB_LEFT];
@@ -523,8 +535,8 @@ static forceinline struct ebmb_node *__ebmb_lookup_prefix(struct eb_root *root,
 			 * be fine with 2.95 to 4.2.
 			 */
 			while (1) {
-				x++; pos++;
-				if (node->key[pos-1] ^ *(unsigned char*)(x-1))
+				px++; pos++;
+				if (pkey[pos-1] ^ *(px-1))
 					return NULL; /* more than one full byte is different */
 				node_bit += 8;
 				if (node_bit >= 0)
@@ -537,8 +549,8 @@ static forceinline struct ebmb_node *__ebmb_lookup_prefix(struct eb_root *root,
 		 *   - more than the last bit differs => data does not match
 		 *   - walk down on side = (x[pos] >> node_bit) & 1
 		 */
-		side = *(unsigned char *)x >> node_bit;
-		if (((node->key[pos] >> node_bit) ^ side) > 1)
+		side = *px >> node_bit;
+		if (((pkey[pos] >> node_bit) ^ side) > 1)
 			return NULL;
 
 		if (!(node->node.bit & 1)) {
diff --git a/ebtree/ebtree.h b/ebtree/ebtree.h
index 39226e3..a362c31 100644
--- a/ebtree/ebtree.h
+++ b/ebtree/ebtree.h
@@ -318,7 +318,7 @@ static inline int fls64(unsigned long long x)
  * <type> which has its member <name> stored at address <ptr>.
  */
 #ifndef container_of
-#define container_of(ptr, type, name) ((type *)(((void *)(ptr)) - ((long)&((type *)0)->name)))
+#define container_of(ptr, type, name) ((type *)(((unsigned char *)(ptr)) - ((long)&((type *)0)->name)))
 #endif
 
 /* returns a pointer to the structure of type <type> which has its member <name>
@@ -326,7 +326,7 @@ static inline int fls64(unsigned long long x)
  */
 #ifndef container_of_safe
 #define container_of_safe(ptr, type, name) \
-	({ void *__p = (ptr); \
+	({ unsigned char *__p = (ptr); \
 		__p ? (type *)(__p - ((long)&((type *)0)->name)) : (type *)0; \
 	})
 #endif
@@ -410,7 +410,7 @@ struct eb_node {
  */
 static inline eb_troot_t *eb_dotag(const struct eb_root *root, const int tag)
 {
-	return (eb_troot_t *)((void *)root + tag);
+	return (eb_troot_t *)((char *)root + tag);
 }
 
 /* Converts an eb_troot_t pointer pointer to its equivalent eb_root pointer,
@@ -420,7 +420,7 @@ static inline eb_troot_t *eb_dotag(const struct eb_root *root, const int tag)
  */
 static inline struct eb_root *eb_untag(const eb_troot_t *troot, const int tag)
 {
-	return (struct eb_root *)((void *)troot - tag);
+	return (struct eb_root *)((char *)troot - tag);
 }
 
 /* returns the tag associated with an eb_troot_t pointer */
-- 
2.5.0

Reply via email to