Remove dependency on NSPR for xpidl, libxpt and tools.

This commit is contained in:
mccabe%netscape.com 1999-04-13 20:22:02 +00:00
parent dcf0040807
commit 8be0ea87e3
26 changed files with 448 additions and 210 deletions

View File

@ -25,6 +25,8 @@
#define __xpt_struct_h__
#include "prtypes.h"
#include <assert.h>
#include <stdlib.h>
/*
* The linkage of XPT API functions differs depending on whether the file is
@ -49,6 +51,22 @@
PR_BEGIN_EXTERN_C
/*
* Some utility macros. Defined here in lieu of equivalent NSPR
* macros, which require NSPR linkage.
*/
#define XPT_MALLOC(_bytes) (malloc((_bytes)))
#define XPT_NEW(_struct) ((_struct *) malloc(sizeof(_struct)))
#define XPT_REALLOC(_ptr, _size) (realloc((_ptr), (_size)))
#define XPT_CALLOC(_size) (calloc(1, (_size)))
#define XPT_NEWZAP(_struct) ((_struct*)calloc(1, sizeof(_struct)))
#define XPT_DELETE(_ptr) { free(_ptr); (_ptr) = NULL; }
#define XPT_FREEIF(_ptr) if (_ptr) free(_ptr)
#define XPT_FREE(_ptr) free(_ptr)
#define XPT_ASSERT(_expr) assert(_expr)
/*
* Originally, I was going to have structures that exactly matched the on-disk
* representation, but that proved difficult: different compilers can pack

View File

@ -34,6 +34,9 @@ typedef struct XPTState XPTState;
typedef struct XPTDatapool XPTDatapool;
typedef struct XPTCursor XPTCursor;
/* Opaque type, for internal use */
typedef struct XPTHashTable XPTHashTable;
extern XPT_PUBLIC_API(PRBool)
XPT_DoString(XPTCursor *cursor, XPTString **strp);
@ -101,7 +104,7 @@ struct XPTState {
};
struct XPTDatapool {
PLHashTable *offset_map;
XPTHashTable *offset_map;
char *data;
PRUint32 count;
PRUint32 allocated;
@ -190,12 +193,16 @@ XPT_GetAddrForOffset(XPTCursor *cursor, PRUint32 offset);
if (already) \
return PR_TRUE; \
/* XXXmccabe currently not used! */
/* also, XPT_ALLOC isn't defined. */
#if 0
#define XPT_PREAMBLE(cursor, addrp, pool, size, new_curs, already, \
XPTType, localp) \
{ \
XPT_PREAMBLE_(cursor, addrp, pool, size, new_curs, already); \
XPT_ALLOC(addrp, new_curs, XPTType, localp) \
}
#endif
#define XPT_PREAMBLE_NO_ALLOC(cursor, addrp, pool, size, new_curs, already) \
{ \
@ -205,7 +212,7 @@ XPT_GetAddrForOffset(XPTCursor *cursor, PRUint32 offset);
#define XPT_ERROR_HANDLE(free_it) \
error: \
if (cursor->state->mode == XPT_DECODE) \
PR_FREEIF(free_it); \
XPT_FREEIF(free_it); \
return PR_FALSE;

View File

@ -65,7 +65,7 @@ DoParamDescriptor(XPTCursor *cursor, XPTParamDescriptor *pd);
#define CURS_POOL_OFFSET_RAW(cursor) \
((cursor)->pool == XPT_HEADER \
? (cursor)->offset \
: (PR_ASSERT((cursor)->state->data_offset), \
: (XPT_ASSERT((cursor)->state->data_offset), \
(cursor)->offset + (cursor)->state->data_offset))
#define CURS_POOL_OFFSET(cursor) \
@ -105,17 +105,17 @@ XPT_SizeOfHeaderBlock(XPTHeader *header)
XPT_PUBLIC_API(XPTHeader *)
XPT_NewHeader(PRUint16 num_interfaces)
{
XPTHeader *header = PR_NEWZAP(XPTHeader);
XPTHeader *header = XPT_NEWZAP(XPTHeader);
if (!header)
return NULL;
memcpy(header->magic, XPT_MAGIC, 16);
header->major_version = XPT_MAJOR_VERSION;
header->minor_version = XPT_MINOR_VERSION;
header->num_interfaces = num_interfaces;
header->interface_directory = PR_CALLOC(num_interfaces *
sizeof(XPTInterfaceDirectoryEntry));
header->interface_directory = XPT_CALLOC(num_interfaces *
sizeof(XPTInterfaceDirectoryEntry));
if (!header->interface_directory) {
PR_DELETE(header);
XPT_DELETE(header);
return NULL;
}
header->data_pool = 0; /* XXX do we even need this struct any more? */
@ -131,7 +131,7 @@ XPT_DoHeader(XPTCursor *cursor, XPTHeader **headerp)
PRUint32 ide_offset;
int i;
if (mode == XPT_DECODE) {
header = PR_NEWZAP(XPTHeader);
header = XPT_NEWZAP(XPTHeader);
if (!header)
return PR_FALSE;
*headerp = header;
@ -169,8 +169,8 @@ XPT_DoHeader(XPTCursor *cursor, XPTHeader **headerp)
if (mode == XPT_DECODE) {
header->interface_directory =
PR_CALLOC(header->num_interfaces *
sizeof(XPTInterfaceDirectoryEntry));
XPT_CALLOC(header->num_interfaces *
sizeof(XPTInterfaceDirectoryEntry));
if (!header->interface_directory)
goto error;
}
@ -248,6 +248,7 @@ DoInterfaceDirectoryEntry(XPTCursor *cursor,
XPT_ERROR_HANDLE(ide);
}
#if 0
/*
* Decode: Get the interface directory entry for the on-disk index.
* Encode: Write the index.
@ -285,27 +286,28 @@ DoInterfaceDirectoryEntryIndex(XPTCursor *cursor,
return PR_TRUE;
}
#endif
XPT_PUBLIC_API(XPTInterfaceDescriptor *)
XPT_NewInterfaceDescriptor(PRUint16 parent_interface, PRUint16 num_methods,
PRUint16 num_constants, PRUint8 flags)
{
XPTInterfaceDescriptor *id = PR_NEWZAP(XPTInterfaceDescriptor);
XPTInterfaceDescriptor *id = XPT_NEWZAP(XPTInterfaceDescriptor);
if (!id)
return NULL;
if (num_methods) {
id->method_descriptors = PR_CALLOC(num_methods *
sizeof(XPTMethodDescriptor));
id->method_descriptors = XPT_CALLOC(num_methods *
sizeof(XPTMethodDescriptor));
if (!id->method_descriptors)
goto free_id;
id->num_methods = num_methods;
}
if (num_constants) {
id->const_descriptors = PR_CALLOC(num_constants *
sizeof(XPTConstDescriptor));
id->const_descriptors = XPT_CALLOC(num_constants *
sizeof(XPTConstDescriptor));
if (!id->const_descriptors)
goto free_meth;
id->num_constants = num_constants;
@ -322,9 +324,9 @@ XPT_NewInterfaceDescriptor(PRUint16 parent_interface, PRUint16 num_methods,
return id;
free_meth:
PR_FREEIF(id->method_descriptors);
XPT_FREEIF(id->method_descriptors);
free_id:
PR_DELETE(id);
XPT_DELETE(id);
return NULL;
}
@ -334,8 +336,8 @@ XPT_InterfaceDescriptorAddMethods(XPTInterfaceDescriptor *id, PRUint16 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));
new = XPT_REALLOC(old,
(id->num_methods + num) * sizeof(XPTMethodDescriptor));
if (!new)
return PR_FALSE;
@ -351,8 +353,8 @@ XPT_InterfaceDescriptorAddConsts(XPTInterfaceDescriptor *id, PRUint16 num)
XPTConstDescriptor *old = id->const_descriptors, *new;
/* XXX should grow in chunks to minimize realloc overhead */
new = PR_REALLOC(old,
(id->num_constants + num) * sizeof(XPTConstDescriptor));
new = XPT_REALLOC(old,
(id->num_constants + num) * sizeof(XPTConstDescriptor));
if (!new)
return PR_FALSE;
@ -441,7 +443,7 @@ DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp)
PRUint32 i, id_sz = 0;
if (mode == XPT_DECODE) {
id = PR_NEWZAP(XPTInterfaceDescriptor);
id = XPT_NEWZAP(XPTInterfaceDescriptor);
if (!id)
return PR_FALSE;
*idp = id;
@ -469,8 +471,8 @@ DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp)
}
if (mode == XPT_DECODE && id->num_methods) {
id->method_descriptors = PR_CALLOC(id->num_methods *
sizeof(XPTMethodDescriptor));
id->method_descriptors = XPT_CALLOC(id->num_methods *
sizeof(XPTMethodDescriptor));
if (!id->method_descriptors)
goto error;
}
@ -485,8 +487,8 @@ DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp)
}
if (mode == XPT_DECODE)
id->const_descriptors = PR_CALLOC(id->num_constants *
sizeof(XPTConstDescriptor));
id->const_descriptors = XPT_CALLOC(id->num_constants *
sizeof(XPTConstDescriptor));
for (i = 0; i < id->num_constants; i++) {
if (!DoConstDescriptor(cursor, &id->const_descriptors[i])) {
@ -582,21 +584,21 @@ XPT_FillMethodDescriptor(XPTMethodDescriptor *meth, PRUint8 flags, char *name,
return PR_FALSE;
meth->num_args = num_args;
if (meth->num_args) {
meth->params = PR_CALLOC(num_args * sizeof(XPTParamDescriptor));
meth->params = XPT_CALLOC(num_args * sizeof(XPTParamDescriptor));
if (!meth->params)
goto free_name;
} else {
meth->params = NULL;
}
meth->result = PR_NEWZAP(XPTParamDescriptor);
meth->result = XPT_NEWZAP(XPTParamDescriptor);
if (!meth->result)
goto free_params;
return PR_TRUE;
free_params:
PR_DELETE(meth->params);
XPT_DELETE(meth->params);
free_name:
PR_DELETE(meth->name);
XPT_DELETE(meth->name);
return PR_FALSE;
}
@ -612,7 +614,7 @@ DoMethodDescriptor(XPTCursor *cursor, XPTMethodDescriptor *md)
return PR_FALSE;
if (mode == XPT_DECODE && md->num_args) {
md->params = PR_CALLOC(md->num_args * sizeof(XPTParamDescriptor));
md->params = XPT_CALLOC(md->num_args * sizeof(XPTParamDescriptor));
if (!md->params)
return PR_FALSE;
}
@ -623,7 +625,7 @@ DoMethodDescriptor(XPTCursor *cursor, XPTMethodDescriptor *md)
}
if (mode == XPT_DECODE) {
md->result = PR_NEWZAP(XPTParamDescriptor);
md->result = XPT_NEWZAP(XPTParamDescriptor);
if (!md->result)
return PR_FALSE;
}
@ -688,7 +690,7 @@ DoTypeDescriptor(XPTCursor *cursor, XPTTypeDescriptor *td)
XPT_PUBLIC_API(XPTAnnotation *)
XPT_NewAnnotation(PRUint8 flags, XPTString *creator, XPTString *private_data)
{
XPTAnnotation *ann = PR_NEWZAP(XPTAnnotation);
XPTAnnotation *ann = XPT_NEWZAP(XPTAnnotation);
if (!ann)
return NULL;
ann->flags = flags;
@ -706,7 +708,7 @@ DoAnnotation(XPTCursor *cursor, XPTAnnotation **annp)
XPTAnnotation *ann;
if (mode == XPT_DECODE) {
ann = PR_NEWZAP(XPTAnnotation);
ann = XPT_NEWZAP(XPTAnnotation);
if (!ann)
return PR_FALSE;
*annp = ann;
@ -738,8 +740,8 @@ DoAnnotation(XPTCursor *cursor, XPTAnnotation **annp)
error_2:
if (ann && XPT_ANN_IS_PRIVATE(ann->flags)) {
PR_FREEIF(ann->creator);
PR_FREEIF(ann->private_data);
XPT_FREEIF(ann->creator);
XPT_FREEIF(ann->private_data);
}
XPT_ERROR_HANDLE(ann);
}

View File

@ -33,7 +33,7 @@ CheckForRepeat(XPTCursor *cursor, void **addrp, XPTPool pool, int len,
#define CURS_POOL_OFFSET_RAW(cursor) \
((cursor)->pool == XPT_HEADER \
? (cursor)->offset \
: (PR_ASSERT((cursor)->state->data_offset), \
: (XPT_ASSERT((cursor)->state->data_offset), \
(cursor)->offset + (cursor)->state->data_offset))
#define CURS_POOL_OFFSET(cursor) \
@ -71,17 +71,76 @@ CheckForRepeat(XPTCursor *cursor, void **addrp, XPTPool pool, int len,
#define CHECK_COUNT(cursor, space) \
(CHECK_COUNT_(cursor, space) \
? PR_TRUE \
: (PR_ASSERT(0), \
: (XPT_ASSERT(0), \
fprintf(stderr, "FATAL: can't no room for %d in cursor\n", space), \
PR_FALSE))
/* increase the data allocation for the pool by XPT_GROW_CHUNK */
#define XPT_GROW_CHUNK 8192
static PLHashNumber
null_hash(const void *key)
{
return (PLHashNumber)key;
/*
* quick and dirty hardcoded hashtable, to avoid dependence on nspr or glib.
* XXXmccabe it might turn out that we could use a simpler data structure here.
*/
typedef struct XPTHashRecord {
void *key;
void *value;
struct XPTHashRecord *next;
} XPTHashRecord;
#define XPT_HASHSIZE 32
struct XPTHashTable { /* it's already typedef'ed from before. */
XPTHashRecord *buckets[XPT_HASHSIZE];
};
static XPTHashTable *
XPT_NewHashTable() {
XPTHashTable *table;
table = XPT_NEWZAP(XPTHashTable);
return table;
}
static void trimrecord(XPTHashRecord *record) {
if (record == NULL)
return;
trimrecord(record->next);
XPT_DELETE(record);
}
static void
XPT_HashTableDestroy(XPTHashTable *table) {
int i;
for (i = 0; i < XPT_HASHSIZE; i++)
trimrecord(table->buckets[i]);
XPT_FREE(table);
}
static void *
XPT_HashTableAdd(XPTHashTable *table, void *key, void *value) {
XPTHashRecord **bucketloc = table->buckets + (((PRInt32)key) % XPT_HASHSIZE);
XPTHashRecord *bucket;
while (*bucketloc != NULL)
bucketloc = &((*bucketloc)->next);
bucket = XPT_NEW(XPTHashRecord);
bucket->key = key;
bucket->value = value;
bucket->next = NULL;
*bucketloc = bucket;
return value;
}
static void *
XPT_HashTableLookup(XPTHashTable *table, void *key) {
XPTHashRecord *bucket = table->buckets[(PRInt32)key % XPT_HASHSIZE];
while (bucket != NULL) {
if (bucket->key == key)
return bucket->value;
bucket = bucket->next;
}
return NULL;
}
XPT_PUBLIC_API(XPTState *)
@ -89,20 +148,21 @@ XPT_NewXDRState(XPTMode mode, char *data, PRUint32 len)
{
XPTState *state;
state = PR_NEW(XPTState);
state = XPT_NEW(XPTState);
if (!state)
return NULL;
state->mode = mode;
state->pool = PR_NEW(XPTDatapool);
state->pool = XPT_NEW(XPTDatapool);
state->next_cursor[0] = state->next_cursor[1] = 1;
if (!state->pool)
goto err_free_state;
state->pool->count = 0;
state->pool->offset_map = PL_NewHashTable(32, null_hash, PL_CompareValues,
PL_CompareValues, NULL, NULL);
state->pool->offset_map = XPT_NewHashTable();
/* state->pool->offset_map = PL_NewHashTable(32, null_hash, PL_CompareValues, */
/* PL_CompareValues, NULL, NULL); */
if (!state->pool->offset_map)
goto err_free_pool;
@ -110,7 +170,7 @@ XPT_NewXDRState(XPTMode mode, char *data, PRUint32 len)
state->pool->data = data;
state->pool->allocated = len;
} else {
state->pool->data = PR_MALLOC(XPT_GROW_CHUNK);
state->pool->data = XPT_MALLOC(XPT_GROW_CHUNK);
if (!state->pool->data)
goto err_free_hash;
state->pool->allocated = XPT_GROW_CHUNK;
@ -119,21 +179,24 @@ XPT_NewXDRState(XPTMode mode, char *data, PRUint32 len)
return state;
err_free_hash:
PL_HashTableDestroy(state->pool->offset_map);
XPT_HashTableDestroy(state->pool->offset_map);
/* PL_HashTableDestroy(state->pool->offset_map); */
err_free_pool:
PR_DELETE(state->pool);
XPT_DELETE(state->pool);
err_free_state:
PR_DELETE(state);
XPT_DELETE(state);
return NULL;
}
XPT_PUBLIC_API(void)
XPT_DestroyXDRState(XPTState *state)
{
if (state->pool->offset_map)
XPT_HashTableDestroy(state->pool->offset_map);
if (state->mode == XPT_ENCODE)
PR_DELETE(state->pool->data);
PR_DELETE(state->pool);
PR_DELETE(state);
XPT_DELETE(state->pool->data);
XPT_DELETE(state->pool);
XPT_DELETE(state);
}
XPT_PUBLIC_API(void)
@ -207,13 +270,13 @@ XPT_SeekTo(XPTCursor *cursor, PRUint32 offset)
XPT_PUBLIC_API(XPTString *)
XPT_NewString(PRUint16 length, char *bytes)
{
XPTString *str = PR_NEW(XPTString);
XPTString *str = XPT_NEW(XPTString);
if (!str)
return NULL;
str->length = length;
str->bytes = malloc(length);
if (!str->bytes) {
PR_DELETE(str);
XPT_DELETE(str);
return NULL;
}
memcpy(str->bytes, bytes, length);
@ -237,7 +300,7 @@ XPT_DoStringInline(XPTCursor *cursor, XPTString **strp)
int i;
if (mode == XPT_DECODE) {
str = PR_NEWZAP(XPTString);
str = XPT_NEWZAP(XPTString);
if (!str)
return PR_FALSE;
*strp = str;
@ -259,9 +322,9 @@ XPT_DoStringInline(XPTCursor *cursor, XPTString **strp)
return PR_TRUE;
error_2:
PR_DELETE(str->bytes);
XPT_DELETE(str->bytes);
error:
PR_DELETE(str);
XPT_DELETE(str);
return PR_FALSE;
}
@ -311,7 +374,7 @@ XPT_DoCString(XPTCursor *cursor, char **identp)
}
len = end - start;
ident = PR_MALLOC(len + 1);
ident = XPT_MALLOC(len + 1);
if (!ident)
return PR_FALSE;
@ -346,27 +409,33 @@ XPT_DoCString(XPTCursor *cursor, char **identp)
XPT_PUBLIC_API(PRUint32)
XPT_GetOffsetForAddr(XPTCursor *cursor, void *addr)
{
return (PRUint32)PL_HashTableLookup(cursor->state->pool->offset_map, addr);
return (PRUint32)XPT_HashTableLookup(cursor->state->pool->offset_map, addr);
/* return (PRUint32)PL_HashTableLookup(cursor->state->pool->offset_map, addr); */
}
XPT_PUBLIC_API(PRBool)
XPT_SetOffsetForAddr(XPTCursor *cursor, void *addr, PRUint32 offset)
{
return PL_HashTableAdd(cursor->state->pool->offset_map,
addr, (void *)offset) != NULL;
return XPT_HashTableAdd(cursor->state->pool->offset_map,
addr, (void *)offset) != NULL;
/* return PL_HashTableAdd(cursor->state->pool->offset_map, */
/* addr, (void *)offset) != NULL; */
}
XPT_PUBLIC_API(PRBool)
XPT_SetAddrForOffset(XPTCursor *cursor, PRUint32 offset, void *addr)
{
return PL_HashTableAdd(cursor->state->pool->offset_map,
(void *)offset, addr) != NULL;
return XPT_HashTableAdd(cursor->state->pool->offset_map,
(void *)offset, addr) != NULL;
/* return PL_HashTableAdd(cursor->state->pool->offset_map, */
/* addr, (void *)offset) != NULL; */
}
XPT_PUBLIC_API(void *)
XPT_GetAddrForOffset(XPTCursor *cursor, PRUint32 offset)
{
return PL_HashTableLookup(cursor->state->pool->offset_map, (void *)offset);
return XPT_HashTableLookup(cursor->state->pool->offset_map, (void *)offset);
/* return PL_HashTableLookup(cursor->state->pool->offset_map, (void *)offset); */
}
static PRBool

View File

@ -30,7 +30,6 @@ CSRCS = PrimitiveTest.c SimpleTypeLib.c
LIBS = \
-L$(DIST)/bin \
-lxpt \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -35,7 +35,6 @@ LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\libxpt
LLIBS= \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\libxpt32.lib \
$(LIBNSPR) \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@ -30,7 +30,6 @@ CSRCS = xpt_dump.c xpt_link.c
LIBS = \
-L$(DIST)/bin \
-lxpt \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -35,7 +35,6 @@ LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\libxpt
LLIBS= \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\libxpt32.lib \
$(LIBNSPR) \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@ -744,7 +744,10 @@ XPT_DumpConstDescriptor(XPTHeader *header, XPTConstDescriptor *cd,
const int indent, PRBool verbose_mode)
{
int new_indent = indent + BASE_INDENT;
char *out, *const_type;
char *const_type;
/* char *out; */
PRUint32 uintout;
PRInt32 intout;
if (verbose_mode) {
fprintf(stdout, "%*sName: %s\n", indent, " ", cd->name);
@ -766,28 +769,36 @@ XPT_DumpConstDescriptor(XPTHeader *header, XPTConstDescriptor *cd,
case TD_INT16:
fprintf(stdout, "%d", cd->value.i16);
break;
case TD_INT64:
/* XXX punt for now to remove NSPR linkage...
* borrow from mozilla/nsprpub/pr/src/io/prprf.c::cvt_ll? */
/* out = PR_smprintf("%lld", cd->value.i64); */
/* fputs(out, stdout); */
/* PR_smprintf_free(out); */
LL_L2I(intout, cd->value.i64);
fprintf(stdout, "%d", intout);
break;
case TD_INT32:
fprintf(stdout, "%d", cd->value.i32);
break;
case TD_INT64:
out = PR_smprintf("%lld", cd->value.i64);
fputs(out, stdout);
PR_smprintf_free(out);
break;
case TD_UINT8:
fprintf(stdout, "%d", cd->value.ui8);
break;
case TD_UINT16:
fprintf(stdout, "%d", cd->value.ui16);
break;
case TD_UINT64:
/* out = PR_smprintf("%lld", cd->value.ui64); */
/* fputs(out, stdout); */
/* PR_smprintf_free(out); */
/* XXX punt for now to remove NSPR linkage. */
LL_L2UI(uintout, cd->value.ui64);
fprintf(stdout, "%d", uintout);
break;
case TD_UINT32:
fprintf(stdout, "%d", cd->value.ui32);
break;
case TD_UINT64:
out = PR_smprintf("%lld", cd->value.ui64);
fputs(out, stdout);
PR_smprintf_free(out);
break;
case TD_FLOAT:
fprintf(stdout, "%f", cd->value.flt);
break;

View File

@ -152,18 +152,18 @@ main(int argc, char **argv)
totalNumberOfInterfaces += header->num_interfaces;
if (k == 0) {
IDE_array = PR_CALLOC(totalNumberOfInterfaces * sizeof(XPTInterfaceDirectoryEntry));
fix_array = PR_CALLOC(totalNumberOfInterfaces * sizeof(fixElement));
IDE_array = XPT_CALLOC(totalNumberOfInterfaces * sizeof(XPTInterfaceDirectoryEntry));
fix_array = XPT_CALLOC(totalNumberOfInterfaces * sizeof(fixElement));
} else {
newIDE = PR_REALLOC(IDE_array, totalNumberOfInterfaces * sizeof(XPTInterfaceDirectoryEntry));
newFix = PR_REALLOC(fix_array, totalNumberOfInterfaces * sizeof(fixElement));
newIDE = XPT_REALLOC(IDE_array, totalNumberOfInterfaces * sizeof(XPTInterfaceDirectoryEntry));
newFix = XPT_REALLOC(fix_array, totalNumberOfInterfaces * sizeof(fixElement));
if (!newIDE) {
perror("FAILED: PR_REALLOC of IDE_array");
perror("FAILED: XPT_REALLOC of IDE_array");
return 1;
}
if (!newFix) {
perror("FAILED: PR_REALLOC of newFix");
perror("FAILED: XPT_REALLOC of newFix");
return 1;
}
IDE_array = newIDE;
@ -197,7 +197,7 @@ main(int argc, char **argv)
ann->next = header->annotations;
}
PR_FREEIF(header)
XPT_FREEIF(header);
if (state)
XPT_DestroyXDRState(state);
free(whole);
@ -564,7 +564,7 @@ update_fix_array(fixElement *fix, int element_to_delete,
return PR_FALSE;
}
deleted = PR_CALLOC(sizeof(fixElement));
deleted = XPT_CALLOC(sizeof(fixElement));
if (!copy_fixElement(&fix[element_to_delete], deleted)) {
return PR_FALSE;
}

View File

@ -42,7 +42,7 @@ CFLAGS += $(shell glib-config --cflags)
LIBXPT=$(DIST)/lib/libxpt.a
# XXX need configure test
EX_LIBS = -lIDL -L$(DIST)/bin $(LIBXPT) $(NSPR_LIBS) $(shell glib-config --libs)
EX_LIBS = -lIDL -L$(DIST)/bin $(LIBXPT) $(shell glib-config --libs)
PROGS = $(OBJDIR)/xpidl

View File

@ -44,7 +44,6 @@ MYLIBS= \
$(DIST)\lib\libxpt32.lib \
$(MOZ_TOOLS)\lib\glib-1.2.lib \
$(MOZ_TOOLS)\lib\libidl-0.6.lib \
$(LIBNSPR) \
$(NULL)
LLIBS= $(MYLIBS) \

View File

@ -211,10 +211,10 @@ fill_iid(struct nsID *id, char *str)
fprintf(stderr, "parsing iid %s\n", str);
#endif
count = PR_sscanf(str, (str[0] == '{' ? nsIDFmt1 : nsIDFmt2),
&n0, &n1, &n2,
&n3[0],&n3[1],&n3[2],&n3[3],
&n3[4],&n3[5],&n3[6],&n3[7]);
count = sscanf(str, (str[0] == '{' ? nsIDFmt1 : nsIDFmt2),
&n0, &n1, &n2,
&n3[0],&n3[1],&n3[2],&n3[3],
&n3[4],&n3[5],&n3[6],&n3[7]);
id->m0 = (PRInt32) n0;
id->m1 = (PRInt16) n1;
@ -243,7 +243,7 @@ fill_ide_table(gpointer key, gpointer value, gpointer user_data)
XPTInterfaceDirectoryEntry *ide;
char *iid;
PR_ASSERT(holder);
XPT_ASSERT(holder);
iid = holder->iid ? holder->iid : "";
#ifdef DEBUG_shaver_ifaces
@ -397,25 +397,41 @@ pass_1(TreeState *state)
} else {
/* write the typelib */
time_t now;
char *annotate_val, *data;
PRUint32 i, len, header_sz;
char *annotate_val, *data, *timestr;
PRUint32 i, len, header_sz, annotation_len, written_so_far;
XPTState *xstate = XPT_NewXDRState(XPT_ENCODE, NULL, 0);
XPTCursor curs, *cursor = &curs;
static char *annotation_format = "Created from %s.idl\nCreation date: %s"
"Interfaces:";
/* fill in the annotations, listing resolved interfaces in order */
(void)time(&now);
annotate_val = PR_smprintf("Created from %s.idl\nCreation date: %s"
"Interfaces:",
state->basename, ctime(&now));
timestr = ctime(&now);
/* Avoid dependence on nspr; no PR_smprintf and friends. */
/* How large should the annotation string be? */
annotation_len = strlen(annotation_format) + strlen(state->basename) +
strlen(timestr);
for (i = 0; i < HEADER(state)->num_interfaces; i++) {
XPTInterfaceDirectoryEntry *ide;
ide = &HEADER(state)->interface_directory[i];
if (ide->interface_descriptor) {
annotation_len += strlen(ide->name) + 1;
}
}
annotate_val = (char *) malloc(annotation_len);
written_so_far = sprintf(annotate_val, annotation_format,
state->basename, timestr);
for (i = 0; i < HEADER(state)->num_interfaces; i++) {
XPTInterfaceDirectoryEntry *ide;
ide = &HEADER(state)->interface_directory[i];
if (ide->interface_descriptor) {
annotate_val = PR_sprintf_append(annotate_val, " %s",
ide->name);
if (!annotate_val)
return FALSE;
written_so_far += sprintf(annotate_val + written_so_far,
" %s", ide->name);
}
}
@ -423,7 +439,7 @@ pass_1(TreeState *state)
XPT_NewAnnotation(XPT_ANN_LAST | XPT_ANN_PRIVATE,
XPT_NewStringZ("xpidl 0.99.9"),
XPT_NewStringZ(annotate_val));
PR_smprintf_free(annotate_val);
free(annotate_val);
#ifdef DEBUG_shaver_misc
fprintf(stderr, "writing the typelib\n");
@ -937,6 +953,7 @@ typelib_const_dcl(TreeState *state)
is_long = TRUE;
break;
default:
is_long = FALSE; /* quell warning. */
success = FALSE;
}
}

View File

@ -42,7 +42,7 @@ CFLAGS += $(shell glib-config --cflags)
LIBXPT=$(DIST)/lib/libxpt.a
# XXX need configure test
EX_LIBS = -lIDL -L$(DIST)/bin $(LIBXPT) $(NSPR_LIBS) $(shell glib-config --libs)
EX_LIBS = -lIDL -L$(DIST)/bin $(LIBXPT) $(shell glib-config --libs)
PROGS = $(OBJDIR)/xpidl

View File

@ -44,7 +44,6 @@ MYLIBS= \
$(DIST)\lib\libxpt32.lib \
$(MOZ_TOOLS)\lib\glib-1.2.lib \
$(MOZ_TOOLS)\lib\libidl-0.6.lib \
$(LIBNSPR) \
$(NULL)
LLIBS= $(MYLIBS) \

View File

@ -211,10 +211,10 @@ fill_iid(struct nsID *id, char *str)
fprintf(stderr, "parsing iid %s\n", str);
#endif
count = PR_sscanf(str, (str[0] == '{' ? nsIDFmt1 : nsIDFmt2),
&n0, &n1, &n2,
&n3[0],&n3[1],&n3[2],&n3[3],
&n3[4],&n3[5],&n3[6],&n3[7]);
count = sscanf(str, (str[0] == '{' ? nsIDFmt1 : nsIDFmt2),
&n0, &n1, &n2,
&n3[0],&n3[1],&n3[2],&n3[3],
&n3[4],&n3[5],&n3[6],&n3[7]);
id->m0 = (PRInt32) n0;
id->m1 = (PRInt16) n1;
@ -243,7 +243,7 @@ fill_ide_table(gpointer key, gpointer value, gpointer user_data)
XPTInterfaceDirectoryEntry *ide;
char *iid;
PR_ASSERT(holder);
XPT_ASSERT(holder);
iid = holder->iid ? holder->iid : "";
#ifdef DEBUG_shaver_ifaces
@ -397,25 +397,41 @@ pass_1(TreeState *state)
} else {
/* write the typelib */
time_t now;
char *annotate_val, *data;
PRUint32 i, len, header_sz;
char *annotate_val, *data, *timestr;
PRUint32 i, len, header_sz, annotation_len, written_so_far;
XPTState *xstate = XPT_NewXDRState(XPT_ENCODE, NULL, 0);
XPTCursor curs, *cursor = &curs;
static char *annotation_format = "Created from %s.idl\nCreation date: %s"
"Interfaces:";
/* fill in the annotations, listing resolved interfaces in order */
(void)time(&now);
annotate_val = PR_smprintf("Created from %s.idl\nCreation date: %s"
"Interfaces:",
state->basename, ctime(&now));
timestr = ctime(&now);
/* Avoid dependence on nspr; no PR_smprintf and friends. */
/* How large should the annotation string be? */
annotation_len = strlen(annotation_format) + strlen(state->basename) +
strlen(timestr);
for (i = 0; i < HEADER(state)->num_interfaces; i++) {
XPTInterfaceDirectoryEntry *ide;
ide = &HEADER(state)->interface_directory[i];
if (ide->interface_descriptor) {
annotation_len += strlen(ide->name) + 1;
}
}
annotate_val = (char *) malloc(annotation_len);
written_so_far = sprintf(annotate_val, annotation_format,
state->basename, timestr);
for (i = 0; i < HEADER(state)->num_interfaces; i++) {
XPTInterfaceDirectoryEntry *ide;
ide = &HEADER(state)->interface_directory[i];
if (ide->interface_descriptor) {
annotate_val = PR_sprintf_append(annotate_val, " %s",
ide->name);
if (!annotate_val)
return FALSE;
written_so_far += sprintf(annotate_val + written_so_far,
" %s", ide->name);
}
}
@ -423,7 +439,7 @@ pass_1(TreeState *state)
XPT_NewAnnotation(XPT_ANN_LAST | XPT_ANN_PRIVATE,
XPT_NewStringZ("xpidl 0.99.9"),
XPT_NewStringZ(annotate_val));
PR_smprintf_free(annotate_val);
free(annotate_val);
#ifdef DEBUG_shaver_misc
fprintf(stderr, "writing the typelib\n");
@ -937,6 +953,7 @@ typelib_const_dcl(TreeState *state)
is_long = TRUE;
break;
default:
is_long = FALSE; /* quell warning. */
success = FALSE;
}
}

View File

@ -25,6 +25,8 @@
#define __xpt_struct_h__
#include "prtypes.h"
#include <assert.h>
#include <stdlib.h>
/*
* The linkage of XPT API functions differs depending on whether the file is
@ -49,6 +51,22 @@
PR_BEGIN_EXTERN_C
/*
* Some utility macros. Defined here in lieu of equivalent NSPR
* macros, which require NSPR linkage.
*/
#define XPT_MALLOC(_bytes) (malloc((_bytes)))
#define XPT_NEW(_struct) ((_struct *) malloc(sizeof(_struct)))
#define XPT_REALLOC(_ptr, _size) (realloc((_ptr), (_size)))
#define XPT_CALLOC(_size) (calloc(1, (_size)))
#define XPT_NEWZAP(_struct) ((_struct*)calloc(1, sizeof(_struct)))
#define XPT_DELETE(_ptr) { free(_ptr); (_ptr) = NULL; }
#define XPT_FREEIF(_ptr) if (_ptr) free(_ptr)
#define XPT_FREE(_ptr) free(_ptr)
#define XPT_ASSERT(_expr) assert(_expr)
/*
* Originally, I was going to have structures that exactly matched the on-disk
* representation, but that proved difficult: different compilers can pack

View File

@ -34,6 +34,9 @@ typedef struct XPTState XPTState;
typedef struct XPTDatapool XPTDatapool;
typedef struct XPTCursor XPTCursor;
/* Opaque type, for internal use */
typedef struct XPTHashTable XPTHashTable;
extern XPT_PUBLIC_API(PRBool)
XPT_DoString(XPTCursor *cursor, XPTString **strp);
@ -101,7 +104,7 @@ struct XPTState {
};
struct XPTDatapool {
PLHashTable *offset_map;
XPTHashTable *offset_map;
char *data;
PRUint32 count;
PRUint32 allocated;
@ -190,12 +193,16 @@ XPT_GetAddrForOffset(XPTCursor *cursor, PRUint32 offset);
if (already) \
return PR_TRUE; \
/* XXXmccabe currently not used! */
/* also, XPT_ALLOC isn't defined. */
#if 0
#define XPT_PREAMBLE(cursor, addrp, pool, size, new_curs, already, \
XPTType, localp) \
{ \
XPT_PREAMBLE_(cursor, addrp, pool, size, new_curs, already); \
XPT_ALLOC(addrp, new_curs, XPTType, localp) \
}
#endif
#define XPT_PREAMBLE_NO_ALLOC(cursor, addrp, pool, size, new_curs, already) \
{ \
@ -205,7 +212,7 @@ XPT_GetAddrForOffset(XPTCursor *cursor, PRUint32 offset);
#define XPT_ERROR_HANDLE(free_it) \
error: \
if (cursor->state->mode == XPT_DECODE) \
PR_FREEIF(free_it); \
XPT_FREEIF(free_it); \
return PR_FALSE;

View File

@ -65,7 +65,7 @@ DoParamDescriptor(XPTCursor *cursor, XPTParamDescriptor *pd);
#define CURS_POOL_OFFSET_RAW(cursor) \
((cursor)->pool == XPT_HEADER \
? (cursor)->offset \
: (PR_ASSERT((cursor)->state->data_offset), \
: (XPT_ASSERT((cursor)->state->data_offset), \
(cursor)->offset + (cursor)->state->data_offset))
#define CURS_POOL_OFFSET(cursor) \
@ -105,17 +105,17 @@ XPT_SizeOfHeaderBlock(XPTHeader *header)
XPT_PUBLIC_API(XPTHeader *)
XPT_NewHeader(PRUint16 num_interfaces)
{
XPTHeader *header = PR_NEWZAP(XPTHeader);
XPTHeader *header = XPT_NEWZAP(XPTHeader);
if (!header)
return NULL;
memcpy(header->magic, XPT_MAGIC, 16);
header->major_version = XPT_MAJOR_VERSION;
header->minor_version = XPT_MINOR_VERSION;
header->num_interfaces = num_interfaces;
header->interface_directory = PR_CALLOC(num_interfaces *
sizeof(XPTInterfaceDirectoryEntry));
header->interface_directory = XPT_CALLOC(num_interfaces *
sizeof(XPTInterfaceDirectoryEntry));
if (!header->interface_directory) {
PR_DELETE(header);
XPT_DELETE(header);
return NULL;
}
header->data_pool = 0; /* XXX do we even need this struct any more? */
@ -131,7 +131,7 @@ XPT_DoHeader(XPTCursor *cursor, XPTHeader **headerp)
PRUint32 ide_offset;
int i;
if (mode == XPT_DECODE) {
header = PR_NEWZAP(XPTHeader);
header = XPT_NEWZAP(XPTHeader);
if (!header)
return PR_FALSE;
*headerp = header;
@ -169,8 +169,8 @@ XPT_DoHeader(XPTCursor *cursor, XPTHeader **headerp)
if (mode == XPT_DECODE) {
header->interface_directory =
PR_CALLOC(header->num_interfaces *
sizeof(XPTInterfaceDirectoryEntry));
XPT_CALLOC(header->num_interfaces *
sizeof(XPTInterfaceDirectoryEntry));
if (!header->interface_directory)
goto error;
}
@ -248,6 +248,7 @@ DoInterfaceDirectoryEntry(XPTCursor *cursor,
XPT_ERROR_HANDLE(ide);
}
#if 0
/*
* Decode: Get the interface directory entry for the on-disk index.
* Encode: Write the index.
@ -285,27 +286,28 @@ DoInterfaceDirectoryEntryIndex(XPTCursor *cursor,
return PR_TRUE;
}
#endif
XPT_PUBLIC_API(XPTInterfaceDescriptor *)
XPT_NewInterfaceDescriptor(PRUint16 parent_interface, PRUint16 num_methods,
PRUint16 num_constants, PRUint8 flags)
{
XPTInterfaceDescriptor *id = PR_NEWZAP(XPTInterfaceDescriptor);
XPTInterfaceDescriptor *id = XPT_NEWZAP(XPTInterfaceDescriptor);
if (!id)
return NULL;
if (num_methods) {
id->method_descriptors = PR_CALLOC(num_methods *
sizeof(XPTMethodDescriptor));
id->method_descriptors = XPT_CALLOC(num_methods *
sizeof(XPTMethodDescriptor));
if (!id->method_descriptors)
goto free_id;
id->num_methods = num_methods;
}
if (num_constants) {
id->const_descriptors = PR_CALLOC(num_constants *
sizeof(XPTConstDescriptor));
id->const_descriptors = XPT_CALLOC(num_constants *
sizeof(XPTConstDescriptor));
if (!id->const_descriptors)
goto free_meth;
id->num_constants = num_constants;
@ -322,9 +324,9 @@ XPT_NewInterfaceDescriptor(PRUint16 parent_interface, PRUint16 num_methods,
return id;
free_meth:
PR_FREEIF(id->method_descriptors);
XPT_FREEIF(id->method_descriptors);
free_id:
PR_DELETE(id);
XPT_DELETE(id);
return NULL;
}
@ -334,8 +336,8 @@ XPT_InterfaceDescriptorAddMethods(XPTInterfaceDescriptor *id, PRUint16 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));
new = XPT_REALLOC(old,
(id->num_methods + num) * sizeof(XPTMethodDescriptor));
if (!new)
return PR_FALSE;
@ -351,8 +353,8 @@ XPT_InterfaceDescriptorAddConsts(XPTInterfaceDescriptor *id, PRUint16 num)
XPTConstDescriptor *old = id->const_descriptors, *new;
/* XXX should grow in chunks to minimize realloc overhead */
new = PR_REALLOC(old,
(id->num_constants + num) * sizeof(XPTConstDescriptor));
new = XPT_REALLOC(old,
(id->num_constants + num) * sizeof(XPTConstDescriptor));
if (!new)
return PR_FALSE;
@ -441,7 +443,7 @@ DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp)
PRUint32 i, id_sz = 0;
if (mode == XPT_DECODE) {
id = PR_NEWZAP(XPTInterfaceDescriptor);
id = XPT_NEWZAP(XPTInterfaceDescriptor);
if (!id)
return PR_FALSE;
*idp = id;
@ -469,8 +471,8 @@ DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp)
}
if (mode == XPT_DECODE && id->num_methods) {
id->method_descriptors = PR_CALLOC(id->num_methods *
sizeof(XPTMethodDescriptor));
id->method_descriptors = XPT_CALLOC(id->num_methods *
sizeof(XPTMethodDescriptor));
if (!id->method_descriptors)
goto error;
}
@ -485,8 +487,8 @@ DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp)
}
if (mode == XPT_DECODE)
id->const_descriptors = PR_CALLOC(id->num_constants *
sizeof(XPTConstDescriptor));
id->const_descriptors = XPT_CALLOC(id->num_constants *
sizeof(XPTConstDescriptor));
for (i = 0; i < id->num_constants; i++) {
if (!DoConstDescriptor(cursor, &id->const_descriptors[i])) {
@ -582,21 +584,21 @@ XPT_FillMethodDescriptor(XPTMethodDescriptor *meth, PRUint8 flags, char *name,
return PR_FALSE;
meth->num_args = num_args;
if (meth->num_args) {
meth->params = PR_CALLOC(num_args * sizeof(XPTParamDescriptor));
meth->params = XPT_CALLOC(num_args * sizeof(XPTParamDescriptor));
if (!meth->params)
goto free_name;
} else {
meth->params = NULL;
}
meth->result = PR_NEWZAP(XPTParamDescriptor);
meth->result = XPT_NEWZAP(XPTParamDescriptor);
if (!meth->result)
goto free_params;
return PR_TRUE;
free_params:
PR_DELETE(meth->params);
XPT_DELETE(meth->params);
free_name:
PR_DELETE(meth->name);
XPT_DELETE(meth->name);
return PR_FALSE;
}
@ -612,7 +614,7 @@ DoMethodDescriptor(XPTCursor *cursor, XPTMethodDescriptor *md)
return PR_FALSE;
if (mode == XPT_DECODE && md->num_args) {
md->params = PR_CALLOC(md->num_args * sizeof(XPTParamDescriptor));
md->params = XPT_CALLOC(md->num_args * sizeof(XPTParamDescriptor));
if (!md->params)
return PR_FALSE;
}
@ -623,7 +625,7 @@ DoMethodDescriptor(XPTCursor *cursor, XPTMethodDescriptor *md)
}
if (mode == XPT_DECODE) {
md->result = PR_NEWZAP(XPTParamDescriptor);
md->result = XPT_NEWZAP(XPTParamDescriptor);
if (!md->result)
return PR_FALSE;
}
@ -688,7 +690,7 @@ DoTypeDescriptor(XPTCursor *cursor, XPTTypeDescriptor *td)
XPT_PUBLIC_API(XPTAnnotation *)
XPT_NewAnnotation(PRUint8 flags, XPTString *creator, XPTString *private_data)
{
XPTAnnotation *ann = PR_NEWZAP(XPTAnnotation);
XPTAnnotation *ann = XPT_NEWZAP(XPTAnnotation);
if (!ann)
return NULL;
ann->flags = flags;
@ -706,7 +708,7 @@ DoAnnotation(XPTCursor *cursor, XPTAnnotation **annp)
XPTAnnotation *ann;
if (mode == XPT_DECODE) {
ann = PR_NEWZAP(XPTAnnotation);
ann = XPT_NEWZAP(XPTAnnotation);
if (!ann)
return PR_FALSE;
*annp = ann;
@ -738,8 +740,8 @@ DoAnnotation(XPTCursor *cursor, XPTAnnotation **annp)
error_2:
if (ann && XPT_ANN_IS_PRIVATE(ann->flags)) {
PR_FREEIF(ann->creator);
PR_FREEIF(ann->private_data);
XPT_FREEIF(ann->creator);
XPT_FREEIF(ann->private_data);
}
XPT_ERROR_HANDLE(ann);
}

View File

@ -33,7 +33,7 @@ CheckForRepeat(XPTCursor *cursor, void **addrp, XPTPool pool, int len,
#define CURS_POOL_OFFSET_RAW(cursor) \
((cursor)->pool == XPT_HEADER \
? (cursor)->offset \
: (PR_ASSERT((cursor)->state->data_offset), \
: (XPT_ASSERT((cursor)->state->data_offset), \
(cursor)->offset + (cursor)->state->data_offset))
#define CURS_POOL_OFFSET(cursor) \
@ -71,17 +71,76 @@ CheckForRepeat(XPTCursor *cursor, void **addrp, XPTPool pool, int len,
#define CHECK_COUNT(cursor, space) \
(CHECK_COUNT_(cursor, space) \
? PR_TRUE \
: (PR_ASSERT(0), \
: (XPT_ASSERT(0), \
fprintf(stderr, "FATAL: can't no room for %d in cursor\n", space), \
PR_FALSE))
/* increase the data allocation for the pool by XPT_GROW_CHUNK */
#define XPT_GROW_CHUNK 8192
static PLHashNumber
null_hash(const void *key)
{
return (PLHashNumber)key;
/*
* quick and dirty hardcoded hashtable, to avoid dependence on nspr or glib.
* XXXmccabe it might turn out that we could use a simpler data structure here.
*/
typedef struct XPTHashRecord {
void *key;
void *value;
struct XPTHashRecord *next;
} XPTHashRecord;
#define XPT_HASHSIZE 32
struct XPTHashTable { /* it's already typedef'ed from before. */
XPTHashRecord *buckets[XPT_HASHSIZE];
};
static XPTHashTable *
XPT_NewHashTable() {
XPTHashTable *table;
table = XPT_NEWZAP(XPTHashTable);
return table;
}
static void trimrecord(XPTHashRecord *record) {
if (record == NULL)
return;
trimrecord(record->next);
XPT_DELETE(record);
}
static void
XPT_HashTableDestroy(XPTHashTable *table) {
int i;
for (i = 0; i < XPT_HASHSIZE; i++)
trimrecord(table->buckets[i]);
XPT_FREE(table);
}
static void *
XPT_HashTableAdd(XPTHashTable *table, void *key, void *value) {
XPTHashRecord **bucketloc = table->buckets + (((PRInt32)key) % XPT_HASHSIZE);
XPTHashRecord *bucket;
while (*bucketloc != NULL)
bucketloc = &((*bucketloc)->next);
bucket = XPT_NEW(XPTHashRecord);
bucket->key = key;
bucket->value = value;
bucket->next = NULL;
*bucketloc = bucket;
return value;
}
static void *
XPT_HashTableLookup(XPTHashTable *table, void *key) {
XPTHashRecord *bucket = table->buckets[(PRInt32)key % XPT_HASHSIZE];
while (bucket != NULL) {
if (bucket->key == key)
return bucket->value;
bucket = bucket->next;
}
return NULL;
}
XPT_PUBLIC_API(XPTState *)
@ -89,20 +148,21 @@ XPT_NewXDRState(XPTMode mode, char *data, PRUint32 len)
{
XPTState *state;
state = PR_NEW(XPTState);
state = XPT_NEW(XPTState);
if (!state)
return NULL;
state->mode = mode;
state->pool = PR_NEW(XPTDatapool);
state->pool = XPT_NEW(XPTDatapool);
state->next_cursor[0] = state->next_cursor[1] = 1;
if (!state->pool)
goto err_free_state;
state->pool->count = 0;
state->pool->offset_map = PL_NewHashTable(32, null_hash, PL_CompareValues,
PL_CompareValues, NULL, NULL);
state->pool->offset_map = XPT_NewHashTable();
/* state->pool->offset_map = PL_NewHashTable(32, null_hash, PL_CompareValues, */
/* PL_CompareValues, NULL, NULL); */
if (!state->pool->offset_map)
goto err_free_pool;
@ -110,7 +170,7 @@ XPT_NewXDRState(XPTMode mode, char *data, PRUint32 len)
state->pool->data = data;
state->pool->allocated = len;
} else {
state->pool->data = PR_MALLOC(XPT_GROW_CHUNK);
state->pool->data = XPT_MALLOC(XPT_GROW_CHUNK);
if (!state->pool->data)
goto err_free_hash;
state->pool->allocated = XPT_GROW_CHUNK;
@ -119,21 +179,24 @@ XPT_NewXDRState(XPTMode mode, char *data, PRUint32 len)
return state;
err_free_hash:
PL_HashTableDestroy(state->pool->offset_map);
XPT_HashTableDestroy(state->pool->offset_map);
/* PL_HashTableDestroy(state->pool->offset_map); */
err_free_pool:
PR_DELETE(state->pool);
XPT_DELETE(state->pool);
err_free_state:
PR_DELETE(state);
XPT_DELETE(state);
return NULL;
}
XPT_PUBLIC_API(void)
XPT_DestroyXDRState(XPTState *state)
{
if (state->pool->offset_map)
XPT_HashTableDestroy(state->pool->offset_map);
if (state->mode == XPT_ENCODE)
PR_DELETE(state->pool->data);
PR_DELETE(state->pool);
PR_DELETE(state);
XPT_DELETE(state->pool->data);
XPT_DELETE(state->pool);
XPT_DELETE(state);
}
XPT_PUBLIC_API(void)
@ -207,13 +270,13 @@ XPT_SeekTo(XPTCursor *cursor, PRUint32 offset)
XPT_PUBLIC_API(XPTString *)
XPT_NewString(PRUint16 length, char *bytes)
{
XPTString *str = PR_NEW(XPTString);
XPTString *str = XPT_NEW(XPTString);
if (!str)
return NULL;
str->length = length;
str->bytes = malloc(length);
if (!str->bytes) {
PR_DELETE(str);
XPT_DELETE(str);
return NULL;
}
memcpy(str->bytes, bytes, length);
@ -237,7 +300,7 @@ XPT_DoStringInline(XPTCursor *cursor, XPTString **strp)
int i;
if (mode == XPT_DECODE) {
str = PR_NEWZAP(XPTString);
str = XPT_NEWZAP(XPTString);
if (!str)
return PR_FALSE;
*strp = str;
@ -259,9 +322,9 @@ XPT_DoStringInline(XPTCursor *cursor, XPTString **strp)
return PR_TRUE;
error_2:
PR_DELETE(str->bytes);
XPT_DELETE(str->bytes);
error:
PR_DELETE(str);
XPT_DELETE(str);
return PR_FALSE;
}
@ -311,7 +374,7 @@ XPT_DoCString(XPTCursor *cursor, char **identp)
}
len = end - start;
ident = PR_MALLOC(len + 1);
ident = XPT_MALLOC(len + 1);
if (!ident)
return PR_FALSE;
@ -346,27 +409,33 @@ XPT_DoCString(XPTCursor *cursor, char **identp)
XPT_PUBLIC_API(PRUint32)
XPT_GetOffsetForAddr(XPTCursor *cursor, void *addr)
{
return (PRUint32)PL_HashTableLookup(cursor->state->pool->offset_map, addr);
return (PRUint32)XPT_HashTableLookup(cursor->state->pool->offset_map, addr);
/* return (PRUint32)PL_HashTableLookup(cursor->state->pool->offset_map, addr); */
}
XPT_PUBLIC_API(PRBool)
XPT_SetOffsetForAddr(XPTCursor *cursor, void *addr, PRUint32 offset)
{
return PL_HashTableAdd(cursor->state->pool->offset_map,
addr, (void *)offset) != NULL;
return XPT_HashTableAdd(cursor->state->pool->offset_map,
addr, (void *)offset) != NULL;
/* return PL_HashTableAdd(cursor->state->pool->offset_map, */
/* addr, (void *)offset) != NULL; */
}
XPT_PUBLIC_API(PRBool)
XPT_SetAddrForOffset(XPTCursor *cursor, PRUint32 offset, void *addr)
{
return PL_HashTableAdd(cursor->state->pool->offset_map,
(void *)offset, addr) != NULL;
return XPT_HashTableAdd(cursor->state->pool->offset_map,
(void *)offset, addr) != NULL;
/* return PL_HashTableAdd(cursor->state->pool->offset_map, */
/* addr, (void *)offset) != NULL; */
}
XPT_PUBLIC_API(void *)
XPT_GetAddrForOffset(XPTCursor *cursor, PRUint32 offset)
{
return PL_HashTableLookup(cursor->state->pool->offset_map, (void *)offset);
return XPT_HashTableLookup(cursor->state->pool->offset_map, (void *)offset);
/* return PL_HashTableLookup(cursor->state->pool->offset_map, (void *)offset); */
}
static PRBool

View File

@ -30,7 +30,6 @@ CSRCS = PrimitiveTest.c SimpleTypeLib.c
LIBS = \
-L$(DIST)/bin \
-lxpt \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -35,7 +35,6 @@ LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\libxpt
LLIBS= \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\libxpt32.lib \
$(LIBNSPR) \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@ -30,7 +30,6 @@ CSRCS = xpt_dump.c xpt_link.c
LIBS = \
-L$(DIST)/bin \
-lxpt \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -35,7 +35,6 @@ LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\libxpt
LLIBS= \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\libxpt32.lib \
$(LIBNSPR) \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@ -744,7 +744,10 @@ XPT_DumpConstDescriptor(XPTHeader *header, XPTConstDescriptor *cd,
const int indent, PRBool verbose_mode)
{
int new_indent = indent + BASE_INDENT;
char *out, *const_type;
char *const_type;
/* char *out; */
PRUint32 uintout;
PRInt32 intout;
if (verbose_mode) {
fprintf(stdout, "%*sName: %s\n", indent, " ", cd->name);
@ -766,28 +769,36 @@ XPT_DumpConstDescriptor(XPTHeader *header, XPTConstDescriptor *cd,
case TD_INT16:
fprintf(stdout, "%d", cd->value.i16);
break;
case TD_INT64:
/* XXX punt for now to remove NSPR linkage...
* borrow from mozilla/nsprpub/pr/src/io/prprf.c::cvt_ll? */
/* out = PR_smprintf("%lld", cd->value.i64); */
/* fputs(out, stdout); */
/* PR_smprintf_free(out); */
LL_L2I(intout, cd->value.i64);
fprintf(stdout, "%d", intout);
break;
case TD_INT32:
fprintf(stdout, "%d", cd->value.i32);
break;
case TD_INT64:
out = PR_smprintf("%lld", cd->value.i64);
fputs(out, stdout);
PR_smprintf_free(out);
break;
case TD_UINT8:
fprintf(stdout, "%d", cd->value.ui8);
break;
case TD_UINT16:
fprintf(stdout, "%d", cd->value.ui16);
break;
case TD_UINT64:
/* out = PR_smprintf("%lld", cd->value.ui64); */
/* fputs(out, stdout); */
/* PR_smprintf_free(out); */
/* XXX punt for now to remove NSPR linkage. */
LL_L2UI(uintout, cd->value.ui64);
fprintf(stdout, "%d", uintout);
break;
case TD_UINT32:
fprintf(stdout, "%d", cd->value.ui32);
break;
case TD_UINT64:
out = PR_smprintf("%lld", cd->value.ui64);
fputs(out, stdout);
PR_smprintf_free(out);
break;
case TD_FLOAT:
fprintf(stdout, "%f", cd->value.flt);
break;

View File

@ -152,18 +152,18 @@ main(int argc, char **argv)
totalNumberOfInterfaces += header->num_interfaces;
if (k == 0) {
IDE_array = PR_CALLOC(totalNumberOfInterfaces * sizeof(XPTInterfaceDirectoryEntry));
fix_array = PR_CALLOC(totalNumberOfInterfaces * sizeof(fixElement));
IDE_array = XPT_CALLOC(totalNumberOfInterfaces * sizeof(XPTInterfaceDirectoryEntry));
fix_array = XPT_CALLOC(totalNumberOfInterfaces * sizeof(fixElement));
} else {
newIDE = PR_REALLOC(IDE_array, totalNumberOfInterfaces * sizeof(XPTInterfaceDirectoryEntry));
newFix = PR_REALLOC(fix_array, totalNumberOfInterfaces * sizeof(fixElement));
newIDE = XPT_REALLOC(IDE_array, totalNumberOfInterfaces * sizeof(XPTInterfaceDirectoryEntry));
newFix = XPT_REALLOC(fix_array, totalNumberOfInterfaces * sizeof(fixElement));
if (!newIDE) {
perror("FAILED: PR_REALLOC of IDE_array");
perror("FAILED: XPT_REALLOC of IDE_array");
return 1;
}
if (!newFix) {
perror("FAILED: PR_REALLOC of newFix");
perror("FAILED: XPT_REALLOC of newFix");
return 1;
}
IDE_array = newIDE;
@ -197,7 +197,7 @@ main(int argc, char **argv)
ann->next = header->annotations;
}
PR_FREEIF(header)
XPT_FREEIF(header);
if (state)
XPT_DestroyXDRState(state);
free(whole);
@ -564,7 +564,7 @@ update_fix_array(fixElement *fix, int element_to_delete,
return PR_FALSE;
}
deleted = PR_CALLOC(sizeof(fixElement));
deleted = XPT_CALLOC(sizeof(fixElement));
if (!copy_fixElement(&fix[element_to_delete], deleted)) {
return PR_FALSE;
}