Fix XPCom on Mac so that autoregistration of .shlb files work.

This commit is contained in:
rjc%netscape.com 1999-02-18 00:24:38 +00:00
parent 58a218c757
commit 3c55ff2cfd
6 changed files with 210 additions and 28 deletions

View File

@ -25,6 +25,13 @@
#include <iostream.h>
#endif
#ifdef XP_MAC
#include <Files.h>
#include <Memory.h>
#include <Processes.h>
#include <TextUtils.h>
#endif
#include "plstr.h"
#include "prlink.h"
#include "prsystem.h"
@ -100,7 +107,7 @@ public:
nsIFactory *factory;
FactoryEntry(const nsCID &aClass, const char *aLibrary,
PRTime lastModTime, PRUint64 fileSize);
PRTime lastModTime, PRUint32 fileSize);
FactoryEntry(const nsCID &aClass, nsIFactory *aFactory);
~FactoryEntry();
// DO NOT DELETE THIS. Many FactoryEntry(s) could be sharing the same Dll.
@ -110,7 +117,7 @@ public:
};
FactoryEntry::FactoryEntry(const nsCID &aClass, const char *aLibrary,
PRTime lastModTime, PRUint64 fileSize)
PRTime lastModTime, PRUint32 fileSize)
: cid(aClass), factory(NULL), dll(NULL)
{
nsDllStore *dllCollection = nsRepository::dllStore;
@ -980,15 +987,71 @@ nsresult nsRepository::FreeLibraries(void)
nsresult nsRepository::AutoRegister(NSRegistrationInstant when,
const char* pathlist)
{
#ifdef XP_MAC
CInfoPBRec catInfo;
Handle pathH;
OSErr err;
ProcessSerialNumber psn;
ProcessInfoRec pInfo;
FSSpec appFSSpec;
long theDirID, oldLen, newLen;
Str255 name;
#endif
if (pathlist != NULL)
{
SyncComponentsInPathList(pathlist);
}
#ifdef XP_MAC
// get info for the the current process to determine the directory its located in
if (!(err = GetCurrentProcess(&psn)))
{
if (!(err = GetProcessInformation(&psn, &pInfo)))
{
appFSSpec = *(pInfo.processAppSpec);
if ((pathH = NewHandle(1)) != NULL)
{
**pathH = '\0'; // initially null terminate the string
HNoPurge(pathH);
HUnlock(pathH);
theDirID = appFSSpec.parID;
do
{
catInfo.dirInfo.ioCompletion = NULL;
catInfo.dirInfo.ioNamePtr = (StringPtr)&name;
catInfo.dirInfo.ioVRefNum = appFSSpec.vRefNum;
catInfo.dirInfo.ioDrDirID = theDirID;
catInfo.dirInfo.ioFDirIndex = -1; // -1 = query dir in ioDrDirID
if (!(err = PBGetCatInfoSync(&catInfo)))
{
// build up a Unix style pathname due to NSPR
// XXX Note: this breaks if any of the parent
// directories contain a "slash" (blame NSPR)
Munger(pathH, 0L, NULL, 0L, (const void *)&name[1], (long)name[0]); // prepend dir name
Munger(pathH, 0L, NULL, 0L, "/", 1); // prepend slash
// move up to parent directory
theDirID = catInfo.dirInfo.ioDrParID;
}
} while ((!err) && (catInfo.dirInfo.ioDrDirID != 2)); // 2 = root
if (!err)
{
HLock(pathH);
SyncComponentsInPathList((const char *)(*pathH));
HUnlock(pathH);
}
DisposeHandle(pathH);
}
}
}
#else
//XXX get default pathlist from registry
//XXX Temporary hack. Registering components from current directory
const char *defaultPathList = ".";
SyncComponentsInPathList(defaultPathList);
#endif
return (NS_OK);
}
@ -1031,7 +1094,7 @@ nsresult nsRepository::SyncComponentsInDir(const char *dir)
unsigned int n = strlen(fullname);
if (n+1 < sizeof(fullname))
{
fullname[n] = PR_GetDirectorySeparator();
fullname[n] = '/'; // PR_GetDirectorySeparator();
n++;
}
char *filepart = fullname + n;
@ -1058,18 +1121,19 @@ nsresult nsRepository::SyncComponentsInFile(const char *fullname)
".dso", /* Unix */
".so", /* Unix */
".sl", /* Unix: HP */
"_dll", /* Mac ? */
".shlb", /* Mac ? */
".dlm", /* new for all platforms */
NULL
};
PRFileInfo64 statbuf;
if (PR_GetFileInfo64(fullname, &statbuf) != PR_SUCCESS)
PRFileInfo statbuf;
if (PR_GetFileInfo(fullname,&statbuf) != PR_SUCCESS)
{
// Skip files that cannot be stat
return (NS_ERROR_FAILURE);
}
if (statbuf.type == PR_FILE_DIRECTORY)
{
// Cant register a directory
@ -1129,7 +1193,7 @@ nsresult nsRepository::SyncComponentsInFile(const char *fullname)
// We already have seen this dll. Check if this dll changed
if (LL_EQ(dll->GetLastModifiedTime(), statbuf.modifyTime) &&
LL_EQ(dll->GetSize(), statbuf.size))
(dll->GetSize() == statbuf.size))
{
// Dll hasn't changed. Skip.
PR_LOG(logmodule, PR_LOG_ALWAYS,

View File

@ -31,7 +31,7 @@ nsDll::nsDll(const char *libFullPath) : m_fullpath(NULL), m_instance(NULL),
m_status(DLL_OK)
{
m_lastModTime = LL_ZERO;
m_size = LL_ZERO;
m_size = 0;
if (libFullPath == NULL)
{
@ -46,8 +46,8 @@ nsDll::nsDll(const char *libFullPath) : m_fullpath(NULL), m_instance(NULL),
return;
}
PRFileInfo64 statinfo;
if (PR_GetFileInfo64(m_fullpath, &statinfo) != PR_SUCCESS)
PRFileInfo statinfo;
if (PR_GetFileInfo(m_fullpath, &statinfo) != PR_SUCCESS)
{
// The stat things works only if people pass in the full pathname.
// Even if our stat fails, we could be able to load it because of
@ -71,7 +71,7 @@ nsDll::nsDll(const char *libFullPath) : m_fullpath(NULL), m_instance(NULL),
}
nsDll::nsDll(const char *libFullPath, PRTime lastModTime, PRUint64 fileSize)
nsDll::nsDll(const char *libFullPath, PRTime lastModTime, PRUint32 fileSize)
: m_fullpath(NULL), m_instance(NULL), m_status(DLL_OK)
{
m_lastModTime = lastModTime;
@ -101,8 +101,15 @@ nsDll::~nsDll(void)
m_fullpath = NULL;
}
PRBool nsDll::Load(void)
{
#ifdef XP_MAC
char *macFileName = NULL;
OSErr err;
int loop;
#endif
if (m_status != DLL_OK)
{
return (PR_FALSE);
@ -112,7 +119,27 @@ PRBool nsDll::Load(void)
// Already loaded
return (PR_TRUE);
}
#ifdef XP_MAC
// err = ConvertUnixPathToMacPath(m_fullpath, &macFileName);
if ((macFileName = PL_strdup(m_fullpath)) != NULL)
{
if (macFileName[0] == '/')
{
for (loop=0; loop<PL_strlen(macFileName); loop++)
{
if (macFileName[loop] == '/') macFileName[loop] = ':';
}
m_instance = PR_LoadLibrary(&macFileName[1]); // skip over initial slash
}
else
{
m_instance = PR_LoadLibrary(macFileName);
}
}
#else
m_instance = PR_LoadLibrary(m_fullpath);
#endif
return ((m_instance == NULL) ? PR_FALSE : PR_TRUE);
}

View File

@ -41,14 +41,14 @@ class nsDll
private:
char *m_fullpath; // system format full filename of dll
PRTime m_lastModTime; // last modified time
PRUint64 m_size; // size of the dynamic library
PRUint32 m_size; // size of the dynamic library
PRLibrary *m_instance; // Load instance
nsDllStatus m_status; // holds current status
public:
nsDll(const char *libFullPath);
nsDll(const char *libFullPath, PRTime lastModTime, PRUint64 fileSize);
nsDll(const char *libFullPath, PRTime lastModTime, PRUint32 fileSize);
~nsDll(void);
@ -66,6 +66,6 @@ public:
const char *GetFullPath(void) { return (m_fullpath); }
PRTime GetLastModifiedTime(void) { return(m_lastModTime); }
PRUint64 GetSize(void) { return(m_size); }
PRUint32 GetSize(void) { return(m_size); }
PRLibrary *GetInstance(void) { return (m_instance); }
};

View File

@ -25,6 +25,13 @@
#include <iostream.h>
#endif
#ifdef XP_MAC
#include <Files.h>
#include <Memory.h>
#include <Processes.h>
#include <TextUtils.h>
#endif
#include "plstr.h"
#include "prlink.h"
#include "prsystem.h"
@ -100,7 +107,7 @@ public:
nsIFactory *factory;
FactoryEntry(const nsCID &aClass, const char *aLibrary,
PRTime lastModTime, PRUint64 fileSize);
PRTime lastModTime, PRUint32 fileSize);
FactoryEntry(const nsCID &aClass, nsIFactory *aFactory);
~FactoryEntry();
// DO NOT DELETE THIS. Many FactoryEntry(s) could be sharing the same Dll.
@ -110,7 +117,7 @@ public:
};
FactoryEntry::FactoryEntry(const nsCID &aClass, const char *aLibrary,
PRTime lastModTime, PRUint64 fileSize)
PRTime lastModTime, PRUint32 fileSize)
: cid(aClass), factory(NULL), dll(NULL)
{
nsDllStore *dllCollection = nsRepository::dllStore;
@ -980,15 +987,71 @@ nsresult nsRepository::FreeLibraries(void)
nsresult nsRepository::AutoRegister(NSRegistrationInstant when,
const char* pathlist)
{
#ifdef XP_MAC
CInfoPBRec catInfo;
Handle pathH;
OSErr err;
ProcessSerialNumber psn;
ProcessInfoRec pInfo;
FSSpec appFSSpec;
long theDirID, oldLen, newLen;
Str255 name;
#endif
if (pathlist != NULL)
{
SyncComponentsInPathList(pathlist);
}
#ifdef XP_MAC
// get info for the the current process to determine the directory its located in
if (!(err = GetCurrentProcess(&psn)))
{
if (!(err = GetProcessInformation(&psn, &pInfo)))
{
appFSSpec = *(pInfo.processAppSpec);
if ((pathH = NewHandle(1)) != NULL)
{
**pathH = '\0'; // initially null terminate the string
HNoPurge(pathH);
HUnlock(pathH);
theDirID = appFSSpec.parID;
do
{
catInfo.dirInfo.ioCompletion = NULL;
catInfo.dirInfo.ioNamePtr = (StringPtr)&name;
catInfo.dirInfo.ioVRefNum = appFSSpec.vRefNum;
catInfo.dirInfo.ioDrDirID = theDirID;
catInfo.dirInfo.ioFDirIndex = -1; // -1 = query dir in ioDrDirID
if (!(err = PBGetCatInfoSync(&catInfo)))
{
// build up a Unix style pathname due to NSPR
// XXX Note: this breaks if any of the parent
// directories contain a "slash" (blame NSPR)
Munger(pathH, 0L, NULL, 0L, (const void *)&name[1], (long)name[0]); // prepend dir name
Munger(pathH, 0L, NULL, 0L, "/", 1); // prepend slash
// move up to parent directory
theDirID = catInfo.dirInfo.ioDrParID;
}
} while ((!err) && (catInfo.dirInfo.ioDrDirID != 2)); // 2 = root
if (!err)
{
HLock(pathH);
SyncComponentsInPathList((const char *)(*pathH));
HUnlock(pathH);
}
DisposeHandle(pathH);
}
}
}
#else
//XXX get default pathlist from registry
//XXX Temporary hack. Registering components from current directory
const char *defaultPathList = ".";
SyncComponentsInPathList(defaultPathList);
#endif
return (NS_OK);
}
@ -1031,7 +1094,7 @@ nsresult nsRepository::SyncComponentsInDir(const char *dir)
unsigned int n = strlen(fullname);
if (n+1 < sizeof(fullname))
{
fullname[n] = PR_GetDirectorySeparator();
fullname[n] = '/'; // PR_GetDirectorySeparator();
n++;
}
char *filepart = fullname + n;
@ -1058,18 +1121,19 @@ nsresult nsRepository::SyncComponentsInFile(const char *fullname)
".dso", /* Unix */
".so", /* Unix */
".sl", /* Unix: HP */
"_dll", /* Mac ? */
".shlb", /* Mac ? */
".dlm", /* new for all platforms */
NULL
};
PRFileInfo64 statbuf;
if (PR_GetFileInfo64(fullname, &statbuf) != PR_SUCCESS)
PRFileInfo statbuf;
if (PR_GetFileInfo(fullname,&statbuf) != PR_SUCCESS)
{
// Skip files that cannot be stat
return (NS_ERROR_FAILURE);
}
if (statbuf.type == PR_FILE_DIRECTORY)
{
// Cant register a directory
@ -1129,7 +1193,7 @@ nsresult nsRepository::SyncComponentsInFile(const char *fullname)
// We already have seen this dll. Check if this dll changed
if (LL_EQ(dll->GetLastModifiedTime(), statbuf.modifyTime) &&
LL_EQ(dll->GetSize(), statbuf.size))
(dll->GetSize() == statbuf.size))
{
// Dll hasn't changed. Skip.
PR_LOG(logmodule, PR_LOG_ALWAYS,

View File

@ -31,7 +31,7 @@ nsDll::nsDll(const char *libFullPath) : m_fullpath(NULL), m_instance(NULL),
m_status(DLL_OK)
{
m_lastModTime = LL_ZERO;
m_size = LL_ZERO;
m_size = 0;
if (libFullPath == NULL)
{
@ -46,8 +46,8 @@ nsDll::nsDll(const char *libFullPath) : m_fullpath(NULL), m_instance(NULL),
return;
}
PRFileInfo64 statinfo;
if (PR_GetFileInfo64(m_fullpath, &statinfo) != PR_SUCCESS)
PRFileInfo statinfo;
if (PR_GetFileInfo(m_fullpath, &statinfo) != PR_SUCCESS)
{
// The stat things works only if people pass in the full pathname.
// Even if our stat fails, we could be able to load it because of
@ -71,7 +71,7 @@ nsDll::nsDll(const char *libFullPath) : m_fullpath(NULL), m_instance(NULL),
}
nsDll::nsDll(const char *libFullPath, PRTime lastModTime, PRUint64 fileSize)
nsDll::nsDll(const char *libFullPath, PRTime lastModTime, PRUint32 fileSize)
: m_fullpath(NULL), m_instance(NULL), m_status(DLL_OK)
{
m_lastModTime = lastModTime;
@ -101,8 +101,15 @@ nsDll::~nsDll(void)
m_fullpath = NULL;
}
PRBool nsDll::Load(void)
{
#ifdef XP_MAC
char *macFileName = NULL;
OSErr err;
int loop;
#endif
if (m_status != DLL_OK)
{
return (PR_FALSE);
@ -112,7 +119,27 @@ PRBool nsDll::Load(void)
// Already loaded
return (PR_TRUE);
}
#ifdef XP_MAC
// err = ConvertUnixPathToMacPath(m_fullpath, &macFileName);
if ((macFileName = PL_strdup(m_fullpath)) != NULL)
{
if (macFileName[0] == '/')
{
for (loop=0; loop<PL_strlen(macFileName); loop++)
{
if (macFileName[loop] == '/') macFileName[loop] = ':';
}
m_instance = PR_LoadLibrary(&macFileName[1]); // skip over initial slash
}
else
{
m_instance = PR_LoadLibrary(macFileName);
}
}
#else
m_instance = PR_LoadLibrary(m_fullpath);
#endif
return ((m_instance == NULL) ? PR_FALSE : PR_TRUE);
}

View File

@ -41,14 +41,14 @@ class nsDll
private:
char *m_fullpath; // system format full filename of dll
PRTime m_lastModTime; // last modified time
PRUint64 m_size; // size of the dynamic library
PRUint32 m_size; // size of the dynamic library
PRLibrary *m_instance; // Load instance
nsDllStatus m_status; // holds current status
public:
nsDll(const char *libFullPath);
nsDll(const char *libFullPath, PRTime lastModTime, PRUint64 fileSize);
nsDll(const char *libFullPath, PRTime lastModTime, PRUint32 fileSize);
~nsDll(void);
@ -66,6 +66,6 @@ public:
const char *GetFullPath(void) { return (m_fullpath); }
PRTime GetLastModifiedTime(void) { return(m_lastModTime); }
PRUint64 GetSize(void) { return(m_size); }
PRUint32 GetSize(void) { return(m_size); }
PRLibrary *GetInstance(void) { return (m_instance); }
};