Bug 1442363, part 2 - Constify XPTHeader::interface_directory. draft
authorAndrew McCreight <continuation@gmail.com>
Tue, 27 Feb 2018 15:08:42 -0800
changeset 762229 378a7eb3777ed8cc8eacbbf9dea199f9f868ffc9
parent 762228 993eeafa1f11e1055081ed0082e56551b66120c2
child 762230 70d8cd6c830731b9fae513120e32f45cc1e7b1ca
push id101107
push userbmo:continuation@gmail.com
push dateThu, 01 Mar 2018 22:22:59 +0000
bugs1442363
milestone60.0a1
Bug 1442363, part 2 - Constify XPTHeader::interface_directory. MozReview-Commit-ID: 3oLZFtXBsV8
xpcom/reflect/xptinfo/XPTInterfaceInfoManager.h
xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
xpcom/reflect/xptinfo/xptiTypelibGuts.cpp
xpcom/typelib/xpt/xpt_struct.cpp
xpcom/typelib/xpt/xpt_struct.h
--- a/xpcom/reflect/xptinfo/XPTInterfaceInfoManager.h
+++ b/xpcom/reflect/xptinfo/XPTInterfaceInfoManager.h
@@ -55,17 +55,17 @@ private:
     XPTInterfaceInfoManager();
     ~XPTInterfaceInfoManager();
 
     void InitMemoryReporter();
 
     void RegisterXPTHeader(const XPTHeader* aHeader);
 
     // idx is the index of this interface in the XPTHeader
-    void VerifyAndAddEntryIfNew(XPTInterfaceDirectoryEntry* iface,
+    void VerifyAndAddEntryIfNew(const XPTInterfaceDirectoryEntry* iface,
                                 uint16_t idx,
                                 xptiTypelibGuts* typelib);
 
 private:
 
     class xptiWorkingSet
     {
     public:
--- a/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
+++ b/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
@@ -126,17 +126,17 @@ XPTInterfaceInfoManager::RegisterXPTHead
     xptiTypelibGuts* typelib = xptiTypelibGuts::Create(aHeader);
 
     ReentrantMonitorAutoEnter monitor(mWorkingSet.mTableReentrantMonitor);
     for(uint16_t k = 0; k < aHeader->num_interfaces; k++)
         VerifyAndAddEntryIfNew(aHeader->interface_directory + k, k, typelib);
 }
 
 void
-XPTInterfaceInfoManager::VerifyAndAddEntryIfNew(XPTInterfaceDirectoryEntry* iface,
+XPTInterfaceInfoManager::VerifyAndAddEntryIfNew(const XPTInterfaceDirectoryEntry* iface,
                                                 uint16_t idx,
                                                 xptiTypelibGuts* typelib)
 {
     if (!iface->interface_descriptor)
         return;
 
     // The number of maximum methods is not arbitrary. It is the same value as
     // in xpcom/reflect/xptcall/genstubs.pl; do not change this value
--- a/xpcom/reflect/xptinfo/xptiTypelibGuts.cpp
+++ b/xpcom/reflect/xptinfo/xptiTypelibGuts.cpp
@@ -39,17 +39,17 @@ xptiTypelibGuts::GetEntryAt(uint16_t i)
 
     NS_ASSERTION(mHeader, "bad state");
     NS_ASSERTION(i < GetEntryCount(), "bad index");
 
     xptiInterfaceEntry* r = mEntryArray[i];
     if (r)
         return r;
 
-    XPTInterfaceDirectoryEntry* iface = mHeader->interface_directory + i;
+    const XPTInterfaceDirectoryEntry* iface = mHeader->interface_directory + i;
 
     XPTInterfaceInfoManager::xptiWorkingSet& set =
         XPTInterfaceInfoManager::GetSingleton()->mWorkingSet;
 
     {
         ReentrantMonitorAutoEnter monitor(set.mTableReentrantMonitor);
         if (iface->iid.Equals(zeroIID))
             r = set.mNameTable.Get(iface->name);
@@ -64,12 +64,12 @@ xptiTypelibGuts::GetEntryAt(uint16_t i)
 }
 
 const char*
 xptiTypelibGuts::GetEntryNameAt(uint16_t i)
 {
     NS_ASSERTION(mHeader, "bad state");
     NS_ASSERTION(i < GetEntryCount(), "bad index");
 
-    XPTInterfaceDirectoryEntry* iface = mHeader->interface_directory + i;
+    const XPTInterfaceDirectoryEntry* iface = mHeader->interface_directory + i;
 
     return iface->name;
 }
--- a/xpcom/typelib/xpt/xpt_struct.cpp
+++ b/xpcom/typelib/xpt/xpt_struct.cpp
@@ -141,21 +141,23 @@ XPT_DoHeader(XPTArena *arena, NotNull<XP
     }
 
     uint32_t data_pool;
     if (!XPT_Do32(cursor, &data_pool))
         return false;
 
     XPT_SetDataOffset(cursor->state, data_pool);
 
+    XPTInterfaceDirectoryEntry* interface_directory = nullptr;
+
     if (header->num_interfaces) {
         size_t n = header->num_interfaces * sizeof(XPTInterfaceDirectoryEntry);
-        header->interface_directory =
+        interface_directory =
             static_cast<XPTInterfaceDirectoryEntry*>(XPT_CALLOC8(arena, n));
-        if (!header->interface_directory)
+        if (!interface_directory)
             return false;
     }
 
     /*
      * Iterate through the annotations rather than recurring, to avoid blowing
      * the stack on large xpt files. We don't actually store annotations, we
      * just skip over them.
      */
@@ -165,20 +167,22 @@ XPT_DoHeader(XPTArena *arena, NotNull<XP
             return false;
     } while (!isLast);
 
     /* shouldn't be necessary now, but maybe later */
     XPT_SeekTo(cursor, ide_offset);
 
     for (i = 0; i < header->num_interfaces; i++) {
         if (!DoInterfaceDirectoryEntry(arena, cursor,
-                                       &header->interface_directory[i]))
+                                       &interface_directory[i]))
             return false;
     }
 
+    header->interface_directory = interface_directory;
+
     return true;
 }
 
 /* InterfaceDirectoryEntry records go in the header */
 bool
 DoInterfaceDirectoryEntry(XPTArena *arena, NotNull<XPTCursor*> cursor,
                           XPTInterfaceDirectoryEntry *ide)
 {
--- a/xpcom/typelib/xpt/xpt_struct.h
+++ b/xpcom/typelib/xpt/xpt_struct.h
@@ -43,17 +43,17 @@ struct XPTHeader {
   // stored in memory (other than very briefly, which can be done with local
   // variables).
 
   //uint8_t magic[16];
   uint8_t major_version;
   //uint8_t minor_version;
   uint16_t num_interfaces;
   //uint32_t file_length;
-  XPTInterfaceDirectoryEntry* interface_directory;
+  const XPTInterfaceDirectoryEntry* interface_directory;
   //uint32_t data_pool;
 };
 
 /*
  * Any file with a major version number of XPT_MAJOR_INCOMPATIBLE_VERSION
  * or higher is to be considered incompatible by this version of xpt and
  * we will refuse to read it. We will return a header with magic, major and
  * minor versions set from the file. num_interfaces will be set to zero to