Added XPT_InterfaceDescriptorAddMethods to grow the method table.

Removed unused XPT_ALLOC macro.
Move XPT_SetDataOffset calls into XPT_DoHeader so that the API consumer doesn't
need to know about header sizing and IDE layout guck.
Handle NULL namespaces and interface_directory bits snd idents better.
Made xpt_dump show the the IID for interfaces.


git-svn-id: svn://10.0.0.236/trunk@19992 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
shaver%netscape.com
1999-02-08 16:30:22 +00:00
parent 8dfb112feb
commit 22f1e69f02
12 changed files with 202 additions and 94 deletions

View File

@@ -147,6 +147,10 @@ XPT_IndexForInterface(XPTInterfaceDirectoryEntry *ide_block,
XPTInterfaceDescriptor *
XPT_NewInterfaceDescriptor(uint32 parent_interface, uint32 num_methods,
uint32 num_constants);
PRBool
XPT_InterfaceDescriptorAddMethods(XPTInterfaceDescriptor *id, uint16 num);
/*
* This is our special string struct with a length value associated with it,
* which means that it can contains embedded NULs.

View File

@@ -188,16 +188,6 @@ XPT_GetAddrForOffset(XPTCursor *cursor, uint32 offset);
if (already) \
return PR_TRUE; \
#define XPT_ALLOC(addrp, new_curs, XPTType, localp) \
if (mode == XPT_DECODE) { \
*addrp = localp = PR_NEWZAP(XPTType); \
if (!localp || \
!XPT_SetAddrForOffset(&new_curs, localp)) \
return PR_FALSE; \
} else { \
localp = *addrp; \
}
#define XPT_PREAMBLE(cursor, addrp, pool, size, new_curs, already, \
XPTType, localp) \
{ \

View File

@@ -128,6 +128,7 @@ XPT_DoHeader(XPTCursor *cursor, XPTHeader **headerp)
/* IDEs appear after header, including annotations */
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++) {
@@ -184,8 +185,8 @@ XPT_FillInterfaceDirectoryEntry(XPTInterfaceDirectoryEntry *ide,
XPTInterfaceDescriptor *descriptor)
{
XPT_COPY_IID(ide->iid, *iid);
ide->name = strdup(name);
ide->namespace = strdup(namespace);
ide->name = name ? strdup(name) : NULL; /* what good is it w/o a name? */
ide->namespace = namespace ? strdup(namespace) : NULL;
ide->interface_descriptor = descriptor;
return PR_TRUE;
}
@@ -303,6 +304,24 @@ XPT_NewInterfaceDescriptor(uint32 parent_interface, uint32 num_methods,
return NULL;
}
PRBool
XPT_InterfaceDescriptorAddMethods(XPTInterfaceDescriptor *id, uint16 num)
{
XPTMethodDescriptor *old = id->method_descriptors, *new;
/* XXX should grow in chunks to minimize realloc overhead */
new = PR_REALLOC(old,
(id->num_methods + num) * sizeof(XPTMethodDescriptor));
if (!new)
return PR_FALSE;
memset(id->method_descriptors + id->num_methods, 0,
sizeof(XPTMethodDescriptor) * num);
id->method_descriptors = new;
id->num_methods += num;
return PR_TRUE;
}
uint32
XPT_SizeOfTypeDescriptor(XPTTypeDescriptor *td)
{
@@ -387,6 +406,10 @@ XPT_DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp)
*idp = id;
} else {
id = *idp;
if (!id) {
id_sz = 0;
return XPT_Do32(outer, &id_sz);
}
id_sz = XPT_SizeOfInterfaceDescriptor(id);
}
@@ -395,6 +418,10 @@ XPT_DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp)
if (!XPT_Do32(outer, &cursor->offset))
goto error;
if (mode == XPT_DECODE && !cursor->offset) {
*idp = NULL;
return PR_TRUE;
}
if(!XPT_DoInterfaceDirectoryEntryIndex(cursor, &id->parent_interface) ||
!XPT_Do16(cursor, &id->num_methods)) {
goto error;

View File

@@ -45,21 +45,22 @@
#endif
/* XXX fail if XPT_DATA and !state->data_offset */
#define CHECK_COUNT_(cursor, space) \
/* if we're in the header, then exceeding the data_offset is illegal */ \
((cursor)->pool == XPT_HEADER ? \
(ENCODING(cursor) && \
((cursor)->offset - 1 + (space) > (cursor)->state->data_offset) \
? (DBG(("no space left in HEADER %d + %d > %d\n", (cursor)->offset, \
(space), (cursor)->state->data_offset)), PR_FALSE) \
: PR_TRUE) : \
/* if we're in the data area and we're about to exceed the allocation */ \
(CURS_POOL_OFFSET(cursor) + (space) > (cursor)->state->pool->allocated ? \
/* then grow if we're in ENCODE mode */ \
(ENCODING(cursor) ? XPT_GrowPool((cursor)->state->pool) \
/* and fail if we're in DECODE mode */ \
: (DBG(("can't extend in DECODE")), PR_FALSE)) \
/* otherwise we're OK */ \
#define CHECK_COUNT_(cursor, space) \
/* if we're in the header, then exceeding the data_offset is illegal */ \
((cursor)->pool == XPT_HEADER ? \
(ENCODING(cursor) && \
((cursor)->state->data_offset && \
((cursor)->offset - 1 + (space) > (cursor)->state->data_offset)) \
? (DBG(("no space left in HEADER %d + %d > %d\n", (cursor)->offset, \
(space), (cursor)->state->data_offset)), PR_FALSE) \
: PR_TRUE) : \
/* if we're in the data area and we're about to exceed the allocation */ \
(CURS_POOL_OFFSET(cursor) + (space) > (cursor)->state->pool->allocated ? \
/* then grow if we're in ENCODE mode */ \
(ENCODING(cursor) ? XPT_GrowPool((cursor)->state->pool) \
/* and fail if we're in DECODE mode */ \
: (DBG(("can't extend in DECODE")), PR_FALSE)) \
/* otherwise we're OK */ \
: PR_TRUE))
#define CHECK_COUNT(cursor, space) \
@@ -277,16 +278,27 @@ XPT_DoCString(XPTCursor *cursor, char **identp)
{
XPTCursor my_cursor;
char *ident = *identp;
PRBool already;
XPTMode mode = cursor->state->mode;
uint32 offset = 0;
XPT_PREAMBLE_NO_ALLOC(cursor, identp, XPT_DATA, strlen(ident) + 1,
my_cursor, already);
XPTMode mode = cursor->state->mode;
if (mode == XPT_DECODE) {
char *start = &CURS_POINT(&my_cursor), *end;
char *start, *end;
int len;
if (!XPT_Do32(cursor, &offset))
return PR_FALSE;
if (!offset) {
*identp = NULL;
return PR_TRUE;
}
my_cursor.pool = XPT_DATA;
my_cursor.offset = offset;
my_cursor.state = cursor->state;
start = &CURS_POINT(&my_cursor);
end = strchr(start, 0); /* find the end of the string */
if (!end) {
fprintf(stderr, "didn't find end of string on decode!\n");
@@ -302,12 +314,20 @@ XPT_DoCString(XPTCursor *cursor, char **identp)
ident[len] = 0;
*identp = ident;
if (!XPT_SetAddrForOffset(&my_cursor, my_cursor.offset, ident)) {
PR_DELETE(ident);
return PR_FALSE;
} else {
if (!ident) {
offset = 0;
if (!XPT_Do32(cursor, &offset))
return PR_FALSE;
return PR_TRUE;
}
} else {
if (!XPT_MakeCursor(cursor->state, XPT_DATA, strlen(ident) + 1,
&my_cursor) ||
!XPT_Do32(cursor, &my_cursor.offset))
return PR_FALSE;
while(*ident)
if (!XPT_Do8(&my_cursor, ident++))
return PR_FALSE;

View File

@@ -123,8 +123,6 @@ main(int argc, char **argv)
state = XPT_NewXDRState(XPT_ENCODE, NULL, 0);
TRY("NewState (ENCODE)", state);
XPT_SetDataOffset(state, header_sz);
ok = XPT_MakeCursor(state, XPT_HEADER, header_sz, cursor);
TRY("MakeCursor", ok);

View File

@@ -257,6 +257,18 @@ XPT_DumpAnnotations(XPTAnnotation *ann, const int indent, PRBool verbose_mode)
return PR_TRUE;
}
static void
print_IID(struct nsID *iid, FILE *file)
{
fprintf(file, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(PRUint32) iid->m0, (PRUint32) iid->m1,(PRUint32) iid->m2,
(PRUint32) iid->m3[0], (PRUint32) iid->m3[1],
(PRUint32) iid->m3[2], (PRUint32) iid->m3[3],
(PRUint32) iid->m3[4], (PRUint32) iid->m3[5],
(PRUint32) iid->m3[6], (PRUint32) iid->m3[7]);
}
PRBool
XPT_DumpInterfaceDirectoryEntry(XPTInterfaceDirectoryEntry *ide,
const int indent, PRBool verbose_mode)
@@ -264,13 +276,9 @@ XPT_DumpInterfaceDirectoryEntry(XPTInterfaceDirectoryEntry *ide,
int new_indent = indent + BASE_INDENT;
if (verbose_mode) {
fprintf(stdout, "%*sIID: "
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\n", indent, " ",
(PRUint32) ide->iid.m0, (PRUint32) ide->iid.m1,(PRUint32) ide->iid.m2,
(PRUint32) ide->iid.m3[0], (PRUint32) ide->iid.m3[1],
(PRUint32) ide->iid.m3[2], (PRUint32) ide->iid.m3[3],
(PRUint32) ide->iid.m3[4], (PRUint32) ide->iid.m3[5],
(PRUint32) ide->iid.m3[6], (PRUint32) ide->iid.m3[7]);
fprintf(stdout, "%*sIID: ", indent, " ");
print_IID(&ide->iid, stdout);
fprintf(stdout, "\n");
fprintf(stdout, "%*sName: %s\n",
indent, " ", ide->name);
@@ -286,8 +294,10 @@ XPT_DumpInterfaceDirectoryEntry(XPTInterfaceDirectoryEntry *ide,
return PR_FALSE;
}
} else {
fprintf(stdout, "%*sInterface %s::%s:\n", indent, " ",
ide->namespace, ide->name);
fprintf(stdout, "%*s- %s::%s (", indent, " ",
ide->namespace ? ide->namespace : "", ide->name);
print_IID(&ide->iid, stdout);
fprintf(stdout, "):\n");
if (!XPT_DumpInterfaceDescriptor(ide->interface_descriptor,
new_indent, verbose_mode)) {
return PR_FALSE;
@@ -305,6 +315,11 @@ XPT_DumpInterfaceDescriptor(XPTInterfaceDescriptor *id, const int indent,
int new_indent = indent + BASE_INDENT;
int more_indent = new_indent + BASE_INDENT;
if (!id) {
fprintf(stdout, "%*s[Unresolved]\n", indent, " ");
return PR_TRUE;
}
if (verbose_mode) {
fprintf(stdout, "%*sOffset of parent interface (in data pool): %p\n",
indent, " ", id->parent_interface);

View File

@@ -147,6 +147,10 @@ XPT_IndexForInterface(XPTInterfaceDirectoryEntry *ide_block,
XPTInterfaceDescriptor *
XPT_NewInterfaceDescriptor(uint32 parent_interface, uint32 num_methods,
uint32 num_constants);
PRBool
XPT_InterfaceDescriptorAddMethods(XPTInterfaceDescriptor *id, uint16 num);
/*
* This is our special string struct with a length value associated with it,
* which means that it can contains embedded NULs.

View File

@@ -188,16 +188,6 @@ XPT_GetAddrForOffset(XPTCursor *cursor, uint32 offset);
if (already) \
return PR_TRUE; \
#define XPT_ALLOC(addrp, new_curs, XPTType, localp) \
if (mode == XPT_DECODE) { \
*addrp = localp = PR_NEWZAP(XPTType); \
if (!localp || \
!XPT_SetAddrForOffset(&new_curs, localp)) \
return PR_FALSE; \
} else { \
localp = *addrp; \
}
#define XPT_PREAMBLE(cursor, addrp, pool, size, new_curs, already, \
XPTType, localp) \
{ \

View File

@@ -128,6 +128,7 @@ XPT_DoHeader(XPTCursor *cursor, XPTHeader **headerp)
/* IDEs appear after header, including annotations */
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++) {
@@ -184,8 +185,8 @@ XPT_FillInterfaceDirectoryEntry(XPTInterfaceDirectoryEntry *ide,
XPTInterfaceDescriptor *descriptor)
{
XPT_COPY_IID(ide->iid, *iid);
ide->name = strdup(name);
ide->namespace = strdup(namespace);
ide->name = name ? strdup(name) : NULL; /* what good is it w/o a name? */
ide->namespace = namespace ? strdup(namespace) : NULL;
ide->interface_descriptor = descriptor;
return PR_TRUE;
}
@@ -303,6 +304,24 @@ XPT_NewInterfaceDescriptor(uint32 parent_interface, uint32 num_methods,
return NULL;
}
PRBool
XPT_InterfaceDescriptorAddMethods(XPTInterfaceDescriptor *id, uint16 num)
{
XPTMethodDescriptor *old = id->method_descriptors, *new;
/* XXX should grow in chunks to minimize realloc overhead */
new = PR_REALLOC(old,
(id->num_methods + num) * sizeof(XPTMethodDescriptor));
if (!new)
return PR_FALSE;
memset(id->method_descriptors + id->num_methods, 0,
sizeof(XPTMethodDescriptor) * num);
id->method_descriptors = new;
id->num_methods += num;
return PR_TRUE;
}
uint32
XPT_SizeOfTypeDescriptor(XPTTypeDescriptor *td)
{
@@ -387,6 +406,10 @@ XPT_DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp)
*idp = id;
} else {
id = *idp;
if (!id) {
id_sz = 0;
return XPT_Do32(outer, &id_sz);
}
id_sz = XPT_SizeOfInterfaceDescriptor(id);
}
@@ -395,6 +418,10 @@ XPT_DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp)
if (!XPT_Do32(outer, &cursor->offset))
goto error;
if (mode == XPT_DECODE && !cursor->offset) {
*idp = NULL;
return PR_TRUE;
}
if(!XPT_DoInterfaceDirectoryEntryIndex(cursor, &id->parent_interface) ||
!XPT_Do16(cursor, &id->num_methods)) {
goto error;

View File

@@ -45,21 +45,22 @@
#endif
/* XXX fail if XPT_DATA and !state->data_offset */
#define CHECK_COUNT_(cursor, space) \
/* if we're in the header, then exceeding the data_offset is illegal */ \
((cursor)->pool == XPT_HEADER ? \
(ENCODING(cursor) && \
((cursor)->offset - 1 + (space) > (cursor)->state->data_offset) \
? (DBG(("no space left in HEADER %d + %d > %d\n", (cursor)->offset, \
(space), (cursor)->state->data_offset)), PR_FALSE) \
: PR_TRUE) : \
/* if we're in the data area and we're about to exceed the allocation */ \
(CURS_POOL_OFFSET(cursor) + (space) > (cursor)->state->pool->allocated ? \
/* then grow if we're in ENCODE mode */ \
(ENCODING(cursor) ? XPT_GrowPool((cursor)->state->pool) \
/* and fail if we're in DECODE mode */ \
: (DBG(("can't extend in DECODE")), PR_FALSE)) \
/* otherwise we're OK */ \
#define CHECK_COUNT_(cursor, space) \
/* if we're in the header, then exceeding the data_offset is illegal */ \
((cursor)->pool == XPT_HEADER ? \
(ENCODING(cursor) && \
((cursor)->state->data_offset && \
((cursor)->offset - 1 + (space) > (cursor)->state->data_offset)) \
? (DBG(("no space left in HEADER %d + %d > %d\n", (cursor)->offset, \
(space), (cursor)->state->data_offset)), PR_FALSE) \
: PR_TRUE) : \
/* if we're in the data area and we're about to exceed the allocation */ \
(CURS_POOL_OFFSET(cursor) + (space) > (cursor)->state->pool->allocated ? \
/* then grow if we're in ENCODE mode */ \
(ENCODING(cursor) ? XPT_GrowPool((cursor)->state->pool) \
/* and fail if we're in DECODE mode */ \
: (DBG(("can't extend in DECODE")), PR_FALSE)) \
/* otherwise we're OK */ \
: PR_TRUE))
#define CHECK_COUNT(cursor, space) \
@@ -277,16 +278,27 @@ XPT_DoCString(XPTCursor *cursor, char **identp)
{
XPTCursor my_cursor;
char *ident = *identp;
PRBool already;
XPTMode mode = cursor->state->mode;
uint32 offset = 0;
XPT_PREAMBLE_NO_ALLOC(cursor, identp, XPT_DATA, strlen(ident) + 1,
my_cursor, already);
XPTMode mode = cursor->state->mode;
if (mode == XPT_DECODE) {
char *start = &CURS_POINT(&my_cursor), *end;
char *start, *end;
int len;
if (!XPT_Do32(cursor, &offset))
return PR_FALSE;
if (!offset) {
*identp = NULL;
return PR_TRUE;
}
my_cursor.pool = XPT_DATA;
my_cursor.offset = offset;
my_cursor.state = cursor->state;
start = &CURS_POINT(&my_cursor);
end = strchr(start, 0); /* find the end of the string */
if (!end) {
fprintf(stderr, "didn't find end of string on decode!\n");
@@ -302,12 +314,20 @@ XPT_DoCString(XPTCursor *cursor, char **identp)
ident[len] = 0;
*identp = ident;
if (!XPT_SetAddrForOffset(&my_cursor, my_cursor.offset, ident)) {
PR_DELETE(ident);
return PR_FALSE;
} else {
if (!ident) {
offset = 0;
if (!XPT_Do32(cursor, &offset))
return PR_FALSE;
return PR_TRUE;
}
} else {
if (!XPT_MakeCursor(cursor->state, XPT_DATA, strlen(ident) + 1,
&my_cursor) ||
!XPT_Do32(cursor, &my_cursor.offset))
return PR_FALSE;
while(*ident)
if (!XPT_Do8(&my_cursor, ident++))
return PR_FALSE;

View File

@@ -123,8 +123,6 @@ main(int argc, char **argv)
state = XPT_NewXDRState(XPT_ENCODE, NULL, 0);
TRY("NewState (ENCODE)", state);
XPT_SetDataOffset(state, header_sz);
ok = XPT_MakeCursor(state, XPT_HEADER, header_sz, cursor);
TRY("MakeCursor", ok);

View File

@@ -257,6 +257,18 @@ XPT_DumpAnnotations(XPTAnnotation *ann, const int indent, PRBool verbose_mode)
return PR_TRUE;
}
static void
print_IID(struct nsID *iid, FILE *file)
{
fprintf(file, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(PRUint32) iid->m0, (PRUint32) iid->m1,(PRUint32) iid->m2,
(PRUint32) iid->m3[0], (PRUint32) iid->m3[1],
(PRUint32) iid->m3[2], (PRUint32) iid->m3[3],
(PRUint32) iid->m3[4], (PRUint32) iid->m3[5],
(PRUint32) iid->m3[6], (PRUint32) iid->m3[7]);
}
PRBool
XPT_DumpInterfaceDirectoryEntry(XPTInterfaceDirectoryEntry *ide,
const int indent, PRBool verbose_mode)
@@ -264,13 +276,9 @@ XPT_DumpInterfaceDirectoryEntry(XPTInterfaceDirectoryEntry *ide,
int new_indent = indent + BASE_INDENT;
if (verbose_mode) {
fprintf(stdout, "%*sIID: "
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\n", indent, " ",
(PRUint32) ide->iid.m0, (PRUint32) ide->iid.m1,(PRUint32) ide->iid.m2,
(PRUint32) ide->iid.m3[0], (PRUint32) ide->iid.m3[1],
(PRUint32) ide->iid.m3[2], (PRUint32) ide->iid.m3[3],
(PRUint32) ide->iid.m3[4], (PRUint32) ide->iid.m3[5],
(PRUint32) ide->iid.m3[6], (PRUint32) ide->iid.m3[7]);
fprintf(stdout, "%*sIID: ", indent, " ");
print_IID(&ide->iid, stdout);
fprintf(stdout, "\n");
fprintf(stdout, "%*sName: %s\n",
indent, " ", ide->name);
@@ -286,8 +294,10 @@ XPT_DumpInterfaceDirectoryEntry(XPTInterfaceDirectoryEntry *ide,
return PR_FALSE;
}
} else {
fprintf(stdout, "%*sInterface %s::%s:\n", indent, " ",
ide->namespace, ide->name);
fprintf(stdout, "%*s- %s::%s (", indent, " ",
ide->namespace ? ide->namespace : "", ide->name);
print_IID(&ide->iid, stdout);
fprintf(stdout, "):\n");
if (!XPT_DumpInterfaceDescriptor(ide->interface_descriptor,
new_indent, verbose_mode)) {
return PR_FALSE;
@@ -305,6 +315,11 @@ XPT_DumpInterfaceDescriptor(XPTInterfaceDescriptor *id, const int indent,
int new_indent = indent + BASE_INDENT;
int more_indent = new_indent + BASE_INDENT;
if (!id) {
fprintf(stdout, "%*s[Unresolved]\n", indent, " ");
return PR_TRUE;
}
if (verbose_mode) {
fprintf(stdout, "%*sOffset of parent interface (in data pool): %p\n",
indent, " ", id->parent_interface);