Permalink
Browse files

Assertions improved

This patch is replaces generic xs_asserts by errno_assers and
alloc_asserts as appropriate.

It is based on 0MQ patch by Martin Hurton.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
  • Loading branch information...
1 parent f84ebfd commit 58d54740785eb2c7208a01afb5bd9736e5808069 @sustrik sustrik committed May 31, 2012
Showing with 16 additions and 16 deletions.
  1. +1 −1 src/ctx.cpp
  2. +1 −1 src/dist.cpp
  3. +1 −1 src/lb.cpp
  4. +1 −1 src/pgm_sender.cpp
  5. +4 −4 src/prefix_filter.cpp
  6. +2 −2 src/session_base.cpp
  7. +2 −2 src/signaler.cpp
  8. +2 −2 src/socket_base.cpp
  9. +1 −1 src/xrep.cpp
  10. +1 −1 src/xsub.cpp
View
2 src/ctx.cpp
@@ -268,7 +268,7 @@ int xs::ctx_t::terminate ()
int rc = mailbox_recv (&term_mailbox, &cmd, -1);
if (rc == -1 && errno == EINTR)
return -1;
- xs_assert (rc == 0);
+ errno_assert (rc == 0);
xs_assert (cmd.type == command_t::done);
slot_sync.lock ();
xs_assert (sockets.empty ());
View
2 src/dist.cpp
@@ -153,7 +153,7 @@ void xs::dist_t::distribute (msg_t *msg_, int flags_)
int rc = msg_->close ();
errno_assert (rc == 0);
rc = msg_->init ();
- xs_assert (rc == 0);
+ errno_assert (rc == 0);
return;
}
View
2 src/lb.cpp
@@ -84,7 +84,7 @@ int xs::lb_t::send (msg_t *msg_, int flags_)
int rc = msg_->close ();
errno_assert (rc == 0);
rc = msg_->init ();
- xs_assert (rc == 0);
+ errno_assert (rc == 0);
return 0;
}
View
2 src/pgm_sender.cpp
@@ -215,7 +215,7 @@ void xs::pgm_sender_t::out_event (fd_t fd_)
xs_assert (!tx_timer);
tx_timer = add_timer (timeout);
} else
- xs_assert (errno == EBUSY);
+ errno_assert (errno == EBUSY);
}
}
View
8 src/prefix_filter.cpp
@@ -111,7 +111,7 @@ static bool pfx_add (pfx_node_t *node_,
(node_->min < c ? c - node_->min : node_->min - c) + 1;
node_->next.table = (pfx_node_t**)
malloc (sizeof (pfx_node_t*) * node_->count);
- xs_assert (node_->next.table);
+ alloc_assert (node_->next.table);
for (unsigned short i = 0; i != node_->count; ++i)
node_->next.table [i] = 0;
node_->min = std::min (node_->min, c);
@@ -293,7 +293,7 @@ static void pfx_rm_all (pfx_node_t *node_, void *subscribers_,
node_->count = new_max - new_min + 1;
node_->next.table =
(pfx_node_t**) malloc (sizeof (pfx_node_t*) * node_->count);
- xs_assert (node_->next.table);
+ alloc_assert (node_->next.table);
memmove (node_->next.table, old_table + (new_min - node_->min),
sizeof (pfx_node_t*) * node_->count);
@@ -393,7 +393,7 @@ static bool pfx_rm (pfx_node_t *node_, const unsigned char *prefix_,
node_->count = node_->count - (new_min - node_->min);
node_->next.table = (pfx_node_t**)
malloc (sizeof (pfx_node_t*) * node_->count);
- xs_assert (node_->next.table);
+ alloc_assert (node_->next.table);
memmove (node_->next.table, old_table + (new_min - node_->min),
sizeof (pfx_node_t*) * node_->count);
@@ -417,7 +417,7 @@ static bool pfx_rm (pfx_node_t *node_, const unsigned char *prefix_,
pfx_node_t **old_table = node_->next.table;
node_->next.table = (pfx_node_t**)
malloc (sizeof (pfx_node_t*) * node_->count);
- xs_assert (node_->next.table);
+ alloc_assert (node_->next.table);
memmove (node_->next.table, old_table,
sizeof (pfx_node_t*) * node_->count);
View
4 src/session_base.cpp
@@ -461,7 +461,7 @@ void xs::session_base_t::start_connecting (bool wait_)
alloc_assert (pgm_sender);
int rc = pgm_sender->init (udp_encapsulation, address.c_str ());
- xs_assert (rc == 0);
+ errno_assert (rc == 0);
send_attach (this, pgm_sender);
}
@@ -473,7 +473,7 @@ void xs::session_base_t::start_connecting (bool wait_)
alloc_assert (pgm_receiver);
int rc = pgm_receiver->init (udp_encapsulation, address.c_str ());
- xs_assert (rc == 0);
+ errno_assert (rc == 0);
send_attach (this, pgm_receiver);
}
View
4 src/signaler.cpp
@@ -332,7 +332,7 @@ int xs::signaler_wait (xs::signaler_t *self_, int timeout_)
pfd.events = POLLIN;
int rc = poll (&pfd, 1, timeout_);
if (unlikely (rc < 0)) {
- xs_assert (errno == EINTR);
+ errno_assert (errno == EINTR);
return -1;
}
else if (unlikely (rc == 0)) {
@@ -358,7 +358,7 @@ int xs::signaler_wait (xs::signaler_t *self_, int timeout_)
int rc = select (self_->r + 1, &self_->fds, NULL, NULL,
timeout_ >= 0 ? &timeout : NULL);
if (unlikely (rc < 0)) {
- xs_assert (errno == EINTR);
+ errno_assert (errno == EINTR);
return -1;
}
#endif
View
4 src/socket_base.cpp
@@ -461,7 +461,7 @@ int xs::socket_base_t::connect (const char *addr_)
if (options.send_identity) {
msg_t id;
rc = id.init_size (options.identity_size);
- xs_assert (rc == 0);
+ errno_assert (rc == 0);
memcpy (id.data (), options.identity, options.identity_size);
id.set_flags (msg_t::identity);
bool written = ppair [0]->write (&id);
@@ -473,7 +473,7 @@ int xs::socket_base_t::connect (const char *addr_)
if (peer.options.send_identity) {
msg_t id;
rc = id.init_size (peer.options.identity_size);
- xs_assert (rc == 0);
+ errno_assert (rc == 0);
memcpy (id.data (), peer.options.identity,
peer.options.identity_size);
id.set_flags (msg_t::identity);
View
2 src/xrep.cpp
@@ -319,7 +319,7 @@ bool xs::xrep_t::xhas_in ()
id.close ();
return false;
}
- xs_assert (rc == 0);
+ errno_assert (rc == 0);
// We have first part of the message prefetched now. We will store the
// prefetched identity as well.
View
2 src/xsub.cpp
@@ -200,7 +200,7 @@ void xs::xsub_t::send_subscription (pipe_t *pipe_, bool subscribe_,
// Create the subsctription message.
msg_t msg;
int rc = msg.init_size (size_ + 4);
- xs_assert (rc == 0);
+ errno_assert (rc == 0);
unsigned char *data = (unsigned char*) msg.data ();
put_uint16 (data, subscribe_ ? SP_PUBSUB_CMD_SUBSCRIBE :
SP_PUBSUB_CMD_UNSUBSCRIBE);

0 comments on commit 58d5474

Please sign in to comment.