Commit 3d1306f7 authored by Ajo Robert's avatar Ajo Robert

Bug#21770366 backport bug#21657078 to 5.5 and 5.6

Problem Statement
=========
Fix various issues when building MySQL with Visual Studio 2015.

Fix:
=======
- Visual Studio 2015 adds support for timespec. Add check and
  related code to use this and only use our replacement if
  timespec is not defined.
- Rename lfind/lsearch to my* to avoid redefinition problems.
- Set default value for TMPDIR to "" on Windows as P_tmpdir
  no longer exists.
- using VS definition of snprintf if available
- tzname are now renamed to _tzname.
parent 8c65e082
# Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -328,9 +328,16 @@ IF(SYSCONFDIR) ...@@ -328,9 +328,16 @@ IF(SYSCONFDIR)
SET(DEFAULT_SYSCONFDIR "${SYSCONFDIR}") SET(DEFAULT_SYSCONFDIR "${SYSCONFDIR}")
ENDIF() ENDIF()
SET(TMPDIR "P_tmpdir" IF(WIN32) # P_tmpdir is not defined on Windows as of VS2015.
CACHE PATH SET(TMPDIR "" # So we use empty path as default. In practice TMP/TEMP is used
"PATH to MySQL TMP dir. Defaults to the P_tmpdir macro in <stdio.h>") CACHE PATH
"PATH to MySQL TMP dir")
ELSE()
SET(TMPDIR "P_tmpdir"
CACHE PATH
"PATH to MySQL TMP dir. Defaults to the P_tmpdir macro in <stdio.h>")
ENDIF()
IF(TMPDIR STREQUAL "P_tmpdir") IF(TMPDIR STREQUAL "P_tmpdir")
# Do not quote it, to refer to the P_tmpdir macro. # Do not quote it, to refer to the P_tmpdir macro.
SET(DEFAULT_TMPDIR "P_tmpdir") SET(DEFAULT_TMPDIR "P_tmpdir")
......
# Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -185,6 +185,8 @@ CHECK_SYMBOL_REPLACEMENT(SIGQUIT SIGTERM signal.h) ...@@ -185,6 +185,8 @@ CHECK_SYMBOL_REPLACEMENT(SIGQUIT SIGTERM signal.h)
CHECK_SYMBOL_REPLACEMENT(SIGPIPE SIGINT signal.h) CHECK_SYMBOL_REPLACEMENT(SIGPIPE SIGINT signal.h)
CHECK_SYMBOL_REPLACEMENT(isnan _isnan float.h) CHECK_SYMBOL_REPLACEMENT(isnan _isnan float.h)
CHECK_SYMBOL_REPLACEMENT(finite _finite float.h) CHECK_SYMBOL_REPLACEMENT(finite _finite float.h)
CHECK_SYMBOL_REPLACEMENT(tzname _tzname time.h)
CHECK_SYMBOL_REPLACEMENT(snprintf _snprintf stdio.h)
CHECK_FUNCTION_REPLACEMENT(popen _popen) CHECK_FUNCTION_REPLACEMENT(popen _popen)
CHECK_FUNCTION_REPLACEMENT(pclose _pclose) CHECK_FUNCTION_REPLACEMENT(pclose _pclose)
CHECK_FUNCTION_REPLACEMENT(access _access) CHECK_FUNCTION_REPLACEMENT(access _access)
......
# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -227,7 +227,6 @@ SET(HAVE_SIZEOF_ULONG FALSE CACHE INTERNAL "") ...@@ -227,7 +227,6 @@ SET(HAVE_SIZEOF_ULONG FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_U_INT32_T FALSE CACHE INTERNAL "") SET(HAVE_SIZEOF_U_INT32_T FALSE CACHE INTERNAL "")
SET(HAVE_SIZE_OF_SSIZE_T FALSE CACHE INTERNAL "") SET(HAVE_SIZE_OF_SSIZE_T FALSE CACHE INTERNAL "")
SET(HAVE_SLEEP CACHE INTERNAL "") SET(HAVE_SLEEP CACHE INTERNAL "")
SET(HAVE_SNPRINTF CACHE INTERNAL "")
SET(HAVE_SOCKADDR_STORAGE_SS_FAMILY 1 CACHE INTERNAL "") SET(HAVE_SOCKADDR_STORAGE_SS_FAMILY 1 CACHE INTERNAL "")
SET(HAVE_SOLARIS_STYLE_GETHOST CACHE INTERNAL "") SET(HAVE_SOLARIS_STYLE_GETHOST CACHE INTERNAL "")
SET(STACK_DIRECTION -1 CACHE INTERNAL "") SET(STACK_DIRECTION -1 CACHE INTERNAL "")
...@@ -301,7 +300,7 @@ SET(HAVE_TIME 1 CACHE INTERNAL "") ...@@ -301,7 +300,7 @@ SET(HAVE_TIME 1 CACHE INTERNAL "")
SET(HAVE_TIMES CACHE INTERNAL "") SET(HAVE_TIMES CACHE INTERNAL "")
SET(HAVE_TIMESPEC_TS_SEC CACHE INTERNAL "") SET(HAVE_TIMESPEC_TS_SEC CACHE INTERNAL "")
SET(HAVE_TIME_H 1 CACHE INTERNAL "") SET(HAVE_TIME_H 1 CACHE INTERNAL "")
SET(HAVE_TZNAME 1 CACHE INTERNAL "") SET(HAVE__tzname 1 CACHE INTERNAL "")
SET(HAVE_UNISTD_H CACHE INTERNAL "") SET(HAVE_UNISTD_H CACHE INTERNAL "")
SET(HAVE_UTIME_H CACHE INTERNAL "") SET(HAVE_UTIME_H CACHE INTERNAL "")
SET(HAVE_VALLOC CACHE INTERNAL "") SET(HAVE_VALLOC CACHE INTERNAL "")
......
/* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. /* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -376,6 +376,7 @@ ...@@ -376,6 +376,7 @@
#cmakedefine HAVE_UINT64 1 #cmakedefine HAVE_UINT64 1
#cmakedefine SIZEOF_BOOL @SIZEOF_BOOL@ #cmakedefine SIZEOF_BOOL @SIZEOF_BOOL@
#cmakedefine HAVE_BOOL 1 #cmakedefine HAVE_BOOL 1
#cmakedefine HAVE_STRUCT_TIMESPEC
#cmakedefine SOCKET_SIZE_TYPE @SOCKET_SIZE_TYPE@ #cmakedefine SOCKET_SIZE_TYPE @SOCKET_SIZE_TYPE@
...@@ -497,6 +498,7 @@ ...@@ -497,6 +498,7 @@
#cmakedefine strtok_r @strtok_r@ #cmakedefine strtok_r @strtok_r@
#cmakedefine strtoll @strtoll@ #cmakedefine strtoll @strtoll@
#cmakedefine strtoull @strtoull@ #cmakedefine strtoull @strtoull@
#cmakedefine tzname @tzname@
#cmakedefine vsnprintf @vsnprintf@ #cmakedefine vsnprintf @vsnprintf@
#if (_MSC_VER > 1310) #if (_MSC_VER > 1310)
# define HAVE_SETENV # define HAVE_SETENV
......
# Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -561,7 +561,7 @@ MY_CHECK_TYPE_SIZE(char CHAR) ...@@ -561,7 +561,7 @@ MY_CHECK_TYPE_SIZE(char CHAR)
MY_CHECK_TYPE_SIZE(short SHORT) MY_CHECK_TYPE_SIZE(short SHORT)
MY_CHECK_TYPE_SIZE(int INT) MY_CHECK_TYPE_SIZE(int INT)
MY_CHECK_TYPE_SIZE("long long" LONG_LONG) MY_CHECK_TYPE_SIZE("long long" LONG_LONG)
SET(CMAKE_EXTRA_INCLUDE_FILES stdio.h sys/types.h) SET(CMAKE_EXTRA_INCLUDE_FILES stdio.h sys/types.h time.h)
MY_CHECK_TYPE_SIZE(off_t OFF_T) MY_CHECK_TYPE_SIZE(off_t OFF_T)
MY_CHECK_TYPE_SIZE(uchar UCHAR) MY_CHECK_TYPE_SIZE(uchar UCHAR)
MY_CHECK_TYPE_SIZE(uint UINT) MY_CHECK_TYPE_SIZE(uint UINT)
...@@ -576,6 +576,7 @@ MY_CHECK_TYPE_SIZE(u_int32_t U_INT32_T) ...@@ -576,6 +576,7 @@ MY_CHECK_TYPE_SIZE(u_int32_t U_INT32_T)
MY_CHECK_TYPE_SIZE(int64 INT64) MY_CHECK_TYPE_SIZE(int64 INT64)
MY_CHECK_TYPE_SIZE(uint64 UINT64) MY_CHECK_TYPE_SIZE(uint64 UINT64)
MY_CHECK_TYPE_SIZE(time_t TIME_T) MY_CHECK_TYPE_SIZE(time_t TIME_T)
MY_CHECK_TYPE_SIZE("struct timespec" STRUCT_TIMESPEC)
SET (CMAKE_EXTRA_INCLUDE_FILES sys/types.h) SET (CMAKE_EXTRA_INCLUDE_FILES sys/types.h)
MY_CHECK_TYPE_SIZE(bool BOOL) MY_CHECK_TYPE_SIZE(bool BOOL)
SET(CMAKE_EXTRA_INCLUDE_FILES) SET(CMAKE_EXTRA_INCLUDE_FILES)
......
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. /* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -90,6 +90,7 @@ typedef volatile LONG my_pthread_once_t; ...@@ -90,6 +90,7 @@ typedef volatile LONG my_pthread_once_t;
windows implementation of pthread_cond_timedwait windows implementation of pthread_cond_timedwait
*/ */
#ifndef HAVE_STRUCT_TIMESPEC
/* /*
Declare a union to make sure FILETIME is properly aligned Declare a union to make sure FILETIME is properly aligned
so it can be used directly as a 64 bit value. The value so it can be used directly as a 64 bit value. The value
...@@ -128,6 +129,7 @@ struct timespec { ...@@ -128,6 +129,7 @@ struct timespec {
((TS1.tv.i64 > TS2.tv.i64) ? 1 : \ ((TS1.tv.i64 > TS2.tv.i64) ? 1 : \
((TS1.tv.i64 < TS2.tv.i64) ? -1 : 0)) ((TS1.tv.i64 < TS2.tv.i64) ? -1 : 0))
#endif
int win_pthread_mutex_trylock(pthread_mutex_t *mutex); int win_pthread_mutex_trylock(pthread_mutex_t *mutex);
int pthread_create(pthread_t *, const pthread_attr_t *, pthread_handler, void *); int pthread_create(pthread_t *, const pthread_attr_t *, pthread_handler, void *);
...@@ -433,13 +435,7 @@ int my_pthread_mutex_trylock(pthread_mutex_t *mutex); ...@@ -433,13 +435,7 @@ int my_pthread_mutex_trylock(pthread_mutex_t *mutex);
#endif /* !set_timespec_nsec */ #endif /* !set_timespec_nsec */
#else #else
#ifndef set_timespec #ifndef set_timespec
#define set_timespec(ABSTIME,SEC) \ #define set_timespec(ABSTIME,SEC) set_timespec_nsec((ABSTIME),(SEC)*1000000000ULL)
{\
struct timeval tv;\
gettimeofday(&tv,0);\
(ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\
(ABSTIME).tv_nsec=tv.tv_usec*1000;\
}
#endif /* !set_timespec */ #endif /* !set_timespec */
#ifndef set_timespec_nsec #ifndef set_timespec_nsec
#define set_timespec_nsec(ABSTIME,NSEC) \ #define set_timespec_nsec(ABSTIME,NSEC) \
......
/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. /* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -43,7 +43,7 @@ typedef struct { ...@@ -43,7 +43,7 @@ typedef struct {
/* /*
a structure to pass the context (pointers two the three successive elements a structure to pass the context (pointers two the three successive elements
in a list) from lfind to linsert/ldelete in a list) from my_lfind to linsert/ldelete
*/ */
typedef struct { typedef struct {
intptr volatile *prev; intptr volatile *prev;
...@@ -70,7 +70,7 @@ typedef struct { ...@@ -70,7 +70,7 @@ typedef struct {
cursor is positioned in either case cursor is positioned in either case
pins[0..2] are used, they are NOT removed on return pins[0..2] are used, they are NOT removed on return
*/ */
static int lfind(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr, static int my_lfind(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
const uchar *key, uint keylen, CURSOR *cursor, LF_PINS *pins) const uchar *key, uint keylen, CURSOR *cursor, LF_PINS *pins)
{ {
uint32 cur_hashnr; uint32 cur_hashnr;
...@@ -138,7 +138,7 @@ retry: ...@@ -138,7 +138,7 @@ retry:
/* /*
DESCRIPTION DESCRIPTION
insert a 'node' in the list that starts from 'head' in the correct insert a 'node' in the list that starts from 'head' in the correct
position (as found by lfind) position (as found by my_lfind)
RETURN RETURN
0 - inserted 0 - inserted
...@@ -156,7 +156,7 @@ static LF_SLIST *linsert(LF_SLIST * volatile *head, CHARSET_INFO *cs, ...@@ -156,7 +156,7 @@ static LF_SLIST *linsert(LF_SLIST * volatile *head, CHARSET_INFO *cs,
for (;;) for (;;)
{ {
if (lfind(head, cs, node->hashnr, node->key, node->keylen, if (my_lfind(head, cs, node->hashnr, node->key, node->keylen,
&cursor, pins) && &cursor, pins) &&
(flags & LF_HASH_UNIQUE)) (flags & LF_HASH_UNIQUE))
{ {
...@@ -207,7 +207,7 @@ static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr, ...@@ -207,7 +207,7 @@ static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
for (;;) for (;;)
{ {
if (!lfind(head, cs, hashnr, key, keylen, &cursor, pins)) if (!my_lfind(head, cs, hashnr, key, keylen, &cursor, pins))
{ {
res= 1; /* not found */ res= 1; /* not found */
break; break;
...@@ -231,7 +231,7 @@ static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr, ...@@ -231,7 +231,7 @@ static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
(to ensure the number of "set DELETED flag" actions (to ensure the number of "set DELETED flag" actions
is equal to the number of "remove from the list" actions) is equal to the number of "remove from the list" actions)
*/ */
lfind(head, cs, hashnr, key, keylen, &cursor, pins); my_lfind(head, cs, hashnr, key, keylen, &cursor, pins);
} }
res= 0; res= 0;
break; break;
...@@ -257,12 +257,12 @@ static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr, ...@@ -257,12 +257,12 @@ static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
it uses pins[0..2], on return the pin[2] keeps the node found it uses pins[0..2], on return the pin[2] keeps the node found
all other pins are removed. all other pins are removed.
*/ */
static LF_SLIST *lsearch(LF_SLIST * volatile *head, CHARSET_INFO *cs, static LF_SLIST *my_lsearch(LF_SLIST * volatile *head, CHARSET_INFO *cs,
uint32 hashnr, const uchar *key, uint keylen, uint32 hashnr, const uchar *key, uint keylen,
LF_PINS *pins) LF_PINS *pins)
{ {
CURSOR cursor; CURSOR cursor;
int res= lfind(head, cs, hashnr, key, keylen, &cursor, pins); int res= my_lfind(head, cs, hashnr, key, keylen, &cursor, pins);
if (res) if (res)
_lf_pin(pins, 2, cursor.curr); _lf_pin(pins, 2, cursor.curr);
_lf_unpin(pins, 0); _lf_unpin(pins, 0);
...@@ -443,7 +443,7 @@ int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen) ...@@ -443,7 +443,7 @@ int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
MY_ERRPTR if OOM MY_ERRPTR if OOM
NOTE NOTE
see lsearch() for pin usage notes see my_lsearch() for pin usage notes
*/ */
void *lf_hash_search(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen) void *lf_hash_search(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
{ {
...@@ -457,7 +457,7 @@ void *lf_hash_search(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen) ...@@ -457,7 +457,7 @@ void *lf_hash_search(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
return MY_ERRPTR; return MY_ERRPTR;
if (*el == NULL && unlikely(initialize_bucket(hash, el, bucket, pins))) if (*el == NULL && unlikely(initialize_bucket(hash, el, bucket, pins)))
return MY_ERRPTR; return MY_ERRPTR;
found= lsearch(el, hash->charset, my_reverse_bits(hashnr) | 1, found= my_lsearch(el, hash->charset, my_reverse_bits(hashnr) | 1,
(uchar *)key, keylen, pins); (uchar *)key, keylen, pins);
lf_rwunlock_by_pins(pins); lf_rwunlock_by_pins(pins);
return found ? found+1 : 0; return found ? found+1 : 0;
......
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. /* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -88,6 +88,7 @@ static void check_native_cond_availability(void) ...@@ -88,6 +88,7 @@ static void check_native_cond_availability(void)
static DWORD get_milliseconds(const struct timespec *abstime) static DWORD get_milliseconds(const struct timespec *abstime)
{ {
#ifndef HAVE_STRUCT_TIMESPEC
long long millis; long long millis;
union ft64 now; union ft64 now;
...@@ -118,6 +119,17 @@ static DWORD get_milliseconds(const struct timespec *abstime) ...@@ -118,6 +119,17 @@ static DWORD get_milliseconds(const struct timespec *abstime)
millis= UINT_MAX; millis= UINT_MAX;
return (DWORD)millis; return (DWORD)millis;
#else
/*
Convert timespec to millis and subtract current time.
my_getsystime() returns time in 100 ns units.
*/
if (abstime == NULL)
return INFINITE;
return (DWORD)(abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000 -
my_getsystime() / 10000);
#endif
} }
......
/* Copyright (C) 2007 Google Inc. /* Copyright (C) 2007 Google Inc.
Copyright (c) 2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
Use is subject to license terms.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -48,7 +47,7 @@ static int getWaitTime(const struct timespec& start_ts); ...@@ -48,7 +47,7 @@ static int getWaitTime(const struct timespec& start_ts);
static unsigned long long timespec_to_usec(const struct timespec *ts) static unsigned long long timespec_to_usec(const struct timespec *ts)
{ {
#ifndef __WIN__ #ifdef HAVE_STRUCT_TIMESPEC
return (unsigned long long) ts->tv_sec * TIME_MILLION + ts->tv_nsec / TIME_THOUSAND; return (unsigned long long) ts->tv_sec * TIME_MILLION + ts->tv_nsec / TIME_THOUSAND;
#else #else
return ts->tv.i64 / 10; return ts->tv.i64 / 10;
...@@ -683,7 +682,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name, ...@@ -683,7 +682,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name,
} }
/* Calcuate the waiting period. */ /* Calcuate the waiting period. */
#ifdef __WIN__ #ifndef HAVE_STRUCT_TIMESPEC
abstime.tv.i64 = start_ts.tv.i64 + (__int64)wait_timeout_ * TIME_THOUSAND * 10; abstime.tv.i64 = start_ts.tv.i64 + (__int64)wait_timeout_ * TIME_THOUSAND * 10;
abstime.max_timeout_msec= (long)wait_timeout_; abstime.max_timeout_msec= (long)wait_timeout_;
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment