File: 0001-Replace-void_fn_t-with-data_fn_t-and-prefix_data_fn_.patch

package info (click to toggle)
pysubnettree 0.36-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 460 kB
  • sloc: cpp: 5,046; ansic: 926; python: 177; makefile: 55; sh: 5
file content (104 lines) | stat: -rw-r--r-- 3,407 bytes parent folder | download
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
From: Tianyu Chen <billchenchina2001@gmail.com>
Date: Tue, 16 Sep 2025 21:02:51 +0800
Subject: Replace void_fn_t with data_fn_t and prefix_data_fn_t

---
 SubnetTree.cc        | 4 ++--
 include/SubnetTree.h | 2 ++
 include/patricia.h   | 9 ++++++---
 patricia.c           | 6 +++---
 4 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/SubnetTree.cc b/SubnetTree.cc
index 1e0b36d..21df9de 100644
--- a/SubnetTree.cc
+++ b/SubnetTree.cc
@@ -101,7 +101,7 @@ inline static bool parse_cidr(const char *cidr, int *family, inx_addr *subnet, u
     return true;
 }
 
-static void free_data(void *data)
+void SubnetTree::PatriciaDeleteFunction(void* data)
 {
     Py_DECREF(static_cast<PyObject*>(data));
 }
@@ -114,7 +114,7 @@ SubnetTree::SubnetTree(bool arg_binary_lookup_mode)
 
 SubnetTree::~SubnetTree()
 {
-    Destroy_Patricia(tree, (void (*)())free_data);
+    Destroy_Patricia(tree, SubnetTree::PatriciaDeleteFunction);
 }
 
 PyObject* SubnetTree::insert(const char *cidr, PyObject* data)
diff --git a/include/SubnetTree.h b/include/SubnetTree.h
index 643837d..eb1a815 100644
--- a/include/SubnetTree.h
+++ b/include/SubnetTree.h
@@ -188,6 +188,8 @@ private:
    PyObject* remove(int family, inx_addr subnet, unsigned short mask);
    PyObject* lookup(int family, inx_addr subnet) const;
 
+   static void PatriciaDeleteFunction(void* data);
+
    patricia_tree_t* tree;
    bool binary_lookup_mode;
 };
diff --git a/include/patricia.h b/include/patricia.h
index dc67226..07527be 100644
--- a/include/patricia.h
+++ b/include/patricia.h
@@ -85,6 +85,9 @@ typedef struct _prefix_t {
     } add;
 } prefix_t;
 
+typedef void (*data_fn_t)(void *);
+typedef void (*prefix_data_fn_t)(prefix_t *, void *);
+
 /* } */
 
 typedef struct _patricia_node_t {
@@ -110,9 +113,9 @@ patricia_node_t * patricia_search_best2 (patricia_tree_t *patricia, prefix_t *pr
 patricia_node_t *patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix);
 void patricia_remove (patricia_tree_t *patricia, patricia_node_t *node);
 patricia_tree_t *New_Patricia (int maxbits);
-void Clear_Patricia (patricia_tree_t *patricia, void_fn_t func);
-void Destroy_Patricia (patricia_tree_t *patricia, void_fn_t func);
-void patricia_process (patricia_tree_t *patricia, void_fn_t func);
+void Clear_Patricia (patricia_tree_t *patricia, data_fn_t func);
+void Destroy_Patricia (patricia_tree_t *patricia, data_fn_t func);
+void patricia_process (patricia_tree_t *patricia, prefix_data_fn_t func);
 
 void Deref_Prefix (prefix_t * prefix);
 
diff --git a/patricia.c b/patricia.c
index 8a9c10a..36486a1 100644
--- a/patricia.c
+++ b/patricia.c
@@ -427,7 +427,7 @@ New_Patricia (int maxbits)
  */
 
 void
-Clear_Patricia (patricia_tree_t *patricia, void_fn_t func)
+Clear_Patricia (patricia_tree_t *patricia, data_fn_t func)
 {
     assert (patricia);
     if (patricia->head) {
@@ -471,7 +471,7 @@ Clear_Patricia (patricia_tree_t *patricia, void_fn_t func)
 
 
 void
-Destroy_Patricia (patricia_tree_t *patricia, void_fn_t func)
+Destroy_Patricia (patricia_tree_t *patricia, data_fn_t func)
 {
     Clear_Patricia (patricia, func);
     Delete (patricia);
@@ -484,7 +484,7 @@ Destroy_Patricia (patricia_tree_t *patricia, void_fn_t func)
  */
 
 void
-patricia_process (patricia_tree_t *patricia, void_fn_t func)
+patricia_process (patricia_tree_t *patricia, prefix_data_fn_t func)
 {
     patricia_node_t *node;
     assert (func);