Skip to content

Commit ec13e0b

Browse files
authored
CDRIVER-4264 Address build failures on VS 2013 variants on Evergreen (#932)
* Remove test suite signal handlers for C90 compatibility * Replace snprintf with bson_snprintf * Address missing _InterlockedExchangePointer on x86 with VS 2013
1 parent 7a35cf8 commit ec13e0b

File tree

6 files changed

+57
-87
lines changed

6 files changed

+57
-87
lines changed

src/libbson/src/bson/bson-atomic.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ _bson_emul_atomic_int32_compare_exchange_weak (volatile int32_t *p,
195195

196196
int
197197
_bson_emul_atomic_int_fetch_add (volatile int *p,
198-
int n,
199-
enum bson_memory_order _unused)
198+
int n,
199+
enum bson_memory_order _unused)
200200
{
201201
int ret;
202202
_lock_emul_atomic ();
@@ -208,8 +208,8 @@ _bson_emul_atomic_int_fetch_add (volatile int *p,
208208

209209
int
210210
_bson_emul_atomic_int_exchange (volatile int *p,
211-
int n,
212-
enum bson_memory_order _unused)
211+
int n,
212+
enum bson_memory_order _unused)
213213
{
214214
int ret;
215215
_lock_emul_atomic ();
@@ -221,9 +221,9 @@ _bson_emul_atomic_int_exchange (volatile int *p,
221221

222222
int
223223
_bson_emul_atomic_int_compare_exchange_strong (volatile int *p,
224-
int expect_value,
225-
int new_value,
226-
enum bson_memory_order _unused)
224+
int expect_value,
225+
int new_value,
226+
enum bson_memory_order _unused)
227227
{
228228
int ret;
229229
_lock_emul_atomic ();
@@ -237,11 +237,24 @@ _bson_emul_atomic_int_compare_exchange_strong (volatile int *p,
237237

238238
int
239239
_bson_emul_atomic_int_compare_exchange_weak (volatile int *p,
240-
int expect_value,
241-
int new_value,
242-
enum bson_memory_order order)
240+
int expect_value,
241+
int new_value,
242+
enum bson_memory_order order)
243243
{
244244
/* We're emulating. We can't do a weak version. */
245245
return _bson_emul_atomic_int_compare_exchange_strong (
246246
p, expect_value, new_value, order);
247247
}
248+
249+
void *
250+
_bson_emul_atomic_ptr_exchange (void *volatile *p,
251+
void *n,
252+
enum bson_memory_order _unused)
253+
{
254+
void *ret;
255+
_lock_emul_atomic ();
256+
ret = *p;
257+
*p = n;
258+
_unlock_emul_atomic ();
259+
return ret;
260+
}

src/libbson/src/bson/bson-atomic.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ enum bson_memory_order {
7373
#define BSON_EMULATE_INT
7474
#endif
7575

76+
/* CDRIVER-4264 Contrary to documentation, VS 2013 targeting x86 does not
77+
* correctly/consistently provide _InterlockedPointerExchange. */
78+
#if defined(_MSC_VER) && _MSC_VER < 1900 && defined(_M_IX86)
79+
#define BSON_EMULATE_PTR
80+
#endif
81+
7682
#define DEF_ATOMIC_OP( \
7783
MSVC_Intrinsic, GNU_Intrinsic, GNU_Legacy_Intrinsic, Order, ...) \
7884
do { \
@@ -433,6 +439,11 @@ _bson_emul_atomic_int_compare_exchange_weak (int volatile *val,
433439
int new_value,
434440
enum bson_memory_order);
435441

442+
BSON_EXPORT (void *)
443+
_bson_emul_atomic_ptr_exchange (void *volatile *val,
444+
void *v,
445+
enum bson_memory_order);
446+
436447
BSON_EXPORT (void)
437448
bson_thrd_yield (void);
438449

@@ -608,8 +619,10 @@ bson_atomic_ptr_exchange (void *volatile *ptr,
608619
void *new_value,
609620
enum bson_memory_order ord)
610621
{
622+
#if defined(BSON_EMULATE_PTR)
623+
return _bson_emul_atomic_ptr_exchange (ptr, new_value, ord);
624+
#elif defined(BSON_USE_LEGACY_GCC_ATOMICS)
611625
/* The older __sync_val_compare_and_swap also takes oldval */
612-
#if defined(BSON_USE_LEGACY_GCC_ATOMICS)
613626
DEF_ATOMIC_OP (_InterlockedExchangePointer,
614627
,
615628
__sync_val_compare_and_swap,
@@ -750,6 +763,8 @@ BSON_EXPORT (int32_t) bson_atomic_int_add (volatile int32_t *p, int32_t n);
750763
BSON_GNUC_DEPRECATED_FOR ("bson_atomic_int64_fetch_add")
751764
BSON_EXPORT (int64_t) bson_atomic_int64_add (volatile int64_t *p, int64_t n);
752765

766+
767+
#undef BSON_EMULATE_PTR
753768
#undef BSON_EMULATE_INT32
754769
#undef BSON_EMULATE_INT
755770

src/libmongoc/tests/TestSuite.c

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -113,45 +113,6 @@ static BSON_ONCE_FUN (_test_suite_ensure_mutex_once)
113113
}
114114

115115

116-
static void
117-
_handle_signal (int signum)
118-
{
119-
const char *s = "\nProcess was interrupted by the delivery of a signal.\n";
120-
const char *sigstr;
121-
size_t n;
122-
switch (signum) {
123-
case SIGABRT:
124-
sigstr = "SIGABRT - Abnormal termination";
125-
break;
126-
case SIGINT:
127-
sigstr = "SIGINT - Interrupted";
128-
break;
129-
case SIGTERM:
130-
sigstr = "SIGTERM - Termination requested";
131-
break;
132-
case SIGSEGV:
133-
sigstr = "SIGSEGV - Access violation";
134-
break;
135-
default:
136-
sigstr = "(Unknown signal delivered)";
137-
}
138-
#ifdef BSON_OS_UNIX
139-
/* On POSIX these APIs are signal-safe */
140-
n = write (STDERR_FILENO, s, strlen (s));
141-
n = write (STDERR_FILENO, " ", 2);
142-
n = write (STDERR_FILENO, sigstr, strlen (sigstr));
143-
n = write (STDERR_FILENO, "\n", 1);
144-
fsync (STDERR_FILENO);
145-
#else
146-
/* On Windows these APIs are signal-safe */
147-
fprintf (stderr, "\n%s\n %s\n", s, sigstr);
148-
fflush (stderr);
149-
#endif
150-
_Exit (signum);
151-
(void) n;
152-
}
153-
154-
155116
void
156117
TestSuite_Init (TestSuite *suite, const char *name, int argc, char **argv)
157118
{
@@ -168,11 +129,6 @@ TestSuite_Init (TestSuite *suite, const char *name, int argc, char **argv)
168129
suite->ctest_run = NULL;
169130
_mongoc_array_init (&suite->match_patterns, sizeof (char *));
170131

171-
suite->prev_sigabrt = signal (SIGABRT, _handle_signal);
172-
suite->prev_sigint = signal (SIGINT, _handle_signal);
173-
suite->prev_sigterm = signal (SIGTERM, _handle_signal);
174-
suite->prev_sigsegv = signal (SIGSEGV, _handle_signal);
175-
176132
for (i = 1; i < argc; i++) {
177133
if (0 == strcmp ("-d", argv[i])) {
178134
suite->flags |= TEST_DEBUGOUTPUT;
@@ -1100,11 +1056,6 @@ TestSuite_Destroy (TestSuite *suite)
11001056
}
11011057

11021058
_mongoc_array_destroy (&suite->match_patterns);
1103-
1104-
signal (SIGABRT, suite->prev_sigabrt);
1105-
signal (SIGINT, suite->prev_sigint);
1106-
signal (SIGTERM, suite->prev_sigterm);
1107-
signal (SIGSEGV, suite->prev_sigsegv);
11081059
}
11091060

11101061

src/libmongoc/tests/TestSuite.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,6 @@ struct _TestSuite {
674674
int silent;
675675
bson_string_t *mock_server_log_buf;
676676
FILE *mock_server_log;
677-
678-
void (*prev_sigabrt) (int);
679-
void (*prev_sigint) (int);
680-
void (*prev_sigterm) (int);
681-
void (*prev_sigsegv) (int);
682677
};
683678

684679

src/libmongoc/tests/json-test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1930,7 +1930,7 @@ _install_json_test_suite_with_check (TestSuite *suite,
19301930
char joined[PATH_MAX];
19311931
char resolved[PATH_MAX];
19321932

1933-
snprintf (joined, PATH_MAX, "%s/%s", base, subdir);
1933+
bson_snprintf (joined, PATH_MAX, "%s/%s", base, subdir);
19341934
ASSERT (realpath (joined, resolved));
19351935

19361936
if (suite->ctest_run) {

src/libmongoc/tests/test-mongoc-uri.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
#include "test-libmongoc.h"
1212
#include "test-conveniences.h"
1313

14-
#ifdef _WIN32
15-
#define snprintf _snprintf
16-
#endif
17-
1814
static void
1915
test_mongoc_uri_new (void)
2016
{
@@ -1579,7 +1575,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
15791575
mongoc_uri_t *uri;
15801576
bson_error_t err;
15811577

1582-
snprintf (url_buffer,
1578+
bson_snprintf (url_buffer,
15831579
sizeof (url_buffer),
15841580
"mongodb://CN=client,OU=kerneluser,O=10Gen,L=New York City,"
15851581
"ST=New York,[email protected]/?"
@@ -1617,7 +1613,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
16171613
mongoc_uri_destroy (uri);
16181614

16191615

1620-
snprintf (url_buffer,
1616+
bson_snprintf (url_buffer,
16211617
sizeof (url_buffer),
16221618
"mongodb://localhost/?%s=true&%s=key.pem&%s=ca.pem",
16231619
tls,
@@ -1650,7 +1646,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
16501646
mongoc_uri_destroy (uri);
16511647

16521648

1653-
snprintf (
1649+
bson_snprintf (
16541650
url_buffer, sizeof (url_buffer), "mongodb://localhost/?%s=true", tls);
16551651
uri = mongoc_uri_new (url_buffer);
16561652

@@ -1670,7 +1666,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
16701666
mongoc_uri_destroy (uri);
16711667

16721668

1673-
snprintf (url_buffer,
1669+
bson_snprintf (url_buffer,
16741670
sizeof (url_buffer),
16751671
"mongodb://localhost/?%s=true&%s=pa$$word!&%s=encrypted.pem",
16761672
tls,
@@ -1703,7 +1699,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
17031699
mongoc_uri_destroy (uri);
17041700

17051701

1706-
snprintf (url_buffer,
1702+
bson_snprintf (url_buffer,
17071703
sizeof (url_buffer),
17081704
"mongodb://localhost/?%s=true&%s=true",
17091705
tls,
@@ -1730,7 +1726,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
17301726
mongoc_uri_destroy (uri);
17311727

17321728

1733-
snprintf (url_buffer,
1729+
bson_snprintf (url_buffer,
17341730
sizeof (url_buffer),
17351731
"mongodb://localhost/?%s=foo.pem",
17361732
tlsCertificateKeyFile);
@@ -1740,7 +1736,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
17401736
mongoc_uri_destroy (uri);
17411737

17421738

1743-
snprintf (url_buffer,
1739+
bson_snprintf (url_buffer,
17441740
sizeof (url_buffer),
17451741
"mongodb://localhost/?%s=foo.pem",
17461742
tlsCAFile);
@@ -1750,7 +1746,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
17501746
mongoc_uri_destroy (uri);
17511747

17521748

1753-
snprintf (url_buffer,
1749+
bson_snprintf (url_buffer,
17541750
sizeof (url_buffer),
17551751
"mongodb://localhost/?%s=true",
17561752
tlsAllowInvalidCertificates);
@@ -1764,7 +1760,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
17641760
mongoc_uri_destroy (uri);
17651761

17661762

1767-
snprintf (url_buffer,
1763+
bson_snprintf (url_buffer,
17681764
sizeof (url_buffer),
17691765
"mongodb://localhost/?%s=true",
17701766
tlsAllowInvalidHostnames);
@@ -1778,7 +1774,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
17781774
mongoc_uri_destroy (uri);
17791775

17801776

1781-
snprintf (url_buffer,
1777+
bson_snprintf (url_buffer,
17821778
sizeof (url_buffer),
17831779
"mongodb://localhost/?%s=false&%s=foo.pem",
17841780
tls,
@@ -1789,7 +1785,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
17891785
mongoc_uri_destroy (uri);
17901786

17911787

1792-
snprintf (url_buffer,
1788+
bson_snprintf (url_buffer,
17931789
sizeof (url_buffer),
17941790
"mongodb://localhost/?%s=false&%s=foo.pem",
17951791
tls,
@@ -1800,7 +1796,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
18001796
mongoc_uri_destroy (uri);
18011797

18021798

1803-
snprintf (url_buffer,
1799+
bson_snprintf (url_buffer,
18041800
sizeof (url_buffer),
18051801
"mongodb://localhost/?%s=false&%s=true",
18061802
tls,
@@ -1815,7 +1811,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
18151811
mongoc_uri_destroy (uri);
18161812

18171813

1818-
snprintf (url_buffer,
1814+
bson_snprintf (url_buffer,
18191815
sizeof (url_buffer),
18201816
"mongodb://localhost/?%s=false&%s=false",
18211817
tls,
@@ -1837,7 +1833,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
18371833

18381834
/* Mixing options okay so long as they match */
18391835
capture_logs (true);
1840-
snprintf (url_buffer,
1836+
bson_snprintf (url_buffer,
18411837
sizeof (url_buffer),
18421838
"mongodb://localhost/?%s=true&%s=true",
18431839
tls,
@@ -1849,7 +1845,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
18491845

18501846
/* Same option with different values okay, latter overrides */
18511847
capture_logs (true);
1852-
snprintf (url_buffer,
1848+
bson_snprintf (url_buffer,
18531849
sizeof (url_buffer),
18541850
"mongodb://localhost/?%s=true&%s=false",
18551851
tls,
@@ -1869,7 +1865,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
18691865

18701866
/* Mixing options not okay if values differ */
18711867
capture_logs (false);
1872-
snprintf (url_buffer,
1868+
bson_snprintf (url_buffer,
18731869
sizeof (url_buffer),
18741870
"mongodb://localhost/?%s=true&%s=false",
18751871
tls,
@@ -1892,7 +1888,7 @@ test_mongoc_uri_tls_ssl (const char *tls,
18921888

18931889
/* No conflict appears with implicit tls=true via SRV */
18941890
capture_logs (false);
1895-
snprintf (url_buffer,
1891+
bson_snprintf (url_buffer,
18961892
sizeof (url_buffer),
18971893
"mongodb+srv://a.b.c/?%s=foo.pem",
18981894
tlsCAFile);

0 commit comments

Comments
 (0)