Bug 1204403 - Fix -Wshadow warnings in xpcom. r=mccr8

This commit is contained in:
Chris Peterson 2015-09-07 23:56:16 -07:00
parent bfd0628cd5
commit 0dbaae1ce2
26 changed files with 215 additions and 187 deletions

View file

@ -144,13 +144,13 @@ public:
do { \ do { \
size_t amount = _amount; /* evaluate _amount only once */ \ size_t amount = _amount; /* evaluate _amount only once */ \
if (amount > 0) { \ if (amount > 0) { \
nsresult rv; \ nsresult rvReport; \
rv = aHandleReport->Callback(NS_LITERAL_CSTRING("System"), _path, \ rvReport = aHandleReport->Callback(NS_LITERAL_CSTRING("System"), _path, \
KIND_NONHEAP, _units, amount, _desc, \ KIND_NONHEAP, _units, amount, _desc, \
aData); \ aData); \
if (NS_WARN_IF(NS_FAILED(rv))) { \ if (NS_WARN_IF(NS_FAILED(rvReport))) { \
_cleanup; \ _cleanup; \
return rv; \ return rvReport; \
} \ } \
} \ } \
} while (0) } while (0)
@ -373,14 +373,15 @@ private:
char devMinor[17]; char devMinor[17];
unsigned int inode; unsigned int inode;
char line[1025]; char line[1025];
// This variable holds the path of the current entry, or is void // This variable holds the path of the current entry, or is void
// if we're scanning for the start of a new entry. // if we're scanning for the start of a new entry.
nsAutoCString path; nsAutoCString currentPath;
int pathOffset; int pathOffset;
path.SetIsVoid(true); currentPath.SetIsVoid(true);
while (fgets(line, sizeof(line), aFile)) { while (fgets(line, sizeof(line), aFile)) {
if (path.IsVoid()) { if (currentPath.IsVoid()) {
int n = sscanf(line, int n = sscanf(line,
"%llx-%llx %4s %llx " "%llx-%llx %4s %llx "
"%16[0-9a-fA-F]:%16[0-9a-fA-F] %u %n", "%16[0-9a-fA-F]:%16[0-9a-fA-F] %u %n",
@ -388,8 +389,8 @@ private:
devMinor, &inode, &pathOffset); devMinor, &inode, &pathOffset);
if (n >= argCount - 1) { if (n >= argCount - 1) {
path.Assign(line + pathOffset); currentPath.Assign(line + pathOffset);
path.StripChars("\n"); currentPath.StripChars("\n");
} }
continue; continue;
} }
@ -404,14 +405,14 @@ private:
size_t pss = pss_kb * 1024; size_t pss = pss_kb * 1024;
if (pss > 0) { if (pss > 0) {
nsAutoCString name, description, tag; nsAutoCString name, description, tag;
GetReporterNameAndDescription(path.get(), perms, name, description, tag); GetReporterNameAndDescription(currentPath.get(), perms, name, description, tag);
nsAutoCString path("mem/processes/"); nsAutoCString processMemPath("mem/processes/");
path.Append(aProcessName); processMemPath.Append(aProcessName);
path.Append('/'); processMemPath.Append('/');
path.Append(name); processMemPath.Append(name);
REPORT(path, pss, description); REPORT(processMemPath, pss, description);
// Increment the appropriate aProcessSizes values, and the total. // Increment the appropriate aProcessSizes values, and the total.
aProcessSizes->Add(tag, pss); aProcessSizes->Add(tag, pss);
@ -419,7 +420,7 @@ private:
} }
// Now that we've seen the PSS, we're done with this entry. // Now that we've seen the PSS, we're done with this entry.
path.SetIsVoid(true); currentPath.SetIsVoid(true);
} }
return NS_OK; return NS_OK;
} }

View file

@ -152,3 +152,6 @@ LOCAL_INCLUDES += [
if CONFIG['MOZ_WIDGET_GTK']: if CONFIG['MOZ_WIDGET_GTK']:
CXXFLAGS += CONFIG['TK_CFLAGS'] CXXFLAGS += CONFIG['TK_CFLAGS']
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']

View file

@ -78,9 +78,9 @@ NS_STATUS_REPORTER_IMPLEMENT(StatusReporter, "StatusReporter State", getStatus)
do { \ do { \
const char* s2 = (s); \ const char* s2 = (s); \
uint32_t dummy; \ uint32_t dummy; \
nsresult rv = (o)->Write((s2), strlen(s2), &dummy); \ nsresult rvDump = (o)->Write((s2), strlen(s2), &dummy); \
if (NS_WARN_IF(NS_FAILED(rv))) \ if (NS_WARN_IF(NS_FAILED(rvDump))) \
return rv; \ return rvDump; \
} while (0) } while (0)
static nsresult static nsresult

View file

@ -70,6 +70,7 @@ SOURCES += [
if CONFIG['GNU_CC']: if CONFIG['GNU_CC']:
CFLAGS += ['-Wshadow'] CFLAGS += ['-Wshadow']
CXXFLAGS += ['-Wshadow']
include('/ipc/chromium/chromium-config.mozbuild') include('/ipc/chromium/chromium-config.mozbuild')

View file

@ -100,3 +100,6 @@ LOCAL_INCLUDES += [
] ]
FINAL_LIBRARY = 'xul' FINAL_LIBRARY = 'xul'
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']

View file

@ -1016,9 +1016,9 @@ nsDiscriminatedUnion::ConvertToStringWithSize(uint32_t* aSize, char** aStr) cons
// *aSize = *mUTF8StringValue->Length(); // *aSize = *mUTF8StringValue->Length();
// *aStr = ToNewCString(*mUTF8StringValue); // *aStr = ToNewCString(*mUTF8StringValue);
// But this will have to do for now. // But this will have to do for now.
NS_ConvertUTF8toUTF16 tempString(*u.mUTF8StringValue); const NS_ConvertUTF8toUTF16 tempString16(*u.mUTF8StringValue);
*aSize = tempString.Length(); *aSize = tempString16.Length();
*aStr = ToNewCString(tempString); *aStr = ToNewCString(tempString16);
break; break;
} }
case nsIDataType::VTYPE_CHAR_STR: { case nsIDataType::VTYPE_CHAR_STR: {

View file

@ -50,17 +50,17 @@ GenericModule::RegisterSelf(nsIComponentManager* aCompMgr,
const char* aLoaderStr, const char* aLoaderStr,
const char* aType) const char* aType)
{ {
nsCOMPtr<nsIComponentRegistrar> r = do_QueryInterface(aCompMgr); nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(aCompMgr);
for (const Module::CIDEntry* e = mData->mCIDs; e->cid; ++e) { for (const Module::CIDEntry* e = mData->mCIDs; e->cid; ++e) {
r->RegisterFactoryLocation(*e->cid, "", nullptr, aLocation, registrar->RegisterFactoryLocation(*e->cid, "", nullptr, aLocation,
aLoaderStr, aType); aLoaderStr, aType);
} }
for (const Module::ContractIDEntry* e = mData->mContractIDs; for (const Module::ContractIDEntry* e = mData->mContractIDs;
e && e->contractid; e && e->contractid;
++e) { ++e) {
r->RegisterFactoryLocation(*e->cid, "", e->contractid, aLocation, registrar->RegisterFactoryLocation(*e->cid, "", e->contractid, aLocation,
aLoaderStr, aType); aLoaderStr, aType);
} }
nsCOMPtr<nsICategoryManager> catman; nsCOMPtr<nsICategoryManager> catman;
@ -71,9 +71,9 @@ GenericModule::RegisterSelf(nsIComponentManager* aCompMgr,
catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID); catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
} }
nsAutoCString r; nsAutoCString prevValue;
catman->AddCategoryEntry(e->category, e->entry, e->value, true, true, catman->AddCategoryEntry(e->category, e->entry, e->value, true, true,
getter_Copies(r)); getter_Copies(prevValue));
} }
return NS_OK; return NS_OK;
} }

View file

@ -120,3 +120,6 @@ USE_LIBS += [
NO_EXPAND_LIBS = True NO_EXPAND_LIBS = True
DIST_INSTALL = True DIST_INSTALL = True
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']

View file

@ -278,19 +278,19 @@ NS_IsAsciiDigit(char16_t aChar)
return aChar >= '0' && aChar <= '9'; return aChar >= '0' && aChar <= '9';
} }
#ifndef XPCOM_GLUE_AVOID_NSPR #ifndef XPCOM_GLUE_AVOID_NSPR
#define TABLE_SIZE 36
static const char table[] = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9'
};
void void
NS_MakeRandomString(char* aBuf, int32_t aBufLen) NS_MakeRandomString(char* aBuf, int32_t aBufLen)
{ {
#define TABLE_SIZE 36
static const char table[] = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9'
};
// turn PR_Now() into milliseconds since epoch // turn PR_Now() into milliseconds since epoch
// and salt rand with that. // and salt rand with that.
static unsigned int seed = 0; static unsigned int seed = 0;
@ -435,5 +435,3 @@ fprintf_stderr(FILE* aFile, const char* aFmt, ...)
} }
va_end(args); va_end(args);
} }

View file

@ -267,8 +267,8 @@ nsTArray_base<Alloc, Copy>::ShiftData(index_type aStart,
aStart *= aElemSize; aStart *= aElemSize;
aNewLen *= aElemSize; aNewLen *= aElemSize;
aOldLen *= aElemSize; aOldLen *= aElemSize;
char* base = reinterpret_cast<char*>(mHdr + 1) + aStart; char* baseAddr = reinterpret_cast<char*>(mHdr + 1) + aStart;
Copy::MoveElements(base + aNewLen, base + aOldLen, num, aElemSize); Copy::MoveElements(baseAddr + aNewLen, baseAddr + aOldLen, num, aElemSize);
} }
} }

View file

