Mojo: Convert assert()s under mojo/public/cpp/bindings/... to MOJO_DCHECK()s.

R=yzshen@chromium.org

Review URL: https://codereview.chromium.org/399313007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284243 0039d316-1c4b-4281-b951-d872f2087c98
parent ab03b47d
......@@ -13,6 +13,7 @@
#include "mojo/public/cpp/bindings/lib/bounds_checker.h"
#include "mojo/public/cpp/bindings/lib/buffer.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/cpp/environment/logging.h"
namespace mojo {
template <typename T> class Array;
......@@ -267,12 +268,12 @@ class Array_Data {
size_t size() const { return header_.num_elements; }
Ref at(size_t offset) {
assert(offset < static_cast<size_t>(header_.num_elements));
MOJO_DCHECK(offset < static_cast<size_t>(header_.num_elements));
return Traits::ToRef(storage(), offset);
}
ConstRef at(size_t offset) const {
assert(offset < static_cast<size_t>(header_.num_elements));
MOJO_DCHECK(offset < static_cast<size_t>(header_.num_elements));
return Traits::ToConstRef(storage(), offset);
}
......
......@@ -4,11 +4,10 @@
#include "mojo/public/cpp/bindings/lib/bindings_serialization.h"
#include <assert.h>
#include "mojo/public/cpp/bindings/lib/bindings_internal.h"
#include "mojo/public/cpp/bindings/lib/bounds_checker.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/cpp/environment/logging.h"
namespace mojo {
namespace internal {
......@@ -44,7 +43,7 @@ void EncodePointer(const void* ptr, uint64_t* offset) {
const char* p_obj = reinterpret_cast<const char*>(ptr);
const char* p_slot = reinterpret_cast<const char*>(offset);
assert(p_obj > p_slot);
MOJO_DCHECK(p_obj > p_slot);
*offset = static_cast<uint64_t>(p_obj - p_slot);
}
......@@ -75,7 +74,7 @@ void DecodeHandle(Handle* handle, std::vector<Handle>* handles) {
*handle = Handle();
return;
}
assert(handle->value() < handles->size());
MOJO_DCHECK(handle->value() < handles->size());
// Just leave holes in the vector so we don't screw up other indices.
*handle = FetchAndReset(&handles->at(handle->value()));
}
......@@ -84,7 +83,7 @@ bool ValidateStructHeader(const void* data,
uint32_t min_num_bytes,
uint32_t min_num_fields,
BoundsChecker* bounds_checker) {
assert(min_num_bytes >= sizeof(StructHeader));
MOJO_DCHECK(min_num_bytes >= sizeof(StructHeader));
if (!IsAligned(data)) {
ReportValidationError(VALIDATION_ERROR_MISALIGNED_OBJECT);
......
......@@ -4,10 +4,9 @@
#include "mojo/public/cpp/bindings/lib/bounds_checker.h"
#include <assert.h>
#include "mojo/public/cpp/bindings/lib/bindings_serialization.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/environment/logging.h"
#include "mojo/public/cpp/system/handle.h"
namespace mojo {
namespace internal {
......@@ -22,13 +21,13 @@ BoundsChecker::BoundsChecker(const void* data, uint32_t data_num_bytes,
// The calculation of |data_end_| overflowed.
// It shouldn't happen but if it does, set the range to empty so
// IsValidRange() and ClaimMemory() always fail.
assert(false); // Not reached.
MOJO_DCHECK(false) << "Not reached";
data_end_ = data_begin_;
}
if (handle_end_ < num_handles) {
// Assigning |num_handles| to |handle_end_| overflowed.
// It shouldn't happen but if it does, set the handle index range to empty.
assert(false); // Not reached.
MOJO_DCHECK(false) << "Not reached";
handle_end_ = 0;
}
}
......
......@@ -4,10 +4,10 @@
#include "mojo/public/cpp/bindings/lib/connector.h"
#include <assert.h>
#include <stdlib.h>
#include <stddef.h>
#include "mojo/public/cpp/bindings/error_handler.h"
#include "mojo/public/cpp/environment/logging.h"
namespace mojo {
namespace internal {
......@@ -66,7 +66,7 @@ bool Connector::WaitForIncomingMessage() {
}
bool Connector::Accept(Message* message) {
assert(message_pipe_.is_valid());
MOJO_DCHECK(message_pipe_.is_valid());
if (error_)
return false;
......@@ -112,7 +112,7 @@ void Connector::CallOnHandleReady(void* closure, MojoResult result) {
}
void Connector::OnHandleReady(MojoResult result) {
assert(async_wait_id_ != 0);
MOJO_DCHECK(async_wait_id_ != 0);
async_wait_id_ = 0;
if (result != MOJO_RESULT_OK) {
NotifyError();
......
......@@ -4,10 +4,10 @@
#include "mojo/public/cpp/bindings/lib/filter_chain.h"
#include <assert.h>
#include <algorithm>
#include "mojo/public/cpp/environment/logging.h"
namespace mojo {
namespace internal {
......@@ -34,14 +34,14 @@ FilterChain::~FilterChain() {
}
void FilterChain::SetSink(MessageReceiver* sink) {
assert(!sink_);
MOJO_DCHECK(!sink_);
sink_ = sink;
if (!filters_.empty())
filters_.back()->set_sink(sink);
}
MessageReceiver* FilterChain::GetHead() {
assert(sink_);
MOJO_DCHECK(sink_);
return filters_.empty() ? sink_ : filters_.front();
}
......
......@@ -4,13 +4,12 @@
#include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include "mojo/public/cpp/bindings/lib/bindings_serialization.h"
#include "mojo/public/cpp/environment/logging.h"
namespace mojo {
namespace internal {
......@@ -31,7 +30,7 @@ void* FixedBuffer::Allocate(size_t delta) {
delta = internal::Align(delta);
if (delta == 0 || delta > size_ - cursor_) {
assert(false);
MOJO_DCHECK(false) << "Not reached";
return NULL;
}
......
......@@ -10,6 +10,7 @@
#include "mojo/public/cpp/bindings/lib/filter_chain.h"
#include "mojo/public/cpp/bindings/lib/message_header_validator.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/environment/logging.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......@@ -31,7 +32,7 @@ class InterfaceImplState : public ErrorHandler {
explicit InterfaceImplState(InterfaceImplBase<Interface>* instance)
: router_(NULL),
proxy_(NULL) {
assert(instance);
MOJO_DCHECK(instance);
stub_.set_sink(instance);
}
......@@ -53,7 +54,7 @@ class InterfaceImplState : public ErrorHandler {
void Bind(ScopedMessagePipeHandle handle,
const MojoAsyncWaiter* waiter) {
assert(!router_);
MOJO_DCHECK(!router_);
FilterChain filters;
filters.Append<MessageHeaderValidator>();
......@@ -70,7 +71,7 @@ class InterfaceImplState : public ErrorHandler {
}
bool WaitForIncomingMethodCall() {
assert(router_);
MOJO_DCHECK(router_);
return router_->WaitForIncomingMessage();
}
......
......@@ -5,13 +5,12 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_
#define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_
#include <assert.h>
#include <algorithm> // For |std::swap()|.
#include "mojo/public/cpp/bindings/lib/filter_chain.h"
#include "mojo/public/cpp/bindings/lib/message_header_validator.h"
#include "mojo/public/cpp/bindings/lib/router.h"
#include "mojo/public/cpp/environment/logging.h"
struct MojoAsyncWaiter;
......@@ -46,10 +45,10 @@ class InterfacePtrState {
}
void Bind(ScopedMessagePipeHandle handle, const MojoAsyncWaiter* waiter) {
assert(!proxy_);
assert(!router_);
assert(!handle_.is_valid());
assert(!waiter_);
MOJO_DCHECK(!proxy_);
MOJO_DCHECK(!router_);
MOJO_DCHECK(!handle_.is_valid());
MOJO_DCHECK(!waiter_);
handle_ = handle.Pass();
waiter_ = waiter;
......@@ -58,7 +57,7 @@ class InterfacePtrState {
bool WaitForIncomingMethodCall() {
ConfigureProxyIfNecessary();
assert(router_);
MOJO_DCHECK(router_);
return router_->WaitForIncomingMessage();
}
......@@ -73,7 +72,7 @@ class InterfacePtrState {
void set_client(typename Interface::Client* client) {
ConfigureProxyIfNecessary();
assert(proxy_);
MOJO_DCHECK(proxy_);
proxy_->stub.set_sink(client);
}
......@@ -84,7 +83,7 @@ class InterfacePtrState {
void set_error_handler(ErrorHandler* error_handler) {
ConfigureProxyIfNecessary();
assert(router_);
MOJO_DCHECK(router_);
router_->set_error_handler(error_handler);
}
......@@ -107,12 +106,12 @@ class InterfacePtrState {
void ConfigureProxyIfNecessary() {
// The proxy has been configured.
if (proxy_) {
assert(router_);
MOJO_DCHECK(router_);
return;
}
// The object hasn't been bound.
if (!waiter_) {
assert(!handle_.is_valid());
MOJO_DCHECK(!handle_.is_valid());
return;
}
......
......@@ -4,11 +4,12 @@
#include "mojo/public/cpp/bindings/message.h"
#include <assert.h>
#include <stdlib.h>
#include <algorithm>
#include "mojo/public/cpp/environment/logging.h"
namespace mojo {
Message::Message()
......@@ -27,13 +28,13 @@ Message::~Message() {
}
void Message::AllocUninitializedData(uint32_t num_bytes) {
assert(!data_);
MOJO_DCHECK(!data_);
data_num_bytes_ = num_bytes;
data_ = static_cast<internal::MessageData*>(malloc(num_bytes));
}
void Message::AdoptData(uint32_t num_bytes, internal::MessageData* data) {
assert(!data_);
MOJO_DCHECK(!data_);
data_num_bytes_ = num_bytes;
data_ = data;
}
......
......@@ -4,10 +4,8 @@
#include "mojo/public/cpp/bindings/lib/message_queue.h"
#include <assert.h>
#include <stddef.h>
#include "mojo/public/cpp/bindings/message.h"
#include "mojo/public/cpp/environment/logging.h"
namespace mojo {
namespace internal {
......@@ -25,7 +23,7 @@ bool MessageQueue::IsEmpty() const {
}
Message* MessageQueue::Peek() {
assert(!queue_.empty());
MOJO_DCHECK(!queue_.empty());
return queue_.front();
}
......@@ -35,13 +33,13 @@ void MessageQueue::Push(Message* message) {
}
void MessageQueue::Pop(Message* message) {
assert(!queue_.empty());
MOJO_DCHECK(!queue_.empty());
queue_.front()->Swap(message);
Pop();
}
void MessageQueue::Pop() {
assert(!queue_.empty());
MOJO_DCHECK(!queue_.empty());
delete queue_.front();
queue_.pop();
}
......
......@@ -4,6 +4,8 @@
#include "mojo/public/cpp/bindings/lib/router.h"
#include "mojo/public/cpp/environment/logging.h"
namespace mojo {
namespace internal {
......@@ -19,7 +21,7 @@ class ResponderThunk : public MessageReceiver {
// MessageReceiver implementation:
virtual bool Accept(Message* message) MOJO_OVERRIDE {
assert(message->has_flag(kMessageIsResponse));
MOJO_DCHECK(message->has_flag(kMessageIsResponse));
bool result = false;
......@@ -73,13 +75,13 @@ Router::~Router() {
}
bool Router::Accept(Message* message) {
assert(!message->has_flag(kMessageExpectsResponse));
MOJO_DCHECK(!message->has_flag(kMessageExpectsResponse));
return connector_.Accept(message);
}
bool Router::AcceptWithResponder(Message* message,
MessageReceiver* responder) {
assert(message->has_flag(kMessageExpectsResponse));
MOJO_DCHECK(message->has_flag(kMessageExpectsResponse));
// Reserve 0 in case we want it to convey special meaning in the future.
uint64_t request_id = next_request_id_++;
......@@ -117,7 +119,7 @@ bool Router::HandleIncomingMessage(Message* message) {
uint64_t request_id = message->request_id();
ResponderMap::iterator it = responders_.find(request_id);
if (it == responders_.end()) {
assert(testing_mode_);
MOJO_DCHECK(testing_mode_);
return false;
}
MessageReceiver* responder = it->second;
......
......@@ -4,8 +4,6 @@
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include <assert.h>
#include "mojo/public/cpp/environment/logging.h"
namespace mojo {
......@@ -50,12 +48,12 @@ void ReportValidationError(ValidationError error) {
ValidationErrorObserverForTesting::ValidationErrorObserverForTesting()
: last_error_(VALIDATION_ERROR_NONE) {
assert(!g_validation_error_observer);
MOJO_DCHECK(!g_validation_error_observer);
g_validation_error_observer = this;
}
ValidationErrorObserverForTesting::~ValidationErrorObserverForTesting() {
assert(g_validation_error_observer == this);
MOJO_DCHECK(g_validation_error_observer == this);
g_validation_error_observer = NULL;
}
......
......@@ -5,11 +5,10 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_
#define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_
#include <assert.h>
#include <vector>
#include "mojo/public/cpp/bindings/lib/message_internal.h"
#include "mojo/public/cpp/environment/logging.h"
namespace mojo {
......@@ -46,12 +45,12 @@ class Message {
// Access the request_id field (if present).
bool has_request_id() const { return data_->header.num_fields >= 3; }
uint64_t request_id() const {
assert(has_request_id());
MOJO_DCHECK(has_request_id());
return static_cast<const internal::MessageHeaderWithRequestID*>(
&data_->header)->request_id;
}
void set_request_id(uint64_t request_id) {
assert(has_request_id());
MOJO_DCHECK(has_request_id());
static_cast<internal::MessageHeaderWithRequestID*>(&data_->header)->
request_id = request_id;
}
......@@ -64,7 +63,7 @@ class Message {
return reinterpret_cast<uint8_t*>(data_) + data_->header.num_bytes;
}
uint32_t payload_num_bytes() const {
assert(data_num_bytes_ >= data_->header.num_bytes);
MOJO_DCHECK(data_num_bytes_ >= data_->header.num_bytes);
return data_num_bytes_ - data_->header.num_bytes;
}
......
......@@ -5,13 +5,11 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_H_
#define MOJO_PUBLIC_CPP_BINDINGS_STRING_H_
#include <assert.h>
#include <string>
#include "mojo/public/cpp/bindings/lib/array_internal.h"
#include "mojo/public/cpp/bindings/type_converter.h"
#include "mojo/public/cpp/system/macros.h"
#include "mojo/public/cpp/environment/logging.h"
namespace mojo {
......@@ -125,7 +123,7 @@ template <size_t N>
class TypeConverter<String, char[N]> {
public:
static String ConvertFrom(const char input[N]) {
assert(input);
MOJO_DCHECK(input);
return String(input, N-1);
}
};
......@@ -135,7 +133,7 @@ template <size_t N>
class TypeConverter<String, const char[N]> {
public:
static String ConvertFrom(const char input[N]) {
assert(input);
MOJO_DCHECK(input);
return String(input, N-1);
}
};
......
......@@ -5,10 +5,9 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
#define MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
#include <assert.h>
#include <new>
#include "mojo/public/cpp/environment/logging.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......@@ -55,11 +54,11 @@ class StructPtr {
bool is_null() const { return ptr_ == NULL; }
Struct& operator*() const {
assert(ptr_);
MOJO_DCHECK(ptr_);
return *ptr_;
}
Struct* operator->() const {
assert(ptr_);
MOJO_DCHECK(ptr_);
return ptr_;
}
Struct* get() const { return ptr_; }
......@@ -76,7 +75,10 @@ class StructPtr {
private:
friend class internal::StructHelper<Struct>;
void Initialize() { assert(!ptr_); ptr_ = new Struct(); }
void Initialize() {
MOJO_DCHECK(!ptr_);
ptr_ = new Struct();
}
void Take(StructPtr* other) {
reset();
......@@ -116,11 +118,11 @@ class InlinedStructPtr {
bool is_null() const { return is_null_; }
Struct& operator*() const {
assert(!is_null_);
MOJO_DCHECK(!is_null_);
return value_;
}
Struct* operator->() const {
assert(!is_null_);
MOJO_DCHECK(!is_null_);
return &value_;
}
Struct* get() const { return &value_; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment