Bug 1442363, part 5 - Constify XPTInterfaceDescriptor::method_descriptors. draft
authorAndrew McCreight <continuation@gmail.com>
Tue, 27 Feb 2018 15:28:16 -0800
changeset 762232 cf15e89688bedf2f0b69403dda94f6b0a891ed00
parent 762231 0ef22db38154bec122d76f7d9d9b308d3959b8d0
child 762233 cbb700837d8104d18e5c7f7ce84794b7620fe11f
push id101107
push userbmo:continuation@gmail.com
push dateThu, 01 Mar 2018 22:22:59 +0000
bugs1442363
milestone60.0a1
Bug 1442363, part 5 - Constify XPTInterfaceDescriptor::method_descriptors. MozReview-Commit-ID: EtPmwxboaq9
xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
xpcom/typelib/xpt/xpt_struct.cpp
xpcom/typelib/xpt/xpt_struct.h
--- a/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
+++ b/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
@@ -80,17 +80,17 @@ xptiInterfaceEntry::ResolveLocked()
             return false;
         }
 
         mParent = parent;
         if (parent->GetHasNotXPCOMFlag()) {
             SetHasNotXPCOMFlag();
         } else {
             for (uint16_t idx = 0; idx < mDescriptor->num_methods; ++idx) {
-                nsXPTMethodInfo* method = reinterpret_cast<nsXPTMethodInfo*>(
+                const nsXPTMethodInfo* method = reinterpret_cast<const nsXPTMethodInfo*>(
                     mDescriptor->method_descriptors + idx);
                 if (method->IsNotXPCOM()) {
                     SetHasNotXPCOMFlag();
                     break;
                 }
             }
         }
 
@@ -185,33 +185,33 @@ xptiInterfaceEntry::GetMethodInfo(uint16
                 mDescriptor->num_methods)
     {
         NS_ERROR("bad param");
         *info = nullptr;
         return NS_ERROR_INVALID_ARG;
     }
 
     // else...
-    *info = reinterpret_cast<nsXPTMethodInfo*>
+    *info = reinterpret_cast<const nsXPTMethodInfo*>
        (&mDescriptor->method_descriptors[index - mMethodBaseIndex]);
     return NS_OK;
 }
 
 nsresult
 xptiInterfaceEntry::GetMethodInfoForName(const char* methodName, uint16_t *index,
                                          const nsXPTMethodInfo** result)
 {
     if(!EnsureResolved())
         return NS_ERROR_UNEXPECTED;
 
     // This is a slow algorithm, but this is not expected to be called much.
     for(uint16_t i = 0; i < mDescriptor->num_methods; ++i)
     {
         const nsXPTMethodInfo* info;
-        info = reinterpret_cast<nsXPTMethodInfo*>
+        info = reinterpret_cast<const nsXPTMethodInfo*>
                                (&mDescriptor->
                                         method_descriptors[i]);
         if (PL_strcmp(methodName, info->GetName()) == 0) {
             *index = i + mMethodBaseIndex;
             *result = info;
             return NS_OK;
         }
     }
--- a/xpcom/typelib/xpt/xpt_struct.cpp
+++ b/xpcom/typelib/xpt/xpt_struct.cpp
@@ -254,29 +254,33 @@ DoInterfaceDescriptor(XPTArena *arena, N
         *idp = NULL;
         return true;
     }
     if(!XPT_Do16(cursor, &id->parent_interface) ||
        !XPT_Do16(cursor, &id->num_methods)) {
         return false;
     }
 
+    XPTMethodDescriptor* method_descriptors = nullptr;
+
     if (id->num_methods) {
         size_t n = id->num_methods * sizeof(XPTMethodDescriptor);
-        id->method_descriptors =
+        method_descriptors =
             static_cast<XPTMethodDescriptor*>(XPT_CALLOC8(arena, n));
-        if (!id->method_descriptors)
+        if (!method_descriptors)
             return false;
     }
 
     for (i = 0; i < id->num_methods; i++) {
-        if (!DoMethodDescriptor(arena, cursor, &id->method_descriptors[i], id))
+        if (!DoMethodDescriptor(arena, cursor, &method_descriptors[i], id))
             return false;
     }
 
+    id->method_descriptors = method_descriptors;
+
     if (!XPT_Do16(cursor, &id->num_constants)) {
         return false;
     }
 
     if (id->num_constants) {
         size_t n = id->num_constants * sizeof(XPTConstDescriptor);
         id->const_descriptors =
             static_cast<XPTConstDescriptor*>(XPT_CALLOC8(arena, n));
--- a/xpcom/typelib/xpt/xpt_struct.h
+++ b/xpcom/typelib/xpt/xpt_struct.h
@@ -96,17 +96,17 @@ struct XPTInterfaceDescriptor {
   bool IsBuiltinClass() const { return !!(flags & kBuiltinClassMask); }
   bool IsMainProcessScriptableOnly() const { return !!(flags & kMainProcessScriptableOnlyMask); }
 
   /*
    * This field ordering minimizes the size of this struct.
    * The fields are serialized on disk in a different order.
    * See DoInterfaceDescriptor().
    */
-  XPTMethodDescriptor* method_descriptors;
+  const XPTMethodDescriptor* method_descriptors;
   XPTConstDescriptor* const_descriptors;
   XPTTypeDescriptor* additional_types;
   uint16_t parent_interface;
   uint16_t num_methods;
   uint16_t num_constants;
   uint8_t flags;
 
   /*