@ -289,20 +289,20 @@ TEST(ThreadUtils, main)
// Test legacy functions. // Test legacy functions.
nsCOMPtr<nsIRunnable> r = nsCOMPtr<nsIRunnable> r1 =
NS_NewRunnableMethod(rpt, &ThreadUtilsObject::Test0); NS_NewRunnableMethod(rpt, &ThreadUtilsObject::Test0);
r->Run(); r1->Run();
EXPECT_EQ(count += 1, rpt->mCount); EXPECT_EQ(count += 1, rpt->mCount);
r = NS_NewRunnableMethodWithArg<int>(rpt, &ThreadUtilsObject::Test1i, 11); r1 = NS_NewRunnableMethodWithArg<int>(rpt, &ThreadUtilsObject::Test1i, 11);
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(11, rpt->mA0); EXPECT_EQ(11, rpt->mA0);
// Test variadic function with simple POD arguments. // Test variadic function with simple POD arguments.
r = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test0); r1 = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test0);
r->Run(); r1->Run();
EXPECT_EQ(count += 1, rpt->mCount); EXPECT_EQ(count += 1, rpt->mCount);
static_assert( static_assert(
@ -314,29 +314,29 @@ TEST(ThreadUtils, main)
StoreCopyPassByValue<int>>::value, StoreCopyPassByValue<int>>::value,
"detail::ParameterStorage<StoreCopyPassByValue<int>>::Type should be StoreCopyPassByValue<int>"); "detail::ParameterStorage<StoreCopyPassByValue<int>>::Type should be StoreCopyPassByValue<int>");
r = NS_NewRunnableMethodWithArgs<int>(rpt, &ThreadUtilsObject::Test1i, 12); r1 = NS_NewRunnableMethodWithArgs<int>(rpt, &ThreadUtilsObject::Test1i, 12);
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(12, rpt->mA0); EXPECT_EQ(12, rpt->mA0);
r = NS_NewRunnableMethodWithArgs<int, int>( r1 = NS_NewRunnableMethodWithArgs<int, int>(
rpt, &ThreadUtilsObject::Test2i, 21, 22); rpt, &ThreadUtilsObject::Test2i, 21, 22);
r->Run(); r1->Run();
EXPECT_EQ(count += 3, rpt->mCount); EXPECT_EQ(count += 3, rpt->mCount);
EXPECT_EQ(21, rpt->mA0); EXPECT_EQ(21, rpt->mA0);
EXPECT_EQ(22, rpt->mA1); EXPECT_EQ(22, rpt->mA1);
r = NS_NewRunnableMethodWithArgs<int, int, int>( r1 = NS_NewRunnableMethodWithArgs<int, int, int>(
rpt, &ThreadUtilsObject::Test3i, 31, 32, 33); rpt, &ThreadUtilsObject::Test3i, 31, 32, 33);
r->Run(); r1->Run();
EXPECT_EQ(count += 4, rpt->mCount); EXPECT_EQ(count += 4, rpt->mCount);
EXPECT_EQ(31, rpt->mA0); EXPECT_EQ(31, rpt->mA0);
EXPECT_EQ(32, rpt->mA1); EXPECT_EQ(32, rpt->mA1);
EXPECT_EQ(33, rpt->mA2); EXPECT_EQ(33, rpt->mA2);
r = NS_NewRunnableMethodWithArgs<int, int, int, int>( r1 = NS_NewRunnableMethodWithArgs<int, int, int, int>(
rpt, &ThreadUtilsObject::Test4i, 41, 42, 43, 44); rpt, &ThreadUtilsObject::Test4i, 41, 42, 43, 44);
r->Run(); r1->Run();
EXPECT_EQ(count += 5, rpt->mCount); EXPECT_EQ(count += 5, rpt->mCount);
EXPECT_EQ(41, rpt->mA0); EXPECT_EQ(41, rpt->mA0);
EXPECT_EQ(42, rpt->mA1); EXPECT_EQ(42, rpt->mA1);
@ -347,8 +347,8 @@ TEST(ThreadUtils, main)
// Passing a short to make sure forwarding works with an inexact type match. // Passing a short to make sure forwarding works with an inexact type match.
short int si = 11; short int si = 11;
r = NS_NewRunnableMethodWithArgs<int>(rpt, &ThreadUtilsObject::Test1i, si); r1 = NS_NewRunnableMethodWithArgs<int>(rpt, &ThreadUtilsObject::Test1i, si);
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(si, rpt->mA0); EXPECT_EQ(si, rpt->mA0);
@ -373,8 +373,8 @@ TEST(ThreadUtils, main)
"detail::ParameterStorage<int*>::Type::passed_type should be int*"); "detail::ParameterStorage<int*>::Type::passed_type should be int*");
{ {
int i = 12; int i = 12;
r = NS_NewRunnableMethodWithArgs<int*>(rpt, &ThreadUtilsObject::Test1pi, &i); r1 = NS_NewRunnableMethodWithArgs<int*>(rpt, &ThreadUtilsObject::Test1pi, &i);
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(i, rpt->mA0); EXPECT_EQ(i, rpt->mA0);
} }
@ -400,8 +400,8 @@ TEST(ThreadUtils, main)
"detail::ParameterStorage<const int*>::Type::passed_type should be const int*"); "detail::ParameterStorage<const int*>::Type::passed_type should be const int*");
{ {
int i = 1201; int i = 1201;
r = NS_NewRunnableMethodWithArgs<const int*>(rpt, &ThreadUtilsObject::Test1pci, &i); r1 = NS_NewRunnableMethodWithArgs<const int*>(rpt, &ThreadUtilsObject::Test1pci, &i);
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(i, rpt->mA0); EXPECT_EQ(i, rpt->mA0);
} }
@ -415,9 +415,9 @@ TEST(ThreadUtils, main)
"StoreCopyPassByPtr<int>::passed_type should be int*"); "StoreCopyPassByPtr<int>::passed_type should be int*");
{ {
int i = 1202; int i = 1202;
r = NS_NewRunnableMethodWithArgs<StoreCopyPassByPtr<int>>( r1 = NS_NewRunnableMethodWithArgs<StoreCopyPassByPtr<int>>(
rpt, &ThreadUtilsObject::Test1pi, i); rpt, &ThreadUtilsObject::Test1pi, i);
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(i, rpt->mA0); EXPECT_EQ(i, rpt->mA0);
} }
@ -431,9 +431,9 @@ TEST(ThreadUtils, main)
"StoreCopyPassByConstPtr<int>::passed_type should be const int*"); "StoreCopyPassByConstPtr<int>::passed_type should be const int*");
{ {
int i = 1203; int i = 1203;
r = NS_NewRunnableMethodWithArgs<StoreCopyPassByConstPtr<int>>( r1 = NS_NewRunnableMethodWithArgs<StoreCopyPassByConstPtr<int>>(
rpt, &ThreadUtilsObject::Test1pci, i); rpt, &ThreadUtilsObject::Test1pci, i);
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(i, rpt->mA0); EXPECT_EQ(i, rpt->mA0);
} }
@ -491,8 +491,8 @@ TEST(ThreadUtils, main)
"ParameterStorage<int&>::Type::passed_type should be int&"); "ParameterStorage<int&>::Type::passed_type should be int&");
{ {
int i = 13; int i = 13;
r = NS_NewRunnableMethodWithArgs<int&>(rpt, &ThreadUtilsObject::Test1ri, i); r1 = NS_NewRunnableMethodWithArgs<int&>(rpt, &ThreadUtilsObject::Test1ri, i);
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(i, rpt->mA0); EXPECT_EQ(i, rpt->mA0);
} }
@ -512,10 +512,10 @@ TEST(ThreadUtils, main)
"ParameterStorage<int&&>::Type::passed_type should be int&&"); "ParameterStorage<int&&>::Type::passed_type should be int&&");
{ {
int i = 14; int i = 14;
r = NS_NewRunnableMethodWithArgs<int&&>( r1 = NS_NewRunnableMethodWithArgs<int&&>(
rpt, &ThreadUtilsObject::Test1rri, mozilla::Move(i)); rpt, &ThreadUtilsObject::Test1rri, mozilla::Move(i));
} }
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(14, rpt->mA0); EXPECT_EQ(14, rpt->mA0);
@ -534,10 +534,10 @@ TEST(ThreadUtils, main)
"ParameterStorage<UniquePtr<int>&&>::Type::passed_type should be UniquePtr<int>&&"); "ParameterStorage<UniquePtr<int>&&>::Type::passed_type should be UniquePtr<int>&&");
{ {
mozilla::UniquePtr<int> upi; mozilla::UniquePtr<int> upi;
r = NS_NewRunnableMethodWithArgs<mozilla::UniquePtr<int>&&>( r1 = NS_NewRunnableMethodWithArgs<mozilla::UniquePtr<int>&&>(
rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi));
} }
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(-1, rpt->mA0); EXPECT_EQ(-1, rpt->mA0);
rpt->mA0 = 0; rpt->mA0 = 0;
@ -557,48 +557,48 @@ TEST(ThreadUtils, main)
"ParameterStorage<StoreCopyPassByRRef<UniquePtr<int>>>::Type::passed_type should be UniquePtr<int>&&"); "ParameterStorage<StoreCopyPassByRRef<UniquePtr<int>>>::Type::passed_type should be UniquePtr<int>&&");
{ {
mozilla::UniquePtr<int> upi; mozilla::UniquePtr<int> upi;
r = NS_NewRunnableMethodWithArgs r1 = NS_NewRunnableMethodWithArgs
<StoreCopyPassByRRef<mozilla::UniquePtr<int>>>( <StoreCopyPassByRRef<mozilla::UniquePtr<int>>>(
rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi));
} }
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(-1, rpt->mA0); EXPECT_EQ(-1, rpt->mA0);
// Unique pointer as xvalue. // Unique pointer as xvalue.
{ {
mozilla::UniquePtr<int> upi = mozilla::MakeUnique<int>(1); mozilla::UniquePtr<int> upi = mozilla::MakeUnique<int>(1);
r = NS_NewRunnableMethodWithArgs<mozilla::UniquePtr<int>&&>( r1 = NS_NewRunnableMethodWithArgs<mozilla::UniquePtr<int>&&>(
rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi));
} }
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(1, rpt->mA0); EXPECT_EQ(1, rpt->mA0);
{ {
mozilla::UniquePtr<int> upi = mozilla::MakeUnique<int>(1); mozilla::UniquePtr<int> upi = mozilla::MakeUnique<int>(1);
r = NS_NewRunnableMethodWithArgs r1 = NS_NewRunnableMethodWithArgs
<StoreCopyPassByRRef<mozilla::UniquePtr<int>>> <StoreCopyPassByRRef<mozilla::UniquePtr<int>>>
(rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); (rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi));
} }
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(1, rpt->mA0); EXPECT_EQ(1, rpt->mA0);
// Unique pointer as prvalue. // Unique pointer as prvalue.
r = NS_NewRunnableMethodWithArgs<mozilla::UniquePtr<int>&&>( r1 = NS_NewRunnableMethodWithArgs<mozilla::UniquePtr<int>&&>(
rpt, &ThreadUtilsObject::Test1upi, mozilla::MakeUnique<int>(2)); rpt, &ThreadUtilsObject::Test1upi, mozilla::MakeUnique<int>(2));
r->Run(); r1->Run();
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(2, rpt->mA0); EXPECT_EQ(2, rpt->mA0);
// Unique pointer as lvalue to lref. // Unique pointer as lvalue to lref.
{ {
mozilla::UniquePtr<int> upi; mozilla::UniquePtr<int> upi;
r = NS_NewRunnableMethodWithArgs<mozilla::UniquePtr<int>&>( r1 = NS_NewRunnableMethodWithArgs<mozilla::UniquePtr<int>&>(
rpt, &ThreadUtilsObject::Test1rupi, upi); rpt, &ThreadUtilsObject::Test1rupi, upi);
// Passed as lref, so Run() must be called while local upi is still alive! // Passed as lref, so Run() must be called while local upi is still alive!
r->Run(); r1->Run();
} }
EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(-1, rpt->mA0); EXPECT_EQ(-1, rpt->mA0);
@ -608,15 +608,15 @@ TEST(ThreadUtils, main)
Spy::ClearAll(); Spy::ClearAll();
if (gDebug) { printf("%d - Test: Store copy from lvalue, pass by value\n", __LINE__); } if (gDebug) { printf("%d - Test: Store copy from lvalue, pass by value\n", __LINE__); }
{ // Block around nsCOMPtr lifetime. { // Block around nsCOMPtr lifetime.
nsCOMPtr<nsIRunnable> r; nsCOMPtr<nsIRunnable> r2;
{ // Block around Spy lifetime. { // Block around Spy lifetime.
if (gDebug) { printf("%d - Spy s(10)\n", __LINE__); } if (gDebug) { printf("%d - Spy s(10)\n", __LINE__); }
Spy s(10); Spy s(10);
EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gConstructions);
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs<StoreCopyPassByValue<Spy>>(&TestByValue, s)\n", __LINE__); } if (gDebug) { printf("%d - r2 = NS_NewRunnableMethodWithArgs<StoreCopyPassByValue<Spy>>(&TestByValue, s)\n", __LINE__); }
r = NS_NewRunnableMethodWithArgs<StoreCopyPassByValue<Spy>>( r2 = NS_NewRunnableMethodWithArgs<StoreCopyPassByValue<Spy>>(
rpt, &ThreadUtilsObject::TestByValue, s); rpt, &ThreadUtilsObject::TestByValue, s);
EXPECT_EQ(2, gAlive); EXPECT_EQ(2, gAlive);
EXPECT_LE(1, gCopyConstructions); // At least 1 copy-construction. EXPECT_LE(1, gCopyConstructions); // At least 1 copy-construction.
Spy::ClearActions(); Spy::ClearActions();
@ -626,7 +626,7 @@ TEST(ThreadUtils, main)
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
Spy::ClearActions(); Spy::ClearActions();
if (gDebug) { printf("%d - Run()\n", __LINE__); } if (gDebug) { printf("%d - Run()\n", __LINE__); }
r->Run(); r2->Run();
EXPECT_LE(1, gCopyConstructions); // Another copy-construction in call. EXPECT_LE(1, gCopyConstructions); // Another copy-construction in call.
EXPECT_EQ(10, rpt->mSpy.mID); EXPECT_EQ(10, rpt->mSpy.mID);
EXPECT_LE(1, gDestructions); EXPECT_LE(1, gDestructions);
@ -641,8 +641,8 @@ TEST(ThreadUtils, main)
Spy::ClearAll(); Spy::ClearAll();
if (gDebug) { printf("%d - Test: Store copy from prvalue, pass by value\n", __LINE__); } if (gDebug) { printf("%d - Test: Store copy from prvalue, pass by value\n", __LINE__); }
{ {
if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs<StoreCopyPassByValue<Spy>>(&TestByValue, Spy(11))\n", __LINE__); } if (gDebug) { printf("%d - r3 = NS_NewRunnableMethodWithArgs<StoreCopyPassByValue<Spy>>(&TestByValue, Spy(11))\n", __LINE__); }
nsCOMPtr<nsIRunnable> r = nsCOMPtr<nsIRunnable> r3 =
NS_NewRunnableMethodWithArgs<StoreCopyPassByValue<Spy>>( NS_NewRunnableMethodWithArgs<StoreCopyPassByValue<Spy>>(
rpt, &ThreadUtilsObject::TestByValue, Spy(11)); rpt, &ThreadUtilsObject::TestByValue, Spy(11));
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
@ -650,7 +650,7 @@ TEST(ThreadUtils, main)
EXPECT_LE(1, gMoveConstructions); EXPECT_LE(1, gMoveConstructions);
Spy::ClearActions(); Spy::ClearActions();
if (gDebug) { printf("%d - Run()\n", __LINE__); } if (gDebug) { printf("%d - Run()\n", __LINE__); }
r->Run(); r3->Run();
EXPECT_LE(1, gCopyConstructions); // Another copy-construction in call. EXPECT_LE(1, gCopyConstructions); // Another copy-construction in call.
EXPECT_EQ(11, rpt->mSpy.mID); EXPECT_EQ(11, rpt->mSpy.mID);
EXPECT_LE(1, gDestructions); EXPECT_LE(1, gDestructions);
@ -664,13 +664,13 @@ TEST(ThreadUtils, main)
Spy::ClearAll(); Spy::ClearAll();
{ // Store copy from xvalue, pass by value. { // Store copy from xvalue, pass by value.
nsCOMPtr<nsIRunnable> r; nsCOMPtr<nsIRunnable> r4;
{ {
Spy s(12); Spy s(12);
EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gConstructions);
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
Spy::ClearActions(); Spy::ClearActions();
r = NS_NewRunnableMethodWithArgs<StoreCopyPassByValue<Spy>>( r4 = NS_NewRunnableMethodWithArgs<StoreCopyPassByValue<Spy>>(
rpt, &ThreadUtilsObject::TestByValue, mozilla::Move(s)); rpt, &ThreadUtilsObject::TestByValue, mozilla::Move(s));
EXPECT_LE(1, gMoveConstructions); EXPECT_LE(1, gMoveConstructions);
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
@ -681,7 +681,7 @@ TEST(ThreadUtils, main)
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
EXPECT_EQ(0, gZombies); EXPECT_EQ(0, gZombies);
Spy::ClearActions(); Spy::ClearActions();
r->Run(); r4->Run();
EXPECT_LE(1, gCopyConstructions); // Another copy-construction in call. EXPECT_LE(1, gCopyConstructions); // Another copy-construction in call.
EXPECT_EQ(12, rpt->mSpy.mID); EXPECT_EQ(12, rpt->mSpy.mID);
EXPECT_LE(1, gDestructions); EXPECT_LE(1, gDestructions);
@ -695,15 +695,15 @@ TEST(ThreadUtils, main)
Spy::ClearAll(); Spy::ClearAll();
if (gDebug) { printf("%d - Test: Store copy from lvalue, pass by const lvalue ref\n", __LINE__); } if (gDebug) { printf("%d - Test: Store copy from lvalue, pass by const lvalue ref\n", __LINE__); }
{ // Block around nsCOMPtr lifetime. { // Block around nsCOMPtr lifetime.
nsCOMPtr<nsIRunnable> r; nsCOMPtr<nsIRunnable> r5;
{ // Block around Spy lifetime. { // Block around Spy lifetime.
if (gDebug) { printf("%d - Spy s(20)\n", __LINE__); } if (gDebug) { printf("%d - Spy s(20)\n", __LINE__); }
Spy s(20); Spy s(20);
EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gConstructions);
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs<StoreCopyPassByConstLRef<Spy>>(&TestByConstLRef, s)\n", __LINE__); } if (gDebug) { printf("%d - r5 = NS_NewRunnableMethodWithArgs<StoreCopyPassByConstLRef<Spy>>(&TestByConstLRef, s)\n", __LINE__); }
r = NS_NewRunnableMethodWithArgs<StoreCopyPassByConstLRef<Spy>>( r5 = NS_NewRunnableMethodWithArgs<StoreCopyPassByConstLRef<Spy>>(
rpt, &ThreadUtilsObject::TestByConstLRef, s); rpt, &ThreadUtilsObject::TestByConstLRef, s);
EXPECT_EQ(2, gAlive); EXPECT_EQ(2, gAlive);
EXPECT_LE(1, gCopyConstructions); // At least 1 copy-construction. EXPECT_LE(1, gCopyConstructions); // At least 1 copy-construction.
Spy::ClearActions(); Spy::ClearActions();
@ -713,7 +713,7 @@ TEST(ThreadUtils, main)
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
Spy::ClearActions(); Spy::ClearActions();
if (gDebug) { printf("%d - Run()\n", __LINE__); } if (gDebug) { printf("%d - Run()\n", __LINE__); }
r->Run(); r5->Run();
EXPECT_EQ(0, gCopyConstructions); // No copies in call. EXPECT_EQ(0, gCopyConstructions); // No copies in call.
EXPECT_EQ(20, rpt->mSpy.mID); EXPECT_EQ(20, rpt->mSpy.mID);
EXPECT_EQ(0, gDestructions); EXPECT_EQ(0, gDestructions);
@ -728,8 +728,8 @@ TEST(ThreadUtils, main)
Spy::ClearAll(); Spy::ClearAll();
if (gDebug) { printf("%d - Test: Store copy from prvalue, pass by const lvalue ref\n", __LINE__); } if (gDebug) { printf("%d - Test: Store copy from prvalue, pass by const lvalue ref\n", __LINE__); }
{ {
if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs<StoreCopyPassByConstLRef<Spy>>(&TestByConstLRef, Spy(21))\n", __LINE__); } if (gDebug) { printf("%d - r6 = NS_NewRunnableMethodWithArgs<StoreCopyPassByConstLRef<Spy>>(&TestByConstLRef, Spy(21))\n", __LINE__); }
nsCOMPtr<nsIRunnable> r = nsCOMPtr<nsIRunnable> r6 =
NS_NewRunnableMethodWithArgs<StoreCopyPassByConstLRef<Spy>>( NS_NewRunnableMethodWithArgs<StoreCopyPassByConstLRef<Spy>>(
rpt, &ThreadUtilsObject::TestByConstLRef, Spy(21)); rpt, &ThreadUtilsObject::TestByConstLRef, Spy(21));
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
@ -737,7 +737,7 @@ TEST(ThreadUtils, main)
EXPECT_LE(1, gMoveConstructions); EXPECT_LE(1, gMoveConstructions);
Spy::ClearActions(); Spy::ClearActions();
if (gDebug) { printf("%d - Run()\n", __LINE__); } if (gDebug) { printf("%d - Run()\n", __LINE__); }
r->Run(); r6->Run();
EXPECT_EQ(0, gCopyConstructions); // No copies in call. EXPECT_EQ(0, gCopyConstructions); // No copies in call.
EXPECT_EQ(21, rpt->mSpy.mID); EXPECT_EQ(21, rpt->mSpy.mID);
EXPECT_EQ(0, gDestructions); EXPECT_EQ(0, gDestructions);
@ -752,15 +752,15 @@ TEST(ThreadUtils, main)
Spy::ClearAll(); Spy::ClearAll();
if (gDebug) { printf("%d - Test: Store copy from lvalue, pass by rvalue ref\n", __LINE__); } if (gDebug) { printf("%d - Test: Store copy from lvalue, pass by rvalue ref\n", __LINE__); }
{ // Block around nsCOMPtr lifetime. { // Block around nsCOMPtr lifetime.
nsCOMPtr<nsIRunnable> r; nsCOMPtr<nsIRunnable> r7;
{ // Block around Spy lifetime. { // Block around Spy lifetime.
if (gDebug) { printf("%d - Spy s(30)\n", __LINE__); } if (gDebug) { printf("%d - Spy s(30)\n", __LINE__); }
Spy s(30); Spy s(30);
EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gConstructions);
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs<StoreCopyPassByRRef<Spy>>(&TestByRRef, s)\n", __LINE__); } if (gDebug) { printf("%d - r7 = NS_NewRunnableMethodWithArgs<StoreCopyPassByRRef<Spy>>(&TestByRRef, s)\n", __LINE__); }
r = NS_NewRunnableMethodWithArgs<StoreCopyPassByRRef<Spy>>( r7 = NS_NewRunnableMethodWithArgs<StoreCopyPassByRRef<Spy>>(
rpt, &ThreadUtilsObject::TestByRRef, s); rpt, &ThreadUtilsObject::TestByRRef, s);
EXPECT_EQ(2, gAlive); EXPECT_EQ(2, gAlive);
EXPECT_LE(1, gCopyConstructions); // At least 1 copy-construction. EXPECT_LE(1, gCopyConstructions); // At least 1 copy-construction.
Spy::ClearActions(); Spy::ClearActions();
@ -770,7 +770,7 @@ TEST(ThreadUtils, main)
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
Spy::ClearActions(); Spy::ClearActions();
if (gDebug) { printf("%d - Run()\n", __LINE__); } if (gDebug) { printf("%d - Run()\n", __LINE__); }
r->Run(); r7->Run();
EXPECT_LE(1, gMoves); // Move in call. EXPECT_LE(1, gMoves); // Move in call.
EXPECT_EQ(30, rpt->mSpy.mID); EXPECT_EQ(30, rpt->mSpy.mID);
EXPECT_EQ(0, gDestructions); EXPECT_EQ(0, gDestructions);
@ -786,8 +786,8 @@ TEST(ThreadUtils, main)
Spy::ClearAll(); Spy::ClearAll();
if (gDebug) { printf("%d - Test: Store copy from prvalue, pass by rvalue ref\n", __LINE__); } if (gDebug) { printf("%d - Test: Store copy from prvalue, pass by rvalue ref\n", __LINE__); }
{ {
if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs<StoreCopyPassByRRef<Spy>>(&TestByRRef, Spy(31))\n", __LINE__); } if (gDebug) { printf("%d - r8 = NS_NewRunnableMethodWithArgs<StoreCopyPassByRRef<Spy>>(&TestByRRef, Spy(31))\n", __LINE__); }
nsCOMPtr<nsIRunnable> r = nsCOMPtr<nsIRunnable> r8 =
NS_NewRunnableMethodWithArgs<StoreCopyPassByRRef<Spy>>( NS_NewRunnableMethodWithArgs<StoreCopyPassByRRef<Spy>>(
rpt, &ThreadUtilsObject::TestByRRef, Spy(31)); rpt, &ThreadUtilsObject::TestByRRef, Spy(31));
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
@ -795,7 +795,7 @@ TEST(ThreadUtils, main)
EXPECT_LE(1, gMoveConstructions); EXPECT_LE(1, gMoveConstructions);
Spy::ClearActions(); Spy::ClearActions();
if (gDebug) { printf("%d - Run()\n", __LINE__); } if (gDebug) { printf("%d - Run()\n", __LINE__); }
r->Run(); r8->Run();
EXPECT_LE(1, gMoves); // Move in call. EXPECT_LE(1, gMoves); // Move in call.
EXPECT_EQ(31, rpt->mSpy.mID); EXPECT_EQ(31, rpt->mSpy.mID);
EXPECT_EQ(0, gDestructions); EXPECT_EQ(0, gDestructions);
@ -816,8 +816,8 @@ TEST(ThreadUtils, main)
EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gConstructions);
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
Spy::ClearActions(); Spy::ClearActions();
if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs<Spy&>(&TestByLRef, s)\n", __LINE__); } if (gDebug) { printf("%d - r9 = NS_NewRunnableMethodWithArgs<Spy&>(&TestByLRef, s)\n", __LINE__); }
nsCOMPtr<nsIRunnable> r = nsCOMPtr<nsIRunnable> r9 =
NS_NewRunnableMethodWithArgs<Spy&>( NS_NewRunnableMethodWithArgs<Spy&>(
rpt, &ThreadUtilsObject::TestByLRef, s); rpt, &ThreadUtilsObject::TestByLRef, s);
EXPECT_EQ(0, gAllConstructions); EXPECT_EQ(0, gAllConstructions);
@ -825,7 +825,7 @@ TEST(ThreadUtils, main)
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
Spy::ClearActions(); Spy::ClearActions();
if (gDebug) { printf("%d - Run()\n", __LINE__); } if (gDebug) { printf("%d - Run()\n", __LINE__); }
r->Run(); r9->Run();
EXPECT_LE(1, gAssignments); // Assignment from reference in call. EXPECT_LE(1, gAssignments); // Assignment from reference in call.
EXPECT_EQ(40, rpt->mSpy.mID); EXPECT_EQ(40, rpt->mSpy.mID);
EXPECT_EQ(&s, rpt->mSpyPtr); EXPECT_EQ(&s, rpt->mSpyPtr);
@ -841,7 +841,7 @@ TEST(ThreadUtils, main)
Spy::ClearAll(); Spy::ClearAll();
if (gDebug) { printf("%d - Test: Store nsRefPtr, pass by pointer\n", __LINE__); } if (gDebug) { printf("%d - Test: Store nsRefPtr, pass by pointer\n", __LINE__); }
{ // Block around nsCOMPtr lifetime. { // Block around nsCOMPtr lifetime.
nsCOMPtr<nsIRunnable> r; nsCOMPtr<nsIRunnable> r10;
SpyWithISupports* ptr = 0; SpyWithISupports* ptr = 0;
{ // Block around nsRefPtr<Spy> lifetime. { // Block around nsRefPtr<Spy> lifetime.
if (gDebug) { printf("%d - nsRefPtr<SpyWithISupports> s(new SpyWithISupports(45))\n", __LINE__); } if (gDebug) { printf("%d - nsRefPtr<SpyWithISupports> s(new SpyWithISupports(45))\n", __LINE__); }
@ -849,9 +849,9 @@ TEST(ThreadUtils, main)
ptr = s.get(); ptr = s.get();
EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gConstructions);
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs<StorensRefPtrPassByPtr<Spy>>(&TestByRRef, s.get())\n", __LINE__); } if (gDebug) { printf("%d - r10 = NS_NewRunnableMethodWithArgs<StorensRefPtrPassByPtr<Spy>>(&TestByRRef, s.get())\n", __LINE__); }
r = NS_NewRunnableMethodWithArgs<StorensRefPtrPassByPtr<SpyWithISupports>>( r10 = NS_NewRunnableMethodWithArgs<StorensRefPtrPassByPtr<SpyWithISupports>>(
rpt, &ThreadUtilsObject::TestByPointer, s.get()); rpt, &ThreadUtilsObject::TestByPointer, s.get());
EXPECT_LE(0, gAllConstructions); EXPECT_LE(0, gAllConstructions);
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
Spy::ClearActions(); Spy::ClearActions();
@ -861,7 +861,7 @@ TEST(ThreadUtils, main)
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
Spy::ClearActions(); Spy::ClearActions();
if (gDebug) { printf("%d - Run()\n", __LINE__); } if (gDebug) { printf("%d - Run()\n", __LINE__); }
r->Run(); r10->Run();
EXPECT_LE(1, gAssignments); // Assignment from pointee in call. EXPECT_LE(1, gAssignments); // Assignment from pointee in call.
EXPECT_EQ(45, rpt->mSpy.mID); EXPECT_EQ(45, rpt->mSpy.mID);
EXPECT_EQ(ptr, rpt->mSpyPtr); EXPECT_EQ(ptr, rpt->mSpyPtr);
@ -882,8 +882,8 @@ TEST(ThreadUtils, main)
EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gConstructions);
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
Spy::ClearActions(); Spy::ClearActions();
if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs<Spy*>(&TestByPointer, s)\n", __LINE__); } if (gDebug) { printf("%d - r11 = NS_NewRunnableMethodWithArgs<Spy*>(&TestByPointer, s)\n", __LINE__); }
nsCOMPtr<nsIRunnable> r = nsCOMPtr<nsIRunnable> r11 =
NS_NewRunnableMethodWithArgs<Spy*>( NS_NewRunnableMethodWithArgs<Spy*>(
rpt, &ThreadUtilsObject::TestByPointer, &s); rpt, &ThreadUtilsObject::TestByPointer, &s);
EXPECT_EQ(0, gAllConstructions); EXPECT_EQ(0, gAllConstructions);
@ -891,7 +891,7 @@ TEST(ThreadUtils, main)
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
Spy::ClearActions(); Spy::ClearActions();
if (gDebug) { printf("%d - Run()\n", __LINE__); } if (gDebug) { printf("%d - Run()\n", __LINE__); }
r->Run(); r11->Run();
EXPECT_LE(1, gAssignments); // Assignment from pointee in call. EXPECT_LE(1, gAssignments); // Assignment from pointee in call.
EXPECT_EQ(55, rpt->mSpy.mID); EXPECT_EQ(55, rpt->mSpy.mID);
EXPECT_EQ(&s, rpt->mSpyPtr); EXPECT_EQ(&s, rpt->mSpyPtr);
@ -912,8 +912,8 @@ TEST(ThreadUtils, main)
EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gConstructions);
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
Spy::ClearActions(); Spy::ClearActions();
if (gDebug) { printf("%d - r = NS_NewRunnableMethodWithArgs<Spy*>(&TestByPointer, s)\n", __LINE__); } if (gDebug) { printf("%d - r12 = NS_NewRunnableMethodWithArgs<Spy*>(&TestByPointer, s)\n", __LINE__); }
nsCOMPtr<nsIRunnable> r = nsCOMPtr<nsIRunnable> r12 =
NS_NewRunnableMethodWithArgs<const Spy*>( NS_NewRunnableMethodWithArgs<const Spy*>(
rpt, &ThreadUtilsObject::TestByPointerToConst, &s); rpt, &ThreadUtilsObject::TestByPointerToConst, &s);
EXPECT_EQ(0, gAllConstructions); EXPECT_EQ(0, gAllConstructions);
@ -921,7 +921,7 @@ TEST(ThreadUtils, main)
EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gAlive);
Spy::ClearActions(); Spy::ClearActions();
if (gDebug) { printf("%d - Run()\n", __LINE__); } if (gDebug) { printf("%d - Run()\n", __LINE__); }
r->Run(); r12->Run();
EXPECT_LE(1, gAssignments); // Assignment from pointee in call. EXPECT_LE(1, gAssignments); // Assignment from pointee in call.
EXPECT_EQ(60, rpt->mSpy.mID); EXPECT_EQ(60, rpt->mSpy.mID);
EXPECT_EQ(&s, rpt->mSpyPtr); EXPECT_EQ(&s, rpt->mSpyPtr);

View file

@ -125,6 +125,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
if CONFIG['GNU_CC']: if CONFIG['GNU_CC']:
CFLAGS += ['-Wshadow'] CFLAGS += ['-Wshadow']
CXXFLAGS += ['-Wshadow']
include('/ipc/chromium/chromium-config.mozbuild') include('/ipc/chromium/chromium-config.mozbuild')

View file

@ -12,7 +12,8 @@
#include "nsCRT.h" #include "nsCRT.h"
#include "plstr.h" #include "plstr.h"
static const char hexChars[] = "0123456789ABCDEF"; static const char hexCharsUpper[] = "0123456789ABCDEF";
static const char hexCharsUpperLower[] = "0123456789ABCDEFabcdef";
static const int netCharType[256] = static const int netCharType[256] =
/* Bit 0 xalpha -- the alphas /* Bit 0 xalpha -- the alphas
@ -51,8 +52,8 @@ AppendPercentHex(char* aBuffer, unsigned char aChar)
{ {
uint32_t i = 0; uint32_t i = 0;
aBuffer[i++] = '%'; aBuffer[i++] = '%';
aBuffer[i++] = hexChars[aChar >> 4]; // high nibble aBuffer[i++] = hexCharsUpper[aChar >> 4]; // high nibble
aBuffer[i++] = hexChars[aChar & 0xF]; // low nibble aBuffer[i++] = hexCharsUpper[aChar & 0xF]; // low nibble
return i; return i;
} }
@ -63,11 +64,11 @@ AppendPercentHex(char16_t* aBuffer, char16_t aChar)
aBuffer[i++] = '%'; aBuffer[i++] = '%';
if (aChar & 0xff00) { if (aChar & 0xff00) {
aBuffer[i++] = 'u'; aBuffer[i++] = 'u';
aBuffer[i++] = hexChars[aChar >> 12]; // high-byte high nibble aBuffer[i++] = hexCharsUpper[aChar >> 12]; // high-byte high nibble
aBuffer[i++] = hexChars[(aChar >> 8) & 0xF]; // high-byte low nibble aBuffer[i++] = hexCharsUpper[(aChar >> 8) & 0xF]; // high-byte low nibble
} }
aBuffer[i++] = hexChars[(aChar >> 4) & 0xF]; // low-byte high nibble aBuffer[i++] = hexCharsUpper[(aChar >> 4) & 0xF]; // low-byte high nibble
aBuffer[i++] = hexChars[aChar & 0xF]; // low-byte low nibble aBuffer[i++] = hexCharsUpper[aChar & 0xF]; // low-byte low nibble
return i; return i;
} }
@ -124,8 +125,8 @@ nsEscapeCount(const char* aStr, nsEscapeMask aFlags, size_t* aOutLen)
*dst++ = '+'; /* convert spaces to pluses */ *dst++ = '+'; /* convert spaces to pluses */
} else { } else {
*dst++ = HEX_ESCAPE; *dst++ = HEX_ESCAPE;
*dst++ = hexChars[c >> 4]; /* high nibble */ *dst++ = hexCharsUpper[c >> 4]; /* high nibble */
*dst++ = hexChars[c & 0x0f]; /* low nibble */ *dst++ = hexCharsUpper[c & 0x0f]; /* low nibble */
} }
} }
} else { } else {
@ -135,8 +136,8 @@ nsEscapeCount(const char* aStr, nsEscapeMask aFlags, size_t* aOutLen)
*dst++ = c; *dst++ = c;
} else { } else {
*dst++ = HEX_ESCAPE; *dst++ = HEX_ESCAPE;
*dst++ = hexChars[c >> 4]; /* high nibble */ *dst++ = hexCharsUpper[c >> 4]; /* high nibble */
*dst++ = hexChars[c & 0x0f]; /* low nibble */ *dst++ = hexCharsUpper[c & 0x0f]; /* low nibble */
} }
} }
} }
@ -175,7 +176,6 @@ nsUnescapeCount(char* aStr)
{ {
char* src = aStr; char* src = aStr;
char* dst = aStr; char* dst = aStr;
static const char hexChars[] = "0123456789ABCDEFabcdef";
char c1[] = " "; char c1[] = " ";
char c2[] = " "; char c2[] = " ";
@ -197,8 +197,8 @@ nsUnescapeCount(char* aStr)
c2[0] = *(src + 2); c2[0] = *(src + 2);
} }
if (*src != HEX_ESCAPE || PL_strpbrk(pc1, hexChars) == 0 || if (*src != HEX_ESCAPE || PL_strpbrk(pc1, hexCharsUpperLower) == 0 ||
PL_strpbrk(pc2, hexChars) == 0) { PL_strpbrk(pc2, hexCharsUpperLower) == 0) {
*dst++ = *src++; *dst++ = *src++;
} else { } else {
src++; /* walk over escape */ src++; /* walk over escape */
@ -498,7 +498,7 @@ NS_EscapeURL(const nsAFlatString& aStr, const nsTArray<char16_t>& aForbidden,
nsSubstring& aResult) nsSubstring& aResult)
{ {
bool didEscape = false; bool didEscape = false;
for (size_t i = 0, len = aStr.Length(); i < len; ) { for (size_t i = 0, strLen = aStr.Length(); i < strLen; ) {
size_t j; size_t j;
if (MOZ_UNLIKELY(FindFirstMatchFrom(aStr, i, aForbidden, &j))) { if (MOZ_UNLIKELY(FindFirstMatchFrom(aStr, i, aForbidden, &j))) {
if (i == 0) { if (i == 0) {
@ -511,14 +511,14 @@ NS_EscapeURL(const nsAFlatString& aStr, const nsTArray<char16_t>& aForbidden,
aResult.Append(nsDependentSubstring(aStr, i, j - i)); aResult.Append(nsDependentSubstring(aStr, i, j - i));
} }
char16_t buffer[ENCODE_MAX_LEN]; char16_t buffer[ENCODE_MAX_LEN];
uint32_t len = ::AppendPercentHex(buffer, aStr[j]); uint32_t bufferLen = ::AppendPercentHex(buffer, aStr[j]);
MOZ_ASSERT(len <= ENCODE_MAX_LEN, "buffer overflow"); MOZ_ASSERT(bufferLen <= ENCODE_MAX_LEN, "buffer overflow");
aResult.Append(buffer, len); aResult.Append(buffer, bufferLen);
i = j + 1; i = j + 1;
} else { } else {
if (MOZ_UNLIKELY(didEscape)) { if (MOZ_UNLIKELY(didEscape)) {
// The tail of the string that needs no escaping. // The tail of the string that needs no escaping.
aResult.Append(nsDependentSubstring(aStr, i, len - i)); aResult.Append(nsDependentSubstring(aStr, i, strLen - i));
} }
break; break;
} }
@ -529,7 +529,7 @@ NS_EscapeURL(const nsAFlatString& aStr, const nsTArray<char16_t>& aForbidden,
return aStr; return aStr;
} }
#define ISHEX(c) memchr(hexChars, c, sizeof(hexChars)-1) #define ISHEX(c) memchr(hexCharsUpperLower, c, sizeof(hexCharsUpperLower)-1)
bool bool
NS_UnescapeURL(const char* aStr, int32_t aLen, uint32_t aFlags, NS_UnescapeURL(const char* aStr, int32_t aLen, uint32_t aFlags,
@ -549,8 +549,6 @@ NS_UnescapeURL(const char* aStr, int32_t aLen, uint32_t aFlags,
bool writing = !!(aFlags & esc_AlwaysCopy); bool writing = !!(aFlags & esc_AlwaysCopy);
bool skipControl = !!(aFlags & esc_SkipControl); bool skipControl = !!(aFlags & esc_SkipControl);
static const char hexChars[] = "0123456789ABCDEFabcdef";
const char* last = aStr; const char* last = aStr;
const char* p = aStr; const char* p = aStr;

View file

@ -138,9 +138,9 @@ nsLocalFile::CreateUnique(uint32_t aType, uint32_t aAttributes)
rootName.SetLength(maxRootLength); rootName.SetLength(maxRootLength);
SetNativeLeafName(rootName + suffix); SetNativeLeafName(rootName + suffix);
#endif #endif
nsresult rv = Create(aType, aAttributes); nsresult rvCreate = Create(aType, aAttributes);
if (rv != NS_ERROR_FILE_ALREADY_EXISTS) { if (rvCreate != NS_ERROR_FILE_ALREADY_EXISTS) {
return rv; return rvCreate;
} }
} }

View file

@ -99,8 +99,8 @@ AvailableMaybeSeek(nsIInputStream* aStream, uint64_t* aResult)
// Seek() could reopen the file if REOPEN_ON_REWIND flag is set. // Seek() could reopen the file if REOPEN_ON_REWIND flag is set.
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(aStream); nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(aStream);
if (seekable) { if (seekable) {
nsresult rv = seekable->Seek(nsISeekableStream::NS_SEEK_CUR, 0); nsresult rvSeek = seekable->Seek(nsISeekableStream::NS_SEEK_CUR, 0);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rvSeek)) {
rv = aStream->Available(aResult); rv = aStream->Available(aResult);
} }
} }
@ -117,8 +117,8 @@ TellMaybeSeek(nsISeekableStream* aSeekable, int64_t* aResult)
// NS_BASE_STREAM_CLOSED. // NS_BASE_STREAM_CLOSED.
// If nsIFileInputStream is closed in Read() due to CLOSE_ON_EOF flag, // If nsIFileInputStream is closed in Read() due to CLOSE_ON_EOF flag,
// Seek() could reopen the file if REOPEN_ON_REWIND flag is set. // Seek() could reopen the file if REOPEN_ON_REWIND flag is set.
nsresult rv = aSeekable->Seek(nsISeekableStream::NS_SEEK_CUR, 0); nsresult rvSeek = aSeekable->Seek(nsISeekableStream::NS_SEEK_CUR, 0);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rvSeek)) {
rv = aSeekable->Tell(aResult); rv = aSeekable->Tell(aResult);
} }
} }
@ -828,4 +828,3 @@ nsMultiplexInputStream::Clone(nsIInputStream** aClone)
clone.forget(aClone); clone.forget(aClone);
return NS_OK; return NS_OK;
} }

