Fixes bugs 149745 148918 149715 149730 149754 129959. Cleanup of nsIFile and nsILocalFile interfaces, supporting do_GetInterface in embedding via xcom glue, and general cleanup of shutdown. r=various, sr=shaver@mozilla.org

This commit is contained in:
dougt%netscape.com 2002-06-11 19:26:04 +00:00
parent e1cfdafdae
commit 913bbb6f6c
22 changed files with 168 additions and 32 deletions

View File

@ -280,6 +280,8 @@ NSPR_LIBS = @NSPR_LIBS@
LDAP_CFLAGS = @LDAP_CFLAGS@
LDAP_LIBS = @LDAP_LIBS@
XPCOM_GLUE_LIBS = @XPCOM_GLUE_LIBS@
# UNIX98 iconv support
LIBICONV = @LIBICONV@

13
configure vendored
View File

@ -6098,7 +6098,7 @@ else
#line 6099 "configure"
#include "confdefs.h"
#ifdef __cplusplus
extern "C" void exit(int);
extern "C" void exit(int) throw();
#endif
#include <stddef.h>
int main () {
@ -8953,7 +8953,7 @@ else
#line 8954 "configure"
#include "confdefs.h"
#ifdef __cplusplus
extern "C" void exit(int);
extern "C" void exit(int) throw();
#endif
class X { int i; public: virtual ~X() { } };
class Y { int j; public: virtual ~Y() { } };
@ -12280,7 +12280,7 @@ else
#line 12281 "configure"
#include "confdefs.h"
#ifdef __cplusplus
extern "C" void exit(int);
extern "C" void exit(int) throw();
#endif
int main () {
if (sizeof(long long) != 8) { return 1; }
@ -13678,6 +13678,12 @@ EOF
fi
if test "$_WIN32_MSVC"; then
XPCOM_GLUE_LIBS='$(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) $(DIST)/lib/$(LIB_PREFIX)string_s.$(LIB_SUFFIX) $(DIST)/lib/$(LIB_PREFIX)string_obsolete_s.$(LIB_SUFFIX) $(DIST)/lib/$(LIB_PREFIX)embed_base_s.$(LIB_SUFFIX)'
else
XPCOM_GLUE_LIBS='-L${DIST}/bin -L${DIST}/lib -lxpcomglue -lstring_s -lstring_obsolete_s -lembed_base_s'
fi
if test "$MOZ_DEBUG" || test "$NS_TRACE_MALLOC"; then
MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS=
fi
@ -14385,6 +14391,7 @@ s%@MOZ_JSDEBUGGER@%$MOZ_JSDEBUGGER%g
s%@ENABLE_EAZEL_PROFILER@%$ENABLE_EAZEL_PROFILER%g
s%@EAZEL_PROFILER_CFLAGS@%$EAZEL_PROFILER_CFLAGS%g
s%@EAZEL_PROFILER_LIBS@%$EAZEL_PROFILER_LIBS%g
s%@XPCOM_GLUE_LIBS@%$XPCOM_GLUE_LIBS%g
s%@MOZ_PERF_METRICS@%$MOZ_PERF_METRICS%g
s%@GC_LEAK_DETECTOR@%$GC_LEAK_DETECTOR%g
s%@MOZ_LOG_REFCNT@%$MOZ_LOG_REFCNT%g

View File

@ -4298,6 +4298,12 @@ dnl ========================================================
dnl =
dnl = Cleanup section for misc ordering snafus
dnl =
if test "$_WIN32_MSVC"; then
XPCOM_GLUE_LIBS='$(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) $(DIST)/lib/$(LIB_PREFIX)string_s.$(LIB_SUFFIX) $(DIST)/lib/$(LIB_PREFIX)string_obsolete_s.$(LIB_SUFFIX) $(DIST)/lib/$(LIB_PREFIX)embed_base_s.$(LIB_SUFFIX)'
else
XPCOM_GLUE_LIBS='-L${DIST}/bin -L${DIST}/lib -lxpcomglue -lstring_s -lstring_obsolete_s -lembed_base_s'
fi
dnl ========================================================
if test "$MOZ_DEBUG" || test "$NS_TRACE_MALLOC"; then
MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS=
@ -4369,6 +4375,7 @@ AC_SUBST(MOZ_JSDEBUGGER)
AC_SUBST(ENABLE_EAZEL_PROFILER)
AC_SUBST(EAZEL_PROFILER_CFLAGS)
AC_SUBST(EAZEL_PROFILER_LIBS)
AC_SUBST(XPCOM_GLUE_LIBS)
AC_SUBST(MOZ_PERF_METRICS)
AC_SUBST(GC_LEAK_DETECTOR)
AC_SUBST(MOZ_LOG_REFCNT)

View File

@ -107,6 +107,7 @@
*/
#if defined(XP_WIN)
#define WM_DNS_SHUTDOWN (WM_USER + 200)
static char *windowClass = "Mozilla:DNSWindowClass";
#endif /* XP_WIN */
@ -976,6 +977,14 @@ nsDNSService::Init()
NS_ASSERTION(mDNSServiceLock == nsnull, "nsDNSService not shut down");
if (mDNSServiceLock) return NS_ERROR_ALREADY_INITIALIZED;
// install xpcom shutdown observer
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1", &rv);
if (NS_FAILED(rv)) return rv;
rv = observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
if (NS_FAILED(rv)) return rv;
#if defined(XP_MAC)
OSStatus errOT = INIT_OPEN_TRANSPORT();
NS_ASSERTION(errOT == kOTNoError, "InitOpenTransport failed.");
@ -1113,6 +1122,10 @@ nsDNSService::~nsDNSService()
}
#endif
CRTFREEIF(mMyIPAddress);
#if defined(XP_WIN)
UnregisterClass(windowClass, (HINSTANCE) NULL);
#endif
}
@ -1265,6 +1278,13 @@ nsDNSService::Observe(nsISupports * subject,
{
nsresult rv = NS_OK;
if (!nsCRT::strcmp(NS_XPCOM_SHUTDOWN_OBSERVER_ID, topic))
{
// we need to shutdown!
ShutdownInternal();
return NS_OK;
}
if (nsCRT::strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, topic))
return NS_OK;
@ -1302,7 +1322,6 @@ nsDNSService::Observe(nsISupports * subject,
mIDNConverter = nsnull;
}
}
return rv;
}
@ -1380,7 +1399,6 @@ NS_IMETHODIMP
nsDNSService::Run()
{
WNDCLASS wc;
char * windowClass = "Mozilla:DNSWindowClass";
// register window class for DNS event receiver window
memset(&wc, 0, sizeof(wc));
@ -1815,7 +1833,7 @@ nsDNSService::ShutdownInternal()
#elif defined(XP_WIN)
SendMessage(mDNSWindow, WM_DNS_SHUTDOWN, 0, 0);
UnregisterClass(windowClass, NULL);
#endif
PR_Unlock(mDNSServiceLock); // so dns thread can aquire it.
@ -1829,6 +1847,15 @@ nsDNSService::ShutdownInternal()
(void) RemovePrefObserver();
// remove xpcom shutdown observer
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1", &rv);
if (NS_FAILED(rv)) return rv;
rv = observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
if (NS_FAILED(rv)) return rv;
// reset hashtable
// XXX assert hashtable is empty
PL_DHashTableFinish(&mHashTable);

View File

@ -37,7 +37,6 @@ CPPSRCS = \
nsAllocator.cpp \
nsMemoryImpl.cpp \
nsErrorService.cpp \
nsIInterfaceRequestor.cpp \
nsTraceRefcnt.cpp \
nsID.cpp \
nsCWeakReference.cpp \

View File

@ -101,7 +101,6 @@ CPP_OBJS = \
.\$(OBJDIR)\nsMemoryImpl.obj \
.\$(OBJDIR)\nsCWeakReference.obj \
.\$(OBJDIR)\nsID.obj \
.\$(OBJDIR)\nsIInterfaceRequestor.obj \
# .\$(OBJDIR)\nsSystemInfo.obj \
.\$(OBJDIR)\nsExceptionService.obj \
.\$(OBJDIR)\nsTraceRefcnt.obj \

View File

@ -203,6 +203,7 @@ void nsExceptionService::Shutdown()
PR_DestroyLock(lock);
lock = nsnull;
}
PR_SetThreadPrivate(tlsIndex, nsnull);
}
/* void setCurrentException (in nsIException error); */

