diff options
| author | Richard Brooksby | 2012-08-22 09:16:03 +0100 |
|---|---|---|
| committer | Richard Brooksby | 2012-08-22 09:16:03 +0100 |
| commit | 76ab2591ef672a5bbd3e18582373a0ca8359ad71 (patch) | |
| tree | fe892c0853592cb985d460153b84580daa2415ea /mps/code | |
| parent | d3a49735dc93c9e4b1dda3bb36df39554461e162 (diff) | |
| download | emacs-76ab2591ef672a5bbd3e18582373a0ca8359ad71.tar.gz emacs-76ab2591ef672a5bbd3e18582373a0ca8359ad71.zip | |
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
Diffstat (limited to 'mps/code')
| -rw-r--r-- | mps/code/event.c | 3 | ||||
| -rw-r--r-- | mps/code/event.h | 5 | ||||
| -rw-r--r-- | mps/code/eventcom.h | 8 |
3 files changed, 13 insertions, 3 deletions
diff --git a/mps/code/event.c b/mps/code/event.c index 0b4d16353b4..c16ac133bbe 100644 --- a/mps/code/event.c +++ b/mps/code/event.c | |||
| @@ -80,6 +80,9 @@ Res EventInit(void) | |||
| 80 | { | 80 | { |
| 81 | Res res; | 81 | Res res; |
| 82 | 82 | ||
| 83 | /* Ensure that no event can be larger than the maximum event size. */ | ||
| 84 | AVER(EventBufferSIZE <= EventSizeMAX); | ||
| 85 | |||
| 83 | /* Only if this is the first call. */ | 86 | /* Only if this is the first call. */ |
| 84 | if(!eventInited) { /* See .trans.log */ | 87 | if(!eventInited) { /* See .trans.log */ |
| 85 | AVER(EventNext == 0); | 88 | AVER(EventNext == 0); |
diff --git a/mps/code/event.h b/mps/code/event.h index f089560cf4d..99373c1712f 100644 --- a/mps/code/event.h +++ b/mps/code/event.h | |||
| @@ -40,16 +40,17 @@ extern Res EventFlush(void); | |||
| 40 | extern char *EventNext, *EventLimit; | 40 | extern char *EventNext, *EventLimit; |
| 41 | extern Word EventKindControl; | 41 | extern Word EventKindControl; |
| 42 | 42 | ||
| 43 | #define EVENT_BEGIN(name, size) \ | 43 | #define EVENT_BEGIN(name, structSize) \ |
| 44 | BEGIN \ | 44 | BEGIN \ |
| 45 | if(BS_IS_MEMBER(EventKindControl, ((Index)Event##name##Kind))) { \ | 45 | if(BS_IS_MEMBER(EventKindControl, ((Index)Event##name##Kind))) { \ |
| 46 | Event##name##Struct *_event; \ | 46 | Event##name##Struct *_event; \ |
| 47 | size_t _size = size_tAlignUp(size, MPS_PF_ALIGN); \ | 47 | size_t _size = size_tAlignUp(structSize, MPS_PF_ALIGN); \ |
| 48 | if (_size > (size_t)(EventLimit - EventNext)) \ | 48 | if (_size > (size_t)(EventLimit - EventNext)) \ |
| 49 | EventFlush(); \ | 49 | EventFlush(); \ |
| 50 | AVER(_size <= (size_t)(EventLimit - EventNext)); \ | 50 | AVER(_size <= (size_t)(EventLimit - EventNext)); \ |
| 51 | _event = (void *)EventNext; \ | 51 | _event = (void *)EventNext; \ |
| 52 | _event->code = Event##name##Code; \ | 52 | _event->code = Event##name##Code; \ |
| 53 | _event->size = (EventSize)_size; \ | ||
| 53 | _event->clock = mps_clock(); | 54 | _event->clock = mps_clock(); |
| 54 | 55 | ||
| 55 | #define EVENT_END(name, size) \ | 56 | #define EVENT_END(name, size) \ |
diff --git a/mps/code/eventcom.h b/mps/code/eventcom.h index f0f4bfdcc5f..1db05d4c0fe 100644 --- a/mps/code/eventcom.h +++ b/mps/code/eventcom.h | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #ifndef eventcom_h | 9 | #ifndef eventcom_h |
| 10 | #define eventcom_h | 10 | #define eventcom_h |
| 11 | 11 | ||
| 12 | #include <limits.h> | ||
| 12 | #include "mpmtypes.h" /* for Word */ | 13 | #include "mpmtypes.h" /* for Word */ |
| 13 | #include "eventdef.h" | 14 | #include "eventdef.h" |
| 14 | 15 | ||
| @@ -17,6 +18,8 @@ | |||
| 17 | 18 | ||
| 18 | typedef unsigned short EventCode; | 19 | typedef unsigned short EventCode; |
| 19 | typedef unsigned EventKind; | 20 | typedef unsigned EventKind; |
| 21 | typedef unsigned short EventSize; | ||
| 22 | #define EventSizeMAX USHRT_MAX | ||
| 20 | 23 | ||
| 21 | typedef Byte EventStringLen; | 24 | typedef Byte EventStringLen; |
| 22 | 25 | ||
| @@ -80,15 +83,18 @@ typedef unsigned EventFU; | |||
| 80 | typedef EventStringStruct EventFS; | 83 | typedef EventStringStruct EventFS; |
| 81 | typedef double EventFD; | 84 | typedef double EventFD; |
| 82 | 85 | ||
| 83 | /* Common prefix for all event structures */ | 86 | /* Common prefix for all event structures. The size field allows an event |
| 87 | reader to skip over events whose codes it does not recognise. */ | ||
| 84 | typedef struct EventAnyStruct { | 88 | typedef struct EventAnyStruct { |
| 85 | EventCode code; | 89 | EventCode code; |
| 90 | EventSize size; | ||
| 86 | Word clock; | 91 | Word clock; |
| 87 | } EventAnyStruct; | 92 | } EventAnyStruct; |
| 88 | 93 | ||
| 89 | #define EVENT_STRUCT(X, name, _code, always, kind, count, format) \ | 94 | #define EVENT_STRUCT(X, name, _code, always, kind, count, format) \ |
| 90 | typedef struct Event##name##Struct { \ | 95 | typedef struct Event##name##Struct { \ |
| 91 | EventCode code; \ | 96 | EventCode code; \ |
| 97 | EventSize size; \ | ||
| 92 | Word clock; \ | 98 | Word clock; \ |
| 93 | EVENT_STRUCT_FIELDS_##count format \ | 99 | EVENT_STRUCT_FIELDS_##count format \ |
| 94 | } Event##name##Struct; | 100 | } Event##name##Struct; |