зеркало из https://github.com/mozilla/pjs.git
adding nsISupportsVoid to the nsISupportsPrimitives family. Fixing some suboptimal use of *retval
This commit is contained in:
Родитель
86287cf931
Коммит
ebb79eaa0a
|
@ -70,6 +70,7 @@ static NS_DEFINE_CID(kSupportsPRInt32CID, NS_SUPPORTS_PRINT32_CID);
|
||||||
static NS_DEFINE_CID(kSupportsPRInt64CID, NS_SUPPORTS_PRINT64_CID);
|
static NS_DEFINE_CID(kSupportsPRInt64CID, NS_SUPPORTS_PRINT64_CID);
|
||||||
static NS_DEFINE_CID(kSupportsFloatCID, NS_SUPPORTS_FLOAT_CID);
|
static NS_DEFINE_CID(kSupportsFloatCID, NS_SUPPORTS_FLOAT_CID);
|
||||||
static NS_DEFINE_CID(kSupportsDoubleCID, NS_SUPPORTS_DOUBLE_CID);
|
static NS_DEFINE_CID(kSupportsDoubleCID, NS_SUPPORTS_DOUBLE_CID);
|
||||||
|
static NS_DEFINE_CID(kSupportsVoidCID, NS_SUPPORTS_VOID_CID);
|
||||||
// io
|
// io
|
||||||
static NS_DEFINE_CID(kFileSpecCID, NS_FILESPEC_CID);
|
static NS_DEFINE_CID(kFileSpecCID, NS_FILESPEC_CID);
|
||||||
static NS_DEFINE_CID(kDirectoryIteratorCID, NS_DIRECTORYITERATOR_CID);
|
static NS_DEFINE_CID(kDirectoryIteratorCID, NS_DIRECTORYITERATOR_CID);
|
||||||
|
@ -99,6 +100,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt32Impl)
|
||||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt64Impl)
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt64Impl)
|
||||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsFloatImpl)
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsFloatImpl)
|
||||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsDoubleImpl)
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsDoubleImpl)
|
||||||
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsVoidImpl)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// XPCOM initialization
|
// XPCOM initialization
|
||||||
|
@ -381,6 +383,12 @@ nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result)
|
||||||
nsSupportsDoubleImplConstructor);
|
nsSupportsDoubleImplConstructor);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
rv = RegisterGenericFactory(compMgr, kSupportsVoidCID,
|
||||||
|
NS_SUPPORTS_VOID_CLASSNAME,
|
||||||
|
NS_SUPPORTS_VOID_PROGID,
|
||||||
|
nsSupportsVoidImplConstructor);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
// Prepopulate registry for performance
|
// Prepopulate registry for performance
|
||||||
// Ignore return value. It is ok if this fails.
|
// Ignore return value. It is ok if this fails.
|
||||||
nsComponentManagerImpl::gComponentManager->PlatformPrePopulateRegistry();
|
nsComponentManagerImpl::gComponentManager->PlatformPrePopulateRegistry();
|
||||||
|
|
|
@ -134,6 +134,14 @@ interface nsISupportsDouble : nsISupports
|
||||||
string toString();
|
string toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[scriptable, uuid(464484f0-568d-11d3-baf8-00805f8a5dd7)]
|
||||||
|
interface nsISupportsVoid : nsISupports
|
||||||
|
{
|
||||||
|
[noscript] void GetData([shared,retval] out voidStar aData);
|
||||||
|
[noscript] void SetData(in voidStar aData);
|
||||||
|
string toString();
|
||||||
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
%{C++
|
%{C++
|
||||||
|
@ -241,6 +249,11 @@ interface nsISupportsDouble : nsISupports
|
||||||
{ 0xba, 0xea, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
|
{ 0xba, 0xea, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
|
||||||
#define NS_SUPPORTS_DOUBLE_PROGID "component://netscape/supports-double"
|
#define NS_SUPPORTS_DOUBLE_PROGID "component://netscape/supports-double"
|
||||||
#define NS_SUPPORTS_DOUBLE_CLASSNAME "Supports double"
|
#define NS_SUPPORTS_DOUBLE_CLASSNAME "Supports double"
|
||||||
|
|
||||||
|
// {AF10F3E0-568D-11d3-BAF8-00805F8A5DD7}
|
||||||
|
#define NS_SUPPORTS_VOID_CID \
|
||||||
|
{ 0xaf10f3e0, 0x568d, 0x11d3, \
|
||||||
|
{ 0xba, 0xf8, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
|
||||||
|
#define NS_SUPPORTS_VOID_PROGID "component://netscape/supports-void"
|
||||||
|
#define NS_SUPPORTS_VOID_CLASSNAME "Supports void"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,18 +69,18 @@ NS_IMETHODIMP nsSupportsIDImpl::SetData(nsID *aData)
|
||||||
|
|
||||||
NS_IMETHODIMP nsSupportsIDImpl::toString(char **_retval)
|
NS_IMETHODIMP nsSupportsIDImpl::toString(char **_retval)
|
||||||
{
|
{
|
||||||
|
char* result = nsnull;
|
||||||
if(!_retval)
|
if(!_retval)
|
||||||
{
|
{
|
||||||
NS_ASSERTION(0,"Bad pointer");
|
NS_ASSERTION(0,"Bad pointer");
|
||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
}
|
}
|
||||||
*_retval = nsnull;
|
|
||||||
if(mData)
|
if(mData)
|
||||||
{
|
{
|
||||||
char * str = mData->ToString();
|
char * str = mData->ToString();
|
||||||
if(str)
|
if(str)
|
||||||
{
|
{
|
||||||
*_retval = (char*) nsAllocator::Clone(str,
|
result = (char*) nsAllocator::Clone(str,
|
||||||
(nsCRT::strlen(str)+1)*sizeof(char));
|
(nsCRT::strlen(str)+1)*sizeof(char));
|
||||||
delete [] str;
|
delete [] str;
|
||||||
}
|
}
|
||||||
|
@ -88,9 +88,11 @@ NS_IMETHODIMP nsSupportsIDImpl::toString(char **_retval)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
static const char nullStr[] = "null";
|
static const char nullStr[] = "null";
|
||||||
*_retval = (char*) nsAllocator::Clone(nullStr, sizeof(nullStr));
|
result = (char*) nsAllocator::Clone(nullStr, sizeof(nullStr));
|
||||||
}
|
}
|
||||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -237,9 +239,10 @@ NS_IMETHODIMP nsSupportsPRBoolImpl::toString(char **_retval)
|
||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
}
|
}
|
||||||
const char * str = mData ? "true" : "false";
|
const char * str = mData ? "true" : "false";
|
||||||
*_retval = (char*) nsAllocator::Clone(str,
|
char* result = (char*) nsAllocator::Clone(str,
|
||||||
(nsCRT::strlen(str)+1)*sizeof(char));
|
(nsCRT::strlen(str)+1)*sizeof(char));
|
||||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -283,9 +286,10 @@ NS_IMETHODIMP nsSupportsPRUint8Impl::toString(char **_retval)
|
||||||
|
|
||||||
PR_snprintf(buf, size, "%u", (PRUint16) mData);
|
PR_snprintf(buf, size, "%u", (PRUint16) mData);
|
||||||
|
|
||||||
*_retval = (char*) nsAllocator::Clone(buf,
|
char* result = (char*) nsAllocator::Clone(buf,
|
||||||
(nsCRT::strlen(buf)+1)*sizeof(char));
|
(nsCRT::strlen(buf)+1)*sizeof(char));
|
||||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -329,9 +333,10 @@ NS_IMETHODIMP nsSupportsPRUint16Impl::toString(char **_retval)
|
||||||
|
|
||||||
PR_snprintf(buf, size, "%u", (int) mData);
|
PR_snprintf(buf, size, "%u", (int) mData);
|
||||||
|
|
||||||
*_retval = (char*) nsAllocator::Clone(buf,
|
char* result = (char*) nsAllocator::Clone(buf,
|
||||||
(nsCRT::strlen(buf)+1)*sizeof(char));
|
(nsCRT::strlen(buf)+1)*sizeof(char));
|
||||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -375,9 +380,10 @@ NS_IMETHODIMP nsSupportsPRUint32Impl::toString(char **_retval)
|
||||||
|
|
||||||
PR_snprintf(buf, size, "%lu", mData);
|
PR_snprintf(buf, size, "%lu", mData);
|
||||||
|
|
||||||
*_retval = (char*) nsAllocator::Clone(buf,
|
char* result = (char*) nsAllocator::Clone(buf,
|
||||||
(nsCRT::strlen(buf)+1)*sizeof(char));
|
(nsCRT::strlen(buf)+1)*sizeof(char));
|
||||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -421,9 +427,10 @@ NS_IMETHODIMP nsSupportsPRUint64Impl::toString(char **_retval)
|
||||||
|
|
||||||
PR_snprintf(buf, size, "%llu", mData);
|
PR_snprintf(buf, size, "%llu", mData);
|
||||||
|
|
||||||
*_retval = (char*) nsAllocator::Clone(buf,
|
char* result = (char*) nsAllocator::Clone(buf,
|
||||||
(nsCRT::strlen(buf)+1)*sizeof(char));
|
(nsCRT::strlen(buf)+1)*sizeof(char));
|
||||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -467,9 +474,10 @@ NS_IMETHODIMP nsSupportsPRTimeImpl::toString(char **_retval)
|
||||||
|
|
||||||
PR_snprintf(buf, size, "%llu", mData);
|
PR_snprintf(buf, size, "%llu", mData);
|
||||||
|
|
||||||
*_retval = (char*) nsAllocator::Clone(buf,
|
char* result = (char*) nsAllocator::Clone(buf,
|
||||||
(nsCRT::strlen(buf)+1)*sizeof(char));
|
(nsCRT::strlen(buf)+1)*sizeof(char));
|
||||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -503,18 +511,20 @@ NS_IMETHODIMP nsSupportsCharImpl::SetData(char aData)
|
||||||
|
|
||||||
NS_IMETHODIMP nsSupportsCharImpl::toString(char **_retval)
|
NS_IMETHODIMP nsSupportsCharImpl::toString(char **_retval)
|
||||||
{
|
{
|
||||||
|
char* result;
|
||||||
if(!_retval)
|
if(!_retval)
|
||||||
{
|
{
|
||||||
NS_ASSERTION(0,"Bad pointer");
|
NS_ASSERTION(0,"Bad pointer");
|
||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
*_retval = (char*) nsAllocator::Alloc(2*sizeof(char));
|
if(nsnull != (result = (char*) nsAllocator::Alloc(2*sizeof(char))))
|
||||||
if(!*_retval)
|
{
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
result[0] = mData;
|
||||||
(*_retval)[0] = mData;
|
result[1] = '\0';
|
||||||
(*_retval)[1] = 0;
|
}
|
||||||
return NS_OK;
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -558,9 +568,10 @@ NS_IMETHODIMP nsSupportsPRInt16Impl::toString(char **_retval)
|
||||||
|
|
||||||
PR_snprintf(buf, size, "%d", mData);
|
PR_snprintf(buf, size, "%d", mData);
|
||||||
|
|
||||||
*_retval = (char*) nsAllocator::Clone(buf,
|
char* result = (char*) nsAllocator::Clone(buf,
|
||||||
(nsCRT::strlen(buf)+1)*sizeof(char));
|
(nsCRT::strlen(buf)+1)*sizeof(char));
|
||||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -604,9 +615,10 @@ NS_IMETHODIMP nsSupportsPRInt32Impl::toString(char **_retval)
|
||||||
|
|
||||||
PR_snprintf(buf, size, "%ld", mData);
|
PR_snprintf(buf, size, "%ld", mData);
|
||||||
|
|
||||||
*_retval = (char*) nsAllocator::Clone(buf,
|
char* result = (char*) nsAllocator::Clone(buf,
|
||||||
(nsCRT::strlen(buf)+1)*sizeof(char));
|
(nsCRT::strlen(buf)+1)*sizeof(char));
|
||||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -650,9 +662,10 @@ NS_IMETHODIMP nsSupportsPRInt64Impl::toString(char **_retval)
|
||||||
|
|
||||||
PR_snprintf(buf, size, "%lld", mData);
|
PR_snprintf(buf, size, "%lld", mData);
|
||||||
|
|
||||||
*_retval = (char*) nsAllocator::Clone(buf,
|
char* result = (char*) nsAllocator::Clone(buf,
|
||||||
(nsCRT::strlen(buf)+1)*sizeof(char));
|
(nsCRT::strlen(buf)+1)*sizeof(char));
|
||||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -696,9 +709,10 @@ NS_IMETHODIMP nsSupportsFloatImpl::toString(char **_retval)
|
||||||
|
|
||||||
PR_snprintf(buf, size, "%f", (double) mData);
|
PR_snprintf(buf, size, "%f", (double) mData);
|
||||||
|
|
||||||
*_retval = (char*) nsAllocator::Clone(buf,
|
char* result = (char*) nsAllocator::Clone(buf,
|
||||||
(nsCRT::strlen(buf)+1)*sizeof(char));
|
(nsCRT::strlen(buf)+1)*sizeof(char));
|
||||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -742,9 +756,54 @@ NS_IMETHODIMP nsSupportsDoubleImpl::toString(char **_retval)
|
||||||
|
|
||||||
PR_snprintf(buf, size, "%f", mData);
|
PR_snprintf(buf, size, "%f", mData);
|
||||||
|
|
||||||
*_retval = (char*) nsAllocator::Clone(buf,
|
char* result = (char*) nsAllocator::Clone(buf,
|
||||||
(nsCRT::strlen(buf)+1)*sizeof(char));
|
(nsCRT::strlen(buf)+1)*sizeof(char));
|
||||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS(nsSupportsVoidImpl, NS_GET_IID(nsISupportsVoid))
|
||||||
|
|
||||||
|
nsSupportsVoidImpl::nsSupportsVoidImpl()
|
||||||
|
: mData(nsnull)
|
||||||
|
{
|
||||||
|
NS_INIT_ISUPPORTS();
|
||||||
|
}
|
||||||
|
|
||||||
|
nsSupportsVoidImpl::~nsSupportsVoidImpl() {}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsSupportsVoidImpl::GetData(const void * *aData)
|
||||||
|
{
|
||||||
|
if(!aData)
|
||||||
|
{
|
||||||
|
NS_ASSERTION(0,"Bad pointer");
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
*aData = mData;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsSupportsVoidImpl::SetData(void * aData)
|
||||||
|
{
|
||||||
|
mData = aData;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsSupportsVoidImpl::toString(char **_retval)
|
||||||
|
{
|
||||||
|
if(!_retval)
|
||||||
|
{
|
||||||
|
NS_ASSERTION(0,"Bad pointer");
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char str[] = "[raw data]";
|
||||||
|
char* result = (char*) nsAllocator::Clone(str, sizeof(str));
|
||||||
|
*_retval = result;
|
||||||
|
return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
|
@ -291,6 +291,22 @@ private:
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
||||||
|
class nsSupportsVoidImpl : public nsISupportsVoid
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
NS_IMETHOD GetData(const void * *aData);
|
||||||
|
NS_IMETHOD SetData(void * aData);
|
||||||
|
NS_IMETHOD toString(char **_retval);
|
||||||
|
|
||||||
|
nsSupportsVoidImpl();
|
||||||
|
virtual ~nsSupportsVoidImpl();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void* mData;
|
||||||
|
};
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
#endif /* nsSupportsPrimitives_h__ */
|
#endif /* nsSupportsPrimitives_h__ */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче