Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ludocode committed Sep 27, 2015
2 parents 7de7650 + 4007cd8 commit 062983a
Show file tree
Hide file tree
Showing 27 changed files with 836 additions and 491 deletions.
3 changes: 2 additions & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ GENERATE_LATEX = no
STRIP_FROM_PATH = . ./src

PREDEFINED = \
static= \
inline= \
MPACK_INLINE= \
MPACK_ALWAYS_INLINE= \
\
MPACK_READER=1 \
MPACK_WRITER=1 \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Conceptually, MessagePack stores data similarly to JSON: they are both composed

- Binary data is not supported by JSON at all. Small binary blobs such as icons and thumbnails need to be Base64 encoded or passed out-of-band.

The above issues greatly increase the complexity of the decoder. Full-featured JSON decoders are quite large, and minimal decoders tend to leave out such features as string unescaping and float parsing, instead leaving these up to the user or platform. This can lead to hard-to-find and/or platform-specific bugs. This also significantly decreases performance, making JSON unattractive for use in applications such as mobile games.
The above issues greatly increase the complexity of the decoder. Full-featured JSON decoders are quite large, and minimal decoders tend to leave out such features as string unescaping and float parsing, instead leaving these up to the user or platform. This can lead to hard-to-find platform-specific and locale-specific bugs. This also significantly decreases performance, making JSON unattractive for use in applications such as mobile games.

While the space inefficiencies of JSON can be partially mitigated through minification and compression, the performance inefficiencies cannot. More importantly, if you are minifying and compressing the data, then why use a human-readable format in the first place?

Expand Down
7 changes: 4 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ for x in os.environ.keys():