View file

@ -138,3 +138,6 @@ DEFINES['MOZILLA_EXTERNAL_LINKAGE'] = True
include('/ipc/chromium/chromium-config.mozbuild') include('/ipc/chromium/chromium-config.mozbuild')
SPHINX_TREES['libxpcomrt'] = 'docs' SPHINX_TREES['libxpcomrt'] = 'docs'
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']

View file

@ -325,3 +325,6 @@ LOCAL_INCLUDES += [
] ]
NO_PGO = True NO_PGO = True
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']

View file

@ -604,10 +604,10 @@ xptiInterfaceEntry::GetInterfaceIsArgNumberForParam(uint16_t methodIndex,
} }
nsresult nsresult
xptiInterfaceEntry::IsIID(const nsIID * IID, bool *_retval) xptiInterfaceEntry::IsIID(const nsIID * iid, bool *_retval)
{ {
// It is not necessary to Resolve because this info is read from manifest. // It is not necessary to Resolve because this info is read from manifest.
*_retval = mIID.Equals(*IID); *_retval = mIID.Equals(*iid);
return NS_OK; return NS_OK;
} }

View file

@ -57,3 +57,6 @@ if CONFIG['INTEL_ARCHITECTURE']:
SOURCES['nsUTF8UtilsSSE2.cpp'].flags += CONFIG['SSE2_FLAGS'] SOURCES['nsUTF8UtilsSSE2.cpp'].flags += CONFIG['SSE2_FLAGS']
FINAL_LIBRARY = 'xul' FINAL_LIBRARY = 'xul'
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']

