Bug 1438707, part 3 - De-macroize CURS_POINT. r=njn draft
authorAndrew McCreight <continuation@gmail.com>
Wed, 14 Feb 2018 13:18:12 -0800
changeset 757289 a62b2ade9e8d445f11c23c69260f39a2b8d19753
parent 757288 2ae821377fa5403cc0178219aba9d5bbbda9e3a4
child 757290 f76d0838dbddcb2c4639a38011a5330469ea89e1
push id99743
push userbmo:continuation@gmail.com
push dateTue, 20 Feb 2018 17:05:54 +0000
reviewersnjn
bugs1438707
milestone60.0a1
Bug 1438707, part 3 - De-macroize CURS_POINT. r=njn MozReview-Commit-ID: CVBGPRVSF7s
xpcom/typelib/xpt/xpt_xdr.cpp
--- a/xpcom/typelib/xpt/xpt_xdr.cpp
+++ b/xpcom/typelib/xpt/xpt_xdr.cpp
@@ -15,19 +15,21 @@
   ((cursor)->pool == XPT_HEADER                                               \
    ? (cursor)->offset                                                         \
    : (XPT_ASSERT((cursor)->state->data_offset),                               \
       (cursor)->offset + (cursor)->state->data_offset))
 
 #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 char*
+CursPoint(NotNull<XPTCursor*> cursor)
+{
+    return &cursor->state->pool_data[CURS_POOL_OFFSET(cursor)];
+}
 
 static bool
 CheckCount(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)) {
@@ -112,17 +114,17 @@ XPT_DoCString(XPTArena *arena, NotNull<X
         *identp = NULL;
         return true;
     }
 
     XPTCursor my_cursor;
     my_cursor.pool = XPT_DATA;
     my_cursor.offset = offset;
     my_cursor.state = cursor->state;
-    char* start = &CURS_POINT(&my_cursor);
+    char* start = CursPoint(WrapNotNull(&my_cursor));
 
     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 false;
     }
     int len = end - start;
     XPT_ASSERT(len > 0);
@@ -176,17 +178,17 @@ XPT_DoIID(NotNull<XPTCursor*> cursor, ns
 #define XPT_DOINT(T, func, valuep)                \
     do {                                          \
         const size_t sz = sizeof(T);              \
                                                   \
         if (!CheckCount(cursor, sz)) {            \
             return false;                         \
         }                                         \
                                                   \
-        *valuep = func(&CURS_POINT(cursor));      \
+        *valuep = func(CursPoint(cursor));        \
         cursor->offset += sz;                     \
         return true;                              \
     } while(0)
 
 bool
 XPT_Do64(NotNull<XPTCursor*> cursor, int64_t *u64p)
 {
     XPT_DOINT(int64_t, mozilla::BigEndian::readInt64, u64p);
@@ -213,16 +215,16 @@ XPT_Do16(NotNull<XPTCursor*> cursor, uin
 #undef XPT_DOINT
 
 bool
 XPT_Do8(NotNull<XPTCursor*> cursor, uint8_t *u8p)
 {
     if (!CheckCount(cursor, 1))
         return false;
 
-    *u8p = CURS_POINT(cursor);
+    *u8p = *CursPoint(cursor);
 
     cursor->offset++;
 
     return true;
 }