Skip to content

Commit af55d10

Browse files
committed
Merge branch 'develop'
2 parents 1aa7097 + 71f2089 commit af55d10

38 files changed

+2240
-1291
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/config.log
99
mpack-test-file
1010
/mpack-test-dir/
11+
/analysis/
1112

1213
# folders
1314
/tags

.travis.yml

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

3-
before_install:
4-
- pip install --user cpp-coveralls
5-
63
addons:
74
apt:
85
packages:

Doxyfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ PROJECT_NUMBER = develop
77

88
INPUT = \
99
README.md \
10-
src/mpack/mpack-platform.h \
1110
src/mpack/mpack-common.h \
1211
src/mpack/mpack-reader.h \
1312
src/mpack/mpack-writer.h \
@@ -22,8 +21,9 @@ STRIP_FROM_PATH = . ./src
2221

2322
PREDEFINED = \
2423
inline= \
25-
MPACK_INLINE= \
2624
MPACK_ALWAYS_INLINE= \
25+
MPACK_INLINE= \
26+
MPACK_INLINE_SPEED= \
2727
\
2828
MPACK_READER=1 \
2929
MPACK_WRITER=1 \

SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ prog = env.Program("mpack-test", srcs,
2424
if platform.machine() in ["i386", "x86_64"]:
2525
valgrind = "valgrind --leak-check=full --error-exitcode=1 "
2626
# travis version of valgrind is too old, doesn't support leak kinds
27-
if "TRAVIS" not in env:
27+
if "TRAVIS" not in env["ENV"]:
2828
valgrind = valgrind + "--show-leak-kinds=all --errors-for-leak-kinds=all "
2929
valgrind = valgrind + "--suppressions=tools/valgrind-suppressions "
3030
else:

SConstruct

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ env = Environment()
1919
conf = Configure(env, custom_tests = {'CheckFlags': CheckFlags})
2020

2121
for x in os.environ.keys():
22-
if x in ["CC", "CXX", "PATH", "TRAVIS", "TERM"] or x.startswith("CLANG_") or x.startswith("CCC_"):
22+
if x in ["CC", "CXX"]:
2323
env[x] = os.environ[x]
24+
if x in ["PATH", "TRAVIS", "TERM"] or x.startswith("CLANG_") or x.startswith("CCC_"):
25+
env["ENV"][x] = os.environ[x]
2426

2527
env.Append(CPPFLAGS = [
2628
"-Wall", "-Wextra", "-Werror",
27-
"-Wconversion", "-Wno-sign-conversion", "-Wundef",
29+
"-Wconversion", "-Wno-sign-conversion", "-Wundef", "-Wshadow",
2830
"-Isrc", "-Itest",
2931
"-DMPACK_SCONS=1",
3032
"-g",
@@ -34,7 +36,7 @@ env.Append(LINKFLAGS = [
3436
])
3537
# Additional warning flags are passed in SConscript based on the language (C/C++)
3638

37-
if 'TRAVIS' not in env:
39+
if 'TRAVIS' not in env["ENV"]:
3840
# Travis-CI currently uses Clang 3.4 which does not support this option,
3941
# and it also appears to be incompatible with other GCC options on Travis-CI
4042
env.Append(CPPFLAGS = ["-Wno-float-conversion"])
@@ -60,7 +62,7 @@ if hasOg:
6062
debugflags = ["-DDEBUG", "-Og"]
6163
else:
6264
debugflags = ["-DDEBUG", "-O0"]
63-
releaseflags = ["-Os"]
65+
releaseflags = ["-O2"]
6466
cflags = ["-std=c99"]
6567

6668
gcovflags = []
@@ -95,7 +97,6 @@ def AddBuilds(variant_dir, cppflags, linkflags = []):
9597

9698
# The default build, everything in debug. This is the build used
9799
# for code coverage measurement and static analysis.
98-
99100
AddBuild("debug", allfeatures + allconfigs + debugflags + cflags + gcovflags, gcovflags)
100101

101102

@@ -105,6 +106,8 @@ if ARGUMENTS.get('more') or ARGUMENTS.get('all'):
105106
AddBuild("release", allfeatures + allconfigs + releaseflags + cflags)
106107
AddBuilds("embed", allfeatures + cflags)
107108
AddBuilds("noio", allfeatures + noioconfigs + cflags)
109+
AddBuild("debug-size", ["-DMPACK_OPTIMIZE_FOR_SIZE=1"] + debugflags + allfeatures + allconfigs + cflags)
110+
AddBuild("release-size", ["-Os"] + allfeatures + allconfigs + cflags)
108111

109112

110113
# Run "scons all=1" to run all builds. This is what the CI runs.
@@ -113,8 +116,6 @@ if ARGUMENTS.get('all'):
113116
# various release builds
114117
AddBuild("release-unopt", allfeatures + allconfigs + cflags + ["-O0"])
115118
AddBuild("release-fastmath", allfeatures + allconfigs + releaseflags + cflags + ["-ffast-math"])
116-
AddBuild("release-speed", ["-DMPACK_OPTIMIZE_FOR_SIZE=0"] +
117-
allfeatures + allconfigs + releaseflags + cflags)
118119
if conf.CheckFlags(ltoflags, ltoflags, "-flto"):
119120
AddBuild("release-lto", allfeatures + allconfigs + ltoflags + cflags, ltoflags)
120121

src/mpack-config.h.sample

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,14 @@
180180
*/
181181

182182
/**
183-
* Whether to optimize for size or speed. Optimizing for size causes
184-
* very few functions to be declared inline, and can save a couple
185-
* kilobytes of space in the resulting executable.
183+
* Whether to optimize for size or speed.
184+
*
185+
* Optimizing for size simplifies some parsing and encoding algorithms
186+
* at the expense of speed, and saves a few kilobytes of space in the
187+
* resulting executable.
186188
*
187189
* This automatically detects -Os with GCC/Clang. Unfortunately there
188190
* doesn't seem to be a macro defined for /Os under MSVC.
189-
*
190-
* This feature is currently experimental and may be removed in a
191-
* future release.
192191
*/
193192
#ifndef MPACK_OPTIMIZE_FOR_SIZE
194193
#ifdef __OPTIMIZE_SIZE__
@@ -199,32 +198,41 @@
199198
#endif
200199

201200
/**
202-
* Stack space to use when initializing a reader or writer with a
203-
* stack-allocated buffer.
201+
* Stack space in bytes to use when initializing a reader or writer
202+
* with a stack-allocated buffer.
204203
*/
205204
#ifndef MPACK_STACK_SIZE
206205
#define MPACK_STACK_SIZE 4096
207206
#endif
208207

209208
/**
210209
* Buffer size to use for allocated buffers (such as for a file writer.)
210+
*
211+
* Starting with a single page and growing as needed seems to
212+
* provide the best performance with minimal memory waste.
213+
* Increasing this does not improve performance even when writing
214+
* huge messages.
211215
*/
212216
#ifndef MPACK_BUFFER_SIZE
213-
#define MPACK_BUFFER_SIZE 65536
217+
#define MPACK_BUFFER_SIZE 4096
214218
#endif
215219

216220
/**
217-
* Number of nodes in each allocated node page.
221+
* Size of an allocated node page in bytes.
222+
*
223+
* The children for a given compound element must be contiguous, so
224+
* larger pages than this may be allocated as needed. (Safety checks
225+
* exist to prevent malicious data from causing too large allocations.)
218226
*
219-
* Nodes are 16 bytes when compiled for a 32-bit architecture and
220-
* 24 bytes when compiled for a 64-bit architecture.
227+
* Nodes are 12 bytes when compiled for a 32-bit architecture and
228+
* 16 bytes when compiled for a 64-bit architecture.
221229
*
222230
* Using as many nodes fit in one memory page seems to provide the
223231
* best performance, and has very little waste when parsing small
224232
* messages.
225233
*/
226234
#ifndef MPACK_NODE_PAGE_SIZE
227-
#define MPACK_NODE_PAGE_SIZE (4096 / sizeof(mpack_node_t))
235+
#define MPACK_NODE_PAGE_SIZE 4096
228236
#endif
229237

230238
/**

src/mpack/mpack-common.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,14 @@ mpack_error_t mpack_track_destroy(mpack_track_t* track, bool cancel) {
311311

312312

313313
/* The below code is from Bjoern Hoehrmann's Flexible and Economical */
314-
/* UTF-8 decoder, modified to support MPack inlining and add the mpack prefix. */
314+
/* UTF-8 decoder, modified to add the mpack prefix. */
315315

316316
/* Copyright (c) 2008-2010 Bjoern Hoehrmann <[email protected]> */
317317
/* See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details. */
318318

319+
#define MPACK_UTF8_ACCEPT 0
320+
#define MPACK_UTF8_REJECT 12
321+
319322
static const uint8_t mpack_utf8d[] = {
320323
/* The first part of the table maps bytes to character classes that */
321324
/* to reduce the size of the transition table and create bitmasks. */
@@ -337,7 +340,25 @@ static const uint8_t mpack_utf8d[] = {
337340
12,36,12,12,12,12,12,12,12,12,12,12,
338341
};
339342

340-
uint32_t mpack_utf8_decode(uint32_t* state, uint32_t* codep, uint8_t byte) {
343+
/**
344+
* Parses one byte from a UTF-8 stream.
345+
*
346+
* Returns and sets state to:
347+
* - MPACK_UTF8_ACCEPT if the byte completes a valid unicode code point, placing it in codep
348+
* - MPACK_UTF8_REJECT if the byte is invalid UTF-8
349+
* - something else if more bytes are needed to form a valid character
350+
*
351+
* If more bytes are needed, this should be called again with the next byte
352+
* in the string. state and codep should not be modified, since they will
353+
* contain the partially read code point.
354+
*
355+
* The initial state should be set to MPACK_UTF8_ACCEPT before parsing a string.
356+
*
357+
* This does not accept any UTF-8 variant such as Modified UTF-8, CESU-8 or
358+
* WTF-8. Overlong sequences and UTF-16 surrogates will be rejected. Only
359+
* pure UTF-8 is accepted.
360+
*/
361+
static inline uint32_t mpack_utf8_decode(uint32_t* state, uint32_t* codep, uint8_t byte) {
341362
uint32_t type = mpack_utf8d[byte];
342363

343364
*codep = (*state != MPACK_UTF8_ACCEPT) ?
@@ -352,7 +373,7 @@ uint32_t mpack_utf8_decode(uint32_t* state, uint32_t* codep, uint8_t byte) {
352373

353374

354375

355-
bool mpack_utf8_check(char* str, size_t bytes) {
376+
bool mpack_utf8_check(const char* str, size_t bytes) {
356377
uint32_t state = MPACK_UTF8_ACCEPT;
357378
uint32_t codepoint;
358379
for (size_t i = 0; i < bytes; ++i)
@@ -361,7 +382,7 @@ bool mpack_utf8_check(char* str, size_t bytes) {
361382
return state == MPACK_UTF8_ACCEPT;
362383
}
363384

364-
bool mpack_utf8_check_no_null(char* str, size_t bytes) {
385+
bool mpack_utf8_check_no_null(const char* str, size_t bytes) {
365386
uint32_t state = MPACK_UTF8_ACCEPT;
366387
uint32_t codepoint;
367388
for (size_t i = 0; i < bytes; ++i)
@@ -370,7 +391,7 @@ bool mpack_utf8_check_no_null(char* str, size_t bytes) {
370391
return state == MPACK_UTF8_ACCEPT;
371392
}
372393

373-
bool mpack_str_check_no_null(char* str, size_t bytes) {
394+
bool mpack_str_check_no_null(const char* str, size_t bytes) {
374395
for (size_t i = 0; i < bytes; ++i)
375396
if (str[i] == '\0')
376397
return false;

0 commit comments

Comments
 (0)