Ticket #11633: 0001-Quench-gcc-s-complaints-about-discarding-constness-i.patch

File 0001-Quench-gcc-s-complaints-about-discarding-constness-i.patch, 3.7 KB (added by _x3j11, 6 years ago)
  • src/or/circuitlist.c

    From f7b850581cd2ee1b419cbcca494a0912a7dc4f27 Mon Sep 17 00:00:00 2001
    From: dana koch <dsk@google.com>
    Date: Tue, 29 Apr 2014 11:02:59 +1000
    Subject: [PATCH] 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 b circuit_max_queued_cell_age(const circuit_t *c, uint32_t now) 
    18211821    age = now - cell->inserted_time;
    18221822
    18231823  if (! CIRCUIT_IS_ORIGIN(c)) {
    1824     const or_circuit_t *orcirc = TO_OR_CIRCUIT((circuit_t*)c);
     1824    const or_circuit_t *orcirc = CONST_TO_OR_CIRCUIT(c);
    18251825    if (NULL != (cell = TOR_SIMPLEQ_FIRST(&orcirc->p_chan_cells.head))) {
    18261826      uint32_t age2 = now - cell->inserted_time;
    18271827      if (age2 > age)
    circuit_max_queued_data_age(const circuit_t *c, uint32_t now) 
    18631863{
    18641864  if (CIRCUIT_IS_ORIGIN(c)) {
    18651865    return circuit_get_streams_max_data_age(
    1866                            TO_ORIGIN_CIRCUIT((circuit_t*)c)->p_streams, now);
     1866        CONST_TO_ORIGIN_CIRCUIT(c)->p_streams, now);
    18671867  } else {
    18681868    return circuit_get_streams_max_data_age(
    1869                            TO_OR_CIRCUIT((circuit_t*)c)->n_streams, now);
     1869        CONST_TO_OR_CIRCUIT(c)->n_streams, now);
    18701870  }
    18711871}
    18721872
    assert_circuit_ok(const circuit_t *c) 
    20572057  tor_assert(c->purpose >= CIRCUIT_PURPOSE_MIN_ &&
    20582058             c->purpose <= CIRCUIT_PURPOSE_MAX_);
    20592059
    2060   {
    2061     /* Having a separate variable for this pleases GCC 4.2 in ways I hope I
    2062      * never understand. -NM. */
    2063     circuit_t *nonconst_circ = (circuit_t*) c;
    2064     if (CIRCUIT_IS_ORIGIN(c))
    2065       origin_circ = TO_ORIGIN_CIRCUIT(nonconst_circ);
    2066     else
    2067       or_circ = TO_OR_CIRCUIT(nonconst_circ);
    2068   }
     2060  if (CIRCUIT_IS_ORIGIN(c))
     2061    origin_circ = CONST_TO_ORIGIN_CIRCUIT(c);
     2062  else
     2063    or_circ = CONST_TO_OR_CIRCUIT(c);
    20692064
    20702065  if (c->n_chan) {
    20712066    tor_assert(!c->n_hop);
  • src/or/or.h

    diff --git a/src/or/or.h b/src/or/or.h
    index 701877c..aeaeb8e 100644
    a b typedef struct or_circuit_rendinfo_s { 
    32313231/** Convert a circuit_t* to a pointer to the enclosing or_circuit_t.  Assert
    32323232 * if the cast is impossible. */
    32333233static or_circuit_t *TO_OR_CIRCUIT(circuit_t *);
     3234static const or_circuit_t *CONST_TO_OR_CIRCUIT(const circuit_t *);
    32343235/** Convert a circuit_t* to a pointer to the enclosing origin_circuit_t.
    32353236 * Assert if the cast is impossible. */
    32363237static origin_circuit_t *TO_ORIGIN_CIRCUIT(circuit_t *);
     3238static const origin_circuit_t *CONST_TO_ORIGIN_CIRCUIT(const circuit_t *);
    32373239
    32383240static INLINE or_circuit_t *TO_OR_CIRCUIT(circuit_t *x)
    32393241{
    32403242  tor_assert(x->magic == OR_CIRCUIT_MAGIC);
    32413243  return DOWNCAST(or_circuit_t, x);
    32423244}
     3245static INLINE const or_circuit_t *CONST_TO_OR_CIRCUIT(const circuit_t *x)
     3246{
     3247  tor_assert(x->magic == OR_CIRCUIT_MAGIC);
     3248  return DOWNCAST(or_circuit_t, x);
     3249}
    32433250static INLINE origin_circuit_t *TO_ORIGIN_CIRCUIT(circuit_t *x)
    32443251{
    32453252  tor_assert(x->magic == ORIGIN_CIRCUIT_MAGIC);
    32463253  return DOWNCAST(origin_circuit_t, x);
    32473254}
     3255static INLINE const origin_circuit_t *CONST_TO_ORIGIN_CIRCUIT(
     3256    const circuit_t *x)
     3257{
     3258  tor_assert(x->magic == ORIGIN_CIRCUIT_MAGIC);
     3259  return DOWNCAST(origin_circuit_t, x);
     3260}
    32483261
    32493262/** Bitfield type: things that we're willing to use invalid routers for. */
    32503263typedef enum invalid_router_usage_t {