Skip to content

Commit 404ef7a

Browse files
committed
Bug 1407838 - Remove the remains of NS_Alloc/NS_Realloc/NS_Free. r=njn
Bug 1134923 removed the use of those functions in gecko, and left some for the XPCOM standalone glue. The XPCOM standalone glue was severely stripped down in bug 1306327, with the effect of removing the implementation for those functions. The remains in nsXPCOM.h are: XPCOM_API(void*) NS_Alloc(size_t aSize); XPCOM_API(void*) NS_Realloc(void* aPtr, size_t aSize); XPCOM_API(void) NS_Free(void* aPtr); With no implementation left, the first arm is never actually used, and the second arm means every remaining use of those functions in the tree is a macro expansion to one of moz_xmalloc, moz_xrealloc or free. --HG-- extra : rebase_source : fd1669abc5a25d8edbd5c3a8522e22a5c3f558e2
1 parent 6e866f3 commit 404ef7a

File tree

14 files changed

+20
-68
lines changed

14 files changed

+20
-68
lines changed

devtools/shared/heapsnapshot/HeapSnapshot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DominatorTree;
3333

3434
struct NSFreePolicy {
3535
void operator()(void* ptr) {
36-
NS_Free(ptr);
36+
free(ptr);
3737
}
3838
};
3939

dom/push/PushManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class MOZ_RAII AutoFreeKeyBuffer final
8383

8484
~AutoFreeKeyBuffer()
8585
{
86-
NS_Free(*mKeyBuffer);
86+
free(*mKeyBuffer);
8787
}
8888
};
8989

dom/push/PushNotifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ PushData::Binary(uint32_t* aDataLen, uint8_t** aData)
224224
return NS_OK;
225225
}
226226
uint32_t length = mData.Length();
227-
uint8_t* data = static_cast<uint8_t*>(NS_Alloc(length * sizeof(uint8_t)));
227+
uint8_t* data = static_cast<uint8_t*>(moz_xmalloc(length * sizeof(uint8_t)));
228228
if (!data) {
229229
return NS_ERROR_OUT_OF_MEMORY;
230230
}

gfx/thebes/gfxFcPlatformFontList.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,12 +1518,12 @@ gfxFcPlatformFontList::MakePlatformFont(const nsAString& aFontName,
15181518
{
15191519
FT_Face face = Factory::NewFTFaceFromData(nullptr, aFontData, aLength, 0);
15201520
if (!face) {
1521-
NS_Free((void*)aFontData);
1521+
free((void*)aFontData);
15221522
return nullptr;
15231523
}
15241524
if (FT_Err_Ok != FT_Select_Charmap(face, FT_ENCODING_UNICODE)) {
15251525
Factory::ReleaseFTFace(face);
1526-
NS_Free((void*)aFontData);
1526+
free((void*)aFontData);
15271527
return nullptr;
15281528
}
15291529

gfx/thebes/gfxFcPlatformFontList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class FTUserFontData {
6060
{
6161
mozilla::gfx::Factory::ReleaseFTFace(mFace);
6262
if (mFontData) {
63-
NS_Free((void*)mFontData);
63+
free((void*)mFontData);
6464
}
6565
}
6666

xpcom/base/nsCRTGlue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ template<typename CharT>
131131
CharT*
132132
NS_strndup(const CharT* aString, uint32_t aLen)
133133
{
134-
auto newBuf = (CharT*)NS_Alloc((aLen + 1) * sizeof(CharT));
134+
auto newBuf = (CharT*)moz_xmalloc((aLen + 1) * sizeof(CharT));
135135
if (newBuf) {
136136
memcpy(newBuf, aString, aLen * sizeof(CharT));
137137
newBuf[aLen] = '\0';
@@ -146,7 +146,7 @@ char*
146146
NS_strdup(const char* aString)
147147
{
148148
uint32_t len = strlen(aString);
149-
char* str = (char*)NS_Alloc(len + 1);
149+
char* str = (char*)moz_xmalloc(len + 1);
150150
if (str) {
151151
memcpy(str, aString, len);
152152
str[len] = '\0';

xpcom/base/nsCRTGlue.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ int NS_strcmp(const char16_t* aStrA, const char16_t* aStrB);
5353
int NS_strncmp(const char16_t* aStrA, const char16_t* aStrB, size_t aLen);
5454

5555
/**
56-
* "strdup" for char16_t strings, uses the NS_Alloc allocator.
56+
* "strdup" for char16_t strings, uses the moz_xmalloc allocator.
5757
*/
5858
char16_t* NS_strdup(const char16_t* aString);
5959

6060
/**
61-
* "strdup", but using the NS_Alloc allocator.
61+
* "strdup", but using the moz_xmalloc allocator.
6262
*/
6363
char* NS_strdup(const char* aString);
6464

6565
/**
6666
* strndup for char16_t or char strings (normal strndup is not available on
6767
* windows). This function will ensure that the new string is
68-
* null-terminated. Uses the NS_Alloc allocator.
68+
* null-terminated. Uses the moz_xmalloc allocator.
6969
*
7070
* CharT may be either char16_t or char.
7171
*/

xpcom/base/nsID.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ static const char gIDFormat[] =
9999

100100
/*
101101
* Returns an allocated string in {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
102-
* format. The string is allocated with NS_Alloc and should be freed by
102+
* format. The string is allocated with moz_xmalloc and should be freed by
103103
* the caller.
104104
*/
105105

106106
char*
107107
nsID::ToString() const
108108
{
109-
char* res = (char*)NS_Alloc(NSID_LENGTH);
109+
char* res = (char*)moz_xmalloc(NSID_LENGTH);
110110

111111
if (res) {
112112
snprintf(res, NSID_LENGTH, gIDFormat,

xpcom/base/nsMemory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ nsMemory::HeapMinimize(bool aImmediate)
3030
void*
3131
nsMemory::Clone(const void* aPtr, size_t aSize)
3232
{
33-
void* newPtr = NS_Alloc(aSize);
33+
void* newPtr = moz_xmalloc(aSize);
3434
if (newPtr) {
3535
memcpy(newPtr, aPtr, aSize);
3636
}

xpcom/base/nsMemory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class nsMemory
7070
int32_t iter_ = int32_t(size); \
7171
while (--iter_ >= 0) \
7272
freeFunc((array)[iter_]); \
73-
NS_Free((array)); \
73+
free((array)); \
7474
} while(0)
7575

7676
// convenience macros for commonly used calls. mmmmm. syntactic sugar.
@@ -86,7 +86,7 @@ class nsMemory
8686
* @param array The array to be freed.
8787
*/
8888
#define NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(size, array) \
89-
NS_FREE_XPCOM_POINTER_ARRAY((size), (array), NS_Free)
89+
NS_FREE_XPCOM_POINTER_ARRAY((size), (array), free)
9090

9191
/**
9292
* Macro to free an array of pointers to nsISupports (or classes

0 commit comments

Comments
 (0)