From 06a1e20d8acd014fb68f97fc0d8d88950fe9c69c Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 5 Jul 2018 13:21:37 +0200 Subject: [PATCH] Merge #13580: build: Detect if char equals int8_t 49d1f4cdd Detect if char equals int8_t (Chun Kuan Lee) Pull request description: Probably fixes #13576. I'm not able to test this. @stacepellegrino, can you test this? Tree-SHA512: b750e00e11e6b6f6341fec668ec2254cc101c8ebdd4878f320d6cb3b07cf326761146e4ceff0b6405b7e503ff64c093a8274bd524a097e2c49382dc296972c4f --- configure.ac | 8 ++++++++ src/serialize.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/configure.ac b/configure.ac index 12557e2d14..046a7dcec4 100644 --- a/configure.ac +++ b/configure.ac @@ -845,6 +845,14 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include [ AC_MSG_RESULT(no)] ) +AC_MSG_CHECKING(for if type char equals int8_t) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include + #include ]], + [[ static_assert(std::is_same::value, ""); ]])], + [ AC_MSG_RESULT(yes); AC_DEFINE(CHAR_EQUALS_INT8, 1,[Define this symbol if type char equals int8_t]) ], + [ AC_MSG_RESULT(no)] +) + # ensure backtrace() is found, check -lexecinfo if necessary if test x$TARGET_OS != xwindows; then AC_SEARCH_LIBS([backtrace], [execinfo], [], [ diff --git a/src/serialize.h b/src/serialize.h index 1c266c6582..26bc5b319b 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -186,7 +186,9 @@ template const X& ReadWriteAsHelper(const X& x) { return x; } SerializationOp(s, CSerActionUnserialize()); \ } +#ifndef CHAR_EQUALS_INT8 template inline void Serialize(Stream& s, char a ) { ser_writedata8(s, a); } // TODO Get rid of bare char +#endif template inline void Serialize(Stream& s, int8_t a ) { ser_writedata8(s, a); } template inline void Serialize(Stream& s, uint8_t a ) { ser_writedata8(s, a); } template inline void Serialize(Stream& s, int16_t a ) { ser_writedata16(s, a); } @@ -198,7 +200,9 @@ template inline void Serialize(Stream& s, uint64_t a) { ser_wri template inline void Serialize(Stream& s, float a ) { ser_writedata32(s, ser_float_to_uint32(a)); } template inline void Serialize(Stream& s, double a ) { ser_writedata64(s, ser_double_to_uint64(a)); } +#ifndef CHAR_EQUALS_INT8 template inline void Unserialize(Stream& s, char& a ) { a = ser_readdata8(s); } // TODO Get rid of bare char +#endif template inline void Unserialize(Stream& s, int8_t& a ) { a = ser_readdata8(s); } template inline void Unserialize(Stream& s, uint8_t& a ) { a = ser_readdata8(s); } template inline void Unserialize(Stream& s, int16_t& a ) { a = ser_readdata16(s); }