Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ludocode committed Nov 29, 2015
2 parents 1aa7097 + 71f2089 commit af55d10
Show file tree
Hide file tree
Showing 38 changed files with 2,240 additions and 1,291 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/config.log
mpack-test-file
/mpack-test-dir/
/analysis/

# folders
/tags
Expand Down
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
language: c

before_install:
- pip install --user cpp-coveralls

addons:
apt:
packages:
Expand Down
4 changes: 2 additions & 2 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ PROJECT_NUMBER = develop

INPUT = \
README.md \
src/mpack/mpack-platform.h \
src/mpack/mpack-common.h \
src/mpack/mpack-reader.h \
src/mpack/mpack-writer.h \
Expand All @@ -22,8 +21,9 @@ STRIP_FROM_PATH = . ./src

PREDEFINED = \
inline= \
MPACK_INLINE= \
MPACK_ALWAYS_INLINE= \
MPACK_INLINE= \
MPACK_INLINE_SPEED= \
\
MPACK_READER=1 \
MPACK_WRITER=1 \
Expand Down
2 changes: 1 addition & 1 deletion SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ prog = env.Program("mpack-test", srcs,
if platform.machine() in ["i386", "x86_64"]:
valgrind = "valgrind --leak-check=full --error-exitcode=1 "
# travis version of valgrind is too old, doesn't support leak kinds
if "TRAVIS" not in env:
if "TRAVIS" not in env["ENV"]:
valgrind = valgrind + "--show-leak-kinds=all --errors-for-leak-kinds=all "
valgrind = valgrind + "--suppressions=tools/valgrind-suppressions "
else:
Expand Down
15 changes: 8 additions & 7 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ env = Environment()
conf = Configure(env, custom_tests = {'CheckFlags': CheckFlags})

for x in os.environ.keys():
if x in ["CC", "CXX", "PATH", "TRAVIS", "TERM"] or x.startswith("CLANG_") or x.startswith("CCC_"):
if x in ["CC", "CXX"]:
env[x] = os.environ[x]
if x in ["PATH", "TRAVIS", "TERM"] or x.startswith("CLANG_") or x.startswith("CCC_"):
env["ENV"][x] = os.environ[x]

env.Append(CPPFLAGS = [
"-Wall", "-Wextra", "-Werror",
"-Wconversion", "-Wno-sign-conversion", "-Wundef",
"-Wconversion", "-Wno-sign-conversion", "-Wundef", "-Wshadow",
"-Isrc", "-Itest",
"-DMPACK_SCONS=1",
"-g",
Expand All @@ -34,7 +36,7 @@ env.Append(LINKFLAGS = [
])
# Additional warning flags are passed in SConscript based on the language (C/C++)

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

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

# The default build, everything in debug. This is the build used
# for code coverage measurement and static analysis.

AddBuild("debug", allfeatures + allconfigs + debugflags + cflags + gcovflags, gcovflags)


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


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

Expand Down
34 changes: 21 additions & 13 deletions src/mpack-config.h.sample
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,14 @@
*/

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

/**
* Stack space to use when initializing a reader or writer with a
* stack-allocated buffer.
* Stack space in bytes to use when initializing a reader or writer
* with a stack-allocated buffer.
*/
#ifndef MPACK_STACK_SIZE
#define MPACK_STACK_SIZE 4096
#endif

/**
* Buffer size to use for allocated buffers (such as for a file writer.)
*
* Starting with a single page and growing as needed seems to
* provide the best performance with minimal memory waste.
* Increasing this does not improve performance even when writing
* huge messages.
*/
#ifndef MPACK_BUFFER_SIZE
#define MPACK_BUFFER_SIZE 65536
#define MPACK_BUFFER_SIZE 4096
#endif

/**
* Number of nodes in each allocated node page.
* Size of an allocated node page in bytes.
*
* The children for a given compound element must be contiguous, so
* larger pages than this may be allocated as needed. (Safety checks
* exist to prevent malicious data from causing too large allocations.)
*
* Nodes are 16 bytes when compiled for a 32-bit architecture and
* 24 bytes when compiled for a 64-bit architecture.
* Nodes are 12 bytes when compiled for a 32-bit architecture and
* 16 bytes when compiled for a 64-bit architecture.
*
* Using as many nodes fit in one memory page seems to provide the
* best performance, and has very little waste when parsing small
* messages.
*/
#ifndef MPACK_NODE_PAGE_SIZE
#define MPACK_NODE_PAGE_SIZE (4096 / sizeof(mpack_node_t))
#define MPACK_NODE_PAGE_SIZE 4096
#endif

/**
Expand Down
31 changes: 26 additions & 5 deletions src/mpack/mpack-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,14 @@ mpack_error_t mpack_track_destroy(mpack_track_t* track, bool cancel) {


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

/* Copyright (c) 2008-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de> */
/* See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details. */

#define MPACK_UTF8_ACCEPT 0
#define MPACK_UTF8_REJECT 12

static const uint8_t mpack_utf8d[] = {
/* The first part of the table maps bytes to character classes that */
/* to reduce the size of the transition table and create bitmasks. */
Expand All @@ -337,7 +340,25 @@ static const uint8_t mpack_utf8d[] = {
12,36,12,12,12,12,12,12,12,12,12,12,
};

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

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



bool mpack_utf8_check(char* str, size_t bytes) {
bool mpack_utf8_check(const char* str, size_t bytes) {
uint32_t state = MPACK_UTF8_ACCEPT;
uint32_t codepoint;
for (size_t i = 0; i < bytes; ++i)
Expand All @@ -361,7 +382,7 @@ bool mpack_utf8_check(char* str, size_t bytes) {
return state == MPACK_UTF8_ACCEPT;
}

bool mpack_utf8_check_no_null(char* str, size_t bytes) {
bool mpack_utf8_check_no_null(const char* str, size_t bytes) {
uint32_t state = MPACK_UTF8_ACCEPT;
uint32_t codepoint;
for (size_t i = 0; i < bytes; ++i)
Expand All @@ -370,7 +391,7 @@ bool mpack_utf8_check_no_null(char* str, size_t bytes) {
return state == MPACK_UTF8_ACCEPT;
}

bool mpack_str_check_no_null(char* str, size_t bytes) {
bool mpack_str_check_no_null(const char* str, size_t bytes) {
for (size_t i = 0; i < bytes; ++i)
if (str[i] == '\0')
return false;
Expand Down
Loading

0 comments on commit af55d10

Please sign in to comment.