Backout bug 979445 due to clang build failures. CLOSED TREE

This commit is contained in:
Kyle Huey 2014-03-06 11:19:44 -08:00
Родитель e151bee907
Коммит 2ffecf71ae
9 изменённых файлов: 45 добавлений и 173 удалений

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

@ -21,7 +21,6 @@
#include "mozilla/dom/quota/FileStreams.h" #include "mozilla/dom/quota/FileStreams.h"
#include "mozilla/Endian.h" #include "mozilla/Endian.h"
#include "mozilla/storage.h" #include "mozilla/storage.h"
#include "nsAutoRef.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsDOMClassInfo.h" #include "nsDOMClassInfo.h"
#include "nsDOMFile.h" #include "nsDOMFile.h"
@ -3095,8 +3094,6 @@ NoRequestObjectStoreHelper::OnError()
mTransaction->Abort(GetResultCode()); mTransaction->Abort(GetResultCode());
} }
namespace {
// This is a duplicate of the js engine's byte munging in StructuredClone.cpp // This is a duplicate of the js engine's byte munging in StructuredClone.cpp
uint64_t uint64_t
ReinterpretDoubleAsUInt64(double d) ReinterpretDoubleAsUInt64(double d)
@ -3109,15 +3106,6 @@ ReinterpretDoubleAsUInt64(double d)
return pun.u; return pun.u;
} }
template <>
class nsAutoRefTraits<char> : public nsPointerRefTraits<char>
{
public:
static void Release(char* ptr) { moz_free(ptr); }
};
} // anonymous namespace
nsresult nsresult
AddHelper::DoDatabaseWork(mozIStorageConnection* aConnection) AddHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
{ {
@ -3194,30 +3182,28 @@ AddHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
mKey.BindToStatement(stmt, NS_LITERAL_CSTRING("key_value")); mKey.BindToStatement(stmt, NS_LITERAL_CSTRING("key_value"));
// Compress the bytes before adding into the database. // Compress the bytes before adding into the database.
const char* uncompressed = const char* uncompressed =
reinterpret_cast<const char*>(mCloneWriteInfo.mCloneBuffer.data()); reinterpret_cast<const char*>(mCloneWriteInfo.mCloneBuffer.data());
size_t uncompressedLength = mCloneWriteInfo.mCloneBuffer.nbytes(); size_t uncompressedLength = mCloneWriteInfo.mCloneBuffer.nbytes();
static const fallible_t fallible = fallible_t();
size_t compressedLength = snappy::MaxCompressedLength(uncompressedLength); size_t compressedLength = snappy::MaxCompressedLength(uncompressedLength);
// moz_malloc is equivalent to NS_Alloc, which we use because mozStorage // This will hold our compressed data until the end of the method. The
// expects to be able to free the adopted pointer with NS_Free. // BindBlobByName function will copy it.
nsAutoRef<char> compressed((char*)moz_malloc(compressedLength)); nsAutoArrayPtr<char> compressed(new (fallible) char[compressedLength]);
NS_ENSURE_TRUE(compressed, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(compressed, NS_ERROR_OUT_OF_MEMORY);
snappy::RawCompress(uncompressed, uncompressedLength, compressed, snappy::RawCompress(uncompressed, uncompressedLength, compressed.get(),
&compressedLength); &compressedLength);
uint8_t* dataBuffer = reinterpret_cast<uint8_t*>(compressed.get()); const uint8_t* dataBuffer =
reinterpret_cast<const uint8_t*>(compressed.get());
size_t dataBufferLength = compressedLength; size_t dataBufferLength = compressedLength;
// If this call succeeds, | compressed | is now owned by mozStorage, and we rv = stmt->BindBlobByName(NS_LITERAL_CSTRING("data"), dataBuffer,
// are no longer responsible for it. dataBufferLength);
rv = stmt->BindAdoptedBlobByName(NS_LITERAL_CSTRING("data"), dataBuffer,
dataBufferLength);
IDB_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); IDB_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
compressed.disown();
// Handle blobs // Handle blobs
uint32_t length = mCloneWriteInfo.mFiles.Length(); uint32_t length = mCloneWriteInfo.mFiles.Length();

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

@ -907,17 +907,21 @@ public:
rv = aArguments->GetSharedBlob(0, &uncompressedLength, &uncompressed); rv = aArguments->GetSharedBlob(0, &uncompressedLength, &uncompressed);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
static const fallible_t fallible = fallible_t();
size_t compressedLength = snappy::MaxCompressedLength(uncompressedLength); size_t compressedLength = snappy::MaxCompressedLength(uncompressedLength);
char* compressed = (char*)moz_malloc(compressedLength); nsAutoArrayPtr<char> compressed(new (fallible) char[compressedLength]);
NS_ENSURE_TRUE(compressed, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(compressed, NS_ERROR_OUT_OF_MEMORY);
snappy::RawCompress(reinterpret_cast<const char*>(uncompressed), snappy::RawCompress(reinterpret_cast<const char*>(uncompressed),
uncompressedLength, compressed, &compressedLength); uncompressedLength, compressed.get(),
&compressedLength);
std::pair<uint8_t *, int> data((uint8_t*)compressed, std::pair<const void *, int> data(static_cast<void*>(compressed.get()),
int(compressedLength)); int(compressedLength));
// The variant takes ownership of | compressed |.
nsCOMPtr<nsIVariant> result = new mozilla::storage::AdoptedBlobVariant(data); // XXX This copies the buffer again... There doesn't appear to be any way to
// preallocate space and write directly to a BlobVariant at the moment.
nsCOMPtr<nsIVariant> result = new mozilla::storage::BlobVariant(data);
result.forget(aResult); result.forget(aResult);
return NS_OK; return NS_OK;

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

@ -16,7 +16,7 @@
* consequently can cause the main thread to lock for extended intervals while * consequently can cause the main thread to lock for extended intervals while
* the asynchronous thread performs some long-running operation. * the asynchronous thread performs some long-running operation.
*/ */
[scriptable, uuid(52e49370-3b2e-4a27-a3fc-79e20ad4056b)] [scriptable, uuid(2400f64d-2cb3-49a9-b01e-f03cacb8aa6e)]
interface mozIStorageAsyncStatement : mozIStorageBaseStatement { interface mozIStorageAsyncStatement : mozIStorageBaseStatement {
/* /*
* 'params' provides a magic JS helper that lets you assign parameters by * 'params' provides a magic JS helper that lets you assign parameters by

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

@ -19,7 +19,7 @@ interface mozIStorageBindingParamsArray;
* (mozIStorageStatement) that can be used for both synchronous and asynchronous * (mozIStorageStatement) that can be used for both synchronous and asynchronous
* purposes. * purposes.
*/ */
[scriptable, uuid(5d34f333-ed3f-4aa2-ba51-f2a8b0cfa33a)] [scriptable, uuid(da2ec336-fbbb-4ba1-9778-8c9825980d01)]
interface mozIStorageBaseStatement : mozIStorageBindingParams { interface mozIStorageBaseStatement : mozIStorageBindingParams {
/** /**
* Finalizes a statement so you can successfully close a database connection. * Finalizes a statement so you can successfully close a database connection.
@ -67,10 +67,6 @@ interface mozIStorageBaseStatement : mozIStorageBindingParams {
in unsigned long aParamIndex, in unsigned long aParamIndex,
[array,const,size_is(aValueSize)] in octet aValue, [array,const,size_is(aValueSize)] in octet aValue,
in unsigned long aValueSize); in unsigned long aValueSize);
[deprecated] void bindAdoptedBlobParameter(
in unsigned long aParamIndex,
[array,size_is(aValueSize)] in octet aValue,
in unsigned long aValueSize);
/**@}*/ /**@}*/
/** /**

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

@ -8,7 +8,7 @@
interface nsIVariant; interface nsIVariant;
[scriptable, uuid(7d8763ad-79d9-4674-ada1-37fd702af68c)] [scriptable, uuid(a8d4827c-641c-45e3-a9ea-493570b4106b)]
interface mozIStorageBindingParams : nsISupports { interface mozIStorageBindingParams : nsISupports {
/** /**
* Binds aValue to the parameter with the name aName. * Binds aValue to the parameter with the name aName.
@ -34,13 +34,6 @@ interface mozIStorageBindingParams : nsISupports {
void bindBlobByName(in AUTF8String aName, void bindBlobByName(in AUTF8String aName,
[array, const, size_is(aValueSize)] in octet aValue, [array, const, size_is(aValueSize)] in octet aValue,
in unsigned long aValueSize); in unsigned long aValueSize);
// The function adopts the storage for the provided blob. After calling
// this function, mozStorage will ensure that NS_Free is called on the
// underlying pointer.
[noscript]
void bindAdoptedBlobByName(in AUTF8String aName,
[array, size_is(aValueSize)] in octet aValue,
in unsigned long aValueSize);
/** /**
* Binds aValue to the parameter with the index aIndex. * Binds aValue to the parameter with the index aIndex.
@ -66,11 +59,4 @@ interface mozIStorageBindingParams : nsISupports {
void bindBlobByIndex(in unsigned long aIndex, void bindBlobByIndex(in unsigned long aIndex,
[array, const, size_is(aValueSize)] in octet aValue, [array, const, size_is(aValueSize)] in octet aValue,
in unsigned long aValueSize); in unsigned long aValueSize);
// The function adopts the storage for the provided blob. After calling
// this function, mozStorage will ensure that NS_Free is called on the
// underlying pointer.
[noscript]
void bindAdoptedBlobByIndex(in unsigned long aIndex,
[array, size_is(aValueSize)] in octet aValue,
in unsigned long aValueSize);
}; };

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

@ -15,7 +15,7 @@
* A SQL statement that can be used for both synchronous and asynchronous * A SQL statement that can be used for both synchronous and asynchronous
* purposes. * purposes.
*/ */
[scriptable, uuid(b3c4476e-c490-4e3b-9db1-e2d3a6f0287c)] [scriptable, uuid(57ec7be1-36cf-4510-b938-7d1c9ee8cec5)]
interface mozIStorageStatement : mozIStorageBaseStatement { interface mozIStorageStatement : mozIStorageBaseStatement {
/** /**
* Create a clone of this statement, by initializing a new statement * Create a clone of this statement, by initializing a new statement

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

@ -319,15 +319,6 @@ NS_DEFINE_STATIC_IID_ACCESSOR(StorageBaseStatementInternal,
(uint32_t aWhere, \ (uint32_t aWhere, \
const uint8_t *aValue, \ const uint8_t *aValue, \
uint32_t aValueSize), \ uint32_t aValueSize), \
(aWhere, aValue, aValueSize)) \
BIND_GEN_IMPL(_class, _optionalGuard, \
AdoptedBlob, \
(const nsACString &aWhere, \
uint8_t *aValue, \
uint32_t aValueSize), \
(uint32_t aWhere, \
uint8_t *aValue, \
uint32_t aValueSize), \
(aWhere, aValue, aValueSize)) (aWhere, aValue, aValueSize))

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

@ -54,7 +54,7 @@ struct variant_traits
static inline uint16_t type() { return nsIDataType::VTYPE_EMPTY; } static inline uint16_t type() { return nsIDataType::VTYPE_EMPTY; }
}; };
template <typename DataType, bool Adopting=false> template <typename DataType>
struct variant_storage_traits struct variant_storage_traits
{ {
typedef DataType ConstructorType; typedef DataType ConstructorType;
@ -63,40 +63,37 @@ struct variant_storage_traits
{ {
*_storage = aData; *_storage = aData;
} }
static inline void destroy(const StorageType& _storage)
{ }
}; };
#define NO_CONVERSION return NS_ERROR_CANNOT_CONVERT_DATA; #define NO_CONVERSION return NS_ERROR_CANNOT_CONVERT_DATA;
template <typename DataType, bool Adopting=false> template <typename DataType>
struct variant_integer_traits struct variant_integer_traits
{ {
typedef typename variant_storage_traits<DataType, Adopting>::StorageType StorageType; typedef typename variant_storage_traits<DataType>::StorageType StorageType;
static inline nsresult asInt32(const StorageType &, int32_t *) { NO_CONVERSION } static inline nsresult asInt32(const StorageType &, int32_t *) { NO_CONVERSION }
static inline nsresult asInt64(const StorageType &, int64_t *) { NO_CONVERSION } static inline nsresult asInt64(const StorageType &, int64_t *) { NO_CONVERSION }
}; };
template <typename DataType, bool Adopting=false> template <typename DataType>
struct variant_float_traits struct variant_float_traits
{ {
typedef typename variant_storage_traits<DataType, Adopting>::StorageType StorageType; typedef typename variant_storage_traits<DataType>::StorageType StorageType;
static inline nsresult asDouble(const StorageType &, double *) { NO_CONVERSION } static inline nsresult asDouble(const StorageType &, double *) { NO_CONVERSION }
}; };
template <typename DataType, bool Adopting=false> template <typename DataType>
struct variant_text_traits struct variant_text_traits
{ {
typedef typename variant_storage_traits<DataType, Adopting>::StorageType StorageType; typedef typename variant_storage_traits<DataType>::StorageType StorageType;
static inline nsresult asUTF8String(const StorageType &, nsACString &) { NO_CONVERSION } static inline nsresult asUTF8String(const StorageType &, nsACString &) { NO_CONVERSION }
static inline nsresult asString(const StorageType &, nsAString &) { NO_CONVERSION } static inline nsresult asString(const StorageType &, nsAString &) { NO_CONVERSION }
}; };
template <typename DataType, bool Adopting=false> template <typename DataType>
struct variant_blob_traits struct variant_blob_traits
{ {
typedef typename variant_storage_traits<DataType, Adopting>::StorageType StorageType; typedef typename variant_storage_traits<DataType>::StorageType StorageType;
static inline nsresult asArray(const StorageType &, uint16_t *, uint32_t *, void **) static inline nsresult asArray(const StorageType &, uint16_t *, uint32_t *, void **)
{ NO_CONVERSION } { NO_CONVERSION }
}; };
@ -181,8 +178,6 @@ struct variant_storage_traits<nsString>
{ {
*_outData = aText; *_outData = aText;
} }
static inline void destroy(const StorageType& _outData)
{ }
}; };
template < > template < >
struct variant_text_traits<nsString> struct variant_text_traits<nsString>
@ -215,8 +210,6 @@ struct variant_storage_traits<nsCString>
{ {
*_outData = aText; *_outData = aText;
} }
static inline void destroy(const StorageType &aData)
{ }
}; };
template < > template < >
struct variant_text_traits<nsCString> struct variant_text_traits<nsCString>
@ -245,7 +238,7 @@ struct variant_traits<uint8_t[]>
static inline uint16_t type() { return nsIDataType::VTYPE_ARRAY; } static inline uint16_t type() { return nsIDataType::VTYPE_ARRAY; }
}; };
template < > template < >
struct variant_storage_traits<uint8_t[], false> struct variant_storage_traits<uint8_t[]>
{ {
typedef std::pair<const void *, int> ConstructorType; typedef std::pair<const void *, int> ConstructorType;
typedef FallibleTArray<uint8_t> StorageType; typedef FallibleTArray<uint8_t> StorageType;
@ -256,28 +249,9 @@ struct variant_storage_traits<uint8_t[], false>
(void)_outData->AppendElements(static_cast<const uint8_t *>(aBlob.first), (void)_outData->AppendElements(static_cast<const uint8_t *>(aBlob.first),
aBlob.second); aBlob.second);
} }
static inline void destroy(const StorageType& _outData)
{ }
}; };
template < > template < >
struct variant_storage_traits<uint8_t[], true> struct variant_blob_traits<uint8_t[]>
{
typedef std::pair<uint8_t *, int> ConstructorType;
typedef std::pair<uint8_t *, int> StorageType;
static inline void storage_conversion(ConstructorType aBlob, StorageType* _outData)
{
*_outData = aBlob;
}
static inline void destroy(StorageType &aData)
{
if (aData.first) {
NS_Free(aData.first);
aData.first = nullptr;
}
}
};
template < >
struct variant_blob_traits<uint8_t[], false>
{ {
static inline nsresult asArray(FallibleTArray<uint8_t> &aData, static inline nsresult asArray(FallibleTArray<uint8_t> &aData,
uint16_t *_type, uint16_t *_type,
@ -303,34 +277,6 @@ struct variant_blob_traits<uint8_t[], false>
} }
}; };
template < >
struct variant_blob_traits<uint8_t[], true>
{
static inline nsresult asArray(std::pair<uint8_t *, int> &aData,
uint16_t *_type,
uint32_t *_size,
void **_result)
{
// For empty blobs, we return nullptr.
if (aData.second == 0) {
*_result = nullptr;
*_type = nsIDataType::VTYPE_UINT8;
*_size = 0;
return NS_OK;
}
// Otherwise, transfer the data out.
*_result = aData.first;
aData.first = nullptr;
MOZ_ASSERT(*_result); // We asked for it twice, better not use adopting!
// Set type and size
*_type = nsIDataType::VTYPE_UINT8;
*_size = aData.second;
return NS_OK;
}
};
/** /**
* nullptr type * nullptr type
*/ */
@ -365,18 +311,13 @@ public:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//// Template Implementation //// Template Implementation
template <typename DataType, bool Adopting=false> template <typename DataType>
class Variant : public Variant_base class Variant : public Variant_base
{ {
~Variant()
{
variant_storage_traits<DataType, Adopting>::destroy(mData);
}
public: public:
Variant(const typename variant_storage_traits<DataType, Adopting>::ConstructorType aData) Variant(const typename variant_storage_traits<DataType>::ConstructorType aData)
{ {
variant_storage_traits<DataType, Adopting>::storage_conversion(aData, &mData); variant_storage_traits<DataType>::storage_conversion(aData, &mData);
} }
NS_IMETHOD GetDataType(uint16_t *_type) NS_IMETHOD GetDataType(uint16_t *_type)
@ -386,27 +327,27 @@ public:
} }
NS_IMETHOD GetAsInt32(int32_t *_integer) NS_IMETHOD GetAsInt32(int32_t *_integer)
{ {
return variant_integer_traits<DataType, Adopting>::asInt32(mData, _integer); return variant_integer_traits<DataType>::asInt32(mData, _integer);
} }
NS_IMETHOD GetAsInt64(int64_t *_integer) NS_IMETHOD GetAsInt64(int64_t *_integer)
{ {
return variant_integer_traits<DataType, Adopting>::asInt64(mData, _integer); return variant_integer_traits<DataType>::asInt64(mData, _integer);
} }
NS_IMETHOD GetAsDouble(double *_double) NS_IMETHOD GetAsDouble(double *_double)
{ {
return variant_float_traits<DataType, Adopting>::asDouble(mData, _double); return variant_float_traits<DataType>::asDouble(mData, _double);
} }
NS_IMETHOD GetAsAUTF8String(nsACString &_str) NS_IMETHOD GetAsAUTF8String(nsACString &_str)
{ {
return variant_text_traits<DataType, Adopting>::asUTF8String(mData, _str); return variant_text_traits<DataType>::asUTF8String(mData, _str);
} }
NS_IMETHOD GetAsAString(nsAString &_str) NS_IMETHOD GetAsAString(nsAString &_str)
{ {
return variant_text_traits<DataType, Adopting>::asString(mData, _str); return variant_text_traits<DataType>::asString(mData, _str);
} }
NS_IMETHOD GetAsArray(uint16_t *_type, NS_IMETHOD GetAsArray(uint16_t *_type,
@ -414,11 +355,11 @@ public:
uint32_t *_size, uint32_t *_size,
void **_data) void **_data)
{ {
return variant_blob_traits<DataType, Adopting>::asArray(mData, _type, _size, _data); return variant_blob_traits<DataType>::asArray(mData, _type, _size, _data);
} }
private: private:
typename variant_storage_traits<DataType, Adopting>::StorageType mData; typename variant_storage_traits<DataType>::StorageType mData;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -428,8 +369,7 @@ typedef Variant<int64_t> IntegerVariant;
typedef Variant<double> FloatVariant; typedef Variant<double> FloatVariant;
typedef Variant<nsString> TextVariant; typedef Variant<nsString> TextVariant;
typedef Variant<nsCString> UTF8TextVariant; typedef Variant<nsCString> UTF8TextVariant;
typedef Variant<uint8_t[], false> BlobVariant; typedef Variant<uint8_t[]> BlobVariant;
typedef Variant<uint8_t[], true> AdoptedBlobVariant;
} // namespace storage } // namespace storage
} // namespace mozilla } // namespace mozilla

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

@ -354,22 +354,6 @@ BindingParams::BindBlobByName(const nsACString &aName,
return BindByName(aName, value); return BindByName(aName, value);
} }
NS_IMETHODIMP
BindingParams::BindAdoptedBlobByName(const nsACString &aName,
uint8_t *aValue,
uint32_t aValueSize)
{
NS_ENSURE_ARG_MAX(aValueSize, INT_MAX);
std::pair<uint8_t *, int> data(
aValue,
int(aValueSize)
);
nsCOMPtr<nsIVariant> value(new AdoptedBlobVariant(data));
return BindByName(aName, value);
}
NS_IMETHODIMP NS_IMETHODIMP
BindingParams::BindByIndex(uint32_t aIndex, BindingParams::BindByIndex(uint32_t aIndex,
nsIVariant *aValue) nsIVariant *aValue)
@ -472,20 +456,5 @@ BindingParams::BindBlobByIndex(uint32_t aIndex,
return BindByIndex(aIndex, value); return BindByIndex(aIndex, value);
} }
NS_IMETHODIMP
BindingParams::BindAdoptedBlobByIndex(uint32_t aIndex,
uint8_t *aValue,
uint32_t aValueSize)
{
NS_ENSURE_ARG_MAX(aValueSize, INT_MAX);
std::pair<uint8_t *, int> data(
static_cast<uint8_t *>(aValue),
int(aValueSize)
);
nsCOMPtr<nsIVariant> value(new AdoptedBlobVariant(data));
return BindByIndex(aIndex, value);
}
} // namespace storage } // namespace storage
} // namespace mozilla } // namespace mozilla