Bug 1442363, part 2 - Constify XPTHeader::interface_directory. r=njn
authorAndrew McCreight <continuation@gmail.com>
Tue, 27 Feb 2018 15:08:42 -0800
changeset 462073 6b7e0ca809e9f414d2832f026512184aa5b96be1
parent 462072 031309abee2cf74705007a7635dc07f1b5816919
child 462074 ae8424c2ac777a4a47044be35d73b3dc920dff80
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1442363
milestone60.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 1442363, part 2 - Constify XPTHeader::interface_directory. r=njn 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