View File

@ -40,10 +40,14 @@
#include "nscore.h"
class nsAString;
class nsACString;
class nsIComponentManager;
class nsIComponentRegistrar;
class nsIServiceManager;
class nsIFile;
class nsILocalFile;
class nsIDirectoryServiceProvider;
class nsIMemory;
/**
@ -53,10 +57,10 @@ class nsIMemory;
*
* @status FROZEN
*
* @note Use <CODE>NS_NewLocalFile</CODE> to create the file object you
* supply as the bin directory path in this call. The function
* may be safely called before the rest of XPCOM or embedding has
* been initialised.
* @note Use <CODE>NS_NewLocalFile</CODE> or <CODE>NS_NewNativeLocalFile</CODE>
* to create the file object you supply as the bin directory path in this
* call. The function may be safely called before the rest of XPCOM or
* embedding has been initialised.
*
* @param result The service manager. You may pass null.
*
@ -151,4 +155,37 @@ NS_GetComponentRegistrar(nsIComponentRegistrar* *result);
extern "C" NS_COM nsresult
NS_GetMemoryManager(nsIMemory* *result);
/**
* Public Method to create an instance of a nsILocalFile. This function
* may be called prior to NS_InitXPCOM2.
*
* @status FROZEN
*
* @param filePath
* A string which specifies a full file path to a
* location. Relative paths will be treated as an
* error (NS_ERROR_FILE_UNRECOGNIZED_PATH).
* |NS_NewNativeLocalFile|'s path must be in the
* filesystem charset.
* @param followLinks
* This attribute will determine if the nsLocalFile will auto
* resolve symbolic links. By default, this value will be false
* on all non unix systems. On unix, this attribute is effectively
* a noop.
* @param result Interface pointer to a new instance of an nsILocalFile
*
* @return NS_OK for success;
* other error codes indicate a failure.
*/
extern "C" NS_COM nsresult
NS_NewLocalFile(const nsAString &path,
PRBool followLinks,
nsILocalFile* *result);
extern "C" NS_COM nsresult
NS_NewNativeLocalFile(const nsACString &path,
PRBool followLinks,
nsILocalFile* *result);
#endif

