# # # delete "m4/ax_create_stdint_h.m4" # # add_file "m4/numeric_vocab.m4" # content [7472e0bb3f49936e0c1e99fd56f374cd3592a97c] # # patch "charset.cc" # from [0b6229965f7158b3f67b981f8e22f0636532859e] # to [5f3f37f70f5bc3ef4a5f793a25f77a0aecdf81c0] # # patch "configure.ac" # from [5282987db39b7d7b0cd8e918005309b776e7e972] # to [16b34b09cda7360d56592b647bdec7b085eda8a6] # # patch "database.cc" # from [110c7499e9532eb016d455799def9d72d05e9e4f] # to [5087d1394d533e4daddc1122c55f9be269eccf7e] # # patch "file_io.cc" # from [a57abb85fc9ed1d7fb14b4aa2c2e6b8d98c27f00] # to [7423effadb4f6f69b74ae1a775a8d54aebf8da85] # # patch "numeric_vocab.cc" # from [06d6f875e2eb934eb15879bd2e07d5ba4e396476] # to [4c9449fc5f958415493a601651fdc4bbea61870a] # # patch "numeric_vocab.hh" # from [33e1ef2e98b7fefc28bf39b8069e65744248a93c] # to [c7b71f42acc2cd8374f60d10c4d5a7a469eed654] # # patch "sanity.cc" # from [9fc53db75a289a176bfdc7ee88b58d505cc6936d] # to [1ff7e0b98b9811286e12de36ac0c6c9bbdb2fbe1] # # patch "sanity.hh" # from [c6a31bb3c9b988803a91dbe258e2acb83ddf73ed] # to [ba076ca717de4cbf92acdbc7d4c645f8696a7517] # # patch "schema_migration.cc" # from [df656cc76752a897bf10249886044e5aed28c36d] # to [222733a13d7a3eb204c67af2123f5a242957b415] # ============================================================ --- m4/numeric_vocab.m4 7472e0bb3f49936e0c1e99fd56f374cd3592a97c +++ m4/numeric_vocab.m4 7472e0bb3f49936e0c1e99fd56f374cd3592a97c @@ -0,0 +1,133 @@ +dnl Copyright (C) 2007 Zack Weinberg +dnl This program is made available under the GNU GPL version 2.0 or +dnl greater. See the accompanying file COPYING for details. +dnl +dnl This program is distributed WITHOUT ANY WARRANTY; without even the +dnl implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +dnl PURPOSE. + +dnl @synopsis MTN_NUMERIC_VOCAB +dnl +dnl This macro determines appropriate types for Monotone's set of +dnl exact-width numeric types, u8/u16/u32/u64 (unsigned) and +dnl s8/s16/s32/s64 (signed). If it cannot find appropriate types, or +dnl if 'char' is not exactly 8 bits, it aborts the configure +dnl operation. +dnl +dnl It should be mentioned that sizeof([[un]signed] char) is 1 *by +dnl definition*. It is written into both the C and C++ standards. +dnl It is never necessary to check this. + +dnl We don't use AC_CHECK_SIZEOF because we don't want the macro it +dnl defines. However, we do use the same test construct and the same +dnl cache variable; except that, as this is used only with fundamental +dnl types, we don't bother with the typedef checks. +AC_DEFUN([MTN_COMPUTE_SIZEOF], +[AS_LITERAL_IF([$1], [], + [AC_FATAL([$0: requires literal arguments])])dnl +AC_CACHE_CHECK([size of $1], [AS_TR_SH([ac_cv_sizeof_$1])], + [AC_COMPUTE_INT([AS_TR_SH([ac_cv_sizeof_$1])], + [(long int)(sizeof (ac__type_sizeof_))], + [AC_INCLUDES_DEFAULT() + typedef $1 ac__type_sizeof_;], + [AC_MSG_FAILURE([cannot compute sizeof ($1)], 77)])])]) + +AC_DEFUN([MTN_CHOOSE_USE_OF_TYPE], [ +MTN_COMPUTE_SIZEOF([$1]) +case $AS_TR_SH([ac_cv_sizeof_$1]) in + (2) mtn_s16_type='$1' + mtn_u16_type='$2' ;; + (4) mtn_s32_type='$1' + mtn_u32_type='$2' ;; + (8) mtn_s64_type='$1' + mtn_u64_type='$2' ;; +esac]) + +dnl AC_LANG_BOOL_COMPILE_TRY is not documented, but is very helpful. +dnl The content of these conditional definitions was lifted from +dnl autoconf 2.61. +m4_ifdef([AC_LANG_BOOL_COMPILE_TRY(C)], [], +[m4_define([AC_LANG_BOOL_COMPILE_TRY(C)], +[AC_LANG_PROGRAM([$1], [static int test_array @<:@1 - 2 * !($2)@:>@; +test_array @<:@0@:>@ = 0 +])])]) +m4_ifdef([AC_LANG_BOOL_COMPILE_TRY(C++)], [], +[m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(C++)])]) +m4_ifdef([AC_LANG_BOOL_COMPILE_TRY], [], +[AC_DEFUN([AC_LANG_BOOL_COMPILE_TRY], +[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])]) + + +AC_DEFUN([MTN_ASSERT_EIGHT_BIT_CHARS], +[AC_LANG_ASSERT([C++]) + AC_MSG_CHECKING([whether char has 8 bits]) + AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY(address@hidden:@include ], + [std::numeric_limits::digits == 8])], + [AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no]) + AC_MSG_ERROR([*** Monotone requires a platform with 8-bit bytes.])])]) + +AC_DEFUN([MTN_CHECK_PLAIN_CHAR_SIGNED], +[AC_CACHE_CHECK([whether plain char is signed], mtn_cv_plain_char_signed, + [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([], [((int)(char)-1) < 0])], + [mtn_cv_plain_char_signed=yes], + [mtn_cv_plain_char_signed=no])])]) + + +AC_DEFUN([MTN_NUMERIC_VOCAB], [dnl +MTN_ASSERT_EIGHT_BIT_CHARS + +# s8 and u8 will be some sort of 'char', but we want to use the plain +# variety for whichever one it is. +MTN_CHECK_PLAIN_CHAR_SIGNED +if test $mtn_cv_plain_char_signed = yes ; then + mtn_s8_type='char' + mtn_u8_type='unsigned char' +else + mtn_s8_type='signed char' + mtn_u8_type='char' +fi + +mtn_s16_type=unknown +mtn_u16_type=unknown +mtn_s32_type=unknown +mtn_u32_type=unknown +mtn_s64_type=unknown +mtn_u64_type=unknown + +# See if we can get away without 'long long' (LP64 model). +# The order here ensures that 'int' will be used if it happens +# to be the same size as 'short' or 'long'. +MTN_CHOOSE_USE_OF_TYPE([short], [unsigned short]) +MTN_CHOOSE_USE_OF_TYPE([long], [unsigned long]) +MTN_CHOOSE_USE_OF_TYPE([int], [unsigned int]) + +# If we didn't get an s16 or an s32 type we are hoz0red. +if test "$mtn_s16_type" = unknown +then AC_MSG_ERROR([*** no signed 16-bit type found]) +fi +if test "$mtn_s32_type" = unknown +then AC_MSG_ERROR([*** no signed 32-bit type found]) +fi + +# If we didn't get an s64 type, try long long. +MTN_CHOOSE_USE_OF_TYPE([long long], [unsigned long long]) +if test "$mtn_s64_type" = unknown +then AC_MSG_ERROR([*** no signed 64-bit type found]) +fi + +AC_DEFINE_UNQUOTED([TYPE_S8], [$mtn_s8_type], [Type to use for `s8'.]) +AC_DEFINE_UNQUOTED([TYPE_S16], [$mtn_s16_type], [Type to use for `s16'.]) +AC_DEFINE_UNQUOTED([TYPE_S32], [$mtn_s32_type], [Type to use for `s32'.]) +AC_DEFINE_UNQUOTED([TYPE_S64], [$mtn_s64_type], [Type to use for `s64'.]) + +AC_DEFINE_UNQUOTED([TYPE_U8], [$mtn_u8_type], [Type to use for `u8'.]) +AC_DEFINE_UNQUOTED([TYPE_U16], [$mtn_u16_type], [Type to use for `u16'.]) +AC_DEFINE_UNQUOTED([TYPE_U32], [$mtn_u32_type], [Type to use for `u32'.]) +AC_DEFINE_UNQUOTED([TYPE_U64], [$mtn_u64_type], [Type to use for `u64'.]) +]) + +dnl Local Variables: +dnl mode: autoconf +dnl indent-tabs-mode: nil +dnl End: ============================================================ --- charset.cc 0b6229965f7158b3f67b981f8e22f0636532859e +++ charset.cc 5f3f37f70f5bc3ef4a5f793a25f77a0aecdf81c0 @@ -461,7 +461,7 @@ idna { char *name; size_t inlen; - uint32_t in[100]; + u32 in[100]; char *out; int allowunassigned; int usestd3asciirules; ============================================================ --- configure.ac 5282987db39b7d7b0cd8e918005309b776e7e972 +++ configure.ac 16b34b09cda7360d56592b647bdec7b085eda8a6 @@ -53,7 +53,7 @@ AC_HEADER_STDBOOL sys/socket.h sys/time.h termios.h errno.h],,, [AC_INCLUDES_DEFAULT()]) AC_HEADER_STDBOOL -AX_CREATE_STDINT_H(mt-stdint.h) + # gettext is nominally a library, but its tests don't work in C++ mode. AM_GNU_GETTEXT([external]) AM_GNU_GETTEXT_VERSION(0.11.5) @@ -100,6 +100,7 @@ AC_CXX_TEMPLATE_STATIC_CONST_BUG AC_CXX_TEMPLATE_STATIC_CONST_BUG # Checks for typedefs and structures. +MTN_NUMERIC_VOCAB AC_TYPE_OFF_T AC_TYPE_SIZE_T AC_TYPE_PID_T ============================================================ --- database.cc 110c7499e9532eb016d455799def9d72d05e9e4f +++ database.cc 5087d1394d533e4daddc1122c55f9be269eccf7e @@ -505,7 +505,7 @@ static string // string, provided that all four characters are graphic. (On disk, it's // stored in the "user version" field of the database.) static string -format_creator_code(uint32_t code) +format_creator_code(u32 code) { char buf[5]; string result; @@ -544,12 +544,12 @@ database::info(ostream & out) sqlite3_exec(__sql, "SELECT 1 FROM sqlite_master LIMIT 0", 0, 0, 0); assert_sqlite3_ok(__sql); - uint32_t ccode; + u32 ccode; { results res; fetch(res, one_col, one_row, query("PRAGMA user_version")); I(res.size() == 1); - ccode = lexical_cast(res[0][0]); + ccode = lexical_cast(res[0][0]); } vector counts; ============================================================ --- file_io.cc a57abb85fc9ed1d7fb14b4aa2c2e6b8d98c27f00 +++ file_io.cc 7423effadb4f6f69b74ae1a775a8d54aebf8da85 @@ -157,7 +157,7 @@ set_char_is_binary(char c, bool is_binar static void set_char_is_binary(char c, bool is_binary) { - char_is_binary[static_cast(c)] = is_binary; + char_is_binary[static_cast(c)] = is_binary; } static void @@ -187,7 +187,7 @@ bool guess_binary(string const & s) for (size_t i = 0; i < s.size(); ++i) { - if (char_is_binary[ static_cast(s[i]) ]) + if (char_is_binary[ static_cast(s[i]) ]) return true; } return false; ============================================================ --- numeric_vocab.cc 06d6f875e2eb934eb15879bd2e07d5ba4e396476 +++ numeric_vocab.cc 4c9449fc5f958415493a601651fdc4bbea61870a @@ -30,19 +30,19 @@ UNIT_TEST(widen, widen) I((widen(255) == 255)); I((widen(static_cast(-1)) == 255)); // unsigned -> signed - I((widen(1) == 1)); - I((widen(255) == 255)); - I((widen(static_cast(-1)) == 255)); + I((widen(1) == 1)); + I((widen(255) == 255)); + I((widen(static_cast(-1)) == 255)); // signed -> signed - I((widen(1) == 1)); - I((widen(255) == -1)); - I((widen(-1) == -1)); + I((widen(1) == 1)); + I((widen(255) == -1)); + I((widen(-1) == -1)); // signed -> unsigned ((critical case!)) - I((widen(1) == 1)); - I((widen(255) == 255)); - I((widen(-1) == 255)); + I((widen(1) == 1)); + I((widen(255) == 255)); + I((widen(-1) == 255)); // contrasts with: - I((static_cast(int8_t(-1)) == u32(4294967295))); + I((static_cast(s8(-1)) == u32(4294967295))); } #endif // BUILD_UNIT_TESTS ============================================================ --- numeric_vocab.hh 33e1ef2e98b7fefc28bf39b8069e65744248a93c +++ numeric_vocab.hh c7b71f42acc2cd8374f60d10c4d5a7a469eed654 @@ -12,15 +12,18 @@ #include #include - -#include "mt-stdint.h" #include -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; +typedef TYPE_U8 u8; +typedef TYPE_U16 u16; +typedef TYPE_U32 u32; +typedef TYPE_U64 u64; +typedef TYPE_S8 s8; +typedef TYPE_S16 s16; +typedef TYPE_S32 s32; +typedef TYPE_S64 s64; + // This is similar to static_cast(v). The difference is that when T is // unsigned, this cast does not sign-extend: // static_cast((signed char) -1) = 4294967295 ============================================================ --- sanity.cc 9fc53db75a289a176bfdc7ee88b58d505cc6936d +++ sanity.cc 1ff7e0b98b9811286e12de36ac0c6c9bbdb2fbe1 @@ -474,15 +474,15 @@ format_base::flush_stream() const pimpl->oss.str(string()); } -void format_base::put_and_flush_signed(int64_t const & s) const { pimpl->fmt % s; } -void format_base::put_and_flush_signed(int32_t const & s) const { pimpl->fmt % s; } -void format_base::put_and_flush_signed(int16_t const & s) const { pimpl->fmt % s; } -void format_base::put_and_flush_signed(int8_t const & s) const { pimpl->fmt % s; } +void format_base::put_and_flush_signed(s64 const & s) const { pimpl->fmt % s; } +void format_base::put_and_flush_signed(s32 const & s) const { pimpl->fmt % s; } +void format_base::put_and_flush_signed(s16 const & s) const { pimpl->fmt % s; } +void format_base::put_and_flush_signed(s8 const & s) const { pimpl->fmt % s; } -void format_base::put_and_flush_unsigned(uint64_t const & u) const { pimpl->fmt % u; } -void format_base::put_and_flush_unsigned(uint32_t const & u) const { pimpl->fmt % u; } -void format_base::put_and_flush_unsigned(uint16_t const & u) const { pimpl->fmt % u; } -void format_base::put_and_flush_unsigned(uint8_t const & u) const { pimpl->fmt % u; } +void format_base::put_and_flush_unsigned(u64 const & u) const { pimpl->fmt % u; } +void format_base::put_and_flush_unsigned(u32 const & u) const { pimpl->fmt % u; } +void format_base::put_and_flush_unsigned(u16 const & u) const { pimpl->fmt % u; } +void format_base::put_and_flush_unsigned(u8 const & u) const { pimpl->fmt % u; } void format_base::put_and_flush_float(float const & f) const { pimpl->fmt % f; } void format_base::put_and_flush_double(double const & d) const { pimpl->fmt % d; } ============================================================ --- sanity.hh c6a31bb3c9b988803a91dbe258e2acb83ddf73ed +++ sanity.hh ba076ca717de4cbf92acdbc7d4c645f8696a7517 @@ -17,8 +17,8 @@ #include "boost/current_function.hpp" #include "i18n.h" -#include "mt-stdint.h" #include "quick_alloc.hh" // to get the QA() macro +#include "numeric_vocab.hh" // our assertion / sanity / error logging system *was* based on GNU Nana, // but we're only using a small section of it, and have anyways rewritten @@ -115,14 +115,14 @@ public: // class is a lie. std::ostream & get_stream() const; void flush_stream() const; - void put_and_flush_signed(int64_t const & s) const; - void put_and_flush_signed(int32_t const & s) const; - void put_and_flush_signed(int16_t const & s) const; - void put_and_flush_signed(int8_t const & s) const; - void put_and_flush_unsigned(uint64_t const & u) const; - void put_and_flush_unsigned(uint32_t const & u) const; - void put_and_flush_unsigned(uint16_t const & u) const; - void put_and_flush_unsigned(uint8_t const & u) const; + void put_and_flush_signed(s64 const & s) const; + void put_and_flush_signed(s32 const & s) const; + void put_and_flush_signed(s16 const & s) const; + void put_and_flush_signed(s8 const & s) const; + void put_and_flush_unsigned(u64 const & u) const; + void put_and_flush_unsigned(u32 const & u) const; + void put_and_flush_unsigned(u16 const & u) const; + void put_and_flush_unsigned(u8 const & u) const; void put_and_flush_float(float const & f) const; void put_and_flush_double(double const & d) const; @@ -192,15 +192,15 @@ SPECIALIZED_OP(const fmt_ty, arg_ty, con SPECIALIZED_OP(const fmt_ty, arg_ty, arg_ty, stem) \ SPECIALIZED_OP(const fmt_ty, arg_ty, const arg_ty, stem) -ALL_CONST_VARIANTS(plain_format, int64_t, signed) -ALL_CONST_VARIANTS(plain_format, int32_t, signed) -ALL_CONST_VARIANTS(plain_format, int16_t, signed) -ALL_CONST_VARIANTS(plain_format, int8_t, signed) +ALL_CONST_VARIANTS(plain_format, s64, signed) +ALL_CONST_VARIANTS(plain_format, s32, signed) +ALL_CONST_VARIANTS(plain_format, s16, signed) +ALL_CONST_VARIANTS(plain_format, s8, signed) -ALL_CONST_VARIANTS(plain_format, uint64_t, unsigned) -ALL_CONST_VARIANTS(plain_format, uint32_t, unsigned) -ALL_CONST_VARIANTS(plain_format, uint16_t, unsigned) -ALL_CONST_VARIANTS(plain_format, uint8_t, unsigned) +ALL_CONST_VARIANTS(plain_format, u64, unsigned) +ALL_CONST_VARIANTS(plain_format, u32, unsigned) +ALL_CONST_VARIANTS(plain_format, u16, unsigned) +ALL_CONST_VARIANTS(plain_format, u8, unsigned) ALL_CONST_VARIANTS(plain_format, float, float) ALL_CONST_VARIANTS(plain_format, double, double) @@ -247,15 +247,15 @@ operator %(i18n_format & f, T & t) return f; } -ALL_CONST_VARIANTS(i18n_format, int64_t, signed) -ALL_CONST_VARIANTS(i18n_format, int32_t, signed) -ALL_CONST_VARIANTS(i18n_format, int16_t, signed) -ALL_CONST_VARIANTS(i18n_format, int8_t, signed) +ALL_CONST_VARIANTS(i18n_format, s64, signed) +ALL_CONST_VARIANTS(i18n_format, s32, signed) +ALL_CONST_VARIANTS(i18n_format, s16, signed) +ALL_CONST_VARIANTS(i18n_format, s8, signed) -ALL_CONST_VARIANTS(i18n_format, uint64_t, unsigned) -ALL_CONST_VARIANTS(i18n_format, uint32_t, unsigned) -ALL_CONST_VARIANTS(i18n_format, uint16_t, unsigned) -ALL_CONST_VARIANTS(i18n_format, uint8_t, unsigned) +ALL_CONST_VARIANTS(i18n_format, u64, unsigned) +ALL_CONST_VARIANTS(i18n_format, u32, unsigned) +ALL_CONST_VARIANTS(i18n_format, u16, unsigned) +ALL_CONST_VARIANTS(i18n_format, u8, unsigned) ALL_CONST_VARIANTS(i18n_format, float, float) ALL_CONST_VARIANTS(i18n_format, double, double) ============================================================ --- schema_migration.cc df656cc76752a897bf10249886044e5aed28c36d +++ schema_migration.cc 222733a13d7a3eb204c67af2123f5a242957b415 @@ -773,7 +773,7 @@ calculate_schema_id(sqlite3 * db, string } } - uint32_t code = sql::value(db, "PRAGMA user_version"); + u32 code = sql::value(db, "PRAGMA user_version"); if (code != 0) { schema += " PRAGMA user_version = "; @@ -850,7 +850,7 @@ classify_schema(sqlite3 * db, migration_ // version 0.33, but all previous versions' databases are recognized // by their schema hashes. - uint32_t code = sql::value(db, "PRAGMA user_version"); + u32 code = sql::value(db, "PRAGMA user_version"); if (code != mtn_creator_code) return SCHEMA_NOT_MONOTONE;