Add new function xzalloc(n) as a shorthand for xcalloc(1, n).
authorBen Pfaff <blp@nicira.com>
Mon, 28 Sep 2009 20:56:42 +0000 (13:56 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 4 Nov 2009 22:52:32 +0000 (14:52 -0800)
22 files changed:
SubmittingPatches
extras/ezio/ovs-switchui.c
lib/dhcp-client.c
lib/dpif-netdev.c
lib/learning-switch.c
lib/netdev-linux.c
lib/poll-loop.c
lib/process.c
lib/rconn.c
lib/stp.c
lib/util.c
lib/util.h
ofproto/discovery.c
ofproto/executer.c
ofproto/in-band.c
ofproto/ofproto.c
ofproto/pinsched.c
ofproto/pktbuf.c
ofproto/status.c
tests/test-classifier.c
vswitchd/bridge.c
vswitchd/proc-net-compat.c

index 917cddb..280f11e 100644 (file)
@@ -193,7 +193,7 @@ index 32647ea..00cffbc 100644
      /* Get rid of deleted bridges and add new bridges. */
      svec_sort(&old_br);
 @@ -793,7 +780,7 @@ bridge_create(const char *name)
-     br = xcalloc(1, sizeof *br);
+     br = xzalloc(sizeof *br);
  
      error = dpif_create(name, &br->dpif);
 -    if (error == EEXIST) {
index 0f6640e..e56f83e 100644 (file)
@@ -1247,7 +1247,7 @@ allocate_message(struct message **msgp)
 {
     if (!*msgp) {
         /* Allocate and initialize message. */
-        *msgp = xcalloc(1, sizeof **msgp);
+        *msgp = xzalloc(sizeof **msgp);
         (*msgp)->index = n_messages;
 
         /* Add to list of messages. */
index 4f90781..720cd2f 100644 (file)
@@ -172,7 +172,7 @@ dhclient_create(const char *netdev_name,
         return error;
     }
 
-    cli = xcalloc(1, sizeof *cli);
+    cli = xzalloc(sizeof *cli);
     cli->modify_request = modify_request;
     cli->validate_offer = validate_offer;
     cli->aux = aux;
index 4c25f13..8bd9648 100644 (file)
@@ -219,7 +219,7 @@ create_dp_netdev(const char *name, int dp_idx, struct dpif **dpifp)
     }
 
     /* Create datapath. */
-    dp_netdevs[dp_idx] = dp = xcalloc(1, sizeof *dp);
+    dp_netdevs[dp_idx] = dp = xzalloc(sizeof *dp);
     list_push_back(&dp_netdev_list, &dp->node);
     dp->dp_idx = dp_idx;
     dp->open_cnt = 0;
@@ -788,7 +788,7 @@ add_flow(struct dpif *dpif, struct odp_flow *odp_flow)
     struct dp_netdev_flow *flow;
     int error;
 
-    flow = xcalloc(1, sizeof *flow);
+    flow = xzalloc(sizeof *flow);
     flow->key = odp_flow->key;
     flow->key.reserved = 0;
 
index 73464c6..99d5ee4 100644 (file)
@@ -110,7 +110,7 @@ lswitch_create(struct rconn *rconn, bool learn_macs, int max_idle)
     struct lswitch *sw;
     size_t i;
 
-    sw = xcalloc(1, sizeof *sw);
+    sw = xzalloc(sizeof *sw);
     sw->max_idle = max_idle;
     sw->datapath_id = 0;
     sw->last_features_request = time_now() - 1;
index 7324703..c33405f 100644 (file)
@@ -203,7 +203,7 @@ netdev_linux_open(const char *name, char *suffix, int ethertype,
     int error;
 
     /* Allocate network device. */
-    netdev = xcalloc(1, sizeof *netdev);
+    netdev = xzalloc(sizeof *netdev);
     netdev_init(&netdev->netdev, suffix, &netdev_linux_class);
     netdev->netdev_fd = -1;
     netdev->tap_fd = -1;
index aff2c33..26a17e8 100644 (file)
@@ -253,7 +253,7 @@ poll_cancel(struct poll_waiter *pw)
 static struct poll_waiter *
 new_waiter(int fd, short int events)
 {
-    struct poll_waiter *waiter = xcalloc(1, sizeof *waiter);
+    struct poll_waiter *waiter = xzalloc(sizeof *waiter);
     assert(fd >= 0);
     waiter->fd = fd;
     waiter->events = events;
index 1fe3c12..0c7f424 100644 (file)
@@ -161,7 +161,7 @@ process_register(const char *name, pid_t pid)
 
     assert(sigchld_is_blocked());
 
-    p = xcalloc(1, sizeof *p);
+    p = xzalloc(sizeof *p);
     p->pid = pid;
     slash = strrchr(name, '/');
     p->name = xstrdup(slash ? slash + 1 : name);
index 2cbe43e..b6e958e 100644 (file)
@@ -176,7 +176,7 @@ rconn_new_from_vconn(const char *name, struct vconn *vconn)
 struct rconn *
 rconn_create(int probe_interval, int max_backoff)
 {
-    struct rconn *rc = xcalloc(1, sizeof *rc);
+    struct rconn *rc = xzalloc(sizeof *rc);
 
     rc->state = S_VOID;
     rc->state_entered = time_now();
index 87230bd..cf1b2f9 100644 (file)
--- a/lib/stp.c
+++ b/lib/stp.c
@@ -214,7 +214,7 @@ stp_create(const char *name, stp_identifier bridge_id,
     struct stp *stp;
     struct stp_port *p;
 
-    stp = xcalloc(1, sizeof *stp);
+    stp = xzalloc(sizeof *stp);
     stp->name = xstrdup(name);
     stp->bridge_id = bridge_id;
     if (!(stp->bridge_id >> 48)) {
index f766d59..cecd582 100644 (file)
@@ -42,6 +42,12 @@ xcalloc(size_t count, size_t size)
     return p;
 }
 
+void *
+xzalloc(size_t size)
+{
+    return xcalloc(1, size);
+}
+
 void *
 xmalloc(size_t size) 
 {
index 962bad2..1290d33 100644 (file)
@@ -98,6 +98,7 @@ void ovs_print_version(char *date, char *time,
 void out_of_memory(void) NO_RETURN;
 void *xmalloc(size_t) MALLOC_LIKE;
 void *xcalloc(size_t, size_t) MALLOC_LIKE;
+void *xzalloc(size_t) MALLOC_LIKE;
 void *xrealloc(void *, size_t);
 void *xmemdup(const void *, size_t) MALLOC_LIKE;
 char *xmemdup0(const char *, size_t) MALLOC_LIKE;
index 2868db5..c762506 100644 (file)
@@ -102,7 +102,7 @@ discovery_create(const char *re, bool update_resolv_conf,
     char local_name[IF_NAMESIZE];
     int error;
 
-    d = xcalloc(1, sizeof *d);
+    d = xzalloc(sizeof *d);
 
     /* Controller regular expression. */
     error = discovery_set_accept_controller_re(d, re);
index bc42ccf..cdbe5bd 100644 (file)
@@ -471,7 +471,7 @@ executer_create(const char *command_acl, const char *command_dir,
         return errno;
     }
 
-    e = xcalloc(1, sizeof *e);
+    e = xzalloc(sizeof *e);
     e->command_acl = xstrdup(command_acl);
     e->command_dir = (command_dir
                       ? xstrdup(command_dir)
index 2b362bc..4a2ea83 100644 (file)
@@ -624,7 +624,7 @@ in_band_create(struct ofproto *ofproto, struct dpif *dpif,
         return error;
     }
 
-    in_band = xcalloc(1, sizeof *in_band);
+    in_band = xzalloc(sizeof *in_band);
     in_band->ofproto = ofproto;
     in_band->controller = controller;
     in_band->ss_cat = switch_status_register(ss, "in-band",
index eb8a7a9..c618e3c 100644 (file)
@@ -292,7 +292,7 @@ ofproto_create(const char *datapath, const struct ofhooks *ofhooks, void *aux,
     dpif_recv_purge(dpif);
 
     /* Initialize settings. */
-    p = xcalloc(1, sizeof *p);
+    p = xzalloc(sizeof *p);
     p->fallback_dpid = pick_fallback_dpid();
     p->datapath_id = p->fallback_dpid;
     p->manufacturer = xstrdup("Nicira Networks, Inc.");
@@ -1389,7 +1389,7 @@ rule_create(struct rule *super,
             const union ofp_action *actions, size_t n_actions,
             uint16_t idle_timeout, uint16_t hard_timeout)
 {
-    struct rule *rule = xcalloc(1, sizeof *rule);
+    struct rule *rule = xzalloc(sizeof *rule);
     rule->idle_timeout = idle_timeout;
     rule->hard_timeout = hard_timeout;
     rule->used = rule->created = time_msec();
@@ -2427,7 +2427,7 @@ query_stats(struct ofproto *p, struct rule *rule,
     byte_count = rule->byte_count;
 
     n_odp_flows = rule->cr.wc.wildcards ? list_size(&rule->list) : 1;
-    odp_flows = xcalloc(1, n_odp_flows * sizeof *odp_flows);
+    odp_flows = xzalloc(n_odp_flows * sizeof *odp_flows);
     if (rule->cr.wc.wildcards) {
         size_t i = 0;
         LIST_FOR_EACH (subrule, struct rule, list, &rule->list) {
index 0afd22f..a4f5bfa 100644 (file)
@@ -227,7 +227,7 @@ pinsched_create(int rate_limit, int burst_limit, struct switch_status *ss)
 {
     struct pinsched *ps;
 
-    ps = xcalloc(1, sizeof *ps);
+    ps = xzalloc(sizeof *ps);
     port_array_init(&ps->queues);
     ps->n_queued = 0;
     ps->last_tx_port = PORT_ARRAY_SIZE;
index 450cc3b..3701aeb 100644 (file)
@@ -63,7 +63,7 @@ pktbuf_capacity(void)
 struct pktbuf *
 pktbuf_create(void)
 {
-    return xcalloc(1, sizeof *pktbuf_create());
+    return xzalloc(sizeof *pktbuf_create());
 }
 
 void
index b2cb935..5e61888 100644 (file)
@@ -177,7 +177,7 @@ switch_status_cb(struct status_reply *sr, void *ss_)
 struct switch_status *
 switch_status_create(const struct ofproto *ofproto)
 {
-    struct switch_status *ss = xcalloc(1, sizeof *ss);
+    struct switch_status *ss = xzalloc(sizeof *ss);
     ss->booted = time_now();
     list_init(&ss->categories);
     ss->config_cat = switch_status_register(ss, "config", config_status_cb,
index 0307e48..d36c8eb 100644 (file)
@@ -446,7 +446,7 @@ make_rule(int wc_fields, unsigned int priority, int value_pat)
         }
     }
 
-    rule = xcalloc(1, sizeof *rule);
+    rule = xzalloc(sizeof *rule);
     cls_rule_from_flow(&rule->cls_rule, &flow, wildcards,
                        !wildcards ? UINT_MAX : priority);
     return rule;
index b0db9ab..b1e4e16 100644 (file)
@@ -964,7 +964,7 @@ bridge_create(const char *name)
     int error;
 
     assert(!bridge_lookup(name));
-    br = xcalloc(1, sizeof *br);
+    br = xzalloc(sizeof *br);
 
     error = dpif_create(name, &br->dpif);
     if (error == EEXIST || error == EBUSY) {
@@ -2838,7 +2838,7 @@ port_create(struct bridge *br, const char *name)
 {
     struct port *port;
 
-    port = xcalloc(1, sizeof *port);
+    port = xzalloc(sizeof *port);
     port->bridge = br;
     port->port_idx = br->n_ports;
     port->vlan = -1;
@@ -3191,7 +3191,7 @@ iface_create(struct port *port, const char *name)
 {
     struct iface *iface;
 
-    iface = xcalloc(1, sizeof *iface);
+    iface = xzalloc(sizeof *iface);
     iface->port = port;
     iface->port_ifidx = port->n_ifaces;
     iface->name = xstrdup(name);
@@ -3398,7 +3398,7 @@ mirror_create(struct bridge *br, const char *name)
     VLOG_INFO("created port mirror %s on bridge %s", name, br->name);
     bridge_flush(br);
 
-    br->mirrors[i] = m = xcalloc(1, sizeof *m);
+    br->mirrors[i] = m = xzalloc(sizeof *m);
     m->bridge = br;
     m->idx = i;
     m->name = xstrdup(name);
index 7a59526..68ae1ac 100644 (file)
@@ -256,7 +256,7 @@ proc_net_compat_update_vlan(const char *tagged_dev, const char *trunk_dev,
         }
         if (!vlan) {
             /* Create a new compat_vlan for (trunk_dev,vid). */
-            vlan = xcalloc(1, sizeof *vlan);
+            vlan = xzalloc(sizeof *vlan);
             vlan->trunk_dev = xstrdup(trunk_dev);
             vlan->vid = vid;
             vlan->vlan_dev = xasprintf("%s.%d", trunk_dev, vid);