View File

@ -323,6 +323,9 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result,
{
nsresult rv = NS_OK;
// We are not shutting down
gXPCOMShuttingDown = PR_FALSE;
#ifdef NS_BUILD_REFCNT_LOGGING
nsTraceRefcnt::Startup();
#endif
@ -585,6 +588,8 @@ nsresult NS_COM NS_ShutdownXPCOM(nsIServiceManager* servMgr)
currentQ->ProcessPendingEvents();
currentQ = 0;
}
nsProxyObjectManager::Shutdown();
// Release the directory service
NS_IF_RELEASE(gDirectoryService);

View File

@ -104,4 +104,5 @@ NS_NewEmptyEnumerator(nsISimpleEnumerator** aResult)
EmptyEnumeratorImpl::Shutdown()
{
delete gEmptyEnumerator;
gEmptyEnumerator = nsnull;
}

View File

@ -55,6 +55,7 @@ LCFLAGS = -D_IMPL_NS_COM -D_IMPL_NS_BASE -DWIN32_LEAN_AND_MEAN
CPP_OBJS = \
.\$(OBJDIR)\nsCOMPtr.obj \
.\$(OBJDIR)\nsDebug.obj \
.\$(OBJDIR)\nsIInterfaceRequestorUtils.cpp \
.\$(OBJDIR)\nsGenericFactory.obj \
.\$(OBJDIR)\nsMemory.obj \
.\$(OBJDIR)\nsWeakReference.obj \

View File

