void nsCacheEntryHashTable::VisitEntries( PLDHashEnumerator etor, void *arg) { NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized"); if (!initialized) return; // NS_ERROR_NOT_INITIALIZED PL_DHashTableEnumerate(&table, etor, arg); }
void nsCacheEntryHashTable::VisitEntries( nsCacheEntryHashTable::Visitor *visitor) { NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized"); if (!initialized) return; // NS_ERROR_NOT_INITIALIZED PL_DHashTableEnumerate(&table, VisitEntry, visitor); }
void nsPropertyTable::PropertyList::Destroy() { // Enumerate any remaining object/value pairs and destroy the value object if (mDtorFunc) PL_DHashTableEnumerate(&mObjectValueMap, DestroyPropertyEnumerator, nullptr); }
void nsPropertyTable::EnumerateAll(NSPropertyFunc aCallBack, void* aData) { for (PropertyList* prop = mPropertyList; prop; prop = prop->mNext) { PropertyEnumeratorData data = { prop->mName, aCallBack, aData }; PL_DHashTableEnumerate(&prop->mObjectValueMap, PropertyEnumerator, &data); } }
nsresult nsScriptNameSpaceManager::InitForContext(nsIScriptContext *aContext) { NameSetClosure closure; closure.ctx = aContext; closure.rv = NS_OK; PL_DHashTableEnumerate(&mGlobalNames, NameSetInitCallback, &closure); return closure.rv; }
NS_IMETHODIMP nsLoadGroup::AdjustPriority(PRInt32 aDelta) { // Update the priority for each request that supports nsISupportsPriority if (aDelta != 0) { mPriority += aDelta; PL_DHashTableEnumerate(&mRequests, RescheduleRequests, &aDelta); } return NS_OK; }
nsHashtable * nsHashtable::Clone() { if (!mHashtable.ops) return nsnull; PRBool threadSafe = (mLock != nsnull); nsHashtable *newHashTable = new nsHashtable(mHashtable.entryCount, threadSafe); PL_DHashTableEnumerate(&mHashtable, hashEnumerateShare, newHashTable); return newHashTable; }
nsresult PREF_ClearAllUserPrefs() { if (!gHashTable.ops) return NS_ERROR_NOT_INITIALIZED; PL_DHashTableEnumerate(&gHashTable, pref_ClearUserPref, nsnull); gDirty = true; return NS_OK; }
/** * ActiveBindings : return true if any bindings have open descriptors */ bool nsDiskCacheBindery::ActiveBindings() { NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized"); if (!initialized) return false; bool activeBinding = false; PL_DHashTableEnumerate(&table, ActiveBinding, &activeBinding); return activeBinding; }
nsresult NativeToJavaProxyMap::Destroy(JNIEnv* env) { // This is only called from FreeGlobals(), which already holds the lock. // nsAutoLock lock(gJavaXPCOMLock); PL_DHashTableEnumerate(mHashTable, DestroyJavaProxyMappingEnum, env); PL_DHashTableDestroy(mHashTable); mHashTable = nsnull; return NS_OK; }
nsresult JavaToXPTCStubMap::Destroy() { // This is only called from FreeGlobals(), which already holds the lock. // nsAutoLock lock(gJavaXPCOMLock); PL_DHashTableEnumerate(mHashTable, DestroyXPTCMappingEnum, nsnull); PL_DHashTableDestroy(mHashTable); mHashTable = nsnull; return NS_OK; }
void nsHashtable::Enumerate(nsHashtableEnumFunc aEnumFunc, void* aClosure) { if (!mHashtable.ops) return; PRBool wasEnumerating = mEnumerating; mEnumerating = PR_TRUE; _HashEnumerateArgs thunk; thunk.fn = aEnumFunc; thunk.arg = aClosure; PL_DHashTableEnumerate(&mHashtable, hashEnumerate, &thunk); mEnumerating = wasEnumerating; }
/** * SizeOfExcludingThis: return the amount of heap memory (bytes) being used by the bindery */ size_t nsDiskCacheBindery::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) { NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized"); if (!initialized) return 0; AccumulatorArg arg; arg.mUsage = 0; arg.mMallocSizeOf = aMallocSizeOf; PL_DHashTableEnumerate(&table, AccumulateHeapUsage, &arg); return arg.mUsage; }
NS_IMETHODIMP nsLoadGroup::Resume() { nsresult rv, firstError; PRUint32 count = mRequests.entryCount; nsAutoTArray<nsIRequest*, 8> requests; PL_DHashTableEnumerate(&mRequests, AppendRequestsToArray, static_cast<nsTArray<nsIRequest*> *>(&requests)); if (requests.Length() != count) { for (PRUint32 i = 0, len = requests.Length(); i < len; ++i) { NS_RELEASE(requests[i]); } return NS_ERROR_OUT_OF_MEMORY; } firstError = NS_OK; // // Operate the elements from back to front so that if items get // get removed from the list it won't affect our iteration // while (count > 0) { nsIRequest* request = requests.ElementAt(--count); NS_ASSERTION(request, "NULL request found in list."); if (!request) continue; #if defined(PR_LOGGING) nsCAutoString nameStr; request->GetName(nameStr); LOG(("LOADGROUP [%x]: Resuming request %x %s.\n", this, request, nameStr.get())); #endif // Resume the request... rv = request->Resume(); // Remember the first failure and return it... if (NS_FAILED(rv) && NS_SUCCEEDED(firstError)) firstError = rv; NS_RELEASE(request); } return firstError; }
void nsHashtable::Reset(nsHashtableEnumFunc destroyFunc, void* aClosure) { if (!mHashtable.ops) return; _HashEnumerateArgs thunk, *thunkp; if (!destroyFunc) { thunkp = nsnull; } else { thunkp = &thunk; thunk.fn = destroyFunc; thunk.arg = aClosure; } PL_DHashTableEnumerate(&mHashtable, hashEnumerateRemove, thunkp); }
NS_IMETHODIMP nsPersistentProperties::Enumerate(nsISimpleEnumerator** aResult) { nsCOMArray<nsIPropertyElement> props; // We know the necessary size; we can avoid growing it while adding elements props.SetCapacity(mTable.EntryCount()); // Step through hash entries populating a transient array uint32_t n = PL_DHashTableEnumerate(&mTable, AddElemToArray, (void*)&props); if (n < mTable.EntryCount()) { return NS_ERROR_OUT_OF_MEMORY; } return NS_NewArrayEnumerator(aResult, props); }
nsHashtable* nsObjectHashtable::Clone() { if (!mHashtable.ops) return nsnull; PRBool threadSafe = PR_FALSE; if (mLock) threadSafe = PR_TRUE; nsObjectHashtable* newHashTable = new nsObjectHashtable(mCloneElementFun, mCloneElementClosure, mDestroyElementFun, mDestroyElementClosure, mHashtable.entryCount, threadSafe); PL_DHashTableEnumerate(&mHashtable, CopyElement, newHashTable); return newHashTable; }
NS_IMETHODIMP nsLoadGroup::GetRequests(nsISimpleEnumerator * *aRequests) { nsCOMPtr<nsISupportsArray> array; nsresult rv = NS_NewISupportsArray(getter_AddRefs(array)); NS_ENSURE_SUCCESS(rv, rv); PL_DHashTableEnumerate(&mRequests, AppendRequestsToISupportsArray, array.get()); PRUint32 count; array->Count(&count); if (count != mRequests.entryCount) { return NS_ERROR_OUT_OF_MEMORY; } return NS_NewArrayEnumerator(aRequests, array); }
NS_IMETHODIMP nsPersistentProperties::Enumerate(nsISimpleEnumerator** aResult) { nsCOMPtr<nsISupportsArray> propArray; nsresult rv = NS_NewISupportsArray(getter_AddRefs(propArray)); if (NS_FAILED(rv)) return rv; // We know the necessary size; we can avoid growing it while adding elements if (!propArray->SizeTo(mTable.entryCount)) return NS_ERROR_OUT_OF_MEMORY; // Step through hash entries populating a transient array PRUint32 n = PL_DHashTableEnumerate(&mTable, AddElemToArray, (void *)propArray); if (n < mTable.entryCount) return NS_ERROR_OUT_OF_MEMORY; return NS_NewArrayEnumerator(aResult, propArray); }
nsresult PREF_DeleteBranch(const char *branch_name) { int len = (int)PL_strlen(branch_name); if (!gHashTable.ops) return NS_ERROR_NOT_INITIALIZED; /* The following check insures that if the branch name already has a "." * at the end, we don't end up with a "..". This fixes an incompatibility * between nsIPref, which needs the period added, and nsIPrefBranch which * does not. When nsIPref goes away this function should be fixed to * never add the period at all. */ nsCAutoString branch_dot(branch_name); if ((len > 1) && branch_name[len - 1] != '.') branch_dot += '.'; PL_DHashTableEnumerate(&gHashTable, pref_DeleteItem, (void*) branch_dot.get()); gDirty = true; return NS_OK; }
nsresult nsPrefService::WritePrefFile(nsIFile* aFile) { const char outHeader[] = "# Mozilla User Preferences" NS_LINEBREAK NS_LINEBREAK "/* Do not edit this file." NS_LINEBREAK " *" NS_LINEBREAK " * If you make changes to this file while the application is running," NS_LINEBREAK " * the changes will be overwritten when the application exits." NS_LINEBREAK " *" NS_LINEBREAK " * To make a manual change to preferences, you can visit the URL about:config" NS_LINEBREAK " * For more information, see http://www.mozilla.org/unix/customizing.html#prefs" NS_LINEBREAK " */" NS_LINEBREAK NS_LINEBREAK; nsCOMPtr<nsIOutputStream> outStreamSink; nsCOMPtr<nsIOutputStream> outStream; PRUint32 writeAmount; nsresult rv; if (!gHashTable.ops) return NS_ERROR_NOT_INITIALIZED; // execute a "safe" save by saving through a tempfile rv = NS_NewSafeLocalFileOutputStream(getter_AddRefs(outStreamSink), aFile, -1, 0600); if (NS_FAILED(rv)) return rv; rv = NS_NewBufferedOutputStream(getter_AddRefs(outStream), outStreamSink, 4096); if (NS_FAILED(rv)) return rv; char** valueArray = (char **)PR_Calloc(sizeof(char *), gHashTable.entryCount); if (!valueArray) return NS_ERROR_OUT_OF_MEMORY; pref_saveArgs saveArgs; saveArgs.prefArray = valueArray; saveArgs.saveTypes = SAVE_ALL; // get the lines that we're supposed to be writing to the file PL_DHashTableEnumerate(&gHashTable, pref_savePref, &saveArgs); /* Sort the preferences to make a readable file on disk */ NS_QuickSort(valueArray, gHashTable.entryCount, sizeof(char *), pref_CompareStrings, NULL); // write out the file header outStream->Write(outHeader, sizeof(outHeader) - 1, &writeAmount); char** walker = valueArray; for (PRUint32 valueIdx = 0; valueIdx < gHashTable.entryCount; valueIdx++, walker++) { if (*walker) { outStream->Write(*walker, strlen(*walker), &writeAmount); outStream->Write(NS_LINEBREAK, NS_LINEBREAK_LEN, &writeAmount); NS_Free(*walker); } } PR_Free(valueArray); // tell the safe output stream to overwrite the real prefs file // (it'll abort if there were any errors during writing) nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(outStream); NS_ASSERTION(safeStream, "expected a safe output stream!"); if (safeStream) { rv = safeStream->Finish(); if (NS_FAILED(rv)) { NS_WARNING("failed to save prefs file! possible dataloss"); return rv; } } gDirty = PR_FALSE; return NS_OK; }
NS_IMETHODIMP nsLoadGroup::Cancel(nsresult status) { NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code"); nsresult rv; PRUint32 count = mRequests.entryCount; nsAutoTArray<nsIRequest*, 8> requests; PL_DHashTableEnumerate(&mRequests, AppendRequestsToArray, static_cast<nsTArray<nsIRequest*> *>(&requests)); if (requests.Length() != count) { for (PRUint32 i = 0, len = requests.Length(); i < len; ++i) { NS_RELEASE(requests[i]); } return NS_ERROR_OUT_OF_MEMORY; } // set the load group status to our cancel status while we cancel // all our requests...once the cancel is done, we'll reset it... // mStatus = status; // Set the flag indicating that the loadgroup is being canceled... This // prevents any new channels from being added during the operation. // mIsCanceling = PR_TRUE; nsresult firstError = NS_OK; while (count > 0) { nsIRequest* request = requests.ElementAt(--count); NS_ASSERTION(request, "NULL request found in list."); RequestMapEntry *entry = static_cast<RequestMapEntry *> (PL_DHashTableOperate(&mRequests, request, PL_DHASH_LOOKUP)); if (PL_DHASH_ENTRY_IS_FREE(entry)) { // |request| was removed already NS_RELEASE(request); continue; } #if defined(PR_LOGGING) nsCAutoString nameStr; request->GetName(nameStr); LOG(("LOADGROUP [%x]: Canceling request %x %s.\n", this, request, nameStr.get())); #endif // // Remove the request from the load group... This may cause // the OnStopRequest notification to fire... // // XXX: What should the context be? // (void)RemoveRequest(request, nsnull, status); // Cancel the request... rv = request->Cancel(status); // Remember the first failure and return it... if (NS_FAILED(rv) && NS_SUCCEEDED(firstError)) firstError = rv; NS_RELEASE(request); } #if defined(DEBUG) NS_ASSERTION(mRequests.entryCount == 0, "Request list is not empty."); NS_ASSERTION(mForegroundCount == 0, "Foreground URLs are active."); #endif mStatus = NS_OK; mIsCanceling = PR_FALSE; return firstError; }
// static PRBool xptiManifest::Write(xptiInterfaceInfoManager* aMgr, xptiWorkingSet* aWorkingSet) { PRBool succeeded = PR_FALSE; PRFileDesc* fd = nsnull; PRUint32 i; PRUint32 size32; PRIntn interfaceCount = 0; nsCAutoString appDirString; nsCOMPtr<nsILocalFile> tempFile; if(!aMgr->GetCloneOfManifestLocation(getter_AddRefs(tempFile)) || !tempFile) return PR_FALSE; nsCAutoString originalLeafName; tempFile->GetNativeLeafName(originalLeafName); nsCAutoString leafName; leafName.Assign(originalLeafName + NS_LITERAL_CSTRING(".tmp")); tempFile->SetNativeLeafName(leafName); // All exits via "goto out;" from here on... if(NS_FAILED(tempFile-> OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0666, &fd)) || !fd) { goto out; } // write file header comments if(!PR_fprintf(fd, "%s\n", g_Disclaimer)) goto out; // write the [Header] block, version number, and appdir. if(!PR_fprintf(fd, "\n[%s,%d]\n", g_TOKEN_Header, 2)) goto out; if(!PR_fprintf(fd, "%d,%s,%d,%d\n", 0, g_TOKEN_Version, g_VERSION_MAJOR, g_VERSION_MINOR)) goto out; GetCurrentAppDirString(aMgr, appDirString); if(appDirString.IsEmpty()) goto out; if(!PR_fprintf(fd, "%d,%s,%s\n", 1, g_TOKEN_AppDir, appDirString.get())) goto out; // write Directories list if(!PR_fprintf(fd, "\n[%s,%d]\n", g_TOKEN_Directories, (int) aWorkingSet->GetDirectoryCount())) goto out; for(i = 0; i < aWorkingSet->GetDirectoryCount(); i++) { nsCOMPtr<nsILocalFile> dir; nsCAutoString str; aWorkingSet->GetDirectoryAt(i, getter_AddRefs(dir)); if(!dir) goto out; dir->GetPersistentDescriptor(str); if(str.IsEmpty()) goto out; if(!PR_fprintf(fd, "%d,%s\n", (int) i, str.get())) goto out; } // write Files list if(!PR_fprintf(fd, "\n[%s,%d]\n", g_TOKEN_Files, (int) aWorkingSet->GetFileCount())) goto out; for(i = 0; i < aWorkingSet->GetFileCount(); i++) { const xptiFile& file = aWorkingSet->GetFileAt(i); LL_L2UI(size32, file.GetSize()); if(!PR_fprintf(fd, "%d,%s,%d,%u,%lld\n", (int) i, file.GetName(), (int) file.GetDirectory(), size32, PRInt64(file.GetDate()))) goto out; } // write ArchiveItems list if(!PR_fprintf(fd, "\n[%s,%d]\n", g_TOKEN_ArchiveItems, (int) aWorkingSet->GetZipItemCount())) goto out; for(i = 0; i < aWorkingSet->GetZipItemCount(); i++) { if(!PR_fprintf(fd, "%d,%s\n", (int) i, aWorkingSet->GetZipItemAt(i).GetName())) goto out; } // write the Interfaces list interfaceCount = aWorkingSet->mNameTable->entryCount; if(!PR_fprintf(fd, "\n[%s,%d]\n", g_TOKEN_Interfaces, (int) interfaceCount)) goto out; if(interfaceCount != (PRIntn) PL_DHashTableEnumerate(aWorkingSet->mNameTable, xpti_InterfaceWriter, fd)) goto out; if(PR_SUCCESS == PR_Close(fd)) { succeeded = PR_TRUE; } fd = nsnull; out: if(fd) PR_Close(fd); if(succeeded) { // delete the old file and rename this nsCOMPtr<nsILocalFile> mainFile; if(!aMgr->GetCloneOfManifestLocation(getter_AddRefs(mainFile)) || !mainFile) return PR_FALSE; PRBool exists; if(NS_FAILED(mainFile->Exists(&exists))) return PR_FALSE; if(exists && NS_FAILED(mainFile->Remove(PR_FALSE))) return PR_FALSE; nsCOMPtr<nsIFile> parent; mainFile->GetParent(getter_AddRefs(parent)); // MoveTo means rename. if(NS_FAILED(tempFile->MoveToNative(parent, originalLeafName))) return PR_FALSE; } return succeeded; }
SpanningCellSorter::Item* SpanningCellSorter::GetNext(PRInt32 *aColSpan) { NS_ASSERTION(mState != DONE, "done enumerating, stop calling"); switch (mState) { case ADDING: /* prepare to enumerate the array */ mState = ENUMERATING_ARRAY; mEnumerationIndex = 0; /* fall through */ case ENUMERATING_ARRAY: while (mEnumerationIndex < ARRAY_SIZE && !mArray[mEnumerationIndex]) ++mEnumerationIndex; if (mEnumerationIndex < ARRAY_SIZE) { Item *result = mArray[mEnumerationIndex]; *aColSpan = IndexToSpan(mEnumerationIndex); NS_ASSERTION(result, "logic error"); #ifdef DEBUG_SPANNING_CELL_SORTER printf("SpanningCellSorter[%p]:" " returning list for colspan=%d from array\n", static_cast<void*>(this), *aColSpan); #endif ++mEnumerationIndex; return result; } /* prepare to enumerate the hash */ mState = ENUMERATING_HASH; mEnumerationIndex = 0; if (mHashTable.entryCount) { HashTableEntry **sh = new HashTableEntry*[mHashTable.entryCount]; if (!sh) { // give up mState = DONE; return nsnull; } PL_DHashTableEnumerate(&mHashTable, FillSortedArray, sh); NS_QuickSort(sh, mHashTable.entryCount, sizeof(sh[0]), SortArray, nsnull); mSortedHashTable = sh; } /* fall through */ case ENUMERATING_HASH: if (mEnumerationIndex < mHashTable.entryCount) { Item *result = mSortedHashTable[mEnumerationIndex]->mItems; *aColSpan = mSortedHashTable[mEnumerationIndex]->mColSpan; NS_ASSERTION(result, "holes in hash table"); #ifdef DEBUG_SPANNING_CELL_SORTER printf("SpanningCellSorter[%p]:" " returning list for colspan=%d from hash\n", static_cast<void*>(this), *aColSpan); #endif ++mEnumerationIndex; return result; } mState = DONE; /* fall through */ case DONE: ; } return nsnull; }