Bug 1297402 - Change public xpt functions to return bool instead of PRBool. r=froydnj.

--HG--
extra : rebase_source : 7517f1d9c8831e7bdf0bf0122b70496ce3348592
This commit is contained in:
Nicholas Nethercote 2016-08-25 15:59:25 +10:00
parent 87a4c57d9d
commit f1b7b1188d
4 changed files with 126 additions and 126 deletions

View File

@ -10,7 +10,7 @@
#ifndef __xpt_arena_h__
#define __xpt_arena_h__
#include "prtypes.h"
#include "prcpucfg.h"
#include <stdlib.h>
#include "mozilla/Attributes.h"
#include "mozilla/MemoryReporting.h"

View File

@ -15,40 +15,40 @@ using mozilla::WrapNotNull;
/***************************************************************************/
/* Forward declarations. */
static PRBool
static bool
DoInterfaceDirectoryEntry(XPTArena *arena, NotNull<XPTCursor*> cursor,
XPTInterfaceDirectoryEntry *ide);
static PRBool
static bool
DoConstDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
XPTConstDescriptor *cd, XPTInterfaceDescriptor *id);
static PRBool
static bool
DoMethodDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
XPTMethodDescriptor *md, XPTInterfaceDescriptor *id);
static PRBool
static bool
SkipAnnotation(NotNull<XPTCursor*> cursor, bool *isLast);
static PRBool
static bool
DoInterfaceDescriptor(XPTArena *arena, NotNull<XPTCursor*> outer,
XPTInterfaceDescriptor **idp);
static PRBool
static bool
DoTypeDescriptorPrefix(XPTArena *arena, NotNull<XPTCursor*> cursor,
XPTTypeDescriptorPrefix *tdp);
static PRBool
static bool
DoTypeDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
XPTTypeDescriptor *td, XPTInterfaceDescriptor *id);
static PRBool
static bool
DoParamDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
XPTParamDescriptor *pd, XPTInterfaceDescriptor *id);
/***************************************************************************/
XPT_PUBLIC_API(PRBool)
XPT_PUBLIC_API(bool)
XPT_DoHeader(XPTArena *arena, NotNull<XPTCursor*> cursor, XPTHeader **headerp)
{
unsigned int i;
@ -57,13 +57,13 @@ XPT_DoHeader(XPTArena *arena, NotNull<XPTCursor*> cursor, XPTHeader **headerp)
XPTHeader* header = XPT_NEWZAP(arena, XPTHeader);
if (!header)
return PR_FALSE;
return false;
*headerp = header;
uint8_t magic[16];
for (i = 0; i < sizeof(magic); i++) {
if (!XPT_Do8(cursor, &magic[i]))
return PR_FALSE;
return false;
}
if (strncmp((const char*)magic, XPT_MAGIC, 16) != 0) {
@ -72,12 +72,12 @@ XPT_DoHeader(XPTArena *arena, NotNull<XPTCursor*> cursor, XPTHeader **headerp)
"libxpt: bad magic header in input file; "
"found '%s', expected '%s'\n",
magic, XPT_MAGIC_STRING);
return PR_FALSE;
return false;
}
if (!XPT_Do8(cursor, &header->major_version) ||
!XPT_Do8(cursor, &header->minor_version)) {
return PR_FALSE;
return false;
}
if (header->major_version >= XPT_MAJOR_INCOMPATIBLE_VERSION) {
@ -85,13 +85,13 @@ XPT_DoHeader(XPTArena *arena, NotNull<XPTCursor*> cursor, XPTHeader **headerp)
* number. We must set the header state thusly and return.
*/
header->num_interfaces = 0;
return PR_TRUE;
return true;
}
if (!XPT_Do16(cursor, &header->num_interfaces) ||
!XPT_Do32(cursor, &file_length) ||
!XPT_Do32(cursor, &ide_offset)) {
return PR_FALSE;
return false;
}
/*
@ -102,12 +102,12 @@ XPT_DoHeader(XPTArena *arena, NotNull<XPTCursor*> cursor, XPTHeader **headerp)
cursor->state->pool_allocated < file_length) {
fputs("libxpt: File length in header does not match actual length. File may be corrupt\n",
stderr);
return PR_FALSE;
return false;
}
uint32_t data_pool;
if (!XPT_Do32(cursor, &data_pool))
return PR_FALSE;
return false;
XPT_SetDataOffset(cursor->state, data_pool);
@ -116,7 +116,7 @@ XPT_DoHeader(XPTArena *arena, NotNull<XPTCursor*> cursor, XPTHeader **headerp)
header->interface_directory =
static_cast<XPTInterfaceDirectoryEntry*>(XPT_CALLOC8(arena, n));
if (!header->interface_directory)
return PR_FALSE;
return false;
}
/*
@ -127,23 +127,23 @@ XPT_DoHeader(XPTArena *arena, NotNull<XPTCursor*> cursor, XPTHeader **headerp)
bool isLast;
do {
if (!SkipAnnotation(cursor, &isLast))
return PR_FALSE;
return false;
} while (!isLast);
/* shouldn't be necessary now, but maybe later */
XPT_SeekTo(cursor, ide_offset);
XPT_SeekTo(cursor, ide_offset);
for (i = 0; i < header->num_interfaces; i++) {
if (!DoInterfaceDirectoryEntry(arena, cursor,
if (!DoInterfaceDirectoryEntry(arena, cursor,
&header->interface_directory[i]))
return PR_FALSE;
return false;
}
return PR_TRUE;
}
return true;
}
/* InterfaceDirectoryEntry records go in the header */
PRBool
bool
DoInterfaceDirectoryEntry(XPTArena *arena, NotNull<XPTCursor*> cursor,
XPTInterfaceDirectoryEntry *ide)
{
@ -151,24 +151,24 @@ DoInterfaceDirectoryEntry(XPTArena *arena, NotNull<XPTCursor*> cursor,
/* write the IID in our cursor space */
if (!XPT_DoIID(cursor, &(ide->iid)) ||
/* write the name string in the data pool, and the offset in our
cursor space */
!XPT_DoCString(arena, cursor, &(ide->name)) ||
/* don't write the name_space string in the data pool, because we don't
* need it. Do write the offset in our cursor space */
!XPT_DoCString(arena, cursor, &dummy_name_space, /* ignore = */ true) ||
/* do InterfaceDescriptors */
!DoInterfaceDescriptor(arena, cursor, &ide->interface_descriptor)) {
return PR_FALSE;
return false;
}
return PR_TRUE;
return true;
}
static PRBool
static bool
InterfaceDescriptorAddTypes(XPTArena *arena, XPTInterfaceDescriptor *id,
uint16_t num)
{
@ -180,20 +180,20 @@ InterfaceDescriptorAddTypes(XPTArena *arena, XPTInterfaceDescriptor *id,
/* XXX should grow in chunks to minimize alloc overhead */
new_ = static_cast<XPTTypeDescriptor*>(XPT_CALLOC8(arena, new_size));
if (!new_)
return PR_FALSE;
return false;
if (old) {
memcpy(new_, old, old_size);
}
id->additional_types = new_;
if (num + uint16_t(id->num_additional_types) > 256)
return PR_FALSE;
return false;
id->num_additional_types += num;
return PR_TRUE;
return true;
}
PRBool
bool
DoInterfaceDescriptor(XPTArena *arena, NotNull<XPTCursor*> outer,
XPTInterfaceDescriptor **idp)
{
@ -204,21 +204,21 @@ DoInterfaceDescriptor(XPTArena *arena, NotNull<XPTCursor*> outer,
id = XPT_NEWZAP(arena, XPTInterfaceDescriptor);
if (!id)
return PR_FALSE;
return false;
*idp = id;
if (!XPT_MakeCursor(outer->state, XPT_DATA, id_sz, cursor))
return PR_FALSE;
return false;
if (!XPT_Do32(outer, &cursor->offset))
return PR_FALSE;
return false;
if (!cursor->offset) {
*idp = NULL;
return PR_TRUE;
return true;
}
if(!XPT_Do16(cursor, &id->parent_interface) ||
!XPT_Do16(cursor, &id->num_methods)) {
return PR_FALSE;
return false;
}
if (id->num_methods) {
@ -226,49 +226,49 @@ DoInterfaceDescriptor(XPTArena *arena, NotNull<XPTCursor*> outer,
id->method_descriptors =
static_cast<XPTMethodDescriptor*>(XPT_CALLOC8(arena, n));
if (!id->method_descriptors)
return PR_FALSE;
return false;
}
for (i = 0; i < id->num_methods; i++) {
if (!DoMethodDescriptor(arena, cursor, &id->method_descriptors[i], id))
return PR_FALSE;
return false;
}
if (!XPT_Do16(cursor, &id->num_constants)) {
return PR_FALSE;
return false;
}
if (id->num_constants) {
size_t n = id->num_constants * sizeof(XPTConstDescriptor);
id->const_descriptors =
static_cast<XPTConstDescriptor*>(XPT_CALLOC8(arena, n));
if (!id->const_descriptors)
return PR_FALSE;
return false;
}
for (i = 0; i < id->num_constants; i++) {
if (!DoConstDescriptor(arena, cursor, &id->const_descriptors[i], id)) {
return PR_FALSE;
return false;
}
}
if (!XPT_Do8(cursor, &id->flags)) {
return PR_FALSE;
return false;
}
return PR_TRUE;
return true;
}
PRBool
bool
DoConstDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
XPTConstDescriptor *cd, XPTInterfaceDescriptor *id)
{
PRBool ok = PR_FALSE;
bool ok = false;
if (!XPT_DoCString(arena, cursor, &cd->name) ||
!DoTypeDescriptor(arena, cursor, &cd->type, id)) {
return PR_FALSE;
return false;
}
switch(XPT_TDP_TAG(cd->type.prefix)) {
@ -312,7 +312,7 @@ DoConstDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
}
PRBool
bool
DoMethodDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
XPTMethodDescriptor *md, XPTInterfaceDescriptor *id)
{
@ -321,79 +321,79 @@ DoMethodDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
if (!XPT_Do8(cursor, &md->flags) ||
!XPT_DoCString(arena, cursor, &md->name) ||
!XPT_Do8(cursor, &md->num_args))
return PR_FALSE;
return false;
if (md->num_args) {
size_t n = md->num_args * sizeof(XPTParamDescriptor);
md->params = static_cast<XPTParamDescriptor*>(XPT_CALLOC8(arena, n));
if (!md->params)
return PR_FALSE;
return false;
}
for(i = 0; i < md->num_args; i++) {
if (!DoParamDescriptor(arena, cursor, &md->params[i], id))
return PR_FALSE;
return false;
}
if (!DoParamDescriptor(arena, cursor, &md->result, id))
return PR_FALSE;
return PR_TRUE;
return false;
return true;
}
PRBool
bool
DoParamDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
XPTParamDescriptor *pd, XPTInterfaceDescriptor *id)
{
if (!XPT_Do8(cursor, &pd->flags) ||
!DoTypeDescriptor(arena, cursor, &pd->type, id))
return PR_FALSE;
return PR_TRUE;
return false;
return true;
}
PRBool
bool
DoTypeDescriptorPrefix(XPTArena *arena, NotNull<XPTCursor*> cursor,
XPTTypeDescriptorPrefix *tdp)
{
return XPT_Do8(cursor, &tdp->flags);
}
PRBool
bool
DoTypeDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
XPTTypeDescriptor *td, XPTInterfaceDescriptor *id)
{
if (!DoTypeDescriptorPrefix(arena, cursor, &td->prefix)) {
return PR_FALSE;
return false;
}
switch (XPT_TDP_TAG(td->prefix)) {
case TD_INTERFACE_TYPE:
uint16_t iface;
if (!XPT_Do16(cursor, &iface))
return PR_FALSE;
return false;
td->u.iface.iface_hi8 = (iface >> 8) & 0xff;
td->u.iface.iface_lo8 = iface & 0xff;
break;
case TD_INTERFACE_IS_TYPE:
if (!XPT_Do8(cursor, &td->u.interface_is.argnum))
return PR_FALSE;
return false;
break;
case TD_ARRAY: {
// argnum2 appears in the on-disk format but it isn't used.
uint8_t argnum2 = 0;
if (!XPT_Do8(cursor, &td->u.array.argnum) ||
!XPT_Do8(cursor, &argnum2))
return PR_FALSE;
return false;
if (!InterfaceDescriptorAddTypes(arena, id, 1))
return PR_FALSE;
return false;
td->u.array.additional_type = id->num_additional_types - 1;
if (!DoTypeDescriptor(arena, cursor,
if (!DoTypeDescriptor(arena, cursor,
&id->additional_types[td->u.array.additional_type],
id))
return PR_FALSE;
return false;
break;
}
case TD_PSTRING_SIZE_IS:
@ -402,31 +402,31 @@ DoTypeDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
uint8_t argnum2 = 0;
if (!XPT_Do8(cursor, &td->u.pstring_is.argnum) ||
!XPT_Do8(cursor, &argnum2))
return PR_FALSE;
return false;
break;
}
default:
/* nothing special */
break;
}
return PR_TRUE;
return true;
}
PRBool
bool
SkipAnnotation(NotNull<XPTCursor*> cursor, bool *isLast)
{
uint8_t flags;
if (!XPT_Do8(cursor, &flags))
return PR_FALSE;
return false;
*isLast = XPT_ANN_IS_LAST(flags);
if (XPT_ANN_IS_PRIVATE(flags)) {
if (!XPT_SkipStringInline(cursor) ||
!XPT_SkipStringInline(cursor))
return PR_FALSE;
return false;
}
return PR_TRUE;
return true;
}

View File

@ -23,7 +23,7 @@
#define CURS_POINT(cursor) \
((cursor)->state->pool_data[CURS_POOL_OFFSET(cursor)])
static PRBool
static bool
CHECK_COUNT(NotNull<XPTCursor*> cursor, uint32_t space)
{
// Fail if we're in the data area and about to exceed the allocation.
@ -32,10 +32,10 @@ CHECK_COUNT(NotNull<XPTCursor*> cursor, uint32_t space)
(CURS_POOL_OFFSET(cursor) + space > (cursor)->state->pool_allocated)) {
XPT_ASSERT(0);
fprintf(stderr, "FATAL: no room for %d in cursor\n", space);
return PR_FALSE;
return false;
}
return PR_TRUE;
return true;
}
XPT_PUBLIC_API(void)
@ -53,7 +53,7 @@ XPT_SetDataOffset(XPTState *state, uint32_t data_offset)
state->data_offset = data_offset;
}
XPT_PUBLIC_API(PRBool)
XPT_PUBLIC_API(bool)
XPT_MakeCursor(XPTState *state, XPTPool pool, uint32_t len,
NotNull<XPTCursor*> cursor)
{
@ -63,53 +63,53 @@ XPT_MakeCursor(XPTState *state, XPTPool pool, uint32_t len,
cursor->offset = state->next_cursor[pool];
if (!(CHECK_COUNT(cursor, len)))
return PR_FALSE;
return false;
/* this check should be in CHECK_CURSOR */
if (pool == XPT_DATA && !state->data_offset) {
fprintf(stderr, "no data offset for XPT_DATA cursor!\n");
return PR_FALSE;
return false;
}
state->next_cursor[pool] += len;
return PR_TRUE;
return true;
}
XPT_PUBLIC_API(PRBool)
XPT_PUBLIC_API(bool)
XPT_SeekTo(NotNull<XPTCursor*> cursor, uint32_t offset)
{
/* XXX do some real checking and update len and stuff */
cursor->offset = offset;
return PR_TRUE;
return true;
}
XPT_PUBLIC_API(PRBool)
XPT_PUBLIC_API(bool)
XPT_SkipStringInline(NotNull<XPTCursor*> cursor)
{
uint16_t length;
if (!XPT_Do16(cursor, &length))
return PR_FALSE;
return false;
uint8_t byte;
for (uint16_t i = 0; i < length; i++)
if (!XPT_Do8(cursor, &byte))
return PR_FALSE;
return false;
return PR_TRUE;
return true;
}
XPT_PUBLIC_API(PRBool)
XPT_PUBLIC_API(bool)
XPT_DoCString(XPTArena *arena, NotNull<XPTCursor*> cursor, char **identp,
bool ignore)
{
uint32_t offset = 0;
if (!XPT_Do32(cursor, &offset))
return PR_FALSE;
return false;
if (!offset) {
*identp = NULL;
return PR_TRUE;
return true;
}
XPTCursor my_cursor;
@ -121,7 +121,7 @@ XPT_DoCString(XPTArena *arena, NotNull<XPTCursor*> cursor, char **identp,
char* end = strchr(start, 0); /* find the end of the string */
if (!end) {
fprintf(stderr, "didn't find end of string on decode!\n");
return PR_FALSE;
return false;
}
int len = end - start;
XPT_ASSERT(len > 0);
@ -129,14 +129,14 @@ XPT_DoCString(XPTArena *arena, NotNull<XPTCursor*> cursor, char **identp,
if (!ignore) {
char *ident = (char*)XPT_CALLOC1(arena, len + 1u);
if (!ident)
return PR_FALSE;
return false;
memcpy(ident, start, (size_t)len);
ident[len] = 0;
*identp = ident;
}
return PR_TRUE;
return true;
}
/*
@ -152,7 +152,7 @@ XPT_DoCString(XPTArena *arena, NotNull<XPTCursor*> cursor, char **identp,
*
* (http://www.mozilla.org/scriptable/typelib_file.html#iid)
*/
XPT_PUBLIC_API(PRBool)
XPT_PUBLIC_API(bool)
XPT_DoIID(NotNull<XPTCursor*> cursor, nsID *iidp)
{
int i;
@ -160,16 +160,16 @@ XPT_DoIID(NotNull<XPTCursor*> cursor, nsID *iidp)
if (!XPT_Do32(cursor, &iidp->m0) ||
!XPT_Do16(cursor, &iidp->m1) ||
!XPT_Do16(cursor, &iidp->m2))
return PR_FALSE;
return false;
for (i = 0; i < 8; i++)
if (!XPT_Do8(cursor, (uint8_t *)&iidp->m3[i]))
return PR_FALSE;
return false;
return PR_TRUE;
return true;
}
XPT_PUBLIC_API(PRBool)
XPT_PUBLIC_API(bool)
XPT_Do64(NotNull<XPTCursor*> cursor, int64_t *u64p)
{
return XPT_Do32(cursor, (uint32_t *)u64p) &&
@ -182,7 +182,7 @@ XPT_Do64(NotNull<XPTCursor*> cursor, int64_t *u64p)
* well-aligned cases and do a single store, if they cared. I might care
* later.
*/
XPT_PUBLIC_API(PRBool)
XPT_PUBLIC_API(bool)
XPT_Do32(NotNull<XPTCursor*> cursor, uint32_t *u32p)
{
union {
@ -191,7 +191,7 @@ XPT_Do32(NotNull<XPTCursor*> cursor, uint32_t *u32p)
} u;
if (!CHECK_COUNT(cursor, 4))
return PR_FALSE;
return false;
u.b8[0] = CURS_POINT(cursor);
cursor->offset++;
@ -203,10 +203,10 @@ XPT_Do32(NotNull<XPTCursor*> cursor, uint32_t *u32p)
*u32p = XPT_SWAB32(u.b32);
cursor->offset++;
return PR_TRUE;
return true;
}
XPT_PUBLIC_API(PRBool)
XPT_PUBLIC_API(bool)
XPT_Do16(NotNull<XPTCursor*> cursor, uint16_t *u16p)
{
union {
@ -215,7 +215,7 @@ XPT_Do16(NotNull<XPTCursor*> cursor, uint16_t *u16p)
} u;
if (!CHECK_COUNT(cursor, 2))
return PR_FALSE;
return false;
u.b8[0] = CURS_POINT(cursor);
cursor->offset++;
@ -224,20 +224,20 @@ XPT_Do16(NotNull<XPTCursor*> cursor, uint16_t *u16p)
cursor->offset++;
return PR_TRUE;
return true;
}
XPT_PUBLIC_API(PRBool)
XPT_PUBLIC_API(bool)
XPT_Do8(NotNull<XPTCursor*> cursor, uint8_t *u8p)
{
if (!CHECK_COUNT(cursor, 1))
return PR_FALSE;
return false;
*u8p = CURS_POINT(cursor);
cursor->offset++;
return PR_TRUE;
return true;
}

View File

@ -22,29 +22,29 @@ extern "C" {
typedef struct XPTState XPTState;
typedef struct XPTCursor XPTCursor;
extern XPT_PUBLIC_API(PRBool)
extern XPT_PUBLIC_API(bool)
XPT_SkipStringInline(NotNull<XPTCursor*> cursor);
extern XPT_PUBLIC_API(PRBool)
extern XPT_PUBLIC_API(bool)
XPT_DoCString(XPTArena *arena, NotNull<XPTCursor*> cursor, char **strp,
bool ignore = false);
extern XPT_PUBLIC_API(PRBool)
extern XPT_PUBLIC_API(bool)
XPT_DoIID(NotNull<XPTCursor*> cursor, nsID *iidp);
extern XPT_PUBLIC_API(PRBool)
extern XPT_PUBLIC_API(bool)
XPT_Do64(NotNull<XPTCursor*> cursor, int64_t *u64p);
extern XPT_PUBLIC_API(PRBool)
extern XPT_PUBLIC_API(bool)
XPT_Do32(NotNull<XPTCursor*> cursor, uint32_t *u32p);
extern XPT_PUBLIC_API(PRBool)
extern XPT_PUBLIC_API(bool)
XPT_Do16(NotNull<XPTCursor*> cursor, uint16_t *u16p);
extern XPT_PUBLIC_API(PRBool)
extern XPT_PUBLIC_API(bool)
XPT_Do8(NotNull<XPTCursor*> cursor, uint8_t *u8p);
extern XPT_PUBLIC_API(PRBool)
extern XPT_PUBLIC_API(bool)
XPT_DoHeader(XPTArena *arena, NotNull<XPTCursor*> cursor, XPTHeader **headerp);
typedef enum {
@ -69,11 +69,11 @@ struct XPTCursor {
extern XPT_PUBLIC_API(void)
XPT_InitXDRState(XPTState* state, char* data, uint32_t len);
extern XPT_PUBLIC_API(PRBool)
extern XPT_PUBLIC_API(bool)
XPT_MakeCursor(XPTState *state, XPTPool pool, uint32_t len,
NotNull<XPTCursor*> cursor);
extern XPT_PUBLIC_API(PRBool)
extern XPT_PUBLIC_API(bool)
XPT_SeekTo(NotNull<XPTCursor*> cursor, uint32_t offset);
extern XPT_PUBLIC_API(void)