Skip to content

Commit

Permalink
Fixing compile errors and warnings on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Marsh committed Feb 9, 2016
1 parent 6e482c9 commit 03d300c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
9 changes: 8 additions & 1 deletion cpp/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,17 @@ static inline int erlpack_append_long_long(erlpack_buffer *b, long long d) {
erlpack_append(b, buf, 1 + 2 + bytes_enc);
}

typedef union {
uint64_t ui64;
double df;
} typePunner;

static inline int erlpack_append_double(erlpack_buffer *b, double f) {
unsigned char buf[1 + 8] = {0};
buf[0] = NEW_FLOAT_EXT;
_erlpack_store64(buf + 1, *(uint64_t*)&f);
typePunner p;
p.df = f;
_erlpack_store64(buf + 1, p.ui64);
erlpack_append(b, buf, 1 + 8);
}

Expand Down
16 changes: 12 additions & 4 deletions js/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#define ntohs(x) (_byteswap_ushort(x))
#define ntohl(x) (_byteswap_ulong(x))
#define ntohll(x) (_byteswap_uint64(x))
#elif defined(__linux__)
#include <endian.h>
#define ntohll(x) be64toh(x)
#endif

using namespace v8;
Expand Down Expand Up @@ -214,8 +217,12 @@ class Decoder {
}

Local<Value> decodeNewFloat() {
uint64_t val = read64();
return Nan::New<Number>(*reinterpret_cast<double*>(&val));
union {
uint64_t ui64;
double df;
} val;
val.ui64 = read64();
return Nan::New<Number>(val.df);
}

Local<Value> decodeBig(uint32_t digits) {
Expand Down Expand Up @@ -248,12 +255,13 @@ class Decoder {

char outBuffer[32] = {0}; // 9223372036854775807
const char* const formatString = sign == 0 ? "%llu" : "-%llu";
const uint8_t length = sprintf(outBuffer, formatString, value);
const int res = sprintf(outBuffer, formatString, value);

if (length < 0) {
if (res < 0) {
THROW("Unable to convert big int to string");
return Nan::Null();
}
const uint8_t length = static_cast<const uint8_t>(res);

return Nan::New(outBuffer, length).ToLocalChecked();
}
Expand Down
2 changes: 2 additions & 0 deletions vendor/zlib/gzguts.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#ifdef _WIN32
# include <stddef.h>
#else
# include <unistd.h>
#endif

#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
Expand Down

0 comments on commit 03d300c

Please sign in to comment.