View file

@ -640,9 +640,9 @@ main(void) {
exit (30); exit (30);
} }
nsAutoCString str; nsAutoCString myEntStr;
myEnt->GetString(str); myEnt->GetString(myEntStr);
printf("Found %s\n", str.get()); printf("Found %s\n", myEntStr.get());
} }
printf("Testing nonexistent entries..."); printf("Testing nonexistent entries...");

View file

@ -259,7 +259,7 @@ int main(int argc, char** argv)
ScopedXPCOM xpcom("RacingServiceManager"); ScopedXPCOM xpcom("RacingServiceManager");
NS_ENSURE_FALSE(xpcom.failed(), 1); NS_ENSURE_FALSE(xpcom.failed(), 1);
AutoCreateAndDestroyReentrantMonitor mon(&gReentrantMonitor); AutoCreateAndDestroyReentrantMonitor mon1(&gReentrantMonitor);
nsRefPtr<Runnable> runnable = new Runnable(); nsRefPtr<Runnable> runnable = new Runnable();
NS_ENSURE_TRUE(runnable, 1); NS_ENSURE_TRUE(runnable, 1);
@ -270,13 +270,13 @@ int main(int argc, char** argv)
NS_ENSURE_SUCCESS(rv, 1); NS_ENSURE_SUCCESS(rv, 1);
{ {
ReentrantMonitorAutoEnter mon(*gReentrantMonitor); ReentrantMonitorAutoEnter mon2(*gReentrantMonitor);
gMainThreadWaiting = true; gMainThreadWaiting = true;
mon.Notify(); mon2.Notify();
while (!gCreateInstanceCalled) { while (!gCreateInstanceCalled) {
mon.Wait(); mon2.Wait();
} }
} }
@ -292,13 +292,13 @@ int main(int argc, char** argv)
NS_ENSURE_SUCCESS(rv, 1); NS_ENSURE_SUCCESS(rv, 1);
{ {
ReentrantMonitorAutoEnter mon(*gReentrantMonitor); ReentrantMonitorAutoEnter mon3(*gReentrantMonitor);
gMainThreadWaiting = true; gMainThreadWaiting = true;
mon.Notify(); mon3.Notify();
while (!gCreateInstanceCalled) { while (!gCreateInstanceCalled) {
mon.Wait(); mon3.Wait();
} }
} }

