fixes bug 271630 "XPCOM glue broken on Linux/PPC [monkeypox orange]" r=bsmedberg

This commit is contained in:
darin%meer.net 2004-11-30 00:28:48 +00:00
Родитель d3a934d8e7
Коммит fc0cee9787
6 изменённых файлов: 549 добавлений и 38 удалений

Просмотреть файл

@ -72,6 +72,7 @@ endif
CPPSRCS = \
$(XPCOM_GLUE_SRC_LCSRCS) \
nsXPComInit.cpp \
nsStringAPI.cpp \
$(NULL)
ifeq ($(OS_ARCH),WINNT)

350
xpcom/build/nsStringAPI.cpp Normal file
Просмотреть файл

@ -0,0 +1,350 @@
/* vim:set ts=2 sw=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is IBM Corporation.
* Portions created by IBM Corporation are Copyright (C) 2003
* IBM Corporation. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsString.h"
#include "nsCharTraits.h"
#include "nsStringAPI.h"
#include "nsNativeCharsetUtils.h"
/* ------------------------------------------------------------------------- */
NS_STRINGAPI(nsresult)
NS_StringContainerInit(nsStringContainer &aContainer)
{
NS_ASSERTION(sizeof(nsStringContainer) >= sizeof(nsString),
"nsStringContainer is not large enough");
// use placement new to avoid heap allocating nsString object
new (&aContainer) nsString();
return NS_OK;
}
NS_STRINGAPI(nsresult)
NS_StringContainerInit2(nsStringContainer &aContainer,
const PRUnichar *aData,
PRUint32 aDataLength,
PRUint32 aFlags)
{
NS_ASSERTION(sizeof(nsStringContainer) >= sizeof(nsString),
"nsStringContainer is not large enough");
if (!aData)
{
new (&aContainer) nsString();
}
else
{
if (aDataLength == PR_UINT32_MAX)
{
NS_ENSURE_ARG(!(aFlags & NS_STRING_CONTAINER_INIT_SUBSTRING));
aDataLength = nsCharTraits<PRUnichar>::length(aData);
}
if (aFlags & (NS_STRING_CONTAINER_INIT_DEPEND |
NS_STRING_CONTAINER_INIT_ADOPT))
{
PRUint32 flags;
if (aFlags & NS_STRING_CONTAINER_INIT_SUBSTRING)
flags = nsSubstring::F_NONE;
else
flags = nsSubstring::F_TERMINATED;
if (aFlags & NS_STRING_CONTAINER_INIT_ADOPT)
flags |= nsSubstring::F_OWNED;
new (&aContainer) nsSubstring(NS_CONST_CAST(PRUnichar *, aData),
aDataLength, flags);
}
else
{
new (&aContainer) nsString(aData, aDataLength);
}
}
return NS_OK;
}
NS_STRINGAPI(void)
NS_StringContainerFinish(nsStringContainer &aContainer)
{
// call the nsString dtor
NS_REINTERPRET_CAST(nsString *, &aContainer)->~nsString();
}
/* ------------------------------------------------------------------------- */
NS_STRINGAPI(PRUint32)
NS_StringGetData(const nsAString &aStr, const PRUnichar **aData,
PRBool *aTerminated)
{
if (aTerminated)
*aTerminated = aStr.IsTerminated();
nsAString::const_iterator begin;
aStr.BeginReading(begin);
*aData = begin.get();
return begin.size_forward();
}
NS_STRINGAPI(PRUnichar *)
NS_StringCloneData(const nsAString &aStr)
{
return ToNewUnicode(aStr);
}
NS_STRINGAPI(nsresult)
NS_StringSetData(nsAString &aStr, const PRUnichar *aData, PRUint32 aDataLength)
{
aStr.Assign(aData, aDataLength);
return NS_OK; // XXX report errors
}
NS_STRINGAPI(nsresult)
NS_StringSetDataRange(nsAString &aStr,
PRUint32 aCutOffset, PRUint32 aCutLength,
const PRUnichar *aData, PRUint32 aDataLength)
{
if (aCutOffset == PR_UINT32_MAX)
{
// append case
if (aData)
aStr.Append(aData, aDataLength);
return NS_OK; // XXX report errors
}
if (aCutLength == PR_UINT32_MAX)
aCutLength = aStr.Length() - aCutOffset;
if (aData)
{
if (aDataLength == PR_UINT32_MAX)
aStr.Replace(aCutOffset, aCutLength, nsDependentString(aData));
else
aStr.Replace(aCutOffset, aCutLength, Substring(aData, aData + aDataLength));
}
else
aStr.Cut(aCutOffset, aCutLength);
return NS_OK; // XXX report errors
}
NS_STRINGAPI(nsresult)
NS_StringCopy(nsAString &aDest, const nsAString &aSrc)
{
aDest.Assign(aSrc);
return NS_OK; // XXX report errors
}
/* ------------------------------------------------------------------------- */
NS_STRINGAPI(nsresult)
NS_CStringContainerInit(nsCStringContainer &aContainer)
{
NS_ASSERTION(sizeof(nsCStringContainer) >= sizeof(nsCString),
"nsCStringContainer is not large enough");
// use placement new to avoid heap allocating nsCString object
new (&aContainer) nsCString();
return NS_OK;
}
NS_STRINGAPI(nsresult)
NS_CStringContainerInit2(nsCStringContainer &aContainer,
const char *aData,
PRUint32 aDataLength,
PRUint32 aFlags)
{
NS_ASSERTION(sizeof(nsCStringContainer) >= sizeof(nsCString),
"nsStringContainer is not large enough");
if (!aData)
{
new (&aContainer) nsCString();
}
else
{
if (aDataLength == PR_UINT32_MAX)
{
NS_ENSURE_ARG(!(aFlags & NS_CSTRING_CONTAINER_INIT_SUBSTRING));
aDataLength = nsCharTraits<char>::length(aData);
}
if (aFlags & (NS_CSTRING_CONTAINER_INIT_DEPEND |
NS_CSTRING_CONTAINER_INIT_ADOPT))
{
PRUint32 flags;
if (aFlags & NS_CSTRING_CONTAINER_INIT_SUBSTRING)
flags = nsCSubstring::F_NONE;
else
flags = nsCSubstring::F_TERMINATED;
if (aFlags & NS_CSTRING_CONTAINER_INIT_ADOPT)
flags |= nsCSubstring::F_OWNED;
new (&aContainer) nsCSubstring(NS_CONST_CAST(char *, aData),
aDataLength, flags);
}
else
{
new (&aContainer) nsCString(aData, aDataLength);
}
}
return NS_OK;
}
NS_STRINGAPI(void)
NS_CStringContainerFinish(nsCStringContainer &aContainer)
{
// call the nsCString dtor
NS_REINTERPRET_CAST(nsCString *, &aContainer)->~nsCString();
}
/* ------------------------------------------------------------------------- */
NS_STRINGAPI(PRUint32)
NS_CStringGetData(const nsACString &aStr, const char **aData,
PRBool *aTerminated)
{
if (aTerminated)
*aTerminated = aStr.IsTerminated();
nsACString::const_iterator begin;
aStr.BeginReading(begin);
*aData = begin.get();
return begin.size_forward();
}
NS_STRINGAPI(char *)
NS_CStringCloneData(const nsACString &aStr)
{
return ToNewCString(aStr);
}
NS_STRINGAPI(nsresult)
NS_CStringSetData(nsACString &aStr, const char *aData, PRUint32 aDataLength)
{
aStr.Assign(aData, aDataLength);
return NS_OK; // XXX report errors
}
NS_STRINGAPI(nsresult)
NS_CStringSetDataRange(nsACString &aStr,
PRUint32 aCutOffset, PRUint32 aCutLength,
const char *aData, PRUint32 aDataLength)
{
if (aCutOffset == PR_UINT32_MAX)
{
// append case
if (aData)
aStr.Append(aData, aDataLength);
return NS_OK; // XXX report errors
}
if (aCutLength == PR_UINT32_MAX)
aCutLength = aStr.Length() - aCutOffset;
if (aData)
{
if (aDataLength == PR_UINT32_MAX)
aStr.Replace(aCutOffset, aCutLength, nsDependentCString(aData));
else
aStr.Replace(aCutOffset, aCutLength, Substring(aData, aData + aDataLength));
}
else
aStr.Cut(aCutOffset, aCutLength);
return NS_OK; // XXX report errors
}
NS_STRINGAPI(nsresult)
NS_CStringCopy(nsACString &aDest, const nsACString &aSrc)
{
aDest.Assign(aSrc);
return NS_OK; // XXX report errors
}
/* ------------------------------------------------------------------------- */
NS_STRINGAPI(nsresult)
NS_CStringToUTF16(const nsACString &aSrc,
nsCStringEncoding aSrcEncoding,
nsAString &aDest)
{
switch (aSrcEncoding)
{
case NS_CSTRING_ENCODING_ASCII:
CopyASCIItoUTF16(aSrc, aDest);
break;
case NS_CSTRING_ENCODING_UTF8:
CopyUTF8toUTF16(aSrc, aDest);
break;
case NS_CSTRING_ENCODING_NATIVE_FILESYSTEM:
NS_CopyNativeToUnicode(aSrc, aDest);
break;
default:
return NS_ERROR_NOT_IMPLEMENTED;
}
return NS_OK; // XXX report errors
}
NS_STRINGAPI(nsresult)
NS_UTF16ToCString(const nsAString &aSrc,
nsCStringEncoding aDestEncoding,
nsACString &aDest)
{
switch (aDestEncoding)
{
case NS_CSTRING_ENCODING_ASCII:
LossyCopyUTF16toASCII(aSrc, aDest);
break;
case NS_CSTRING_ENCODING_UTF8:
CopyUTF16toUTF8(aSrc, aDest);
break;
case NS_CSTRING_ENCODING_NATIVE_FILESYSTEM:
NS_CopyUnicodeToNative(aSrc, aDest);
break;
default:
return NS_ERROR_NOT_IMPLEMENTED;
}
return NS_OK; // XXX report errors
}

Просмотреть файл

@ -46,10 +46,32 @@
* dependency on the implementation details of the abstract string types.
*/
// Map frozen functions to private symbol names if not using strict API.
#ifndef MOZILLA_STRICT_API
# define NS_StringContainerInit NS_StringContainerInit_P
# define NS_StringContainerInit2 NS_StringContainerInit2_P
# define NS_StringContainerFinish NS_StringContainerFinish_P
# define NS_StringGetData NS_StringGetData_P
# define NS_StringCloneData NS_StringCloneData_P
# define NS_StringSetData NS_StringSetData_P
# define NS_StringSetDataRange NS_StringSetDataRange_P
# define NS_StringCopy NS_StringCopy_P
# define NS_CStringContainerInit NS_CStringContainerInit_P
# define NS_CStringContainerInit2 NS_CStringContainerInit2_P
# define NS_CStringContainerFinish NS_CStringContainerFinish_P
# define NS_CStringGetData NS_CStringGetData_P
# define NS_CStringCloneData NS_CStringCloneData_P
# define NS_CStringSetData NS_CStringSetData_P
# define NS_CStringSetDataRange NS_CStringSetDataRange_P
# define NS_CStringCopy NS_CStringCopy_P
# define NS_CStringToUTF16 NS_CStringToUTF16_P
# define NS_UTF16ToCString NS_UTF16ToCString_P
#endif
#include "nscore.h"
#if defined( XPCOM_GLUE )
#define NS_STRINGAPI(type) extern "C" type
#define NS_STRINGAPI(type) extern "C" NS_HIDDEN_(type)
#elif defined( _IMPL_NS_STRINGAPI )
#define NS_STRINGAPI(type) extern "C" NS_EXPORT type
#else

