[Click] PATCH: Compile fix for new kernels

rootkit85 at yahoo.it rootkit85 at yahoo.it
Wed Oct 21 07:07:13 EDT 2009


Hi.

You may know that I'm using click with a kernel 2.6.31. One of the biggest
fix, in term of patch size, was to replace the "swap" occurrences with
something else,
like "swapx", as Linux now has a swap macro:
http://lxr.linux.no/linux+v2.6.31/include/linux/kernel.h#L637
If you apply my patch you help me to keep my patches small, it would be great.
I have other kernel fixes but I have to surround them with #if VERSION
statements yet.

Cheers,
Matteo Croce

diff --git a/elements/ethernet/arptable.cc b/elements/ethernet/arptable.cc
index 3804d6c..58d6bbe 100644
--- a/elements/ethernet/arptable.cc
+++ b/elements/ethernet/arptable.cc
@@ -93,12 +93,12 @@ ARPTable::take_state(Element *e, ErrorHandler *errh)
 	return;
     }

-    _table.swap(arpt->_table);
-    _age.swap(arpt->_age);
+    _table.swapx(arpt->_table);
+    _age.swapx(arpt->_age);
     _entry_count = arpt->_entry_count;
     _packet_count = arpt->_packet_count;
     _drops = arpt->_drops;
-    _alloc.swap(arpt->_alloc);
+    _alloc.swapx(arpt->_alloc);

     arpt->_entry_count = 0;
     arpt->_packet_count = 0;
diff --git a/elements/ip/sortediplookup.cc b/elements/ip/sortediplookup.cc
index 15c01e7..9534683 100644
--- a/elements/ip/sortediplookup.cc
+++ b/elements/ip/sortediplookup.cc
@@ -107,7 +107,7 @@ SortedIPLookup::sort_table()
 	    nt[i] = _t[permute[i]];
 	nt[i].extra = 0x7FFFFFFF;
     }
-    _t.swap(nt);
+    _t.swapx(nt);
     _t.resize(permute.size());
     _zero_route = -1;

diff --git a/elements/tcpudp/iprewriter.cc b/elements/tcpudp/iprewriter.cc
index 206e2a1..9c8f111 100644
--- a/elements/tcpudp/iprewriter.cc
+++ b/elements/tcpudp/iprewriter.cc
@@ -146,8 +146,8 @@ IPRewriter::take_state(Element *e, ErrorHandler *errh)
       errh->message("(out of range mappings will be dropped)");
   }

-  _tcp_map.swap(rw->_tcp_map);
-  _udp_map.swap(rw->_udp_map);
+  _tcp_map.swapx(rw->_tcp_map);
+  _udp_map.swapx(rw->_udp_map);

   // check rw->_all_patterns against our _all_patterns
   Vector<Pattern *> pattern_map;
diff --git a/elements/tcpudp/tcprewriter.cc b/elements/tcpudp/tcprewriter.cc
index 3519c8b..a8fa31d 100644
--- a/elements/tcpudp/tcprewriter.cc
+++ b/elements/tcpudp/tcprewriter.cc
@@ -287,7 +287,7 @@ TCPRewriter::take_state(Element *e, ErrorHandler *errh)
       errh->message("(out of range mappings will be dropped)");
   }

-  _tcp_map.swap(rw->_tcp_map);
+  _tcp_map.swapx(rw->_tcp_map);

   // check rw->_all_patterns against our _all_patterns
   Vector<Pattern *> pattern_map;
diff --git a/include/click/atomic.hh b/include/click/atomic.hh
index 8302e41..d3f83c1 100644
--- a/include/click/atomic.hh
+++ b/include/click/atomic.hh
@@ -65,7 +65,7 @@ class atomic_uint32_t { public:
     inline void operator--();
     inline void operator--(int);

-    inline uint32_t swap(uint32_t x);
+    inline uint32_t swapx(uint32_t x);
     inline uint32_t fetch_and_add(uint32_t delta);
     inline bool dec_and_test();
     inline bool compare_and_swap(uint32_t test_value, uint32_t new_value);
@@ -288,7 +288,7 @@ atomic_uint32_t::operator--(int)
  *
  * Also acts as a memory barrier. */
 inline uint32_t
-atomic_uint32_t::swap(uint32_t x)
+atomic_uint32_t::swapx(uint32_t x)
 {
 #if CLICK_ATOMIC_X86
     asm volatile ("xchgl %0,%1"
diff --git a/include/click/bitvector.hh b/include/click/bitvector.hh
index a569c87..69f7cbb 100644
--- a/include/click/bitvector.hh
+++ b/include/click/bitvector.hh
@@ -194,7 +194,7 @@ class Bitvector { public:


     /** @brief Swap the contents of this bitvector and @a x. */
-    void swap(Bitvector &x);
+    void swapx(Bitvector &x);


     /** @brief Data word type.
@@ -418,7 +418,7 @@ Bitvector::operator-(const Bitvector &o) const

 inline void click_swap(Bitvector &a, Bitvector &b)
 {
-    a.swap(b);
+    a.swapx(b);
 }

 CLICK_ENDDECLS
diff --git a/include/click/dequeue.cc b/include/click/dequeue.cc
index 502824c..4206daf 100644
--- a/include/click/dequeue.cc
+++ b/include/click/dequeue.cc
@@ -117,7 +117,7 @@ DEQueue<T>::resize(int nn, const T &e)
 }

 template <class T> void
-DEQueue<T>::swap(DEQueue<T> &o)
+DEQueue<T>::swapx(DEQueue<T> &o)
 {
   T *l = _l;
   int n = _n;
diff --git a/include/click/dequeue.hh b/include/click/dequeue.hh
index 6bbea0a..23c516f 100644
--- a/include/click/dequeue.hh
+++ b/include/click/dequeue.hh
@@ -79,7 +79,7 @@ public:

   DEQueue<T> &operator=(const DEQueue<T> &);
   DEQueue<T> &assign(int n, const T &e = T());
-  void swap(DEQueue<T> &);
+  void swapx(DEQueue<T> &);

 private:

@@ -145,7 +145,7 @@ DEQueue<T>::pop_back()
 template <typename T>
 inline void click_swap(DEQueue<T> &a, DEQueue<T> &b)
 {
-    a.swap(b);
+    a.swapx(b);
 }

 CLICK_ENDDECLS
diff --git a/include/click/hashallocator.hh b/include/click/hashallocator.hh
index 38d55ce..cc0a186 100644
--- a/include/click/hashallocator.hh
+++ b/include/click/hashallocator.hh
@@ -19,7 +19,7 @@ class HashAllocator { public:
     inline void *allocate();
     inline void deallocate(void *p);

-    void swap(HashAllocator &x);
+    void swapx(HashAllocator &x);

   private:

diff --git a/include/click/hashcontainer.hh b/include/click/hashcontainer.hh
index 51cb804..22050a6 100644
--- a/include/click/hashcontainer.hh
+++ b/include/click/hashcontainer.hh
@@ -252,7 +252,7 @@ class HashContainer { public:
     void clear();

     /** @brief Swaps the contents of *this and @a x. */
-    inline void swap(HashContainer<T, A> &x);
+    inline void swapx(HashContainer<T, A> &x);

     /** @brief Rehash the table, ensuring it contains at least @a n buckets.
      *
diff --git a/include/click/hashmap.cc b/include/click/hashmap.cc
index 20e4f45..acd15f8 100644
--- a/include/click/hashmap.cc
+++ b/include/click/hashmap.cc
@@ -305,7 +305,7 @@ HashMap<K, V>::clear()

 template <class K, class V>
 void
-HashMap<K, V>::swap(HashMap<K, V> &o)
+HashMap<K, V>::swapx(HashMap<K, V> &o)
 {
   Elt **t_elts;
   V t_v;
@@ -667,7 +667,7 @@ HashMap<K, void *>::clear()

 template <class K>
 void
-HashMap<K, void *>::swap(HashMap<K, void *> &o)
+HashMap<K, void *>::swapx(HashMap<K, void *> &o)
 {
   Elt **t_elts;
   void *t_v;
diff --git a/include/click/hashmap.hh b/include/click/hashmap.hh
index c417cec..40b32f3 100644
--- a/include/click/hashmap.hh
+++ b/include/click/hashmap.hh
@@ -59,7 +59,7 @@ class HashMap { public:
   }
   void clear();

-  void swap(HashMap<K, V> &);
+  void swapx(HashMap<K, V> &);

   // iteration
   typedef _HashMap_const_iterator<K, V> const_iterator;
@@ -262,7 +262,7 @@ class HashMap<K, void *> { public:
   }
   void clear();

-  void swap(HashMap<K, void *> &);
+  void swapx(HashMap<K, void *> &);

   // iterators
   typedef _HashMap_const_iterator<K, void *> const_iterator;
@@ -465,7 +465,7 @@ class HashMap<K, T *> : public HashMap<K, void *> { public:
   // bool remove(const K &)		inherited
   // void clear()			inherited

-  void swap(HashMap<K, T *> &o)	{ inherited::swap(o); }
+  void swapx(HashMap<K, T *> &o)	{ inherited::swapx(o); }

   // iteration
   typedef _HashMap_const_iterator<K, T *> const_iterator;
diff --git a/include/click/hashtable.hh b/include/click/hashtable.hh
index 2ffefca..3d4cf5f 100644
--- a/include/click/hashtable.hh
+++ b/include/click/hashtable.hh
@@ -269,7 +269,7 @@ class HashTable<T> {


     /** @brief Swap the contents of this hash table and @a x. */
-    void swap(HashTable<T> &x);
+    void swapx(HashTable<T> &x);


     /** @brief Rehash the table, ensuring it contains at least @a n buckets.
@@ -799,8 +799,8 @@ class HashTable {


     /** @brief Swap the contents of this hash table and @a x. */
-    void swap(HashTable<K, V> &x) {
-	_rep.swap(x._rep);
+    void swapx(HashTable<K, V> &x) {
+	_rep.swapx(x._rep);

 	V odefault_value(_default_value);
 	_default_value = x._default_value;
@@ -1013,10 +1013,10 @@ void HashTable<T>::clear()
 }

 template <typename T>
-void HashTable<T>::swap(HashTable<T> &o)
+void HashTable<T>::swapx(HashTable<T> &o)
 {
-    _rep.swap(o._rep);
-    _alloc.swap(o._alloc);
+    _rep.swapx(o._rep);
+    _alloc.swapx(o._alloc);
 }

 template <typename K, typename V>
@@ -1050,7 +1050,7 @@ inline bool operator!=(const
HashTable_const_iterator<T> &a, const HashTable_con
 template <typename K, typename V>
 inline void click_swap(HashTable<K, V> &a, HashTable<K, V> &b)
 {
-    a.swap(b);
+    a.swapx(b);
 }

 template <typename K, typename V>
@@ -1058,7 +1058,7 @@ inline void clear_by_swap(HashTable<K, V> &x)
 {
     // specialization avoids losing x's default value
     HashTable<K, V> tmp(x.default_value());
-    x.swap(tmp);
+    x.swapx(tmp);
 }

 CLICK_ENDDECLS
diff --git a/include/click/list.hh b/include/click/list.hh
index afc9bbb..97ec0f9 100644
--- a/include/click/list.hh
+++ b/include/click/list.hh
@@ -357,7 +357,7 @@ class List { public:


     /** @brief Exchange list contents with list @a x. */
-    void swap(List<T, member> &x) {
+    void swapx(List<T, member> &x) {
 	T *h = x._head, *t = x._tail;
 	x._head = _head, x._tail = _tail;
 	_head = h, _tail = t;
diff --git a/include/click/straccum.hh b/include/click/straccum.hh
index 37d2ebe..02f12de 100644
--- a/include/click/straccum.hh
+++ b/include/click/straccum.hh
@@ -361,7 +361,7 @@ class StringAccum { public:
     }

     /** @brief Swap this StringAccum's contents with @a x. */
-    void swap(StringAccum &x);
+    void swapx(StringAccum &x);

     // see also operator<< declarations below

@@ -605,7 +605,7 @@ operator<<(StringAccum &sa, const StringAccum &sb)

 inline void click_swap(StringAccum &a, StringAccum &b)
 {
-    a.swap(b);
+    a.swapx(b);
 }

 #undef CLICK_SNPRINTF_ATTR
diff --git a/include/click/sync.hh b/include/click/sync.hh
index e327623..9ab1c3c 100644
--- a/include/click/sync.hh
+++ b/include/click/sync.hh
@@ -101,7 +101,7 @@ Spinlock::acquire()
 #if CLICK_MULTITHREAD_SPINLOCK
     click_processor_t my_cpu = click_get_processor();
     if (_owner != my_cpu) {
-	while (_lock.swap(1) != 0)
+	while (_lock.swapx(1) != 0)
 	    while (_lock != 0)
 		asm volatile ("" : : : "memory");
 	_owner = my_cpu;
@@ -122,7 +122,7 @@ Spinlock::attempt()
 #if CLICK_MULTITHREAD_SPINLOCK
     click_processor_t my_cpu = click_get_processor();
     if (_owner != my_cpu) {
-	if (_lock.swap(1) != 0) {
+	if (_lock.swapx(1) != 0) {
 	    click_put_processor();
 	    return false;
 	}
diff --git a/include/click/vector.cc b/include/click/vector.cc
index 1d77cb3..4072cdc 100644
--- a/include/click/vector.cc
+++ b/include/click/vector.cc
@@ -164,7 +164,7 @@ Vector<T>::resize(size_type nn, const T &e)
 }

 template <class T> void
-Vector<T>::swap(Vector<T> &x)
+Vector<T>::swapx(Vector<T> &x)
 {
     T *l = _l;
     _l = x._l;
diff --git a/include/click/vector.hh b/include/click/vector.hh
index a040af9..e3c6eed 100644
--- a/include/click/vector.hh
+++ b/include/click/vector.hh
@@ -76,7 +76,7 @@ class Vector { public:
   iterator insert(iterator, const T&);
   inline iterator erase(iterator);
   iterator erase(iterator, iterator);
-  void swap(Vector<T> &);
+  void swapx(Vector<T> &);
   void clear()				{ erase(begin(), end()); }

  private:
@@ -134,7 +134,7 @@ Vector<T>::pop_front()
 template <typename T>
 inline void click_swap(Vector<T> &a, Vector<T> &b)
 {
-    a.swap(b);
+    a.swapx(b);
 }


@@ -200,7 +200,7 @@ class Vector<void*> { public:
   iterator insert(iterator, void*);
   inline iterator erase(iterator);
   iterator erase(iterator, iterator);
-  void swap(Vector<void*> &);
+  void swapx(Vector<void*> &);
   void clear()				{ _n = 0; }

  private:
@@ -315,7 +315,7 @@ class Vector<T*>: private Vector<void*> {
   iterator insert(iterator i, T* e) { return
(iterator)Base::insert((void**)i, (void*)e); }
   iterator erase(iterator i)	{ return (iterator)Base::erase((void**)i); }
   iterator erase(iterator i, iterator j) { return
(iterator)Base::erase((void**)i, (void**)j); }
-  void swap(Vector<T *> &o)	{ Base::swap(o); }
+  void swapx(Vector<T *> &o)	{ Base::swapx(o); }
   void clear()			{ Base::clear(); }

 };
diff --git a/lib/bitvector.cc b/lib/bitvector.cc
index 3f9ab6d..1b4c58b 100644
--- a/lib/bitvector.cc
+++ b/lib/bitvector.cc
@@ -218,7 +218,7 @@ Bitvector::nonzero_intersection(const Bitvector &o) const
 }

 void
-Bitvector::swap(Bitvector &x)
+Bitvector::swapx(Bitvector &x)
 {
     uint32_t u = _f0;
     _f0 = x._f0;
diff --git a/lib/confparse.cc b/lib/confparse.cc
index 6ea6812..38518f6 100644
--- a/lib/confparse.cc
+++ b/lib/confparse.cc
@@ -2119,7 +2119,7 @@ cp_ip_address_list(const String &str,
Vector<IPAddress> *result  CP_CONTEXT)
 	cp_errno = CPE_MEMORY;
 	return false;
     }
-    result->swap(build);
+    result->swapx(build);
     return true;
 }

diff --git a/lib/hashallocator.cc b/lib/hashallocator.cc
index 123e81c..0e2c30e 100644
--- a/lib/hashallocator.cc
+++ b/lib/hashallocator.cc
@@ -72,7 +72,7 @@ void *HashAllocator::hard_allocate()
 	return 0;
 }

-void HashAllocator::swap(HashAllocator &x)
+void HashAllocator::swapx(HashAllocator &x)
 {
     size_t xsize = _size;
     _size = x._size;
diff --git a/tools/click-align/click-align.cc b/tools/click-align/click-align.cc
index 3994d51..108305b 100644
--- a/tools/click-align/click-align.cc
+++ b/tools/click-align/click-align.cc
@@ -166,7 +166,7 @@ RouterAlign::have_input()
   for (int i = 0; i < nialign && !changed; i++)
     if (new_ialign[i] != _ialign[i])
       changed = true;
-  _ialign.swap(new_ialign);
+  _ialign.swapx(new_ialign);
   return changed;
 }

@@ -207,7 +207,7 @@ RouterAlign::want_output()
       /* fprintf(stderr, "%s[%d] %s <- %s\n",
_router->ename(oindex_eindex(i)).c_str(), oindex_port(i),
new_oalign[i].s().c_str(), _oalign[i].s().c_str()); */
       changed = true;
     }
-  _oalign.swap(new_oalign);
+  _oalign.swapx(new_oalign);
   return changed;
 }

diff --git a/tools/click-devirtualize/signature.cc
b/tools/click-devirtualize/signature.cc
index b76c46a..e6f2e0b 100644
--- a/tools/click-devirtualize/signature.cc
+++ b/tools/click-devirtualize/signature.cc
@@ -88,7 +88,7 @@ Signatures::check_port_numbers(int eid, const ProcessingT &pt)
   // add new node to list
   if (_sigs[old_sigid]._connections.size() == 0) {
     // set new from old
-    _sigs[old_sigid]._connections.swap(new_ports);
+    _sigs[old_sigid]._connections.swapx(new_ports);
     _sigs[old_sigid]._next = -1;
     return;
   }
@@ -108,7 +108,7 @@ Signatures::check_port_numbers(int eid, const
ProcessingT &pt)
   // if not found, append
   _sigs.push_back(SignatureNode(eid));
   SignatureNode &new_node = _sigs.back();
-  new_node._connections.swap(new_ports);
+  new_node._connections.swapx(new_ports);
   _sigid[eid] = _sigs[prev]._next = _sigs.size() - 1;
 }

@@ -144,7 +144,7 @@ Signatures::next_phase(int phase, int eid,
Vector<int> &new_sigid,
   if (_sigs[old_sigid]._phase != phase) {
     // set new from old
     _sigs[old_sigid]._phase = phase;
-    _sigs[old_sigid]._connections.swap(new_connections);
+    _sigs[old_sigid]._connections.swapx(new_connections);
     _sigs[old_sigid]._next = -1;
     new_sigid[eid] = old_sigid;
     return false;
@@ -166,7 +166,7 @@ Signatures::next_phase(int phase, int eid,
Vector<int> &new_sigid,
   _sigs.push_back(SignatureNode(eid));
   SignatureNode &new_node = _sigs.back();
   new_node._phase = phase;
-  new_node._connections.swap(new_connections);
+  new_node._connections.swapx(new_connections);
   new_sigid[eid] = _sigs[prev]._next = _sigs.size() - 1;
   return true;
 }
@@ -208,6 +208,6 @@ Signatures::analyze(ElementMap &em)
     alive = false;
     for (int i = 0; i < ne; i++)
       alive |= next_phase(phase, i, new_sigid, pt);
-    _sigid.swap(new_sigid);
+    _sigid.swapx(new_sigid);
   }
 }
diff --git a/tools/click-mkmindriver/click-mkmindriver.cc
b/tools/click-mkmindriver/click-mkmindriver.cc
index 85a47f1..ea98bb8 100644
--- a/tools/click-mkmindriver/click-mkmindriver.cc
+++ b/tools/click-mkmindriver/click-mkmindriver.cc
@@ -547,7 +547,7 @@ particular purpose.\n");
     // now, loop over requirements until closure
     while (1) {
 	HashTable<String, int> old_reqs(-1);
-	old_reqs.swap(md._requirements);
+	old_reqs.swapx(md._requirements);

 	for (HashTable<String, int>::iterator iter = old_reqs.begin();
iter.live(); iter++)
 	    md.resolve_requirement(iter.key(), default_emap, errh);
diff --git a/tools/click-xform/click-xform.cc b/tools/click-xform/click-xform.cc
index e2c2a29..6554d16 100644
--- a/tools/click-xform/click-xform.cc
+++ b/tools/click-xform/click-xform.cc
@@ -602,8 +602,8 @@ particular purpose.\n");
 	new_patterns.push_back(replacements[i]);
 	new_replacements.push_back(patterns[i]);
       }
-      patterns.swap(new_patterns);
-      replacements.swap(new_replacements);
+      patterns.swapx(new_patterns);
+      replacements.swapx(new_replacements);
     }

     // flatten patterns
diff --git a/tools/lib/routert.cc b/tools/lib/routert.cc
index c8295ea..74c9940 100644
--- a/tools/lib/routert.cc
+++ b/tools/lib/routert.cc
@@ -1032,7 +1032,7 @@ RouterT::expand_tunnel(Vector<PortT> *port_expansions,
     }

     // save results
-    expanded.swap(store);
+    expanded.swapx(store);
 }

 void


More information about the click mailing list