From a5f077cab9cf975f705030d5817e891d0a4de588 Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 17:09:52 +0100 Subject: [PATCH 01/16] Trying windows CI --- appveyor.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..0803a0ca --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,22 @@ +image: Visual Studio 2015 +version: '{build}' + +branches: + except: + - gh-pages + +platform: x64 + + +# Via https://github.com/apitrace/apitrace/blob/master/appveyor.yml + +before_build: +- cmake -H. -Bbuild -G "%CMAKE_GENERATOR%" + +build_script: +- if "%APPVEYOR_REPO_TAG%"=="true" (set CONFIGURATION=RelWithDebInfo) else (set CONFIGURATION=Debug) +- cmake --build build --config "%CONFIGURATION%" + +after_build: +- cmake --build build --config "%CONFIGURATION%" --target check +- cmake --build build --config "%CONFIGURATION%" --target package \ No newline at end of file From dc03c0faa2173ce2be99d602d67ae9025bf2b90d Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 17:11:46 +0100 Subject: [PATCH 02/16] Win CI #2 --- appveyor.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 0803a0ca..98a2da40 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,6 +8,10 @@ branches: platform: x64 +environment: + matrix: + - CMAKE_GENERATOR: "Visual Studio 15 2017 Win64" + # Via https://github.com/apitrace/apitrace/blob/master/appveyor.yml before_build: From 2c45509f70de9bcf36f6f3fb44de41274d51616e Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 17:16:59 +0100 Subject: [PATCH 03/16] Win CI #3 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 98a2da40..f9afaad1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,7 +10,7 @@ platform: x64 environment: matrix: - - CMAKE_GENERATOR: "Visual Studio 15 2017 Win64" + - CMAKE_GENERATOR: "Visual Studio 14 2015 Win64" # Via https://github.com/apitrace/apitrace/blob/master/appveyor.yml From 266cdcfeca4e34efa4bcf1f40b1cb71280e10ed1 Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 17:38:11 +0100 Subject: [PATCH 04/16] Win CI #4 --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index f9afaad1..bf931799 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,6 +16,7 @@ environment: before_build: - cmake -H. -Bbuild -G "%CMAKE_GENERATOR%" +- C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\CL.exe /? build_script: - if "%APPVEYOR_REPO_TAG%"=="true" (set CONFIGURATION=RelWithDebInfo) else (set CONFIGURATION=Debug) From 656ec1fd541fbbb0546bf776da530969a3c16831 Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 18:03:58 +0100 Subject: [PATCH 05/16] Workaround for inlines and restricts --- CMakeLists.txt | 16 ++++++++++++---- src/cbor/common.c | 26 +++++++++++++------------- src/cbor/common.h | 4 +++- src/cbor/configuration.h.in | 2 ++ 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4e4b1ba..583270dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,16 +58,24 @@ set(CPACK_PACKAGE_VERSION_PATCH ${CBOR_VERSION_PATCH}) include(CPack) -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -Wall -pedantic -g -ggdb -DDEBUG=true") -set(CMAKE_C_FLAGS_RELEASE "-O3 -flto -Wall -pedantic -DNDEBUG") - if(MINGW) # https://github.com/PJK/libcbor/issues/13 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") -else() +elseif(NOT MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") endif() +if(MSVC) + set(CBOR_RESTRICT_SPECIFIER "__restrict") + set(CBOR_INLINE_SPECIFIER "__inline") +else() + set(CBOR_RESTRICT_SPECIFIER "restrict") + set(CBOR_INLINE_SPECIFIER "inline") + + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -Wall -pedantic -g -ggdb -DDEBUG=true") + set(CMAKE_C_FLAGS_RELEASE "-O3 -flto -Wall -pedantic -DNDEBUG") +endif() + set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-g") set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-flto") diff --git a/src/cbor/common.c b/src/cbor/common.c index 2febb06c..9aabcdc0 100644 --- a/src/cbor/common.c +++ b/src/cbor/common.c @@ -15,71 +15,71 @@ #include "strings.h" #include "tags.h" -inline bool cbor_isa_uint(const cbor_item_t *item) +CBOR_INLINE_FUNCTION bool cbor_isa_uint(const cbor_item_t *item) { return item->type == CBOR_TYPE_UINT; } -inline bool cbor_isa_negint(const cbor_item_t *item) +CBOR_INLINE_FUNCTION bool cbor_isa_negint(const cbor_item_t *item) { return item->type == CBOR_TYPE_NEGINT; } -inline bool cbor_isa_bytestring(const cbor_item_t *item) +CBOR_INLINE_FUNCTION bool cbor_isa_bytestring(const cbor_item_t *item) { return item->type == CBOR_TYPE_BYTESTRING; } -inline bool cbor_isa_string(const cbor_item_t *item) +CBOR_INLINE_FUNCTION bool cbor_isa_string(const cbor_item_t *item) { return item->type == CBOR_TYPE_STRING; } -inline bool cbor_isa_array(const cbor_item_t *item) +CBOR_INLINE_FUNCTION bool cbor_isa_array(const cbor_item_t *item) { return item->type == CBOR_TYPE_ARRAY; } -inline bool cbor_isa_map(const cbor_item_t *item) +CBOR_INLINE_FUNCTION bool cbor_isa_map(const cbor_item_t *item) { return item->type == CBOR_TYPE_MAP; } -inline bool cbor_isa_tag(const cbor_item_t *item) +CBOR_INLINE_FUNCTION bool cbor_isa_tag(const cbor_item_t *item) { return item->type == CBOR_TYPE_TAG; } -inline bool cbor_isa_float_ctrl(const cbor_item_t *item) +CBOR_INLINE_FUNCTION bool cbor_isa_float_ctrl(const cbor_item_t *item) { return item->type == CBOR_TYPE_FLOAT_CTRL; } -inline cbor_type cbor_typeof(const cbor_item_t *item) +CBOR_INLINE_FUNCTION cbor_type cbor_typeof(const cbor_item_t *item) { return item->type; } -inline bool cbor_is_int(const cbor_item_t *item) +CBOR_INLINE_FUNCTION bool cbor_is_int(const cbor_item_t *item) { return cbor_isa_uint(item) || cbor_isa_negint(item); } -inline bool cbor_is_bool(const cbor_item_t *item) +CBOR_INLINE_FUNCTION bool cbor_is_bool(const cbor_item_t *item) { return cbor_isa_float_ctrl(item) && (cbor_ctrl_value(item) == CBOR_CTRL_FALSE || cbor_ctrl_value(item) == CBOR_CTRL_TRUE); } -inline bool cbor_is_null(const cbor_item_t *item) +CBOR_INLINE_FUNCTION bool cbor_is_null(const cbor_item_t *item) { return cbor_isa_float_ctrl(item) && cbor_ctrl_value(item) == CBOR_CTRL_NULL; } -inline bool cbor_is_undef(const cbor_item_t *item) +CBOR_INLINE_FUNCTION bool cbor_is_undef(const cbor_item_t *item) { return cbor_isa_float_ctrl(item) && cbor_ctrl_value(item) == CBOR_CTRL_UNDEF; } diff --git a/src/cbor/common.h b/src/cbor/common.h index 0a62d878..9c510b41 100644 --- a/src/cbor/common.h +++ b/src/cbor/common.h @@ -29,7 +29,9 @@ extern "C" { #else -#define CBOR_RESTRICT_POINTER restrict +// Windows + C++ workarounds +#define CBOR_RESTRICT_POINTER CBOR_RESTRICT_SPECIFIER +#define CBOR_INLINE_FUNCTION CBOR_INLINE_SPECIFIER #endif diff --git a/src/cbor/configuration.h.in b/src/cbor/configuration.h.in index b50e128c..b81a0e64 100644 --- a/src/cbor/configuration.h.in +++ b/src/cbor/configuration.h.in @@ -9,5 +9,7 @@ #define CBOR_BUFFER_GROWTH ${CBOR_BUFFER_GROWTH} #cmakedefine01 CBOR_PRETTY_PRINTER +#define CBOR_RESTRICT_SPECIFIER ${CBOR_RESTRICT_SPECIFIER} +#define CBOR_INLINE_SPECIFIER ${CBOR_INLINE_SPECIFIER} #endif //LIBCBOR_CONFIGURATION_H From aa9e0aead1736974050bf74827966dbef2afb310 Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 18:04:51 +0100 Subject: [PATCH 06/16] Win CI #5 --- src/cbor/common.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cbor/common.h b/src/cbor/common.h index 9c510b41..3a076fc9 100644 --- a/src/cbor/common.h +++ b/src/cbor/common.h @@ -29,12 +29,14 @@ extern "C" { #else -// Windows + C++ workarounds +// MSVC + C++ workaround #define CBOR_RESTRICT_POINTER CBOR_RESTRICT_SPECIFIER -#define CBOR_INLINE_FUNCTION CBOR_INLINE_SPECIFIER #endif +// MSVC workaround +#define CBOR_INLINE_FUNCTION CBOR_INLINE_SPECIFIER + static const uint8_t cbor_major_version = CBOR_MAJOR_VERSION; static const uint8_t cbor_minor_version = CBOR_MINOR_VERSION; static const uint8_t cbor_patch_version = CBOR_PATCH_VERSION; From cff2b4a99d47d6e6604e018112228576a9156649 Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 18:16:13 +0100 Subject: [PATCH 07/16] Win CI #6 --- CMakeLists.txt | 3 ++- appveyor.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 583270dc..1cf424ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,8 @@ elseif(NOT MSVC) endif() if(MSVC) - set(CBOR_RESTRICT_SPECIFIER "__restrict") + # This just doesn't work right -- https://msdn.microsoft.com/en-us/library/5ft82fed.aspx + set(CBOR_RESTRICT_SPECIFIER "") set(CBOR_INLINE_SPECIFIER "__inline") else() set(CBOR_RESTRICT_SPECIFIER "restrict") diff --git a/appveyor.yml b/appveyor.yml index bf931799..59f45563 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,4 +24,4 @@ build_script: after_build: - cmake --build build --config "%CONFIGURATION%" --target check -- cmake --build build --config "%CONFIGURATION%" --target package \ No newline at end of file +- cmake --build build --config "%CONFIGURATION%" --target package From 953bedab75724a59bf70e9fd6b5729dd4c7a0d41 Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 18:19:39 +0100 Subject: [PATCH 08/16] Win CI #7 --- src/cbor/bytestrings.c | 2 +- src/cbor/strings.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cbor/bytestrings.c b/src/cbor/bytestrings.c index c97ecb56..ada4832f 100644 --- a/src/cbor/bytestrings.c +++ b/src/cbor/bytestrings.c @@ -69,7 +69,7 @@ cbor_item_t *cbor_build_bytestring(cbor_data handle, size_t length) return res; } -void cbor_bytestring_set_handle(cbor_item_t *item, unsigned char * restrict data, size_t length) +void cbor_bytestring_set_handle(cbor_item_t *item, cbor_mutable_data CBOR_RESTRICT_POINTER data, size_t length) { assert(cbor_isa_bytestring(item)); assert(cbor_bytestring_is_definite(item)); diff --git a/src/cbor/strings.c b/src/cbor/strings.c index ba1319ad..35589ac9 100644 --- a/src/cbor/strings.c +++ b/src/cbor/strings.c @@ -56,7 +56,7 @@ cbor_item_t *cbor_build_stringn(const char *val, size_t length) return item; } -void cbor_string_set_handle(cbor_item_t *item, unsigned char * restrict data, size_t length) +void cbor_string_set_handle(cbor_item_t *item, cbor_mutable_data CBOR_RESTRICT_POINTER data, size_t length) { assert(cbor_isa_string(item)); assert(cbor_string_is_definite(item)); From e319cc0ff5084e1ef949049330cd9a015728c0de Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 18:22:35 +0100 Subject: [PATCH 09/16] Use standard (not Posix) header --- src/cbor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cbor.c b/src/cbor.c index 6ea6901c..86a30124 100644 --- a/src/cbor.c +++ b/src/cbor.c @@ -242,7 +242,7 @@ cbor_item_t * cbor_copy(cbor_item_t * item) #include #include #include -#include +#include #define __STDC_FORMAT_MACROS From 2793f065a58cb895c8152a90a806b80fb5687558 Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 18:53:56 +0100 Subject: [PATCH 10/16] Win CI #8 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cf424ae..01fb05ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ endif() if(MSVC) # This just doesn't work right -- https://msdn.microsoft.com/en-us/library/5ft82fed.aspx set(CBOR_RESTRICT_SPECIFIER "") - set(CBOR_INLINE_SPECIFIER "__inline") + set(CBOR_INLINE_SPECIFIER "inline") else() set(CBOR_RESTRICT_SPECIFIER "restrict") set(CBOR_INLINE_SPECIFIER "inline") From c70d47ec8da505bca0f05439d68e4eee2354c556 Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 20:38:53 +0100 Subject: [PATCH 11/16] Win CI #9 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01fb05ab..0f728a57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ endif() if(MSVC) # This just doesn't work right -- https://msdn.microsoft.com/en-us/library/5ft82fed.aspx set(CBOR_RESTRICT_SPECIFIER "") - set(CBOR_INLINE_SPECIFIER "inline") + set(CBOR_INLINE_SPECIFIER "") else() set(CBOR_RESTRICT_SPECIFIER "restrict") set(CBOR_INLINE_SPECIFIER "inline") From 7c97226830e67f827367297b693b79690d889389 Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 21:43:38 +0100 Subject: [PATCH 12/16] Disable check phase --- appveyor.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 59f45563..e0dd5a5f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,6 +22,4 @@ build_script: - if "%APPVEYOR_REPO_TAG%"=="true" (set CONFIGURATION=RelWithDebInfo) else (set CONFIGURATION=Debug) - cmake --build build --config "%CONFIGURATION%" -after_build: -- cmake --build build --config "%CONFIGURATION%" --target check -- cmake --build build --config "%CONFIGURATION%" --target package +# TODO enable CMocka tests, maybe package the binaries From 4bae06e2cb136e1afb84dd1114d4e9dfb5c3f5ae Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 22:05:49 +0100 Subject: [PATCH 13/16] Windows badge, yay! --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0e0b5ec7..0b897564 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # [libcbor](https://github.com/PJK/libcbor) [![Build Status](https://travis-ci.org/PJK/libcbor.svg?branch=master)](https://travis-ci.org/PJK/libcbor) +[![Build status](https://ci.appveyor.com/api/projects/status/8kkmvmefelsxp5u2?svg=true)](https://ci.appveyor.com/project/PJK/libcbor) [![Documentation Status](https://readthedocs.org/projects/libcbor/badge/?version=latest)](https://readthedocs.org/projects/libcbor/?badge=latest) **libcbor** is a C library for parsing and generating [CBOR](http://tools.ietf.org/html/rfc7049), the general-purpose schema-less binary data format. From 84f5c0761d5a8f60069df0477c9aa83480ede24a Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 22:08:41 +0100 Subject: [PATCH 14/16] Unify size_t modifiers --- src/cbor/arrays.h | 2 +- src/cbor/maps.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cbor/arrays.h b/src/cbor/arrays.h index 91b30ce1..62629f4e 100644 --- a/src/cbor/arrays.h +++ b/src/cbor/arrays.h @@ -86,7 +86,7 @@ cbor_item_t ** cbor_array_handle(const cbor_item_t * item); * @param size Number of slots to preallocate * @return **new** array or `NULL` upon malloc failure */ -cbor_item_t * cbor_new_definite_array(const size_t size); +cbor_item_t * cbor_new_definite_array(size_t size); /** Create new indefinite array * diff --git a/src/cbor/maps.h b/src/cbor/maps.h index 4c3af13d..cd433b31 100644 --- a/src/cbor/maps.h +++ b/src/cbor/maps.h @@ -39,7 +39,7 @@ size_t cbor_map_allocated(const cbor_item_t *item); * @param size The number of slots to preallocate * @return **new** definite map. `NULL` on malloc failure. */ -cbor_item_t *cbor_new_definite_map(const size_t size); +cbor_item_t *cbor_new_definite_map(size_t size); /** Create a new indefinite map * From 0f49dbd08cd394f419d8457e1d9dff9001f1032f Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 22:09:28 +0100 Subject: [PATCH 15/16] Try __inline --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f728a57..1cf424ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ endif() if(MSVC) # This just doesn't work right -- https://msdn.microsoft.com/en-us/library/5ft82fed.aspx set(CBOR_RESTRICT_SPECIFIER "") - set(CBOR_INLINE_SPECIFIER "") + set(CBOR_INLINE_SPECIFIER "__inline") else() set(CBOR_RESTRICT_SPECIFIER "restrict") set(CBOR_INLINE_SPECIFIER "inline") From eb483ba8f5671c120185d8f8f7bbeca64e2be44d Mon Sep 17 00:00:00 2001 From: PJK Date: Fri, 6 Jan 2017 22:19:42 +0100 Subject: [PATCH 16/16] Give up on inlining --- CMakeLists.txt | 3 ++- appveyor.yml | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cf424ae..fc844950 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,8 @@ endif() if(MSVC) # This just doesn't work right -- https://msdn.microsoft.com/en-us/library/5ft82fed.aspx set(CBOR_RESTRICT_SPECIFIER "") - set(CBOR_INLINE_SPECIFIER "__inline") + # This also didn't link -- https://msdn.microsoft.com/en-us/library/799kze2z.aspx + set(CBOR_INLINE_SPECIFIER "") else() set(CBOR_RESTRICT_SPECIFIER "restrict") set(CBOR_INLINE_SPECIFIER "inline") diff --git a/appveyor.yml b/appveyor.yml index e0dd5a5f..452ced56 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -23,3 +23,5 @@ build_script: - cmake --build build --config "%CONFIGURATION%" # TODO enable CMocka tests, maybe package the binaries +# TODO add MinGW +# TODO add older MSVC \ No newline at end of file