diff options
author | Yorhel <git@yorhel.nl> | 2014-08-18 15:49:32 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2014-08-18 15:49:49 +0200 |
commit | 49a943d037352d6c15d4b3d2109ce40010e3f299 (patch) | |
tree | 82321c21e944081bd6f802ccb194b9cc8385fe48 | |
parent | a19e8244dd57b161858c3a793b255a0d72035ebc (diff) |
More portable definition of ypc_val_parser
Turns out bit flags work differently on mingw, so I switched to uint8_t's. I
also changed the utf8 decode function to be able to handle bit-flagged state,
but that turned out not be necessary at the moment. Still useful if the bit
flags turn out to be needed in the future.
-rw-r--r-- | build.bat | 2 | ||||
-rw-r--r-- | lib/util/utf8.h | 10 | ||||
-rw-r--r-- | lib/val/ypc_val_parse.c | 3 | ||||
-rw-r--r-- | lib/ypc.h | 8 |
4 files changed, 11 insertions, 12 deletions
@@ -1,2 +1,2 @@ REM A proper build system would be great... -CL /LD /O2 /nologo /MT ws2_32.lib advapi32.lib lib/*.c lib/util/*.c lib/net/*.c /link /OUT:ypc.dll /IMPLIB:ypc.lib +CL /LD /O2 /nologo /MT ws2_32.lib advapi32.lib lib/*.c lib/util/*.c lib/net/*.c lib/val/*.c /link /OUT:ypc.dll /IMPLIB:ypc.lib diff --git a/lib/util/utf8.h b/lib/util/utf8.h index b284c14..cd60c5d 100644 --- a/lib/util/utf8.h +++ b/lib/util/utf8.h @@ -4,8 +4,7 @@ * Minor modifications for ypc: * - Split into .c/.h files * - Renamed global symbols - * - Reduced state to a uint8_t (possibly making things slower, but reducing - * the parsing state of serialized values) + * - Changed state argument to be a scalar value rather than a pointer */ #include <stdint.h> @@ -15,14 +14,13 @@ extern const uint8_t ypc__utf8d[]; -static inline uint32_t ypc__utf8_decode(uint8_t* state, uint32_t* codep, uint32_t byte) { +static inline uint32_t ypc__utf8_decode(uint32_t state, uint32_t* codep, uint32_t byte) { uint32_t type = ypc__utf8d[byte]; - *codep = (*state != UTF8_ACCEPT) ? + *codep = (state != UTF8_ACCEPT) ? (byte & 0x3fu) | (*codep << 6) : (0xff >> type) & (byte); - *state = ypc__utf8d[256 + *state + type]; - return *state; + return ypc__utf8d[256 + state + type]; } diff --git a/lib/val/ypc_val_parse.c b/lib/val/ypc_val_parse.c index 603a01c..3065876 100644 --- a/lib/val/ypc_val_parse.c +++ b/lib/val/ypc_val_parse.c @@ -128,7 +128,8 @@ YPC_EXPORT int ypc_val_parse(ypc_val_parser *p, const uint8_t *buf, size_t *lenp case YPCP_TEXT: { uint32_t codepoint; - if(ypc__utf8_decode(&p->utf8state, &codepoint, *buf) == UTF8_REJECT) + p->utf8state = ypc__utf8_decode(p->utf8state, &codepoint, *buf); + if(p->utf8state == UTF8_REJECT) r = -1; else if(*buf == 0) r = p->utf8state == UTF8_ACCEPT ? ypc__parse_endval(p) : -1; @@ -70,10 +70,10 @@ typedef enum { typedef struct { uint32_t len; uint32_t bitmap; - uint32_t depth : 6; - uint32_t state : 3; - bool wantval : 1; - uint8_t utf8state; + uint8_t utf8state; /* Can be reduced to 7 bits (or less, 4 least significant bits are always 0) */ + uint8_t depth; /* Can be reduced to 6 bits */ + uint8_t state; /* Can be reduced to 3 bits */ + uint8_t wantval; /* Can be reduced to 1 bit */ uint32_t pad; } ypc_val_parser; |