diff options
author | Ben Pfaff <blp@nicira.com> | 2012-07-13 16:00:29 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2012-08-03 13:33:13 -0700 |
commit | ebc56baa41db060b8783051e67b6fcbc148ebd60 (patch) | |
tree | 6eccb5e9fe078abf361ed9bcc2d23f5a3ca79395 /ovsdb | |
parent | e9c048007b113fdf05ca3ccbfa25d01c24f1da43 (diff) |
util: New macro CONST_CAST.
Casts are sometimes necessary. One common reason that they are necessary
is for discarding a "const" qualifier. However, this can impede
maintenance: if the type of the expression being cast changes, then the
presence of the cast can hide a necessary change in the code that does the
cast. Using CONST_CAST, instead of a bare cast, makes these changes
visible.
Inspired by my own work elsewhere:
http://git.savannah.gnu.org/cgit/pspp.git/tree/src/libpspp/cast.h#n80
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'ovsdb')
-rw-r--r-- | ovsdb/ovsdb-server.c | 8 | ||||
-rw-r--r-- | ovsdb/row.c | 6 | ||||
-rw-r--r-- | ovsdb/transaction.c | 12 |
3 files changed, 13 insertions, 13 deletions
diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index 6c68e506..1bf10d9b 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -350,8 +350,8 @@ read_map_string_column(const struct ovsdb_row *row, const char *column_name, union ovsdb_atom *atom_key = NULL, *atom_value = NULL; size_t i; - datum = get_datum((struct ovsdb_row *) row, column_name, OVSDB_TYPE_STRING, - OVSDB_TYPE_STRING, UINT_MAX); + datum = get_datum(CONST_CAST(struct ovsdb_row *, row), column_name, + OVSDB_TYPE_STRING, OVSDB_TYPE_STRING, UINT_MAX); if (!datum) { return NULL; @@ -374,8 +374,8 @@ read_column(const struct ovsdb_row *row, const char *column_name, { const struct ovsdb_datum *datum; - datum = get_datum((struct ovsdb_row *) row, column_name, type, OVSDB_TYPE_VOID, - 1); + datum = get_datum(CONST_CAST(struct ovsdb_row *, row), column_name, type, + OVSDB_TYPE_VOID, 1); return datum && datum->n ? datum->keys : NULL; } diff --git a/ovsdb/row.c b/ovsdb/row.c index 457869b3..450c3274 100644 --- a/ovsdb/row.c +++ b/ovsdb/row.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010, 2011 Nicira, Inc. +/* Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ allocate_row(const struct ovsdb_table *table) + sizeof(struct ovsdb_datum) * n_fields + sizeof(struct hmap_node) * n_indexes); struct ovsdb_row *row = xmalloc(row_size); - row->table = (struct ovsdb_table *) table; + row->table = CONST_CAST(struct ovsdb_table *, table); row->txn_row = NULL; list_init(&row->src_refs); list_init(&row->dst_refs); @@ -347,7 +347,7 @@ ovsdb_row_hash_destroy(struct ovsdb_row_hash *rh, bool destroy_rows) HMAP_FOR_EACH_SAFE (node, next, hmap_node, &rh->rows) { hmap_remove(&rh->rows, &node->hmap_node); if (destroy_rows) { - ovsdb_row_destroy((struct ovsdb_row *) node->row); + ovsdb_row_destroy(CONST_CAST(struct ovsdb_row *, node->row)); } free(node); } diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c index e785e216..cc890ad8 100644 --- a/ovsdb/transaction.c +++ b/ovsdb/transaction.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010, 2011 Nicira, Inc. +/* Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -439,8 +439,8 @@ static void add_weak_ref(struct ovsdb_txn *txn, const struct ovsdb_row *src_, const struct ovsdb_row *dst_) { - struct ovsdb_row *src = (struct ovsdb_row *) src_; - struct ovsdb_row *dst = (struct ovsdb_row *) dst_; + struct ovsdb_row *src = CONST_CAST(struct ovsdb_row *, src_); + struct ovsdb_row *dst = CONST_CAST(struct ovsdb_row *, dst_); struct ovsdb_weak_ref *weak; if (src == dst) { @@ -864,7 +864,7 @@ ovsdb_txn_row_create(struct ovsdb_txn *txn, struct ovsdb_table *table, const struct ovsdb_row *old_, struct ovsdb_row *new) { const struct ovsdb_row *row = old_ ? old_ : new; - struct ovsdb_row *old = (struct ovsdb_row *) old_; + struct ovsdb_row *old = CONST_CAST(struct ovsdb_row *, old_); size_t n_columns = shash_count(&table->schema->columns); struct ovsdb_txn_table *txn_table; struct ovsdb_txn_row *txn_row; @@ -895,7 +895,7 @@ ovsdb_txn_row_create(struct ovsdb_txn *txn, struct ovsdb_table *table, struct ovsdb_row * ovsdb_txn_row_modify(struct ovsdb_txn *txn, const struct ovsdb_row *ro_row_) { - struct ovsdb_row *ro_row = (struct ovsdb_row *) ro_row_; + struct ovsdb_row *ro_row = CONST_CAST(struct ovsdb_row *, ro_row_); if (ro_row->txn_row) { assert(ro_row == ro_row->txn_row->new); @@ -931,7 +931,7 @@ ovsdb_txn_row_insert(struct ovsdb_txn *txn, struct ovsdb_row *row) void ovsdb_txn_row_delete(struct ovsdb_txn *txn, const struct ovsdb_row *row_) { - struct ovsdb_row *row = (struct ovsdb_row *) row_; + struct ovsdb_row *row = CONST_CAST(struct ovsdb_row *, row_); struct ovsdb_table *table = row->table; struct ovsdb_txn_row *txn_row = row->txn_row; |