Skip to content

Commit

Permalink
Bug 1438688, part 2 - Load XPT information from a static variable ins…
Browse files Browse the repository at this point in the history
…tead of a file. r=njn

This patch removes C++ code related to reading in XPT information from
files. (Code related to packaging XPT files will be removed in the
next patch.) This includes code in the manifest parser, in addition to
the actual code for parsing files.

XPT information is now loaded directly from a single static data
structure, XPTHeader::kHeader, which will be automatically generated
at compile time from .idl files (via .xpt files). Note that the script
to do that is not added until part 6 of this patch series, so linking
will fail on parts 2 through 5.

I inlined XPTInterfaceInfoManager::RegisterXPTHeader into the ctor,
because that is the only caller. It feels like the lock there should
not be needed any more, but I left it alone for now.

The forward declaration of XPTArena in xptiprivate.h is needed because
it was being bootlegged via xpt_xdr.h. Some of the data structures in
reflect/xptinfo/ (which wrap the xpt_struct.h data structures) are
still allocated using XPTArena. Hopefully we can get rid of that in
followup work.

I also deleted a lot of comments in xpt_struct.h that talk about the
on-disk format. I also deleted checking of the major version number,
because that should not matter when the XPT information is baked into
the executable.

MozReview-Commit-ID: 6NJdaCWRBhU
  • Loading branch information
amccreight committed Feb 28, 2018
1 parent da1c8fd commit b3d4e6f
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 953 deletions.
4 changes: 0 additions & 4 deletions xpcom/components/ManifestParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ static const ManifestDirective kParsingTable[] = {
"binary-component", 1, true, true, false, false, false,
&nsComponentManagerImpl::ManifestBinaryComponent, nullptr,
},
{
"interfaces", 1, false, true, false, false, false,
&nsComponentManagerImpl::ManifestXPT, nullptr,
},
{
"component", 2, false, true, false, false, false,
&nsComponentManagerImpl::ManifestComponent, nullptr,
Expand Down
34 changes: 0 additions & 34 deletions xpcom/components/nsComponentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
#include "nsDirectoryServiceDefs.h"
#include "nsCategoryManager.h"
#include "nsCategoryManagerUtils.h"
#include "xptiprivate.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/XPTInterfaceInfoManager.h"
#include "nsIConsoleService.h"
#include "nsIObserverService.h"
#include "nsISimpleEnumerator.h"
Expand All @@ -32,7 +30,6 @@
#include "nsReadableUtils.h"
#include "nsString.h"
#include "prcmon.h"
#include "xptinfo.h" // this after nsISupports, to pick up IID so that xpt stuff doesn't try to define it itself...
#include "nsThreadUtils.h"
#include "prthread.h"
#include "private/pprthred.h"
Expand Down Expand Up @@ -575,37 +572,6 @@ nsComponentManagerImpl::ManifestBinaryComponent(ManifestProcessingContext& aCx,
"Binary XPCOM components are no longer supported.");
}

static void
DoRegisterXPT(FileLocation& aFile)
{
uint32_t len;
FileLocation::Data data;
UniquePtr<char[]> buf;
nsresult rv = aFile.GetData(data);
if (NS_SUCCEEDED(rv)) {
rv = data.GetSize(&len);
}
if (NS_SUCCEEDED(rv)) {
buf = MakeUnique<char[]>(len);
rv = data.Copy(buf.get(), len);
}
if (NS_SUCCEEDED(rv)) {
XPTInterfaceInfoManager::GetSingleton()->RegisterBuffer(buf.get(), len);
} else {
nsCString uri;
aFile.GetURIString(uri);
LogMessage("Could not read '%s'.", uri.get());
}
}

void
nsComponentManagerImpl::ManifestXPT(ManifestProcessingContext& aCx,
int aLineNo, char* const* aArgv)
{
FileLocation f(aCx.mFile, aArgv[0]);
DoRegisterXPT(f);
}

