/*
- * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc.
+ * Copyright (c) 2008, 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.
static inline unsigned long *
bitmap_unit__(const unsigned long *bitmap, size_t offset)
{
- return (unsigned long *) &bitmap[offset / BITMAP_ULONG_BITS];
+ return CONST_CAST(unsigned long *, &bitmap[offset / BITMAP_ULONG_BITS]);
}
static inline unsigned long
return error;
}
- dpif_port->name = (char *) vport.name;
- dpif_port->type = (char *) netdev_vport_get_netdev_type(&vport);
+ dpif_port->name = CONST_CAST(char *, vport.name);
+ dpif_port->type = CONST_CAST(char *, netdev_vport_get_netdev_type(&vport));
dpif_port->port_no = vport.port_no;
return 0;
}
dpif_linux_flow_get_stats(&reply, stats);
}
if (actionsp) {
- buf->data = (void *) reply.actions;
+ buf->data = CONST_CAST(struct nlattr *, reply.actions);
buf->size = reply.actions_len;
*actionsp = buf;
} else {
memset(upcall, 0, sizeof *upcall);
upcall->type = type;
upcall->packet = buf;
- upcall->packet->data = (void *) nl_attr_get(a[OVS_PACKET_ATTR_PACKET]);
+ upcall->packet->data = CONST_CAST(struct nlattr *,
+ nl_attr_get(a[OVS_PACKET_ATTR_PACKET]));
upcall->packet->size = nl_attr_get_size(a[OVS_PACKET_ATTR_PACKET]);
- upcall->key = (void *) nl_attr_get(a[OVS_PACKET_ATTR_KEY]);
+ upcall->key = CONST_CAST(struct nlattr *,
+ nl_attr_get(a[OVS_PACKET_ATTR_KEY]));
upcall->key_len = nl_attr_get_size(a[OVS_PACKET_ATTR_KEY]);
upcall->userdata = (a[OVS_PACKET_ATTR_USERDATA]
? nl_attr_get_u64(a[OVS_PACKET_ATTR_USERDATA])
const char *
ds_cstr_ro(const struct ds *ds)
{
- return ds_cstr((struct ds *) ds);
+ return ds_cstr(CONST_CAST(struct ds *, ds));
}
/* Returns a null-terminated string representing the current contents of 'ds',
while (node != NULL && node->hash != hash) {
node = node->next;
}
- return (struct hmap_node *) node;
+ return CONST_CAST(struct hmap_node *, node);
}
/* Returns the first node in 'hmap' with the given 'hash', or a null pointer if
/*
- * 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.
json_array(const struct json *json)
{
assert(json->type == JSON_ARRAY);
- return (struct json_array *) &json->u.array;
+ return CONST_CAST(struct json_array *, &json->u.array);
}
struct shash *
json_object(const struct json *json)
{
assert(json->type == JSON_OBJECT);
- return (struct shash *) json->u.object;
+ return CONST_CAST(struct shash *, json->u.object);
}
bool
/*
- * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc.
+ * Copyright (c) 2008, 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.
struct list *
list_front(const struct list *list_)
{
- struct list *list = (struct list *) list_;
+ struct list *list = CONST_CAST(struct list *, list_);
assert(!list_is_empty(list));
return list->next;
struct list *
list_back(const struct list *list_)
{
- struct list *list = (struct list *) list_;
+ struct list *list = CONST_CAST(struct list *, list_);
assert(!list_is_empty(list));
return list->prev;
sll.sll_family = AF_PACKET;
sll.sll_ifindex = ifindex;
- iov.iov_base = (void *) data;
+ iov.iov_base = CONST_CAST(void *, data);
iov.iov_len = size;
msg.msg_name = &sll;
}
/* Instantiate it. */
- load_error = ops->tc_load((struct netdev *) netdev, qdisc);
+ load_error = ops->tc_load(CONST_CAST(struct netdev *, netdev), qdisc);
assert((load_error == 0) == (netdev_dev->tc != NULL));
ofpbuf_delete(qdisc);
int
netdev_get_flags(const struct netdev *netdev_, enum netdev_flags *flagsp)
{
- struct netdev *netdev = (struct netdev *) netdev_;
+ struct netdev *netdev = CONST_CAST(struct netdev *, netdev_);
return do_update_flags(netdev, 0, 0, flagsp, false);
}
struct nl_transaction *transactionp;
struct nl_transaction transaction;
- transaction.request = (struct ofpbuf *) request;
+ transaction.request = CONST_CAST(struct ofpbuf *, request);
transaction.reply = replyp ? ofpbuf_new(1024) : NULL;
transactionp = &transaction;
void
ofpbuf_use_const(struct ofpbuf *b, const void *data, size_t size)
{
- ofpbuf_use__(b, (void *) data, size, OFPBUF_STACK);
+ ofpbuf_use__(b, CONST_CAST(void *, data), size, OFPBUF_STACK);
b->size = size;
}
if (n) {
*n = b->size - initial_size;
}
- return (char *) s;
+ return CONST_CAST(char *, s);
}
ofpbuf_put(b, &byte, 1);
d = &default_data[kt][vt];
if (!d->n) {
d->n = 1;
- d->keys = (union ovsdb_atom *) ovsdb_atom_default(kt);
+ d->keys = CONST_CAST(union ovsdb_atom *, ovsdb_atom_default(kt));
if (vt != OVSDB_TYPE_VOID) {
- d->values = (union ovsdb_atom *) ovsdb_atom_default(vt);
+ d->values = CONST_CAST(union ovsdb_atom *,
+ ovsdb_atom_default(vt));
}
}
return d;
const struct ovsdb_idl_column *column,
struct ovsdb_datum *datum)
{
- struct ovsdb_idl_row *row = (struct ovsdb_idl_row *) row_;
+ struct ovsdb_idl_row *row = CONST_CAST(struct ovsdb_idl_row *, row_);
const struct ovsdb_idl_table_class *class;
size_t column_idx;
ovsdb_idl_txn_verify(const struct ovsdb_idl_row *row_,
const struct ovsdb_idl_column *column)
{
- struct ovsdb_idl_row *row = (struct ovsdb_idl_row *) row_;
+ struct ovsdb_idl_row *row = CONST_CAST(struct ovsdb_idl_row *, row_);
const struct ovsdb_idl_table_class *class;
size_t column_idx;
void
ovsdb_idl_txn_delete(const struct ovsdb_idl_row *row_)
{
- struct ovsdb_idl_row *row = (struct ovsdb_idl_row *) row_;
+ struct ovsdb_idl_row *row = CONST_CAST(struct ovsdb_idl_row *, row_);
if (ovsdb_idl_row_is_synthetic(row)) {
return;
/*
- * 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.
{
struct shash_node *node = xmalloc(sizeof *node);
node->name = name;
- node->data = (void *) data;
+ node->data = CONST_CAST(void *, data);
hmap_insert(&sh->map, &node->node, hash);
return node;
}
return NULL;
} else {
void *old_data = node->data;
- node->data = (void *) data;
+ node->data = CONST_CAST(void *, data);
return old_data;
}
}
/*
- * Copyright (c) 2011 Nicira, Inc.
+ * Copyright (c) 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.
#define SSET_H
#include "hmap.h"
+#include "util.h"
#ifdef __cplusplus
extern "C" {
#define SSET_NODE_FROM_HMAP_NODE(HMAP_NODE) \
CONTAINER_OF(HMAP_NODE, struct sset_node, hmap_node)
#define SSET_NAME_FROM_HMAP_NODE(HMAP_NODE) \
- ((const char *) (SSET_NODE_FROM_HMAP_NODE(HMAP_NODE)->name))
+ (CONST_CAST(const char *, (SSET_NODE_FROM_HMAP_NODE(HMAP_NODE)->name)))
#define SSET_NODE_FROM_NAME(NAME) CONTAINER_OF(NAME, struct sset_node, name)
#define SSET_FIRST(SSET) SSET_NAME_FROM_HMAP_NODE(hmap_first(&(SSET)->map))
#define SSET_NEXT(SSET, NAME) \
/*
- * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc.
+ * Copyright (c) 2008, 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.
{
for (; port < &stp->ports[ARRAY_SIZE(stp->ports)]; port++) {
if (port->state != STP_DISABLED) {
- return (struct stp_port *) port;
+ return CONST_CAST(struct stp_port *, port);
}
}
return NULL;
/*
- * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc.
+ * Copyright (c) 2008, 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.
/* New OpenSSL changed TLSv1_method() to return a "const" pointer, so the
* cast is needed to avoid a warning with those newer versions. */
- method = (SSL_METHOD *) TLSv1_method();
+ method = CONST_CAST(SSL_METHOD *, TLSv1_method());
if (method == NULL) {
VLOG_ERR("TLSv1_method: %s", ERR_error_string(ERR_get_error(), NULL));
return ENOPROTOOPT;
#define BUILD_ASSERT_DECL_GCCONLY(EXPR) ((void) 0)
#endif
+/* Casts 'pointer' to 'type' and issues a compiler warning if the cast changes
+ * anything other than an outermost "const" or "volatile" qualifier.
+ *
+ * The cast to int is present only to suppress an "expression using sizeof
+ * bool" warning from "sparse" (see
+ * http://permalink.gmane.org/gmane.comp.parsers.sparse/2967). */
+#define CONST_CAST(TYPE, POINTER) \
+ ((void) sizeof ((int) ((POINTER) == (TYPE) (POINTER))), \
+ (TYPE) (POINTER))
+
extern const char *program_name;
extern const char *subprogram_name;
vlog_fatal_valist(const struct vlog_module *module_,
const char *message, va_list args)
{
- struct vlog_module *module = (struct vlog_module *) module_;
+ struct vlog_module *module = CONST_CAST(struct vlog_module *, module_);
/* Don't log this message to the console to avoid redundancy with the
* message written by the later ovs_fatal_valist(). */
SHASH_FOR_EACH (node, info) {
struct ofproto_controller_info *cinfo = node->data;
while (cinfo->pairs.n) {
- free((char *) cinfo->pairs.values[--cinfo->pairs.n]);
+ free(CONST_CAST(char *, cinfo->pairs.values[--cinfo->pairs.n]));
}
free(cinfo);
}
break;
case PORT_VLAN_TRUNK:
- trunks = (unsigned long *) s->trunks;
+ trunks = CONST_CAST(unsigned long *, s->trunks);
break;
case PORT_VLAN_NATIVE_UNTAGGED:
bitmap_set1(trunks, vlan);
bitmap_set0(trunks, 0);
} else {
- trunks = (unsigned long *) s->trunks;
+ trunks = CONST_CAST(unsigned long *, s->trunks);
}
break;
fu.hard_timeout = rule->hard_timeout;
fu.table_id = rule->table_id;
fu.cookie = rule->flow_cookie;
- fu.match = (struct cls_rule *) &rule->cr;
+ fu.match = CONST_CAST(struct cls_rule *, &rule->cr);
if (!(flags & NXFMF_ACTIONS)) {
fu.ofpacts = NULL;
fu.ofpacts_len = 0;
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;
{
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;
}
-/* 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.
+ 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);
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);
}
-/* 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.
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) {
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;
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);
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;
/*
- * Copyright (c) 2008, 2009, 2010 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 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.
for (i = 0; i < tc->n_lans; i++) {
struct lan *lan = tc->lans[i];
- free((char *) lan->name);
+ free(CONST_CAST(char *, lan->name));
free(lan);
}
for (i = 0; i < tc->n_bridges; i++) {