зеркало из https://github.com/mozilla/pjs.git
Bug 83591: XPIDL does not store the file length in the header in XPT Files. sr=scc, r=jband
This commit is contained in:
Родитель
c582db8bd2
Коммит
610d3f8976
|
@ -850,7 +850,8 @@ xptiInterfaceInfoManager::DoFullValidationMergeFromFileList(nsISupportsArray* aF
|
|||
if(!header)
|
||||
{
|
||||
// XXX do something!
|
||||
NS_ASSERTION(0,"");
|
||||
NS_ASSERTION(0,"Unable to read an XPT file, turn logging on to see which file");
|
||||
LOG_AUTOREG((" unable to read file\n"));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -378,6 +378,8 @@ typelib_epilog(TreeState *state)
|
|||
XPTState *xstate = XPT_NewXDRState(XPT_ENCODE, NULL, 0);
|
||||
XPTCursor curs, *cursor = &curs;
|
||||
PRUint32 i, len, header_sz;
|
||||
PRUint32 oldOffset;
|
||||
PRUint32 newOffset;
|
||||
char *data;
|
||||
|
||||
/* Write any annotations */
|
||||
|
@ -441,10 +443,18 @@ typelib_epilog(TreeState *state)
|
|||
if (!xstate ||
|
||||
!XPT_MakeCursor(xstate, XPT_HEADER, header_sz, cursor))
|
||||
goto destroy_header;
|
||||
|
||||
oldOffset = cursor->offset;
|
||||
if (!XPT_DoHeader(ARENA(state), cursor, &HEADER(state)))
|
||||
goto destroy;
|
||||
|
||||
newOffset = cursor->offset;
|
||||
XPT_GetXDRDataLength(xstate, XPT_HEADER, &len);
|
||||
HEADER(state)->file_length = len;
|
||||
XPT_GetXDRDataLength(xstate, XPT_DATA, &len);
|
||||
HEADER(state)->file_length += len;
|
||||
XPT_SeekTo(cursor, oldOffset);
|
||||
if (!XPT_DoHeaderPrologue(ARENA(state), cursor, &HEADER(state), NULL))
|
||||
goto destroy;
|
||||
XPT_SeekTo(cursor, newOffset);
|
||||
XPT_GetXDRData(xstate, XPT_HEADER, &data, &len);
|
||||
fwrite(data, len, 1, state->file);
|
||||
XPT_GetXDRData(xstate, XPT_DATA, &data, &len);
|
||||
|
|
|
@ -62,6 +62,8 @@ XPT_Do16(XPTCursor *cursor, PRUint16 *u16p);
|
|||
extern XPT_PUBLIC_API(PRBool)
|
||||
XPT_Do8(XPTCursor *cursor, PRUint8 *u8p);
|
||||
|
||||
extern XPT_PUBLIC_API(PRBool)
|
||||
XPT_DoHeaderPrologue(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp, PRUint32 * ide_offset);
|
||||
extern XPT_PUBLIC_API(PRBool)
|
||||
XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp);
|
||||
|
||||
|
@ -113,6 +115,10 @@ XPT_DestroyXDRState(XPTState *state);
|
|||
extern XPT_PUBLIC_API(PRBool)
|
||||
XPT_UpdateFileLength(XPTState *state);
|
||||
|
||||
/* returns the length of the specified data block */
|
||||
extern XPT_PUBLIC_API(void)
|
||||
XPT_GetXDRDataLength(XPTState *state, XPTPool pool, PRUint32 *len);
|
||||
|
||||
extern XPT_PUBLIC_API(void)
|
||||
XPT_GetXDRData(XPTState *state, XPTPool pool, char **data, PRUint32 *len);
|
||||
|
||||
|
|
|
@ -156,13 +156,11 @@ XPT_FreeHeader(XPTArena *arena, XPTHeader* aHeader)
|
|||
}
|
||||
|
||||
XPT_PUBLIC_API(PRBool)
|
||||
XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp)
|
||||
XPT_DoHeaderPrologue(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp, PRUint32 * ide_offset)
|
||||
{
|
||||
XPTMode mode = cursor->state->mode;
|
||||
XPTHeader *header;
|
||||
PRUint32 ide_offset;
|
||||
int i;
|
||||
XPTAnnotation *ann, *next, **annp;
|
||||
XPTHeader * header;
|
||||
|
||||
if (mode == XPT_DECODE) {
|
||||
header = XPT_NEWZAP(arena, XPTHeader);
|
||||
|
@ -175,12 +173,15 @@ XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp)
|
|||
|
||||
if (mode == XPT_ENCODE) {
|
||||
/* IDEs appear after header, including annotations */
|
||||
ide_offset = XPT_SizeOfHeader(*headerp) + 1; /* one-based offset */
|
||||
if (ide_offset != NULL)
|
||||
{
|
||||
*ide_offset = XPT_SizeOfHeader(*headerp) + 1; /* one-based offset */
|
||||
}
|
||||
header->data_pool = XPT_SizeOfHeaderBlock(*headerp);
|
||||
XPT_SetDataOffset(cursor->state, header->data_pool);
|
||||
}
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
for (i = 0; i < sizeof(header->magic); i++) {
|
||||
if (!XPT_Do8(cursor, &header->magic[i]))
|
||||
goto error;
|
||||
}
|
||||
|
@ -213,10 +214,27 @@ XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp)
|
|||
|
||||
if (!XPT_Do16(cursor, &header->num_interfaces) ||
|
||||
!XPT_Do32(cursor, &header->file_length) ||
|
||||
!XPT_Do32(cursor, &ide_offset)) {
|
||||
(ide_offset != NULL && !XPT_Do32(cursor, ide_offset))) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
/* XXX need to free child data sometimes! */
|
||||
XPT_ERROR_HANDLE(arena, header);
|
||||
}
|
||||
|
||||
XPT_PUBLIC_API(PRBool)
|
||||
XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp)
|
||||
{
|
||||
const int HEADER_SIZE = 24;
|
||||
XPTMode mode = cursor->state->mode;
|
||||
XPTHeader * header;
|
||||
PRUint32 ide_offset;
|
||||
int i;
|
||||
XPTAnnotation *ann, *next, **annp;
|
||||
|
||||
if (!XPT_DoHeaderPrologue(arena, cursor, headerp, &ide_offset))
|
||||
return PR_FALSE;
|
||||
header = *headerp;
|
||||
if (mode == XPT_ENCODE)
|
||||
XPT_DataOffset(cursor->state, &header->data_pool);
|
||||
if (!XPT_Do32(cursor, &header->data_pool))
|
||||
|
|
|
@ -218,6 +218,12 @@ XPT_DestroyXDRState(XPTState *state)
|
|||
XPT_DestroyArena(arena);
|
||||
}
|
||||
|
||||
XPT_PUBLIC_API(void)
|
||||
XPT_GetXDRDataLength(XPTState *state, XPTPool pool, PRUint32 *len)
|
||||
{
|
||||
*len = state->next_cursor[pool] - 1;
|
||||
}
|
||||
|
||||
XPT_PUBLIC_API(void)
|
||||
XPT_GetXDRData(XPTState *state, XPTPool pool, char **data, PRUint32 *len)
|
||||
{
|
||||
|
|
|
@ -113,6 +113,8 @@ main(int argc, char **argv)
|
|||
XPTTypeDescriptor *td;
|
||||
XPTAnnotation *ann, *first_ann;
|
||||
PRUint32 header_sz, len;
|
||||
PRUint32 oldOffset;
|
||||
PRUint32 newOffset;
|
||||
size_t flen = 0;
|
||||
char *head, *data, *whole;
|
||||
FILE *in, *out;
|
||||
|
@ -498,18 +500,28 @@ main(int argc, char **argv)
|
|||
perror("FAILED: error making cursor");
|
||||
return 1;
|
||||
}
|
||||
|
||||
oldOffset = cursor->offset;
|
||||
if (!XPT_DoHeader(arena, cursor, &header)) {
|
||||
perror("FAILED: error doing Header");
|
||||
return 1;
|
||||
}
|
||||
|
||||
newOffset = cursor->offset;
|
||||
XPT_GetXDRDataLength(state, XPT_HEADER, &len);
|
||||
header->file_length = len;
|
||||
XPT_GetXDRDataLength(state, XPT_DATA, &len);
|
||||
header->file_length += len;
|
||||
XPT_SeekTo(cursor, oldOffset);
|
||||
if (!XPT_DoHeaderPrologue(arena, cursor, &header, NULL)) {
|
||||
perror("FAILED: error doing Header");
|
||||
return 1;
|
||||
}
|
||||
XPT_SeekTo(cursor, newOffset);
|
||||
out = fopen(argv[1], "wb");
|
||||
if (!out) {
|
||||
perror("FAILED: fopen");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
XPT_GetXDRData(state, XPT_HEADER, &head, &len);
|
||||
fwrite(head, len, 1, out);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче