You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2013/12/24 00:31:21 UTC

[12/12] git commit: updated refs/heads/1843-replace-ejson-with-jiffy to 2e6092e

Replace ejson with jiffy


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/2e6092e4
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/2e6092e4
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/2e6092e4

Branch: refs/heads/1843-replace-ejson-with-jiffy
Commit: 2e6092e4ee0fb3f42da9a6e5b361f0de010486af
Parents: 81b75f5
Author: Robert Newson <rn...@apache.org>
Authored: Mon Dec 23 12:21:14 2013 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Mon Dec 23 13:36:24 2013 +0000

----------------------------------------------------------------------
 rebar.config                                    |      2 +-
 src/couch/include/couch_db.hrl                  |      4 +-
 .../couch_ejson_compare/couch_ejson_compare.c   |    457 -
 src/couch/src/couch_ejson_compare.erl           |    113 -
 src/couch/src/couch_util.erl                    |     12 +
 src/ejson/c_src/decode.c                        |    308 -
 src/ejson/c_src/ejson.c                         |     30 -
 src/ejson/c_src/encode.c                        |    200 -
 src/ejson/c_src/erl_nif_compat.h                |    120 -
 src/ejson/c_src/yajl/yajl.c                     |    159 -
 src/ejson/c_src/yajl/yajl_alloc.c               |     65 -
 src/ejson/c_src/yajl/yajl_alloc.h               |     50 -
 src/ejson/c_src/yajl/yajl_buf.c                 |    119 -
 src/ejson/c_src/yajl/yajl_buf.h                 |     73 -
 src/ejson/c_src/yajl/yajl_bytestack.h           |     85 -
 src/ejson/c_src/yajl/yajl_common.h              |     85 -
 src/ejson/c_src/yajl/yajl_encode.c              |    188 -
 src/ejson/c_src/yajl/yajl_encode.h              |     50 -
 src/ejson/c_src/yajl/yajl_gen.c                 |    322 -
 src/ejson/c_src/yajl/yajl_gen.h                 |    159 -
 src/ejson/c_src/yajl/yajl_lex.c                 |    737 -
 src/ejson/c_src/yajl/yajl_lex.h                 |    133 -
 src/ejson/c_src/yajl/yajl_parse.h               |    193 -
 src/ejson/c_src/yajl/yajl_parser.c              |    470 -
 src/ejson/c_src/yajl/yajl_parser.h              |     95 -
 src/ejson/src/ejson.app.src                     |      9 -
 src/ejson/src/ejson.erl                         |    168 -
 src/ejson/src/mochijson2.erl                    |    849 -
 src/ejson/src/mochinum.erl                      |    354 -
 src/jiffy/.gitignore                            |      7 +
 src/jiffy/LICENSE                               |     90 +
 src/jiffy/Makefile                              |     47 +
 src/jiffy/README.md                             |     58 +
 src/jiffy/c_src/decoder.c                       |    914 +
 src/jiffy/c_src/double-conversion/AUTHORS       |     12 +
 src/jiffy/c_src/double-conversion/COPYING       |     26 +
 src/jiffy/c_src/double-conversion/DOWNLOADED    |      3 +
 src/jiffy/c_src/double-conversion/LICENSE       |     26 +
 src/jiffy/c_src/double-conversion/README        |     11 +
 .../c_src/double-conversion/bignum-dtoa.cc      |    640 +
 src/jiffy/c_src/double-conversion/bignum-dtoa.h |     84 +
 src/jiffy/c_src/double-conversion/bignum.cc     |    764 +
 src/jiffy/c_src/double-conversion/bignum.h      |    145 +
 .../c_src/double-conversion/cached-powers.cc    |    175 +
 .../c_src/double-conversion/cached-powers.h     |     64 +
 src/jiffy/c_src/double-conversion/diy-fp.cc     |     57 +
 src/jiffy/c_src/double-conversion/diy-fp.h      |    118 +
 .../double-conversion/double-conversion.cc      |    889 +
 .../c_src/double-conversion/double-conversion.h |    536 +
 src/jiffy/c_src/double-conversion/fast-dtoa.cc  |    666 +
 src/jiffy/c_src/double-conversion/fast-dtoa.h   |     88 +
 src/jiffy/c_src/double-conversion/fixed-dtoa.cc |    402 +
 src/jiffy/c_src/double-conversion/fixed-dtoa.h  |     56 +
 src/jiffy/c_src/double-conversion/ieee.h        |    398 +
 src/jiffy/c_src/double-conversion/strtod.cc     |    554 +
 src/jiffy/c_src/double-conversion/strtod.h      |     45 +
 src/jiffy/c_src/double-conversion/utils.h       |    326 +
 src/jiffy/c_src/doubles.cc                      |     33 +
 src/jiffy/c_src/encoder.c                       |    709 +
 src/jiffy/c_src/jiffy.c                         |     61 +
 src/jiffy/c_src/jiffy.h                         |     45 +
 src/jiffy/c_src/utf8.c                          |    249 +
 src/jiffy/c_src/util.c                          |     26 +
 src/jiffy/rebar.config                          |     34 +
 src/jiffy/rebar.config.script                   |     33 +
 src/jiffy/src/jiffy.app.src                     |      6 +
 src/jiffy/src/jiffy.erl                         |    107 +
 src/jiffy/src/jiffy_utf8.erl                    |    104 +
 src/jiffy/test/001-yajl-tests.t                 |     30 +
 src/jiffy/test/002-literals.t                   |     21 +
 src/jiffy/test/003-numbers.t                    |    118 +
 src/jiffy/test/004-strings.t                    |    131 +
 src/jiffy/test/005-arrays.t                     |     36 +
 src/jiffy/test/006-maps.t                       |     36 +
 src/jiffy/test/007-compound.t                   |     41 +
 src/jiffy/test/008-halfword.t                   |     15 +
 src/jiffy/test/009-reg-issue-24.t               |   3459 +
 src/jiffy/test/010-short-doubles.t              |     29 +
 src/jiffy/test/cases/array.eterm                |     16 +
 src/jiffy/test/cases/array.json                 |      6 +
 src/jiffy/test/cases/array_close.eterm          |      1 +
 src/jiffy/test/cases/array_close.json           |      1 +
 src/jiffy/test/cases/array_open.eterm           |      1 +
 src/jiffy/test/cases/array_open.json            |      1 +
 src/jiffy/test/cases/bogus_char.eterm           |      1 +
 src/jiffy/test/cases/bogus_char.json            |      4 +
 .../cases/codepoints_from_unicode_org.eterm     |      1 +
 .../test/cases/codepoints_from_unicode_org.json |      1 +
 src/jiffy/test/cases/deep_arrays.eterm          |      1 +
 src/jiffy/test/cases/deep_arrays.json           |      1 +
 .../test/cases/difficult_json_c_test_case.eterm |     19 +
 .../test/cases/difficult_json_c_test_case.json  |      1 +
 src/jiffy/test/cases/doubles.eterm              |      1 +
 src/jiffy/test/cases/doubles.json               |      1 +
 src/jiffy/test/cases/empty_array.eterm          |      1 +
 src/jiffy/test/cases/empty_array.json           |      1 +
 src/jiffy/test/cases/empty_string.eterm         |      1 +
 src/jiffy/test/cases/empty_string.json          |      1 +
 src/jiffy/test/cases/escaped_bulgarian.eterm    |      6 +
 src/jiffy/test/cases/escaped_bulgarian.json     |      4 +
 src/jiffy/test/cases/escaped_foobar.eterm       |      1 +
 src/jiffy/test/cases/escaped_foobar.json        |      1 +
 src/jiffy/test/cases/false.eterm                |      1 +
 src/jiffy/test/cases/false.json                 |      1 +
 src/jiffy/test/cases/false_then_garbage.eterm   |      1 +
 src/jiffy/test/cases/false_then_garbage.json    |      1 +
 src/jiffy/test/cases/four_byte_utf8.eterm       |      1 +
 src/jiffy/test/cases/four_byte_utf8.json        |      2 +
 src/jiffy/test/cases/integers.eterm             |     13 +
 src/jiffy/test/cases/integers.json              |      3 +
 src/jiffy/test/cases/invalid_utf8.eterm         |      1 +
 src/jiffy/test/cases/invalid_utf8.json          |      1 +
 .../test/cases/isolated_surrogate_marker.eterm  |      1 +
 .../test/cases/isolated_surrogate_marker.json   |      1 +
 .../test/cases/leading_zero_in_number.eterm     |      1 +
 .../test/cases/leading_zero_in_number.json      |      1 +
 src/jiffy/test/cases/lonely_minus_sign.eterm    |      1 +
 src/jiffy/test/cases/lonely_minus_sign.json     |      7 +
 src/jiffy/test/cases/lonely_number.eterm        |      1 +
 src/jiffy/test/cases/lonely_number.json         |      1 +
 src/jiffy/test/cases/map_close.eterm            |      1 +
 src/jiffy/test/cases/map_close.json             |      1 +
 src/jiffy/test/cases/map_open.eterm             |      1 +
 src/jiffy/test/cases/map_open.json              |      1 +
 .../missing_integer_after_decimal_point.eterm   |      1 +
 .../missing_integer_after_decimal_point.json    |      1 +
 .../cases/missing_integer_after_exponent.eterm  |      1 +
 .../cases/missing_integer_after_exponent.json   |      1 +
 .../test/cases/non_utf8_char_in_string.eterm    |      1 +
 .../test/cases/non_utf8_char_in_string.json     |      1 +
 src/jiffy/test/cases/null.eterm                 |      1 +
 src/jiffy/test/cases/null.json                  |      1 +
 src/jiffy/test/cases/null_then_garbage.eterm    |      1 +
 src/jiffy/test/cases/null_then_garbage.json     |      1 +
 src/jiffy/test/cases/nulls_and_bools.eterm      |      5 +
 src/jiffy/test/cases/nulls_and_bools.json       |      5 +
 src/jiffy/test/cases/short-doubles.txt          | 100000 ++++++++++++++++
 src/jiffy/test/cases/simple.eterm               |      5 +
 src/jiffy/test/cases/simple.json                |      5 +
 .../test/cases/string_invalid_escape.eterm      |      1 +
 src/jiffy/test/cases/string_invalid_escape.json |      1 +
 .../test/cases/string_invalid_hex_char.eterm    |      1 +
 .../test/cases/string_invalid_hex_char.json     |      1 +
 src/jiffy/test/cases/string_with_escapes.eterm  |      5 +
 src/jiffy/test/cases/string_with_escapes.json   |      3 +
 .../cases/string_with_invalid_newline.eterm     |      1 +
 .../test/cases/string_with_invalid_newline.json |      2 +
 src/jiffy/test/cases/three_byte_utf8.eterm      |      4 +
 src/jiffy/test/cases/three_byte_utf8.json       |      1 +
 src/jiffy/test/cases/true.eterm                 |      1 +
 src/jiffy/test/cases/true.json                  |      1 +
 src/jiffy/test/cases/true_then_garbage.eterm    |      1 +
 src/jiffy/test/cases/true_then_garbage.json     |      1 +
 src/jiffy/test/cases/unescaped_bulgarian.eterm  |      5 +
 src/jiffy/test/cases/unescaped_bulgarian.json   |      1 +
 src/jiffy/test/etap.erl                         |    612 +
 src/jiffy/test/jiffy_tests.erl                  |    135 +
 src/jiffy/test/util.erl                         |     44 +
 158 files changed, 113506 insertions(+), 5594 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/rebar.config