View file

@ -21,3 +21,6 @@ DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
# Need to link with CoreFoundation on Mac # Need to link with CoreFoundation on Mac
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
OS_LIBS += CONFIG['TK_LIBS'] OS_LIBS += CONFIG['TK_LIBS']
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']

View file

@ -28,3 +28,6 @@ UNIFIED_SOURCES += [
] ]
FINAL_LIBRARY = 'xul-gtest' FINAL_LIBRARY = 'xul-gtest'
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']

View file

@ -108,3 +108,6 @@ LOCAL_INCLUDES += [
RESOURCE_FILES += [ RESOURCE_FILES += [
'test.properties', 'test.properties',
] ]
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']

View file

@ -9,11 +9,11 @@
#include "nsISimpleEnumerator.h" #include "nsISimpleEnumerator.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
bool LoopInDir(nsIFile* file) static bool LoopInDir(nsIFile* aFile)
{ {
nsresult rv; nsresult rv;
nsCOMPtr<nsISimpleEnumerator> entries; nsCOMPtr<nsISimpleEnumerator> entries;
rv = file->GetDirectoryEntries(getter_AddRefs(entries)); rv = aFile->GetDirectoryEntries(getter_AddRefs(entries));
if(NS_FAILED(rv) || !entries) if(NS_FAILED(rv) || !entries)
return false; return false;
@ -25,17 +25,17 @@ bool LoopInDir(nsIFile* file)
if(!sup) if(!sup)
return false; return false;
nsCOMPtr<nsIFile> file = do_QueryInterface(sup); nsCOMPtr<nsIFile> nextFile = do_QueryInterface(sup);
if(!file) if (!nextFile)
return false; return false;
nsAutoCString name; nsAutoCString name;
if(NS_FAILED(file->GetNativeLeafName(name))) if(NS_FAILED(nextFile->GetNativeLeafName(name)))
return false; return false;
bool isDir; bool isDir;
printf("%s\n", name.get()); printf("%s\n", name.get());
rv = file->IsDirectory(&isDir); rv = nextFile->IsDirectory(&isDir);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
{ {
printf("IsDirectory Failed!!!\n"); printf("IsDirectory Failed!!!\n");
@ -44,7 +44,7 @@ bool LoopInDir(nsIFile* file)
if (isDir) if (isDir)
{ {
LoopInDir(file); LoopInDir(nextFile);
} }
} }
return true; return true;

View file

@ -36,3 +36,6 @@ if CONFIG['_MSC_VER']:
DEFINES['MOZ_NO_MOZALLOC'] = True DEFINES['MOZ_NO_MOZALLOC'] = True
DIST_INSTALL = True DIST_INSTALL = True
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']