Skip to content

Commit 3d1306f

Browse files
author
Ajo Robert
committed
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.
1 parent 8c65e08 commit 3d1306f

9 files changed

Lines changed: 53 additions & 35 deletions

File tree

CMakeLists.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -328,9 +328,16 @@ IF(SYSCONFDIR)
328328
SET(DEFAULT_SYSCONFDIR "${SYSCONFDIR}")
329329
ENDIF()
330330

331-
SET(TMPDIR "P_tmpdir"
332-
CACHE PATH
333-
"PATH to MySQL TMP dir. Defaults to the P_tmpdir macro in <stdio.h>")
331+
IF(WIN32) # P_tmpdir is not defined on Windows as of VS2015.
332+
SET(TMPDIR "" # So we use empty path as default. In practice TMP/TEMP is used
333+
CACHE PATH
334+
"PATH to MySQL TMP dir")
335+
ELSE()
336+
SET(TMPDIR "P_tmpdir"
337+
CACHE PATH
338+
"PATH to MySQL TMP dir. Defaults to the P_tmpdir macro in <stdio.h>")
339+
ENDIF()
340+
334341
IF(TMPDIR STREQUAL "P_tmpdir")
335342
# Do not quote it, to refer to the P_tmpdir macro.
336343
SET(DEFAULT_TMPDIR "P_tmpdir")

cmake/os/Windows.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -185,6 +185,8 @@ CHECK_SYMBOL_REPLACEMENT(SIGQUIT SIGTERM signal.h)
185185
CHECK_SYMBOL_REPLACEMENT(SIGPIPE SIGINT signal.h)
186186
CHECK_SYMBOL_REPLACEMENT(isnan _isnan float.h)
187187
CHECK_SYMBOL_REPLACEMENT(finite _finite float.h)
188+
CHECK_SYMBOL_REPLACEMENT(tzname _tzname time.h)
189+
CHECK_SYMBOL_REPLACEMENT(snprintf _snprintf stdio.h)
188190
CHECK_FUNCTION_REPLACEMENT(popen _popen)
189191
CHECK_FUNCTION_REPLACEMENT(pclose _pclose)
190192
CHECK_FUNCTION_REPLACEMENT(access _access)

cmake/os/WindowsCache.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -227,7 +227,6 @@ SET(HAVE_SIZEOF_ULONG FALSE CACHE INTERNAL "")
227227
SET(HAVE_SIZEOF_U_INT32_T FALSE CACHE INTERNAL "")
228228
SET(HAVE_SIZE_OF_SSIZE_T FALSE CACHE INTERNAL "")
229229
SET(HAVE_SLEEP CACHE INTERNAL "")
230-
SET(HAVE_SNPRINTF CACHE INTERNAL "")
231230
SET(HAVE_SOCKADDR_STORAGE_SS_FAMILY 1 CACHE INTERNAL "")
232231
SET(HAVE_SOLARIS_STYLE_GETHOST CACHE INTERNAL "")
233232
SET(STACK_DIRECTION -1 CACHE INTERNAL "")
@@ -301,7 +300,7 @@ SET(HAVE_TIME 1 CACHE INTERNAL "")
301300
SET(HAVE_TIMES CACHE INTERNAL "")
302301
SET(HAVE_TIMESPEC_TS_SEC CACHE INTERNAL "")
303302
SET(HAVE_TIME_H 1 CACHE INTERNAL "")
304-
SET(HAVE_TZNAME 1 CACHE INTERNAL "")
303+
SET(HAVE__tzname 1 CACHE INTERNAL "")
305304
SET(HAVE_UNISTD_H CACHE INTERNAL "")
306305
SET(HAVE_UTIME_H CACHE INTERNAL "")
307306
SET(HAVE_VALLOC CACHE INTERNAL "")

config.h.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
22

33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -376,6 +376,7 @@
376376
#cmakedefine HAVE_UINT64 1
377377
#cmakedefine SIZEOF_BOOL @SIZEOF_BOOL@
378378
#cmakedefine HAVE_BOOL 1
379+
#cmakedefine HAVE_STRUCT_TIMESPEC
379380

380381
#cmakedefine SOCKET_SIZE_TYPE @SOCKET_SIZE_TYPE@
381382

@@ -497,6 +498,7 @@
497498
#cmakedefine strtok_r @strtok_r@
498499
#cmakedefine strtoll @strtoll@
499500
#cmakedefine strtoull @strtoull@
501+
#cmakedefine tzname @tzname@
500502
#cmakedefine vsnprintf @vsnprintf@
501503
#if (_MSC_VER > 1310)
502504
# define HAVE_SETENV

