diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..865c125 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,32 @@ +build: + verbosity: detailed + +branches: + only: + - master + - development + +platform: x64 + +environment: + matrix: + - GENERATOR: Visual Studio 16 2019 + BUILD_TYPE: Debug + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 + +build_script: + - mkdir tmp + - cd tmp + - curl -fsSL "https://github.com/microsoft/GSL/archive/v2.0.0.zip" -o gsl.zip + - 7z x gsl.zip + - Xcopy /E /I GSL-2.0.0\include\gsl ..\include\extern\gsl\ + - curl -fsSL "https://github.com/Tencent/rapidjson/archive/v1.1.0.zip" -o rapidjson.zip + - 7z x rapidjson.zip + - Xcopy /E /I rapidjson-1.1.0\include\rapidjson ..\include\extern\rapidjson + - cd .. + - mkdir build + - cd build + - cmake .. -G "%GENERATOR%" -A x64 -Dbuild_abi=ON -Dextended_test=ON + - cmake --build . --config %BUILD_TYPE% + - path=%cd%\%BUILD_TYPE%;%PATH% + - ctest --output-on-failure --build-config %BUILD_TYPE% diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a30389..a0bd504 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,9 +19,9 @@ option(gen_coverage "Generate gcov coverage information in support envs" OFF) option(use_asan "Link tests with address sanitizer" OFF) # Check which dependencies are installed. -find_path(libgsl gsl/gsl) find_library(libyaml yaml) -find_path(librj rapidjson/reader.h) +find_path(libgsl gsl/gsl HINTS ${PROJECT_SOURCE_DIR}/include/extern) +find_path(librj rapidjson/reader.h HINTS ${PROJECT_SOURCE_DIR}/include/extern) if (NOT librj) CHECK_INCLUDE_FILE_CXX("rapidjson/reader.h" librj) endif () diff --git a/README.md b/README.md index 8884856..3e16100 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Dart ============== [![Build Status](https://travis-ci.com/target/libdart.svg?branch=master)](https://travis-ci.com/target/libdart) +[![Build status](https://ci.appveyor.com/api/projects/status/trv6dpc03nm3d9df?svg=true)](https://ci.appveyor.com/project/Cfretz244/libdart) [![Coverage Status](https://coveralls.io/repos/github/target/libdart/badge.svg?branch=master)](https://coveralls.io/github/target/libdart?branch=master) ### A High Performance, Network Optimized, JSON Manipulation Library **Dart** is both a wire-level binary `JSON` protocol, along with a high performance, diff --git a/include/dart/abi.h b/include/dart/abi.h index 9db4a8d..2b6d639 100644 --- a/include/dart/abi.h +++ b/include/dart/abi.h @@ -8118,6 +8118,20 @@ extern "C" { */ DART_ABI_EXPORT char const* dart_get_error(); + /** + * @brief + * Free a buffer returned from one of the dart_*_dup_bytes functions + * + * @details + * Dart requires its buffer representations to be aligned to a 64-bit + * boundary for internal design reasons (simplifies alignment logic significantly). + * Very easy to do on *nix machines with posix_memalign, which allocates aligned + * memory that can be passed directly to free. + * Windows, on the other hand, has _aligned_malloc and _aligned_free, which MUST + * be paired, so to write portable code this function must exist. + */ + DART_ABI_EXPORT void dart_aligned_free(void* ptr); + #ifdef __cplusplus } #endif diff --git a/src/generic.cc b/src/generic.cc index 393360b..704ea3a 100644 --- a/src/generic.cc +++ b/src/generic.cc @@ -1644,4 +1644,8 @@ extern "C" { return dart::detail::errmsg.data(); } + void dart_aligned_free(void* ptr) { + dart::shim::aligned_free(ptr); + } + } diff --git a/test/buffer_abi_unit_tests.cc b/test/buffer_abi_unit_tests.cc index 5381571..8e56d20 100644 --- a/test/buffer_abi_unit_tests.cc +++ b/test/buffer_abi_unit_tests.cc @@ -512,8 +512,8 @@ SCENARIO("finalized buffer objects have unique object representations") { auto* ownone = dart_buffer_dup_bytes(&finone, &lenone); auto* owntwo = dart_buffer_dup_bytes(&fintwo, nullptr); auto guard = make_scope_guard([&] { - free(owntwo); - free(ownone); + dart_aligned_free(owntwo); + dart_aligned_free(ownone); }); REQUIRE(lenone == lentwo); REQUIRE(std::memcmp(ownone, owntwo, lenone) == 0); diff --git a/test/generic_abi_unit_tests.cc b/test/generic_abi_unit_tests.cc index a898c19..fb9b1ff 100644 --- a/test/generic_abi_unit_tests.cc +++ b/test/generic_abi_unit_tests.cc @@ -1120,8 +1120,8 @@ SCENARIO("finalized objects have unique object representations") { auto* ownone = dart_dup_bytes(&finone, &lenone); auto* owntwo = dart_dup_bytes(&fintwo, &lentwo); auto guard = make_scope_guard([&] { - free(owntwo); - free(ownone); + dart_aligned_free(owntwo); + dart_aligned_free(ownone); }); REQUIRE(lenone == lentwo); REQUIRE(std::memcmp(ownone, owntwo, lenone) == 0); diff --git a/test/heap_abi_unit_tests.cc b/test/heap_abi_unit_tests.cc index 740d38e..691d753 100644 --- a/test/heap_abi_unit_tests.cc +++ b/test/heap_abi_unit_tests.cc @@ -1118,8 +1118,8 @@ SCENARIO("heap finalized objects have unique object representations") { auto* ownone = dart_dup_bytes(&finone, &lenone); auto* owntwo = dart_dup_bytes(&fintwo, &lentwo); auto guard = make_scope_guard([&] { - free(owntwo); - free(ownone); + dart_aligned_free(owntwo); + dart_aligned_free(ownone); }); REQUIRE(lenone == lentwo); REQUIRE(std::memcmp(ownone, owntwo, lenone) == 0); diff --git a/test/json_test.cc b/test/json_test.cc index 258e1e3..27ee179 100644 --- a/test/json_test.cc +++ b/test/json_test.cc @@ -255,22 +255,6 @@ TEST_CASE("dart_packet parses JSON via RapidJSON", "[json unit]") { compare_rj_dart_abi(packet, &bufferthree); compare_rj_dart_abi(packet, &bufferfour); - // Validate the underlying buffer. - auto pktdup = dart_take_bytes(dart_dup_bytes(&bufferone, nullptr)); - auto pktduptwo = dart_take_bytes_rc(dart_dup_bytes(&bufferone, nullptr), DART_RC_SAFE); - auto bufferdup = dart_buffer_take_bytes(dart_buffer_dup_bytes(&bufferone, nullptr)); - auto bufferduptwo = dart_buffer_take_bytes_rc(dart_buffer_dup_bytes(&bufferone, nullptr), DART_RC_SAFE); - auto guard_two = make_scope_guard([&] { - dart_destroy(&bufferduptwo); - dart_destroy(&bufferdup); - dart_destroy(&pktduptwo); - dart_destroy(&pktdup); - }); - compare_rj_dart_abi(packet, &pktdup); - compare_rj_dart_abi(packet, &pktduptwo); - compare_rj_dart_abi(packet, &bufferdup); - compare_rj_dart_abi(packet, &bufferduptwo); - // Generate JSON, reparse it, and validate it's still the same. rj::Document rjone, rjtwo, rjthree; auto* pktjson = dart_to_json(&pktone, nullptr);