Просмотреть файл

@ -62,7 +62,7 @@ REQUIRES = string \
DEFINES = -D_IMPL_NS_STRINGAPI
LOCAL_INCLUDES = -I$(srcdir)/../build
CPPSRCS = nsXPComStub.cpp nsStringAPI.cpp
CPPSRCS = nsXPComStub.cpp
# If we have an import library, then copy that to the SDK. Otherwise,
# copy the shared library.

Просмотреть файл

Просмотреть файл

@ -60,29 +60,29 @@ static const XPCOMFunctions kFrozenFunctions = {
&NS_GetTraceRefcnt_P,
// these functions were added post 1.6
&NS_StringContainerInit,
&NS_StringContainerFinish,
&NS_StringGetData,
&NS_StringSetData,
&NS_StringSetDataRange,
&NS_StringCopy,
&NS_CStringContainerInit,
&NS_CStringContainerFinish,
&NS_CStringGetData,
&NS_CStringSetData,
&NS_CStringSetDataRange,
&NS_CStringCopy,
&NS_CStringToUTF16,
&NS_UTF16ToCString,
&NS_StringCloneData,
&NS_CStringCloneData,
&NS_StringContainerInit_P,
&NS_StringContainerFinish_P,
&NS_StringGetData_P,
&NS_StringSetData_P,
&NS_StringSetDataRange_P,
&NS_StringCopy_P,
&NS_CStringContainerInit_P,
&NS_CStringContainerFinish_P,
&NS_CStringGetData_P,
&NS_CStringSetData_P,
&NS_CStringSetDataRange_P,
&NS_CStringCopy_P,
&NS_CStringToUTF16_P,
&NS_UTF16ToCString_P,
&NS_StringCloneData_P,
&NS_CStringCloneData_P,
// these functions were added post 1.7 (post Firefox 1.0)
&NS_Alloc_P,
&NS_Realloc_P,
&NS_Free_P,
&NS_StringContainerInit2,
&NS_CStringContainerInit2
&NS_StringContainerInit2_P,
&NS_CStringContainerInit2_P
};
extern "C" NS_EXPORT nsresult
@ -185,24 +185,6 @@ NS_GetTraceRefcnt(nsITraceRefcnt **result)
return NS_GetTraceRefcnt_P(result);
}
/*
* Stubs for nsXPCOMPrivate.h
*/
#undef NS_RegisterXPCOMExitRoutine
extern "C" NS_EXPORT nsresult
NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, PRUint32 priority)
{
return NS_RegisterXPCOMExitRoutine_P(exitRoutine, priority);
}
#undef NS_UnregisterXPCOMExitRoutine
extern "C" NS_EXPORT nsresult
NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine)
{
return NS_UnregisterXPCOMExitRoutine_P(exitRoutine);
}
#undef NS_Alloc
extern "C" NS_EXPORT void*
NS_Alloc(PRSize size)
@ -223,3 +205,159 @@ NS_Free(void* ptr)
{
NS_Free_P(ptr);
}
/*
* Stubs for nsXPCOMPrivate.h
*/
#undef NS_RegisterXPCOMExitRoutine
extern "C" NS_EXPORT nsresult
NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, PRUint32 priority)
{
return NS_RegisterXPCOMExitRoutine_P(exitRoutine, priority);
}
#undef NS_UnregisterXPCOMExitRoutine
extern "C" NS_EXPORT nsresult
NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine)
{
return NS_UnregisterXPCOMExitRoutine_P(exitRoutine);
}
/*
* Stubs for nsStringAPI.h
*/
#undef NS_StringContainerInit
extern "C" NS_EXPORT nsresult
NS_StringContainerInit(nsStringContainer &aStr)
{
return NS_StringContainerInit_P(aStr);
}
#undef NS_StringContainerInit2
extern "C" NS_EXPORT nsresult
NS_StringContainerInit2(nsStringContainer &aStr,
const PRUnichar *aData,
PRUint32 aDataLength,
PRUint32 aFlags)
{
return NS_StringContainerInit2_P(aStr, aData, aDataLength, aFlags);
}
#undef NS_StringContainerFinish
extern "C" NS_EXPORT void
NS_StringContainerFinish(nsStringContainer &aStr)
{
NS_StringContainerFinish_P(aStr);
}
#undef NS_StringGetData
extern "C" NS_EXPORT PRUint32
NS_StringGetData(const nsAString &aStr, const PRUnichar **aBuf, PRBool *aTerm)
{
return NS_StringGetData_P(aStr, aBuf, aTerm);
}
#undef NS_StringCloneData
extern "C" NS_EXPORT PRUnichar *
NS_StringCloneData(const nsAString &aStr)
{
return NS_StringCloneData_P(aStr);
}
#undef NS_StringSetData
extern "C" NS_EXPORT nsresult
NS_StringSetData(nsAString &aStr, const PRUnichar *aBuf, PRUint32 aCount)
{
return NS_StringSetData_P(aStr, aBuf, aCount);
}
#undef NS_StringSetDataRange
extern "C" NS_EXPORT nsresult
NS_StringSetDataRange(nsAString &aStr, PRUint32 aCutStart, PRUint32 aCutLength,
const PRUnichar *aBuf, PRUint32 aCount)
{
return NS_StringSetDataRange_P(aStr, aCutStart, aCutLength, aBuf, aCount);
}
#undef NS_StringCopy
extern "C" NS_EXPORT nsresult
NS_StringCopy(nsAString &aDest, const nsAString &aSrc)
{
return NS_StringCopy_P(aDest, aSrc);
}
#undef NS_CStringContainerInit
extern "C" NS_EXPORT nsresult
NS_CStringContainerInit(nsCStringContainer &aStr)
{
return NS_CStringContainerInit_P(aStr);
}
#undef NS_CStringContainerInit2
extern "C" NS_EXPORT nsresult
NS_CStringContainerInit2(nsCStringContainer &aStr,
const char *aData,
PRUint32 aDataLength,
PRUint32 aFlags)
{
return NS_CStringContainerInit2_P(aStr, aData, aDataLength, aFlags);
}
#undef NS_CStringContainerFinish
extern "C" NS_EXPORT void
NS_CStringContainerFinish(nsCStringContainer &aStr)
{
NS_CStringContainerFinish_P(aStr);
}
#undef NS_CStringGetData
extern "C" NS_EXPORT PRUint32
NS_CStringGetData(const nsACString &aStr, const char **aBuf, PRBool *aTerm)
{
return NS_CStringGetData_P(aStr, aBuf, aTerm);
}
#undef NS_CStringCloneData
extern "C" NS_EXPORT char *
NS_CStringCloneData(const nsACString &aStr)
{
return NS_CStringCloneData_P(aStr);
}
#undef NS_CStringSetData
extern "C" NS_EXPORT nsresult
NS_CStringSetData(nsACString &aStr, const char *aBuf, PRUint32 aCount)
{
return NS_CStringSetData_P(aStr, aBuf, aCount);
}
#undef NS_CStringSetDataRange
extern "C" NS_EXPORT nsresult
NS_CStringSetDataRange(nsACString &aStr, PRUint32 aCutStart, PRUint32 aCutLength,
const char *aBuf, PRUint32 aCount)
{
return NS_CStringSetDataRange_P(aStr, aCutStart, aCutLength, aBuf, aCount);
}
#undef NS_CStringCopy
extern "C" NS_EXPORT nsresult
NS_CStringCopy(nsACString &aDest, const nsACString &aSrc)
{
return NS_CStringCopy_P(aDest, aSrc);
}
#undef NS_CStringToUTF16
extern "C" NS_EXPORT nsresult
NS_CStringToUTF16(const nsACString &aSrc, nsCStringEncoding aSrcEncoding, nsAString &aDest)
{
return NS_CStringToUTF16_P(aSrc, aSrcEncoding, aDest);
}
#undef NS_UTF16ToCString
extern "C" NS_EXPORT nsresult
NS_UTF16ToCString(const nsAString &aSrc, nsCStringEncoding aDestEncoding, nsACString &aDest)
{
return NS_UTF16ToCString_P(aSrc, aDestEncoding, aDest);
}