Skip to content

Commit

Permalink
[NaCl SDK] Remove invalid assert from nacl_io.
Browse files Browse the repository at this point in the history
Also, add NDEBUG to CFLAGS by default so that asserts not
compiled into release builds, and fix resulting unused
variable warnings by making KernelProxy::Init do more
error checking and return a result.

R=binji@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221470 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sbc@chromium.org committed Sep 5, 2013
1 parent daae132 commit 51b8711
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 19 deletions.
6 changes: 4 additions & 2 deletions native_client_sdk/src/examples/api/graphics_3d/graphics_3d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ void DecompressTexture() {
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
};
const uint8_t* input = &kRLETextureData[0];
const uint8_t * const input_end = &kRLETextureData[kRLETextureDataLength];
const uint8_t* const input_end = &kRLETextureData[kRLETextureDataLength];
uint8_t* output = &g_texture_data[0];
const uint8_t * const output_end = &g_texture_data[kTextureDataLength];
#ifndef NDEBUG
const uint8_t* const output_end = &g_texture_data[kTextureDataLength];
#endif

uint8_t decoded[4];
int decoded_count = 0;
Expand Down
10 changes: 9 additions & 1 deletion native_client_sdk/src/examples/api/input_event/shared_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,22 @@ class ScopedLock {
ScopedLock(const ScopedLock&);
};


#ifdef __GNUC__
#define UNUSED __attribute__ ((unused))
#else
#define UNUSED
#endif