configure.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -561,7 +561,7 @@ MY_CHECK_TYPE_SIZE(char CHAR)
561561
MY_CHECK_TYPE_SIZE(short SHORT)
562562
MY_CHECK_TYPE_SIZE(int INT)
563563
MY_CHECK_TYPE_SIZE("long long" LONG_LONG)
564-
SET(CMAKE_EXTRA_INCLUDE_FILES stdio.h sys/types.h)
564+
SET(CMAKE_EXTRA_INCLUDE_FILES stdio.h sys/types.h time.h)
565565
MY_CHECK_TYPE_SIZE(off_t OFF_T)
566566
MY_CHECK_TYPE_SIZE(uchar UCHAR)
567567
MY_CHECK_TYPE_SIZE(uint UINT)
@@ -576,6 +576,7 @@ MY_CHECK_TYPE_SIZE(u_int32_t U_INT32_T)
576576
MY_CHECK_TYPE_SIZE(int64 INT64)
577577
MY_CHECK_TYPE_SIZE(uint64 UINT64)
578578
MY_CHECK_TYPE_SIZE(time_t TIME_T)
579+
MY_CHECK_TYPE_SIZE("struct timespec" STRUCT_TIMESPEC)
579580
SET (CMAKE_EXTRA_INCLUDE_FILES sys/types.h)
580581
MY_CHECK_TYPE_SIZE(bool BOOL)
581582
SET(CMAKE_EXTRA_INCLUDE_FILES)

include/my_pthread.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -90,6 +90,7 @@ typedef volatile LONG my_pthread_once_t;
9090
windows implementation of pthread_cond_timedwait
9191
*/
9292