@ -52,7 +52,9 @@
#include <signal.h>
/* for nsTraceRefcnt::WalkTheStack() */
#include "nsISupportsUtils.h"
#ifndef MOZILLA_STRICT_API
#include "nsTraceRefcnt.h"
#endif
#if defined(linux) && defined(__i386)
# define DebugBreak() { asm("int $3"); }
@ -321,13 +323,17 @@ NS_COM void nsDebug::Break(const char* aFile, PRIntn aLine)
//
;
} else if ( strcmp(assertBehavior,"stack")==0 ) {
}
#ifndef XPCOM_GLUE
else if ( strcmp(assertBehavior,"stack")==0 ) {
// walk the stack
//
nsTraceRefcnt::WalkTheStack(stderr);
} else if ( strcmp(assertBehavior,"abort")==0 ) {
}
#endif
else if ( strcmp(assertBehavior,"abort")==0 ) {
// same as UNIX_CRASH_ON_ASSERT
//

View File

@ -46,12 +46,26 @@
#endif
#include "pratom.h" /* needed for PR_AtomicIncrement and PR_AtomicDecrement */
#ifdef XPCOM_GLUE
// nsTraceRefcnt needs a cleaning...
#define NS_LOG_ADDREF(_p, _rc, _type, _size)
#define NS_LOG_RELEASE(_p, _rc, _type)
#define NS_LOG_NEW_XPCOM(_p,_type,_size,_file,_line)
#define NS_LOG_DELETE_XPCOM(_p,_file,_line)
#define NS_LOG_ADDREF_CALL(_p,_rc,_file,_line) _rc
#define NS_LOG_RELEASE_CALL(_p,_rc,_file,_line) _rc
#define MOZ_DECL_CTOR_COUNTER(_type)
#define MOZ_COUNT_CTOR(_type)
#define MOZ_COUNT_DTOR(_type)
#else
#include "nsTraceRefcnt.h"
#endif
////////////////////////////////////////////////////////////////////////////////
// Macros to help detect thread-safety:
#if defined(NS_DEBUG) && defined(NS_MT_SUPPORTED)
#if defined(NS_DEBUG) && defined(NS_MT_SUPPORTED) && !defined(XPCOM_GLUE)
extern "C" NS_COM void* NS_CurrentThread(void);
extern "C" NS_COM void NS_CheckThreadSafe(void* owningThread,

View File

@ -38,6 +38,7 @@ XPCOM_GLUE_SRC_LCSRCS = \
nsCOMPtr.cpp \
nsDebug.cpp \
nsGenericFactory.cpp \
nsIInterfaceRequestorUtils.cpp \
nsMemory.cpp \
nsWeakReference.cpp \
nsComponentManagerUtils.cpp \

View File

@ -70,7 +70,7 @@ include $(topsrcdir)/config/rules.mk
export:: $(XPCOM_GLUE_SRC_CSRCS)
$(INSTALL) $^ .
DEFINES += -D_IMPL_NS_COM_OFF
DEFINES += -D_IMPL_NS_COM_OFF -DXPCOM_GLUE
ifeq ($(OS_ARCH),WINNT)
DEFINES += -DWIN32_LEAN_AND_MEAN

View File

@ -63,6 +63,8 @@ interface nsIFile : nsISupports
*
* @param node
* A string which is intended to be a child node of the nsIFile.
* For the |appendNative| method, the node must be in the native
* filesystem charset.
*/
void append(in AString node);
[noscript] void appendNative(in ACString node);
@ -95,7 +97,9 @@ interface nsIFile : nsISupports
void create(in unsigned long type, in unsigned long permissions);
/**
* Accessor to the leaf name of the file itself.
* Accessor to the leaf name of the file itself.
* For the |nativeLeafName| method, the nativeLeafName must
* be in the native filesystem charset.
*/
attribute AString leafName;
[noscript] attribute ACString nativeLeafName;
@ -118,7 +122,9 @@ interface nsIFile : nsISupports
* newParentDir is null, copyTo() will use the parent
* directory of this file. If the newParentDir is not
* empty and is not a directory, an error will be
* returned (NS_ERROR_FILE_DESTINATION_NOT_DIR)
* returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For the
* |CopyToNative| method, the newName must be in the
* native filesystem charset.
*
* @param newName
* This param allows you to specify a new name for
@ -133,7 +139,9 @@ interface nsIFile : nsISupports
*
* This function is identical to copyTo with the exception that,
* as the name implies, it follows symbolic links. The XP_UNIX
* implementation always follow symbolic links when copying.
* implementation always follow symbolic links when copying. For
* the |CopyToFollowingLinks| method, the newName must be in the
* native filesystem charset.
*/
void copyToFollowingLinks(in nsIFile newParentDir, in AString newName);
[noscript] void copyToFollowingLinksNative(in nsIFile newParentDir, in ACString newName);
@ -155,7 +163,9 @@ interface nsIFile : nsISupports
* newParentDir is empty, moveTo() will rename the file
* within its current directory. If the newParentDir is
* not empty and does not name a directory, an error will
* be returned (NS_ERROR_FILE_DESTINATION_NOT_DIR)
* be returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For
* the |moveToNative| method, the newName must be in the
* native filesystem charset.
*
* @param newName
* This param allows you to specify a new name for
@ -217,6 +227,10 @@ interface nsIFile : nsISupports
*
* path
* Find out what the nsIFile points at.
*
* Note that the ACString attributes are returned in the
* native filesystem charset.
*
*/
readonly attribute AString target;
[noscript] readonly attribute ACString nativeTarget;

View File

@ -60,8 +60,9 @@ interface nsILocalFile : nsIFile
* @param filePath
* A string which specifies a full file path to a
* location. Relative paths will be treated as an
* error (NS_ERROR_FILE_UNRECOGNIZED_PATH). This
* path must in native.
* error (NS_ERROR_FILE_UNRECOGNIZED_PATH). For
* initWithNativePath, the filePath must be in the native
* filesystem charset.
*/
void initWithPath(in AString filePath);
[noscript] void initWithNativePath(in ACString filePath);
@ -107,8 +108,9 @@ interface nsILocalFile : nsIFile
*
* @param relativeFilePath
* relativeFilePath is a native relative path. For security reasons,
* this cannot contain .. or cannot start with a directory separator
* XXXbe Why not? Bogus!
* this cannot contain .. or cannot start with a directory separator.
* For the |appendRelativeNativePath| method, the relativeFilePath
* must be in the native filesystem charset.
*/
void appendRelativePath(in AString relativeFilePath);
[noscript] void appendRelativeNativePath(in ACString relativeFilePath);
@ -162,7 +164,9 @@ interface nsILocalFile : nsIFile
*
* @param fromFile
* the file to which the descriptor is relative
*/
* @param relative
* the relative descriptor obtained from getRelativeDescriptor
*/
void setRelativeDescriptor(in nsILocalFile fromFile, in ACString relativeDesc);
};
@ -170,8 +174,4 @@ interface nsILocalFile : nsIFile
#define NS_LOCAL_FILE_CONTRACTID "@mozilla.org/file/local;1"
#define NS_LOCAL_FILE_CLASSNAME "Local File Specification"
extern "C" NS_EXPORT nsresult
NS_NewLocalFile(const nsAString &path, PRBool followLinks, nsILocalFile* *result);
extern "C" NS_EXPORT nsresult
NS_NewNativeLocalFile(const nsACString &path, PRBool followLinks, nsILocalFile* *result);
%}

