PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
nsFreeLibrary(nsDll *dll, nsIServiceManager *serviceMgr, PRInt32 when){    nsresult rv = NS_ERROR_FAILURE;    if (!dll || dll->IsLoaded() == PR_FALSE)    {        return NS_ERROR_INVALID_ARG;    }    // Get if the dll was marked for unload in an earlier round    PRBool dllMarkedForUnload = dll->IsMarkedForUnload();    // Reset dll marking for unload just in case we return with    // an error.    dll->MarkForUnload(PR_FALSE);    PRBool canUnload = PR_FALSE;    // Get the module object    nsCOMPtr<nsIModule> mobj;    /* XXXshaver cheat and use the global component manager */    rv = dll->GetModule(NS_STATIC_CAST(nsIComponentManager*, nsComponentManagerImpl::gComponentManager),                        getter_AddRefs(mobj));    if (NS_SUCCEEDED(rv))    {        rv = mobj->CanUnload(nsComponentManagerImpl::gComponentManager, &canUnload);    }    mobj = nsnull; // Release our reference to the module object    // When shutting down, whether we can unload the dll or not,    // we will shutdown the dll to release any memory it has got    if (when == nsIComponentManagerObsolete::NS_Shutdown)    {        dll->Shutdown();    }            // Check error status on CanUnload() call    if (NS_FAILED(rv))    {#ifdef PR_LOGGING        nsXPIDLCString displayPath;        dll->GetDisplayPath(displayPath);        PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,               ("nsNativeComponentLoader: nsIModule::CanUnload() returned error for %s.",                displayPath.get()));#endif        return rv;    }    if (canUnload)    {        if (dllMarkedForUnload)        {#ifdef PR_LOGGING            nsXPIDLCString displayPath;            dll->GetDisplayPath(displayPath);            PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,                    ("nsNativeComponentLoader: + Unloading \"%s\".", displayPath.get()));#endif#ifdef DEBUG_dougt            // XXX dlls aren't counting their outstanding instances correctly            // XXX hence, dont unload until this gets enforced.            rv = dll->Unload();#endif /* 0 */        }        else        {#ifdef PR_LOGGING            nsXPIDLCString displayPath;            dll->GetDisplayPath(displayPath);            PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,                   ("nsNativeComponentLoader: Ready for unload \"%s\".", displayPath.get()));#endif        }    }    else    {#ifdef PR_LOGGING        nsXPIDLCString displayPath;        dll->GetDisplayPath(displayPath);        PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,                ("nsNativeComponentLoader: NOT ready for unload %s", displayPath.get()));#endif        rv = NS_ERROR_FAILURE;    }    return rv;}