Bug 1272203 (part 4) - Use NotNull for XPTCursor. r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 27 May 2016 09:49:26 +1000
changeset 338461 a797b1192ac89f6f11049e2ea6d87dd66fb1cedc
parent 338460 c329d2652ad52f3261db1cc8bdbe4d68a220ab19
child 338462 bc8ea177c0d8303861f04c6009582acf40c692bb
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1272203
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1272203 (part 4) - Use NotNull for XPTCursor. r=froydnj. This is a nice example of using NotNull for a single non-null pointer that gets passed around lots of different functions.
xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
xpcom/typelib/xpt/xpt_struct.cpp
xpcom/typelib/xpt/xpt_xdr.cpp
xpcom/typelib/xpt/xpt_xdr.h
--- a/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
+++ b/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
@@ -97,23 +97,24 @@ XPTInterfaceInfoManager::InitMemoryRepor
 }
 
 void
 XPTInterfaceInfoManager::RegisterBuffer(char *buf, uint32_t length)
 {
     XPTState state;
     XPT_InitXDRState(&state, buf, length);
 
-    XPTCursor cursor;
-    if (!XPT_MakeCursor(&state, XPT_HEADER, 0, &cursor)) {
+    XPTCursor curs;
+    NotNull<XPTCursor*> cursor = WrapNotNull(&curs);
+    if (!XPT_MakeCursor(&state, XPT_HEADER, 0, cursor)) {
         return;
     }
 
     XPTHeader *header = nullptr;
-    if (XPT_DoHeader(gXPTIStructArena, &cursor, &header)) {
+    if (XPT_DoHeader(gXPTIStructArena, cursor, &header)) {
         RegisterXPTHeader(header);
     }
 }
 
 void
 XPTInterfaceInfoManager::RegisterXPTHeader(XPTHeader* aHeader)
 {
     if (aHeader->major_version >= XPT_MAJOR_INCOMPATIBLE_VERSION) {
--- a/xpcom/typelib/xpt/xpt_struct.cpp
+++ b/xpcom/typelib/xpt/xpt_struct.cpp
@@ -5,52 +5,56 @@
 
 /* Implementation of XDR routines for typelib structures. */
 
 #include "xpt_xdr.h"
 #include "xpt_struct.h"
 #include <string.h>
 #include <stdio.h>
 
+using mozilla::WrapNotNull;
+
 /***************************************************************************/
 /* Forward declarations. */
 
 static PRBool
-DoInterfaceDirectoryEntry(XPTArena *arena, XPTCursor *cursor,
+DoInterfaceDirectoryEntry(XPTArena *arena, NotNull<XPTCursor*> cursor,
                           XPTInterfaceDirectoryEntry *ide);
 
 static PRBool
-DoConstDescriptor(XPTArena *arena, XPTCursor *cursor, XPTConstDescriptor *cd,
-                  XPTInterfaceDescriptor *id);
+DoConstDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
+                  XPTConstDescriptor *cd, XPTInterfaceDescriptor *id);
 
 static PRBool
-DoMethodDescriptor(XPTArena *arena, XPTCursor *cursor, XPTMethodDescriptor *md, 
-                   XPTInterfaceDescriptor *id);
+DoMethodDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
+                   XPTMethodDescriptor *md, XPTInterfaceDescriptor *id);
 
 static PRBool
-SkipAnnotation(XPTCursor *cursor, bool *isLast);
+SkipAnnotation(NotNull<XPTCursor*> cursor, bool *isLast);
 
 static PRBool
-DoInterfaceDescriptor(XPTArena *arena, XPTCursor *outer, XPTInterfaceDescriptor **idp);
-
-static PRBool
-DoTypeDescriptorPrefix(XPTArena *arena, XPTCursor *cursor, XPTTypeDescriptorPrefix *tdp);
+DoInterfaceDescriptor(XPTArena *arena, NotNull<XPTCursor*> outer,
+                      XPTInterfaceDescriptor **idp);
 
 static PRBool
-DoTypeDescriptor(XPTArena *arena, XPTCursor *cursor, XPTTypeDescriptor *td,
-                 XPTInterfaceDescriptor *id);
+DoTypeDescriptorPrefix(XPTArena *arena, NotNull<XPTCursor*> cursor,
+                       XPTTypeDescriptorPrefix *tdp);
 
 static PRBool
-DoParamDescriptor(XPTArena *arena, XPTCursor *cursor, XPTParamDescriptor *pd,
-                  XPTInterfaceDescriptor *id);
+DoTypeDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
+                 XPTTypeDescriptor *td, XPTInterfaceDescriptor *id);
+
+static PRBool
+DoParamDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
+                  XPTParamDescriptor *pd, XPTInterfaceDescriptor *id);
 
 /***************************************************************************/
 
 XPT_PUBLIC_API(PRBool)
-XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp)
+XPT_DoHeader(XPTArena *arena, NotNull<XPTCursor*> cursor, XPTHeader **headerp)
 {
     unsigned int i;
     uint32_t file_length = 0;
     uint32_t ide_offset;
 
     XPTHeader* header = XPT_NEWZAP(arena, XPTHeader);
     if (!header)
         return PR_FALSE;
@@ -135,17 +139,17 @@ XPT_DoHeader(XPTArena *arena, XPTCursor 
             return PR_FALSE;
     }
     
     return PR_TRUE;
 }   
 
 /* InterfaceDirectoryEntry records go in the header */
 PRBool
-DoInterfaceDirectoryEntry(XPTArena *arena, XPTCursor *cursor,
+DoInterfaceDirectoryEntry(XPTArena *arena, NotNull<XPTCursor*> cursor,
                           XPTInterfaceDirectoryEntry *ide)
 {
     char* dummy_name_space;
 
     /* 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
@@ -185,21 +189,22 @@ InterfaceDescriptorAddTypes(XPTArena *ar
     if (num + uint16_t(id->num_additional_types) > 256)
         return PR_FALSE;
 
     id->num_additional_types += num;
     return PR_TRUE;
 }
 
 PRBool
-DoInterfaceDescriptor(XPTArena *arena, XPTCursor *outer, 
+DoInterfaceDescriptor(XPTArena *arena, NotNull<XPTCursor*> outer,
                       XPTInterfaceDescriptor **idp)
 {
     XPTInterfaceDescriptor *id;
-    XPTCursor curs, *cursor = &curs;
+    XPTCursor curs;
+    NotNull<XPTCursor*> cursor = WrapNotNull(&curs);
     uint32_t i, id_sz = 0;
 
     id = XPT_NEWZAP(arena, XPTInterfaceDescriptor);
     if (!id)
         return PR_FALSE;
     *idp = id;
 
     if (!XPT_MakeCursor(outer->state, XPT_DATA, id_sz, cursor))
@@ -250,18 +255,18 @@ DoInterfaceDescriptor(XPTArena *arena, X
     if (!XPT_Do8(cursor, &id->flags)) {
         return PR_FALSE;
     }
 
     return PR_TRUE;
 }
 
 PRBool
-DoConstDescriptor(XPTArena *arena, XPTCursor *cursor, XPTConstDescriptor *cd,
-                  XPTInterfaceDescriptor *id)
+DoConstDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
+                  XPTConstDescriptor *cd, XPTInterfaceDescriptor *id)
 {
     PRBool ok = PR_FALSE;
 
     if (!XPT_DoCString(arena, cursor, &cd->name) ||
         !DoTypeDescriptor(arena, cursor, &cd->type, id)) {
 
         return PR_FALSE;
     }
@@ -303,18 +308,18 @@ DoConstDescriptor(XPTArena *arena, XPTCu
         break;
     }
 
     return ok;
 
 }
 
 PRBool
-DoMethodDescriptor(XPTArena *arena, XPTCursor *cursor, XPTMethodDescriptor *md,
-                   XPTInterfaceDescriptor *id)
+DoMethodDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
+                   XPTMethodDescriptor *md, XPTInterfaceDescriptor *id)
 {
     int i;
 
     if (!XPT_Do8(cursor, &md->flags) ||
         !XPT_DoCString(arena, cursor, &md->name) ||
         !XPT_Do8(cursor, &md->num_args))
         return PR_FALSE;
 
@@ -332,35 +337,36 @@ DoMethodDescriptor(XPTArena *arena, XPTC
     
     if (!DoParamDescriptor(arena, cursor, &md->result, id))
         return PR_FALSE;
     
     return PR_TRUE;
 }
 
 PRBool
-DoParamDescriptor(XPTArena *arena, XPTCursor *cursor, XPTParamDescriptor *pd, 
-                  XPTInterfaceDescriptor *id)
+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;
 }
 
 PRBool
-DoTypeDescriptorPrefix(XPTArena *arena, XPTCursor *cursor, XPTTypeDescriptorPrefix *tdp)
+DoTypeDescriptorPrefix(XPTArena *arena, NotNull<XPTCursor*> cursor,
+                       XPTTypeDescriptorPrefix *tdp)
 {
     return XPT_Do8(cursor, &tdp->flags);
 }
 
 PRBool
-DoTypeDescriptor(XPTArena *arena, XPTCursor *cursor, XPTTypeDescriptor *td,
-                 XPTInterfaceDescriptor *id)
+DoTypeDescriptor(XPTArena *arena, NotNull<XPTCursor*> cursor,
+                 XPTTypeDescriptor *td, XPTInterfaceDescriptor *id)
 {
     if (!DoTypeDescriptorPrefix(arena, cursor, &td->prefix)) {
         return PR_FALSE;
     }
     
     switch (XPT_TDP_TAG(td->prefix)) {
       case TD_INTERFACE_TYPE:
         uint16_t iface;
@@ -402,17 +408,17 @@ DoTypeDescriptor(XPTArena *arena, XPTCur
       default:
         /* nothing special */
         break;
     }
     return PR_TRUE;
 }
 
 PRBool