env.Append(CPPFLAGS = [
"-Wall", "-Wextra", "-Werror",
"-Wconversion", "-Wno-sign-conversion",
"-Wconversion", "-Wno-sign-conversion", "-Wundef",
"-Isrc", "-Itest",
"-DMPACK_SCONS=1",
"-g",
Expand All @@ -36,14 +36,13 @@ allfeatures = [
]
noioconfigs = [
"-DMPACK_STDLIB=1",
"-DMPACK_SETJMP=1",
"-DMPACK_MALLOC=test_malloc",
"-DMPACK_FREE=test_free",
]
allconfigs = noioconfigs + ["-DMPACK_STDIO=1"]

debugflags = ["-DDEBUG", "-O0"]
releaseflags = ["-Os"]
releaseflags = ["-Os"] # If you change this, also change the MPACK_OPTIMIZE_FOR_SIZE below to test the opposite
cflags = ["-std=c99", "-Wc++-compat"]


Expand Down Expand Up @@ -74,6 +73,8 @@ AddBuild("debug", allfeatures + allconfigs + debugflags + cflags, [])

if ARGUMENTS.get('all'):
AddBuild("release", allfeatures + allconfigs + releaseflags + cflags, [])
AddBuild("release-speed", ["-DMPACK_OPTIMIZE_FOR_SIZE=0"] +
allfeatures + allconfigs + releaseflags + cflags, [])

# feature subsets with default configuration
AddBuilds("empty", allconfigs + cflags, [])
Expand Down
70 changes: 55 additions & 15 deletions src/mpack-config.h.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
/**
* This is a sample MPack configuration file. Copy it to mpack-config.h somewhere
* in your project's include tree and, optionally, edit it to suit your setup.
*
* In most cases you can leave this file with the default config.
*
* You can also override the default configuration by pre-defining options to 0 or 1.
*/

#ifndef MPACK_CONFIG_H
Expand All @@ -14,16 +17,24 @@
*/

/** Enables compilation of the base Tag Reader. */
#ifndef MPACK_READER
#define MPACK_READER 1
#endif

/** Enables compilation of the static Expect API. */
#ifndef MPACK_EXPECT
#define MPACK_EXPECT 1
#endif

/** Enables compilation of the dynamic Node API. */
#ifndef MPACK_NODE
#define MPACK_NODE 1
#endif

/** Enables compilation of the Writer. */
#ifndef MPACK_WRITER
#define MPACK_WRITER 1
#endif


/*
Expand All @@ -34,13 +45,17 @@
* Enables the use of C stdlib. This allows the library to use malloc
* for debugging and in allocation helpers.
*/
#ifndef MPACK_STDLIB
#define MPACK_STDLIB 1
#endif

/**
* Enables the use of C stdio. This adds helpers for easily
* reading/writing C files and makes debugging easier.
*/
#ifndef MPACK_STDIO
#define MPACK_STDIO 1
#endif

/**
* \def MPACK_MALLOC
Expand Down Expand Up @@ -80,16 +95,6 @@
#define MPACK_FREE free
#endif

/**
* Enables the setjmp()/longjmp() error handling option. MPACK_MALLOC is required.
*
* Note that you don't have to use it; this just enables the option. It can be
* disabled to avoid the dependency on setjmp.h .
*/
#if defined(MPACK_MALLOC)
#define MPACK_SETJMP 1
#endif


/*
* Debugging options
Expand All @@ -107,10 +112,8 @@
* files. Your entire project must be compiled with the same value of
* MPACK_DEBUG. (This is why NDEBUG is not used.)
*/
#if defined(DEBUG) || defined(_DEBUG)
#if !defined(MPACK_DEBUG) && (defined(DEBUG) || defined(_DEBUG))
#define MPACK_DEBUG 1
#else
#define MPACK_DEBUG 0
#endif

/**
Expand All @@ -122,7 +125,9 @@
* Asserts are only used when MPACK_DEBUG is enabled, and can be triggered
* by bugs in mpack or bugs due to incorrect usage of mpack.
*/
#ifndef MPACK_CUSTOM_ASSERT
#define MPACK_CUSTOM_ASSERT 0
#endif

/**
* \def MPACK_READ_TRACKING
Expand All @@ -133,7 +138,10 @@
* This is enabled by default in debug builds (provided a malloc() is
* available.)
*/
#if MPACK_DEBUG && MPACK_READER && defined(MPACK_MALLOC)
#if !defined(MPACK_READ_TRACKING) && \
defined(MPACK_DEBUG) && MPACK_DEBUG && \
defined(MPACK_READER) && MPACK_READER && \
defined(MPACK_MALLOC)
#define MPACK_READ_TRACKING 1
#endif

Expand All @@ -151,7 +159,10 @@
* This is enabled by default in debug builds (provided a malloc() is
* available.)
*/
#if MPACK_DEBUG && MPACK_WRITER && defined(MPACK_MALLOC)
#if !defined(MPACK_WRITE_TRACKING) && \
defined(MPACK_DEBUG) && MPACK_DEBUG && \
defined(MPACK_WRITER) && MPACK_WRITER && \
defined(MPACK_MALLOC)
#define MPACK_WRITE_TRACKING 1
#endif

Expand All @@ -160,16 +171,39 @@
* Miscellaneous
*/

/**
* 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.
*
* 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__
#define MPACK_OPTIMIZE_FOR_SIZE 1
#else
#define MPACK_OPTIMIZE_FOR_SIZE 0
#endif
#endif

/**
* Stack space 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.)
*/
#ifndef MPACK_BUFFER_SIZE
#define MPACK_BUFFER_SIZE 65536
#endif

/**
* Number of nodes in each allocated node page.
Expand All @@ -181,20 +215,26 @@
* 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))
#endif

/**
* The initial depth for the node parser. When MPACK_MALLOC is available,
* the node parser has no practical depth limit, and it is not recursive
* so there is no risk of overflowing the call stack.
*/
#ifndef MPACK_NODE_INITIAL_DEPTH
#define MPACK_NODE_INITIAL_DEPTH 8
#endif

/**
* The maximum depth for the node parser if MPACK_MALLOC is not available.
* The parsing stack is placed on the call stack.
*/
#ifndef MPACK_NODE_MAX_DEPTH_WITHOUT_MALLOC
#define MPACK_NODE_MAX_DEPTH_WITHOUT_MALLOC 32
#endif


#endif
Expand Down
33 changes: 31 additions & 2 deletions src/mpack/mpack-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ int mpack_tag_cmp(mpack_tag_t left, mpack_tag_t right) {
#define MPACK_TRACKING_INITIAL_CAPACITY 8
#endif

MPACK_INTERNAL_STATIC mpack_error_t mpack_track_init(mpack_track_t* track) {
mpack_error_t mpack_track_init(mpack_track_t* track) {
track->count = 0;
track->capacity = MPACK_TRACKING_INITIAL_CAPACITY;
track->elements = (mpack_track_element_t*)MPACK_MALLOC(sizeof(mpack_track_element_t) * track->capacity);
Expand All @@ -171,7 +171,7 @@ MPACK_INTERNAL_STATIC mpack_error_t mpack_track_init(mpack_track_t* track) {
return mpack_ok;
}

MPACK_INTERNAL_STATIC mpack_error_t mpack_track_grow(mpack_track_t* track) {
mpack_error_t mpack_track_grow(mpack_track_t* track) {
mpack_assert(track->elements, "null track elements!");
mpack_assert(track->count == track->capacity, "incorrect growing?");

Expand All @@ -189,3 +189,32 @@ MPACK_INTERNAL_STATIC mpack_error_t mpack_track_grow(mpack_track_t* track) {

#endif



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

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

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. */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8,

/* The second part is a transition table that maps a combination */
/* of a state of the automaton and a character class to a state. */
0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
12,36,12,12,12,12,12,12,12,12,12,12,
};

Loading

0 comments on commit 062983a

Please sign in to comment.