// LockingQueue contains a collection of <T>, such as a collection of
// objects or pointers. The Push() method is used to add items to the
// queue in a thread-safe manner. The GetItem() is used to retrieve
// items from the queue in a thread-safe manner.
template <class T> class LockingQueue {
public:
LockingQueue() : quit_(false) {
int result = pthread_mutex_init(&queue_mutex_, NULL);
int result UNUSED;
result = pthread_mutex_init(&queue_mutex_, NULL);
assert(result == 0);
result = pthread_cond_init(&queue_condition_var_, NULL);
assert(result == 0);
Expand Down
5 changes: 4 additions & 1 deletion native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ char* VprintfToNewString(const char* format, va_list args) {
length = vsnprintf(NULL, 0, format, args);
buffer = (char*)malloc(length + 1); /* +1 for NULL-terminator. */
result = vsnprintf(&buffer[0], length + 1, format, args_copy);
assert(result == length);
if (result != length) {
assert(0);
return NULL;
}
return buffer;
}

Expand Down
3 changes: 3 additions & 0 deletions native_client_sdk/src/examples/demo/voronoi/voronoi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ inline void rand_reset(unsigned int seed) {
g_rand_state = seed;
}

#ifndef NDEBUG
// returns true if input is power of two.
// only used in assertions.
inline bool is_pow2(int x) {
return (x & (x - 1)) == 0;
}
#endif

inline double getseconds() {
const double usec_to_sec = 0.000001;
Expand Down
39 changes: 32 additions & 7 deletions native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ KernelProxy::~KernelProxy() {
delete ppapi_;
}

void KernelProxy::Init(PepperInterface* ppapi) {
Error KernelProxy::Init(PepperInterface* ppapi) {
Error rtn = 0;
ppapi_ = ppapi;
dev_ = 1;

Expand All @@ -98,23 +99,47 @@ void KernelProxy::Init(PepperInterface* ppapi) {

int result;
result = mount("", "/", "passthroughfs", 0, NULL);
assert(result == 0);
if (result != 0) {
assert(false);
rtn = errno;
}

result = mount("", "/dev", "dev", 0, NULL);
assert(result == 0);
if (result != 0) {
assert(false);
rtn = errno;
}

// Open the first three in order to get STDIN, STDOUT, STDERR
open("/dev/stdin", O_RDONLY);
open("/dev/stdout", O_WRONLY);
open("/dev/stderr", O_WRONLY);
int fd;
fd = open("/dev/stdin", O_RDONLY);
assert(fd == 0);
if (fd < 0)
rtn = errno;

fd = open("/dev/stdout", O_WRONLY);
assert(fd == 1);
if (fd < 0)
rtn = errno;

fd = open("/dev/stderr", O_WRONLY);
assert(fd == 2);
if (fd < 0)
rtn = errno;

#ifdef PROVIDES_SOCKET_API
host_resolver_.Init(ppapi_);
#endif

StringMap_t args;
socket_mount_.reset(new MountSocket());
socket_mount_->Init(0, args, ppapi);
result = socket_mount_->Init(0, args, ppapi);
if (result != 0) {
assert(false);
rtn = result;
}

return rtn;
}

int KernelProxy::open_resource(const char* path) {
Expand Down
2 changes: 1 addition & 1 deletion native_client_sdk/src/libraries/nacl_io/kernel_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class KernelProxy : protected KernelObject {

// Takes ownership of |ppapi|.
// |ppapi| may be NULL. If so, no mount that uses pepper calls can be mounted.
virtual void Init(PepperInterface* ppapi);
virtual Error Init(PepperInterface* ppapi);

// NaCl-only function to read resources specified in the NMF file.
virtual int open_resource(const char* file);
Expand Down
2 changes: 0 additions & 2 deletions native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "nacl_io/kernel_wrap.h"

#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <irt.h>
Expand All @@ -35,7 +34,6 @@ EXTERN_C_BEGIN

// Assign the REAL function pointer.
#define ASSIGN_REAL_PTR(group, name) \
assert(__libnacl_irt_##group.name != NULL); \
REAL(name) = __libnacl_irt_##group.name;

// Switch IRT's pointer to the REAL pointer
Expand Down
9 changes: 6 additions & 3 deletions native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,10 @@ class MountMockInit : public MountMem {
};

class KernelProxyMountMock : public KernelProxy {
virtual void Init(PepperInterface* ppapi) {
virtual Error Init(PepperInterface* ppapi) {
KernelProxy::Init(NULL);
factories_["initfs"] = new TypedMountFactory<MountMockInit>;
return 0;
}
};

Expand Down Expand Up @@ -378,9 +379,10 @@ class MountMockMMap : public Mount {
};

class KernelProxyMockMMap : public KernelProxy {
virtual void Init(PepperInterface* ppapi) {
virtual Error Init(PepperInterface* ppapi) {
KernelProxy::Init(NULL);
factories_["mmapfs"] = new TypedMountFactory<MountMockMMap>;
return 0;
}
};

Expand Down Expand Up @@ -450,11 +452,12 @@ class KernelProxyError : public KernelProxy {
public:
KernelProxyError() : mnt_(new MountMock) {}

virtual void Init(PepperInterface* ppapi) {
virtual Error Init(PepperInterface* ppapi) {
KernelProxy::Init(ppapi);
factories_["testfs"] = new SingletonMountFactory(mnt_);

EXPECT_CALL(*mnt_, Destroy()).Times(1);
return 0;
}

ScopedRef<MountMock> mnt() { return mnt_; }
Expand Down
5 changes: 4 additions & 1 deletion native_client_sdk/src/tools/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,11 @@ endif
#
# Common Compile Options
#
# For example, -DNDEBUG is added to release builds by default
# so that calls to assert(3) are not included in the build.
#
ifeq ($(CONFIG),Release)
POSIX_FLAGS ?= -g -O2 -pthread -MMD
POSIX_FLAGS ?= -g -O2 -pthread -MMD -DNDEBUG
else
POSIX_FLAGS ?= -g -O0 -pthread -MMD -DNACL_SDK_DEBUG
endif
Expand Down
2 changes: 1 addition & 1 deletion native_client_sdk/src/tools/host_vc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ endif


ifeq ($(CONFIG),Release)
WIN_OPT_FLAGS ?= /O2 /MT /Z7
WIN_OPT_FLAGS ?= /O2 /MT /Z7 -DNDEBUG
else
WIN_OPT_FLAGS ?= /Od /MTd /Z7 -DNACL_SDK_DEBUG
endif
Expand Down

0 comments on commit 51b8711

Please sign in to comment.