diff --git a/0151-cleancode-refactor-lwipgz_list.h.patch b/0151-cleancode-refactor-lwipgz_list.h.patch new file mode 100644 index 0000000..093a507 --- /dev/null +++ b/0151-cleancode-refactor-lwipgz_list.h.patch @@ -0,0 +1,162 @@ +From 7b51e2ad967e1ca11443e82d5c5c9f0bce57990b Mon Sep 17 00:00:00 2001 +From: Lemmy Huang +Date: Thu, 11 Jul 2024 11:52:58 +0800 +Subject: [PATCH] cleancode: refactor lwipgz_list.h + + Changed: + list_is_empty -> list_head_empty + list_is_null -> list_node_null + + init_list_node -> list_init_head + init_list_node_null -> list_init_node + + list_add_node -> list_add_node + list_del_node_null -> list_del_node + list_del_node -> __list_del_node + list_for_each_safe -> list_for_each_node + Deprecated: + list_del_node_init + Added: + list_get_node_count + list_entry + +Signed-off-by: Lemmy Huang +--- + src/include/lwipgz_list.h | 94 ++++++++++++++++++++------------------- + 1 file changed, 49 insertions(+), 45 deletions(-) + +diff --git a/src/include/lwipgz_list.h b/src/include/lwipgz_list.h +index 3ee6650..9729210 100644 +--- a/src/include/lwipgz_list.h ++++ b/src/include/lwipgz_list.h +@@ -33,78 +33,82 @@ + #ifndef __LWIPGZ_LIST_H__ + #define __LWIPGZ_LIST_H__ + +-#ifndef NULL +-#ifdef __cplusplus +-#define NULL 0 +-#else +-#define NULL ((void *)0) +-#endif +-#endif +- ++/* double circular linked list */ + struct list_node { + struct list_node *prev; + struct list_node *next; + }; + +-static inline void init_list_node_null(struct list_node *n) ++#ifndef container_of ++#define container_of(ptr, type, member) ({ \ ++ typeof( ((type *)0)->member ) *__mptr = (ptr); \ ++ (type *)((char *)__mptr - offsetof(type, member));}) ++#endif /* container_of */ ++ ++#define list_entry(ptr, type, member) \ ++ container_of(ptr, type, member) ++ ++#define list_for_each_node(node, n, head) \ ++ for (node = (head)->next, n = (node)->next; \ ++ node != (head); \ ++ node = n, n = (node)->next) ++ ++static inline unsigned list_get_node_count(const struct list_node *h) + { +- n->prev = NULL; +- n->next = NULL; ++ const struct list_node *node, *n; ++ unsigned count = 0; ++ list_for_each_node(node, n, h) { ++ ++count; ++ } ++ return count; + } + +-static inline void init_list_node(struct list_node *n) ++static inline int list_node_null(const struct list_node *n) + { +- n->prev = n; +- n->next = n; ++ return (n->prev == NULL) || (n->next == NULL); + } + +-static inline void list_add_node(struct list_node *h, struct list_node *n) ++static inline int list_head_empty(const struct list_node *h) + { +- n->next = h; +- n->prev = h->prev; +- h->prev->next = n; +- h->prev = n; ++ return h == h->next; + } + +-static inline void list_del_node(struct list_node *n) ++static inline void list_init_head(struct list_node *h) + { +- struct list_node *prev = n->prev; +- struct list_node *next = n->next; +- next->prev = prev; +- prev->next = next; ++ h->prev = h; ++ h->next = h; + } + +-static inline void list_del_node_init(struct list_node *n) ++static inline void list_init_node(struct list_node *n) + { +- list_del_node(n); +- init_list_node(n); ++ n->prev = NULL; ++ n->next = NULL; + } + +-static inline void list_del_node_null(struct list_node *n) ++/* add node befor head, means at tail */ ++static inline void list_add_node(struct list_node *n, struct list_node *head) + { +- if ((n->next) && (n->prev)) { +- list_del_node(n); +- } +- init_list_node_null(n); ++ n->next = head; ++ n->prev = head->prev; ++ head->prev->next = n; ++ head->prev = n; + } + +-static inline int list_is_null(const struct list_node *n) ++static inline void __list_del_node(struct list_node *n) + { +- return (n->prev == NULL) && (n->next == NULL); ++ struct list_node *prev = n->prev; ++ struct list_node *next = n->next; ++ next->prev = prev; ++ prev->next = next; + } + +-static inline int list_is_empty(const struct list_node *h) ++static inline void list_del_node(struct list_node *n) + { +- return h == h->next; ++ if (list_node_null(n)) { ++ return; ++ } ++ __list_del_node(n); ++ list_init_node(n); + } + +-#define list_for_each_safe(pos, n, head) \ +- for (pos = (head)->next, n = (pos)->next; pos != (head); pos = n, n = (pos)->next) +- +-#ifndef container_of +-#define container_of(ptr, type, member) ({ \ +- typeof( ((type *)0)->member ) *__mptr = (ptr); \ +- (type *)((char *)__mptr - offsetof(type,member));}) +-#endif /* container_of */ +- + #endif /* __LWIPGZ_LIST_H__ */ +-- +2.33.0 + diff --git a/lwip.spec b/lwip.spec index 0659e98..73c8d5d 100644 --- a/lwip.spec +++ b/lwip.spec @@ -4,7 +4,7 @@ Summary: lwip is a small independent implementation of the TCP/IP protocol suite Name: lwip Version: 2.2.0 -Release: 42 +Release: 43 License: BSD URL: http://savannah.nongnu.org/projects/lwip/ Source0: http://download.savannah.nongnu.org/releases/lwip/%{name}-%{version}.zip @@ -162,6 +162,7 @@ Patch9146: 0147-cleancode-rename-gazelle-files-in-lwip.patch Patch9147: 0148-cleancode-refactor-lwipsock.h.patch Patch9148: 0149-cleancode-refactor-posix-type-and-get_socket.patch Patch9149: 0150-cleancode-refactor-posix_api.patch +Patch9150: 0151-cleancode-refactor-lwipgz_list.h.patch BuildRequires: gcc-c++ dos2unix dpdk-devel @@ -191,6 +192,9 @@ cd %{_builddir}/%{name}-%{version}/src %{_libdir}/liblwip.a %changelog +* Thu Jul 18 2024 LemmyHuang - 2.2.0-43 +- cleancode: refactor lwipgz_list.h + * Thu Jul 18 2024 LemmyHuang - 2.2.0-42 - cleancode: refactor posix_api