----------------------------------------------------------------------
diff --git a/rebar.config b/rebar.config
index 1ae51fd..ad484a2 100644
--- a/rebar.config
+++ b/rebar.config
@@ -21,7 +21,7 @@
     "src/chttpd",
     "src/couch_replicator",
     "src/ddoc_cache",
-    "src/ejson",
+    "src/jiffy",
     "src/ets_lru",
     "src/fabric",
     "src/mochiweb",

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/couch/include/couch_db.hrl
----------------------------------------------------------------------
diff --git a/src/couch/include/couch_db.hrl b/src/couch/include/couch_db.hrl
index ffecae0..2c015df 100644
--- a/src/couch/include/couch_db.hrl
+++ b/src/couch/include/couch_db.hrl
@@ -18,8 +18,8 @@
 -define(MIN_STR, <<"">>).
 -define(MAX_STR, <<255>>). % illegal utf string
 
--define(JSON_ENCODE(V), ejson:encode(V)).
--define(JSON_DECODE(V), ejson:decode(V)).
+-define(JSON_ENCODE(V), couch_util:json_encode(V)).
+-define(JSON_DECODE(V), couch_util:json_decode(V)).
 
 -define(b2l(V), binary_to_list(V)).
 -define(l2b(V), list_to_binary(V)).

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/couch/priv/couch_ejson_compare/couch_ejson_compare.c
----------------------------------------------------------------------
diff --git a/src/couch/priv/couch_ejson_compare/couch_ejson_compare.c b/src/couch/priv/couch_ejson_compare/couch_ejson_compare.c
deleted file mode 100644
index df68c2a..0000000
--- a/src/couch/priv/couch_ejson_compare/couch_ejson_compare.c
+++ /dev/null
@@ -1,457 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-#include <stdio.h>
-#include <assert.h>
-#include "erl_nif_compat.h"
-#include "unicode/ucol.h"
-#include "unicode/ucasemap.h"
-
-#define MAX_DEPTH 10
-
-#if (ERL_NIF_MAJOR_VERSION > 2) || \
-    (ERL_NIF_MAJOR_VERSION == 2 && ERL_NIF_MINOR_VERSION >= 3)
-/* OTP R15B or higher */
-#define term_is_number(env, t) enif_is_number(env, t)
-#else
-#define term_is_number(env, t)  \
-    (!enif_is_binary(env, t) && \
-     !enif_is_list(env, t) &&   \
-     !enif_is_tuple(env, t))
-#endif
-
-static ERL_NIF_TERM ATOM_TRUE;
-static ERL_NIF_TERM ATOM_FALSE;
-static ERL_NIF_TERM ATOM_NULL;
-
-typedef struct {
-    ErlNifEnv* env;
-    int error;
-    UCollator* coll;
-} ctx_t;
-
-static UCollator** collators = NULL;
-static int collStackTop = 0;
-static int numCollators = 0;
-static ErlNifMutex* collMutex = NULL;
-
-static ERL_NIF_TERM less_json_nif(ErlNifEnv*, int, const ERL_NIF_TERM []);
-static int on_load(ErlNifEnv*, void**, ERL_NIF_TERM);
-static void on_unload(ErlNifEnv*, void*);
-static __inline int less_json(int, ctx_t*, ERL_NIF_TERM, ERL_NIF_TERM);
-static __inline int atom_sort_order(ErlNifEnv*, ERL_NIF_TERM);
-static __inline int compare_strings(ctx_t*, ErlNifBinary, ErlNifBinary);
-static __inline int compare_lists(int, ctx_t*, ERL_NIF_TERM, ERL_NIF_TERM);
-static __inline int compare_props(int, ctx_t*, ERL_NIF_TERM, ERL_NIF_TERM);
-static __inline void reserve_coll(ctx_t*);
-static __inline void release_coll(ctx_t*);
-
-
-void
-reserve_coll(ctx_t *ctx)
-{
-    if (ctx->coll == NULL) {
-        enif_mutex_lock(collMutex);
-        assert(collStackTop < numCollators);
-        ctx->coll = collators[collStackTop];
-        collStackTop += 1;
-        enif_mutex_unlock(collMutex);
-    }
-}
-
-
-void
-release_coll(ctx_t *ctx)
-{
-    if (ctx->coll != NULL) {
-        enif_mutex_lock(collMutex);
-        collStackTop -= 1;
-        assert(collStackTop >= 0);
-        enif_mutex_unlock(collMutex);
-    }
-}
-
-
-
-ERL_NIF_TERM
-less_json_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
-{
-    ctx_t ctx;
-    int result;
-
-    ctx.env = env;
-    ctx.error = 0;
-    ctx.coll = NULL;
-
-    result = less_json(1, &ctx, argv[0], argv[1]);
-    release_coll(&ctx);
-
-    /*
-     * There are 2 possible failure reasons:
-     *
-     * 1) We got an invalid EJSON operand;
-     * 2) The EJSON structures are too deep - to avoid allocating too
-     *    many C stack frames (because less_json is a recursive function),
-     *    and running out of memory, we throw a badarg exception to Erlang
-     *    and do the comparison in Erlang land. In practice, views keys are
-     *    EJSON structures with very little nesting.
-     */
-    return ctx.error ? enif_make_badarg(env) : enif_make_int(env, result);
-}
-
-
-int
-less_json(int depth, ctx_t* ctx, ERL_NIF_TERM a, ERL_NIF_TERM b)
-{
-    int aIsAtom, bIsAtom;
-    int aIsBin, bIsBin;
-    int aIsNumber, bIsNumber;
-    int aIsList, bIsList;
-    int aArity, bArity;
-    const ERL_NIF_TERM *aProps, *bProps;
-
-    /*
-     * Avoid too much recursion. Normally there isn't more than a few levels
-     * of recursion, as in practice view keys do not go beyond 1 to 3 levels
-     * of nesting. In case of too much recursion, signal it to the Erlang land
-     * via an exception and do the EJSON comparison in Erlang land.
-     */
-    if (depth > MAX_DEPTH) {
-        ctx->error = 1;
-        return 0;
-    }
-
-    aIsAtom = enif_is_atom(ctx->env, a);
-    bIsAtom = enif_is_atom(ctx->env, b);
-
-    if (aIsAtom) {
-        if (bIsAtom) {
-            int aSortOrd, bSortOrd;
-
-            if ((aSortOrd = atom_sort_order(ctx->env, a)) == -1) {
-                ctx->error = 1;
-                return 0;
-            }
-
-            if ((bSortOrd = atom_sort_order(ctx->env, b)) == -1) {
-                ctx->error = 1;
-                return 0;
-            }
-
-            return aSortOrd - bSortOrd;
-        }
-
-        return -1;
-    }
-
-    if (bIsAtom) {
-        return 1;
-    }
-
-    aIsNumber = term_is_number(ctx->env, a);
-    bIsNumber = term_is_number(ctx->env, b);
-
-    if (aIsNumber) {
-        if (bIsNumber) {
-            return enif_compare_compat(ctx->env, a, b);
-        }
-
-        return -1;
-    }
-
-    if (bIsNumber) {
-        return 1;
-    }
-
-    aIsBin = enif_is_binary(ctx->env, a);
-    bIsBin = enif_is_binary(ctx->env, b);
-
-    if (aIsBin) {
-        if (bIsBin) {
-            ErlNifBinary binA, binB;
-
-            enif_inspect_binary(ctx->env, a, &binA);
-            enif_inspect_binary(ctx->env, b, &binB);
-
-            return compare_strings(ctx, binA, binB);
-        }
-
-        return -1;
-    }
-
-    if (bIsBin) {
-        return 1;
-    }
-
-    aIsList = enif_is_list(ctx->env, a);
-    bIsList = enif_is_list(ctx->env, b);
-
-    if (aIsList) {
-        if (bIsList) {
-            return compare_lists(depth, ctx, a, b);
-        }
-
-        return -1;
-    }
-
-    if (bIsList) {
-        return 1;
-    }
-
-    if (!enif_get_tuple(ctx->env, a, &aArity, &aProps)) {
-        ctx->error = 1;
-        return 0;
-    }
-    if ((aArity != 1) || !enif_is_list(ctx->env, aProps[0])) {
-        ctx->error = 1;
-        return 0;
-    }
-
-    if (!enif_get_tuple(ctx->env, b, &bArity, &bProps)) {
-        ctx->error = 1;
-        return 0;
-    }
-    if ((bArity != 1) || !enif_is_list(ctx->env, bProps[0])) {
-        ctx->error = 1;
-        return 0;
-    }
-
-    return compare_props(depth, ctx, aProps[0], bProps[0]);
-}
-
-
-int
-atom_sort_order(ErlNifEnv* env, ERL_NIF_TERM a)
-{
-    if (enif_compare_compat(env, a, ATOM_NULL) == 0) {
-        return 1;
-    } else if (enif_compare_compat(env, a, ATOM_FALSE) == 0) {
-        return 2;
-    } else if (enif_compare_compat(env, a, ATOM_TRUE) == 0) {
-        return 3;
-    }
-
-    return -1;
-}
-
-
-int
-compare_lists(int depth, ctx_t* ctx, ERL_NIF_TERM a, ERL_NIF_TERM b)
-{
-    ERL_NIF_TERM headA, tailA;
-    ERL_NIF_TERM headB, tailB;
-    int aIsEmpty, bIsEmpty;
-    int result;
-
-    while (1) {
-        aIsEmpty = !enif_get_list_cell(ctx->env, a, &headA, &tailA);
-        bIsEmpty = !enif_get_list_cell(ctx->env, b, &headB, &tailB);
-
-        if (aIsEmpty) {
-            if (bIsEmpty) {
-                return 0;
-            }
-            return -1;
-        }
-
-        if (bIsEmpty) {
-            return 1;
-        }
-
-        result = less_json(depth + 1, ctx, headA, headB);
-
-        if (ctx->error || result != 0) {
-            return result;
-        }
-
-        a = tailA;
-        b = tailB;
-    }
-
-    return result;
-}
-
-
-int
-compare_props(int depth, ctx_t* ctx, ERL_NIF_TERM a, ERL_NIF_TERM b)
-{
-    ERL_NIF_TERM headA, tailA;
-    ERL_NIF_TERM headB, tailB;
-    int aArity, bArity;
-    const ERL_NIF_TERM *aKV, *bKV;
-    ErlNifBinary keyA, keyB;
-    int aIsEmpty, bIsEmpty;
-    int keyCompResult, valueCompResult;
-
-    while (1) {
-        aIsEmpty = !enif_get_list_cell(ctx->env, a, &headA, &tailA);
-        bIsEmpty = !enif_get_list_cell(ctx->env, b, &headB, &tailB);
-
-        if (aIsEmpty) {
-            if (bIsEmpty) {
-                return 0;
-            }
-            return -1;
-        }
-
-        if (bIsEmpty) {
-            return 1;
-        }
-
-        if (!enif_get_tuple(ctx->env, headA, &aArity, &aKV)) {
-            ctx->error = 1;
-            return 0;
-        }
-        if ((aArity != 2) || !enif_inspect_binary(ctx->env, aKV[0], &keyA)) {
-            ctx->error = 1;
-            return 0;
-        }
-
-        if (!enif_get_tuple(ctx->env, headB, &bArity, &bKV)) {
-            ctx->error = 1;
-            return 0;
-        }
-        if ((bArity != 2) || !enif_inspect_binary(ctx->env, bKV[0], &keyB)) {
-            ctx->error = 1;
-            return 0;
-        }
-
-        keyCompResult = compare_strings(ctx, keyA, keyB);
-
-        if (ctx->error || keyCompResult != 0) {
-            return keyCompResult;
-        }
-
-        valueCompResult = less_json(depth + 1, ctx, aKV[1], bKV[1]);
-
-        if (ctx->error || valueCompResult != 0) {
-            return valueCompResult;
-        }
-
-        a = tailA;
-        b = tailB;
-    }
-
-    return 0;
-}
-
-
-int
-compare_strings(ctx_t* ctx, ErlNifBinary a, ErlNifBinary b)
-{
-    UErrorCode status = U_ZERO_ERROR;
-    UCharIterator iterA, iterB;
-    int result;
-
-    uiter_setUTF8(&iterA, (const char *) a.data, (uint32_t) a.size);
-    uiter_setUTF8(&iterB, (const char *) b.data, (uint32_t) b.size);
-
-    reserve_coll(ctx);
-    result = ucol_strcollIter(ctx->coll, &iterA, &iterB, &status);
-
-    if (U_FAILURE(status)) {
-        ctx->error = 1;
-        return 0;
-    }
-
-    /* ucol_strcollIter returns 0, -1 or 1
-     * (see type UCollationResult in unicode/ucol.h) */
-
-    return result;
-}
-
-
-int
-on_load(ErlNifEnv* env, void** priv, ERL_NIF_TERM info)
-{
-    UErrorCode status = U_ZERO_ERROR;
-    int i, j;
-
-    if (!enif_get_int(env, info, &numCollators)) {
-        return 1;
-    }
-
-    if (numCollators < 1) {
-        return 2;
-    }
-
-    collMutex = enif_mutex_create("coll_mutex");
-
-    if (collMutex == NULL) {
-        return 3;
-    }
-
-    collators = enif_alloc(sizeof(UCollator*) * numCollators);
-
-    if (collators == NULL) {
-        enif_mutex_destroy(collMutex);
-        return 4;
-    }
-
-    for (i = 0; i < numCollators; i++) {
-        collators[i] = ucol_open("", &status);
-
-        if (U_FAILURE(status)) {
-            for (j = 0; j < i; j++) {
-                ucol_close(collators[j]);
-            }
-
-            enif_free(collators);
-            enif_mutex_destroy(collMutex);
-
-            return 5;
-        }
-    }
-
-    ATOM_TRUE = enif_make_atom(env, "true");
-    ATOM_FALSE = enif_make_atom(env, "false");
-    ATOM_NULL = enif_make_atom(env, "null");
-
-    return 0;
-}
-
-
-void
-on_unload(ErlNifEnv* env, void* priv_data)
-{
-    if (collators != NULL) {
-        int i;
-
-        for (i = 0; i < numCollators; i++) {
-            ucol_close(collators[i]);
-        }
-
-        enif_free(collators);
-    }
-
-    if (collMutex != NULL) {
-        enif_mutex_destroy(collMutex);
-    }
-}
-
-
-static ErlNifFunc nif_functions[] = {
-    {"less_nif", 2, less_json_nif}
-};
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-ERL_NIF_INIT(couch_ejson_compare, nif_functions, &on_load, NULL, NULL, &on_unload);
-
-#ifdef __cplusplus
-}
-#endif

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/couch/src/couch_ejson_compare.erl
----------------------------------------------------------------------
diff --git a/src/couch/src/couch_ejson_compare.erl b/src/couch/src/couch_ejson_compare.erl
deleted file mode 100644
index 7b000fc..0000000
--- a/src/couch/src/couch_ejson_compare.erl
+++ /dev/null
@@ -1,113 +0,0 @@
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-%   http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--module(couch_ejson_compare).
-
--export([less/2, less_json_ids/2, less_json/2]).
-
--on_load(init/0).
-
-
-init() ->
-    LibDir = case config:get("couchdb", "util_driver_dir") of
-    undefined ->
-        filename:join(couch_util:priv_dir(), "lib");
-    LibDir0 ->
-        LibDir0
-    end,
-    NumScheds = erlang:system_info(schedulers),
-    (catch erlang:load_nif(filename:join([LibDir, ?MODULE]), NumScheds)),
-    case erlang:system_info(otp_release) of
-    "R13B03" -> true;
-    _ -> ok
-    end.
-
-
-less(A, B) ->
-    try
-        less_nif(A, B)
-    catch
-    error:badarg ->
-        % Maybe the EJSON structure is too deep, fallback to Erlang land.
-        less_erl(A, B)
-    end.
-
-less_json_ids({JsonA, IdA}, {JsonB, IdB}) ->
-    case less(JsonA, JsonB) of
-    0 ->
-        IdA < IdB;
-    Result ->
-        Result < 0
-    end.
-
-less_json(A,B) ->
-    less(A, B) < 0.
-
-
-less_nif(A, B) ->
-    less_erl(A, B).
-
-
-less_erl(A,A)                                 -> 0;
-
-less_erl(A,B) when is_atom(A), is_atom(B)     -> atom_sort(A) - atom_sort(B);
-less_erl(A,_) when is_atom(A)                 -> -1;
-less_erl(_,B) when is_atom(B)                 -> 1;
-
-less_erl(A,B) when is_number(A), is_number(B) -> A - B;
-less_erl(A,_) when is_number(A)               -> -1;
-less_erl(_,B) when is_number(B)               -> 1;
-
-less_erl(A,B) when is_binary(A), is_binary(B) -> couch_util:collate(A,B);
-less_erl(A,_) when is_binary(A)               -> -1;
-less_erl(_,B) when is_binary(B)               -> 1;
-
-less_erl(A,B) when is_list(A), is_list(B)     -> less_list(A,B);
-less_erl(A,_) when is_list(A)                 -> -1;
-less_erl(_,B) when is_list(B)                 -> 1;
-
-less_erl({A},{B}) when is_list(A), is_list(B) -> less_props(A,B);
-less_erl({A},_) when is_list(A)               -> -1;
-less_erl(_,{B}) when is_list(B)               -> 1.
-
-atom_sort(null) -> 1;
-atom_sort(false) -> 2;
-atom_sort(true) -> 3.
-
-less_props([], [_|_]) ->
-    -1;
-less_props(_, []) ->
-    1;
-less_props([{AKey, AValue}|RestA], [{BKey, BValue}|RestB]) ->
-    case couch_util:collate(AKey, BKey) of
-    0 ->
-        case less_erl(AValue, BValue) of
-        0 ->
-            less_props(RestA, RestB);
-        Result ->
-            Result
-        end;
-    Result ->
-        Result
-    end.
-
-less_list([], [_|_]) ->
-    -1;
-less_list(_, []) ->
-    1;
-less_list([A|RestA], [B|RestB]) ->
-    case less_erl(A,B) of
-    0 ->
-        less_list(RestA, RestB);
-    Result ->
-        Result
-    end.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/couch/src/couch_util.erl
----------------------------------------------------------------------
diff --git a/src/couch/src/couch_util.erl b/src/couch/src/couch_util.erl
index d09211a..beb9622 100644
--- a/src/couch/src/couch_util.erl
+++ b/src/couch/src/couch_util.erl
@@ -21,6 +21,7 @@
 -export([get_nested_json_value/2, json_user_ctx/1]).
 -export([proplist_apply_field/2, json_apply_field/2]).
 -export([to_binary/1, to_integer/1, to_list/1, url_encode/1]).
