Commit 907b508e authored by Kenton Varda's avatar Kenton Varda Committed by GitHub

Merge pull request #387 from harrishancock/msvc-grab-bag

A grab bag of small changes to support the MSVC port
parents b6d7079a 73e9b41a
......@@ -243,9 +243,11 @@ if(BUILD_TESTING)
${test_capnp_h_files}
)
target_link_libraries(capnp-heavy-tests ${test_libraries})
set_target_properties(capnp-heavy-tests
PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations"
)
if(NOT MSVC)
set_target_properties(capnp-heavy-tests
PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations"
)
endif()
add_dependencies(check capnp-heavy-tests)
add_test(NAME capnp-heavy-tests-run COMMAND capnp-heavy-tests)
......
......@@ -577,7 +577,12 @@ KJ_TEST("basic json decoding") {
KJ_EXPECT_THROW_MESSAGE("Input remains", json.decodeRaw("11a", root));
KJ_EXPECT_THROW_MESSAGE("Invalid escape", json.decodeRaw(R"("\z")", root));
KJ_EXPECT_THROW_MESSAGE("Invalid escape", json.decodeRaw(R"("\z")", root));
KJ_EXPECT_THROW_MESSAGE("ends prematurely", json.decodeRaw(R"(["\n\", 3])", root));
{
// TODO(msvc): This raw string literal currently confuses MSVC's preprocessor, so I hoisted
// it outside the macro.
auto f = [&] { json.decodeRaw(R"(["\n\", 3])", root); };
KJ_EXPECT_THROW_MESSAGE("ends prematurely", f());
}
KJ_EXPECT_THROW_MESSAGE("Invalid hex", json.decodeRaw(R"("\u12zz")", root));
KJ_EXPECT_THROW_MESSAGE("ends prematurely", json.decodeRaw("-", root));
KJ_EXPECT_THROW_MESSAGE("Unexpected input", json.decodeRaw("--", root));
......
......@@ -634,6 +634,7 @@ public:
// - DynamicEnum: Returns the corresponding type.
// - DynamicStruct, DynamicList: Returns the corresponding Reader.
// - Any capability type, including DynamicCapability: Returns the corresponding Client.
// - DynamicValue: Returns an identical Reader. Useful to avoid special-casing in generic code.
// (TODO(perf): On GCC 4.8 / Clang 3.3, provide rvalue-qualified version that avoids
// refcounting.)
//
......@@ -1408,6 +1409,19 @@ struct DynamicValue::Builder::AsImpl<T, Kind::INTERFACE> {
}
};
template <>
struct DynamicValue::Reader::AsImpl<DynamicValue> {
static DynamicValue::Reader apply(const Reader& reader) {
return reader;
}
};
template <>
struct DynamicValue::Builder::AsImpl<DynamicValue> {
static DynamicValue::Builder apply(Builder& builder) {
return builder;
}
};
inline DynamicValue::Pipeline::Pipeline(std::nullptr_t n): type(UNKNOWN) {}
inline DynamicValue::Pipeline::Pipeline(DynamicStruct::Pipeline&& value)
: type(STRUCT), structValue(kj::mv(value)) {}
......
......@@ -36,7 +36,7 @@ struct SkipTestHack {
SkipTestHack() {
if (getenv("CAPNP_SKIP_FUZZ_TEST") != nullptr) {
char message[] = "Skipping test because CAPNP_SKIP_FUZZ_TEST is set in environment.\n";
write(STDOUT_FILENO, message, sizeof(message));
KJ_SYSCALL(write(STDOUT_FILENO, message, sizeof(message)));
_exit(0);
}
}
......
......@@ -19,7 +19,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// This file is included form all generated headers.
// This file is included from all generated headers.
#ifndef CAPNP_GENERATED_HEADER_SUPPORT_H_
#define CAPNP_GENERATED_HEADER_SUPPORT_H_
......
......@@ -58,7 +58,8 @@ public:
if (amount == 0 || canPrintAllInline(items, kind)) {
return kj::StringTree(kj::mv(items), ", ");
} else {
char delim[amount * 2 + 3];
KJ_STACK_ARRAY(char, delimArrayPtr, amount * 2 + 3, 32, 256);
auto delim = delimArrayPtr.begin();
delim[0] = ',';
delim[1] = '\n';
memset(delim + 2, ' ', amount * 2);
......
......@@ -86,6 +86,9 @@
#endif
#if defined(_MSC_VER)
#ifndef NOMINMAX
#define NOMINMAX 1
#endif
#include <intrin.h> // __popcnt
#endif
......
......@@ -56,7 +56,7 @@ TEST(Io, WriteVec) {
KJ_TEST("stringify AutoCloseFd") {
int fds[2];
miniposix::pipe(fds);
KJ_SYSCALL(miniposix::pipe(fds));
AutoCloseFd in(fds[0]), out(fds[1]);
KJ_EXPECT(kj::str(in) == kj::str(fds[0]), in, fds[0]);
......
......@@ -94,8 +94,12 @@ private:
// TODO(someday): Generalize the above template and make it common. I tried, but C++ decided to
// be difficult so I cut my losses.
static constexpr auto spaceSize = maxSize(sizeof(Variants)...);
// TODO(msvc): This constant could just as well go directly inside space's bracket's, where it's
// used, but MSVC suffers a parse error on `...`.
union {
byte space[maxSize(sizeof(Variants)...)];
byte space[spaceSize];
void* forceAligned;
// TODO(someday): Use C++11 alignas() once we require GCC 4.8 / Clang 3.3.
......
......@@ -134,7 +134,7 @@ void* Thread::runThread(void* ptr) {
void Thread::ThreadState::unref() {
#if _MSC_VER
if (_InterlockedDecrement(&refcount)) {
if (_InterlockedDecrement(&refcount) == 0) {
#else
if (__atomic_sub_fetch(&refcount, 1, __ATOMIC_RELEASE) == 0) {
__atomic_thread_fence(__ATOMIC_ACQUIRE);
......
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