mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 07:15:46 +00:00
more header goo, xdr implementation stubs
This commit is contained in:
parent
68750d1591
commit
82abed2f8f
@ -48,7 +48,6 @@ typedef struct XPTTypeDescriptorPrefix XPTTypeDescriptorPrefix;
|
||||
typedef struct XPTSimpleTypeDescriptor XPTSimpleTypeDescriptor;
|
||||
typedef struct XPTInterfaceDescriptor XPTInterfaceDescriptor;
|
||||
typedef struct XPTInterfaceIsTypeDescriptor XPTInterfaceIsTypeDescriptor;
|
||||
typedef char *XPTIdentifier;
|
||||
typedef struct XPTString XPTString;
|
||||
typedef struct XPTAnnotationPrefix XPTAnnotationPrefix;
|
||||
typedef struct XPTEmptyAnnotation XPTEmptyAnnotation;
|
||||
@ -79,8 +78,8 @@ struct XPTInterfaceDescriptor {
|
||||
XPTConstDescriptor *const_descriptors;
|
||||
};
|
||||
|
||||
struct XPTConstDescriptorD {
|
||||
XPTIdentifier name;
|
||||
struct XPTConstDescriptor {
|
||||
char *name;
|
||||
XPTTypeDescriptor type;
|
||||
char value[0]; /* really varies according to type */
|
||||
};
|
||||
@ -88,7 +87,7 @@ struct XPTConstDescriptorD {
|
||||
struct XPTMethodDescriptor {
|
||||
uint8 is_getter:1, is_setter:1, is_varargs:1,
|
||||
is_constructor:1, reserved:4;
|
||||
XPTIdentifier name;
|
||||
char *name;
|
||||
uint8 num_args;
|
||||
XPTParamDescriptor *params;
|
||||
XPTParamDescriptor *result;
|
||||
@ -110,7 +109,7 @@ struct XPTSimpleTypeDescriptor {
|
||||
|
||||
struct XPTInterfaceTypeDescriptor {
|
||||
XPTTypeDescriptorPrefix prefix;
|
||||
XPTInterfaceDirectoryEntry *interface; /* XPTInterfaceDirectoryEntryD */
|
||||
XPTInterfaceDirectoryEntry *interface;
|
||||
};
|
||||
|
||||
struct XPTInterfaceIsTypeDescriptor {
|
||||
|
@ -34,7 +34,17 @@ PRBool
|
||||
XPT_DoString(XPTXDRState *state, XPTString **strp);
|
||||
|
||||
PRBool
|
||||
XPT_DoIdentifier(XPTState *state, XPTIdentifier *identp);
|
||||
XPT_DoIdentifier(XPTState *state, char **identp);
|
||||
|
||||
/*
|
||||
* XXX need to think about ordering and API issues for offset<->addr
|
||||
* XXX conversion
|
||||
*/
|
||||
PRBool
|
||||
XPT_GetOffsetForAddr(XPTXDRState *state, void *addr, uint32 *offsetp);
|
||||
|
||||
PRBool
|
||||
XPT_GetAddrForOffset(XPTXDRState *state, uint32 offset, void **addr);
|
||||
|
||||
PRBool
|
||||
XPT_Do32(XPTXDRState *state, uint32 *u32p);
|
||||
@ -46,35 +56,18 @@ PRBool
|
||||
XPT_Do8(XPTXDRState *state, uint8 *u8p);
|
||||
|
||||
/*
|
||||
* When working with bitfields, use the Do7-Do1 calls with a uint8.
|
||||
* Only the appropriate number of bits are manipulated, and when in decode
|
||||
* mode, the rest are zeroed. When you're done sending bits along, use
|
||||
* When working with bitfields, use the DoBits call with a uint8.
|
||||
* Only the appropriate number of bits are manipulated, so when
|
||||
* you're decoding you probably want to ensure that the uint8 is pre-zeroed.
|
||||
* When you're done sending bits along, use
|
||||
* XPT_FlushBits to make sure that you don't eat a leading bit from the
|
||||
* next structure. (You should probably be writing full bytes' worth of bits
|
||||
* anyway, and zeroing out the bits you don't use, but just to be sure...
|
||||
* anyway, and zeroing out the bits you don't use, but just to be sure...)
|
||||
*/
|
||||
|
||||
PRBool
|
||||
XPT_DoBits(XPTXDRState *state, uint8 *u8p, uintN nbits);
|
||||
|
||||
PRBool
|
||||
XPT_Do6(XPTXDRState *state, uint8 *u6p);
|
||||
|
||||
PRBool
|
||||
XPT_Do5(XPTXDRState *state, uint8 *u5p);
|
||||
|
||||
PRBool
|
||||
XPT_Do4(XPTXDRState *state, uint8 *u4p);
|
||||
|
||||
PRBool
|
||||
XPT_Do3(XPTXDRState *state, uint8 *u3p);
|
||||
|
||||
PRBool
|
||||
XPT_Do2(XPTXDRState *state, uint8 *u2p);
|
||||
|
||||
PRBool
|
||||
XPT_Do1(XPTXDRState *state, uint8 *u1p);
|
||||
|
||||
/* returns the number of bits skipped, which should be 0-7 */
|
||||
int
|
||||
XPT_FlushBits(XPTXDRState *state);
|
||||
@ -91,12 +84,17 @@ struct XPTXDRState {
|
||||
|
||||
struct XPTXDRDatapool {
|
||||
PLHash *offset_map;
|
||||
void *data;
|
||||
char *data;
|
||||
uint32 point;
|
||||
uint8 bits;
|
||||
uint8 bit;
|
||||
uint32 allocated;
|
||||
};
|
||||
|
||||
/* increase the data allocation for the pool by XPT_GROW_CHUNK */
|
||||
#define XPT_GROW_CHUNK 8192
|
||||
PRBool
|
||||
XPT_GrowPool(XPTXDRDatapool *pool);
|
||||
|
||||
/* all data structures are big-endian */
|
||||
|
||||
#if defined IS_BIG_ENDIAN
|
||||
|
129
xpcom/libxpt/src/xpt_xdr.c
Normal file
129
xpcom/libxpt/src/xpt_xdr.c
Normal file
@ -0,0 +1,129 @@
|
||||
#define CHECK_COUNT(state) \
|
||||
((state)->pool->count > (state)->pool->allocated ? \
|
||||
((state)->mode == XPTXDR_ENCODE ? XPT_GrowPool((state)->pool) : \
|
||||
PR_FALSE) : PR_TRUE)
|
||||
|
||||
PRBool
|
||||
XPT_GrowPool(XPTXDRDatapool *pool)
|
||||
{
|
||||
char *newdata = realloc(pool->data, pool->allocated + XPT_GROW_CHUNK);
|
||||
if (!newdata)
|
||||
return PR_FALSE;
|
||||
pool->data = newdata;
|
||||
pool->allocated += XPT_GROW_CHUNK;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_DoString(XPTXDRState *state, XPTString **strp)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_DoIdentifier(XPTXDRState *state, char **identp)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_Do32(XPTXDRState *state, uint32 *u32p)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_Do16(XPTXDRState *state, uint16 *u16p)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_Do8(XPTXDRState *state, uint8 *u8p)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_GetOffsetForAddr(XPTXDRState *state, void *addr, uint32 *offsetp)
|
||||
{
|
||||
*offsetp = 0;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_GetAddrForOffset(XPTXDRState *state, uint32 offset, void **addr)
|
||||
{
|
||||
*addr = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
static PRBool
|
||||
do_bit(XPTXDRState *state, uint8 *u8p, int bitno)
|
||||
{
|
||||
int bit_value, delta, new_value;
|
||||
XPTXDRDatapool *pool = state->pool;
|
||||
|
||||
if (state->mode == XPTXDR_ENCODE) {
|
||||
bit_value = (*u8p & 1) << (bitno); /* 7 = 0100 0000, 6 = 0010 0000 */
|
||||
if (bit_value) {
|
||||
delta = pool->bit + (bitno) - 7;
|
||||
new_value = delta >= 0 ? bit_value >> delta : bit_value << -delta;
|
||||
pool->data[pool->count] |= new_value;
|
||||
}
|
||||
} else {
|
||||
bit_value = pool->data[pool->count] & (1 << (7 - pool->bit));
|
||||
*u2p = bit_value >> (7 - pool->bit);
|
||||
}
|
||||
if (++pool->bit == 8) {
|
||||
pool->count++;
|
||||
pool->bit = 0;
|
||||
}
|
||||
|
||||
return CHECK_COUNT(state);
|
||||
}
|
||||
|
||||
int
|
||||
XPT_DoBits(XPTXDRState *state, uint8 *u8p, uintN nbits)
|
||||
{
|
||||
|
||||
#define DO_BIT(state, u8p, nbits) \
|
||||
if (!do_bit(state, u8p, nbits)) \
|
||||
return PR_FALSE;
|
||||
|
||||
switch(nbits) {
|
||||
case 7:
|
||||
DO_BIT(state, u8p, 7);
|
||||
case 6:
|
||||
DO_BIT(state, u8p, 6);
|
||||
case 5:
|
||||
DO_BIT(state, u8p, 5);
|
||||
case 4:
|
||||
DO_BIT(state, u8p, 4);
|
||||
case 3:
|
||||
DO_BIT(state, u8p, 3);
|
||||
case 2:
|
||||
DO_BIT(state, u8p, 2);
|
||||
case 1:
|
||||
DO_BIT(state, u8p, 1);
|
||||
default:;
|
||||
};
|
||||
|
||||
#undef DO_BIT
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
XPT_FlushBits(XPTXDRState *state)
|
||||
{
|
||||
int skipped = 8 - state->pool->bits;
|
||||
|
||||
state->pool->bits = 0;
|
||||
state->count++;
|
||||
|
||||
if (!CHECK_COUNT(state))
|
||||
return -1;
|
||||
|
||||
return skipped == 8 ? 0 : skipped;
|
||||
}
|
@ -48,7 +48,6 @@ typedef struct XPTTypeDescriptorPrefix XPTTypeDescriptorPrefix;
|
||||
typedef struct XPTSimpleTypeDescriptor XPTSimpleTypeDescriptor;
|
||||
typedef struct XPTInterfaceDescriptor XPTInterfaceDescriptor;
|
||||
typedef struct XPTInterfaceIsTypeDescriptor XPTInterfaceIsTypeDescriptor;
|
||||
typedef char *XPTIdentifier;
|
||||
typedef struct XPTString XPTString;
|
||||
typedef struct XPTAnnotationPrefix XPTAnnotationPrefix;
|
||||
typedef struct XPTEmptyAnnotation XPTEmptyAnnotation;
|
||||
@ -79,8 +78,8 @@ struct XPTInterfaceDescriptor {
|
||||
XPTConstDescriptor *const_descriptors;
|
||||
};
|
||||
|
||||
struct XPTConstDescriptorD {
|
||||
XPTIdentifier name;
|
||||
struct XPTConstDescriptor {
|
||||
char *name;
|
||||
XPTTypeDescriptor type;
|
||||
char value[0]; /* really varies according to type */
|
||||
};
|
||||
@ -88,7 +87,7 @@ struct XPTConstDescriptorD {
|
||||
struct XPTMethodDescriptor {
|
||||
uint8 is_getter:1, is_setter:1, is_varargs:1,
|
||||
is_constructor:1, reserved:4;
|
||||
XPTIdentifier name;
|
||||
char *name;
|
||||
uint8 num_args;
|
||||
XPTParamDescriptor *params;
|
||||
XPTParamDescriptor *result;
|
||||
@ -110,7 +109,7 @@ struct XPTSimpleTypeDescriptor {
|
||||
|
||||
struct XPTInterfaceTypeDescriptor {
|
||||
XPTTypeDescriptorPrefix prefix;
|
||||
XPTInterfaceDirectoryEntry *interface; /* XPTInterfaceDirectoryEntryD */
|
||||
XPTInterfaceDirectoryEntry *interface;
|
||||
};
|
||||
|
||||
struct XPTInterfaceIsTypeDescriptor {
|
||||
|
@ -34,7 +34,17 @@ PRBool
|
||||
XPT_DoString(XPTXDRState *state, XPTString **strp);
|
||||
|
||||
PRBool
|
||||
XPT_DoIdentifier(XPTState *state, XPTIdentifier *identp);
|
||||
XPT_DoIdentifier(XPTState *state, char **identp);
|
||||
|
||||
/*
|
||||
* XXX need to think about ordering and API issues for offset<->addr
|
||||
* XXX conversion
|
||||
*/
|
||||
PRBool
|
||||
XPT_GetOffsetForAddr(XPTXDRState *state, void *addr, uint32 *offsetp);
|
||||
|
||||
PRBool
|
||||
XPT_GetAddrForOffset(XPTXDRState *state, uint32 offset, void **addr);
|
||||
|
||||
PRBool
|
||||
XPT_Do32(XPTXDRState *state, uint32 *u32p);
|
||||
@ -46,35 +56,18 @@ PRBool
|
||||
XPT_Do8(XPTXDRState *state, uint8 *u8p);
|
||||
|
||||
/*
|
||||
* When working with bitfields, use the Do7-Do1 calls with a uint8.
|
||||
* Only the appropriate number of bits are manipulated, and when in decode
|
||||
* mode, the rest are zeroed. When you're done sending bits along, use
|
||||
* When working with bitfields, use the DoBits call with a uint8.
|
||||
* Only the appropriate number of bits are manipulated, so when
|
||||
* you're decoding you probably want to ensure that the uint8 is pre-zeroed.
|
||||
* When you're done sending bits along, use
|
||||
* XPT_FlushBits to make sure that you don't eat a leading bit from the
|
||||
* next structure. (You should probably be writing full bytes' worth of bits
|
||||
* anyway, and zeroing out the bits you don't use, but just to be sure...
|
||||
* anyway, and zeroing out the bits you don't use, but just to be sure...)
|
||||
*/
|
||||
|
||||
PRBool
|
||||
XPT_DoBits(XPTXDRState *state, uint8 *u8p, uintN nbits);
|
||||
|
||||
PRBool
|
||||
XPT_Do6(XPTXDRState *state, uint8 *u6p);
|
||||
|
||||
PRBool
|
||||
XPT_Do5(XPTXDRState *state, uint8 *u5p);
|
||||
|
||||
PRBool
|
||||
XPT_Do4(XPTXDRState *state, uint8 *u4p);
|
||||
|
||||
PRBool
|
||||
XPT_Do3(XPTXDRState *state, uint8 *u3p);
|
||||
|
||||
PRBool
|
||||
XPT_Do2(XPTXDRState *state, uint8 *u2p);
|
||||
|
||||
PRBool
|
||||
XPT_Do1(XPTXDRState *state, uint8 *u1p);
|
||||
|
||||
/* returns the number of bits skipped, which should be 0-7 */
|
||||
int
|
||||
XPT_FlushBits(XPTXDRState *state);
|
||||
@ -91,12 +84,17 @@ struct XPTXDRState {
|
||||
|
||||
struct XPTXDRDatapool {
|
||||
PLHash *offset_map;
|
||||
void *data;
|
||||
char *data;
|
||||
uint32 point;
|
||||
uint8 bits;
|
||||
uint8 bit;
|
||||
uint32 allocated;
|
||||
};
|
||||
|
||||
/* increase the data allocation for the pool by XPT_GROW_CHUNK */
|
||||
#define XPT_GROW_CHUNK 8192
|
||||
PRBool
|
||||
XPT_GrowPool(XPTXDRDatapool *pool);
|
||||
|
||||
/* all data structures are big-endian */
|
||||
|
||||
#if defined IS_BIG_ENDIAN
|
||||
|
129
xpcom/typelib/xpt/src/xpt_xdr.c
Normal file
129
xpcom/typelib/xpt/src/xpt_xdr.c
Normal file
@ -0,0 +1,129 @@
|
||||
#define CHECK_COUNT(state) \
|
||||
((state)->pool->count > (state)->pool->allocated ? \
|
||||
((state)->mode == XPTXDR_ENCODE ? XPT_GrowPool((state)->pool) : \
|
||||
PR_FALSE) : PR_TRUE)
|
||||
|
||||
PRBool
|
||||
XPT_GrowPool(XPTXDRDatapool *pool)
|
||||
{
|
||||
char *newdata = realloc(pool->data, pool->allocated + XPT_GROW_CHUNK);
|
||||
if (!newdata)
|
||||
return PR_FALSE;
|
||||
pool->data = newdata;
|
||||
pool->allocated += XPT_GROW_CHUNK;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_DoString(XPTXDRState *state, XPTString **strp)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_DoIdentifier(XPTXDRState *state, char **identp)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_Do32(XPTXDRState *state, uint32 *u32p)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_Do16(XPTXDRState *state, uint16 *u16p)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_Do8(XPTXDRState *state, uint8 *u8p)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_GetOffsetForAddr(XPTXDRState *state, void *addr, uint32 *offsetp)
|
||||
{
|
||||
*offsetp = 0;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
XPT_GetAddrForOffset(XPTXDRState *state, uint32 offset, void **addr)
|
||||
{
|
||||
*addr = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
static PRBool
|
||||
do_bit(XPTXDRState *state, uint8 *u8p, int bitno)
|
||||
{
|
||||
int bit_value, delta, new_value;
|
||||
XPTXDRDatapool *pool = state->pool;
|
||||
|
||||
if (state->mode == XPTXDR_ENCODE) {
|
||||
bit_value = (*u8p & 1) << (bitno); /* 7 = 0100 0000, 6 = 0010 0000 */
|
||||
if (bit_value) {
|
||||
delta = pool->bit + (bitno) - 7;
|
||||
new_value = delta >= 0 ? bit_value >> delta : bit_value << -delta;
|
||||
pool->data[pool->count] |= new_value;
|
||||
}
|
||||
} else {
|
||||
bit_value = pool->data[pool->count] & (1 << (7 - pool->bit));
|
||||
*u2p = bit_value >> (7 - pool->bit);
|
||||
}
|
||||
if (++pool->bit == 8) {
|
||||
pool->count++;
|
||||
pool->bit = 0;
|
||||
}
|
||||
|
||||
return CHECK_COUNT(state);
|
||||
}
|
||||
|
||||
int
|
||||
XPT_DoBits(XPTXDRState *state, uint8 *u8p, uintN nbits)
|
||||
{
|
||||
|
||||
#define DO_BIT(state, u8p, nbits) \
|
||||
if (!do_bit(state, u8p, nbits)) \
|
||||
return PR_FALSE;
|
||||
|
||||
switch(nbits) {
|
||||
case 7:
|
||||
DO_BIT(state, u8p, 7);
|
||||
case 6:
|
||||
DO_BIT(state, u8p, 6);
|
||||
case 5:
|
||||
DO_BIT(state, u8p, 5);
|
||||
case 4:
|
||||
DO_BIT(state, u8p, 4);
|
||||
case 3:
|
||||
DO_BIT(state, u8p, 3);
|
||||
case 2:
|
||||
DO_BIT(state, u8p, 2);
|
||||
case 1:
|
||||
DO_BIT(state, u8p, 1);
|
||||
default:;
|
||||
};
|
||||
|
||||
#undef DO_BIT
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
XPT_FlushBits(XPTXDRState *state)
|
||||
{
|
||||
int skipped = 8 - state->pool->bits;
|
||||
|
||||
state->pool->bits = 0;
|
||||
state->count++;
|
||||
|
||||
if (!CHECK_COUNT(state))
|
||||
return -1;
|
||||
|
||||
return skipped == 8 ? 0 : skipped;
|
||||
}
|
Loading…
Reference in New Issue
Block a user