[tor-commits] [tor/master] Quench gcc's complaints about discarding constness in TO_ORIGIN_CIRCUIT.

nickm at torproject.org nickm at torproject.org
Tue Apr 29 17:23:58 UTC 2014


commit 88679aa53f81ed3b537f214094faa96f4e9a395d
Author: dana koch <dsk at google.com>
Date:   Tue Apr 29 11:02:59 2014 +1000

    Quench gcc's complaints about discarding constness in TO_ORIGIN_CIRCUIT.
    
    This was previously satisfied by using a temporary variable, but there
    are three other instances in circuitlist.c that gcc is now bothered by,
    so now introduce a CONST_TO_ORIGIN_CIRCUIT that takes a const
    circuit_t instead.
---
 src/or/circuitlist.c |   19 +++++++------------
 src/or/or.h          |   13 +++++++++++++
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index c54a954..90fc93f 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -1821,7 +1821,7 @@ circuit_max_queued_cell_age(const circuit_t *c, uint32_t now)
     age = now - cell->inserted_time;
 
   if (! CIRCUIT_IS_ORIGIN(c)) {
-    const or_circuit_t *orcirc = TO_OR_CIRCUIT((circuit_t*)c);
+    const or_circuit_t *orcirc = CONST_TO_OR_CIRCUIT(c);
     if (NULL != (cell = TOR_SIMPLEQ_FIRST(&orcirc->p_chan_cells.head))) {
       uint32_t age2 = now - cell->inserted_time;
       if (age2 > age)
@@ -1863,10 +1863,10 @@ circuit_max_queued_data_age(const circuit_t *c, uint32_t now)
 {
   if (CIRCUIT_IS_ORIGIN(c)) {
     return circuit_get_streams_max_data_age(
-                           TO_ORIGIN_CIRCUIT((circuit_t*)c)->p_streams, now);
+        CONST_TO_ORIGIN_CIRCUIT(c)->p_streams, now);
   } else {
     return circuit_get_streams_max_data_age(
-                           TO_OR_CIRCUIT((circuit_t*)c)->n_streams, now);
+        CONST_TO_OR_CIRCUIT(c)->n_streams, now);
   }
 }
 
@@ -2057,15 +2057,10 @@ assert_circuit_ok(const circuit_t *c)
   tor_assert(c->purpose >= CIRCUIT_PURPOSE_MIN_ &&
              c->purpose <= CIRCUIT_PURPOSE_MAX_);
 
-  {
-    /* Having a separate variable for this pleases GCC 4.2 in ways I hope I
-     * never understand. -NM. */
-    circuit_t *nonconst_circ = (circuit_t*) c;
-    if (CIRCUIT_IS_ORIGIN(c))
-      origin_circ = TO_ORIGIN_CIRCUIT(nonconst_circ);
-    else
-      or_circ = TO_OR_CIRCUIT(nonconst_circ);
-  }
+  if (CIRCUIT_IS_ORIGIN(c))
+    origin_circ = CONST_TO_ORIGIN_CIRCUIT(c);
+  else
+    or_circ = CONST_TO_OR_CIRCUIT(c);
 
   if (c->n_chan) {
     tor_assert(!c->n_hop);
diff --git a/src/or/or.h b/src/or/or.h
index 701877c..aeaeb8e 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -3231,20 +3231,33 @@ typedef struct or_circuit_rendinfo_s {
 /** Convert a circuit_t* to a pointer to the enclosing or_circuit_t.  Assert
  * if the cast is impossible. */
 static or_circuit_t *TO_OR_CIRCUIT(circuit_t *);
+static const or_circuit_t *CONST_TO_OR_CIRCUIT(const circuit_t *);
 /** Convert a circuit_t* to a pointer to the enclosing origin_circuit_t.
  * Assert if the cast is impossible. */
 static origin_circuit_t *TO_ORIGIN_CIRCUIT(circuit_t *);
+static const origin_circuit_t *CONST_TO_ORIGIN_CIRCUIT(const circuit_t *);
 
 static INLINE or_circuit_t *TO_OR_CIRCUIT(circuit_t *x)
 {
   tor_assert(x->magic == OR_CIRCUIT_MAGIC);
   return DOWNCAST(or_circuit_t, x);
 }
+static INLINE const or_circuit_t *CONST_TO_OR_CIRCUIT(const circuit_t *x)
+{
+  tor_assert(x->magic == OR_CIRCUIT_MAGIC);
+  return DOWNCAST(or_circuit_t, x);
+}
 static INLINE origin_circuit_t *TO_ORIGIN_CIRCUIT(circuit_t *x)
 {
   tor_assert(x->magic == ORIGIN_CIRCUIT_MAGIC);
   return DOWNCAST(origin_circuit_t, x);
 }
+static INLINE const origin_circuit_t *CONST_TO_ORIGIN_CIRCUIT(
+    const circuit_t *x)
+{
+  tor_assert(x->magic == ORIGIN_CIRCUIT_MAGIC);
+  return DOWNCAST(origin_circuit_t, x);
+}
 
 /** Bitfield type: things that we're willing to use invalid routers for. */
 typedef enum invalid_router_usage_t {





More information about the tor-commits mailing list