Adding a size field to events so that a reader can skip unknown event codes (unimplemented).

Copied from Perforce
 Change: 179019
 ServerID: perforce.ravenbrook.com
This commit is contained in:
Richard Brooksby 2012-08-22 09:16:03 +01:00
parent d3a49735dc
commit 76ab2591ef
3 changed files with 13 additions and 3 deletions

View file

@ -80,6 +80,9 @@ Res EventInit(void)
{
Res res;
/* Ensure that no event can be larger than the maximum event size. */
AVER(EventBufferSIZE <= EventSizeMAX);
/* Only if this is the first call. */
if(!eventInited) { /* See .trans.log */
AVER(EventNext == 0);

View file

@ -40,16 +40,17 @@ extern Res EventFlush(void);
extern char *EventNext, *EventLimit;
extern Word EventKindControl;
#define EVENT_BEGIN(name, size) \
#define EVENT_BEGIN(name, structSize) \
BEGIN \
if(BS_IS_MEMBER(EventKindControl, ((Index)Event##name##Kind))) { \
Event##name##Struct *_event; \
size_t _size = size_tAlignUp(size, MPS_PF_ALIGN); \
size_t _size = size_tAlignUp(structSize, MPS_PF_ALIGN); \
if (_size > (size_t)(EventLimit - EventNext)) \
EventFlush(); \
AVER(_size <= (size_t)(EventLimit - EventNext)); \
_event = (void *)EventNext; \
_event->code = Event##name##Code; \
_event->size = (EventSize)_size; \
_event->clock = mps_clock();
#define EVENT_END(name, size) \

View file

@ -9,6 +9,7 @@
#ifndef eventcom_h
#define eventcom_h
#include <limits.h>
#include "mpmtypes.h" /* for Word */
#include "eventdef.h"
@ -17,6 +18,8 @@
typedef unsigned short EventCode;
typedef unsigned EventKind;
typedef unsigned short EventSize;
#define EventSizeMAX USHRT_MAX
typedef Byte EventStringLen;
@ -80,15 +83,18 @@ typedef unsigned EventFU;
typedef EventStringStruct EventFS;
typedef double EventFD;
/* Common prefix for all event structures */
/* Common prefix for all event structures. The size field allows an event
reader to skip over events whose codes it does not recognise. */
typedef struct EventAnyStruct {
EventCode code;
EventSize size;
Word clock;
} EventAnyStruct;
#define EVENT_STRUCT(X, name, _code, always, kind, count, format) \
typedef struct Event##name##Struct { \
EventCode code; \
EventSize size; \
Word clock; \
EVENT_STRUCT_FIELDS_##count format \
} Event##name##Struct;