Skip to content

Commit

Permalink
Merge bitcoin#13580: build: Detect if char equals int8_t
Browse files Browse the repository at this point in the history
49d1f4c Detect if char equals int8_t (Chun Kuan Lee)

Pull request description:

  Probably fixes bitcoin#13576. I'm not able to test this. @stacepellegrino, can you test this?

Tree-SHA512: b750e00e11e6b6f6341fec668ec2254cc101c8ebdd4878f320d6cb3b07cf326761146e4ceff0b6405b7e503ff64c093a8274bd524a097e2c49382dc296972c4f
  • Loading branch information
laanwj authored and Dmitriy Korniychuk committed Jun 26, 2021
1 parent f9fea45 commit d29ea73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,14 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
[ AC_MSG_RESULT(no)]
)

AC_MSG_CHECKING(for if type char equals int8_t)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdint.h>
#include <type_traits>]],
[[ static_assert(std::is_same<int8_t, char>::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
if test "x$enable_stacktraces" != xno; then
Expand Down
4 changes: 4 additions & 0 deletions src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ enum
SerializationOp(s, CSerActionUnserialize()); \
}

#ifndef CHAR_EQUALS_INT8
template<typename Stream> inline void Serialize(Stream& s, char a ) { ser_writedata8(s, a); } // TODO Get rid of bare char
#endif
template<typename Stream> inline void Serialize(Stream& s, int8_t a ) { ser_writedata8(s, a); }
template<typename Stream> inline void Serialize(Stream& s, uint8_t a ) { ser_writedata8(s, a); }
template<typename Stream> inline void Serialize(Stream& s, int16_t a ) { ser_writedata16(s, a); }
Expand All @@ -201,7 +203,9 @@ template<typename Stream> inline void Serialize(Stream& s, double a ) { ser_wri
template<typename Stream, int N> inline void Serialize(Stream& s, const char (&a)[N]) { s.write(a, N); }
template<typename Stream, int N> inline void Serialize(Stream& s, const unsigned char (&a)[N]) { s.write(CharCast(a), N); }

#ifndef CHAR_EQUALS_INT8
template<typename Stream> inline void Unserialize(Stream& s, char& a ) { a = ser_readdata8(s); } // TODO Get rid of bare char
#endif
template<typename Stream> inline void Unserialize(Stream& s, int8_t& a ) { a = ser_readdata8(s); }
template<typename Stream> inline void Unserialize(Stream& s, uint8_t& a ) { a = ser_readdata8(s); }
template<typename Stream> inline void Unserialize(Stream& s, int16_t& a ) { a = ser_readdata16(s); }
Expand Down

0 comments on commit d29ea73

Please sign in to comment.