+-export([json_encode/1, json_decode/1]).
 -export([verify/2,simple_call/2,shutdown_sync/1]).
 -export([get_value/2, get_value/3]).
 -export([md5/1, md5_init/0, md5_update/2, md5_final/1]).
@@ -376,6 +377,17 @@ url_encode([H|T]) ->
 url_encode([]) ->
     [].
 
+json_encode(V) ->
+    jiffy:encode(V, [force_utf8]).
+
+json_decode(V) ->
+    try
+        jiffy:decode(V)
+    catch
+        throw:Error ->
+            throw({invalid_json, Error})
+    end.
+
 verify([X|RestX], [Y|RestY], Result) ->
     verify(RestX, RestY, (X bxor Y) bor Result);
 verify([], [], Result) ->

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/ejson/c_src/decode.c
----------------------------------------------------------------------
diff --git a/src/ejson/c_src/decode.c b/src/ejson/c_src/decode.c
deleted file mode 100644
index 68f1317..0000000
--- a/src/ejson/c_src/decode.c
+++ /dev/null
@@ -1,308 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "erl_nif.h"
-#include "erl_nif_compat.h"
-#include "yajl/yajl_parse.h"
-#include "yajl/yajl_parser.h"
-#include "yajl/yajl_lex.h"
-
-typedef struct {
-    ERL_NIF_TERM head;
-    ErlNifEnv* env;
-} decode_ctx;
-
-#define ENV(ctxarg) (((decode_ctx*)ctxarg)->env)
-
-#define CONTINUE 1
-#define CANCEL 0
-
-
-static ERL_NIF_TERM
-make_error(yajl_handle handle, ErlNifEnv* env)
-{
-    char* yajlError = (char*) yajl_get_error(handle, 0, NULL, 0);
-    ERL_NIF_TERM errMsg;
-
-    if(yajlError != NULL)
-    {
-        errMsg = enif_make_string(env, yajlError, ERL_NIF_LATIN1);
-        yajl_free_error(handle, (unsigned char*) yajlError);
-    }
-    else
-    {
-        errMsg = enif_make_string(env, "unknown parse error", ERL_NIF_LATIN1);
-    }
-
-    return enif_make_tuple(env, 2,
-        enif_make_atom(env, "error"),
-        enif_make_tuple(env, 2,
-            enif_make_uint(env, handle->bytesConsumed),
-            errMsg
-        )
-    );
-}
-
-
-static void
-add_to_head(void* vctx, ERL_NIF_TERM newhead)
-{
-    decode_ctx* ctx = (decode_ctx*)vctx;
-    ctx->head = enif_make_list_cell(ctx->env, newhead, ctx->head);
-}
-
-static int
-decode_null(void* ctx)
-{
-    add_to_head(ctx, enif_make_atom(ENV(ctx), "null"));
-    return CONTINUE;
-}
-
-static int
-decode_boolean(void* ctx, int val)
-{
-    add_to_head(ctx, enif_make_atom(ENV(ctx), val ? "true" : "false"));
-    return CONTINUE;
-}
-
-static int
-decode_number(void * ctx, const char * numberVal, unsigned int numberLen)
-{
-    // scan in the input to see if it's a float or int
-
-    int numberType = 0; // 0 means integer, 1 means float
-    unsigned int i;
-    ErlNifBinary bin;
-    int missingDot = 1;
-    unsigned int expPos;
-
-    for(i=0; i<numberLen; i++) {
-        switch (numberVal[i]) {
-        case '.':
-            missingDot = 0;
-            numberType = 1; // it's  a float
-            goto loopend;
-        case 'E':
-        case 'e':
-            expPos = i;
-            numberType = 1; // it's  a float
-            goto loopend;
-        }
-    }
-loopend:
-    if ((numberType == 1) && missingDot)
-    {
-        if(!enif_alloc_binary_compat(ENV(ctx), numberLen + 2, &bin))
-        {
-            return CANCEL;
-        }
-        memcpy(bin.data, numberVal, expPos);
-        bin.data[expPos] = '.';
-        bin.data[expPos + 1] = '0';
-        memcpy(bin.data + expPos + 2, numberVal + expPos, numberLen - expPos);
-    }
-    else
-    {
-        if(!enif_alloc_binary_compat(ENV(ctx), numberLen, &bin))
-        {
-            return CANCEL;
-        }
-        memcpy(bin.data, numberVal, numberLen);
-    }
-    add_to_head(ctx, enif_make_tuple(ENV(ctx), 2,
-                        enif_make_int(ENV(ctx), numberType),
-                        enif_make_binary(ENV(ctx), &bin)));
-    return CONTINUE;
-}
-
-
-
-static int
-decode_string(void* ctx, const unsigned char* data, unsigned int size)
-{
-    ErlNifBinary bin;
-    if(!enif_alloc_binary_compat(ENV(ctx), size, &bin))
-    {
-        return CANCEL;
-    }
-    memcpy(bin.data, data, size);
-    add_to_head(ctx, enif_make_binary(ENV(ctx), &bin));
-    return CONTINUE;
-}
-
-static int
-decode_start_array(void* ctx)
-{
-    add_to_head(ctx, enif_make_int(ENV(ctx), 0));
-    return CONTINUE;
-}
-
-
-static int
-decode_end_array(void* ctx)
-{
-    add_to_head(ctx, enif_make_int(ENV(ctx), 1));
-    return CONTINUE;
-}
-
-
-static int
-decode_start_map(void* ctx)
-{
-    add_to_head(ctx, enif_make_int(ENV(ctx), 2));
-    return CONTINUE;
-}
-
-
-static int
-decode_end_map(void* ctx)
-{
-    add_to_head(ctx, enif_make_int(ENV(ctx), 3));
-    return CONTINUE;
-}
-
-
-static int
-decode_map_key(void* ctx, const unsigned char* data, unsigned int size)
-{
-    ErlNifBinary bin;
-    if(!enif_alloc_binary_compat(ENV(ctx), size, &bin))
-    {
-       return CANCEL;
-    }
-    memcpy(bin.data, data, size);
-    add_to_head(ctx, enif_make_tuple(ENV(ctx), 2,
-                        enif_make_int(ENV(ctx), 3),
-                        enif_make_binary(ENV(ctx), &bin)));
-    return CONTINUE;
-}
-
-static yajl_callbacks
-decoder_callbacks = {
-    decode_null,
-    decode_boolean,
-    NULL,
-    NULL,
-    decode_number,
-    decode_string,
-    decode_start_map,
-    decode_map_key,
-    decode_end_map,
-    decode_start_array,
-    decode_end_array
-};
-
-static int
-check_rest(unsigned char* data, unsigned int size, unsigned int used)
-{
-    unsigned int i = 0;
-    for(i = used; i < size; i++)
-    {
-        switch(data[i])
-        {
-            case ' ':
-            case '\t':
-            case '\r':
-            case '\n':
-                continue;
-            default:
-                return CANCEL;
-        }
-    }
-
-    return CONTINUE;
-}
-
-ERL_NIF_TERM
-reverse_tokens(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
-{
-    decode_ctx ctx;
-    yajl_parser_config conf = {0, 1}; // No comments, check utf8
-    yajl_handle handle = yajl_alloc(&decoder_callbacks, &conf, NULL, &ctx);
-    yajl_status status;
-    unsigned int used;
-    ErlNifBinary bin;
-    ERL_NIF_TERM ret;
-
-    ctx.env = env;
-    ctx.head = enif_make_list_from_array(env, NULL, 0);
-
-    if(!enif_inspect_iolist_as_binary(env, argv[0], &bin))
-    {
-        ret = enif_make_badarg(env);
-        goto done;
-    }
-
-    status = yajl_parse(handle, bin.data, bin.size);
-    used = handle->bytesConsumed;
-
-    // Parsing something like "2.0" (without quotes) will
-    // cause a spurious semi-error. We add the extra size
-    // check so that "2008-20-10" doesn't pass.
-    if(status == yajl_status_insufficient_data && used == bin.size)
-    {
-        status = yajl_parse_complete(handle);
-    }
-
-    if(status == yajl_status_ok && used != bin.size)
-    {
-        if(check_rest(bin.data, bin.size, used) == CANCEL)
-        {
-            ret = enif_make_tuple(env, 2,
-                enif_make_atom(env, "error"),
-                enif_make_atom(env, "garbage_after_value")
-            );
-            goto done;
-        }
-    }
-
-    switch(status)
-    {
-        case yajl_status_ok:
-            ret = enif_make_tuple(env, 2, enif_make_atom(env, "ok"), ctx.head);
-            goto done;
-
-        case yajl_status_error:
-            ret = make_error(handle, env);
-            goto done;
-
-        case yajl_status_insufficient_data:
-            ret = enif_make_tuple(env, 2,
-                enif_make_atom(env, "error"),
-                enif_make_atom(env, "insufficient_data")
-            );
-            goto done;
-
-        case yajl_status_client_canceled:
-        /* the only time we do this is when we can't allocate a binary. */
-            ret = enif_make_tuple(env, 2,
-                enif_make_atom(env, "error"),
-                enif_make_atom(env, "insufficient_memory")
-            );
-            goto done;
-
-        default:
-            ret = enif_make_tuple(env, 2,
-                enif_make_atom(env, "error"),
-                enif_make_atom(env, "unknown")
-            );
-            goto done;
-    }
-
-done:
-    if(handle != NULL) yajl_free(handle);
-    return ret;
-}

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/ejson/c_src/ejson.c
----------------------------------------------------------------------
diff --git a/src/ejson/c_src/ejson.c b/src/ejson/c_src/ejson.c
deleted file mode 100644
index 390f762..0000000
--- a/src/ejson/c_src/ejson.c
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "erl_nif.h"
-
-ERL_NIF_TERM final_encode(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
-ERL_NIF_TERM reverse_tokens(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
-
-int
-on_load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM info)
-{
-    return 0;
-}
-
-int
-on_reload(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM info)
-{
-    return 0;
-}
-
-int
-on_upgrade(ErlNifEnv* env, void** priv_data, void** old_data, ERL_NIF_TERM info)
-{
-    return 0;
-}
-
-static ErlNifFunc nif_funcs[] =
-{
-    {"final_encode", 1, final_encode},
-    {"reverse_tokens", 1, reverse_tokens}
-};
-
-ERL_NIF_INIT(ejson, nif_funcs, &on_load, &on_reload, &on_upgrade, NULL);

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/ejson/c_src/encode.c
----------------------------------------------------------------------
diff --git a/src/ejson/c_src/encode.c b/src/ejson/c_src/encode.c
deleted file mode 100644
index 1dbd1df..0000000
--- a/src/ejson/c_src/encode.c
+++ /dev/null
@@ -1,200 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-
-#include "erl_nif.h"
-#include "erl_nif_compat.h"
-#include "yajl/yajl_encode.h"
-
-#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__)
-#include <float.h>
-#define isnan _isnan
-#define isinf !_finite
-#define snprintf _snprintf
-#endif
-
-#define SUCCESS 0
-#define NOMEM 1
-#define BADARG 2
-
-
-typedef struct {
-    ErlNifEnv* env;
-    ErlNifBinary bin;
-    size_t fill_offset;
-    int error;
-} encode_ctx;
-
-
-static int
-ensure_buffer(void* vctx, unsigned int len) {
-    encode_ctx* ctx = (encode_ctx*)vctx;
-    if ((ctx->bin.size - ctx->fill_offset) < len) {
-        if(!enif_realloc_binary_compat(ctx->env, &(ctx->bin), (ctx->bin.size * 2) + len)) {
-            return NOMEM;
-        }
-    }
-    return SUCCESS;
-}
-
-static void
-fill_buffer(void* vctx, const char* str, unsigned int len)
-{
-    encode_ctx* ctx = (encode_ctx*)vctx;
-
-    if (ctx->error || (ctx->error = ensure_buffer(vctx, len))) {
-        return;
-    }
-    memcpy(ctx->bin.data + ctx->fill_offset, str, len);
-    ctx->fill_offset += len;
-}
-
-/* Json encode the string binary into the ctx.bin,
-  with surrounding quotes and all */
-static int
-encode_string(void* vctx, ERL_NIF_TERM binary)
-{
-    encode_ctx* ctx = (encode_ctx*)vctx;
-    ErlNifBinary bin;
-
-    if(!enif_inspect_binary(ctx->env, binary, &bin)) {
-        return NOMEM;
-    }
-    fill_buffer(ctx, "\"", 1);
-    if (ctx->error) {
-        return ctx->error;
-    }
-    yajl_string_encode2(fill_buffer, ctx, bin.data, bin.size);
-    fill_buffer(ctx, "\"", 1);
-
-    return ctx->error;
-}
-
-static ERL_NIF_TERM
-no_mem_error(ErlNifEnv* env)
-{
-    return enif_make_tuple(env, 2,
-            enif_make_atom(env, "error"),
-            enif_make_atom(env, "insufficient_memory"));
-}
-
-ERL_NIF_TERM
-final_encode(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
-{
-    ERL_NIF_TERM head = argv[0];
-    ERL_NIF_TERM term;
-    double number;
-    encode_ctx ctx;
-    char* start;
-    size_t len;
-    size_t i;
-
-    ctx.env = env;
-    ctx.fill_offset = 0;
-    ctx.error = 0;
-
-    if (!enif_alloc_binary_compat(env, 100, &ctx.bin)) {
-            return no_mem_error(env);
-    }
-
-    while(enif_get_list_cell(env, head, &term, &head)) {
-        ErlNifBinary termbin;
-        const ERL_NIF_TERM* array;
-        int arity;
-        int code;
-
-        // We scan the list, looking for things to write into the binary, or
-        // encode and then write into the binary. We encode values that are
-        // tuples tagged with a type and a value: {Type, Value} where Type
-        // is a an Integer and Value is what is to be encoded
-
-        if (enif_get_tuple(env, term, &arity, &array)) {
-            // It's a tuple to encode and copy
-            if (arity != 2 || !enif_get_int(env, array[0], &code)) {
-                // not arity 2 or the first element isn't an int
-                ctx.error = BADARG;
-                goto done;
-            }
-            if (code == 0) {
-                // {0, String}
-                if (encode_string(&ctx, array[1]) != SUCCESS) {
-                    goto done;
-                }
-            }
-            else {
-                // {1, Double}
-                if(!enif_get_double(env, array[1], &number)) {
-                    ctx.error = BADARG;
-                    goto done;
-                }
-                // We can't encode these.
-                if (isnan(number) || isinf(number)) {
-                    ctx.error = BADARG;
-                    goto done;
-                }
-                if ((ctx.error = ensure_buffer(&ctx, 32)) != SUCCESS) {
-                    goto done;
-                }
-                // write the string into the buffer
-                start = (char*) (ctx.bin.data + ctx.fill_offset);
-                snprintf(start, 32, "%0.20g", number);
-                len = strlen(start);
-                for(i = 0; i < len; i++) {
-                    if(start[i] == '.' || start[i] == 'e' || start[i] == 'E') {
-                        break;
-                    }
-                }
-                if(i == len) {
-                    if(i > 29) {
-                        ctx.error = BADARG;
-                        goto done;
-                    }
-                    start[len++] = '.';
-                    start[len++] = '0';
-                }
-                // increment the length
-                ctx.fill_offset += len;
-            }
-        } else if (enif_inspect_binary(env, term, &termbin)) {
-            // this is a regular binary, copy the contents into the buffer
-            fill_buffer(&ctx, (char*)termbin.data, termbin.size);
-            if (ctx.error) {
-                goto done;
-            }
-        }
-        else {
-            //not a binary, not a tuple, wtf!
-            ctx.error = BADARG;
-            goto done;
-        }
-    }
-done:
-    if (ctx.error == NOMEM) {
-        enif_release_binary_compat(env, &ctx.bin);
-        return no_mem_error(env);
-    } else if (ctx.error == BADARG) {
-        enif_release_binary_compat(env, &ctx.bin);
-        return enif_make_badarg(env);
-    }
-
-    // Resize the binary to our exact final size
-    if(!enif_realloc_binary_compat(env, &(ctx.bin), ctx.fill_offset)) {
-        enif_release_binary_compat(env, &ctx.bin);
-        return no_mem_error(env);
-    }
-    // make the binary term which transfers ownership
-    return enif_make_binary(env, &ctx.bin);
-}
-

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/ejson/c_src/erl_nif_compat.h
----------------------------------------------------------------------
diff --git a/src/ejson/c_src/erl_nif_compat.h b/src/ejson/c_src/erl_nif_compat.h
deleted file mode 100644
index 548ea7a..0000000
--- a/src/ejson/c_src/erl_nif_compat.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/* Copyright (c) 2010-2011 Basho Technologies, Inc.
- * With some minor modifications for Apache CouchDB.
- *
- * This file is provided to you under the Apache License,
- * Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License.  You may obtain
- * a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
-*/
-
-#ifndef ERL_NIF_COMPAT_H_
-#define ERL_NIF_COMPAT_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#include "erl_nif.h"
-
-
-#if ERL_NIF_MAJOR_VERSION == 0 && ERL_NIF_MINOR_VERSION == 1
-#define OTP_R13B03
-#elif ERL_NIF_MAJOR_VERSION == 1 && ERL_NIF_MINOR_VERSION == 0
-#define OTP_R13B04
-#elif ERL_NIF_MAJOR_VERSION == 2 && ERL_NIF_MINOR_VERSION == 0
-#define OTP_R14A
-#define OTP_R14B
-#define OTP_R14B01
-#elif ERL_NIF_MAJOR_VERSION == 2 && ERL_NIF_MINOR_VERSION == 1
-#define OTP_R14B02
-#endif
-
-
-#ifdef OTP_R13B03
-
-#define enif_open_resource_type_compat enif_open_resource_type
-#define enif_alloc_resource_compat enif_alloc_resource
-#define enif_release_resource_compat enif_release_resource
-#define enif_alloc_binary_compat enif_alloc_binary
-#define enif_alloc_compat enif_alloc
-#define enif_release_binary_compat enif_release_binary
-#define enif_free_compat enif_free
-#define enif_get_atom_compat enif_get_atom
-#define enif_priv_data_compat enif_get_data
-#define enif_make_uint_compat enif_make_ulong
-
-#define enif_make_string_compat(E, B, Enc) \
-    enif_make_string(E, B)
-
-#endif /* R13B03 */
-
-
-#ifdef OTP_R13B04
-
-#define enif_open_resource_type_compat enif_open_resource_type
-#define enif_alloc_resource_compat enif_alloc_resource
-#define enif_release_resource_compat enif_release_resource
-#define enif_alloc_binary_compat enif_alloc_binary
-#define enif_realloc_binary_compat enif_realloc_binary
-#define enif_release_binary_compat enif_release_binary
-#define enif_alloc_compat enif_alloc
-#define enif_free_compat enif_free
-#define enif_get_atom_compat enif_get_atom
-#define enif_priv_data_compat enif_priv_data
-#define enif_make_string_compat enif_make_string
-#define enif_make_uint_compat enif_make_uint
-
-#endif /* R13B04 */
-
-
-/* OTP R14 and future releases */
-#if !defined(OTP_R13B03) && !defined(OTP_R13B04)
-
-#define enif_open_resource_type_compat(E, N, D, F, T) \
-    enif_open_resource_type(E, NULL, N, D, F, T)
-
-#define enif_alloc_resource_compat(E, T, S) \
-    enif_alloc_resource(T, S)
-
-#define enif_release_resource_compat(E, H) \
-    enif_release_resource(H)
-
-#define enif_alloc_binary_compat(E, S, B) \
-    enif_alloc_binary(S, B)
-
-#define enif_realloc_binary_compat(E, S, B) \
-    enif_realloc_binary(S, B)
-
-#define enif_release_binary_compat(E, B) \
-    enif_release_binary(B)
-
-#define enif_alloc_compat(E, S) \
-    enif_alloc(S)
-
-#define enif_free_compat(E, P) \
-    enif_free(P)
-
-#define enif_get_atom_compat(E, T, B, S) \
-    enif_get_atom(E, T, B, S, ERL_NIF_LATIN1)
-
-#define enif_priv_data_compat enif_priv_data
-#define enif_make_string_compat enif_make_string
-#define enif_make_uint_compat enif_make_uint
-
-#endif  /* R14 and future releases */
-
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* ERL_NIF_COMPAT_H_ */

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/ejson/c_src/yajl/yajl.c
----------------------------------------------------------------------
diff --git a/src/ejson/c_src/yajl/yajl.c b/src/ejson/c_src/yajl/yajl.c
deleted file mode 100644
index 39d8b9f..0000000
--- a/src/ejson/c_src/yajl/yajl.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright 2010, Lloyd Hilaiel.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * 
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in
- *     the documentation and/or other materials provided with the
- *     distribution.
- * 
- *  3. Neither the name of Lloyd Hilaiel nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */ 
-
-#include "yajl_parse.h"
-#include "yajl_lex.h"
-#include "yajl_parser.h"
-#include "yajl_alloc.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-const char *
-yajl_status_to_string(yajl_status stat)
-{
-    const char * statStr = "unknown";
-    switch (stat) {
-        case yajl_status_ok:
-            statStr = "ok, no error";
-            break;
-        case yajl_status_client_canceled:
-            statStr = "client canceled parse";
-            break;
-        case yajl_status_insufficient_data:
-            statStr = "eof was met before the parse could complete";
-            break;
-        case yajl_status_error:
-            statStr = "parse error";
-            break;
-    }
-    return statStr;
-}
-
-yajl_handle
-yajl_alloc(const yajl_callbacks * callbacks,
-           const yajl_parser_config * config,
-           const yajl_alloc_funcs * afs,
-           void * ctx)
-{
-    unsigned int allowComments = 0;
-    unsigned int validateUTF8 = 0;
-    yajl_handle hand = NULL;
-    yajl_alloc_funcs afsBuffer;
-    
-    /* first order of business is to set up memory allocation routines */
-    if (afs != NULL) {
-        if (afs->malloc == NULL || afs->realloc == NULL || afs->free == NULL)
-        {
-            return NULL;
-        }
-    } else {
-        yajl_set_default_alloc_funcs(&afsBuffer);
-        afs = &afsBuffer;
-    }
-
-    hand = (yajl_handle) YA_MALLOC(afs, sizeof(struct yajl_handle_t));
-
-    /* copy in pointers to allocation routines */
-    memcpy((void *) &(hand->alloc), (void *) afs, sizeof(yajl_alloc_funcs));
-
-    if (config != NULL) {
-        allowComments = config->allowComments;
-        validateUTF8 = config->checkUTF8;
-    }
-
-    hand->callbacks = callbacks;
-    hand->ctx = ctx;
-    hand->lexer = yajl_lex_alloc(&(hand->alloc), allowComments, validateUTF8);
-    hand->bytesConsumed = 0;
-    hand->decodeBuf = yajl_buf_alloc(&(hand->alloc));
-    yajl_bs_init(hand->stateStack, &(hand->alloc));
-
-    yajl_bs_push(hand->stateStack, yajl_state_start);    
-
-    return hand;
-}
-
-void
-yajl_free(yajl_handle handle)
-{
-    yajl_bs_free(handle->stateStack);
-    yajl_buf_free(handle->decodeBuf);
-    yajl_lex_free(handle->lexer);
-    YA_FREE(&(handle->alloc), handle);
-}
-
-yajl_status
-yajl_parse(yajl_handle hand, const unsigned char * jsonText,
-           unsigned int jsonTextLen)
-{
-    yajl_status status;
-    status = yajl_do_parse(hand, jsonText, jsonTextLen);
-    return status;
-}
-
-yajl_status
-yajl_parse_complete(yajl_handle hand)
-{
-    /* The particular case we want to handle is a trailing number.
-     * Further input consisting of digits could cause our interpretation
-     * of the number to change (buffered "1" but "2" comes in).
-     * A very simple approach to this is to inject whitespace to terminate
-     * any number in the lex buffer.
-     */
-    return yajl_parse(hand, (const unsigned char *)" ", 1);
-}
-
-unsigned char *
-yajl_get_error(yajl_handle hand, int verbose,
-               const unsigned char * jsonText, unsigned int jsonTextLen)
-{
-    return yajl_render_error_string(hand, jsonText, jsonTextLen, verbose);
-}
-
-unsigned int
-yajl_get_bytes_consumed(yajl_handle hand)
-{
-    if (!hand) return 0;
-    else return hand->bytesConsumed;
-}
-
-
-void
-yajl_free_error(yajl_handle hand, unsigned char * str)
-{
-    /* use memory allocation functions if set */
-    YA_FREE(&(hand->alloc), str);
-}
-
-/* XXX: add utility routines to parse from file */

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/ejson/c_src/yajl/yajl_alloc.c
----------------------------------------------------------------------
diff --git a/src/ejson/c_src/yajl/yajl_alloc.c b/src/ejson/c_src/yajl/yajl_alloc.c
deleted file mode 100644
index ccfb7c3..0000000
--- a/src/ejson/c_src/yajl/yajl_alloc.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2010, Lloyd Hilaiel.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * 
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in
- *     the documentation and/or other materials provided with the
- *     distribution.
- * 
- *  3. Neither the name of Lloyd Hilaiel nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */ 
-
-/**
- * \file yajl_alloc.h
- * default memory allocation routines for yajl which use malloc/realloc and
- * free
- */
-
-#include "yajl_alloc.h"
-#include <stdlib.h>
-
-static void * yajl_internal_malloc(void *ctx, unsigned int sz)
-{
-    return malloc(sz);
-}
-
-static void * yajl_internal_realloc(void *ctx, void * previous,
-                                    unsigned int sz)
-{
-    return realloc(previous, sz);
-}
-
-static void yajl_internal_free(void *ctx, void * ptr)
-{
-    free(ptr);
-}
-
-void yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf)
-{
-    yaf->malloc = yajl_internal_malloc;
-    yaf->free = yajl_internal_free;
-    yaf->realloc = yajl_internal_realloc;
-    yaf->ctx = NULL;
-}
-

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/ejson/c_src/yajl/yajl_alloc.h
----------------------------------------------------------------------
diff --git a/src/ejson/c_src/yajl/yajl_alloc.h b/src/ejson/c_src/yajl/yajl_alloc.h
deleted file mode 100644
index cc1e5cf..0000000
--- a/src/ejson/c_src/yajl/yajl_alloc.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2010, Lloyd Hilaiel.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * 
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in
- *     the documentation and/or other materials provided with the
- *     distribution.
- * 
- *  3. Neither the name of Lloyd Hilaiel nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */ 
-
-/**
- * \file yajl_alloc.h
- * default memory allocation routines for yajl which use malloc/realloc and
- * free
- */
-
-#ifndef __YAJL_ALLOC_H__
-#define __YAJL_ALLOC_H__
-
-#include "yajl_common.h"
-
-#define YA_MALLOC(afs, sz) (afs)->malloc((afs)->ctx, (sz))
-#define YA_FREE(afs, ptr) (afs)->free((afs)->ctx, (ptr))
-#define YA_REALLOC(afs, ptr, sz) (afs)->realloc((afs)->ctx, (ptr), (sz))
-
-void yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf);
-
-#endif

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/ejson/c_src/yajl/yajl_buf.c
----------------------------------------------------------------------
diff --git a/src/ejson/c_src/yajl/yajl_buf.c b/src/ejson/c_src/yajl/yajl_buf.c
deleted file mode 100644
index 04e608a..0000000
--- a/src/ejson/c_src/yajl/yajl_buf.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright 2010, Lloyd Hilaiel.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * 
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in
- *     the documentation and/or other materials provided with the
- *     distribution.
- * 
- *  3. Neither the name of Lloyd Hilaiel nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */ 
-
-#include "yajl_buf.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define YAJL_BUF_INIT_SIZE 2048
-
-struct yajl_buf_t {
-    unsigned int len;
-    unsigned int used;
-    unsigned char * data;
-    yajl_alloc_funcs * alloc;
-};
-
-static
-void yajl_buf_ensure_available(yajl_buf buf, unsigned int want)
-{
-    unsigned int need;
-    
-    assert(buf != NULL);
-
-    /* first call */
-    if (buf->data == NULL) {
-        buf->len = YAJL_BUF_INIT_SIZE;
-        buf->data = (unsigned char *) YA_MALLOC(buf->alloc, buf->len);
-        buf->data[0] = 0;
-    }
-
-    need = buf->len;
-
-    while (want >= (need - buf->used)) need <<= 1;
-
-    if (need != buf->len) {
-        buf->data = (unsigned char *) YA_REALLOC(buf->alloc, buf->data, need);
-        buf->len = need;
-    }
-}
-
-yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc)
-{
-    yajl_buf b = YA_MALLOC(alloc, sizeof(struct yajl_buf_t));
-    memset((void *) b, 0, sizeof(struct yajl_buf_t));
-    b->alloc = alloc;
-    return b;
-}
-
-void yajl_buf_free(yajl_buf buf)
-{
-    assert(buf != NULL);
-    if (buf->data) YA_FREE(buf->alloc, buf->data);
-    YA_FREE(buf->alloc, buf);
-}
-
-void yajl_buf_append(yajl_buf buf, const void * data, unsigned int len)
-{
-    yajl_buf_ensure_available(buf, len);
-    if (len > 0) {
-        assert(data != NULL);
-        memcpy(buf->data + buf->used, data, len);
-        buf->used += len;
-        buf->data[buf->used] = 0;
-    }
-}
-
-void yajl_buf_clear(yajl_buf buf)
-{
-    buf->used = 0;
-    if (buf->data) buf->data[buf->used] = 0;
-}
-
-const unsigned char * yajl_buf_data(yajl_buf buf)
-{
-    return buf->data;
-}
-
-unsigned int yajl_buf_len(yajl_buf buf)
-{
-    return buf->used;
-}
-
-void
-yajl_buf_truncate(yajl_buf buf, unsigned int len)
-{
-    assert(len <= buf->used);
-    buf->used = len;
-}

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/ejson/c_src/yajl/yajl_buf.h
----------------------------------------------------------------------
diff --git a/src/ejson/c_src/yajl/yajl_buf.h b/src/ejson/c_src/yajl/yajl_buf.h
deleted file mode 100644
index a6dcbe9..0000000
--- a/src/ejson/c_src/yajl/yajl_buf.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2010, Lloyd Hilaiel.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * 
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in
- *     the documentation and/or other materials provided with the
- *     distribution.
- * 
- *  3. Neither the name of Lloyd Hilaiel nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */ 
-
-#ifndef __YAJL_BUF_H__
-#define __YAJL_BUF_H__
-
-#include "yajl_common.h"
-#include "yajl_alloc.h"
-
-/*
- * Implementation/performance notes.  If this were moved to a header
- * only implementation using #define's where possible we might be 
- * able to sqeeze a little performance out of the guy by killing function
- * call overhead.  YMMV.
- */
-
-/**
- * yajl_buf is a buffer with exponential growth.  the buffer ensures that
- * you are always null padded.
- */
-typedef struct yajl_buf_t * yajl_buf;
-
-/* allocate a new buffer */
-yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc);
-
-/* free the buffer */
-void yajl_buf_free(yajl_buf buf);
-
-/* append a number of bytes to the buffer */
-void yajl_buf_append(yajl_buf buf, const void * data, unsigned int len);
-
-/* empty the buffer */
-void yajl_buf_clear(yajl_buf buf);
-
-/* get a pointer to the beginning of the buffer */
-const unsigned char * yajl_buf_data(yajl_buf buf);
-
-/* get the length of the buffer */
-unsigned int yajl_buf_len(yajl_buf buf);
-
-/* truncate the buffer */
-void yajl_buf_truncate(yajl_buf buf, unsigned int len);
-
-#endif

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/ejson/c_src/yajl/yajl_bytestack.h
----------------------------------------------------------------------
diff --git a/src/ejson/c_src/yajl/yajl_bytestack.h b/src/ejson/c_src/yajl/yajl_bytestack.h
deleted file mode 100644
index 3b49d17..0000000
--- a/src/ejson/c_src/yajl/yajl_bytestack.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2010, Lloyd Hilaiel.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * 
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in
- *     the documentation and/or other materials provided with the
- *     distribution.
- * 
- *  3. Neither the name of Lloyd Hilaiel nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */ 
-
-/*
- * A header only implementation of a simple stack of bytes, used in YAJL
- * to maintain parse state.
- */
-
-#ifndef __YAJL_BYTESTACK_H__
-#define __YAJL_BYTESTACK_H__
-
-#include "yajl_common.h"
-
-#define YAJL_BS_INC 128
-
-typedef struct yajl_bytestack_t
-{
-    unsigned char * stack;
-    unsigned int size;
-    unsigned int used;
-    yajl_alloc_funcs * yaf;
-} yajl_bytestack;
-
-/* initialize a bytestack */
-#define yajl_bs_init(obs, _yaf) {               \
-        (obs).stack = NULL;                     \
-        (obs).size = 0;                         \
-        (obs).used = 0;                         \
-        (obs).yaf = (_yaf);                     \
-    }                                           \
-
-
-/* initialize a bytestack */
-#define yajl_bs_free(obs)                 \
-    if ((obs).stack) (obs).yaf->free((obs).yaf->ctx, (obs).stack);   
-
-#define yajl_bs_current(obs)               \
-    (assert((obs).used > 0), (obs).stack[(obs).used - 1])
-
-#define yajl_bs_push(obs, byte) {                       \
-    if (((obs).size - (obs).used) == 0) {               \
-        (obs).size += YAJL_BS_INC;                      \
-        (obs).stack = (obs).yaf->realloc((obs).yaf->ctx,\
-                                         (void *) (obs).stack, (obs).size);\
-    }                                                   \
-    (obs).stack[((obs).used)++] = (byte);               \
-}
-    
-/* removes the top item of the stack, returns nothing */
-#define yajl_bs_pop(obs) { ((obs).used)--; }
-
-#define yajl_bs_set(obs, byte)                          \
-    (obs).stack[((obs).used) - 1] = (byte);             
-    
-
-#endif

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/ejson/c_src/yajl/yajl_common.h
----------------------------------------------------------------------
diff --git a/src/ejson/c_src/yajl/yajl_common.h b/src/ejson/c_src/yajl/yajl_common.h
deleted file mode 100644
index a227deb..0000000
--- a/src/ejson/c_src/yajl/yajl_common.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2010, Lloyd Hilaiel.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * 
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in
- *     the documentation and/or other materials provided with the
- *     distribution.
- * 
- *  3. Neither the name of Lloyd Hilaiel nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */ 
-
-#ifndef __YAJL_COMMON_H__
-#define __YAJL_COMMON_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif    
-
-#define YAJL_MAX_DEPTH 128
-
-/* msft dll export gunk.  To build a DLL on windows, you
- * must define WIN32, YAJL_SHARED, and YAJL_BUILD.  To use a shared
- * DLL, you must define YAJL_SHARED and WIN32 */
-#if defined(WIN32) && defined(YAJL_SHARED)
-#  ifdef YAJL_BUILD
-#    define YAJL_API __declspec(dllexport)
-#  else
-#    define YAJL_API __declspec(dllimport)
-#  endif
-#else
-#  define YAJL_API
-#endif 
-
-/** pointer to a malloc function, supporting client overriding memory
- *  allocation routines */
-typedef void * (*yajl_malloc_func)(void *ctx, unsigned int sz);
-
-/** pointer to a free function, supporting client overriding memory
- *  allocation routines */
-typedef void (*yajl_free_func)(void *ctx, void * ptr);
-
-/** pointer to a realloc function which can resize an allocation. */
-typedef void * (*yajl_realloc_func)(void *ctx, void * ptr, unsigned int sz);
-
-/** A structure which can be passed to yajl_*_alloc routines to allow the
- *  client to specify memory allocation functions to be used. */
-typedef struct
-{
-    /** pointer to a function that can allocate uninitialized memory */
-    yajl_malloc_func malloc;
-    /** pointer to a function that can resize memory allocations */
-    yajl_realloc_func realloc;
-    /** pointer to a function that can free memory allocated using
-     *  reallocFunction or mallocFunction */
-    yajl_free_func free;
-    /** a context pointer that will be passed to above allocation routines */
-    void * ctx;
-} yajl_alloc_funcs;
-
-#ifdef __cplusplus
-}
-#endif    
-
-#endif

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/ejson/c_src/yajl/yajl_encode.c
----------------------------------------------------------------------
diff --git a/src/ejson/c_src/yajl/yajl_encode.c b/src/ejson/c_src/yajl/yajl_encode.c
deleted file mode 100644
index ad5b1c5..0000000
--- a/src/ejson/c_src/yajl/yajl_encode.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright 2010, Lloyd Hilaiel.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * 
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in
- *     the documentation and/or other materials provided with the
- *     distribution.
- * 
- *  3. Neither the name of Lloyd Hilaiel nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */ 
-
-#include "yajl_encode.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-static void CharToHex(unsigned char c, char * hexBuf)
-{
-    const char * hexchar = "0123456789ABCDEF";
-    hexBuf[0] = hexchar[c >> 4];
-    hexBuf[1] = hexchar[c & 0x0F];
-}
-
-void
-yajl_string_encode(yajl_buf buf, const unsigned char * str,
-                   unsigned int len)
-{
-    yajl_string_encode2((const yajl_print_t) &yajl_buf_append, buf, str, len);
-}
-
-void
-yajl_string_encode2(const yajl_print_t print,
-                    void * ctx,
-                    const unsigned char * str,
-                    unsigned int len)
-{
-    unsigned int beg = 0;
-    unsigned int end = 0;    
-    char hexBuf[7];
-    hexBuf[0] = '\\'; hexBuf[1] = 'u'; hexBuf[2] = '0'; hexBuf[3] = '0';
-    hexBuf[6] = 0;
-
-    while (end < len) {
-        const char * escaped = NULL;
-        switch (str[end]) {
-            case '\r': escaped = "\\r"; break;
-            case '\n': escaped = "\\n"; break;
-            case '\\': escaped = "\\\\"; break;
-            /* case '/': escaped = "\\/"; break; */
-            case '"': escaped = "\\\""; break;
-            case '\f': escaped = "\\f"; break;
-            case '\b': escaped = "\\b"; break;
-            case '\t': escaped = "\\t"; break;
-            default:
-                if ((unsigned char) str[end] < 32) {
-                    CharToHex(str[end], hexBuf + 4);
-                    escaped = hexBuf;
-                }
-                break;
-        }
-        if (escaped != NULL) {
-            print(ctx, (const char *) (str + beg), end - beg);
-            print(ctx, escaped, strlen(escaped));
-            beg = ++end;
-        } else {
-            ++end;
-        }
-    }
-    print(ctx, (const char *) (str + beg), end - beg);
-}
-
-static void hexToDigit(unsigned int * val, const unsigned char * hex)
-{
-    unsigned int i;
-    for (i=0;i<4;i++) {
-        unsigned char c = hex[i];
-        if (c >= 'A') c = (c & ~0x20) - 7;
-        c -= '0';
-        assert(!(c & 0xF0));
-        *val = (*val << 4) | c;
-    }
-}
-
-static void Utf32toUtf8(unsigned int codepoint, char * utf8Buf) 
-{
-    if (codepoint < 0x80) {
-        utf8Buf[0] = (char) codepoint;
-        utf8Buf[1] = 0;
-    } else if (codepoint < 0x0800) {
-        utf8Buf[0] = (char) ((codepoint >> 6) | 0xC0);
-        utf8Buf[1] = (char) ((codepoint & 0x3F) | 0x80);
-        utf8Buf[2] = 0;
-    } else if (codepoint < 0x10000) {
-        utf8Buf[0] = (char) ((codepoint >> 12) | 0xE0);
-        utf8Buf[1] = (char) (((codepoint >> 6) & 0x3F) | 0x80);
-        utf8Buf[2] = (char) ((codepoint & 0x3F) | 0x80);
-        utf8Buf[3] = 0;
-    } else if (codepoint < 0x200000) {
-        utf8Buf[0] =(char)((codepoint >> 18) | 0xF0);
-        utf8Buf[1] =(char)(((codepoint >> 12) & 0x3F) | 0x80);
-        utf8Buf[2] =(char)(((codepoint >> 6) & 0x3F) | 0x80);
-        utf8Buf[3] =(char)((codepoint & 0x3F) | 0x80);
-        utf8Buf[4] = 0;
-    } else {
-        utf8Buf[0] = '?';
-        utf8Buf[1] = 0;
-    }
-}
-
-void yajl_string_decode(yajl_buf buf, const unsigned char * str,
-                        unsigned int len)
-{
-    unsigned int beg = 0;
-    unsigned int end = 0;    
-
-    while (end < len) {
-        if (str[end] == '\\') {
-            char utf8Buf[5];
-            const char * unescaped = "?";
-            yajl_buf_append(buf, str + beg, end - beg);
-            switch (str[++end]) {
-                case 'r': unescaped = "\r"; break;
-                case 'n': unescaped = "\n"; break;
-                case '\\': unescaped = "\\"; break;
-                case '/': unescaped = "/"; break;
-                case '"': unescaped = "\""; break;
-                case 'f': unescaped = "\f"; break;
-                case 'b': unescaped = "\b"; break;
-                case 't': unescaped = "\t"; break;
-                case 'u': {
-                    unsigned int codepoint = 0;
-                    hexToDigit(&codepoint, str + ++end);
-                    end+=3;
-                    /* check if this is a surrogate */
-                    if ((codepoint & 0xFC00) == 0xD800) {
-                        end++;
-                        if (str[end] == '\\' && str[end + 1] == 'u') {
-                            unsigned int surrogate = 0;
-                            hexToDigit(&surrogate, str + end + 2);
-                            codepoint =
-                                (((codepoint & 0x3F) << 10) | 
-                                 ((((codepoint >> 6) & 0xF) + 1) << 16) | 
-                                 (surrogate & 0x3FF));
-                            end += 5;
-                        } else {
-                            unescaped = "?";
-                            break;
-                        }
-                    }
-                    
-                    Utf32toUtf8(codepoint, utf8Buf);
-                    unescaped = utf8Buf;
-                    break;
-                }
-                default:
-                    assert("this should never happen" == NULL);
-            }
-            yajl_buf_append(buf, unescaped, strlen(unescaped));
-            beg = ++end;
-        } else {
-            end++;
-        }
-    }
-    yajl_buf_append(buf, str + beg, end - beg);
-}

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2e6092e4/src/ejson/c_src/yajl/yajl_encode.h
----------------------------------------------------------------------
diff --git a/src/ejson/c_src/yajl/yajl_encode.h b/src/ejson/c_src/yajl/yajl_encode.h
deleted file mode 100644
index 3e3b092..0000000
--- a/src/ejson/c_src/yajl/yajl_encode.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2010, Lloyd Hilaiel.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * 
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in
- *     the documentation and/or other materials provided with the
- *     distribution.
- * 
- *  3. Neither the name of Lloyd Hilaiel nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */ 
-
-#ifndef __YAJL_ENCODE_H__
-#define __YAJL_ENCODE_H__
-
-#include "yajl_buf.h"
-#include "yajl_gen.h"
-
-void yajl_string_encode2(const yajl_print_t printer,
-                         void * ctx,
-                         const unsigned char * str,
-                         unsigned int length);
-
-void yajl_string_encode(yajl_buf buf, const unsigned char * str,
-                        unsigned int length);
-
-void yajl_string_decode(yajl_buf buf, const unsigned char * str,
-                        unsigned int length);
-
-#endif