Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

Build fixes for MSVC. #135

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ endif()
if (MSVC)
set (BSON_OS 2)
set (BSON_HAVE_CLOCK_GETTIME 0)
set (BSON_HAVE_SNPRINTF 0)
if (MSVC14)
set (BSON_HAVE_SNPRINTF 1)
else()
set (BSON_HAVE_SNPRINTF 0)
endif()
set (BSON_HAVE_STDBOOL_H 0)
set (BSON_HAVE_STRNLEN 0)
else ()
Expand Down
9 changes: 7 additions & 2 deletions src/bson/bson.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#include <string.h>
#include <math.h>

#if defined(_MSC_VER) && (_MSC_VER >= 1400 && _MSC_VER < 1900)
#define NEEDS_SET_TWO_DIGIT_EXPONENT
#include <stdio.h> // _set_output_format and _TWO_DIGIT_EXPONENT Added in vs2005 and removed in vs2015.
#endif

#include "b64_ntop.h"
#include "bson.h"
#include "bson-private.h"
Expand Down Expand Up @@ -2346,13 +2351,13 @@ _bson_as_json_visit_double (const bson_iter_t *iter,
{
bson_json_state_t *state = data;

#ifdef _MSC_VER
#ifdef NEEDS_SET_TWO_DIGIT_EXPONENT
unsigned int current_format = _set_output_format(_TWO_DIGIT_EXPONENT);
#endif

bson_string_append_printf (state->str, "%.15g", v_double);

#ifdef _MSC_VER
#ifdef NEEDS_SET_TWO_DIGIT_EXPONENT
_set_output_format(current_format);
#endif

Expand Down
2 changes: 1 addition & 1 deletion tests/TestSuite.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
# define AtomicInt_DecrementAndTest(p) (bson_atomic_int_add(p, -1) == 0)


#if defined(_MSC_VER)
#if defined(_MSC_VER) && _MSC_VER < 1900
struct timespec
{
time_t tv_sec;
Expand Down
2 changes: 2 additions & 0 deletions tests/test-bson.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ test_bson_new_from_buffer (void)
static void
test_bson_utf8_key (void)
{
#ifndef _MSC_VER
uint32_t length;
bson_iter_t iter;
const char *str;
Expand All @@ -1091,6 +1092,7 @@ test_bson_utf8_key (void)
assert(length == 15); /* 5 3-byte sequences. */
assert(!strcmp(str, "€€€€€"));
bson_destroy(b);
#endif
}


Expand Down
2 changes: 2 additions & 0 deletions tests/test-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ test_bson_as_json_double (void)
static void
test_bson_as_json_utf8 (void)
{
#ifndef _MSC_VER
size_t len;
bson_t *b;
char *str;
Expand All @@ -152,6 +153,7 @@ test_bson_as_json_utf8 (void)
assert(!strcmp(str, "{ \"€€€€€\" : \"€€€€€\" }"));
bson_free(str);
bson_destroy(b);
#endif
}


Expand Down