93+
#ifndef HAVE_STRUCT_TIMESPEC
9394
/*
9495
Declare a union to make sure FILETIME is properly aligned
9596
so it can be used directly as a 64 bit value. The value
@@ -128,6 +129,7 @@ struct timespec {
128129
((TS1.tv.i64 > TS2.tv.i64) ? 1 : \
129130
((TS1.tv.i64 < TS2.tv.i64) ? -1 : 0))
130131

132+
#endif
131133

132134
int win_pthread_mutex_trylock(pthread_mutex_t *mutex);
133135
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);
433435
#endif /* !set_timespec_nsec */
434436
#else
435437
#ifndef set_timespec
436-
#define set_timespec(ABSTIME,SEC) \
437-
{\
438-
struct timeval tv;\
439-
gettimeofday(&tv,0);\
440-
(ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\
441-
(ABSTIME).tv_nsec=tv.tv_usec*1000;\
442-
}
438+
#define set_timespec(ABSTIME,SEC) set_timespec_nsec((ABSTIME),(SEC)*1000000000ULL)
443439
#endif /* !set_timespec */
444440
#ifndef set_timespec_nsec
445441
#define set_timespec_nsec(ABSTIME,NSEC) \

mysys/lf_hash.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -43,7 +43,7 @@ typedef struct {
4343

4444
/*
4545
a structure to pass the context (pointers two the three successive elements
46-
in a list) from lfind to linsert/ldelete
46+
in a list) from my_lfind to linsert/ldelete
4747
*/
4848
typedef struct {
4949
intptr volatile *prev;
@@ -70,7 +70,7 @@ typedef struct {
7070
cursor is positioned in either case
7171
pins[0..2] are used, they are NOT removed on return
7272
*/
73-
static int lfind(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
73+
static int my_lfind(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
7474
const uchar *key, uint keylen, CURSOR *cursor, LF_PINS *pins)
7575
{
7676
uint32 cur_hashnr;
@@ -138,7 +138,7 @@ static int lfind(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
138138
/*
139139
DESCRIPTION
140140
insert a 'node' in the list that starts from 'head' in the correct
141-
position (as found by lfind)
141+
position (as found by my_lfind)
142142
143143
RETURN
144144
0 - inserted
@@ -156,7 +156,7 @@ static LF_SLIST *linsert(LF_SLIST * volatile *head, CHARSET_INFO *cs,
156156

157157
for (;;)
158158
{
159-
if (lfind(head, cs, node->hashnr, node->key, node->keylen,
159+
if (my_lfind(head, cs, node->hashnr, node->key, node->keylen,
160160
&cursor, pins) &&
161161
(flags & LF_HASH_UNIQUE))
162162
{
@@ -207,7 +207,7 @@ static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
207207

208208
for (;;)
209209
{
210-
if (!lfind(head, cs, hashnr, key, keylen, &cursor, pins))
210+
if (!my_lfind(head, cs, hashnr, key, keylen, &cursor, pins))
211211
{
212212
res= 1; /* not found */
213213
break;
@@ -231,7 +231,7 @@ static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
231231
(to ensure the number of "set DELETED flag" actions
232232
is equal to the number of "remove from the list" actions)
233233
*/
234-
lfind(head, cs, hashnr, key, keylen, &cursor, pins);
234+
my_lfind(head, cs, hashnr, key, keylen, &cursor, pins);
235235
}
236236
res= 0;
237237
break;
@@ -257,12 +257,12 @@ static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
257257
it uses pins[0..2], on return the pin[2] keeps the node found
258258
all other pins are removed.
259259
*/
260-
static LF_SLIST *lsearch(LF_SLIST * volatile *head, CHARSET_INFO *cs,
260+
static LF_SLIST *my_lsearch(LF_SLIST * volatile *head, CHARSET_INFO *cs,
261261
uint32 hashnr, const uchar *key, uint keylen,
262262
LF_PINS *pins)
263263
{
264264
CURSOR cursor;
265-
int res= lfind(head, cs, hashnr, key, keylen, &cursor, pins);
265+
int res= my_lfind(head, cs, hashnr, key, keylen, &cursor, pins);
266266
if (res)
267267
_lf_pin(pins, 2, cursor.curr);
268268
_lf_unpin(pins, 0);
@@ -443,7 +443,7 @@ int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
443443
MY_ERRPTR if OOM
444444
445445
NOTE
446-
see lsearch() for pin usage notes
446+
see my_lsearch() for pin usage notes
447447
*/
448448
void *lf_hash_search(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
449449
{
@@ -457,7 +457,7 @@ void *lf_hash_search(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
457457
return MY_ERRPTR;
458458
if (*el == NULL && unlikely(initialize_bucket(hash, el, bucket, pins)))
459459
return MY_ERRPTR;
460-
found= lsearch(el, hash->charset, my_reverse_bits(hashnr) | 1,
460+
found= my_lsearch(el, hash->charset, my_reverse_bits(hashnr) | 1,
461461
(uchar *)key, keylen, pins);
462462
lf_rwunlock_by_pins(pins);
463463
return found ? found+1 : 0;

mysys/my_wincond.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -88,6 +88,7 @@ static void check_native_cond_availability(void)
8888

8989
static DWORD get_milliseconds(const struct timespec *abstime)
9090
{
91+
#ifndef HAVE_STRUCT_TIMESPEC
9192
long long millis;
9293
union ft64 now;
9394

@@ -118,6 +119,17 @@ static DWORD get_milliseconds(const struct timespec *abstime)
118119
millis= UINT_MAX;
119120

120121
return (DWORD)millis;
122+
#else
123+
/*
124+
Convert timespec to millis and subtract current time.
125+
my_getsystime() returns time in 100 ns units.
126+
*/
127+
if (abstime == NULL)
128+
return INFINITE;
129+
130+
return (DWORD)(abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000 -
131+
my_getsystime() / 10000);
132+
#endif
121133
}
122134

123135

plugin/semisync/semisync_master.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* Copyright (C) 2007 Google Inc.
2-
Copyright (c) 2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
3-
Use is subject to license terms.
2+
Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
43
54
This program is free software; you can redistribute it and/or modify
65
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);
4847

4948
static unsigned long long timespec_to_usec(const struct timespec *ts)
5049
{
51-
#ifndef __WIN__
50+
#ifdef HAVE_STRUCT_TIMESPEC
5251
return (unsigned long long) ts->tv_sec * TIME_MILLION + ts->tv_nsec / TIME_THOUSAND;
5352
#else
5453
return ts->tv.i64 / 10;
@@ -683,7 +682,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name,
683682
}
684683

685684
/* Calcuate the waiting period. */
686-
#ifdef __WIN__
685+
#ifndef HAVE_STRUCT_TIMESPEC
687686
abstime.tv.i64 = start_ts.tv.i64 + (__int64)wait_timeout_ * TIME_THOUSAND * 10;
688687
abstime.max_timeout_msec= (long)wait_timeout_;
689688
#else

0 commit comments

Comments
 (0)