Commit adbf5561 authored by Radford Neal's avatar Radford Neal

fixes and tests for serialize/unserialize

parent 26499efc
...@@ -217,8 +217,8 @@ static int Rsnprintf(char *buf, int size, const char *format, ...) ...@@ -217,8 +217,8 @@ static int Rsnprintf(char *buf, int size, const char *format, ...)
static inline void encode_integer(int i, void *buf) static inline void encode_integer(int i, void *buf)
{ {
# if __GNUC__ # if __GNUC__ && defined(__BYTE_ORDER__)
# if __BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
i = __builtin_bswap32(i); i = __builtin_bswap32(i);
# endif # endif
memcpy(buf,&i,sizeof(int)); memcpy(buf,&i,sizeof(int));
...@@ -235,8 +235,8 @@ static inline void encode_double(double d, void *buf) ...@@ -235,8 +235,8 @@ static inline void encode_double(double d, void *buf)
uint64_t u; uint64_t u;
memcpy(&u,&d,8); memcpy(&u,&d,8);
# if __GNUC__ # if __GNUC__ && defined(__FLOAT_WORD_ORDER__)
# if __FLOAT_WORD_ORDER == __ORDER_LITTLE_ENDIAN__ # if __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__
u = __builtin_bswap64(u); u = __builtin_bswap64(u);
# endif # endif
memcpy(buf,&u,sizeof(double)); memcpy(buf,&u,sizeof(double));
...@@ -256,9 +256,9 @@ static inline int decode_integer(void *buf) ...@@ -256,9 +256,9 @@ static inline int decode_integer(void *buf)
{ {
int i; int i;
# if __GNUC__ # if __GNUC__ && defined(__BYTE_ORDER__)
memcpy(&i,buf,sizeof(int)); memcpy(&i,buf,sizeof(int));
# if __BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
i = __builtin_bswap32(i); i = __builtin_bswap32(i);
# endif # endif
# else # else
...@@ -275,9 +275,9 @@ static inline double decode_double(void *buf) ...@@ -275,9 +275,9 @@ static inline double decode_double(void *buf)
{ {
uint64_t u; uint64_t u;
# if __GNUC__ # if __GNUC__ && defined(__FLOAT_WORD_ORDER__)
memcpy(&u,buf,sizeof(double)); memcpy(&u,buf,sizeof(double));
# if __BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ # if __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__
u = __builtin_bswap64(u); u = __builtin_bswap64(u);
# endif # endif
# else # else
......
...@@ -118,3 +118,11 @@ if(suppressMessages(require("Matrix"))) { ...@@ -118,3 +118,11 @@ if(suppressMessages(require("Matrix"))) {
contr.sum(4) contr.sum(4)
contr.helmert(4) contr.helmert(4)
contr.sum(2) # needed drop=FALSE at one point. contr.sum(2) # needed drop=FALSE at one point.
## Check correct serialize output, and correct unserialization.
a <- serialize(quote(0x12345678L+0.1),NULL)
print(a[-(7:10)]) # eliminate R version number
print(unserialize(a))
print(0x12345678L)
...@@ -733,3 +733,16 @@ b . 1 ...@@ -733,3 +733,16 @@ b . 1
1 1 1 1
2 -1 2 -1
> >
>
> ## Check correct serialize output, and correct unserialization.
>
> a <- serialize(quote(0x12345678L+0.1),NULL)
> print(a[-(7:10)]) # eliminate R version number
[1] 58 0a 00 00 00 02 00 02 03 00 00 00 00 06 00 00 00 01 00 04 00 09 00 00 00
[26] 01 2b 00 00 00 02 00 00 00 0d 00 00 00 01 12 34 56 78 00 00 00 02 00 00 00
[51] 0e 00 00 00 01 3f b9 99 99 99 99 99 9a 00 00 00 fe
> print(unserialize(a))
305419896L + 0.1
> print(0x12345678L)
[1] 305419896
>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment