static int32_t* GetCOMPtrCount(void* aPtr) { PLHashEntry** hep = PL_HashTableRawLookup(gSerialNumbers, PLHashNumber(NS_PTR_TO_INT32(aPtr)), aPtr); if (hep && *hep) { return &((reinterpret_cast<serialNumberRecord*>((*hep)->value))->COMPtrCount); } else { return nullptr; } }
static intptr_t GetSerialNumber(void* aPtr, bool aCreate) { PLHashEntry** hep = PL_HashTableRawLookup(gSerialNumbers, PLHashNumber(NS_PTR_TO_INT32(aPtr)), aPtr); if (hep && *hep) { return reinterpret_cast<serialNumberRecord*>((*hep)->value)->serialNumber; } else if (aCreate) { serialNumberRecord *record = PR_NEW(serialNumberRecord); record->serialNumber = ++gNextSerialNumber; record->refCount = 0; record->COMPtrCount = 0; PL_HashTableRawAdd(gSerialNumbers, hep, PLHashNumber(NS_PTR_TO_INT32(aPtr)), aPtr, reinterpret_cast<void*>(record)); return gNextSerialNumber; } else { return 0; } }
// static nsHTMLTag nsHTMLTags::CaseSensitiveLookupTag(const PRUnichar* aTagName) { NS_ASSERTION(gTagTable, "no lookup table, needs addref"); NS_ASSERTION(aTagName, "null tagname!"); PRUint32 tag = NS_PTR_TO_INT32(PL_HashTableLookupConst(gTagTable, aTagName)); return tag == eHTMLTag_unknown ? eHTMLTag_userdefined : (nsHTMLTag)tag; }
PRBool tmQueue::IsAttached(PRUint32 aClientID) { // XXX could be an issue if the aClientID is 0 and there // is a "hole" in the mListeners vector. - may NEED to store PRUint32*s PRUint32 size = mListeners.Size(); for (PRUint32 index = 0; index < size; index++) { if (aClientID == (PRUint32)NS_PTR_TO_INT32(mListeners[index])) return PR_TRUE; } return PR_FALSE; }
PLHashNumber nsNodeInfoManager::GetNodeInfoInnerHashValue(const void *key) { NS_ASSERTION(key, "Null key passed to nsNodeInfo::GetHashValue!"); const nsINodeInfo::nsNodeInfoInner *node = reinterpret_cast<const nsINodeInfo::nsNodeInfoInner *>(key); // Is this an acceptable hash value? return (PLHashNumber(NS_PTR_TO_INT32(node->mName)) & 0xffff) >> 8; }
static void AssertActivityIsLegal() { if (gActivityTLS == BAD_TLS_INDEX || NS_PTR_TO_INT32(PR_GetThreadPrivate(gActivityTLS)) != 0) { if (PR_GetEnv("MOZ_FATAL_STATIC_XPCOM_CTORS_DTORS")) { NS_RUNTIMEABORT(kStaticCtorDtorWarning); } else { NS_WARNING(kStaticCtorDtorWarning); } } }
nsresult txMozillaXMLOutput::endHTMLElement(nsIContent* aElement) { nsIAtom *atom = aElement->Tag(); if (mTableState == ADDED_TBODY) { NS_ASSERTION(atom == txHTMLAtoms::tbody, "Element flagged as added tbody isn't a tbody"); PRUint32 last = mCurrentNodeStack.Count() - 1; NS_ASSERTION(last != (PRUint32)-1, "empty stack"); mCurrentNode = mCurrentNodeStack.SafeObjectAt(last); mCurrentNodeStack.RemoveObjectAt(last); mTableState = static_cast<TableState> (NS_PTR_TO_INT32(mTableStateStack.pop())); return NS_OK; } else if (mCreatingNewDocument && atom == txHTMLAtoms::base && !mHaveBaseElement) { // The first base wins mHaveBaseElement = PR_TRUE; nsAutoString value; aElement->GetAttr(kNameSpaceID_None, txHTMLAtoms::target, value); mDocument->SetBaseTarget(value); aElement->GetAttr(kNameSpaceID_None, txHTMLAtoms::href, value); nsCOMPtr<nsIURI> baseURI; NS_NewURI(getter_AddRefs(baseURI), value, nsnull); if (baseURI) { mDocument->SetBaseURI(baseURI); // The document checks if it is legal to set this base } } else if (mCreatingNewDocument && atom == txHTMLAtoms::meta) { // handle HTTP-EQUIV data nsAutoString httpEquiv; aElement->GetAttr(kNameSpaceID_None, txHTMLAtoms::httpEquiv, httpEquiv); if (!httpEquiv.IsEmpty()) { nsAutoString value; aElement->GetAttr(kNameSpaceID_None, txHTMLAtoms::content, value); if (!value.IsEmpty()) { ToLowerCase(httpEquiv); nsCOMPtr<nsIAtom> header = do_GetAtom(httpEquiv); processHTTPEquiv(header, value); } } } return NS_OK; }
NS_LogCOMPtrRelease(void* aCOMPtr, nsISupports* aObject) { #if defined(NS_IMPL_REFCNT_LOGGING) && defined(HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR) // Get the most-derived object. void *object = dynamic_cast<void *>(aObject); // This is a very indirect way of finding out what the class is // of the object being logged. If we're logging a specific type, // then if (!gTypesToLog || !gSerialNumbers) { return; } intptr_t serialno = GetSerialNumber(object, false); if (serialno == 0) { return; } if (!gInitialized) InitTraceLog(); if (gLogging) { LOCK_TRACELOG(); int32_t* count = GetCOMPtrCount(object); if(count) (*count)--; bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno)); if (gCOMPtrLog && loggingThisObject) { fprintf(gCOMPtrLog, "\n<?> 0x%08X %ld nsCOMPtrRelease %d 0x%08X\n", NS_PTR_TO_INT32(object), serialno, count?(*count):-1, NS_PTR_TO_INT32(aCOMPtr)); nsTraceRefcntImpl::WalkTheStack(gCOMPtrLog); } UNLOCK_TRACELOG(); } #endif }
void LossyConvertEncoding16to8::write_sse2(const char16_t* aSource, uint32_t aSourceLength) { char* dest = mDestination; // Align source to a 16-byte boundary. uint32_t i = 0; uint32_t alignLen = XPCOM_MIN<uint32_t>(aSourceLength, uint32_t(-NS_PTR_TO_INT32(aSource) & 0xf) / sizeof(char16_t)); for (; i < alignLen; ++i) { dest[i] = static_cast<unsigned char>(aSource[i]); } // Walk 64 bytes (four XMM registers) at a time. __m128i vectmask = _mm_set1_epi16(0x00ff); for (; aSourceLength - i > 31; i += 32) { __m128i source1 = _mm_load_si128(reinterpret_cast<const __m128i*>(aSource + i)); source1 = _mm_and_si128(source1, vectmask); __m128i source2 = _mm_load_si128(reinterpret_cast<const __m128i*>(aSource + i + 8)); source2 = _mm_and_si128(source2, vectmask); __m128i source3 = _mm_load_si128(reinterpret_cast<const __m128i*>(aSource + i + 16)); source3 = _mm_and_si128(source3, vectmask); __m128i source4 = _mm_load_si128(reinterpret_cast<const __m128i*>(aSource + i + 24)); source4 = _mm_and_si128(source4, vectmask); // Pack the source data. SSE2 views this as a saturating uint16_t to // uint8_t conversion, but since we masked off the high-order byte of every // uint16_t, we're really just grabbing the low-order bytes of source1 and // source2. __m128i packed1 = _mm_packus_epi16(source1, source2); __m128i packed2 = _mm_packus_epi16(source3, source4); // This store needs to be unaligned since there's no guarantee that the // alignment we did above for the source will align the destination. _mm_storeu_si128(reinterpret_cast<__m128i*>(dest + i), packed1); _mm_storeu_si128(reinterpret_cast<__m128i*>(dest + i + 16), packed2); } // Finish up the rest. for (; i < aSourceLength; ++i) { dest[i] = static_cast<unsigned char>(aSource[i]); } mDestination += i; }
void TestCase_NestedLoop(nsIThread *thread, PRInt32 index) { nsCOMPtr<nsIProxyObjectManager> manager = do_GetService(NS_XPCOMPROXY_CONTRACTID); LOG(("TEST: ProxyObjectManager: %p\n", (void *) manager.get())); PR_ASSERT(manager); nsITestProxy *proxyObject; nsTestXPCFoo2* foo = new nsTestXPCFoo2(); PR_ASSERT(foo); manager->GetProxyForObject(thread, NS_GET_IID(nsITestProxy), foo, NS_PROXY_SYNC, (void**)&proxyObject); if (proxyObject) { // release ownership of the real object. nsresult rv; LOG(("TEST: Deleting real Object (%d)\n", index)); NS_RELEASE(foo); PRInt32 retval; LOG(("TEST: Getting EventThread...\n")); //nsCOMPtr<nsIThread> curThread = do_GetCurrentThread(); PRThread *curThread = PR_GetCurrentThread(); if (curThread) { LOG(("TEST: Thread (%d) Prior to calling proxyObject->Test.\n", index)); rv = proxyObject->Test(NS_PTR_TO_INT32((void*)curThread), 0, &retval); // XXX broken on 64-bit arch LOG(("TEST: Thread (%d) proxyObject error: %x.\n", index, rv)); LOG(("TEST: Deleting Proxy Object (%d)\n", index)); NS_RELEASE(proxyObject); } PR_Sleep( PR_MillisecondsToInterval(1000) ); // If your thread goes away, your stack goes away. Only use ASYNC on calls that do not have out parameters } }
bool nsSmallVoidArray::InsertElementAt(void* aElement, int32_t aIndex) { NS_ASSERTION(!(NS_PTR_TO_INT32(aElement) & 0x1), "Attempt to add element with 0x1 bit set to nsSmallVoidArray"); if (aIndex == 0 && IsEmpty()) { SetSingle(aElement); return true; } if (!EnsureArray()) { return false; } return AsArray()->InsertElementAt(aElement, aIndex); }
PRBool nsSmallVoidArray::AppendElement(void* aElement) { NS_ASSERTION(!(NS_PTR_TO_INT32(aElement) & 0x1), "Attempt to add element with 0x1 bit set to nsSmallVoidArray"); if (IsEmpty()) { SetSingle(aElement); return PR_TRUE; } if (!EnsureArray()) { return PR_FALSE; } return AsArray()->AppendElement(aElement); }
PRBool nsSmallVoidArray::ReplaceElementAt(void* aElement, PRInt32 aIndex) { NS_ASSERTION(!(NS_PTR_TO_INT32(aElement) & 0x1), "Attempt to add element with 0x1 bit set to nsSmallVoidArray"); if (aIndex == 0 && (IsEmpty() || HasSingle())) { SetSingle(aElement); return PR_TRUE; } if (!EnsureArray()) { return PR_FALSE; } return AsArray()->ReplaceElementAt(aElement, aIndex); }
static inline PRInt32 FirstNon8BitUnvectorized(const PRUnichar *str, const PRUnichar *end) { #if PR_BYTES_PER_WORD == 4 const size_t mask = 0xff00ff00; const PRUint32 alignMask = 0x3; const PRUint32 numUnicharsPerWord = 2; #elif PR_BYTES_PER_WORD == 8 const size_t mask = 0xff00ff00ff00ff00; const PRUint32 alignMask = 0x7; const PRUint32 numUnicharsPerWord = 4; #else #error Unknown platform! #endif const PRInt32 len = end - str; PRInt32 i = 0; // Align ourselves to a word boundary. PRInt32 alignLen = NS_MIN(len, PRInt32(((-NS_PTR_TO_INT32(str)) & alignMask) / sizeof(PRUnichar))); for (; i < alignLen; i++) { if (str[i] > 255) return i; } // Check one word at a time. const PRInt32 wordWalkEnd = ((len - i) / numUnicharsPerWord) * numUnicharsPerWord; for (; i < wordWalkEnd; i += numUnicharsPerWord) { const size_t word = *reinterpret_cast<const size_t*>(str + i); if (word & mask) return i; } // Take care of the remainder one character at a time. for (; i < len; i++) { if (str[i] > 255) return i; } return -1; }
void LossyConvertEncoding8to16::write_sse2(const char* aSource, uint32_t aSourceLength) { char16_t* dest = mDestination; // Align source to a 16-byte boundary. We choose to align source rather than // dest because we'd rather have our loads than our stores be fast. You have // to wait for a load to complete, but you can keep on moving after issuing a // store. uint32_t i = 0; uint32_t alignLen = XPCOM_MIN(aSourceLength, uint32_t(-NS_PTR_TO_INT32(aSource) & 0xf)); for (; i < alignLen; ++i) { dest[i] = static_cast<unsigned char>(aSource[i]); } // Walk 32 bytes (two XMM registers) at a time. for (; aSourceLength - i > 31; i += 32) { __m128i source1 = _mm_load_si128(reinterpret_cast<const __m128i*>(aSource + i)); __m128i source2 = _mm_load_si128(reinterpret_cast<const __m128i*>(aSource + i + 16)); // Interleave 0s in with the bytes of source to create lo and hi. __m128i lo1 = _mm_unpacklo_epi8(source1, _mm_setzero_si128()); __m128i hi1 = _mm_unpackhi_epi8(source1, _mm_setzero_si128()); __m128i lo2 = _mm_unpacklo_epi8(source2, _mm_setzero_si128()); __m128i hi2 = _mm_unpackhi_epi8(source2, _mm_setzero_si128()); // store lo and hi into dest. _mm_storeu_si128(reinterpret_cast<__m128i*>(dest + i), lo1); _mm_storeu_si128(reinterpret_cast<__m128i*>(dest + i + 8), hi1); _mm_storeu_si128(reinterpret_cast<__m128i*>(dest + i + 16), lo2); _mm_storeu_si128(reinterpret_cast<__m128i*>(dest + i + 24), hi2); } // Finish up whatever's left. for (; i < aSourceLength; ++i) { dest[i] = static_cast<unsigned char>(aSource[i]); } mDestination += i; }
PRBool nsSmallVoidArray::InsertElementsAt(const nsVoidArray &aOther, PRInt32 aIndex) { #ifdef DEBUG for (int i = 0; i < aOther.Count(); i++) { NS_ASSERTION(!(NS_PTR_TO_INT32(aOther.ElementAt(i)) & 0x1), "Attempt to add element with 0x1 bit set to nsSmallVoidArray"); } #endif if (aIndex == 0 && IsEmpty() && aOther.Count() == 1) { SetSingle(aOther.FastElementAt(0)); return PR_TRUE; } if (!EnsureArray()) { return PR_FALSE; } return AsArray()->InsertElementsAt(aOther, aIndex); }
NS_LogDtor(void* aPtr, const char* aType, uint32_t aInstanceSize) { #ifdef NS_IMPL_REFCNT_LOGGING ASSERT_ACTIVITY_IS_LEGAL; if (!gInitialized) InitTraceLog(); if (gLogging) { LOCK_TRACELOG(); if (gBloatLog) { BloatEntry* entry = GetBloatEntry(aType, aInstanceSize); if (entry) { entry->Dtor(); } } bool loggingThisType = (!gTypesToLog || LogThisType(aType)); intptr_t serialno = 0; if (gSerialNumbers && loggingThisType) { serialno = GetSerialNumber(aPtr, false); RecycleSerialNumberPtr(aPtr); } bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno)); // (If we're on a losing architecture, don't do this because we'll be // using LogDeleteXPCOM instead to get file and line numbers.) if (gAllocLog && loggingThisType && loggingThisObject) { fprintf(gAllocLog, "\n<%s> 0x%08X %ld Dtor (%d)\n", aType, NS_PTR_TO_INT32(aPtr), serialno, aInstanceSize); nsTraceRefcntImpl::WalkTheStack(gAllocLog); } UNLOCK_TRACELOG(); } #endif }
/* static */ PLDHashOperator nsPresArena::FreeListEnumerator(FreeList* aEntry, void* aData) { EnumerateData* data = static_cast<EnumerateData*>(aData); // Note that we're not measuring the size of the entries on the free // list here. The free list knows how many objects we've allocated // ever (which includes any objects that may be on the FreeList's // |mEntries| at this point) and we're using that to determine the // total size of objects allocated with a given ID. size_t totalSize = aEntry->mEntrySize * aEntry->mEntriesEverAllocated; size_t* p; switch (NS_PTR_TO_INT32(aEntry->mKey)) { #define FRAME_ID(classname) \ case nsQueryFrame::classname##_id: \ p = &data->stats->FRAME_ID_STAT_FIELD(classname); \ break; #include "nsFrameIdList.h" #undef FRAME_ID case nsLineBox_id: p = &data->stats->mLineBoxes; break; case nsRuleNode_id: p = &data->stats->mRuleNodes; break; case nsStyleContext_id: p = &data->stats->mStyleContexts; break; default: return PL_DHASH_NEXT; } *p += totalSize; data->total += totalSize; return PL_DHASH_NEXT; }
PRInt32 tmQueue::PostTransaction(tmTransaction *aTrans) { PRInt32 status = -1; PRUint32 ownerID = aTrans->GetOwnerID(); // if we are attached, have the right queue and have successfully // appended the transaction to the queue, send the transaction // to all the listeners. if (IsAttached(ownerID) && aTrans->GetQueueID() == mID) status = mTransactions.Append(aTrans); if (status >= 0) { // send the transaction to all members of mListeners except the owner PRUint32 size = mListeners.Size(); PRUint32 id = 0; for (PRUint32 index = 0; index < size; index++) { id = (PRUint32)NS_PTR_TO_INT32(mListeners[index]); if (ownerID != id) mTM->SendTransaction(id, aTrans); } } tmTransaction trans; if (NS_SUCCEEDED(trans.Init(ownerID, mID, TM_POST_REPLY, status, nsnull, 0))) { // send the reply mTM->SendTransaction(ownerID, &trans); } return status; }
NS_LogRelease(void* aPtr, nsrefcnt aRefcnt, const char* aClazz) { #ifdef NS_IMPL_REFCNT_LOGGING ASSERT_ACTIVITY_IS_LEGAL; if (!gInitialized) InitTraceLog(); if (gLogging) { LOCK_TRACELOG(); if (gBloatLog) { BloatEntry* entry = GetBloatEntry(aClazz, 0); if (entry) { entry->Release(aRefcnt); } } bool loggingThisType = (!gTypesToLog || LogThisType(aClazz)); intptr_t serialno = 0; if (gSerialNumbers && loggingThisType) { serialno = GetSerialNumber(aPtr, false); NS_ASSERTION(serialno != 0, "Serial number requested for unrecognized pointer! " "Are you memmoving a refcounted object?"); int32_t* count = GetRefCount(aPtr); if(count) (*count)--; } bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno)); if (gRefcntsLog && loggingThisType && loggingThisObject) { if (gLogToLeaky) { (*leakyLogRelease)(aPtr, aRefcnt + 1, aRefcnt); } else { // Can't use PR_LOG(), b/c it truncates the line fprintf(gRefcntsLog, "\n<%s> 0x%08X %ld Release %d\n", aClazz, NS_PTR_TO_INT32(aPtr), serialno, aRefcnt); nsTraceRefcntImpl::WalkTheStack(gRefcntsLog); fflush(gRefcntsLog); } } // Here's the case where MOZ_COUNT_DTOR was not used, // yet we still want to see deletion information: if (aRefcnt == 0 && gAllocLog && loggingThisType && loggingThisObject) { fprintf(gAllocLog, "\n<%s> 0x%08X %ld Destroy\n", aClazz, NS_PTR_TO_INT32(aPtr), serialno); nsTraceRefcntImpl::WalkTheStack(gAllocLog); } if (aRefcnt == 0 && gSerialNumbers && loggingThisType) { RecycleSerialNumberPtr(aPtr); } UNLOCK_TRACELOG(); } #endif }
NS_IMETHODIMP nsSystemPrincipal::GetHashValue(PRUint32 *result) { *result = NS_PTR_TO_INT32(this); return NS_OK; }
int main(int argc, char** argv) { if (3 != argc) { printf("usage: CvtURL url utf8\n"); return -1; } char* characterSetName = argv[2]; nsString* cset = ConvertCharacterSetName(characterSetName); if (NS_PTR_TO_INT32(cset) < 0) { printf("illegal character set name: '%s'\n", characterSetName); return -1; } // Create url object char* urlName = argv[1]; nsIURI* url; nsresult rv; rv = NS_NewURI(&url, urlName); if (NS_OK != rv) { printf("invalid URL: '%s'\n", urlName); return -1; } // Get an input stream from the url nsresult ec; nsIInputStream* in; ec = NS_OpenURI(&in, url); if (nsnull == in) { printf("open of url('%s') failed: error=%x\n", urlName, ec); return -1; } // Translate the input using the argument character set id into // unicode nsCOMPtr<nsIConverterInputStream> uin = do_CreateInstance("@mozilla.org/intl/converter-input-stream;1", &rv); if (NS_SUCCEEDED(rv)) rv = uin->Init(in, cset->get(), 4096); if (NS_FAILED(rv)) { printf("can't create converter input stream: %d\n", rv); return -1; } // Read the input and write some output PRTime start = PR_Now(); PRInt32 count = 0; for (;;) { PRUnichar buf[1000]; PRUint32 nb; ec = uin->Read(buf, 0, 1000, &nb); if (NS_FAILED(ec)) { printf("i/o error: %d\n", ec); break; } if (nb == 0) break; // EOF count += nb; } PRTime end = PR_Now(); PRTime conversion, ustoms; LL_I2L(ustoms, 1000); LL_SUB(conversion, end, start); LL_DIV(conversion, conversion, ustoms); char buf[500]; PR_snprintf(buf, sizeof(buf), "converting and discarding %d bytes took %lldms", count, conversion); puts(buf); // Release the objects in->Release(); url->Release(); return 0; }
NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request, nsISupports* aContext, nsIInputStream *aIStream, uint64_t sourceOffset, uint32_t aLength) { NS_ASSERTION(mRequests.IndexOfObject(GetBaseRequest(request)) != -1, "Received OnDataAvailable for untracked request."); if (mRequestFailed) return NS_ERROR_FAILURE; if (mAbort) { uint32_t magicNumber = 0; // set it to something that is not the magic number. nsCOMPtr<nsISupportsPRUint32> container = do_QueryInterface(aContext); if (container) container->GetData(&magicNumber); if (magicNumber != MAGIC_REQUEST_CONTEXT) { // this is not one of our range requests mAbort = false; return NS_BINDING_ABORTED; } } nsresult rv = NS_OK; if (!mPStreamListener) return NS_ERROR_FAILURE; const char * url = nullptr; GetURL(&url); PLUGIN_LOG(PLUGIN_LOG_NOISY, ("nsPluginStreamListenerPeer::OnDataAvailable this=%p request=%p, offset=%llu, length=%u, url=%s\n", this, request, sourceOffset, aLength, url ? url : "no url set")); // if the plugin has requested an AsFileOnly stream, then don't // call OnDataAvailable if (mStreamType != NP_ASFILEONLY) { // get the absolute offset of the request, if one exists. nsCOMPtr<nsIByteRangeRequest> brr = do_QueryInterface(request); if (brr) { if (!mDataForwardToRequest) return NS_ERROR_FAILURE; int64_t absoluteOffset64 = 0; brr->GetStartRange(&absoluteOffset64); // XXX handle 64-bit for real int32_t absoluteOffset = (int32_t)int64_t(absoluteOffset64); // we need to track how much data we have forwarded to the // plugin. // FIXME: http://bugzilla.mozilla.org/show_bug.cgi?id=240130 // // Why couldn't this be tracked on the plugin info, and not in a // *hash table*? nsPRUintKey key(absoluteOffset); int32_t amtForwardToPlugin = NS_PTR_TO_INT32(mDataForwardToRequest->Get(&key)); mDataForwardToRequest->Put(&key, NS_INT32_TO_PTR(amtForwardToPlugin + aLength)); SetStreamOffset(absoluteOffset + amtForwardToPlugin); } nsCOMPtr<nsIInputStream> stream = aIStream; // if we are caching the file ourselves to disk, we want to 'tee' off // the data as the plugin read from the stream. We do this by the magic // of an input stream tee. if (mFileCacheOutputStream) { rv = NS_NewInputStreamTee(getter_AddRefs(stream), aIStream, mFileCacheOutputStream); if (NS_FAILED(rv)) return rv; } rv = mPStreamListener->OnDataAvailable(this, stream, aLength); // if a plugin returns an error, the peer must kill the stream // else the stream and PluginStreamListener leak if (NS_FAILED(rv)) request->Cancel(rv); } else { // if we don't read from the stream, OnStopRequest will never be called char* buffer = new char[aLength]; uint32_t amountRead, amountWrote = 0; rv = aIStream->Read(buffer, aLength, &amountRead); // if we are caching this to disk ourselves, lets write the bytes out. if (mFileCacheOutputStream) { while (amountWrote < amountRead && NS_SUCCEEDED(rv)) { rv = mFileCacheOutputStream->Write(buffer, amountRead, &amountWrote); } } delete [] buffer; } return rv; }
/* static */ PLDHashNumber SpanningCellSorter::HashTableHashKey(PLDHashTable *table, const void *key) { return NS_PTR_TO_INT32(key); }
NS_IMETHODIMP nsAbLDIFService::ImportLDIFFile(nsIAddrDatabase *aDb, nsIFile *aSrc, bool aStoreLocAsHome, PRUint32 *aProgress) { NS_ENSURE_ARG_POINTER(aSrc); NS_ENSURE_ARG_POINTER(aDb); mStoreLocAsHome = aStoreLocAsHome; char buf[1024]; char* pBuf = &buf[0]; PRInt32 startPos = 0; PRUint32 len = 0; nsVoidArray listPosArray; // where each list/group starts in ldif file nsVoidArray listSizeArray; // size of the list/group info PRInt32 savedStartPos = 0; PRInt32 filePos = 0; PRUint32 bytesLeft = 0; nsCOMPtr<nsIInputStream> inputStream; nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), aSrc); NS_ENSURE_SUCCESS(rv, rv); // Initialize the parser for a run... mLdifLine.Truncate(); while (NS_SUCCEEDED(inputStream->Available(&bytesLeft)) && bytesLeft > 0) { if (NS_SUCCEEDED(inputStream->Read(pBuf, sizeof(buf), &len)) && len > 0) { startPos = 0; while (NS_SUCCEEDED(GetLdifStringRecord(buf, len, startPos))) { if (mLdifLine.Find("groupOfNames") == -1) AddLdifRowToDatabase(aDb, false); else { //keep file position for mailing list listPosArray.AppendElement((void*)savedStartPos); listSizeArray.AppendElement((void*)(filePos + startPos-savedStartPos)); ClearLdifRecordBuffer(); } savedStartPos = filePos + startPos; } filePos += len; if (aProgress) *aProgress = (PRUint32)filePos; } } //last row if (!mLdifLine.IsEmpty() && mLdifLine.Find("groupOfNames") == -1) AddLdifRowToDatabase(aDb, false); // mail Lists PRInt32 i, pos; PRUint32 size; PRInt32 listTotal = listPosArray.Count(); char *listBuf; ClearLdifRecordBuffer(); // make sure the buffer is clean nsCOMPtr<nsISeekableStream> seekableStream = do_QueryInterface(inputStream, &rv); NS_ENSURE_SUCCESS(rv, rv); for (i = 0; i < listTotal; i++) { pos = NS_PTR_TO_INT32(listPosArray.ElementAt(i)); size = NS_PTR_TO_INT32(listSizeArray.ElementAt(i)); if (NS_SUCCEEDED(seekableStream->Seek(nsISeekableStream::NS_SEEK_SET, pos))) { // Allocate enough space for the lists/groups as the size varies. listBuf = (char *) PR_Malloc(size); if (!listBuf) continue; if (NS_SUCCEEDED(inputStream->Read(listBuf, size, &len)) && len > 0) { startPos = 0; while (NS_SUCCEEDED(GetLdifStringRecord(listBuf, len, startPos))) { if (mLdifLine.Find("groupOfNames") != -1) { AddLdifRowToDatabase(aDb, true); if (NS_SUCCEEDED(seekableStream->Seek(nsISeekableStream::NS_SEEK_SET, 0))) break; } } } PR_FREEIF(listBuf); } } rv = inputStream->Close(); NS_ENSURE_SUCCESS(rv, rv); // Finally commit everything to the database and return. return aDb->Commit(nsAddrDBCommitType::kLargeCommit); }
static PLDHashNumber HashKey( PLDHashTable *table, const void *key) { return (PLDHashNumber) NS_PTR_TO_INT32(key); }
nsresult txMozillaXMLOutput::endElement() { TX_ENSURE_CURRENTNODE; if (mBadChildLevel) { --mBadChildLevel; PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("endElement, mBadChildLevel = %d\n", mBadChildLevel)); return NS_OK; } --mTreeDepth; nsresult rv = closePrevious(PR_TRUE); NS_ENSURE_SUCCESS(rv, rv); NS_ASSERTION(mCurrentNode->IsElement(), "borked mCurrentNode"); NS_ENSURE_TRUE(mCurrentNode->IsElement(), NS_ERROR_UNEXPECTED); nsIContent* element = static_cast<nsIContent*> (static_cast<nsINode*> (mCurrentNode)); // Handle html-elements if (!mNoFixup) { if (element->IsHTML()) { rv = endHTMLElement(element); NS_ENSURE_SUCCESS(rv, rv); } // Handle script elements if (element->Tag() == nsGkAtoms::script && (element->IsHTML() || element->GetNameSpaceID() == kNameSpaceID_SVG)) { rv = element->DoneAddingChildren(PR_TRUE); // If the act of insertion evaluated the script, we're fine. // Else, add this script element to the array of loading scripts. if (rv == NS_ERROR_HTMLPARSER_BLOCK) { nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(element); rv = mNotifier->AddScriptElement(sele); NS_ENSURE_SUCCESS(rv, rv); } } } if (mCreatingNewDocument) { // Handle all sorts of stylesheets nsCOMPtr<nsIStyleSheetLinkingElement> ssle = do_QueryInterface(mCurrentNode); if (ssle) { ssle->SetEnableUpdates(PR_TRUE); PRBool willNotify; PRBool isAlternate; nsresult rv = ssle->UpdateStyleSheet(mNotifier, &willNotify, &isAlternate); if (mNotifier && NS_SUCCEEDED(rv) && willNotify && !isAlternate) { mNotifier->AddPendingStylesheet(); } } } // Add the element to the tree if it wasn't added before and take one step // up the tree PRUint32 last = mCurrentNodeStack.Count() - 1; NS_ASSERTION(last != (PRUint32)-1, "empty stack"); nsCOMPtr<nsINode> parent = mCurrentNodeStack.SafeObjectAt(last); mCurrentNodeStack.RemoveObjectAt(last); if (mCurrentNode == mNonAddedNode) { if (parent == mDocument) { NS_ASSERTION(!mRootContentCreated, "Parent to add to shouldn't be a document if we " "have a root content"); mRootContentCreated = PR_TRUE; } // Check to make sure that script hasn't inserted the node somewhere // else in the tree if (!mCurrentNode->GetNodeParent()) { parent->AppendChildTo(mNonAddedNode, PR_TRUE); } mNonAddedNode = nsnull; } mCurrentNode = parent; mTableState = static_cast<TableState>(NS_PTR_TO_INT32(mTableStateStack.pop())); return NS_OK; }
PRUint32 nsAttrValue::HashValue() const { switch(BaseType()) { case eStringBase: { nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr()); if (str) { PRUint32 len = str->StorageSize()/sizeof(PRUnichar) - 1; return nsCRT::HashCode(static_cast<PRUnichar*>(str->Data()), len); } return 0; } case eOtherBase: { break; } case eAtomBase: case eIntegerBase: { // mBits and PRUint32 might have different size. This should silence // any warnings or compile-errors. This is what the implementation of // NS_PTR_TO_INT32 does to take care of the same problem. return mBits - 0; } } MiscContainer* cont = GetMiscContainer(); if (static_cast<ValueBaseType>(cont->mStringBits & NS_ATTRVALUE_BASETYPE_MASK) == eAtomBase) { return cont->mStringBits - 0; } switch (cont->mType) { case eInteger: { return cont->mInteger; } case eEnum: { return cont->mEnumValue; } case ePercent: { return cont->mPercent; } case eColor: { return cont->mColor; } case eCSSStyleRule: { return NS_PTR_TO_INT32(cont->mCSSStyleRule); } case eAtomArray: { PRUint32 retval = 0; PRUint32 count = cont->mAtomArray->Length(); for (nsCOMPtr<nsIAtom> *cur = cont->mAtomArray->Elements(), *end = cur + count; cur != end; ++cur) { retval ^= NS_PTR_TO_INT32(cur->get()); } return retval; } case eSVGValue: { return NS_PTR_TO_INT32(cont->mSVGValue); } case eDoubleValue: { // XXX this is crappy, but oh well return cont->mDoubleValue; } case eIntMarginValue: { return NS_PTR_TO_INT32(cont->mIntMargin); } default: { NS_NOTREACHED("unknown type stored in MiscContainer"); return 0; } } }
static PLHashNumber HashNumber(const void* aKey) { return PLHashNumber(NS_PTR_TO_INT32(aKey)); }
nsresult txMozillaXMLOutput::startHTMLElement(nsIContent* aElement, PRBool aIsHTML) { nsresult rv = NS_OK; nsIAtom *atom = aElement->Tag(); if ((atom != txHTMLAtoms::tr || !aIsHTML) && NS_PTR_TO_INT32(mTableStateStack.peek()) == ADDED_TBODY) { PRUint32 last = mCurrentNodeStack.Count() - 1; NS_ASSERTION(last != (PRUint32)-1, "empty stack"); mCurrentNode = mCurrentNodeStack.SafeObjectAt(last); mCurrentNodeStack.RemoveObjectAt(last); mTableStateStack.pop(); } if (atom == txHTMLAtoms::table && aIsHTML) { mTableState = TABLE; } else if (atom == txHTMLAtoms::tr && aIsHTML && NS_PTR_TO_INT32(mTableStateStack.peek()) == TABLE) { nsCOMPtr<nsIContent> tbody; rv = createHTMLElement(nsGkAtoms::tbody, getter_AddRefs(tbody)); NS_ENSURE_SUCCESS(rv, rv); rv = mCurrentNode->AppendChildTo(tbody, PR_TRUE); NS_ENSURE_SUCCESS(rv, rv); rv = mTableStateStack.push(NS_INT32_TO_PTR(ADDED_TBODY)); NS_ENSURE_SUCCESS(rv, rv); if (!mCurrentNodeStack.AppendObject(tbody)) { return NS_ERROR_OUT_OF_MEMORY; } mCurrentNode = tbody; } else if (atom == txHTMLAtoms::head && mOutputFormat.mMethod == eHTMLOutput) { // Insert META tag, according to spec, 16.2, like // <META http-equiv="Content-Type" content="text/html; charset=EUC-JP"> nsCOMPtr<nsIContent> meta; rv = createHTMLElement(nsGkAtoms::meta, getter_AddRefs(meta)); NS_ENSURE_SUCCESS(rv, rv); rv = meta->SetAttr(kNameSpaceID_None, nsGkAtoms::httpEquiv, NS_LITERAL_STRING("Content-Type"), PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); nsAutoString metacontent; metacontent.Append(mOutputFormat.mMediaType); metacontent.AppendLiteral("; charset="); metacontent.Append(mOutputFormat.mEncoding); rv = meta->SetAttr(kNameSpaceID_None, nsGkAtoms::content, metacontent, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); // No need to notify since aElement hasn't been inserted yet NS_ASSERTION(!aElement->IsInDoc(), "should not be in doc"); rv = aElement->AppendChildTo(meta, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; }