diff options
author | Dmitry Shulga <dmitry.shulga@mariadb.com> | 2020-11-11 19:31:11 +0700 |
---|---|---|
committer | Dmitry Shulga <dmitry.shulga@mariadb.com> | 2020-11-11 19:31:11 +0700 |
commit | ddddae70e66d1d58e07f7ddfec3a6edbece1e64f (patch) | |
tree | 5688f13f64b8e4b3b89a4a73be802b388a75db70 | |
parent | 1418439d3823fe059b41092af72ab32d5e7cd7ab (diff) | |
download | mariadb-git-ddddae70e66d1d58e07f7ddfec3a6edbece1e64f.tar.gz |
MDEV-24115: Build failure on MacOS on compiling the file btr/btr0btr.ccbb-10.5-MDEV-24115
Attempt to build MariaDB server on mac OS leads to compilation error:
[ 57%] Building CXX object server-10.5/storage/innobase/CMakeFiles/innobase.dir/btr/btr0btr.cc.o
In file included from server-10.5/storage/innobase/btr/btr0btr.cc:41:
In file included from server-10.5/storage/innobase/include/trx0trx.h:34:
In file included from server-10.5/storage/innobase/include/trx0xa.h:27:
In file included from server-10.5/sql/handler.h:34:
server-10.5/sql/structs.h:877:14: error: implicit conversion loses integer
precision: 'ulong' (aka 'unsigned long') to '__darwin_suseconds_t' (aka 'int')
[-Werror,-Wshorten-64-to-32]
tv_usec= usec;
This error happens in the constructor Timeval(my_time_t sec, ulong usec)
The data member tv_usec of the struct timeval is declared as suseconds_t on MacOS.
Size of suseconds_t is 4 bytes. On the other hand, size of ulong is 8 bytes
on 64-bit MacOS, so attempt to assign a value of wider type (usec) to a value (tv_usec)
of narrower type leads to error.
Declaration of the class Timeval was introduced in 10.4 and since then never changed.
When server 10.4 is built on MacOS the original error message from the bug report
IS NOT generated.
Starting from 10.5 clang compiler starts to emit this error message.
The reason of changes in compiler behaviour is that the extra compiler option
-Wconversion was added to compiler's flags in 10.5.
(see the file storage/innobase/innodb.cmake)
So, to fix the compilation error explicit casting to uint is done before
assignment of an argument value to tv_usec.
-rw-r--r-- | sql/structs.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/sql/structs.h b/sql/structs.h index 27acb9e200e..d838e331dd1 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -874,7 +874,16 @@ public: Timeval(my_time_t sec, ulong usec) { tv_sec= sec; - tv_usec= usec; + + /* + According to POSIX.1-2001 tv_usec is declared as suseconds_t. + On some platform (e.g. MacOS) the real type of suseconds_t + is uint. To avoid compiler warnings about losing integer precision + during implicit conversion from ulong to uint it is better + to cast usec parameter explicitly to uint. + */ + DBUG_ASSERT(usec < 1000000); + tv_usec= (uint)usec; } explicit Timeval(const timeval &tv) :timeval(tv) |