void
nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& aCx,
int aLineNo, char* const* aArgv)
Expand Down
2 changes: 0 additions & 2 deletions xpcom/components/nsComponentManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,6 @@ class nsComponentManagerImpl final
char* const* aArgv);
void ManifestBinaryComponent(ManifestProcessingContext& aCx, int aLineNo,
char* const* aArgv);
void ManifestXPT(ManifestProcessingContext& aCx, int aLineNo,
char* const* aArgv);
void ManifestComponent(ManifestProcessingContext& aCx, int aLineNo,
char* const* aArgv);
void ManifestContract(ManifestProcessingContext& aCx, int aLineNo,
Expand Down
5 changes: 0 additions & 5 deletions xpcom/reflect/xptinfo/XPTInterfaceInfoManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

template<typename T> class nsCOMArray;
class nsIMemoryReporter;
struct XPTHeader;
struct XPTInterfaceDirectoryEntry;
class xptiInterfaceEntry;
class xptiInterfaceInfo;
Expand All @@ -40,8 +39,6 @@ class XPTInterfaceInfoManager final

void GetScriptableInterfaces(nsCOMArray<nsIInterfaceInfo>& aInterfaces);

void RegisterBuffer(char *buf, uint32_t length);

static Mutex& GetResolveLock()
{
return GetSingleton()->mResolveLock;
Expand All @@ -57,8 +54,6 @@ class XPTInterfaceInfoManager final

void InitMemoryReporter();

void RegisterXPTHeader(const XPTHeader* aHeader);

// idx is the index of this interface in the XPTHeader
void VerifyAndAddEntryIfNew(const XPTInterfaceDirectoryEntry* iface,
uint16_t idx,
Expand Down
38 changes: 6 additions & 32 deletions xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ XPTInterfaceInfoManager::XPTInterfaceInfoManager()
: mWorkingSet(),
mResolveLock("XPTInterfaceInfoManager.mResolveLock")
{
xptiTypelibGuts* typelib = xptiTypelibGuts::Create(&XPTHeader::kHeader);

ReentrantMonitorAutoEnter monitor(mWorkingSet.mTableReentrantMonitor);
for (uint16_t k = 0; k < XPTHeader::kHeader.mNumInterfaces; k++) {
VerifyAndAddEntryIfNew(XPTHeader::kHeader.mInterfaceDirectory + k, k, typelib);
}
}

XPTInterfaceInfoManager::~XPTInterfaceInfoManager()
Expand All @@ -97,38 +103,6 @@ XPTInterfaceInfoManager::InitMemoryReporter()
RegisterWeakMemoryReporter(this);
}

void
XPTInterfaceInfoManager::RegisterBuffer(char *buf, uint32_t length)
{
XPTState state;
XPT_InitXDRState(&state, buf, length);

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)) {
RegisterXPTHeader(header);
}
}

void
XPTInterfaceInfoManager::RegisterXPTHeader(const XPTHeader* aHeader)
{
if (aHeader->mMajorVersion >= XPT_MAJOR_INCOMPATIBLE_VERSION) {
MOZ_ASSERT(!aHeader->mNumInterfaces, "bad libxpt");
}

xptiTypelibGuts* typelib = xptiTypelibGuts::Create(aHeader);

ReentrantMonitorAutoEnter monitor(mWorkingSet.mTableReentrantMonitor);
for(uint16_t k = 0; k < aHeader->mNumInterfaces; k++)
VerifyAndAddEntryIfNew(aHeader->mInterfaceDirectory + k, k, typelib);
}

void
XPTInterfaceInfoManager::VerifyAndAddEntryIfNew(const XPTInterfaceDirectoryEntry* iface,
uint16_t idx,
Expand Down
2 changes: 1 addition & 1 deletion xpcom/reflect/xptinfo/xptiprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// this after nsISupports, to pick up IID
// so that xpt stuff doesn't try to define it itself...
#include "xpt_struct.h"
#include "xpt_xdr.h"

#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
Expand Down Expand Up @@ -62,6 +61,7 @@ class xptiInterfaceInfo;
class xptiInterfaceEntry;
class xptiTypelibGuts;

struct XPTArena;
extern XPTArena* gXPTIStructArena;

/***************************************************************************/
Expand Down
3 changes: 0 additions & 3 deletions xpcom/typelib/xpt/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ DIRS += ['tools']

UNIFIED_SOURCES += [
'xpt_arena.cpp',
'xpt_struct.cpp',
'xpt_xdr.cpp',
]

EXPORTS += [
'xpt_arena.h',
'xpt_struct.h',
'xpt_xdr.h',
]

FINAL_LIBRARY = 'xul'
Expand Down
Loading

0 comments on commit b3d4e6f

Please sign in to comment.