Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC compatibility and Windows CI #47

Merged
merged 16 commits into from
Jan 6, 2017
Merged
18 changes: 14 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,26 @@ 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)
# This just doesn't work right -- https://msdn.microsoft.com/en-us/library/5ft82fed.aspx
set(CBOR_RESTRICT_SPECIFIER "")
# 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")

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")

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
27 changes: 27 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
image: Visual Studio 2015
version: '{build}'

branches:
except:
- gh-pages

platform: x64


environment:
matrix:
- CMAKE_GENERATOR: "Visual Studio 14 2015 Win64"

# Via https://github.com/apitrace/apitrace/blob/master/appveyor.yml

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)
- cmake --build build --config "%CONFIGURATION%"

# TODO enable CMocka tests, maybe package the binaries
# TODO add MinGW
# TODO add older MSVC
2 changes: 1 addition & 1 deletion src/cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ cbor_item_t * cbor_copy(cbor_item_t * item)
#include <inttypes.h>
#include <wchar.h>
#include <locale.h>
#include <unistd.h>
#include <stdlib.h>

#define __STDC_FORMAT_MACROS

Expand Down
2 changes: 1 addition & 1 deletion src/cbor/arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion src/cbor/bytestrings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
26 changes: 13 additions & 13 deletions src/cbor/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion src/cbor/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ extern "C" {

#else

#define CBOR_RESTRICT_POINTER restrict
// MSVC + C++ workaround
#define CBOR_RESTRICT_POINTER CBOR_RESTRICT_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;
Expand Down
2 changes: 2 additions & 0 deletions src/cbor/configuration.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/cbor/maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion src/cbor/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down