View File

@ -180,6 +180,7 @@ public:
static nsProxyObjectManager *GetInstance();
static PRBool IsManagerShutdown();
static void Shutdown();
nsHashtable* GetRealObjectToProxyObjectMap() const { return mProxyObjectMap;}
nsHashtable* GetIIDToProxyClassMap() const { return mProxyClassMap; }

View File

@ -168,6 +168,13 @@ nsProxyObjectManager::GetInstance()
}
void
nsProxyObjectManager::Shutdown()
{
mInstance = nsnull;
}
// Helpers
NS_IMETHODIMP
nsProxyObjectManager::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)

View File

@ -52,7 +52,7 @@ PrepareAndDispatch(nsXPTCStubBase* self, PRUint32 methodIndex,
nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
nsXPTCMiniVariant* dispatchParams = NULL;
nsIInterfaceInfo* iface_info = NULL;
const nsXPTMethodInfo* info;
const nsXPTMethodInfo* info = NULL;
PRUint8 paramCount;
PRUint8 i;
nsresult result = NS_ERROR_FAILURE;

View File

@ -50,6 +50,9 @@ NS_IMPL_THREADSAFE_ISUPPORTS2(xptiInterfaceInfoManager,
nsIInterfaceInfoSuperManager)
static xptiInterfaceInfoManager* gInterfaceInfoManager = nsnull;
#ifdef DEBUG
static int gCallCount = 0;
#endif
// static
xptiInterfaceInfoManager*
@ -171,8 +174,10 @@ xptiInterfaceInfoManager::~xptiInterfaceInfoManager()
if(mAdditionalManagersLock)
PR_DestroyLock(mAdditionalManagersLock);
gInterfaceInfoManager = nsnull;
#ifdef DEBUG
xptiInterfaceInfo::DEBUG_ShutdownNotification();
gCallCount = 0;
#endif
}
@ -224,8 +229,7 @@ AppendFromDirServiceList(const char* codename, nsISupportsArray* aPath)
PRBool xptiInterfaceInfoManager::BuildFileSearchPath(nsISupportsArray** aPath)
{
#ifdef DEBUG
static int callCount = 0;
NS_ASSERTION(!callCount++, "Expected only one call!");
NS_ASSERTION(!gCallCount++, "Expected only one call!");
#endif
nsCOMPtr<nsISupportsArray> searchPath;

View File

@ -265,6 +265,7 @@ nsThread::Init(nsIRunnable* runnable,
PR_Unlock(mStartLock);
PR_LOG(nsIThreadLog, PR_LOG_DEBUG,
("nsIThread %p created\n", this));
if (mThread == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
@ -436,6 +437,8 @@ nsThread::Shutdown()
nsrefcnt cnt;
NS_RELEASE2(gMainThread, cnt);
NS_WARN_IF_FALSE(cnt == 0, "Main thread being held past XPCOM shutdown.");
kIThreadSelfIndex = 0;
}
}