diff --git a/mozilla/caps/src/nsScriptSecurityManager.cpp b/mozilla/caps/src/nsScriptSecurityManager.cpp index 5a411d9836e..54608b47ec5 100644 --- a/mozilla/caps/src/nsScriptSecurityManager.cpp +++ b/mozilla/caps/src/nsScriptSecurityManager.cpp @@ -208,7 +208,9 @@ nsScriptSecurityManager::CheckPropertyAccessImpl(PRUint32 aAction, } else { - nsXPIDLCString className; + nsXPIDLCString classNameStr; + const char* className; + nsCAutoString propertyName(aProperty); if (aClassName) className = aClassName; @@ -216,7 +218,9 @@ nsScriptSecurityManager::CheckPropertyAccessImpl(PRUint32 aAction, //-- Get className and propertyName from aClassInfo and aName, repectively { if(aClassInfo) - aClassInfo->GetClassDescription(getter_Copies(className)); + aClassInfo->GetClassDescription(getter_Copies(classNameStr)); + className = classNameStr.get(); + if (!className) className = "UnknownClass"; propertyName.AssignWithConversion((PRUnichar*)JSValIDToString(aJSContext, aName)); diff --git a/mozilla/chrome/src/nsChromeProtocolHandler.cpp b/mozilla/chrome/src/nsChromeProtocolHandler.cpp index 09641510ca4..e5204b7e10e 100644 --- a/mozilla/chrome/src/nsChromeProtocolHandler.cpp +++ b/mozilla/chrome/src/nsChromeProtocolHandler.cpp @@ -324,7 +324,7 @@ nsCachedChromeChannel::SetNotificationCallbacks(nsIInterfaceRequestor * aNotific NS_IMETHODIMP nsCachedChromeChannel::GetContentType(char * *aContentType) { - *aContentType = nsXPIDLCString::Copy("mozilla.application/cached-xul"); + *aContentType = nsCRT::strdup("mozilla.application/cached-xul"); return *aContentType ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/chrome/src/nsChromeRegistry.cpp b/mozilla/chrome/src/nsChromeRegistry.cpp index 22360365022..0fb83fb7578 100644 --- a/mozilla/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/chrome/src/nsChromeRegistry.cpp @@ -551,9 +551,7 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL, char** aResult) } } - finalURL += remaining; - - *aResult = nsXPIDLCString::Copy(finalURL); + *aResult = ToNewCString(finalURL + remaining); return NS_OK; } @@ -1576,7 +1574,7 @@ NS_IMETHODIMP nsChromeRegistry::GetSelectedLocale(const PRUnichar *aPackageName, if (NS_FAILED(rv)) return rv; // this is not i18n friendly? RDF now use UTF8 internally. - *_retval = nsXPIDLString::Copy(NS_ConvertASCIItoUCS2(lc_name).GetUnicode()); + *_retval = ToNewUnicode(lc_name); return NS_OK; } diff --git a/mozilla/chrome/src/nsChromeUIDataSource.cpp b/mozilla/chrome/src/nsChromeUIDataSource.cpp index fba5c701397..2ae9c3c64eb 100644 --- a/mozilla/chrome/src/nsChromeUIDataSource.cpp +++ b/mozilla/chrome/src/nsChromeUIDataSource.cpp @@ -106,7 +106,7 @@ nsChromeUIDataSource::Release() NS_IMETHODIMP nsChromeUIDataSource::GetURI(char** aURI) { - *aURI = nsXPIDLCString::Copy("rdf:chrome"); + *aURI = nsCRT::strdup("rdf:chrome"); if (! *aURI) return NS_ERROR_OUT_OF_MEMORY; diff --git a/mozilla/content/base/src/nsHTMLContentSerializer.cpp b/mozilla/content/base/src/nsHTMLContentSerializer.cpp index 7685a211bd5..c84df500e42 100644 --- a/mozilla/content/base/src/nsHTMLContentSerializer.cpp +++ b/mozilla/content/base/src/nsHTMLContentSerializer.cpp @@ -179,7 +179,7 @@ nsHTMLContentSerializer::EscapeURI(const nsAReadableString& aURI, nsAWritableStr if (mCharSet && !uri.IsASCII()) { const PRUnichar *charset; mCharSet->GetUnicode(&charset); - documentCharset = NS_ConvertUCS2toUTF8(charset).get(); + documentCharset.Adopt(ToNewUTF8String(nsDependentString(charset))); textToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); } @@ -198,7 +198,7 @@ nsHTMLContentSerializer::EscapeURI(const nsAReadableString& aURI, nsAWritableStr NS_ENSURE_SUCCESS(rv, rv); } else { - escapedURI = nsEscape(NS_ConvertUCS2toUTF8(part).get(), url_Path); + escapedURI.Adopt(nsEscape(NS_ConvertUCS2toUTF8(part).get(), url_Path)); } aEscapedURI.Append(NS_ConvertASCIItoUCS2(escapedURI)); @@ -216,7 +216,7 @@ nsHTMLContentSerializer::EscapeURI(const nsAReadableString& aURI, nsAWritableStr NS_ENSURE_SUCCESS(rv, rv); } else { - escapedURI = nsEscape(NS_ConvertUCS2toUTF8(part).get(), url_Path); + escapedURI.Adopt(nsEscape(NS_ConvertUCS2toUTF8(part).get(), url_Path)); } aEscapedURI.Append(NS_ConvertASCIItoUCS2(escapedURI)); } @@ -244,8 +244,8 @@ nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent, *getter_AddRefs(attrPrefix)); // Filter out any attribute starting with _moz - nsXPIDLString sharedName; - attrName->GetUnicode(getter_Shares(sharedName)); + const PRUnichar* sharedName; + attrName->GetUnicode(&sharedName); if (nsCRT::strncmp(sharedName, NS_ConvertASCIItoUCS2(kMozStr).get(), sizeof(kMozStr)-1) == 0) { @@ -334,8 +334,8 @@ nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, AppendToString(kLessThan, aStr); - nsXPIDLString sharedName; - name->GetUnicode(getter_Shares(sharedName)); + const PRUnichar* sharedName; + name->GetUnicode(&sharedName); AppendToString(sharedName, -1, aStr); SerializeAttributes(content, name, aStr); @@ -376,8 +376,8 @@ nsHTMLContentSerializer::AppendElementEnd(nsIDOMElement *aElement, mPreLevel--; } - nsXPIDLString sharedName; - name->GetUnicode(getter_Shares(sharedName)); + const PRUnichar* sharedName; + name->GetUnicode(&sharedName); nsCOMPtr parserService; GetParserService(getter_AddRefs(parserService)); diff --git a/mozilla/content/xbl/src/nsXBLBinding.cpp b/mozilla/content/xbl/src/nsXBLBinding.cpp index 8f2f978df82..766c23402cd 100644 --- a/mozilla/content/xbl/src/nsXBLBinding.cpp +++ b/mozilla/content/xbl/src/nsXBLBinding.cpp @@ -107,7 +107,7 @@ nsXBLJSClass::nsXBLJSClass(const nsCString& aClassName) { memset(this, 0, sizeof(nsXBLJSClass)); next = prev = NS_STATIC_CAST(JSCList*, this); - name = nsXPIDLCString::Copy(aClassName); + name = ToNewCString(aClassName); addProperty = delProperty = setProperty = getProperty = ::JS_PropertyStub; enumerate = ::JS_EnumerateStub; resolve = ::JS_ResolveStub; @@ -1616,7 +1616,7 @@ nsXBLBinding::InitClass(const nsCString& aClassName, nsIScriptContext* aContext, // Change the class name and we're done. nsMemory::Free((void*) c->name); - c->name = nsXPIDLCString::Copy(aClassName); + c->name = ToNewCString(aClassName); } // Add c to our table. diff --git a/mozilla/embedding/components/windowwatcher/src/nsPromptService.cpp b/mozilla/embedding/components/windowwatcher/src/nsPromptService.cpp index af31ecde272..ca7a46b3a76 100644 --- a/mozilla/embedding/components/windowwatcher/src/nsPromptService.cpp +++ b/mozilla/embedding/components/windowwatcher/src/nsPromptService.cpp @@ -280,35 +280,39 @@ nsPromptService::ConfirmEx(nsIDOMWindow *parent, PRInt32 numberButtons = 0; for (int i = 0; i < 3; i++) { - nsXPIDLString buttonText; + nsXPIDLString buttonTextStr; + const PRUnichar* buttonText = 0; switch (buttonFlags & 0xff) { case BUTTON_TITLE_OK: - GetLocaleString("OK", getter_Copies(buttonText)); + GetLocaleString("OK", getter_Copies(buttonTextStr)); break; case BUTTON_TITLE_CANCEL: - GetLocaleString("Cancel", getter_Copies(buttonText)); + GetLocaleString("Cancel", getter_Copies(buttonTextStr)); break; case BUTTON_TITLE_YES: - GetLocaleString("Yes", getter_Copies(buttonText)); + GetLocaleString("Yes", getter_Copies(buttonTextStr)); break; case BUTTON_TITLE_NO: - GetLocaleString("No", getter_Copies(buttonText)); + GetLocaleString("No", getter_Copies(buttonTextStr)); break; case BUTTON_TITLE_SAVE: - GetLocaleString("Save", getter_Copies(buttonText)); + GetLocaleString("Save", getter_Copies(buttonTextStr)); break; case BUTTON_TITLE_DONT_SAVE: - GetLocaleString("DontSave", getter_Copies(buttonText)); + GetLocaleString("DontSave", getter_Copies(buttonTextStr)); break; case BUTTON_TITLE_REVERT: - GetLocaleString("Revert", getter_Copies(buttonText)); + GetLocaleString("Revert", getter_Copies(buttonTextStr)); break; case BUTTON_TITLE_IS_STRING: - *getter_Shares(buttonText) = buttonStrings[i]; + buttonText = buttonStrings[i]; break; } - if (buttonText.get()) { - block->SetString(buttonIDs[i], buttonText.get()); + if (!buttonText) + buttonText = buttonTextStr.get(); + + if (buttonText) { + block->SetString(buttonIDs[i], buttonText); ++numberButtons; } buttonFlags >>= 8; diff --git a/mozilla/extensions/finger/nsFingerChannel.cpp b/mozilla/extensions/finger/nsFingerChannel.cpp index 470a0d424f9..bc54b187ff8 100644 --- a/mozilla/extensions/finger/nsFingerChannel.cpp +++ b/mozilla/extensions/finger/nsFingerChannel.cpp @@ -417,7 +417,7 @@ nsFingerChannel::SendRequest(nsITransport* aTransport) { requestBuffer.Append(CRLF); - mRequest = requestBuffer.ToNewCString(); + mRequest.Adopt(ToNewCString(requestBuffer)); rv = NS_NewCharInputStream(getter_AddRefs(result), mRequest); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/gfx/src/nsFontList.cpp b/mozilla/gfx/src/nsFontList.cpp index 86e0e434b5c..ef68f99a95c 100644 --- a/mozilla/gfx/src/nsFontList.cpp +++ b/mozilla/gfx/src/nsFontList.cpp @@ -104,9 +104,9 @@ nsFontListEnumerator::Init(const PRUnichar *aLangGroup, return rv; nsXPIDLCString langGroup; - langGroup = ToNewUTF8String(nsDependentString(aLangGroup)); + langGroup.Adopt(ToNewUTF8String(nsDependentString(aLangGroup))); nsXPIDLCString fontType; - fontType = ToNewUTF8String(nsDependentString(aFontType)); + fontType.Adopt(ToNewUTF8String(nsDependentString(aFontType))); rv = fontEnumerator->EnumerateFonts(langGroup.get(), fontType.get(), &mCount, &mFonts); return rv; diff --git a/mozilla/gfx/src/ps/nsPostScriptObj.cpp b/mozilla/gfx/src/ps/nsPostScriptObj.cpp index 1ad5c361129..e1b08669437 100644 --- a/mozilla/gfx/src/ps/nsPostScriptObj.cpp +++ b/mozilla/gfx/src/ps/nsPostScriptObj.cpp @@ -1670,8 +1670,8 @@ static void PrefEnumCallback(const char *aName, void *aClosure) if (((psnativefont)&&(*psnativefont)) && ((psnativecode)&&(*psnativecode))) { use_prefsfile = PR_TRUE; } else { - psnativefont = nsnull; - psnativecode = nsnull; + psnativefont.Adopt(0); + psnativecode.Adopt(0); } // @@ -1683,8 +1683,8 @@ static void PrefEnumCallback(const char *aName, void *aClosure) if ((psnativefont) && (psnativecode)) { use_vendorfile = PR_TRUE; } else { - psnativefont = nsnull; - psnativecode = nsnull; + psnativefont.Adopt(0); + psnativecode.Adopt(0); } } if (!use_prefsfile && !use_vendorfile) { @@ -1694,8 +1694,8 @@ static void PrefEnumCallback(const char *aName, void *aClosure) /* psnativefont and psnativecode both should be set */ if (!psnativefont || !psnativecode) { - psnativefont = nsnull; - psnativecode = nsnull; + psnativefont.Adopt(0); + psnativecode.Adopt(0); } else { nsCAutoString namepsfontorder("print.psfontorder."); namepsfontorder.AppendWithConversion(lang); diff --git a/mozilla/intl/uconv/src/nsCharsetMenu.cpp b/mozilla/intl/uconv/src/nsCharsetMenu.cpp index 4197a8e3468..2ee2a7008e0 100644 --- a/mozilla/intl/uconv/src/nsCharsetMenu.cpp +++ b/mozilla/intl/uconv/src/nsCharsetMenu.cpp @@ -1604,7 +1604,7 @@ NS_IMETHODIMP nsCharsetMenu::GetURI(char ** uri) { if (!uri) return NS_ERROR_NULL_POINTER; - *uri = nsXPIDLCString::Copy("rdf:charset-menu"); + *uri = nsCRT::strdup("rdf:charset-menu"); if (!(*uri)) return NS_ERROR_OUT_OF_MEMORY; return NS_OK; diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index 86d13346ae6..cea27803eb0 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -840,12 +840,12 @@ nsObjectFrame::Reflow(nsIPresContext* aPresContext, rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, "application/x-java-vm", fullURL); } else { // traditional plugin - nsXPIDLCString mimeType; + nsXPIDLCString mimeTypeStr; nsAutoString type; mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::type, type); if (type.Length()) { - *getter_Copies(mimeType) = type.ToNewCString(); + mimeTypeStr.Adopt(ToNewCString(type)); } //stream in the object source if there is one... if (NS_CONTENT_ATTR_HAS_VALUE == @@ -878,13 +878,14 @@ nsObjectFrame::Reflow(nsIPresContext* aPresContext, // if we didn't find the type, but we do have a src, we can // determine the mimetype based on the file extension + const char* mimeType = mimeTypeStr.get(); if (!mimeType && src.GetUnicode()) { nsXPIDLCString extension; PRInt32 offset = src.RFindChar(PRUnichar('.')); if (offset != kNotFound) { *getter_Copies(extension) = ToNewCString(Substring(src, offset+1, src.Length())); } - pluginHost->IsPluginEnabledForExtension(extension, *getter_Shares(mimeType)); + pluginHost->IsPluginEnabledForExtension(extension, mimeType); } rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, mimeType, fullURL); diff --git a/mozilla/layout/html/base/src/nsObjectFrame.cpp b/mozilla/layout/html/base/src/nsObjectFrame.cpp index 86d13346ae6..cea27803eb0 100644 --- a/mozilla/layout/html/base/src/nsObjectFrame.cpp +++ b/mozilla/layout/html/base/src/nsObjectFrame.cpp @@ -840,12 +840,12 @@ nsObjectFrame::Reflow(nsIPresContext* aPresContext, rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, "application/x-java-vm", fullURL); } else { // traditional plugin - nsXPIDLCString mimeType; + nsXPIDLCString mimeTypeStr; nsAutoString type; mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::type, type); if (type.Length()) { - *getter_Copies(mimeType) = type.ToNewCString(); + mimeTypeStr.Adopt(ToNewCString(type)); } //stream in the object source if there is one... if (NS_CONTENT_ATTR_HAS_VALUE == @@ -878,13 +878,14 @@ nsObjectFrame::Reflow(nsIPresContext* aPresContext, // if we didn't find the type, but we do have a src, we can // determine the mimetype based on the file extension + const char* mimeType = mimeTypeStr.get(); if (!mimeType && src.GetUnicode()) { nsXPIDLCString extension; PRInt32 offset = src.RFindChar(PRUnichar('.')); if (offset != kNotFound) { *getter_Copies(extension) = ToNewCString(Substring(src, offset+1, src.Length())); } - pluginHost->IsPluginEnabledForExtension(extension, *getter_Shares(mimeType)); + pluginHost->IsPluginEnabledForExtension(extension, mimeType); } rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, mimeType, fullURL); diff --git a/mozilla/layout/xul/base/src/outliner/src/nsOutlinerBodyFrame.cpp b/mozilla/layout/xul/base/src/outliner/src/nsOutlinerBodyFrame.cpp index 06eb68a8994..28d20066b6f 100644 --- a/mozilla/layout/xul/base/src/outliner/src/nsOutlinerBodyFrame.cpp +++ b/mozilla/layout/xul/base/src/outliner/src/nsOutlinerBodyFrame.cpp @@ -788,11 +788,11 @@ NS_IMETHODIMP nsOutlinerBodyFrame::GetCellAt(PRInt32 aX, PRInt32 aY, PRInt32* aR if (x >= cellRect.x && x < cellRect.x + cellRect.width) { // We know the column hit now. - *aColID = nsXPIDLString::Copy(currCol->GetID()); + *aColID = nsCRT::strdup(currCol->GetID()); if (currCol->IsCycler()) // Cyclers contain only images. Fill this in immediately and return. - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("image").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("image")); else GetItemWithinCellAt(x, cellRect, *aRow, currCol, aChildElt); break; @@ -1050,7 +1050,7 @@ nsOutlinerBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, if (aX < cellRect.x || aX >= cellRect.x + cellRect.width) { // The user clicked within the cell's margins/borders/padding. This constitutes a click on the cell. - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("cell").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("cell")); return NS_OK; } @@ -1069,7 +1069,7 @@ nsOutlinerBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, if (aX < currX) { // The user clicked within the indentation. - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("cell").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("cell")); return NS_OK; } @@ -1104,9 +1104,9 @@ nsOutlinerBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, // then we return "cell". if (aX >= twistyRect.x && aX < twistyRect.x + twistyRect.width) { if (hasTwisty) - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("twisty").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("twisty")); else - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("cell").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("cell")); return NS_OK; } @@ -1130,13 +1130,13 @@ nsOutlinerBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, if (aX >= iconRect.x && aX < iconRect.x + iconRect.width) { // The user clicked on the image. - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("image").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("image")); return NS_OK; } // Just assume "text". // XXX For marquee selection, we'll have to make this more precise and do text measurement. - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("text").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("text")); return NS_OK; } diff --git a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index 06eb68a8994..28d20066b6f 100644 --- a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -788,11 +788,11 @@ NS_IMETHODIMP nsOutlinerBodyFrame::GetCellAt(PRInt32 aX, PRInt32 aY, PRInt32* aR if (x >= cellRect.x && x < cellRect.x + cellRect.width) { // We know the column hit now. - *aColID = nsXPIDLString::Copy(currCol->GetID()); + *aColID = nsCRT::strdup(currCol->GetID()); if (currCol->IsCycler()) // Cyclers contain only images. Fill this in immediately and return. - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("image").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("image")); else GetItemWithinCellAt(x, cellRect, *aRow, currCol, aChildElt); break; @@ -1050,7 +1050,7 @@ nsOutlinerBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, if (aX < cellRect.x || aX >= cellRect.x + cellRect.width) { // The user clicked within the cell's margins/borders/padding. This constitutes a click on the cell. - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("cell").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("cell")); return NS_OK; } @@ -1069,7 +1069,7 @@ nsOutlinerBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, if (aX < currX) { // The user clicked within the indentation. - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("cell").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("cell")); return NS_OK; } @@ -1104,9 +1104,9 @@ nsOutlinerBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, // then we return "cell". if (aX >= twistyRect.x && aX < twistyRect.x + twistyRect.width) { if (hasTwisty) - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("twisty").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("twisty")); else - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("cell").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("cell")); return NS_OK; } @@ -1130,13 +1130,13 @@ nsOutlinerBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, if (aX >= iconRect.x && aX < iconRect.x + iconRect.width) { // The user clicked on the image. - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("image").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("image")); return NS_OK; } // Just assume "text". // XXX For marquee selection, we'll have to make this more precise and do text measurement. - *aChildElt = nsXPIDLString::Copy(NS_LITERAL_STRING("text").get()); + *aChildElt = ToNewUnicode(NS_LITERAL_STRING("text")); return NS_OK; } diff --git a/mozilla/mailnews/addrbook/src/nsCardDataSource.cpp b/mozilla/mailnews/addrbook/src/nsCardDataSource.cpp index aa1558a309e..7ebe1311fdb 100644 --- a/mozilla/mailnews/addrbook/src/nsCardDataSource.cpp +++ b/mozilla/mailnews/addrbook/src/nsCardDataSource.cpp @@ -272,7 +272,7 @@ NS_IMETHODIMP nsAbCardDataSource::QueryInterface(REFNSIID iid, void** result) // nsIRDFDataSource methods NS_IMETHODIMP nsAbCardDataSource::GetURI(char* *uri) { - if ((*uri = nsXPIDLCString::Copy("rdf:addresscard")) == nsnull) + if ((*uri = nsCRT::strdup("rdf:addresscard")) == nsnull) return NS_ERROR_OUT_OF_MEMORY; else return NS_OK; diff --git a/mozilla/mailnews/addrbook/src/nsDirectoryDataSource.cpp b/mozilla/mailnews/addrbook/src/nsDirectoryDataSource.cpp index 7097e340d10..0ab031ad60c 100644 --- a/mozilla/mailnews/addrbook/src/nsDirectoryDataSource.cpp +++ b/mozilla/mailnews/addrbook/src/nsDirectoryDataSource.cpp @@ -172,7 +172,7 @@ NS_IMETHODIMP nsAbDirectoryDataSource::QueryInterface(REFNSIID iid, void** resul // nsIRDFDataSource methods NS_IMETHODIMP nsAbDirectoryDataSource::GetURI(char* *uri) { - if ((*uri = nsXPIDLCString::Copy("rdf:addressdirectory")) == nsnull) + if ((*uri = nsCRT::strdup("rdf:addressdirectory")) == nsnull) return NS_ERROR_OUT_OF_MEMORY; else return NS_OK; diff --git a/mozilla/mailnews/base/search/src/nsMsgFilterDataSource.cpp b/mozilla/mailnews/base/search/src/nsMsgFilterDataSource.cpp index b1e3b1e82a9..7a17b09f1eb 100644 --- a/mozilla/mailnews/base/search/src/nsMsgFilterDataSource.cpp +++ b/mozilla/mailnews/base/search/src/nsMsgFilterDataSource.cpp @@ -283,10 +283,10 @@ nsMsgFilterDataSource::getFilterListTargets(nsIMsgFilterList *aFilterList, // a better way to do this might be to ask the filter // what folder it's in. Then we wouldn't need aSource - nsXPIDLCString filterListUri; - aSource->GetValueConst(getter_Shares(filterListUri)); + const char* filterListUri; + aSource->GetValueConst(&filterListUri); - nsCAutoString filterUri((const char *)filterListUri); + nsCAutoString filterUri(filterListUri); filterUri.Append(";filterName="); // we'll use the length of this base string to truncate the string later diff --git a/mozilla/mailnews/base/search/src/nsMsgFilterDelegateFactory.cpp b/mozilla/mailnews/base/search/src/nsMsgFilterDelegateFactory.cpp index 96550a3d4bb..fd6fc43701a 100644 --- a/mozilla/mailnews/base/search/src/nsMsgFilterDelegateFactory.cpp +++ b/mozilla/mailnews/base/search/src/nsMsgFilterDelegateFactory.cpp @@ -69,8 +69,8 @@ NS_IMETHODIMP nsMsgFilterDelegateFactory::CreateDelegate(nsIRDFResource *aOuter, // mailbox://userid@server/foldername;filterName=foo - nsXPIDLCString uri; - aOuter->GetValueConst(getter_Shares(uri)); + const char* uri; + aOuter->GetValueConst(&uri); // if it has ';filter' then it's a filter, otherwise we'll assume // that it's a folder. diff --git a/mozilla/mailnews/base/src/nsMessengerMigrator.cpp b/mozilla/mailnews/base/src/nsMessengerMigrator.cpp index 53e6912d10f..41963f6537b 100644 --- a/mozilla/mailnews/base/src/nsMessengerMigrator.cpp +++ b/mozilla/mailnews/base/src/nsMessengerMigrator.cpp @@ -1899,7 +1899,7 @@ nsMessengerMigrator::migrateAddressBookPrefEnum(const char *aPref, void *aClosur if (NS_FAILED(rv)) { // if we fail to get the pref value, set it to "", which will // later cause us to use the system charset - *((char **)getter_Copies(csidPrefValue)) = nsXPIDLCString::Copy(""); + csidPrefValue.Adopt(nsCRT::strdup("")); } nsCOMPtr abUpgrader = do_GetService(NS_AB4xUPGRADER_CONTRACTID, &rv); diff --git a/mozilla/mailnews/base/src/nsMsgAccount.cpp b/mozilla/mailnews/base/src/nsMsgAccount.cpp index 4b6974842fd..031cfaad29d 100644 --- a/mozilla/mailnews/base/src/nsMsgAccount.cpp +++ b/mozilla/mailnews/base/src/nsMsgAccount.cpp @@ -136,8 +136,7 @@ nsMsgAccount::createIncomingServer() // the server type doesn't exist, use "generic" if (NS_FAILED(rv)) { - *((char **)getter_Copies(serverType)) = nsXPIDLCString::Copy("generic"); - return rv; + serverType.Adopt(nsCRT::strdup("generic")); } #ifdef DEBUG_alecf diff --git a/mozilla/mailnews/base/src/nsMsgFolderDataSource.cpp b/mozilla/mailnews/base/src/nsMsgFolderDataSource.cpp index 8491a13a507..283143b035a 100644 --- a/mozilla/mailnews/base/src/nsMsgFolderDataSource.cpp +++ b/mozilla/mailnews/base/src/nsMsgFolderDataSource.cpp @@ -294,7 +294,7 @@ nsMsgFolderDataSource::QueryInterface(REFNSIID iid, void** result) // nsIRDFDataSource methods NS_IMETHODIMP nsMsgFolderDataSource::GetURI(char* *uri) { - if ((*uri = nsXPIDLCString::Copy("rdf:mailnewsfolders")) == nsnull) + if ((*uri = nsCRT::strdup("rdf:mailnewsfolders")) == nsnull) return NS_ERROR_OUT_OF_MEMORY; else return NS_OK; diff --git a/mozilla/mailnews/base/src/nsSubscribeDataSource.cpp b/mozilla/mailnews/base/src/nsSubscribeDataSource.cpp index 0232286d562..3c10e77bfc9 100644 --- a/mozilla/mailnews/base/src/nsSubscribeDataSource.cpp +++ b/mozilla/mailnews/base/src/nsSubscribeDataSource.cpp @@ -95,7 +95,7 @@ nsSubscribeDataSource::Init() NS_IMETHODIMP nsSubscribeDataSource::GetURI(char * *aURI) { - if ((*aURI = nsXPIDLCString::Copy("rdf:subscribe")) == nsnull) + if ((*aURI = nsCRT::strdup("rdf:subscribe")) == nsnull) return NS_ERROR_OUT_OF_MEMORY; else return NS_OK; diff --git a/mozilla/mailnews/base/util/nsMsgMailNewsUrl.cpp b/mozilla/mailnews/base/util/nsMsgMailNewsUrl.cpp index 9be36c63a75..b8b770b290c 100644 --- a/mozilla/mailnews/base/util/nsMsgMailNewsUrl.cpp +++ b/mozilla/mailnews/base/util/nsMsgMailNewsUrl.cpp @@ -168,7 +168,7 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetServer(nsIMsgIncomingServer ** aIncomingServe if (NS_SUCCEEDED(rv)) { if (nsCRT::strcmp((const char *)scheme, "pop") == 0) - scheme = "pop3"; + scheme.Adopt(nsCRT::strdup("pop3")); NS_WITH_SERVICE(nsIMsgAccountManager, accountManager, NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/mailnews/compose/src/nsMsgCompose.cpp b/mozilla/mailnews/compose/src/nsMsgCompose.cpp index dac7e284256..23efd771ab6 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompose.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompose.cpp @@ -87,6 +87,7 @@ #include "nsMsgUtils.h" #include "nsIMsgImapMailFolder.h" #include "nsImapCore.h" +#include "nsReadableUtils.h" // Defines.... static NS_DEFINE_CID(kHeaderParserCID, NS_MSGHEADERPARSER_CID); @@ -1064,7 +1065,7 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, GetTopmostMsgWindowCharacterSet(mailCharset); if (mailCharset && (* (const PRUnichar *) mailCharset) ) { - charset = PL_strdup(NS_ConvertUCS2toUTF8(mailCharset).get()); + charset.Adopt(ToNewUTF8String(nsDependentString(mailCharset))); charsetOverride = PR_TRUE; } @@ -1117,7 +1118,7 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, GetTopmostMsgWindowCharacterSet(mailCharset); if (mailCharset && (* (const PRUnichar *) mailCharset) ) { - charset = PL_strdup(NS_ConvertUCS2toUTF8(mailCharset).get()); + charset.Adopt(ToNewUTF8String(nsDependentString(mailCharset))); charsetOverride = PR_TRUE; } diff --git a/mozilla/mailnews/compose/src/nsMsgSend.cpp b/mozilla/mailnews/compose/src/nsMsgSend.cpp index e84e676cb12..f03155c5b01 100644 --- a/mozilla/mailnews/compose/src/nsMsgSend.cpp +++ b/mozilla/mailnews/compose/src/nsMsgSend.cpp @@ -1133,7 +1133,7 @@ nsMsgComposeAndSend::PreProcessPart(nsMsgAttachmentHandler *ma, nsXPIDLCString turl; if (!ma->mURL) - *((char **)getter_Copies(turl)) = nsXPIDLCString::Copy(ma->m_uri); + turl.Adopt(nsCRT::strdup(ma->m_uri)); else ma->mURL->GetSpec(getter_Copies(turl)); hdrs = mime_generate_attachment_headers (ma->m_type, ma->m_encoding, diff --git a/mozilla/mailnews/compose/src/nsSmtpDelegateFactory.cpp b/mozilla/mailnews/compose/src/nsSmtpDelegateFactory.cpp index e1c3bc8a1ef..c1b22d026b5 100644 --- a/mozilla/mailnews/compose/src/nsSmtpDelegateFactory.cpp +++ b/mozilla/mailnews/compose/src/nsSmtpDelegateFactory.cpp @@ -56,8 +56,8 @@ nsSmtpDelegateFactory::CreateDelegate(nsIRDFResource *aOuter, { nsresult rv; - nsXPIDLCString uri; - aOuter->GetValueConst(getter_Shares(uri)); + const char* uri; + aOuter->GetValueConst(&uri); nsCOMPtr url; rv = nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, diff --git a/mozilla/mailnews/compose/src/nsURLFetcher.cpp b/mozilla/mailnews/compose/src/nsURLFetcher.cpp index f9642414cb1..2973950c056 100644 --- a/mozilla/mailnews/compose/src/nsURLFetcher.cpp +++ b/mozilla/mailnews/compose/src/nsURLFetcher.cpp @@ -159,7 +159,7 @@ nsURLFetcher::DoContent(const char * aContentType, { rv = InsertConverter(aContentType); if (NS_SUCCEEDED(rv)) - mConverterContentType = aContentType; + mConverterContentType.Adopt(nsCRT::strdup(aContentType)); } return rv; @@ -501,7 +501,10 @@ NS_IMETHODIMP nsURLFetcherStreamConsumer::OnStopRequest(nsIRequest *aRequest, ns if (NS_SUCCEEDED(aChannel->GetContentType(&contentType)) && contentType) if (PL_strcasecmp(contentType, UNKNOWN_CONTENT_TYPE) != 0) - mURLFetcher->mContentType = contentType; + { + mURLFetcher->mContentType.Adopt(contentType); + contentType = 0; + } if (contentType) nsCRT::free(contentType); @@ -509,7 +512,10 @@ NS_IMETHODIMP nsURLFetcherStreamConsumer::OnStopRequest(nsIRequest *aRequest, ns nsCOMPtr httpChannel = do_QueryInterface(aChannel); if (httpChannel) if (NS_SUCCEEDED(httpChannel->GetCharset(&charset)) && charset) - mURLFetcher->mCharset = charset; + { + mURLFetcher->mCharset.Adopt(charset); + charset = 0; + } if (charset) nsCRT::free(charset); diff --git a/mozilla/mailnews/db/msgdb/src/nsMsgOfflineImapOperation.cpp b/mozilla/mailnews/db/msgdb/src/nsMsgOfflineImapOperation.cpp index 16ffea52832..1eaa1a0ca62 100644 --- a/mozilla/mailnews/db/msgdb/src/nsMsgOfflineImapOperation.cpp +++ b/mozilla/mailnews/db/msgdb/src/nsMsgOfflineImapOperation.cpp @@ -84,7 +84,7 @@ NS_IMETHODIMP nsMsgOfflineImapOperation::ClearOperation(nsOfflineImapOperationTy case kMsgMoved: case kAppendTemplate: case kAppendDraft: - m_moveDestination = ""; + m_moveDestination.Adopt(nsCRT::strdup("")); break; case kMsgCopy: m_copyDestinations.RemoveCStringAt(0); @@ -152,7 +152,7 @@ NS_IMETHODIMP nsMsgOfflineImapOperation::GetDestinationFolderURI(char * *aDestin NS_IMETHODIMP nsMsgOfflineImapOperation::SetDestinationFolderURI(const char * aDestinationFolderURI) { - m_moveDestination = aDestinationFolderURI; + m_moveDestination.Adopt(nsCRT::strdup(aDestinationFolderURI)); return m_mdb->SetProperty(m_mdbRow, PROP_MOVE_DEST_FOLDER_URI, aDestinationFolderURI); } @@ -167,7 +167,7 @@ NS_IMETHODIMP nsMsgOfflineImapOperation::GetSourceFolderURI(char * *aSourceFolde NS_IMETHODIMP nsMsgOfflineImapOperation::SetSourceFolderURI(const char * aSourceFolderURI) { - m_sourceFolder = aSourceFolderURI; + m_sourceFolder.Adopt(nsCRT::strdup(aSourceFolderURI)); SetOperation(kMoveResult); return m_mdb->SetProperty(m_mdbRow, PROP_SRC_FOLDER_URI, aSourceFolderURI); diff --git a/mozilla/mailnews/imap/src/nsImapIncomingServer.cpp b/mozilla/mailnews/imap/src/nsImapIncomingServer.cpp index 88f4de56e06..410d6b50d07 100644 --- a/mozilla/mailnews/imap/src/nsImapIncomingServer.cpp +++ b/mozilla/mailnews/imap/src/nsImapIncomingServer.cpp @@ -153,7 +153,7 @@ NS_IMETHODIMP nsImapIncomingServer::SetKey(const char * aKey) // override nsMsg if (NS_FAILED(rv)) return rv; if (!personalNamespace && !publicNamespace && !otherUsersNamespace) - personalNamespace = "\"\""; + personalNamespace.Adopt(nsCRT::strdup("\"\"")); hostSession->SetNamespaceFromPrefForHost(aKey, personalNamespace, kPersonalNamespace); diff --git a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp index 72381cc21b0..bcfa5159b40 100644 --- a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp @@ -4742,7 +4742,7 @@ nsresult nsImapMailFolder::CopyMessagesOffline(nsIMsgFolder* srcFolder, nsXPIDLCString sourceFolderURI; srcFolder->GetURI(getter_Copies(sourceFolderURI)); nsXPIDLCString originalSrcFolderURI; - originalSrcFolderURI = sourceFolderURI.get(); + originalSrcFolderURI.Adopt(nsCRT::strdup(sourceFolderURI.get())); nsCOMPtr msgSupports; nsCOMPtr message; @@ -4782,7 +4782,7 @@ nsresult nsImapMailFolder::CopyMessagesOffline(nsIMsgFolder* srcFolder, srcFolder->GetURI(getter_Copies(srcFolderURI)); sourceOp->GetSourceFolderURI(getter_Copies(originalString)); sourceOp->GetMessageKey(&originalKey); - originalSrcFolderURI = originalString.get(); + originalSrcFolderURI.Adopt(nsCRT::strdup(originalString.get())); if (isMove) sourceMailDB->RemoveOfflineOp(sourceOp); diff --git a/mozilla/mailnews/imap/src/nsImapService.cpp b/mozilla/mailnews/imap/src/nsImapService.cpp index bd76ba486ec..626745d3d52 100644 --- a/mozilla/mailnews/imap/src/nsImapService.cpp +++ b/mozilla/mailnews/imap/src/nsImapService.cpp @@ -153,10 +153,10 @@ nsImapService::GetFolderName(nsIMsgFolder* aImapFolder, PRBool escapeSlashes = (GetHierarchyDelimiter(aImapFolder) != (PRUnichar) '/'); if (escapeSlashes && (const char *) onlineName) { - nsXPIDLCString escapedOnlineName; - rv = nsImapUrl::EscapeSlashes((const char *) onlineName, getter_Copies(escapedOnlineName)); + char* escapedOnlineName; + rv = nsImapUrl::EscapeSlashes((const char *) onlineName, &escapedOnlineName); if (NS_SUCCEEDED(rv)) - onlineName = (const char *) escapedOnlineName; + onlineName.Adopt(escapedOnlineName); } // need to escape everything else *folderName = nsEscape((const char *) onlineName, url_Path); @@ -1870,7 +1870,7 @@ nsImapService::OnlineMessageCopy(nsIEventQueue* aClientEventQueue, urlSpec.Append(messageIds); urlSpec.Append('>'); urlSpec.AppendWithConversion(hierarchySeparator); - folderName = ""; + folderName.Adopt(nsCRT::strdup("")); GetFolderName(aDstFolder, getter_Copies(folderName)); urlSpec.Append((const char *) folderName); @@ -2016,7 +2016,7 @@ nsImapService::MoveFolder(nsIEventQueue* eventQueue, nsIMsgFolder* srcFolder, urlSpec.Append(hierarchySeparator); urlSpec.Append((const char *) folderName); urlSpec.Append('>'); - folderName = ""; + folderName.Adopt(nsCRT::strdup("")); GetFolderName(dstFolder, getter_Copies(folderName)); if ( folderName && folderName[0]) { diff --git a/mozilla/mailnews/local/src/nsMailboxUrl.cpp b/mozilla/mailnews/local/src/nsMailboxUrl.cpp index ace638ad26f..3e6b68cf726 100644 --- a/mozilla/mailnews/local/src/nsMailboxUrl.cpp +++ b/mozilla/mailnews/local/src/nsMailboxUrl.cpp @@ -304,7 +304,7 @@ nsMailboxUrl::GetOriginalSpec(char **aSpec) NS_IMETHODIMP nsMailboxUrl::SetOriginalSpec(const char *aSpec) { - m_originalSpec = aSpec; + m_originalSpec.Adopt(nsCRT::strdup(aSpec)); return NS_OK; } diff --git a/mozilla/mailnews/local/src/nsPop3Sink.cpp b/mozilla/mailnews/local/src/nsPop3Sink.cpp index 99570df1a94..c66c7b6a961 100644 --- a/mozilla/mailnews/local/src/nsPop3Sink.cpp +++ b/mozilla/mailnews/local/src/nsPop3Sink.cpp @@ -548,6 +548,6 @@ nsPop3Sink::SetBaseMessageUri(const char *baseMessageUri) { if (!baseMessageUri) return NS_ERROR_NULL_POINTER; - m_baseMessageUri = baseMessageUri; + m_baseMessageUri.Adopt(nsCRT::strdup(baseMessageUri)); return NS_OK; } diff --git a/mozilla/mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp b/mozilla/mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp index 20a75abe30e..548d8950b87 100644 --- a/mozilla/mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp +++ b/mozilla/mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp @@ -35,6 +35,7 @@ #include "nsXPIDLString.h" #include "nsMimeTypes.h" #include "prtime.h" +#include "nsReadableUtils.h" // hack: include this to fix opening news attachments. #include "nsINntpUrl.h" @@ -219,7 +220,7 @@ nsresult nsMimeHtmlDisplayEmitter::WriteHTMLHeaders() else { // Convert UTF-8 to UCS2 - *((PRUnichar **)getter_Copies(unicodeHeaderValue)) = nsXPIDLString::Copy(NS_ConvertUTF8toUCS2(headerValue).GetUnicode()); + unicodeHeaderValue.Adopt(ToNewUnicode(nsDependentCString(headerValue))); if (NS_SUCCEEDED(rv)) headerSink->HandleHeader(headerInfo->name, unicodeHeaderValue, bFromNewsgroups); @@ -328,21 +329,14 @@ nsMimeHtmlDisplayEmitter::StartAttachment(const char *name, const char *contentT // we emit it... nsXPIDLString unicodeHeaderValue; - rv = NS_OK; + rv = NS_ERROR_FAILURE; if (mUnicodeConverter) rv = mUnicodeConverter->DecodeMimeHeader(name, getter_Copies(unicodeHeaderValue)); - else { - nsAutoString attachmentName; attachmentName.AssignWithConversion(name); - *((PRUnichar **)getter_Copies(unicodeHeaderValue)) = - nsXPIDLString::Copy(attachmentName.GetUnicode()); - } if (NS_FAILED(rv)) { - nsAutoString attachmentName; attachmentName.AssignWithConversion(name); - *((PRUnichar **)getter_Copies(unicodeHeaderValue)) = - nsXPIDLString::Copy(attachmentName.GetUnicode()); + unicodeHeaderValue.Adopt(ToNewUnicode(nsDependentCString(name))); } headerSink->HandleAttachment(contentType, url /* was escapedUrl */, unicodeHeaderValue, uriString, aNotDownloaded); diff --git a/mozilla/netwerk/base/src/nsProtocolProxyService.cpp b/mozilla/netwerk/base/src/nsProtocolProxyService.cpp index c21161997db..cb7d5938f2e 100644 --- a/mozilla/netwerk/base/src/nsProtocolProxyService.cpp +++ b/mozilla/netwerk/base/src/nsProtocolProxyService.cpp @@ -121,11 +121,10 @@ nsProtocolProxyService::PrefsChanged(const char* pref) { if (!pref || !PL_strcmp(pref, "network.proxy.http")) { - mHTTPProxyHost = ""; rv = mPrefs->CopyCharPref("network.proxy.http", - getter_Copies(tempString)); - if (NS_SUCCEEDED(rv)) - mHTTPProxyHost = nsCRT::strdup(tempString); + getter_Copies(mHTTPProxyHost)); + if (!NS_SUCCEEDED(rv)) + mHTTPProxyHost.Adopt(nsCRT::strdup("")); } if (!pref || !PL_strcmp(pref, "network.proxy.http_port")) @@ -139,11 +138,10 @@ nsProtocolProxyService::PrefsChanged(const char* pref) { if (!pref || !PL_strcmp(pref, "network.proxy.ssl")) { - mHTTPSProxyHost = ""; rv = mPrefs->CopyCharPref("network.proxy.ssl", - getter_Copies(tempString)); - if (NS_SUCCEEDED(rv)) - mHTTPSProxyHost = nsCRT::strdup(tempString); + getter_Copies(mHTTPSProxyHost)); + if (!NS_SUCCEEDED(rv)) + mHTTPSProxyHost.Adopt(nsCRT::strdup("")); } if (!pref || !PL_strcmp(pref, "network.proxy.ssl_port")) @@ -157,11 +155,10 @@ nsProtocolProxyService::PrefsChanged(const char* pref) { if (!pref || !PL_strcmp(pref, "network.proxy.ftp")) { - mFTPProxyHost = ""; rv = mPrefs->CopyCharPref("network.proxy.ftp", - getter_Copies(tempString)); - if (NS_SUCCEEDED(rv)) - mFTPProxyHost = nsCRT::strdup(tempString); + getter_Copies(mFTPProxyHost)); + if (!NS_SUCCEEDED(rv)) + mFTPProxyHost.Adopt(nsCRT::strdup("")); } if (!pref || !PL_strcmp(pref, "network.proxy.ftp_port")) @@ -175,11 +172,10 @@ nsProtocolProxyService::PrefsChanged(const char* pref) { if (!pref || !PL_strcmp(pref, "network.proxy.gopher")) { - mGopherProxyHost = ""; rv = mPrefs->CopyCharPref("network.proxy.gopher", - getter_Copies(tempString)); - if (NS_SUCCEEDED(rv) && tempString && *tempString) - mGopherProxyHost = nsCRT::strdup(tempString); + getter_Copies(mGopherProxyHost)); + if (!NS_SUCCEEDED(rv) || !mGopherProxyHost) + mGopherProxyHost.Adopt(nsCRT::strdup("")); } if (!pref || !PL_strcmp(pref, "network.proxy.gopher_port")) @@ -193,11 +189,10 @@ nsProtocolProxyService::PrefsChanged(const char* pref) { if (!pref || !PL_strcmp(pref, "network.proxy.socks")) { - mSOCKSProxyHost = ""; rv = mPrefs->CopyCharPref("network.proxy.socks", - getter_Copies(tempString)); - if (NS_SUCCEEDED(rv)) - mSOCKSProxyHost = nsCRT::strdup(tempString); + getter_Copies(mSOCKSProxyHost)); + if (!NS_SUCCEEDED(rv)) + mSOCKSProxyHost.Adopt(nsCRT::strdup("")); } if (!pref || !PL_strcmp(pref, "network.proxy.socks_port")) @@ -223,7 +218,7 @@ nsProtocolProxyService::PrefsChanged(const char* pref) { rv = mPrefs->CopyCharPref("network.proxy.autoconfig_url", getter_Copies(tempString)); if (NS_SUCCEEDED(rv) && (!reloadPAC || PL_strcmp(tempString, mPACURL))) { - mPACURL = nsCRT::strdup(tempString); + mPACURL.Adopt(nsCRT::strdup(tempString)); // create pac js component mPAC = do_CreateInstance(NS_PROXY_AUTO_CONFIG_CONTRACTID, &rv); diff --git a/mozilla/netwerk/base/src/nsStdURL.cpp b/mozilla/netwerk/base/src/nsStdURL.cpp index c35edba69b6..b374e8bccda 100644 --- a/mozilla/netwerk/base/src/nsStdURL.cpp +++ b/mozilla/netwerk/base/src/nsStdURL.cpp @@ -152,10 +152,12 @@ nsStdURL::Init(PRUint32 urlType, PRInt32 defaultPort, if (initialSpec == nsnull) return NS_OK; - nsXPIDLCString resolvedURI; + nsXPIDLCString resolvedURIStr; + const char* resolvedURI; if (baseURI) { - rv = baseURI->Resolve(initialSpec, getter_Copies(resolvedURI)); + rv = baseURI->Resolve(initialSpec, getter_Copies(resolvedURIStr)); if (NS_FAILED(rv)) return rv; + resolvedURI = resolvedURIStr.get(); } else { resolvedURI = initialSpec; diff --git a/mozilla/netwerk/protocol/about/src/nsAboutCacheEntry.cpp b/mozilla/netwerk/protocol/about/src/nsAboutCacheEntry.cpp index 3355d482df0..e835ed6ff5f 100644 --- a/mozilla/netwerk/protocol/about/src/nsAboutCacheEntry.cpp +++ b/mozilla/netwerk/protocol/about/src/nsAboutCacheEntry.cpp @@ -436,7 +436,7 @@ nsAboutCacheEntry::WriteCacheEntryDescription(nsIOutputStream *outputStream, // File on disk // Security Info - str = 0; + str.Adopt(0); nsCOMPtr securityInfo; descriptor->GetSecurityInfo(getter_AddRefs(securityInfo)); if (securityInfo) { @@ -452,7 +452,7 @@ nsAboutCacheEntry::WriteCacheEntryDescription(nsIOutputStream *outputStream, buffer.Append("
"); // Client ID - str = 0; + str.Adopt(0); descriptor->GetClientID(getter_Copies(str)); if (str) APPEND_ROW("Client", str); diff --git a/mozilla/netwerk/protocol/finger/src/nsFingerChannel.cpp b/mozilla/netwerk/protocol/finger/src/nsFingerChannel.cpp index 470a0d424f9..bc54b187ff8 100644 --- a/mozilla/netwerk/protocol/finger/src/nsFingerChannel.cpp +++ b/mozilla/netwerk/protocol/finger/src/nsFingerChannel.cpp @@ -417,7 +417,7 @@ nsFingerChannel::SendRequest(nsITransport* aTransport) { requestBuffer.Append(CRLF); - mRequest = requestBuffer.ToNewCString(); + mRequest.Adopt(ToNewCString(requestBuffer)); rv = NS_NewCharInputStream(getter_AddRefs(result), mRequest); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp index b0f0ae26adc..08f07fdc013 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp +++ b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp @@ -1608,8 +1608,7 @@ nsFtpState::Init(nsIFTPChannel* aChannel, rv = mURL->GetPath(&path); if (NS_FAILED(rv)) return rv; - mPath = nsUnescape(path); - nsMemory::Free(path); + mPath.Adopt(nsUnescape(path)); // pull any username and/or password out of the uri nsXPIDLCString uname; diff --git a/mozilla/netwerk/protocol/gopher/src/nsGopherChannel.cpp b/mozilla/netwerk/protocol/gopher/src/nsGopherChannel.cpp index b53d2fbc787..02fdb066665 100644 --- a/mozilla/netwerk/protocol/gopher/src/nsGopherChannel.cpp +++ b/mozilla/netwerk/protocol/gopher/src/nsGopherChannel.cpp @@ -108,10 +108,10 @@ nsGopherChannel::Init(nsIURI* uri) // No path given if (buffer[0]=='\0' || (buffer[0]=='/' && buffer[1]=='\0')) { mType = '1'; - mSelector = ""; + mSelector.Adopt(nsCRT::strdup("")); } else { mType = buffer[1]; // Ignore leading '/' - mSelector = nsUnescape(NS_CONST_CAST(char*,&buffer[2])); + mSelector.Adopt(nsCRT::strdup(nsUnescape(NS_CONST_CAST(char*,&buffer[2])))); } PR_LOG(gGopherLog, diff --git a/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp b/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp index 9d8e7020ee2..5c5b1ca7fc6 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp @@ -294,16 +294,18 @@ nsHttpChannel::SetupTransaction() // use the URI path if not proxying (transparent proxying such as SSL proxy // does not count here). - nsXPIDLCString requestURI; + nsXPIDLCString requestURIStr; + const char* requestURI; if ((mConnectionInfo->ProxyHost() == nsnull) || mConnectionInfo->UsingSSL()) { - rv = mURI->GetPath(getter_Copies(requestURI)); + rv = mURI->GetPath(getter_Copies(requestURIStr)); if (NS_FAILED(rv)) return rv; + requestURI = requestURIStr.get(); } else requestURI = mSpec.get(); // trim off the #ref portion if any... - char *p = PL_strrchr(requestURI.get(), '#'); + char *p = PL_strrchr(requestURI, '#'); if (p) *p = 0; mRequestHead.SetVersion(nsHttpHandler::get()->DefaultVersion()); @@ -672,7 +674,7 @@ nsHttpChannel::CheckCache() if (mRequestHead.Method() != nsHttp::Head) return NS_OK; } - buf = 0; + buf.Adopt(0); // Get the cached HTTP response headers rv = mCacheEntry->GetMetaDataElement("response-head", getter_Copies(buf)); @@ -685,7 +687,7 @@ nsHttpChannel::CheckCache() return NS_ERROR_OUT_OF_MEMORY; rv = mCachedResponseHead->Parse((char *) buf.get()); if (NS_FAILED(rv)) return rv; - buf = 0; + buf.Adopt(0); // If we were only granted read access, then assume the entry is valid. if (mCacheAccess == nsICache::ACCESS_READ) { diff --git a/mozilla/netwerk/protocol/http/src/nsHttpConnection.h b/mozilla/netwerk/protocol/http/src/nsHttpConnection.h index 08145a56c70..b884eb2fbed 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpConnection.h +++ b/mozilla/netwerk/protocol/http/src/nsHttpConnection.h @@ -36,6 +36,7 @@ #include "nsXPIDLString.h" #include "plstr.h" #include "prclist.h" +#include "nsCRT.h" class nsHttpHandler; class nsHttpConnectionInfo; @@ -151,10 +152,11 @@ public: NS_INIT_ISUPPORTS(); - mHost = host; + mHost.Adopt(nsCRT::strdup(host)); + mProxyHost.Adopt(nsCRT::strdup(proxyHost)); + mProxyType.Adopt(nsCRT::strdup(proxyType)); + mPort = port == -1 ? DefaultPort() : port; - mProxyHost = proxyHost; - mProxyType = proxyType; } virtual ~nsHttpConnectionInfo() diff --git a/mozilla/netwerk/protocol/http/src/nsHttpHandler.cpp b/mozilla/netwerk/protocol/http/src/nsHttpHandler.cpp index bfb2835819d..ad0e84f6166 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpHandler.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpHandler.cpp @@ -47,6 +47,7 @@ #include "nsNetCID.h" #include "nsAutoLock.h" #include "prprf.h" +#include "nsReadableUtils.h" #if defined(XP_UNIX) || defined(XP_BEOS) #include @@ -882,36 +883,38 @@ nsHttpHandler::InitUserAgentComponents() getter_Copies(mMisc)); // Gather Application name and Version. - mAppName = UA_APPNAME; - mAppVersion = UA_APPVERSION; + mAppName.Adopt(nsCRT::strdup(UA_APPNAME)); + mAppVersion.Adopt(nsCRT::strdup(UA_APPVERSION)); // Get Security level supported mPrefs->CopyCharPref(UA_PREF_PREFIX "security", getter_Copies(mSecurity)); if (!mSecurity) - mSecurity = UA_APPSECURITY_FALLBACK; + mSecurity.Adopt(nsCRT::strdup(UA_APPSECURITY_FALLBACK)); // Gather locale. nsXPIDLString uval; mPrefs->GetLocalizedUnicharPref(UA_PREF_PREFIX "locale", getter_Copies(uval)); if (uval) - mLanguage = NS_ConvertUCS2toUTF8(uval).get(); + mLanguage.Adopt(ToNewUTF8String(nsDependentString(uval))); - // Gather platform. + // Gather platform. + mPlatform.Adopt(nsCRT::strdup( #if defined(XP_OS2) - mPlatform = "OS/2"; + "OS/2" #elif defined(XP_PC) - mPlatform = "Windows"; + "Windows" #elif defined(RHAPSODY) - mPlatform = "Macintosh"; + "Macintosh" #elif defined (XP_UNIX) - mPlatform = "X11"; + "X11" #elif defined(XP_BEOS) - mPlatform = "BeOS"; + "BeOS" #elif defined(XP_MAC) - mPlatform = "Macintosh"; + "Macintosh" #endif + )); // Gather OS/CPU. #if defined(XP_OS2) @@ -919,40 +922,40 @@ nsHttpHandler::InitUserAgentComponents() DosQuerySysInfo(QSV_VERSION_MINOR, QSV_VERSION_MINOR, &os2ver, sizeof(os2ver)); if (os2ver == 11) - mOscpu = "2.11"; + mOscpu.Adopt(nsCRT::strdup("2.11")); else if (os2ver == 30) - mOscpu = "Warp 3"; + mOscpu.Adopt(nsCRT::strdup("Warp 3")); else if (os2ver == 40) - mOscpu = "Warp 4"; + mOscpu.Adopt(nsCRT::strdup("Warp 4")); else if (os2ver == 45) - mOscpu = "Warp 4.5"; + mOscpu.Adopt(nsCRT::strdup("Warp 4.5")); #elif defined(XP_PC) OSVERSIONINFO info = { sizeof OSVERSIONINFO }; if (GetVersionEx(&info)) { if (info.dwPlatformId == VER_PLATFORM_WIN32_NT) { if (info.dwMajorVersion == 3) - mOscpu = "WinNT3.51"; + mOscpu.Adopt(nsCRT::strdup("WinNT3.51")); else if (info.dwMajorVersion == 4) - mOscpu = "WinNT4.0"; + mOscpu.Adopt(nsCRT::strdup("WinNT4.0")); else if (info.dwMajorVersion >= 5) { char *buf = PR_smprintf("Windows NT %ld.%ld", info.dwMajorVersion, info.dwMinorVersion); if (buf) { - mOscpu = buf; + mOscpu.Adopt(nsCRT::strdup(buf)); PR_smprintf_free(buf); } } else - mOscpu = "WinNT"; + mOscpu.Adopt(nsCRT::strdup("WinNT")); } else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { if (info.dwMinorVersion == 90) - mOscpu = "Win 9x 4.90"; + mOscpu.Adopt(nsCRT::strdup("Win 9x 4.90")); else if (info.dwMinorVersion > 0) - mOscpu = "Win98"; + mOscpu.Adopt(nsCRT::strdup("Win98")); else - mOscpu = "Win95"; + mOscpu.Adopt(nsCRT::strdup("Win95")); } } #elif defined (XP_UNIX) || defined (XP_BEOS) @@ -964,10 +967,10 @@ nsHttpHandler::InitUserAgentComponents() buf = (char*)name.sysname; buf += ' '; buf += (char*)name.machine; - mOscpu = buf; + mOscpu.Adopt(ToNewCString(buf)); } #elif defined (XP_MAC) - mOscpu = "PPC"; + mOscpu.Adopt(nsCRT::strdup("PPC")); #endif mUserAgentIsDirty = PR_TRUE; @@ -1103,13 +1106,15 @@ nsHttpHandler::PrefsChanged(const char *pref) // general.useragent.override if (bChangedAll || PL_strcmp(pref, UA_PREF_PREFIX "override") == 0) { - nsXPIDLCString uval; + char* temp = 0; rv = mPrefs->CopyCharPref(UA_PREF_PREFIX "override", - getter_Copies(uval)); + &temp); if (NS_SUCCEEDED(rv)) { - mUserAgentOverride = uval.get(); + mUserAgentOverride.Adopt(temp); + temp = 0; mUserAgentIsDirty = PR_TRUE; } + NS_ASSERTION(!temp, "trouble: |CopyCharPref| failed, but returned a string anyway!"); } if (bChangedAll || PL_strcmp(pref, UA_PREF_PREFIX "locale") == 0) { @@ -1118,20 +1123,22 @@ nsHttpHandler::PrefsChanged(const char *pref) rv = mPrefs->GetLocalizedUnicharPref(UA_PREF_PREFIX "locale", getter_Copies(uval)); if (NS_SUCCEEDED(rv)) { - mLanguage = NS_ConvertUCS2toUTF8(uval).get(); + mLanguage.Adopt(ToNewUTF8String(nsDependentString(uval))); mUserAgentIsDirty = PR_TRUE; } } // general.useragent.misc if (bChangedAll || PL_strcmp(pref, UA_PREF_PREFIX "misc") == 0) { - nsXPIDLCString uval; + char* temp; rv = mPrefs->CopyCharPref(UA_PREF_PREFIX "misc", - getter_Copies(uval)); + &temp); if (NS_SUCCEEDED(rv)) { - mMisc = uval.get(); + mMisc.Adopt(temp); + temp = 0; mUserAgentIsDirty = PR_TRUE; } + NS_ASSERTION(!temp, "trouble: |CopyCharPref| failed, but returned a string anyway!"); } if (bChangedAll || PL_strcmp(pref, "network.http.accept.default") == 0) { @@ -1590,7 +1597,7 @@ nsHttpHandler::GetVendor(char **aVendor) NS_IMETHODIMP nsHttpHandler::SetVendor(const char *aVendor) { - mVendor = aVendor; + mVendor.Adopt(nsCRT::strdup(aVendor)); mUserAgentIsDirty = PR_TRUE; return NS_OK; } @@ -1603,7 +1610,7 @@ nsHttpHandler::GetVendorSub(char **aVendorSub) NS_IMETHODIMP nsHttpHandler::SetVendorSub(const char *aVendorSub) { - mVendorSub = aVendorSub; + mVendorSub.Adopt(nsCRT::strdup(aVendorSub)); mUserAgentIsDirty = PR_TRUE; return NS_OK; } @@ -1616,7 +1623,7 @@ nsHttpHandler::GetVendorComment(char **aVendorComment) NS_IMETHODIMP nsHttpHandler::SetVendorComment(const char *aVendorComment) { - mVendorComment = aVendorComment; + mVendorComment.Adopt(nsCRT::strdup(aVendorComment)); mUserAgentIsDirty = PR_TRUE; return NS_OK; } @@ -1629,7 +1636,7 @@ nsHttpHandler::GetProduct(char **aProduct) NS_IMETHODIMP nsHttpHandler::SetProduct(const char *aProduct) { - mProduct = aProduct; + mProduct.Adopt(nsCRT::strdup(aProduct)); mUserAgentIsDirty = PR_TRUE; return NS_OK; } @@ -1642,7 +1649,7 @@ nsHttpHandler::GetProductSub(char **aProductSub) NS_IMETHODIMP nsHttpHandler::SetProductSub(const char *aProductSub) { - mProductSub = aProductSub; + mProductSub.Adopt(nsCRT::strdup(aProductSub)); mUserAgentIsDirty = PR_TRUE; return NS_OK; } @@ -1655,7 +1662,7 @@ nsHttpHandler::GetProductComment(char **aProductComment) NS_IMETHODIMP nsHttpHandler::SetProductComment(const char *aProductComment) { - mProductComment = aProductComment; + mProductComment.Adopt(nsCRT::strdup(aProductComment)); mUserAgentIsDirty = PR_TRUE; return NS_OK; } @@ -1680,7 +1687,7 @@ nsHttpHandler::GetLanguage(char **aLanguage) NS_IMETHODIMP nsHttpHandler::SetLanguage(const char *aLanguage) { - mLanguage = aLanguage; + mLanguage.Adopt(nsCRT::strdup(aLanguage)); mUserAgentIsDirty = PR_TRUE; return NS_OK; } @@ -1693,7 +1700,7 @@ nsHttpHandler::GetMisc(char **aMisc) NS_IMETHODIMP nsHttpHandler::SetMisc(const char *aMisc) { - mMisc = aMisc; + mMisc.Adopt(nsCRT::strdup(aMisc)); mUserAgentIsDirty = PR_TRUE; return NS_OK; } diff --git a/mozilla/netwerk/protocol/http/src/nsHttpRequestHead.h b/mozilla/netwerk/protocol/http/src/nsHttpRequestHead.h index dc7479d8c16..81f7d3cceaa 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpRequestHead.h +++ b/mozilla/netwerk/protocol/http/src/nsHttpRequestHead.h @@ -41,7 +41,7 @@ public: void SetMethod(nsHttpAtom method) { mMethod = method; } void SetVersion(nsHttpVersion version) { mVersion = version; } - void SetRequestURI(const char *s) { mRequestURI = s; } + void SetRequestURI(const char *s) { mRequestURI.Adopt(nsCRT::strdup(s)); } nsHttpHeaderArray &Headers() { return mHeaders; } nsHttpAtom Method() { return mMethod; } diff --git a/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.cpp b/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.cpp index f596fe64fe1..1956cd8389d 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.cpp @@ -130,7 +130,7 @@ nsHttpResponseHead::ParseStatusLine(char *line) if ((mVersion == NS_HTTP_VERSION_0_9) || !(line = PL_strchr(line, ' '))) { mStatus = 200; - mStatusText = "OK"; + mStatusText.Adopt(nsCRT::strdup("OK")); LOG(("Have status line [version=%d status=%d statusText=%s]\n", mVersion, mStatus, mStatusText.get())); return; @@ -146,10 +146,10 @@ nsHttpResponseHead::ParseStatusLine(char *line) // Reason-Phrase is whatever is remaining of the line if (!(line = PL_strchr(line, ' '))) { LOG(("mal-formed response status line; assuming statusText = 'OK'\n")); - mStatusText = "OK"; + mStatusText.Adopt(nsCRT::strdup("OK")); } else - mStatusText = ++line; + mStatusText.Adopt(nsCRT::strdup(++line)); LOG(("Have status line [version=%d status=%d statusText=%s]\n", mVersion, mStatus, mStatusText.get())); @@ -356,10 +356,10 @@ nsHttpResponseHead::Reset() mVersion = NS_HTTP_VERSION_1_1; mStatus = 200; - mStatusText = 0; + mStatusText.Adopt(0); mContentLength = -1; - mContentType = 0; - mContentCharset = 0; + mContentType.Adopt(0); + mContentCharset.Adopt(0); } //----------------------------------------------------------------------------- @@ -435,7 +435,7 @@ nsHttpResponseHead::ParseContentType(char *type) } while ((*p3 == ' ') || (*p3 == '\t')); *++p3 = 0; // overwrite first char after the charset field - mContentCharset = p2; + mContentCharset.Adopt(nsCRT::strdup(p2)); } } else @@ -450,7 +450,7 @@ nsHttpResponseHead::ParseContentType(char *type) while (--p >= type) *p = nsCRT::ToLower(*p); - mContentType = type; + mContentType.Adopt(nsCRT::strdup(type)); return NS_OK; } diff --git a/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.h b/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.h index 5d08be6dd6f..458efcb9622 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.h +++ b/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.h @@ -54,7 +54,7 @@ public: nsresult GetHeader(nsHttpAtom h, char **v) { return mHeaders.GetHeader(h, v); } void ClearHeaders() { mHeaders.Clear(); } - void SetContentType(const char *s) { mContentType = s; } + void SetContentType(const char *s) { mContentType.Adopt(nsCRT::strdup(s)); } void SetContentLength(PRInt32 len) { mContentLength = len; } // write out the response status line and headers as a single text block, diff --git a/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.cpp b/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.cpp index f82b059ff27..86df6922894 100644 --- a/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.cpp +++ b/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.cpp @@ -586,7 +586,7 @@ nsMultiMixedConv::OnStartRequest(nsIRequest *request, nsISupports *ctxt) { boundaryString.Trim(" \""); - mToken = boundaryString.get(); + mToken.Adopt(nsCRT::strdup(boundaryString.get())); mTokenLen = boundaryString.Length(); return NS_OK; @@ -890,7 +890,7 @@ nsMultiMixedConv::FindToken(char *aCursor, PRUint32 aLen) { // we're playing w/ double dash tokens, adjust. nsCString newToken("--"); newToken.Append(mToken); - mToken = newToken.get(); + mToken.Adopt(nsCRT::strdup(newToken.get())); mTokenLen += 2; } } diff --git a/mozilla/rdf/base/src/nsRDFService.cpp b/mozilla/rdf/base/src/nsRDFService.cpp index 07e83a34a22..99913d6ee11 100644 --- a/mozilla/rdf/base/src/nsRDFService.cpp +++ b/mozilla/rdf/base/src/nsRDFService.cpp @@ -304,7 +304,7 @@ LiteralImpl::GetValue(PRUnichar* *value) if (! value) return NS_ERROR_NULL_POINTER; - *value = nsXPIDLString::Copy(GetValue()); + *value = nsCRT::strdup(GetValue()); return NS_OK; } @@ -1288,7 +1288,7 @@ RDFServiceImpl::RegisterLiteral(nsIRDFLiteral* aLiteral, PRBool aReplace) #ifdef REUSE_LITERAL_VALUE_AS_KEY PL_HashTableAdd(mLiterals, value, aLiteral); #else - const PRUnichar* key = nsXPIDLString::Copy(value); + const PRUnichar* key = nsCRT::strdup(value.get()); if (! key) return NS_ERROR_OUT_OF_MEMORY; diff --git a/mozilla/rdf/base/src/nsRDFXMLDataSource.cpp b/mozilla/rdf/base/src/nsRDFXMLDataSource.cpp index 17bb06e4cda..1ceea2d1153 100644 --- a/mozilla/rdf/base/src/nsRDFXMLDataSource.cpp +++ b/mozilla/rdf/base/src/nsRDFXMLDataSource.cpp @@ -656,7 +656,7 @@ RDFXMLDataSourceImpl::GetURI(char* *aURI) if (mOriginalURLSpec) { // We don't use the mURL, because it might get re-written when // it's actually opened. - *aURI = nsXPIDLCString::Copy(mOriginalURLSpec); + *aURI = nsCRT::strdup(mOriginalURLSpec); if (! *aURI) return NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp b/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp index 09641510ca4..e5204b7e10e 100644 --- a/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp +++ b/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp @@ -324,7 +324,7 @@ nsCachedChromeChannel::SetNotificationCallbacks(nsIInterfaceRequestor * aNotific NS_IMETHODIMP nsCachedChromeChannel::GetContentType(char * *aContentType) { - *aContentType = nsXPIDLCString::Copy("mozilla.application/cached-xul"); + *aContentType = nsCRT::strdup("mozilla.application/cached-xul"); return *aContentType ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp index 22360365022..0fb83fb7578 100644 --- a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp @@ -551,9 +551,7 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL, char** aResult) } } - finalURL += remaining; - - *aResult = nsXPIDLCString::Copy(finalURL); + *aResult = ToNewCString(finalURL + remaining); return NS_OK; } @@ -1576,7 +1574,7 @@ NS_IMETHODIMP nsChromeRegistry::GetSelectedLocale(const PRUnichar *aPackageName, if (NS_FAILED(rv)) return rv; // this is not i18n friendly? RDF now use UTF8 internally. - *_retval = nsXPIDLString::Copy(NS_ConvertASCIItoUCS2(lc_name).GetUnicode()); + *_retval = ToNewUnicode(lc_name); return NS_OK; } diff --git a/mozilla/rdf/chrome/src/nsChromeUIDataSource.cpp b/mozilla/rdf/chrome/src/nsChromeUIDataSource.cpp index fba5c701397..2ae9c3c64eb 100644 --- a/mozilla/rdf/chrome/src/nsChromeUIDataSource.cpp +++ b/mozilla/rdf/chrome/src/nsChromeUIDataSource.cpp @@ -106,7 +106,7 @@ nsChromeUIDataSource::Release() NS_IMETHODIMP nsChromeUIDataSource::GetURI(char** aURI) { - *aURI = nsXPIDLCString::Copy("rdf:chrome"); + *aURI = nsCRT::strdup("rdf:chrome"); if (! *aURI) return NS_ERROR_OUT_OF_MEMORY; diff --git a/mozilla/rdf/datasource/src/nsFileSystemDataSource.cpp b/mozilla/rdf/datasource/src/nsFileSystemDataSource.cpp index d051454c5f2..16383d062cb 100644 --- a/mozilla/rdf/datasource/src/nsFileSystemDataSource.cpp +++ b/mozilla/rdf/datasource/src/nsFileSystemDataSource.cpp @@ -383,7 +383,7 @@ FileSystemDataSource::GetURI(char **uri) if (! uri) return NS_ERROR_NULL_POINTER; - if ((*uri = nsXPIDLCString::Copy("rdf:files")) == nsnull) + if ((*uri = nsCRT::strdup("rdf:files")) == nsnull) return NS_ERROR_OUT_OF_MEMORY; return NS_OK; diff --git a/mozilla/rdf/datasource/src/nsLocalStore.cpp b/mozilla/rdf/datasource/src/nsLocalStore.cpp index f661daede18..8cbb45208e6 100644 --- a/mozilla/rdf/datasource/src/nsLocalStore.cpp +++ b/mozilla/rdf/datasource/src/nsLocalStore.cpp @@ -428,7 +428,7 @@ LocalStoreImpl::GetURI(char* *aURI) if (! aURI) return NS_ERROR_NULL_POINTER; - *aURI = nsXPIDLCString::Copy("rdf:localstore"); + *aURI = nsCRT::strdup("rdf:localstore"); if (! *aURI) return NS_ERROR_OUT_OF_MEMORY; diff --git a/mozilla/rdf/util/src/nsRDFResource.cpp b/mozilla/rdf/util/src/nsRDFResource.cpp index a52e8970612..fc103d12d83 100644 --- a/mozilla/rdf/util/src/nsRDFResource.cpp +++ b/mozilla/rdf/util/src/nsRDFResource.cpp @@ -127,7 +127,7 @@ nsRDFResource::GetValue(char* *aURI) if (!aURI) return NS_ERROR_NULL_POINTER; - if ((*aURI = nsXPIDLCString::Copy(mURI)) == nsnull) + if ((*aURI = nsCRT::strdup(mURI)) == nsnull) return NS_ERROR_OUT_OF_MEMORY; else return NS_OK; diff --git a/mozilla/string/obsolete/nsXPIDLString.cpp b/mozilla/string/obsolete/nsXPIDLString.cpp index 0c59e6b581e..7c95c828678 100644 --- a/mozilla/string/obsolete/nsXPIDLString.cpp +++ b/mozilla/string/obsolete/nsXPIDLString.cpp @@ -35,129 +35,38 @@ nsXPIDLString::~nsXPIDLString() { - if (mBufOwner && mBuf) + if (mBuf) XPIDL_FREE(mBuf); } -PRUnichar* -nsXPIDLString::Copy(const PRUnichar* aString) -{ - NS_ASSERTION(aString, "null ptr"); - if (! aString) - return 0; - - PRInt32 len = 0; - - { - const PRUnichar* p = aString; - while (*p++) - len++; - } - - PRUnichar* result = XPIDL_STRING_ALLOC(len + 1); - if (result) { - PRUnichar* q = result; - while (*aString) { - *q = *aString; - q++; - aString++; - } - *q = '\0'; - } - return result; -} - - PRUnichar** nsXPIDLString::StartAssignmentByValue() { - if (mBufOwner && mBuf) + if (mBuf) XPIDL_FREE(mBuf); - mBuf = 0; - mBufOwner = PR_TRUE; return &mBuf; } -const PRUnichar** -nsXPIDLString::StartAssignmentByReference() -{ - if (mBufOwner && mBuf) - XPIDL_FREE(mBuf); - - mBuf = 0; - mBufOwner = PR_FALSE; - return (const PRUnichar**) &mBuf; -} - - //////////////////////////////////////////////////////////////////////// // nsXPIDLCString nsXPIDLCString::~nsXPIDLCString() { - if (mBufOwner && mBuf) + if (mBuf) XPIDL_FREE(mBuf); } -nsXPIDLCString& nsXPIDLCString::operator =(const char* aCString) -{ - if (mBufOwner && mBuf) - XPIDL_FREE(mBuf); - - if (aCString) { - mBuf = Copy(aCString); - mBufOwner = PR_TRUE; - } - else { - mBuf = 0; - mBufOwner = PR_FALSE; - } - - return *this; -} - - -char* -nsXPIDLCString::Copy(const char* aCString) -{ - NS_ASSERTION(aCString, "null ptr"); - if (! aCString) - return 0; - - PRInt32 len = PL_strlen(aCString); - char* result = XPIDL_CSTRING_ALLOC(len + 1); - if (result) - PL_strcpy(result, aCString); - - return result; -} - - char** nsXPIDLCString::StartAssignmentByValue() { - if (mBufOwner && mBuf) + if (mBuf) XPIDL_FREE(mBuf); - mBuf = 0; - mBufOwner = PR_TRUE; return &mBuf; } -const char** -nsXPIDLCString::StartAssignmentByReference() -{ - if (mBufOwner && mBuf) - XPIDL_FREE(mBuf); - - mBuf = 0; - mBufOwner = PR_FALSE; - return (const char**) &mBuf; -} - - diff --git a/mozilla/string/obsolete/nsXPIDLString.h b/mozilla/string/obsolete/nsXPIDLString.h index 6c92f49a8ee..294c1025b38 100644 --- a/mozilla/string/obsolete/nsXPIDLString.h +++ b/mozilla/string/obsolete/nsXPIDLString.h @@ -76,14 +76,15 @@ Like nsCOMPtr, nsXPIDLString uses some syntactic sugar to make it painfully clear exactly what the code expects. You need to wrap an - nsXPIDLString object with either `getter_Copies()' or - `getter_Shares()' before passing it to a getter: these tell the + nsXPIDLString object with `getter_Copies()' + before passing it to a getter: these tell the nsXPIDLString how ownership is being handled. In the case of `getter_Copies()', the callee is allocating a copy - (which is usually the case). In the case of `getter_Shares()', the + (which is usually the case). In the case where the callee is returning a const reference to `the real deal' (this can - be done using the [shared] attribute in XPIDL). + be done using the [shared] attribute in XPIDL) you can just use + a |const char*|. */ @@ -99,8 +100,8 @@ typedef PRUint16 PRUnichar; //////////////////////////////////////////////////////////////////////// // nsXPIDLString // -// A wrapper for Unicode strings. With the |getter_Copies()| and -// |getter_Shares()| helper functions, this can be used instead of +// A wrapper for Unicode strings. With the |getter_Copies()| +// helper function, this can be used instead of // the "naked" |PRUnichar*| interface for |wstring| parameters in // XPIDL interfaces. // @@ -108,16 +109,14 @@ typedef PRUint16 PRUnichar; class NS_COM nsXPIDLString { private: PRUnichar* mBuf; - PRBool mBufOwner; PRUnichar** StartAssignmentByValue(); - const PRUnichar** StartAssignmentByReference(); public: /** * Construct a new, uninitialized wrapper for a Unicode string. */ - nsXPIDLString() : mBuf(0), mBufOwner(PR_FALSE) {} + nsXPIDLString() : mBuf(0) {} ~nsXPIDLString(); @@ -131,12 +130,6 @@ public: */ const PRUnichar* get() const { return mBuf; } - /** - * Make a copy of the Unicode string. Use this function in the - * callee to ensure that the correct memory allocator is used. - */ - static PRUnichar* Copy(const PRUnichar* aString); - // A helper class for assignment-by-value. This class is an // implementation detail and should not be considered part of the // public interface. @@ -157,25 +150,7 @@ public: friend class GetterCopies; - // A helper class for assignment-by-reference. This class is an - // implementation detail and should not be considered part of the - // public interface. - class NS_COM GetterShares { - private: - nsXPIDLString& mXPIDLString; - - public: - GetterShares(nsXPIDLString& aXPIDLString) - : mXPIDLString(aXPIDLString) {} - - operator const PRUnichar**() { - return mXPIDLString.StartAssignmentByReference(); - } - - friend GetterShares getter_Shares(nsXPIDLString& aXPIDLString); - }; - - friend class GetterShares; + inline void Adopt( PRUnichar* ); private: // not to be implemented @@ -183,7 +158,6 @@ private: void operator=(nsXPIDLString& /* aXPIDLString */) {} }; - /** * Use this function to "wrap" the nsXPIDLString object that is to * receive an |out| value. @@ -194,30 +168,26 @@ getter_Copies(nsXPIDLString& aXPIDLString) return nsXPIDLString::GetterCopies(aXPIDLString); } -/** - * Use this function to "wrap" the nsXPIDLString object that is to - * receive a |[shared] out| value. - */ -inline nsXPIDLString::GetterShares -getter_Shares(nsXPIDLString& aXPIDLString) -{ - return nsXPIDLString::GetterShares(aXPIDLString); -} - +inline +void +nsXPIDLString::Adopt( PRUnichar* aNewValue ) + { + *getter_Copies(*this) = aNewValue; + } // XXX THESE ARE NOT strcmp()! DON'T TRY TO USE THEM AS SUCH! inline PRBool operator==(const PRUnichar* lhs, const nsXPIDLString& rhs) { - return lhs == NS_STATIC_CAST(const PRUnichar*, rhs); + return lhs == rhs.get(); } inline PRBool operator==(const nsXPIDLString& lhs, const PRUnichar* rhs) { - return NS_STATIC_CAST(const PRUnichar*, lhs) == rhs; + return lhs.get() == rhs; } @@ -242,8 +212,8 @@ operator==(const nsXPIDLString& lhs, int rhs) //////////////////////////////////////////////////////////////////////// // nsXPIDLCString // -// A wrapper for Unicode strings. With the |getter_Copies()| and -// |getter_Shares()| helper functions, this can be used instead of +// A wrapper for Unicode strings. With the |getter_Copies()| +// helper function, this can be used instead of // the "naked" |char*| interface for |string| parameters in XPIDL // interfaces. // @@ -251,25 +221,17 @@ operator==(const nsXPIDLString& lhs, int rhs) class NS_COM nsXPIDLCString { private: char* mBuf; - PRBool mBufOwner; char** StartAssignmentByValue(); - const char** StartAssignmentByReference(); public: /** * Construct a new, uninitialized wrapper for a single-byte string. */ - nsXPIDLCString() : mBuf(0), mBufOwner(PR_FALSE) {} + nsXPIDLCString() : mBuf(0) {} ~nsXPIDLCString(); - /** - * Assign a single-byte string to this wrapper. Copies - * and owns the result. - */ - nsXPIDLCString& operator=(const char* aString); - /** * Return a reference to the immutable single-byte string. */ @@ -280,12 +242,6 @@ public: */ const char* get() const { return mBuf; } - /** - * Make a copy of the single-byte string. Use this function in the - * callee to ensure that the correct memory allocator is used. - */ - static char* Copy(const char* aString); - // A helper class for assignment-by-value. This class is an // implementation detail and should not be considered part of the // public interface. @@ -306,25 +262,7 @@ public: friend class GetterCopies; - // A helper class for assignment-by-reference. This class is an - // implementation detail and should not be considered part of the - // public interface. - class NS_COM GetterShares { - private: - nsXPIDLCString& mXPIDLString; - - public: - GetterShares(nsXPIDLCString& aXPIDLString) - : mXPIDLString(aXPIDLString) {} - - operator const char**() { - return mXPIDLString.StartAssignmentByReference(); - } - - friend GetterShares getter_Shares(nsXPIDLCString& aXPIDLString); - }; - - friend class GetterShares; + inline void Adopt( char* ); private: // not to be implemented @@ -342,30 +280,26 @@ getter_Copies(nsXPIDLCString& aXPIDLString) return nsXPIDLCString::GetterCopies(aXPIDLString); } - -/** - * Use this function to "wrap" the nsXPIDLCString object that is to - * receive a |[shared] out| value. - */ -inline nsXPIDLCString::GetterShares -getter_Shares(nsXPIDLCString& aXPIDLString) -{ - return nsXPIDLCString::GetterShares(aXPIDLString); -} +inline +void +nsXPIDLCString::Adopt( char* aNewValue ) + { + *getter_Copies(*this) = aNewValue; + } // XXX THESE ARE NOT strcmp()! DON'T TRY TO USE THEM AS SUCH! inline PRBool operator==(const char* lhs, const nsXPIDLCString& rhs) { - return lhs == NS_STATIC_CAST(const char*, rhs); + return lhs == rhs.get(); } inline PRBool operator==(const nsXPIDLCString& lhs, const char* rhs) { - return NS_STATIC_CAST(const char*, lhs) == rhs; + return lhs.get() == rhs; } #ifdef HAVE_CPP_TROUBLE_COMPARING_TO_ZERO diff --git a/mozilla/uriloader/base/nsDocLoader.cpp b/mozilla/uriloader/base/nsDocLoader.cpp index b448c45f7ce..56cc66351e1 100644 --- a/mozilla/uriloader/base/nsDocLoader.cpp +++ b/mozilla/uriloader/base/nsDocLoader.cpp @@ -67,7 +67,7 @@ PRLogModuleInfo* gDocLoaderLog = nsnull; #if defined(DEBUG) void GetURIStringFromRequest(nsIRequest* request, nsXPIDLCString &aStr) { - *getter_Shares(aStr) = "???"; + aStr.Adopt(nsCRT::strdup("???")); if (request) { nsXPIDLString name; diff --git a/mozilla/widget/src/gtk/nsDragService.cpp b/mozilla/widget/src/gtk/nsDragService.cpp index dce70b2052a..51b5b297d97 100644 --- a/mozilla/widget/src/gtk/nsDragService.cpp +++ b/mozilla/widget/src/gtk/nsDragService.cpp @@ -751,8 +751,8 @@ nsDragService::SourceDataGet(GtkWidget *aWidget, } PR_LOG(sDragLm, PR_LOG_DEBUG, ("Type is %s\n", typeName)); - // this makes a copy... - mimeFlavor = typeName; + // make a copy since |nsXPIDLCString| won't use |g_free|... + mimeFlavor.Adopt(nsCRT::strdup(typeName)); g_free(typeName); // check to make sure that we have data items to return. if (!mSourceDataItems) { diff --git a/mozilla/xpcom/build/dlldeps.cpp b/mozilla/xpcom/build/dlldeps.cpp index f1d2be4a142..8f67c4f2238 100644 --- a/mozilla/xpcom/build/dlldeps.cpp +++ b/mozilla/xpcom/build/dlldeps.cpp @@ -66,7 +66,7 @@ #include "nsStaticNameTable.h" #include "nsProcess.h" #include "nsSlidingString.h" -#include "nsIInputStreamTee.h" +#include "nsIInputStreamTee.h" #ifdef DEBUG #include "pure.h" #endif @@ -116,7 +116,6 @@ void XXXNeverCalled() nsDeque(NULL); NS_NewObserver(NULL, NULL); nsTraceRefcnt::DumpStatistics(); - nsXPIDLCString::Copy(NULL); NS_NewEmptyEnumerator(NULL); nsArrayEnumerator(NULL); NS_NewIntersectionEnumerator(NULL, NULL, NULL); @@ -161,7 +160,7 @@ void XXXNeverCalled() ToNewCString(str2); PL_DHashTableFinish(NULL); nsSlidingString sliding(NULL, NULL, NULL); - NS_NewInputStreamTee(NULL, NULL, NULL); + NS_NewInputStreamTee(NULL, NULL, NULL); #ifdef NS_ENABLE_LOGGING nsLog(); #endif diff --git a/mozilla/xpcom/components/nsCategoryManager.cpp b/mozilla/xpcom/components/nsCategoryManager.cpp index 5ab3fec56c5..977fe2f6f20 100644 --- a/mozilla/xpcom/components/nsCategoryManager.cpp +++ b/mozilla/xpcom/components/nsCategoryManager.cpp @@ -295,7 +295,7 @@ nsCategoryManager::GetCategoryEntryRaw( const char *aCategoryName, nsCStringKey entryKey(aEntryName); LeafNode* entry = NS_STATIC_CAST(LeafNode*, category->Get(&entryKey)); if (entry) - status = (*_retval = nsXPIDLCString::Copy(*entry)) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + status = (*_retval = nsCRT::strdup(*entry)) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } return status; @@ -349,7 +349,7 @@ nsCategoryManager::AddCategoryEntry( const char *aCategoryName, { // return the value that we're replacing if ( _retval ) - *_retval = nsXPIDLCString::Copy(*entry); + *_retval = nsCRT::strdup(*entry); } else status = NS_ERROR_INVALID_ARG; // ...stops us from putting the value in diff --git a/mozilla/xpcom/components/nsComponentManager.cpp b/mozilla/xpcom/components/nsComponentManager.cpp index 5161110b638..c94967c68ef 100644 --- a/mozilla/xpcom/components/nsComponentManager.cpp +++ b/mozilla/xpcom/components/nsComponentManager.cpp @@ -215,12 +215,9 @@ nsFactoryEntry::nsFactoryEntry(const nsCID &aClass, const char *aLocation, const char *aType, nsIComponentLoader *aLoader) - : cid(aClass), factory(nsnull), loader(aLoader) + : cid(aClass), location(aLocation), factory(nsnull), type(aType), loader(aLoader) { MOZ_COUNT_CTOR(nsFactoryEntry); - loader = aLoader; - type = aType; - location = aLocation; } nsFactoryEntry::nsFactoryEntry(const nsCID &aClass, nsIFactory *aFactory) @@ -725,9 +722,10 @@ nsComponentManagerImpl::PlatformFind(const nsCID &aCID, nsFactoryEntry* *result) return rv; } - nsXPIDLCString componentType; + nsXPIDLCString componentTypeStr; rv = mRegistry->GetStringUTF8(cidKey, componentTypeValueName, - getter_Copies(componentType)); + getter_Copies(componentTypeStr)); + const char* componentType = componentTypeStr.get(); if (NS_FAILED(rv)) if (rv == NS_ERROR_REG_NOT_FOUND) diff --git a/mozilla/xpcom/components/nsComponentManager.h b/mozilla/xpcom/components/nsComponentManager.h index 337d71ab68e..5fdcd868ee5 100644 --- a/mozilla/xpcom/components/nsComponentManager.h +++ b/mozilla/xpcom/components/nsComponentManager.h @@ -221,9 +221,9 @@ public: } nsCID cid; - nsXPIDLCString location; + nsCString location; nsCOMPtr factory; - nsXPIDLCString type; + nsCString type; nsCOMPtr loader; }; diff --git a/mozilla/xpcom/io/nsFileSpecMac.cpp b/mozilla/xpcom/io/nsFileSpecMac.cpp index b16ef46a4d9..5c0f586915b 100644 --- a/mozilla/xpcom/io/nsFileSpecMac.cpp +++ b/mozilla/xpcom/io/nsFileSpecMac.cpp @@ -1297,8 +1297,7 @@ nsFilePath::nsFilePath(const nsString& inString, PRBool inCreateDirs) void nsFilePath::operator = (const char* inString) //---------------------------------------------------------------------------------------- { - nsXPIDLCString temp; temp = inString; - AssignFromPath(*this, temp, PR_FALSE); + AssignFromPath(*this, inString, PR_FALSE); } //---------------------------------------------------------------------------------------- diff --git a/mozilla/xpcom/io/nsLocalFileUnix.cpp b/mozilla/xpcom/io/nsLocalFileUnix.cpp index 153ef29054e..8a763dcb514 100644 --- a/mozilla/xpcom/io/nsLocalFileUnix.cpp +++ b/mozilla/xpcom/io/nsLocalFileUnix.cpp @@ -261,8 +261,7 @@ nsLocalFile::InitWithPath(const char *filePath) while (name[len-1] == '/' && len > 1) name[--len] = '\0'; - mPath = name; - nsMemory::Free(name); + mPath.Adopt(name); InvalidateCache(); return NS_OK; @@ -454,10 +453,8 @@ nsLocalFile::AppendRelativePath(const char *fragment) while (newPath[len-1] == '/' && len > 1) newPath[--len] = '\0'; - // nsXPIDLCString will copy. - mPath = newPath; + mPath.Adopt(newPath); InvalidateCache(); - nsMemory::Free(newPath); return NS_OK; } @@ -483,8 +480,7 @@ nsLocalFile::Normalize() if (!resolved_path_ptr) return NSRESULT_FOR_ERRNO(); - // nsXPIDLCString will copy. - mPath = resolved_path; + mPath.Adopt(nsCRT::strdup(resolved_path)); return NS_OK; } @@ -535,10 +531,8 @@ nsLocalFile::SetLeafName(const char *aLeafName) strcpy(newPath, mPath); strcat(newPath, aLeafName); - // nsXPIDLCString will copy. - mPath = newPath; + mPath.Adopt(newPath); InvalidateCache(); - nsMemory::Free(newPath); return NS_OK; } diff --git a/mozilla/xpcom/string/obsolete/nsXPIDLString.cpp b/mozilla/xpcom/string/obsolete/nsXPIDLString.cpp index 0c59e6b581e..7c95c828678 100644 --- a/mozilla/xpcom/string/obsolete/nsXPIDLString.cpp +++ b/mozilla/xpcom/string/obsolete/nsXPIDLString.cpp @@ -35,129 +35,38 @@ nsXPIDLString::~nsXPIDLString() { - if (mBufOwner && mBuf) + if (mBuf) XPIDL_FREE(mBuf); } -PRUnichar* -nsXPIDLString::Copy(const PRUnichar* aString) -{ - NS_ASSERTION(aString, "null ptr"); - if (! aString) - return 0; - - PRInt32 len = 0; - - { - const PRUnichar* p = aString; - while (*p++) - len++; - } - - PRUnichar* result = XPIDL_STRING_ALLOC(len + 1); - if (result) { - PRUnichar* q = result; - while (*aString) { - *q = *aString; - q++; - aString++; - } - *q = '\0'; - } - return result; -} - - PRUnichar** nsXPIDLString::StartAssignmentByValue() { - if (mBufOwner && mBuf) + if (mBuf) XPIDL_FREE(mBuf); - mBuf = 0; - mBufOwner = PR_TRUE; return &mBuf; } -const PRUnichar** -nsXPIDLString::StartAssignmentByReference() -{ - if (mBufOwner && mBuf) - XPIDL_FREE(mBuf); - - mBuf = 0; - mBufOwner = PR_FALSE; - return (const PRUnichar**) &mBuf; -} - - //////////////////////////////////////////////////////////////////////// // nsXPIDLCString nsXPIDLCString::~nsXPIDLCString() { - if (mBufOwner && mBuf) + if (mBuf) XPIDL_FREE(mBuf); } -nsXPIDLCString& nsXPIDLCString::operator =(const char* aCString) -{ - if (mBufOwner && mBuf) - XPIDL_FREE(mBuf); - - if (aCString) { - mBuf = Copy(aCString); - mBufOwner = PR_TRUE; - } - else { - mBuf = 0; - mBufOwner = PR_FALSE; - } - - return *this; -} - - -char* -nsXPIDLCString::Copy(const char* aCString) -{ - NS_ASSERTION(aCString, "null ptr"); - if (! aCString) - return 0; - - PRInt32 len = PL_strlen(aCString); - char* result = XPIDL_CSTRING_ALLOC(len + 1); - if (result) - PL_strcpy(result, aCString); - - return result; -} - - char** nsXPIDLCString::StartAssignmentByValue() { - if (mBufOwner && mBuf) + if (mBuf) XPIDL_FREE(mBuf); - mBuf = 0; - mBufOwner = PR_TRUE; return &mBuf; } -const char** -nsXPIDLCString::StartAssignmentByReference() -{ - if (mBufOwner && mBuf) - XPIDL_FREE(mBuf); - - mBuf = 0; - mBufOwner = PR_FALSE; - return (const char**) &mBuf; -} - - diff --git a/mozilla/xpcom/string/obsolete/nsXPIDLString.h b/mozilla/xpcom/string/obsolete/nsXPIDLString.h index 6c92f49a8ee..294c1025b38 100644 --- a/mozilla/xpcom/string/obsolete/nsXPIDLString.h +++ b/mozilla/xpcom/string/obsolete/nsXPIDLString.h @@ -76,14 +76,15 @@ Like nsCOMPtr, nsXPIDLString uses some syntactic sugar to make it painfully clear exactly what the code expects. You need to wrap an - nsXPIDLString object with either `getter_Copies()' or - `getter_Shares()' before passing it to a getter: these tell the + nsXPIDLString object with `getter_Copies()' + before passing it to a getter: these tell the nsXPIDLString how ownership is being handled. In the case of `getter_Copies()', the callee is allocating a copy - (which is usually the case). In the case of `getter_Shares()', the + (which is usually the case). In the case where the callee is returning a const reference to `the real deal' (this can - be done using the [shared] attribute in XPIDL). + be done using the [shared] attribute in XPIDL) you can just use + a |const char*|. */ @@ -99,8 +100,8 @@ typedef PRUint16 PRUnichar; //////////////////////////////////////////////////////////////////////// // nsXPIDLString // -// A wrapper for Unicode strings. With the |getter_Copies()| and -// |getter_Shares()| helper functions, this can be used instead of +// A wrapper for Unicode strings. With the |getter_Copies()| +// helper function, this can be used instead of // the "naked" |PRUnichar*| interface for |wstring| parameters in // XPIDL interfaces. // @@ -108,16 +109,14 @@ typedef PRUint16 PRUnichar; class NS_COM nsXPIDLString { private: PRUnichar* mBuf; - PRBool mBufOwner; PRUnichar** StartAssignmentByValue(); - const PRUnichar** StartAssignmentByReference(); public: /** * Construct a new, uninitialized wrapper for a Unicode string. */ - nsXPIDLString() : mBuf(0), mBufOwner(PR_FALSE) {} + nsXPIDLString() : mBuf(0) {} ~nsXPIDLString(); @@ -131,12 +130,6 @@ public: */ const PRUnichar* get() const { return mBuf; } - /** - * Make a copy of the Unicode string. Use this function in the - * callee to ensure that the correct memory allocator is used. - */ - static PRUnichar* Copy(const PRUnichar* aString); - // A helper class for assignment-by-value. This class is an // implementation detail and should not be considered part of the // public interface. @@ -157,25 +150,7 @@ public: friend class GetterCopies; - // A helper class for assignment-by-reference. This class is an - // implementation detail and should not be considered part of the - // public interface. - class NS_COM GetterShares { - private: - nsXPIDLString& mXPIDLString; - - public: - GetterShares(nsXPIDLString& aXPIDLString) - : mXPIDLString(aXPIDLString) {} - - operator const PRUnichar**() { - return mXPIDLString.StartAssignmentByReference(); - } - - friend GetterShares getter_Shares(nsXPIDLString& aXPIDLString); - }; - - friend class GetterShares; + inline void Adopt( PRUnichar* ); private: // not to be implemented @@ -183,7 +158,6 @@ private: void operator=(nsXPIDLString& /* aXPIDLString */) {} }; - /** * Use this function to "wrap" the nsXPIDLString object that is to * receive an |out| value. @@ -194,30 +168,26 @@ getter_Copies(nsXPIDLString& aXPIDLString) return nsXPIDLString::GetterCopies(aXPIDLString); } -/** - * Use this function to "wrap" the nsXPIDLString object that is to - * receive a |[shared] out| value. - */ -inline nsXPIDLString::GetterShares -getter_Shares(nsXPIDLString& aXPIDLString) -{ - return nsXPIDLString::GetterShares(aXPIDLString); -} - +inline +void +nsXPIDLString::Adopt( PRUnichar* aNewValue ) + { + *getter_Copies(*this) = aNewValue; + } // XXX THESE ARE NOT strcmp()! DON'T TRY TO USE THEM AS SUCH! inline PRBool operator==(const PRUnichar* lhs, const nsXPIDLString& rhs) { - return lhs == NS_STATIC_CAST(const PRUnichar*, rhs); + return lhs == rhs.get(); } inline PRBool operator==(const nsXPIDLString& lhs, const PRUnichar* rhs) { - return NS_STATIC_CAST(const PRUnichar*, lhs) == rhs; + return lhs.get() == rhs; } @@ -242,8 +212,8 @@ operator==(const nsXPIDLString& lhs, int rhs) //////////////////////////////////////////////////////////////////////// // nsXPIDLCString // -// A wrapper for Unicode strings. With the |getter_Copies()| and -// |getter_Shares()| helper functions, this can be used instead of +// A wrapper for Unicode strings. With the |getter_Copies()| +// helper function, this can be used instead of // the "naked" |char*| interface for |string| parameters in XPIDL // interfaces. // @@ -251,25 +221,17 @@ operator==(const nsXPIDLString& lhs, int rhs) class NS_COM nsXPIDLCString { private: char* mBuf; - PRBool mBufOwner; char** StartAssignmentByValue(); - const char** StartAssignmentByReference(); public: /** * Construct a new, uninitialized wrapper for a single-byte string. */ - nsXPIDLCString() : mBuf(0), mBufOwner(PR_FALSE) {} + nsXPIDLCString() : mBuf(0) {} ~nsXPIDLCString(); - /** - * Assign a single-byte string to this wrapper. Copies - * and owns the result. - */ - nsXPIDLCString& operator=(const char* aString); - /** * Return a reference to the immutable single-byte string. */ @@ -280,12 +242,6 @@ public: */ const char* get() const { return mBuf; } - /** - * Make a copy of the single-byte string. Use this function in the - * callee to ensure that the correct memory allocator is used. - */ - static char* Copy(const char* aString); - // A helper class for assignment-by-value. This class is an // implementation detail and should not be considered part of the // public interface. @@ -306,25 +262,7 @@ public: friend class GetterCopies; - // A helper class for assignment-by-reference. This class is an - // implementation detail and should not be considered part of the - // public interface. - class NS_COM GetterShares { - private: - nsXPIDLCString& mXPIDLString; - - public: - GetterShares(nsXPIDLCString& aXPIDLString) - : mXPIDLString(aXPIDLString) {} - - operator const char**() { - return mXPIDLString.StartAssignmentByReference(); - } - - friend GetterShares getter_Shares(nsXPIDLCString& aXPIDLString); - }; - - friend class GetterShares; + inline void Adopt( char* ); private: // not to be implemented @@ -342,30 +280,26 @@ getter_Copies(nsXPIDLCString& aXPIDLString) return nsXPIDLCString::GetterCopies(aXPIDLString); } - -/** - * Use this function to "wrap" the nsXPIDLCString object that is to - * receive a |[shared] out| value. - */ -inline nsXPIDLCString::GetterShares -getter_Shares(nsXPIDLCString& aXPIDLString) -{ - return nsXPIDLCString::GetterShares(aXPIDLString); -} +inline +void +nsXPIDLCString::Adopt( char* aNewValue ) + { + *getter_Copies(*this) = aNewValue; + } // XXX THESE ARE NOT strcmp()! DON'T TRY TO USE THEM AS SUCH! inline PRBool operator==(const char* lhs, const nsXPIDLCString& rhs) { - return lhs == NS_STATIC_CAST(const char*, rhs); + return lhs == rhs.get(); } inline PRBool operator==(const nsXPIDLCString& lhs, const char* rhs) { - return NS_STATIC_CAST(const char*, lhs) == rhs; + return lhs.get() == rhs; } #ifdef HAVE_CPP_TROUBLE_COMPARING_TO_ZERO diff --git a/mozilla/xpcom/tests/TestXPIDLString.cpp b/mozilla/xpcom/tests/TestXPIDLString.cpp index 921fd7cf985..f2802e1f6c8 100644 --- a/mozilla/xpcom/tests/TestXPIDLString.cpp +++ b/mozilla/xpcom/tests/TestXPIDLString.cpp @@ -1,20 +1,11 @@ #include "nsString.h" +#include "nsReadableUtils.h" #include "nsXPIDLString.h" static void nsXPIDLStringTest_Value(PRUnichar** aResult) { - nsAutoString s(NS_ConvertASCIItoUCS2("Hello, World")); - *aResult = nsXPIDLString::Copy(s.GetUnicode()); -} - -static void -nsXPIDLStringTest_Reference(const PRUnichar** aResult) -{ - static const PRUnichar s[] = { 'H', 'e', 'l', 'l', 'o', ',', ' ', - 'w', 'o', 'r', 'l', 'd', '\0' }; - - *aResult = s; + *aResult = ToNewUnicode(NS_LITERAL_STRING("Hello, World")); } int @@ -22,7 +13,6 @@ main(int argc, char* argv[]) { nsXPIDLString s1; nsXPIDLStringTest_Value(getter_Copies(s1)); - nsXPIDLStringTest_Reference(getter_Shares(s1)); return 0; } diff --git a/mozilla/xpfe/appshell/src/nsWindowMediator.h b/mozilla/xpfe/appshell/src/nsWindowMediator.h index d653c7fcae4..f85a79912f4 100644 --- a/mozilla/xpfe/appshell/src/nsWindowMediator.h +++ b/mozilla/xpfe/appshell/src/nsWindowMediator.h @@ -27,6 +27,7 @@ #include "nsIWindowMediator.h" #include "nsIWindowWatcher.h" #include "nsXPIDLString.h" +#include "nsCRT.h" class nsWindowEnumerator; struct nsWindowInfo; @@ -54,7 +55,7 @@ public: if (! uri) return NS_ERROR_NULL_POINTER; - *uri = nsXPIDLCString::Copy("rdf:window-mediator"); + *uri = nsCRT::strdup("rdf:window-mediator"); if (! *uri) return NS_ERROR_OUT_OF_MEMORY; diff --git a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp index 627350e03c7..7b7a2725fdb 100644 --- a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp +++ b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp @@ -1109,8 +1109,8 @@ BookmarkParser::ParseBookmarkInfo(BookmarkField *fields, PRBool isBookmarkFlag, if (bookmark) { - nsXPIDLCString bookmarkURI; - bookmark->GetValueConst(getter_Shares(bookmarkURI)); + const char* bookmarkURI; + bookmark->GetValueConst(&bookmarkURI); bookmarkNode = bookmark; @@ -2081,7 +2081,7 @@ nsBookmarksService::OnStopRequest(nsIRequest* request, nsISupports *ctxt, lastModValue = val; if (NS_SUCCEEDED(httpChannel->GetResponseHeader("Content-Length", getter_Copies(val)))) contentLengthValue = val; - val = 0; + val.Adopt(0); PRBool changedFlag = PR_FALSE; @@ -2822,7 +2822,7 @@ nsBookmarksService::GetAnonymousResource(nsIRDFResource** aResult) NS_IMETHODIMP nsBookmarksService::GetURI(char* *aURI) { - *aURI = nsXPIDLCString::Copy("rdf:bookmarks"); + *aURI = nsCRT::strdup("rdf:bookmarks"); if (! *aURI) return NS_ERROR_OUT_OF_MEMORY; diff --git a/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp b/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp index 567f9e23dc1..b27869ab606 100644 --- a/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp +++ b/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp @@ -808,7 +808,7 @@ nsHTTPIndex::GetEncoding(char **encoding) if (! encoding) return(NS_ERROR_NULL_POINTER); - *encoding = nsXPIDLCString::Copy(mEncoding); + *encoding = ToNewCString(mEncoding); if (!*encoding) return(NS_ERROR_OUT_OF_MEMORY); @@ -1257,7 +1257,7 @@ NS_IMPL_THREADSAFE_ISUPPORTS2(nsHTTPIndex, nsIHTTPIndex, nsIRDFDataSource); NS_IMETHODIMP nsHTTPIndex::GetBaseURL(char** _result) { - *_result = nsXPIDLCString::Copy(mBaseURL); + *_result = ToNewCString(mBaseURL); if (! *_result) return NS_ERROR_OUT_OF_MEMORY; @@ -1293,11 +1293,13 @@ void nsHTTPIndex::GetDestination(nsIRDFResource* r, nsXPIDLCString& dest) { url = do_QueryInterface(node); if (!url) { - r->GetValueConst(getter_Shares(dest)); + const char* temp; + r->GetValueConst(&temp); + dest.Adopt(nsCRT::strdup(temp)); } else { const PRUnichar* uri; url->GetValueConst(&uri); - *getter_Copies(dest) = ToNewUTF8String(nsDependentString(uri)); + dest.Adopt(ToNewUTF8String(nsDependentString(uri))); } } @@ -1371,7 +1373,7 @@ nsHTTPIndex::GetURI(char * *uri) if (! uri) return(NS_ERROR_NULL_POINTER); - if ((*uri = nsXPIDLCString::Copy("rdf:httpindex")) == nsnull) + if ((*uri = nsCRT::strdup("rdf:httpindex")) == nsnull) return(NS_ERROR_OUT_OF_MEMORY); return(NS_OK); diff --git a/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp b/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp index 81ee1517c68..4ca95135365 100644 --- a/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp +++ b/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp @@ -1148,7 +1148,7 @@ nsGlobalHistory::GetURI(char* *aURI) if (! aURI) return NS_ERROR_NULL_POINTER; - *aURI = nsXPIDLCString::Copy("rdf:history"); + *aURI = nsCRT::strdup("rdf:history"); if (! *aURI) return NS_ERROR_OUT_OF_MEMORY; @@ -1698,8 +1698,8 @@ nsGlobalHistory::Unassert(nsIRDFResource* aSource, if (NS_FAILED(rv)) return NS_RDF_ASSERTION_REJECTED; - nsXPIDLCString targetUrl; - rv = resource->GetValueConst(getter_Shares(targetUrl)); + const char* targetUrl; + rv = resource->GetValueConst(&targetUrl); if (NS_FAILED(rv)) return NS_RDF_ASSERTION_REJECTED; // ignore any error @@ -2294,8 +2294,8 @@ nsGlobalHistory::CreateFindEnumerator(nsIRDFResource *aSource, if (!IsFindResource(aSource)) return NS_ERROR_FAILURE; - nsXPIDLCString uri; - rv = aSource->GetValueConst(getter_Shares(uri)); + const char* uri; + rv = aSource->GetValueConst(&uri); if (NS_FAILED(rv)) return rv; // convert uri to a query @@ -3055,8 +3055,9 @@ nsGlobalHistory::NotifyFindUnassertions(nsIRDFResource *aSource, query.terms.AppendElement((void *)&hostterm); GetFindUriPrefix(query, PR_FALSE, findUri); - nsXPIDLCString sourceStr; - aSource->GetValueConst(getter_Shares(sourceStr)); + // XXX |sourceStr| unused ... why are we doing this? + const char* sourceStr; + aSource->GetValueConst(&sourceStr); gRDFService->GetResource(findUri.get(), getter_AddRefs(findResource)); diff --git a/mozilla/xpfe/components/regviewer/nsRegistryDataSource.cpp b/mozilla/xpfe/components/regviewer/nsRegistryDataSource.cpp index e17353fdfad..0e83260bc5f 100644 --- a/mozilla/xpfe/components/regviewer/nsRegistryDataSource.cpp +++ b/mozilla/xpfe/components/regviewer/nsRegistryDataSource.cpp @@ -225,7 +225,7 @@ nsRegistryDataSource::OpenDefaultRegistry() NS_IMETHODIMP nsRegistryDataSource::GetURI(char * *aURI) { - *aURI = nsXPIDLCString::Copy("rdf:registry"); + *aURI = nsCRT::strdup("rdf:registry"); return *aURI ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/xpfe/components/related/src/nsRelatedLinksHandler.cpp b/mozilla/xpfe/components/related/src/nsRelatedLinksHandler.cpp index 0faeda3fe44..4da86e95ef1 100644 --- a/mozilla/xpfe/components/related/src/nsRelatedLinksHandler.cpp +++ b/mozilla/xpfe/components/related/src/nsRelatedLinksHandler.cpp @@ -663,7 +663,7 @@ RelatedLinksHandlerImpl::GetURL(char** aURL) if (mRelatedLinksURL) { - *aURL = nsXPIDLCString::Copy(mRelatedLinksURL); + *aURL = nsCRT::strdup(mRelatedLinksURL); return *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } else @@ -734,7 +734,7 @@ RelatedLinksHandlerImpl::GetURI(char **aURI) // XXX We could munge in the current URL that we're looking at I // suppose. Not critical because this datasource shouldn't be // registered with the RDF service. - *aURI = nsXPIDLCString::Copy("rdf:related-links"); + *aURI = nsCRT::strdup("rdf:related-links"); if (! *aURI) return NS_ERROR_OUT_OF_MEMORY; diff --git a/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp b/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp index 15a2990969f..503d04de28b 100755 --- a/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp +++ b/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp @@ -932,7 +932,7 @@ InternetSearchDataSource::GetURI(char **uri) if (! uri) return NS_ERROR_NULL_POINTER; - if ((*uri = nsXPIDLCString::Copy("rdf:internetsearch")) == nsnull) + if ((*uri = nsCRT::strdup("rdf:internetsearch")) == nsnull) return NS_ERROR_OUT_OF_MEMORY; return NS_OK; @@ -4504,7 +4504,7 @@ InternetSearchDataSource::OnStopRequest(nsIRequest *request, nsISupports *ctxt, lastModValue = val; if (NS_SUCCEEDED(httpChannel->GetResponseHeader("Content-Length", getter_Copies(val)))) contentLengthValue = val; - val = 0; + val.Adopt(0); // should we fetch the entire file? PRBool updateSearchEngineFile = PR_FALSE; diff --git a/mozilla/xpfe/components/search/src/nsLocalSearchService.cpp b/mozilla/xpfe/components/search/src/nsLocalSearchService.cpp index 89d0d48dd50..aec6bf19804 100755 --- a/mozilla/xpfe/components/search/src/nsLocalSearchService.cpp +++ b/mozilla/xpfe/components/search/src/nsLocalSearchService.cpp @@ -148,7 +148,7 @@ LocalSearchDataSource::GetURI(char **uri) if (! uri) return NS_ERROR_NULL_POINTER; - if ((*uri = nsXPIDLCString::Copy("rdf:localsearch")) == nsnull) + if ((*uri = nsCRT::strdup("rdf:localsearch")) == nsnull) return NS_ERROR_OUT_OF_MEMORY; return NS_OK;