From ceed9b8853ab7b10e5a9e39704e712bfce53ce8a Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Mon, 6 May 2019 17:26:38 -0700 Subject: [PATCH] Sand edges down on GBIT64()/PBIT64() macros. Now, you can safely use them in unbraced if statements, and with char*s. --- sys/include/fcall.h | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/sys/include/fcall.h b/sys/include/fcall.h index 25a73636f..d68b405a0 100644 --- a/sys/include/fcall.h +++ b/sys/include/fcall.h @@ -61,17 +61,20 @@ struct Fcall } Fcall; -#define GBIT8(p) ((p)[0]) -#define GBIT16(p) ((p)[0]|((p)[1]<<8)) -#define GBIT32(p) ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) -#define GBIT64(p) ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\ - ((vlong)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32)) +#define GBIT8(p) (((uchar*)(p))[0]) +#define GBIT16(p) (((uchar*)(p))[0]|(((uchar*)(p))[1]<<8)) +#define GBIT32(p) (((uchar*)(p))[0]|(((uchar*)(p))[1]<<8)|\ + (((uchar*)(p))[2]<<16)|(((uchar*)(p))[3]<<24)) +#define GBIT64(p) ((u32int)(((uchar*)(p))[0]|(((uchar*)(p))[1]<<8)|\ + (((uchar*)(p))[2]<<16)|(((uchar*)(p))[3]<<24)) |\ + ((uvlong)(((uchar*)(p))[4]|(((uchar*)(p))[5]<<8)|\ + (((uchar*)(p))[6]<<16)|(((uchar*)(p))[7]<<24)) << 32)) -#define PBIT8(p,v) (p)[0]=(v) -#define PBIT16(p,v) (p)[0]=(v);(p)[1]=(v)>>8 -#define PBIT32(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24 -#define PBIT64(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\ - (p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56 +#define PBIT8(p,v) do{(p)[0]=(v);}while(0) +#define PBIT16(p,v) do{(p)[0]=(v);(p)[1]=(v)>>8;}while(0) +#define PBIT32(p,v) do{(p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;}while(0) +#define PBIT64(p,v) do{(p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\ + (p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56;}while(0) #define BIT8SZ 1 #define BIT16SZ 2