Skip to content

Commit 1aa7097

Browse files
committed
Merge branch 'develop'
2 parents 062983a + 185088a commit 1aa7097

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+5049
-2050
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
*.swp
55
*.gcov
66
/.sconsign.dblite
7+
/.sconf_temp/
8+
/config.log
9+
mpack-test-file
10+
/mpack-test-dir/
711

812
# folders
913
/tags

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
language: c
22

3+
before_install:
4+
- pip install --user cpp-coveralls
5+
36
addons:
47
apt:
58
packages:

Doxyfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ PREDEFINED = \
4040
MPACK_READ_TRACKING=1 \
4141
MPACK_WRITE_TRACKING=1 \
4242
\
43+
MPACK_HEADER_START= \
44+
MPACK_HEADER_END= \
4345

4446
MARKDOWN_SUPPORT = YES
4547
JAVADOC_AUTOBRIEF = YES

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
[![Build Status](https://travis-ci.org/ludocode/mpack.svg?branch=master)](https://travis-ci.org/ludocode/mpack/branches)
2-
31
## Introduction
42

53
MPack is a C implementation of an encoder and decoder for the [MessagePack](http://msgpack.org/) serialization format. It is intended to be:
@@ -16,7 +14,13 @@ The MPack code is small enough to be embedded directly into your codebase. The e
1614

1715
MPack is written in the portable intersection of C99 and C++. In other words, it's written in C99, but if you are stuck using a certain popular compiler from a certain unpopular vendor that refuses to support C99, you can compile it as C++ instead.
1816

19-
*NOTE: MPack is beta software under development. The API occasionally changes, there are still some TODOs in the codebase, some security issues to fix, some MessagePack 1.0/1.1 compatibility and interoperability issues to sort out, some test suite portability issues to fix, and there is only around 65% unit test coverage.*
17+
## Build Status
18+
19+
MPack is beta software under development.
20+
21+
| [Travis-CI](https://travis-ci.org/) | [Coveralls.io](https://coveralls.io/) |
22+
| :-------: | :----------: |
23+
| [![Build Status](https://travis-ci.org/ludocode/mpack.svg?branch=master)](https://travis-ci.org/ludocode/mpack/branches) | [![Coverage Status](https://coveralls.io/repos/ludocode/mpack/badge.svg?branch=master&service=github)](https://coveralls.io/github/ludocode/mpack?branch=master) |
2024

2125
## The Node Reader API
2226

@@ -39,7 +43,7 @@ if (mpack_tree_destroy(tree) != mpack_ok) {
3943
}
4044
```
4145
42-
Note that no additional error handling is needed in the above code. If the file is missing or corrupt, if map keys are missing or if nodes are not in the expected types, special "nil" nodes and false/zero values are returned and the tree is placed in an error state. An error check is only needed before using the data. Alternatively, the tree can be configured to longjmp in such cases if a handler is set.
46+
Note that no additional error handling is needed in the above code. If the file is missing or corrupt, if map keys are missing or if nodes are not in the expected types, special "nil" nodes and false/zero values are returned and the tree is placed in an error state. An error check is only needed before using the data.
4347
4448
## The Write API
4549
@@ -73,7 +77,7 @@ free(data);
7377

7478
In the above example, we encode to a growable memory buffer. The writer can instead write to a pre-allocated or stack-allocated buffer, avoiding the need for memory allocation. The writer can also be provided with a flush function (such as a file or socket write function) to call when the buffer is full or when writing is done.
7579

76-
If any error occurs, the writer is placed in an error state and can optionally longjmp if a handler is set. The writer will flag an error if too much data is written, if the wrong number of elements are written, if the data could not be flushed, etc. No additional error handling is needed in the above code; any subsequent writes are ignored when the writer is in an error state, so you don't need to check every write for errors.
80+
If any error occurs, the writer is placed in an error state. The writer will flag an error if too much data is written, if the wrong number of elements are written, if the data could not be flushed, etc. No additional error handling is needed in the above code; any subsequent writes are ignored when the writer is in an error state, so you don't need to check every write for errors.
7781

7882
Note in particular that in debug mode, the `mpack_finish_map()` call above ensures that two key/value pairs were actually written as claimed, something that other MessagePack C/C++ libraries may not do.
7983

@@ -83,7 +87,7 @@ Conceptually, MessagePack stores data similarly to JSON: they are both composed
8387

8488
- Compound types such as strings, maps and arrays are delimited, so appropriate storage cannot be allocated upfront. The whole object must be parsed to determine its size.
8589

86-
- Strings are not stored in their native encoding. They cannot contain quotes or special characters, so they must be escaped when written and converted back when read.
90+
- Strings are not stored in their native encoding. Special characters such as quotes and backslashes must be escaped when written and converted back when read.
8791

8892
- Numbers are particularly inefficient (especially when parsing back floats), making JSON inappropriate as a base format for structured data that contains lots of numbers.
8993

SConscript

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import platform
22

33
Import('env', 'CPPFLAGS', 'LINKFLAGS')
44

5+
# we add the C/C++ specific flags here. we can't use CCFLAGS/CXXFLAGS
6+
# because as far as SCons is concerned, they are all C files; we're
7+
# passing -x c++ to force the language.
8+
if "c++" in CPPFLAGS:
9+
CPPFLAGS += ["-Wmissing-declarations"]
10+
LINKFLAGS += ["-lstdc++"]
11+
else:
12+
CPPFLAGS += ["-Wmissing-prototypes", "-Wc++-compat"]
13+
514
srcs = env.Object(env.Glob('src/mpack/*.c') + env.Glob('test/*.c'),
615
CPPFLAGS=env['CPPFLAGS'] + CPPFLAGS)
716

SConstruct

Lines changed: 92 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
import platform, os
22

3+
def CheckFlags(context, cppflags, linkflags = [], message = None):
4+
if message == None:
5+
message = " ".join(cppflags + ((cppflags != linkflags) and linkflags or []))
6+
context.Message("Checking for " + message + " support... ")
7+
8+
env.Prepend(CPPFLAGS = cppflags, LINKFLAGS = linkflags)
9+
result = context.TryLink("int main(void){return 0;}\n", '.c')
10+
env.Replace(CPPFLAGS = env["CPPFLAGS"][len(cppflags):], LINKFLAGS = env["LINKFLAGS"][len(linkflags):])
11+
12+
context.Result(result)
13+
return result
14+
315

416
# Common environment setup
517

618
env = Environment()
19+
conf = Configure(env, custom_tests = {'CheckFlags': CheckFlags})
20+
721
for x in os.environ.keys():
822
if x in ["CC", "CXX", "PATH", "TRAVIS", "TERM"] or x.startswith("CLANG_") or x.startswith("CCC_"):
923
env[x] = os.environ[x]
10-
env["ENV"][x] = os.environ[x]
1124

1225
env.Append(CPPFLAGS = [
1326
"-Wall", "-Wextra", "-Werror",
@@ -19,11 +32,12 @@ env.Append(CPPFLAGS = [
1932
env.Append(LINKFLAGS = [
2033
"-g",
2134
])
35+
# Additional warning flags are passed in SConscript based on the language (C/C++)
2236

23-
if 'CC' not in env or "clang" not in env['CC']:
24-
env.Append(CPPFLAGS = ["-Wno-float-conversion"]) # unsupported in clang 3.4
25-
env.Append(CPPFLAGS = ["-fprofile-arcs", "-ftest-coverage"]) # only works properly with gcc
26-
env.Append(LINKFLAGS = ["-fprofile-arcs", "-ftest-coverage"])
37+
if 'TRAVIS' not in env:
38+
# Travis-CI currently uses Clang 3.4 which does not support this option,
39+
# and it also appears to be incompatible with other GCC options on Travis-CI
40+
env.Append(CPPFLAGS = ["-Wno-float-conversion"])
2741

2842

2943
# Optional flags used in various builds
@@ -41,74 +55,104 @@ noioconfigs = [
4155
]
4256
allconfigs = noioconfigs + ["-DMPACK_STDIO=1"]
4357

44-
debugflags = ["-DDEBUG", "-O0"]
45-
releaseflags = ["-Os"] # If you change this, also change the MPACK_OPTIMIZE_FOR_SIZE below to test the opposite
46-
cflags = ["-std=c99", "-Wc++-compat"]
58+
hasOg = conf.CheckFlags(["-Og"])
59+
if hasOg:
60+
debugflags = ["-DDEBUG", "-Og"]
61+
else:
62+
debugflags = ["-DDEBUG", "-O0"]
63+
releaseflags = ["-Os"]
64+
cflags = ["-std=c99"]
65+
66+
gcovflags = []
67+
if ARGUMENTS.get('gcov'):
68+
gcovflags = ["-DMPACK_GCOV=1", "--coverage"]
69+
70+
ltoflags = ["-O3", "-flto", "-fuse-linker-plugin", "-fno-fat-lto-objects"]
71+
72+
# -lstdc++ is added in SConscript
73+
cxxflags = ["-x", "c++"]
4774

4875

4976
# Functions to add a variant build. One variant build will build and run the
5077
# entire library and test suite in a given configuration.
5178

52-
def AddBuild(variant_dir, cppflags, linkflags):
79+
def AddBuild(variant_dir, cppflags, linkflags = []):
5380
env.SConscript("SConscript",
5481
variant_dir="build/" + variant_dir,
5582
src="../..",
56-
exports={'env': env, 'CPPFLAGS': cppflags, 'LINKFLAGS': linkflags},
83+
exports={
84+
'env': env,
85+
'CPPFLAGS': cppflags,
86+
'LINKFLAGS': linkflags
87+
},
5788
duplicate=0)
5889

59-
def AddBuilds(variant_dir, cppflags, linkflags):
90+
def AddBuilds(variant_dir, cppflags, linkflags = []):
6091
AddBuild("debug-" + variant_dir, debugflags + cppflags, debugflags + linkflags)
61-
AddBuild("release-" + variant_dir, releaseflags + cppflags, releaseflags + linkflags)
92+
if ARGUMENTS.get('all'):
93+
AddBuild("release-" + variant_dir, releaseflags + cppflags, releaseflags + linkflags)
6294

6395

64-
# The default build, everything in debug. Run "scons dev=1" during
65-
# development to build only this. You would also use this for static
66-
# analysis, e.g. "scan-build scons dev=1".
96+
# The default build, everything in debug. This is the build used
97+
# for code coverage measurement and static analysis.
6798

68-
AddBuild("debug", allfeatures + allconfigs + debugflags + cflags, [])
99+
AddBuild("debug", allfeatures + allconfigs + debugflags + cflags + gcovflags, gcovflags)
69100

70101

71-
# Otherwise run all builds. Use a parallel build, e.g. "scons -j12" to
72-
# build this in a reasonable amount of time.
102+
# Run "scons more=1" to run a handful of builds that are likely
103+
# to reveal configuration errors.
104+
if ARGUMENTS.get('more') or ARGUMENTS.get('all'):
105+
AddBuild("release", allfeatures + allconfigs + releaseflags + cflags)
106+
AddBuilds("embed", allfeatures + cflags)
107+
AddBuilds("noio", allfeatures + noioconfigs + cflags)
73108

109+
110+
# Run "scons all=1" to run all builds. This is what the CI runs.
74111
if ARGUMENTS.get('all'):
75-
AddBuild("release", allfeatures + allconfigs + releaseflags + cflags, [])
112+
113+
# various release builds
114+
AddBuild("release-unopt", allfeatures + allconfigs + cflags + ["-O0"])
115+
AddBuild("release-fastmath", allfeatures + allconfigs + releaseflags + cflags + ["-ffast-math"])
76116
AddBuild("release-speed", ["-DMPACK_OPTIMIZE_FOR_SIZE=0"] +
77-
allfeatures + allconfigs + releaseflags + cflags, [])
117+
allfeatures + allconfigs + releaseflags + cflags)
118+
if conf.CheckFlags(ltoflags, ltoflags, "-flto"):
119+
AddBuild("release-lto", allfeatures + allconfigs + ltoflags + cflags, ltoflags)
78120

79121
# feature subsets with default configuration
80-
AddBuilds("empty", allconfigs + cflags, [])
81-
AddBuilds("writer", ["-DMPACK_WRITER=1"] + allconfigs + cflags, [])
82-
AddBuilds("reader", ["-DMPACK_READER=1"] + allconfigs + cflags, [])
83-
AddBuilds("expect", ["-DMPACK_READER=1", "-DMPACK_EXPECT=1"] + allconfigs + cflags, [])
84-
AddBuilds("node", ["-DMPACK_NODE=1"] + allconfigs + cflags, [])
122+
AddBuilds("empty", allconfigs + cflags)
123+
AddBuilds("writer", ["-DMPACK_WRITER=1"] + allconfigs + cflags)
124+
AddBuilds("reader", ["-DMPACK_READER=1"] + allconfigs + cflags)
125+
AddBuilds("expect", ["-DMPACK_READER=1", "-DMPACK_EXPECT=1"] + allconfigs + cflags)
126+
AddBuilds("node", ["-DMPACK_NODE=1"] + allconfigs + cflags)
85127

86128
# no i/o
87-
AddBuilds("noio", allfeatures + noioconfigs + cflags, [])
88-
AddBuilds("noio-writer", ["-DMPACK_WRITER=1"] + noioconfigs + cflags, [])
89-
AddBuilds("noio-reader", ["-DMPACK_READER=1"] + noioconfigs + cflags, [])
90-
AddBuilds("noio-expect", ["-DMPACK_READER=1", "-DMPACK_EXPECT=1"] + noioconfigs + cflags, [])
91-
AddBuilds("noio-node", ["-DMPACK_NODE=1"] + noioconfigs + cflags, [])
129+
AddBuilds("noio-writer", ["-DMPACK_WRITER=1"] + noioconfigs + cflags)
130+
AddBuilds("noio-reader", ["-DMPACK_READER=1"] + noioconfigs + cflags)
131+
AddBuilds("noio-expect", ["-DMPACK_READER=1", "-DMPACK_EXPECT=1"] + noioconfigs + cflags)
132+
AddBuilds("noio-node", ["-DMPACK_NODE=1"] + noioconfigs + cflags)
92133

93134
# embedded builds without libc
94-
AddBuilds("embed", allfeatures + cflags, [])
95-
AddBuilds("embed-writer", ["-DMPACK_WRITER=1"] + cflags, [])
96-
AddBuilds("embed-reader", ["-DMPACK_READER=1"] + cflags, [])
97-
AddBuilds("embed-expect", ["-DMPACK_READER=1", "-DMPACK_EXPECT=1"] + cflags, [])
98-
AddBuilds("embed-node", ["-DMPACK_NODE=1"] + cflags, [])
135+
AddBuilds("embed-writer", ["-DMPACK_WRITER=1"] + cflags)
136+
AddBuilds("embed-reader", ["-DMPACK_READER=1"] + cflags)
137+
AddBuilds("embed-expect", ["-DMPACK_READER=1", "-DMPACK_EXPECT=1"] + cflags)
138+
AddBuilds("embed-node", ["-DMPACK_NODE=1"] + cflags)
99139

100140
# miscellaneous test builds
101-
AddBuilds("cxx", allfeatures + allconfigs + ["-xc++", "-std=c++98"], ["-lstdc++"])
102-
AddBuilds("notrack", ["-DMPACK_NO_TRACKING=1"] + allfeatures + allconfigs + cflags, [])
103-
AddBuilds("realloc", allfeatures + allconfigs + debugflags + cflags + ["-DMPACK_REALLOC=test_realloc"], [])
104-
105-
# Travis-CI currently only has GCC 4.6 and Clang 3.4, doesn't properly support these options
106-
if 'TRAVIS' not in env:
107-
AddBuilds("c11", allfeatures + allconfigs + ["-std=c11", "-Wc++-compat"], [])
108-
AddBuilds("cxx11", allfeatures + allconfigs + ["-xc++", "-std=c++11"], ["-lstdc++"])
109-
AddBuilds("cxx14", allfeatures + allconfigs + ["-xc++", "-std=c++14"], ["-lstdc++"])
110-
111-
# 32-bit builds (Travis-CI doesn't support multilib)
112-
if 'TRAVIS' not in env and '64' in platform.architecture()[0]:
141+
AddBuilds("notrack", ["-DMPACK_NO_TRACKING=1"] + allfeatures + allconfigs + cflags)
142+
AddBuilds("realloc", allfeatures + allconfigs + debugflags + cflags + ["-DMPACK_REALLOC=test_realloc"])
143+
if hasOg:
144+
AddBuild("debug-O0", allfeatures + allconfigs + ["-DDEBUG", "-O0"] + cflags)
145+
146+
# other language standards (C11, various C++ versions)
147+
if conf.CheckFlags(["-std=c11"]):
148+
AddBuilds("c11", allfeatures + allconfigs + ["-std=c11"])
149+
AddBuilds("cxx", allfeatures + allconfigs + cxxflags + ["-std=c++98"])
150+
if conf.CheckFlags(cxxflags + ["-std=c++11"], [], "-std=c++11"):
151+
AddBuilds("cxx11", allfeatures + allconfigs + cxxflags + ["-std=c++11"])
152+
if conf.CheckFlags(cxxflags + ["-std=c++14"], [], "-std=c++14"):
153+
AddBuilds("cxx14", allfeatures + allconfigs + cxxflags + ["-std=c++14"])
154+
155+
# 32-bit build
156+
if conf.CheckFlags(["-m32"], ["-m32"]):
113157
AddBuilds("32", allfeatures + allconfigs + cflags + ["-m32"], ["-m32"])
114-
AddBuilds("cxx11-32", allfeatures + allconfigs + ["-xc++", "-std=c++11"] + ["-m32"], ["-m32", "-lstdc++"])
158+
AddBuilds("cxx32", allfeatures + allconfigs + cxxflags + ["-std=c++98", "-m32"], ["-m32"])

projects/vs/mpack.vcxproj

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@
8181
<ClCompile Include="..\..\src\mpack\mpack-platform.c" />
8282
<ClCompile Include="..\..\src\mpack\mpack-reader.c" />
8383
<ClCompile Include="..\..\src\mpack\mpack-writer.c" />
84-
<ClCompile Include="..\..\test\main.c" />
84+
<ClCompile Include="..\..\test\test-reader.c" />
85+
<ClCompile Include="..\..\test\test.c" />
8586
<ClCompile Include="..\..\test\test-buffer.c" />
8687
<ClCompile Include="..\..\test\test-file.c" />
87-
<ClCompile Include="..\..\test\test-malloc.c" />
88+
<ClCompile Include="..\..\test\test-system.c" />
8889
<ClCompile Include="..\..\test\test-node.c" />
8990
<ClCompile Include="..\..\test\test-expect.c" />
90-
<ClCompile Include="..\..\test\test-tag.c" />
91+
<ClCompile Include="..\..\test\test-common.c" />
9192
<ClCompile Include="..\..\test\test-write.c" />
9293
</ItemGroup>
9394
<ItemGroup>
@@ -101,14 +102,15 @@
101102
<ClInclude Include="..\..\test\mpack-config.h" />
102103
<ClInclude Include="..\..\test\test-buffer.h" />
103104
<ClInclude Include="..\..\test\test-file.h" />
104-
<ClInclude Include="..\..\test\test-malloc.h" />
105+
<ClInclude Include="..\..\test\test-reader.h" />
106+
<ClInclude Include="..\..\test\test-system.h" />
105107
<ClInclude Include="..\..\test\test-node.h" />
106108
<ClInclude Include="..\..\test\test-expect.h" />
107-
<ClInclude Include="..\..\test\test-tag.h" />
109+
<ClInclude Include="..\..\test\test-common.h" />
108110
<ClInclude Include="..\..\test\test-write.h" />
109111
<ClInclude Include="..\..\test\test.h" />
110112
</ItemGroup>
111113
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
112114
<ImportGroup Label="ExtensionTargets">
113115
</ImportGroup>
114-
</Project>
116+
</Project>

projects/vs/mpack.vcxproj.filters

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<ClCompile Include="..\..\src\mpack\mpack-writer.c">
3030
<Filter>Source Files</Filter>
3131
</ClCompile>
32-
<ClCompile Include="..\..\test\main.c">
32+
<ClCompile Include="..\..\test\test.c">
3333
<Filter>Source Files</Filter>
3434
</ClCompile>
3535
<ClCompile Include="..\..\test\test-buffer.c">
@@ -38,7 +38,7 @@
3838
<ClCompile Include="..\..\test\test-file.c">
3939
<Filter>Source Files</Filter>
4040
</ClCompile>
41-
<ClCompile Include="..\..\test\test-malloc.c">
41+
<ClCompile Include="..\..\test\test-system.c">
4242
<Filter>Source Files</Filter>
4343
</ClCompile>
4444
<ClCompile Include="..\..\test\test-node.c">
@@ -47,12 +47,15 @@
4747
<ClCompile Include="..\..\test\test-expect.c">
4848
<Filter>Source Files</Filter>
4949
</ClCompile>
50-
<ClCompile Include="..\..\test\test-tag.c">
50+
<ClCompile Include="..\..\test\test-common.c">
5151
<Filter>Source Files</Filter>
5252
</ClCompile>
5353
<ClCompile Include="..\..\test\test-write.c">
5454
<Filter>Source Files</Filter>
5555
</ClCompile>
56+
<ClCompile Include="..\..\test\test-reader.c">
57+
<Filter>Source Files</Filter>
58+
</ClCompile>
5659
</ItemGroup>
5760
<ItemGroup>
5861
<ClInclude Include="..\..\src\mpack\mpack-common.h">
@@ -85,7 +88,7 @@
8588
<ClInclude Include="..\..\test\test-file.h">
8689
<Filter>Header Files</Filter>
8790
</ClInclude>
88-
<ClInclude Include="..\..\test\test-malloc.h">
91+
<ClInclude Include="..\..\test\test-system.h">
8992
<Filter>Header Files</Filter>
9093
</ClInclude>
9194
<ClInclude Include="..\..\test\test-node.h">
@@ -94,7 +97,7 @@
9497
<ClInclude Include="..\..\test\test-expect.h">
9598
<Filter>Header Files</Filter>
9699
</ClInclude>
97-
<ClInclude Include="..\..\test\test-tag.h">
100+
<ClInclude Include="..\..\test\test-common.h">
98101
<Filter>Header Files</Filter>
99102
</ClInclude>
100103
<ClInclude Include="..\..\test\test-write.h">
@@ -103,5 +106,8 @@
103106
<ClInclude Include="..\..\test\test.h">
104107
<Filter>Header Files</Filter>
105108
</ClInclude>
109+
<ClInclude Include="..\..\test\test-reader.h">
110+
<Filter>Header Files</Filter>
111+
</ClInclude>
106112
</ItemGroup>
107-
</Project>
113+
</Project>

0 commit comments

Comments
 (0)