-SkipAnnotation(XPTCursor *cursor, bool *isLast)
+SkipAnnotation(NotNull<XPTCursor*> cursor, bool *isLast)
 {
     uint8_t flags;
     if (!XPT_Do8(cursor, &flags))
         return PR_FALSE;
 
     *isLast = XPT_ANN_IS_LAST(flags);
 
     if (XPT_ANN_IS_PRIVATE(flags)) {
--- a/xpcom/typelib/xpt/xpt_xdr.cpp
+++ b/xpcom/typelib/xpt/xpt_xdr.cpp
@@ -19,17 +19,17 @@
 #define CURS_POOL_OFFSET(cursor)                                              \
   (CURS_POOL_OFFSET_RAW(cursor) - 1)
 
 /* can be used as lvalue */
 #define CURS_POINT(cursor)                                                    \
   ((cursor)->state->pool_data[CURS_POOL_OFFSET(cursor)])
 
 static PRBool
-CHECK_COUNT(XPTCursor* cursor, uint32_t space)
+CHECK_COUNT(NotNull<XPTCursor*> cursor, uint32_t space)
 {
     // Fail if we're in the data area and about to exceed the allocation.
     // XXX Also fail if we're in the data area and !state->data_offset
     if (cursor->pool == XPT_DATA &&
         (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;
@@ -49,17 +49,18 @@ XPT_InitXDRState(XPTState* state, char *
 /* All offsets are 1-based */
 XPT_PUBLIC_API(void)
 XPT_SetDataOffset(XPTState *state, uint32_t data_offset)
 {
    state->data_offset = data_offset;
 }
 
 XPT_PUBLIC_API(PRBool)
-XPT_MakeCursor(XPTState *state, XPTPool pool, uint32_t len, XPTCursor *cursor)
+XPT_MakeCursor(XPTState *state, XPTPool pool, uint32_t len,
+               NotNull<XPTCursor*> cursor)
 {
     cursor->state = state;
     cursor->pool = pool;
     cursor->bits = 0;
     cursor->offset = state->next_cursor[pool];
 
     if (!(CHECK_COUNT(cursor, len)))
         return PR_FALSE;
@@ -71,40 +72,41 @@ XPT_MakeCursor(XPTState *state, XPTPool 
     }
 
     state->next_cursor[pool] += len;
 
     return PR_TRUE;
 }
 
 XPT_PUBLIC_API(PRBool)
-XPT_SeekTo(XPTCursor *cursor, uint32_t offset)
+XPT_SeekTo(NotNull<XPTCursor*> cursor, uint32_t offset)
 {
     /* XXX do some real checking and update len and stuff */
     cursor->offset = offset;
     return PR_TRUE;
 }
 
 XPT_PUBLIC_API(PRBool)
-XPT_SkipStringInline(XPTCursor *cursor)
+XPT_SkipStringInline(NotNull<XPTCursor*> cursor)
 {
     uint16_t length;
     if (!XPT_Do16(cursor, &length))
         return PR_FALSE;
 
     uint8_t byte;
     for (uint16_t i = 0; i < length; i++)
         if (!XPT_Do8(cursor, &byte))
             return PR_FALSE;
 
     return PR_TRUE;
 }
 
 XPT_PUBLIC_API(PRBool)
-XPT_DoCString(XPTArena *arena, XPTCursor *cursor, char **identp, bool ignore)
+XPT_DoCString(XPTArena *arena, NotNull<XPTCursor*> cursor, char **identp,
+              bool ignore)
 {
     uint32_t offset = 0;
     if (!XPT_Do32(cursor, &offset))
         return PR_FALSE;
 
     if (!offset) {
         *identp = NULL;
         return PR_TRUE;
@@ -146,47 +148,47 @@ XPT_DoCString(XPTArena *arena, XPTCursor
  *   is converted to the 128-bit value
  *     0x00112233445566778899aabbccddeeff
  *   Note that the byte storage order corresponds to the layout of the nsIID
  *   C-struct on a big-endian architecture."
  *
  * (http://www.mozilla.org/scriptable/typelib_file.html#iid)
  */
 XPT_PUBLIC_API(PRBool)
-XPT_DoIID(XPTCursor *cursor, nsID *iidp)
+XPT_DoIID(NotNull<XPTCursor*> cursor, nsID *iidp)
 {
     int i;
 
     if (!XPT_Do32(cursor, &iidp->m0) ||
         !XPT_Do16(cursor, &iidp->m1) ||
         !XPT_Do16(cursor, &iidp->m2))
         return PR_FALSE;
 
     for (i = 0; i < 8; i++)
         if (!XPT_Do8(cursor, (uint8_t *)&iidp->m3[i]))
             return PR_FALSE;
 
     return PR_TRUE;
 }
 
 XPT_PUBLIC_API(PRBool)
-XPT_Do64(XPTCursor *cursor, int64_t *u64p)
+XPT_Do64(NotNull<XPTCursor*> cursor, int64_t *u64p)
 {
     return XPT_Do32(cursor, (uint32_t *)u64p) &&
         XPT_Do32(cursor, ((uint32_t *)u64p) + 1);
 }
 
 /*
  * When we're handling 32- or 16-bit quantities, we handle a byte at a time to
  * avoid alignment issues.  Someone could come and optimize this to detect
  * well-aligned cases and do a single store, if they cared.  I might care
  * later.
  */
 XPT_PUBLIC_API(PRBool)
-XPT_Do32(XPTCursor *cursor, uint32_t *u32p)
+XPT_Do32(NotNull<XPTCursor*> cursor, uint32_t *u32p)
 {
     union {
         uint8_t b8[4];
         uint32_t b32;
     } u;
 
     if (!CHECK_COUNT(cursor, 4))
         return PR_FALSE;
@@ -200,17 +202,17 @@ XPT_Do32(XPTCursor *cursor, uint32_t *u3
     u.b8[3] = CURS_POINT(cursor);
     *u32p = XPT_SWAB32(u.b32);
 
     cursor->offset++;
     return PR_TRUE;
 }
 
 XPT_PUBLIC_API(PRBool)
-XPT_Do16(XPTCursor *cursor, uint16_t *u16p)
+XPT_Do16(NotNull<XPTCursor*> cursor, uint16_t *u16p)
 {
     union {
         uint8_t b8[2];
         uint16_t b16;
     } u;
 
     if (!CHECK_COUNT(cursor, 2))
         return PR_FALSE;
@@ -221,17 +223,17 @@ XPT_Do16(XPTCursor *cursor, uint16_t *u1
     *u16p = XPT_SWAB16(u.b16);
 
     cursor->offset++;
 
     return PR_TRUE;
 }
 
 XPT_PUBLIC_API(PRBool)
-XPT_Do8(XPTCursor *cursor, uint8_t *u8p)
+XPT_Do8(NotNull<XPTCursor*> cursor, uint8_t *u8p)
 {
     if (!CHECK_COUNT(cursor, 1))
         return PR_FALSE;
 
     *u8p = CURS_POINT(cursor);
 
     cursor->offset++;
 
--- a/xpcom/typelib/xpt/xpt_xdr.h
+++ b/xpcom/typelib/xpt/xpt_xdr.h
@@ -6,48 +6,51 @@
 /*
  * Basic APIs for streaming typelib structures from disk.
  */
 
 #ifndef __xpt_xdr_h__
 #define __xpt_xdr_h__
 
 #include "xpt_struct.h"
+#include "mozilla/NotNull.h"
+
+using mozilla::NotNull;
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 typedef struct XPTState         XPTState;
 typedef struct XPTCursor        XPTCursor;
 
 extern XPT_PUBLIC_API(PRBool)
-XPT_SkipStringInline(XPTCursor *cursor);
+XPT_SkipStringInline(NotNull<XPTCursor*> cursor);
 
 extern XPT_PUBLIC_API(PRBool)
-XPT_DoCString(XPTArena *arena, XPTCursor *cursor, char **strp,
+XPT_DoCString(XPTArena *arena, NotNull<XPTCursor*> cursor, char **strp,
               bool ignore = false);
 
 extern XPT_PUBLIC_API(PRBool)
-XPT_DoIID(XPTCursor *cursor, nsID *iidp);
+XPT_DoIID(NotNull<XPTCursor*> cursor, nsID *iidp);
 
 extern XPT_PUBLIC_API(PRBool)
-XPT_Do64(XPTCursor *cursor, int64_t *u64p);
+XPT_Do64(NotNull<XPTCursor*> cursor, int64_t *u64p);
 
 extern XPT_PUBLIC_API(PRBool)
-XPT_Do32(XPTCursor *cursor, uint32_t *u32p);
+XPT_Do32(NotNull<XPTCursor*> cursor, uint32_t *u32p);
 
 extern XPT_PUBLIC_API(PRBool)
-XPT_Do16(XPTCursor *cursor, uint16_t *u16p);
+XPT_Do16(NotNull<XPTCursor*> cursor, uint16_t *u16p);
 
 extern XPT_PUBLIC_API(PRBool)
-XPT_Do8(XPTCursor *cursor, uint8_t *u8p);
+XPT_Do8(NotNull<XPTCursor*> cursor, uint8_t *u8p);
 
 extern XPT_PUBLIC_API(PRBool)
-XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp);
+XPT_DoHeader(XPTArena *arena, NotNull<XPTCursor*> cursor, XPTHeader **headerp);
 
 typedef enum {
     XPT_HEADER = 0,
     XPT_DATA = 1
 } XPTPool;
 
 struct XPTState {
     uint32_t         data_offset;
@@ -62,20 +65,21 @@ struct XPTCursor {
     uint32_t    offset;
     uint8_t     bits;
 };
 
 extern XPT_PUBLIC_API(void)
 XPT_InitXDRState(XPTState* state, char* data, uint32_t len);
 
 extern XPT_PUBLIC_API(PRBool)
-XPT_MakeCursor(XPTState *state, XPTPool pool, uint32_t len, XPTCursor *cursor);
+XPT_MakeCursor(XPTState *state, XPTPool pool, uint32_t len,
+               NotNull<XPTCursor*> cursor);
 
 extern XPT_PUBLIC_API(PRBool)
-XPT_SeekTo(XPTCursor *cursor, uint32_t offset);
+XPT_SeekTo(NotNull<XPTCursor*> cursor, uint32_t offset);
 
 extern XPT_PUBLIC_API(void)
 XPT_SetDataOffset(XPTState *state, uint32_t data_offset);
 
 /* all data structures are big-endian */
 
 #if defined IS_BIG_ENDIAN
 #  define XPT_SWAB32(x) x