зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1248534 (part 8) - Remove useless XPT freeing code. r=khuey.
XPT has some functions and macros for freeing memory. However, they (a) are only used on error paths, and (b) don't actually free memory -- they just optionally log the "freeing" -- because piecewise freeing doesn't make sense with arena allocation. This patch removes all that unnecessary machinery. --HG-- extra : rebase_source : 40fb8dfd3851a89aaf0501ae290b3a6ca8ac90bc
This commit is contained in:
Родитель
74cc2d7704
Коммит
a6ecbe4768
|
@ -41,18 +41,6 @@
|
|||
(_a)->LOG_RealMallocTotalBytesRequested += (_size); \
|
||||
} while(0)
|
||||
|
||||
#define LOG_FREE(_a) \
|
||||
do{ \
|
||||
XPT_ASSERT((_a)); \
|
||||
++(_a)->LOG_FreeCallCount; \
|
||||
} while(0)
|
||||
|
||||
#define LOG_DONE_LOADING(_a) \
|
||||
do{ \
|
||||
XPT_ASSERT((_a)); \
|
||||
(_a)->LOG_LoadingFreeCallCount = (_a)->LOG_FreeCallCount; \
|
||||
} while(0)
|
||||
|
||||
#define PRINT_STATS(_a) xpt_DebugPrintArenaStats((_a))
|
||||
static void xpt_DebugPrintArenaStats(XPTArena *arena);
|
||||
|
||||
|
@ -60,9 +48,7 @@ static void xpt_DebugPrintArenaStats(XPTArena *arena);
|
|||
|
||||
#define LOG_MALLOC(_a, _req, _used) ((void)0)
|
||||
#define LOG_REAL_MALLOC(_a, _size) ((void)0)
|
||||
#define LOG_FREE(_a) ((void)0)
|
||||
|
||||
#define LOG_DONE_LOADING(_a) ((void)0)
|
||||
#define PRINT_STATS(_a) ((void)0)
|
||||
|
||||
#endif /* XPT_ARENA_LOGGING */
|
||||
|
@ -95,8 +81,6 @@ struct XPTArena
|
|||
uint32_t LOG_MallocCallCount;
|
||||
uint32_t LOG_MallocTotalBytesRequested;
|
||||
uint32_t LOG_MallocTotalBytesUsed;
|
||||
uint32_t LOG_FreeCallCount;
|
||||
uint32_t LOG_LoadingFreeCallCount;
|
||||
uint32_t LOG_RealMallocCallCount;
|
||||
uint32_t LOG_RealMallocTotalBytesRequested;
|
||||
#endif /* XPT_ARENA_LOGGING */
|
||||
|
@ -249,22 +233,6 @@ XPT_ArenaStrDup(XPTArena *arena, const char * s)
|
|||
return cur;
|
||||
}
|
||||
|
||||
XPT_PUBLIC_API(void)
|
||||
XPT_NotifyDoneLoading(XPTArena *arena)
|
||||
{
|
||||
#ifdef XPT_ARENA_LOGGING
|
||||
if (arena) {
|
||||
LOG_DONE_LOADING(arena);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
XPT_PUBLIC_API(void)
|
||||
XPT_ArenaFree(XPTArena *arena, void *block)
|
||||
{
|
||||
LOG_FREE(arena);
|
||||
}
|
||||
|
||||
#ifdef XPT_ARENA_LOGGING
|
||||
static void xpt_DebugPrintArenaStats(XPTArena *arena)
|
||||
{
|
||||
|
@ -278,12 +246,6 @@ static void xpt_DebugPrintArenaStats(XPTArena *arena)
|
|||
printf("%d average bytes used per call (accounts for alignment overhead)\n", (int)arena->LOG_MallocCallCount ? (arena->LOG_MallocTotalBytesUsed/arena->LOG_MallocCallCount) : 0);
|
||||
printf("%d average bytes used per call (accounts for all overhead and waste)\n", (int)arena->LOG_MallocCallCount ? (arena->LOG_RealMallocTotalBytesRequested/arena->LOG_MallocCallCount) : 0);
|
||||
printf("\n");
|
||||
printf("%d during loading times arena free called\n", (int) arena->LOG_LoadingFreeCallCount);
|
||||
printf("%d during loading approx total bytes not freed\n", (int) arena->LOG_LoadingFreeCallCount * (int) (arena->LOG_MallocCallCount ? (arena->LOG_MallocTotalBytesUsed/arena->LOG_MallocCallCount) : 0));
|
||||
printf("\n");
|
||||
printf("%d total times arena free called\n", (int) arena->LOG_FreeCallCount);
|
||||
printf("%d approx total bytes not freed until arena destruction\n", (int) arena->LOG_FreeCallCount * (int) (arena->LOG_MallocCallCount ? (arena->LOG_MallocTotalBytesUsed/arena->LOG_MallocCallCount) : 0 ));
|
||||
printf("\n");
|
||||
printf("%d times arena called system malloc\n", (int) arena->LOG_RealMallocCallCount);
|
||||
printf("%d total bytes arena requested from system\n", (int) arena->LOG_RealMallocTotalBytesRequested);
|
||||
printf("%d byte block size specified at arena creation time\n", (int) arena->block_size);
|
||||
|
|
|
@ -49,12 +49,6 @@ XPT_ArenaMalloc(XPTArena *arena, size_t size);
|
|||
XPT_PUBLIC_API(char *)
|
||||
XPT_ArenaStrDup(XPTArena *arena, const char * s);
|
||||
|
||||
XPT_PUBLIC_API(void)
|
||||
XPT_NotifyDoneLoading(XPTArena *arena);
|
||||
|
||||
XPT_PUBLIC_API(void)
|
||||
XPT_ArenaFree(XPTArena *arena, void* block);
|
||||
|
||||
XPT_PUBLIC_API(size_t)
|
||||
XPT_SizeOfArena(XPTArena *arena, MozMallocSizeOf mallocSizeOf);
|
||||
|
||||
|
@ -63,22 +57,12 @@ XPT_SizeOfArena(XPTArena *arena, MozMallocSizeOf mallocSizeOf);
|
|||
#define XPT_MALLOC(_arena, _bytes) \
|
||||
XPT_ArenaMalloc((_arena), (_bytes))
|
||||
|
||||
#ifdef DEBUG
|
||||
#define XPT_FREE(_arena, _ptr) \
|
||||
XPT_ArenaFree((_arena), (_ptr))
|
||||
#else
|
||||
#define XPT_FREE(_arena, _ptr) \
|
||||
((void)0)
|
||||
#endif
|
||||
|
||||
#define XPT_STRDUP(_arena, _s) \
|
||||
XPT_ArenaStrDup((_arena), (_s))
|
||||
|
||||
#define XPT_CALLOC(_arena, _size) XPT_MALLOC((_arena), (_size))
|
||||
#define XPT_NEW(_arena, _struct) ((_struct *) XPT_MALLOC((_arena), sizeof(_struct)))
|
||||
#define XPT_NEWZAP(_arena, _struct) XPT_NEW((_arena), _struct)
|
||||
#define XPT_DELETE(_arena, _ptr) do{XPT_FREE((_arena), (_ptr)); ((_ptr)) = NULL;}while(0)
|
||||
#define XPT_FREEIF(_arena, _ptr) do{if ((_ptr)) XPT_FREE((_arena), (_ptr));}while(0)
|
||||
|
||||
/* --------------------------------------------------------- */
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ XPT_DoHeaderPrologue(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp, ui
|
|||
|
||||
for (i = 0; i < sizeof(header->magic); i++) {
|
||||
if (!XPT_Do8(cursor, &header->magic[i]))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (strncmp((const char*)header->magic, XPT_MAGIC, 16) != 0) {
|
||||
|
@ -64,12 +64,12 @@ XPT_DoHeaderPrologue(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp, ui
|
|||
"libxpt: bad magic header in input file; "
|
||||
"found '%s', expected '%s'\n",
|
||||
header->magic, XPT_MAGIC_STRING);
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (!XPT_Do8(cursor, &header->major_version) ||
|
||||
!XPT_Do8(cursor, &header->minor_version)) {
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (header->major_version >= XPT_MAJOR_INCOMPATIBLE_VERSION) {
|
||||
|
@ -84,11 +84,9 @@ XPT_DoHeaderPrologue(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp, ui
|
|||
if (!XPT_Do16(cursor, &header->num_interfaces) ||
|
||||
!XPT_Do32(cursor, &header->file_length) ||
|
||||
(ide_offset != NULL && !XPT_Do32(cursor, ide_offset))) {
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
return PR_TRUE;
|
||||
/* XXX need to free child data sometimes! */
|
||||
XPT_ERROR_HANDLE(arena, header);
|
||||
}
|
||||
|
||||
XPT_PUBLIC_API(PRBool)
|
||||
|
@ -109,11 +107,11 @@ XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp)
|
|||
cursor->state->pool_allocated < header->file_length) {
|
||||
fputs("libxpt: File length in header does not match actual length. File may be corrupt\n",
|
||||
stderr);
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (!XPT_Do32(cursor, &header->data_pool))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
|
||||
XPT_SetDataOffset(cursor->state, header->data_pool);
|
||||
|
||||
|
@ -122,11 +120,11 @@ XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp)
|
|||
(XPTInterfaceDirectoryEntry*)XPT_CALLOC(arena, header->num_interfaces *
|
||||
sizeof(XPTInterfaceDirectoryEntry));
|
||||
if (!header->interface_directory)
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (!DoAnnotations(cursor))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
|
||||
/* shouldn't be necessary now, but maybe later */
|
||||
XPT_SeekTo(cursor, ide_offset);
|
||||
|
@ -134,13 +132,10 @@ XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp)
|
|||
for (i = 0; i < header->num_interfaces; i++) {
|
||||
if (!DoInterfaceDirectoryEntry(arena, cursor,
|
||||
&header->interface_directory[i]))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
|
||||
/* XXX need to free child data sometimes! */
|
||||
XPT_ERROR_HANDLE(arena, header);
|
||||
}
|
||||
|
||||
/* InterfaceDirectoryEntry records go in the header */
|
||||
|
@ -161,12 +156,10 @@ DoInterfaceDirectoryEntry(XPTArena *arena, XPTCursor *cursor,
|
|||
|
||||
/* do InterfaceDescriptors */
|
||||
!DoInterfaceDescriptor(arena, cursor, &ide->interface_descriptor)) {
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
|
||||
XPT_ERROR_HANDLE(arena, ide);
|
||||
}
|
||||
|
||||
XPT_PUBLIC_API(PRBool)
|
||||
|
@ -183,9 +176,7 @@ XPT_InterfaceDescriptorAddTypes(XPTArena *arena, XPTInterfaceDescriptor *id,
|
|||
if (!new_)
|
||||
return PR_FALSE;
|
||||
if (old) {
|
||||
if (old_size)
|
||||
memcpy(new_, old, old_size);
|
||||
XPT_FREE(arena, old);
|
||||
memcpy(new_, old, old_size);
|
||||
}
|
||||
id->additional_types = new_;
|
||||
id->num_additional_types += num;
|
||||
|
@ -206,55 +197,52 @@ DoInterfaceDescriptor(XPTArena *arena, XPTCursor *outer,
|
|||
*idp = id;
|
||||
|
||||
if (!XPT_MakeCursor(outer->state, XPT_DATA, id_sz, cursor))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
|
||||
if (!XPT_Do32(outer, &cursor->offset))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
if (!cursor->offset) {
|
||||
XPT_DELETE(arena, *idp);
|
||||
return PR_TRUE;
|
||||
}
|
||||
if(!XPT_Do16(cursor, &id->parent_interface) ||
|
||||
!XPT_Do16(cursor, &id->num_methods)) {
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (id->num_methods) {
|
||||
id->method_descriptors = (XPTMethodDescriptor*)XPT_CALLOC(arena, id->num_methods *
|
||||
sizeof(XPTMethodDescriptor));
|
||||
if (!id->method_descriptors)
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < id->num_methods; i++) {
|
||||
if (!DoMethodDescriptor(arena, cursor, &id->method_descriptors[i], id))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (!XPT_Do16(cursor, &id->num_constants)) {
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (id->num_constants) {
|
||||
id->const_descriptors = (XPTConstDescriptor*)XPT_CALLOC(arena, id->num_constants *
|
||||
sizeof(XPTConstDescriptor));
|
||||
if (!id->const_descriptors)
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < id->num_constants; i++) {
|
||||
if (!DoConstDescriptor(arena, cursor, &id->const_descriptors[i], id)) {
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!XPT_Do8(cursor, &id->flags)) {
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
|
||||
XPT_ERROR_HANDLE(arena, id);
|
||||
}
|
||||
|
||||
PRBool
|
||||
|
@ -329,15 +317,13 @@ DoMethodDescriptor(XPTArena *arena, XPTCursor *cursor, XPTMethodDescriptor *md,
|
|||
|
||||
for(i = 0; i < md->num_args; i++) {
|
||||
if (!DoParamDescriptor(arena, cursor, &md->params[i], id))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (!DoParamDescriptor(arena, cursor, &md->result, id))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
|
||||
return PR_TRUE;
|
||||
|
||||
XPT_ERROR_HANDLE(arena, md->params);
|
||||
}
|
||||
|
||||
PRBool
|
||||
|
@ -362,37 +348,37 @@ DoTypeDescriptor(XPTArena *arena, XPTCursor *cursor, XPTTypeDescriptor *td,
|
|||
XPTInterfaceDescriptor *id)
|
||||
{
|
||||
if (!DoTypeDescriptorPrefix(arena, cursor, &td->prefix)) {
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
switch (XPT_TDP_TAG(td->prefix)) {
|
||||
case TD_INTERFACE_TYPE:
|
||||
if (!XPT_Do16(cursor, &td->type.iface))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
break;
|
||||
case TD_INTERFACE_IS_TYPE:
|
||||
if (!XPT_Do8(cursor, &td->argnum))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
break;
|
||||
case TD_ARRAY:
|
||||
if (!XPT_Do8(cursor, &td->argnum) ||
|
||||
!XPT_Do8(cursor, &td->argnum2))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
|
||||
if (!XPT_InterfaceDescriptorAddTypes(arena, id, 1))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
td->type.additional_type = id->num_additional_types - 1;
|
||||
|
||||
if (!DoTypeDescriptor(arena, cursor,
|
||||
&id->additional_types[td->type.additional_type],
|
||||
id))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
break;
|
||||
case TD_PSTRING_SIZE_IS:
|
||||
case TD_PWSTRING_SIZE_IS:
|
||||
if (!XPT_Do8(cursor, &td->argnum) ||
|
||||
!XPT_Do8(cursor, &td->argnum2))
|
||||
goto error;
|
||||
return PR_FALSE;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -400,8 +386,6 @@ DoTypeDescriptor(XPTArena *arena, XPTCursor *cursor, XPTTypeDescriptor *td,
|
|||
break;
|
||||
}
|
||||
return PR_TRUE;
|
||||
|
||||
XPT_ERROR_HANDLE(arena, td);
|
||||
}
|
||||
|
||||
PRBool
|
||||
|
|
|
@ -88,12 +88,6 @@ XPT_SetDataOffset(XPTState *state, uint32_t data_offset);
|
|||
# error "unknown byte order"
|
||||
#endif
|
||||
|
||||
#define XPT_ERROR_HANDLE(arena, free_it) \
|
||||
error: \
|
||||
XPT_FREEIF(arena, free_it); \
|
||||
return PR_FALSE;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче