You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2015/07/25 14:42:30 UTC
[01/19] jiffy commit: updated refs/heads/upstream to f661ee9
Repository: couchdb-jiffy
Updated Branches:
refs/heads/upstream 446e284bd -> f661ee9fd
Add compile option no_native
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/79f1dd17
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/79f1dd17
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/79f1dd17
Branch: refs/heads/upstream
Commit: 79f1dd17259b71e3af2263d602099d8b1be2eba1
Parents: 99867af
Author: Louis-Philippe Gauthier <lp...@gmail.com>
Authored: Tue Jul 15 20:43:33 2014 -0400
Committer: Louis-Philippe Gauthier <lp...@gmail.com>
Committed: Tue Jul 15 20:43:33 2014 -0400
----------------------------------------------------------------------
src/jiffy.erl | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/79f1dd17/src/jiffy.erl
----------------------------------------------------------------------
diff --git a/src/jiffy.erl b/src/jiffy.erl
index 8903831..6f63982 100644
--- a/src/jiffy.erl
+++ b/src/jiffy.erl
@@ -5,6 +5,8 @@
-export([decode/1, decode/2, encode/1, encode/2]).
-define(NOT_LOADED, not_loaded(?LINE)).
+-compile([no_native]).
+
-on_load(init/0).
[03/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Add an option to escape forward slashes
This brings back escaping forward slashes as an option during encoding.
Default is still not to escape.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/1784ca2a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/1784ca2a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/1784ca2a
Branch: refs/heads/upstream
Commit: 1784ca2ab567a3b52b8916565bb41db716c2b9ca
Parents: cd1b263
Author: Jeremie Lasalle Ratelle <je...@gmail.com>
Authored: Wed May 20 18:20:17 2015 -0400
Committer: Jeremie Lasalle Ratelle <je...@gmail.com>
Committed: Wed Jul 15 13:56:51 2015 -0400
----------------------------------------------------------------------
c_src/encoder.c | 17 +++++++++++++++++
c_src/jiffy.c | 1 +
c_src/jiffy.h | 1 +
test/jiffy_04_string_tests.erl | 14 +++++++++++++-
4 files changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/1784ca2a/c_src/encoder.c
----------------------------------------------------------------------
diff --git a/c_src/encoder.c b/c_src/encoder.c
index 471cfcc..59b1b52 100644
--- a/c_src/encoder.c
+++ b/c_src/encoder.c
@@ -34,6 +34,7 @@ typedef struct {
int uescape;
int pretty;
int use_nil;
+ int escape_forward_slashes;
int shiftcnt;
int count;
@@ -77,6 +78,7 @@ enc_new(ErlNifEnv* env)
e->uescape = 0;
e->pretty = 0;
e->use_nil = 0;
+ e->escape_forward_slashes = 0;
e->shiftcnt = 0;
e->count = 0;
@@ -281,6 +283,12 @@ enc_string(Encoder* e, ERL_NIF_TERM val)
esc_extra += 1;
i++;
continue;
+ case '/':
+ if(e->escape_forward_slashes) {
+ esc_extra += 1;
+ i++;
+ continue;
+ }
default:
if(data[i] < 0x20) {
esc_extra += 5;
@@ -348,6 +356,13 @@ enc_string(Encoder* e, ERL_NIF_TERM val)
e->p[e->i++] = 't';
i++;
continue;
+ case '/':
+ if(e->escape_forward_slashes) {
+ e->p[e->i++] = '\\';
+ e->u[e->i++] = data[i];
+ i++;
+ continue;
+ }
default:
if(data[i] < 0x20) {
ulen = unicode_uescape(data[i], &(e->p[e->i]));
@@ -591,6 +606,8 @@ encode_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
e->uescape = 1;
} else if(enif_compare(val, e->atoms->atom_pretty) == 0) {
e->pretty = 1;
+ } else if(enif_compare(val, e->atoms->atom_escape_forward_slashes) == 0) {
+ e->escape_forward_slashes = 1;
} else if(enif_compare(val, e->atoms->atom_use_nil) == 0) {
e->use_nil = 1;
} else if(enif_compare(val, e->atoms->atom_force_utf8) == 0) {
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/1784ca2a/c_src/jiffy.c
----------------------------------------------------------------------
diff --git a/c_src/jiffy.c b/c_src/jiffy.c
index c18a111..9048f5e 100644
--- a/c_src/jiffy.c
+++ b/c_src/jiffy.c
@@ -29,6 +29,7 @@ load(ErlNifEnv* env, void** priv, ERL_NIF_TERM info)
st->atom_nil = make_atom(env, "nil");
st->atom_use_nil = make_atom(env, "use_nil");
st->atom_null_term = make_atom(env, "null_term");
+ st->atom_escape_forward_slashes = make_atom(env, "escape_forward_slashes");
// Markers used in encoding
st->ref_object = make_atom(env, "$object_ref$");
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/1784ca2a/c_src/jiffy.h
----------------------------------------------------------------------
diff --git a/c_src/jiffy.h b/c_src/jiffy.h
index ecad9da..7a2b7d5 100644
--- a/c_src/jiffy.h
+++ b/c_src/jiffy.h
@@ -31,6 +31,7 @@ typedef struct {
ERL_NIF_TERM atom_nil;
ERL_NIF_TERM atom_use_nil;
ERL_NIF_TERM atom_null_term;
+ ERL_NIF_TERM atom_escape_forward_slashes;
ERL_NIF_TERM ref_object;
ERL_NIF_TERM ref_array;
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/1784ca2a/test/jiffy_04_string_tests.erl
----------------------------------------------------------------------
diff --git a/test/jiffy_04_string_tests.erl b/test/jiffy_04_string_tests.erl
index f2136d8..0d642d5 100644
--- a/test/jiffy_04_string_tests.erl
+++ b/test/jiffy_04_string_tests.erl
@@ -23,6 +23,8 @@ string_error_test_() ->
string_utf8_test_() ->
[gen(utf8, Case) || Case <- cases(utf8)].
+string_escaped_slashes_test_() ->
+ [gen(escaped_slashes, Case) || Case <- cases(escaped_slashes)].
gen(ok, {J, E}) ->
gen(ok, {J, E, J});
@@ -50,8 +52,13 @@ gen(utf8, {Case, Fixed}) ->
?_assertThrow({error, {invalid_string, _}}, jiffy:encode(Case)),
?_assertEqual(Fixed2, jiffy:encode(Case, [force_utf8])),
?_assertThrow({error, {_, invalid_string}}, jiffy:decode(Case2))
- ]}.
+ ]};
+gen(escaped_slashes, {J, E}) ->
+ {msg("escaped_slashes - ~s", [J]), [
+ {"Decode", ?_assertEqual(E, dec(J))},
+ {"Encode", ?_assertEqual(J, enc(E, [escape_forward_slashes]))}
+ ]}.
cases(ok) ->
[
@@ -143,4 +150,9 @@ cases(utf8) ->
{<<16#F8, 16#84, 16#80, 16#80, 16#80>>, <<16#EF, 16#BF, 16#BD>>},
{<<16#FC, 16#80, 16#80, 16#80, 16#80, 16#80>>, <<16#EF, 16#BF, 16#BD>>},
{<<16#FC, 16#82, 16#80, 16#80, 16#80, 16#80>>, <<16#EF, 16#BF, 16#BD>>}
+ ];
+
+cases(escaped_slashes) ->
+ [
+ {<<"\"\\/\"">>, <<"/">>}
].
[18/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Remove flaky test case
This test has proved its point and now just exists to randomly fail some
builds depending on race conditions with the garbage collector.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/d95c07cf
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/d95c07cf
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/d95c07cf
Branch: refs/heads/upstream
Commit: d95c07cf53a45a05aceb7ef1d1a4972a2d98cd50
Parents: 32b8939
Author: Paul J. Davis <pa...@gmail.com>
Authored: Fri Jul 17 12:18:21 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Fri Jul 17 12:18:21 2015 -0500
----------------------------------------------------------------------
test/jiffy_14_bignum_memory_leak.erl | 29 -----------------------------
1 file changed, 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/d95c07cf/test/jiffy_14_bignum_memory_leak.erl
----------------------------------------------------------------------
diff --git a/test/jiffy_14_bignum_memory_leak.erl b/test/jiffy_14_bignum_memory_leak.erl
deleted file mode 100644
index df3f4df..0000000
--- a/test/jiffy_14_bignum_memory_leak.erl
+++ /dev/null
@@ -1,29 +0,0 @@
-% This file is part of Jiffy released under the MIT license.
-% See the LICENSE file for more information.
-
--module(jiffy_14_bignum_memory_leak).
-
--include_lib("eunit/include/eunit.hrl").
-
-
-bignum_encoding_leak_test_() ->
- run_gc(),
- Before = erlang:memory(binary),
- encode_bignums(1000000),
- run_gc(),
- After = erlang:memory(binary),
- ?_assert(After - Before < 100000).
-
-
-run_gc() ->
- [erlang:garbage_collect(Pid) || Pid <- erlang:processes()].
-
-
-encode_bignums(N) ->
- {_, Ref} = spawn_monitor(fun() ->
- [jiffy:encode(1072502107250210725021072502) || _ <- lists:seq(1, N)]
- end),
- receive
- {'DOWN', Ref, process, _, _} ->
- ok
- end.
[08/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Squash to new double-conversion
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/43d9516b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/43d9516b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/43d9516b
Branch: refs/heads/upstream
Commit: 43d9516bfcb54919cfd3eb89360448bdcc1c583f
Parents: 3458b79
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Jul 15 15:44:18 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Jul 15 15:44:18 2015 -0500
----------------------------------------------------------------------
rebar.config | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/43d9516b/rebar.config
----------------------------------------------------------------------
diff --git a/rebar.config b/rebar.config
index 3d725b6..76c5806 100644
--- a/rebar.config
+++ b/rebar.config
@@ -8,9 +8,9 @@
{port_env, [
{"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)",
- "CFLAGS", "$CFLAGS -g -Wall -Werror -O3 -fno-strict-aliasing"},
+ "CFLAGS", "$CFLAGS -Ic_src/ -g -Wall -Werror -O3 -fno-strict-aliasing"},
{"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)",
- "CXXFLAGS", "$CXXFLAGS -g -Wall -Werror -O3"},
+ "CXXFLAGS", "$CXXFLAGS -Ic_src/ -g -Wall -Werror -O3"},
{"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)",
"LDFLAGS", "$LDFLAGS -lstdc++"},
[04/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Merge pull request #93 from ratelle/master
Add replace_undefined and escape_forward_slashes
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/b403e4ab
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/b403e4ab
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/b403e4ab
Branch: refs/heads/upstream
Commit: b403e4ab5b8f64ee1b62a9e23453e3ad522d6ba2
Parents: 446e284 1784ca2
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Jul 15 15:18:30 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Jul 15 15:18:30 2015 -0500
----------------------------------------------------------------------
c_src/decoder.c | 10 ++++++----
c_src/encoder.c | 17 +++++++++++++++++
c_src/jiffy.c | 2 ++
c_src/jiffy.h | 3 +++
c_src/util.c | 28 ++++++++++++++++++++++++++++
test/jiffy_02_literal_tests.erl | 11 +++++++++++
test/jiffy_04_string_tests.erl | 14 +++++++++++++-
7 files changed, 80 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
[19/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Add latest Erlang VMs to the test matrix
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/f661ee9f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/f661ee9f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/f661ee9f
Branch: refs/heads/upstream
Commit: f661ee9fd80e5b6b03e9dfbb17d1c72fb6cfdba9
Parents: d95c07c
Author: Paul J. Davis <pa...@gmail.com>
Authored: Fri Jul 17 12:31:11 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Fri Jul 17 12:31:11 2015 -0500
----------------------------------------------------------------------
.travis.yml | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/f661ee9f/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index bab69d6..2865a8a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,6 +2,9 @@ language: erlang
notifications:
email: paul.joseph.davis@gmail.com
otp_release:
+ - 17.5
+ - 17.4
+ - 17.3
- 17.1
- 17.0
- R16B03-1
[05/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Fix typo in README.md
Thanks to @dvliman and @kxepal for noticing.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/a1418434
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/a1418434
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/a1418434
Branch: refs/heads/upstream
Commit: a1418434b275183aae3bb4e853c44c8e91b7b0a6
Parents: b403e4a
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Jul 15 15:19:29 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Jul 15 15:20:53 2015 -0500
----------------------------------------------------------------------
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/a1418434/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 13bc42e..1e95bc0 100644
--- a/README.md
+++ b/README.md
@@ -91,7 +91,7 @@ the `return_maps` option to `jiffy:decode/2`.
Improvements over EEP0018
-------------------------
-Jiffy should be in all ways an improvemnt over EEP0018. It no longer
+Jiffy should be in all ways an improvement over EEP0018. It no longer
imposes limits on the nesting depth. It is capable of encoding and
decoding large numbers and it does quite a bit more validation of UTF-8 in strings.
[13/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Add new return_trailer option
Previously Jiffy would throw an error about trailing data if there is
any non-whitespace character encounter after the first term had been
decoded.
This patch adds a decoder option `return_trailer` that will instead
return a sub-binary starting at the first non-whitespace character. This
allows users to be able to decode multiple terms from a single iodata()
term.
Thanks to @vlm for the original patch.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/6d2278e9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/6d2278e9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/6d2278e9
Branch: refs/heads/upstream
Commit: 6d2278e90694bb484845ad149d484d0a3cae10ec
Parents: 238c653
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Jul 15 16:18:13 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Jul 15 18:40:27 2015 -0500
----------------------------------------------------------------------
README.md | 4 ++++
c_src/decoder.c | 18 ++++++++++++++++--
c_src/jiffy.c | 2 ++
c_src/jiffy.h | 2 ++
src/jiffy.erl | 8 ++++++--
test/jiffy_11_proper_tests.erl | 21 +++++++++++++++++++++
test/jiffy_15_return_trailer_tests.erl | 19 +++++++++++++++++++
7 files changed, 70 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/6d2278e9/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 7f51ce1..f354ecf 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,10 @@ The options for decode are:
instead of `null`.
* `use_nil` - Returns the atom `nil` instead of `null` when decoding
JSON. This is a short hand for `{null_term, nil}`.
+* `return_trailer` - If any non-whitespace is found after the first
+ JSON term is decoded the return value of decode/2 becomes
+ `{has_trailer, FirstTerm, RestData::iodata()}`. This is useful to
+ decode multiple terms in a single binary.
`jiffy:encode/1,2`
------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/6d2278e9/c_src/decoder.c
----------------------------------------------------------------------
diff --git a/c_src/decoder.c b/c_src/decoder.c
index f39575a..60b3257 100644
--- a/c_src/decoder.c
+++ b/c_src/decoder.c
@@ -52,6 +52,7 @@ typedef struct {
size_t bytes_per_iter;
int is_partial;
int return_maps;
+ int return_trailer;
ERL_NIF_TERM null_term;
char* p;
@@ -80,6 +81,7 @@ dec_new(ErlNifEnv* env)
d->bytes_per_iter = DEFAULT_BYTES_PER_ITER;
d->is_partial = 0;
d->return_maps = 0;
+ d->return_trailer = 0;
d->null_term = d->atoms->atom_null;
d->p = NULL;
@@ -710,6 +712,8 @@ decode_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
#else
return enif_make_badarg(env);
#endif
+ } else if(enif_compare(val, d->atoms->atom_return_trailer) == 0) {
+ d->return_trailer = 1;
} else if(enif_compare(val, d->atoms->atom_use_nil) == 0) {
d->null_term = d->atoms->atom_nil;
} else if(get_null_term(env, val, &(d->null_term))) {
@@ -733,6 +737,7 @@ decode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
ERL_NIF_TERM objs;
ERL_NIF_TERM curr;
ERL_NIF_TERM val = argv[2];
+ ERL_NIF_TERM trailer;
ERL_NIF_TERM ret;
size_t start;
@@ -1030,8 +1035,7 @@ decode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
d->i++;
break;
default:
- ret = dec_error(d, "invalid_trailing_data");
- goto done;
+ goto decode_done;
}
break;
@@ -1041,6 +1045,16 @@ decode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
}
}
+decode_done:
+
+ if(d->i < bin.size && d->return_trailer) {
+ trailer = enif_make_sub_binary(env, argv[0], d->i, bin.size - d->i);
+ val = enif_make_tuple3(env, d->atoms->atom_has_trailer, val, trailer);
+ } else if(d->i < bin.size) {
+ ret = dec_error(d, "invalid_trailing_data");
+ goto done;
+ }
+
if(dec_curr(d) != st_done) {
ret = dec_error(d, "truncated_json");
} else if(d->is_partial) {
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/6d2278e9/c_src/jiffy.c
----------------------------------------------------------------------
diff --git a/c_src/jiffy.c b/c_src/jiffy.c
index 9048f5e..1ea60a3 100644
--- a/c_src/jiffy.c
+++ b/c_src/jiffy.c
@@ -26,6 +26,8 @@ load(ErlNifEnv* env, void** priv, ERL_NIF_TERM info)
st->atom_iter = make_atom(env, "iter");
st->atom_bytes_per_iter = make_atom(env, "bytes_per_iter");
st->atom_return_maps = make_atom(env, "return_maps");
+ st->atom_return_trailer = make_atom(env, "return_trailer");
+ st->atom_has_trailer = make_atom(env, "has_trailer");
st->atom_nil = make_atom(env, "nil");
st->atom_use_nil = make_atom(env, "use_nil");
st->atom_null_term = make_atom(env, "null_term");
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/6d2278e9/c_src/jiffy.h
----------------------------------------------------------------------
diff --git a/c_src/jiffy.h b/c_src/jiffy.h
index 7a2b7d5..61c7b70 100644
--- a/c_src/jiffy.h
+++ b/c_src/jiffy.h
@@ -28,6 +28,8 @@ typedef struct {
ERL_NIF_TERM atom_iter;
ERL_NIF_TERM atom_bytes_per_iter;
ERL_NIF_TERM atom_return_maps;
+ ERL_NIF_TERM atom_return_trailer;
+ ERL_NIF_TERM atom_has_trailer;
ERL_NIF_TERM atom_nil;
ERL_NIF_TERM atom_use_nil;
ERL_NIF_TERM atom_null_term;
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/6d2278e9/src/jiffy.erl
----------------------------------------------------------------------
diff --git a/src/jiffy.erl b/src/jiffy.erl
index a272cf9..4517acb 100644
--- a/src/jiffy.erl
+++ b/src/jiffy.erl
@@ -23,8 +23,12 @@
-type json_number() :: integer() | float().
-type json_object() :: {[{json_string(),json_value()}]}.
+-type decode_result() :: json_value()
+ | {has_trailer, json_value(), binary()}.
+
-type decode_option() :: return_maps
| use_nil
+ | return_trailer
| {null_term, any()}
| {bytes_per_iter, non_neg_integer()}.
@@ -37,10 +41,10 @@
-type decode_options() :: [decode_option()].
-type encode_options() :: [encode_option()].
--export_type([json_value/0]).
+-export_type([json_value/0, jiffy_decode_result/0]).
--spec decode(iolist() | binary()) -> json_value().
+-spec decode(iolist() | binary()) -> jiffy_decode_result().
decode(Data) ->
decode(Data, []).
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/6d2278e9/test/jiffy_11_proper_tests.erl
----------------------------------------------------------------------
diff --git a/test/jiffy_11_proper_tests.erl b/test/jiffy_11_proper_tests.erl
index 2c254bf..23aa38d 100644
--- a/test/jiffy_11_proper_tests.erl
+++ b/test/jiffy_11_proper_tests.erl
@@ -24,6 +24,7 @@ proper_encode_decode_test_() ->
[
run(prop_enc_dec),
run(prop_enc_dec_pretty),
+ run(prop_dec_trailer),
run(prop_enc_no_crash),
run(prop_dec_no_crash_bin),
run(prop_dec_no_crash_any)
@@ -37,6 +38,26 @@ prop_enc_dec() ->
end
).
+prop_dec_trailer() ->
+ ?FORALL({T1, T2}, {json(), json()},
+ begin
+ B1 = jiffy:encode(T1),
+ B2 = jiffy:encode(T2),
+ Combiners = [
+ <<" ">>,
+ <<"\r\t">>,
+ <<"\n \t">>,
+ <<" ">>
+ ],
+ lists:foreach(fun(Comb) ->
+ Bin = <<B1/binary, Comb/binary, B2/binary>>,
+ {has_trailer, T1, Rest} = jiffy:decode(Bin, [return_trailer]),
+ T2 = jiffy:decode(Rest)
+ end, Combiners),
+ true
+ end
+ ).
+
-ifndef(JIFFY_NO_MAPS).
to_map_ejson({Props}) ->
NewProps = [{K, to_map_ejson(V)} || {K, V} <- Props],
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/6d2278e9/test/jiffy_15_return_trailer_tests.erl
----------------------------------------------------------------------
diff --git a/test/jiffy_15_return_trailer_tests.erl b/test/jiffy_15_return_trailer_tests.erl
new file mode 100644
index 0000000..af80a46
--- /dev/null
+++ b/test/jiffy_15_return_trailer_tests.erl
@@ -0,0 +1,19 @@
+% This file is part of Jiffy released under the MIT license.
+% See the LICENSE file for more information.
+
+-module(jiffy_15_return_trailer_tests).
+
+-include_lib("eunit/include/eunit.hrl").
+
+trailer_test_() ->
+ Opts = [return_trailer],
+ Cases = [
+ {<<"true">>, true},
+ {<<"true;">>, {has_trailer, true, <<";">>}},
+ {<<"true[]">>, {has_trailer, true, <<"[]">>}},
+ {<<"[]{}">>, {has_trailer, [], <<"{}">>}},
+ {<<"1 2 3">>, {has_trailer, 1, <<"2 3">>}}
+ ],
+ {"Test return_trailer", lists:map(fun({Data, Result}) ->
+ ?_assertEqual(Result, jiffy:decode(Data, Opts))
+ end, Cases)}.
\ No newline at end of file
[14/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Fix dialyzer type specs
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/a32a12f8
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/a32a12f8
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/a32a12f8
Branch: refs/heads/upstream
Commit: a32a12f8b5262a975084ccf918390c650b0b4aff
Parents: 454928f
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Jul 15 18:43:06 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Jul 15 18:43:06 2015 -0500
----------------------------------------------------------------------
src/jiffy.erl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/a32a12f8/src/jiffy.erl
----------------------------------------------------------------------
diff --git a/src/jiffy.erl b/src/jiffy.erl
index 9edaa3a..6fc0fa3 100644
--- a/src/jiffy.erl
+++ b/src/jiffy.erl
@@ -23,7 +23,7 @@
-type json_number() :: integer() | float().
-type json_object() :: {[{json_string(),json_value()}]}.
--type decode_result() :: json_value()
+-type jiffy_decode_result() :: json_value()
| {has_trailer, json_value(), binary()}.
-type decode_option() :: return_maps
@@ -37,7 +37,7 @@
| pretty
| force_utf8
| escape_forward_slashes
- | {bytes_per_iter, non_neg_integer()},
+ | {bytes_per_iter, non_neg_integer()}
| {bytes_per_red, non_neg_integer()}.
-type decode_options() :: [decode_option()].
[02/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Add an option to control null value decoding atom
This is pretty much a generalisation of the use_nil option to support an
arbitrary atom.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/cd1b2632
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/cd1b2632
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/cd1b2632
Branch: refs/heads/upstream
Commit: cd1b2632083c3724b246c8e8107845d9903bc578
Parents: 801f9e7
Author: Jeremie Lasalle Ratelle <je...@gmail.com>
Authored: Fri Apr 24 12:35:32 2015 -0400
Committer: Jeremie Lasalle Ratelle <je...@gmail.com>
Committed: Wed Jul 15 13:38:19 2015 -0400
----------------------------------------------------------------------
c_src/decoder.c | 10 ++++++----
c_src/jiffy.c | 1 +
c_src/jiffy.h | 2 ++
c_src/util.c | 28 ++++++++++++++++++++++++++++
test/jiffy_02_literal_tests.erl | 11 +++++++++++
5 files changed, 48 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/cd1b2632/c_src/decoder.c
----------------------------------------------------------------------
diff --git a/c_src/decoder.c b/c_src/decoder.c
index ad3e8d3..f39575a 100644
--- a/c_src/decoder.c
+++ b/c_src/decoder.c
@@ -52,7 +52,7 @@ typedef struct {
size_t bytes_per_iter;
int is_partial;
int return_maps;
- int use_nil;
+ ERL_NIF_TERM null_term;
char* p;
unsigned char* u;
@@ -80,7 +80,7 @@ dec_new(ErlNifEnv* env)
d->bytes_per_iter = DEFAULT_BYTES_PER_ITER;
d->is_partial = 0;
d->return_maps = 0;
- d->use_nil = 0;
+ d->null_term = d->atoms->atom_null;
d->p = NULL;
d->u = NULL;
@@ -711,7 +711,9 @@ decode_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
return enif_make_badarg(env);
#endif
} else if(enif_compare(val, d->atoms->atom_use_nil) == 0) {
- d->use_nil = 1;
+ d->null_term = d->atoms->atom_nil;
+ } else if(get_null_term(env, val, &(d->null_term))) {
+ continue;
} else {
return enif_make_badarg(env);
}
@@ -783,7 +785,7 @@ decode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
ret = dec_error(d, "invalid_literal");
goto done;
}
- val = d->use_nil ? d->atoms->atom_nil : d->atoms->atom_null;
+ val = d->null_term;
dec_pop(d, st_value);
d->i += 4;
break;
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/cd1b2632/c_src/jiffy.c
----------------------------------------------------------------------
diff --git a/c_src/jiffy.c b/c_src/jiffy.c
index 31aa854..c18a111 100644
--- a/c_src/jiffy.c
+++ b/c_src/jiffy.c
@@ -28,6 +28,7 @@ load(ErlNifEnv* env, void** priv, ERL_NIF_TERM info)
st->atom_return_maps = make_atom(env, "return_maps");
st->atom_nil = make_atom(env, "nil");
st->atom_use_nil = make_atom(env, "use_nil");
+ st->atom_null_term = make_atom(env, "null_term");
// Markers used in encoding
st->ref_object = make_atom(env, "$object_ref$");
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/cd1b2632/c_src/jiffy.h
----------------------------------------------------------------------
diff --git a/c_src/jiffy.h b/c_src/jiffy.h
index 6d869a5..ecad9da 100644
--- a/c_src/jiffy.h
+++ b/c_src/jiffy.h
@@ -30,6 +30,7 @@ typedef struct {
ERL_NIF_TERM atom_return_maps;
ERL_NIF_TERM atom_nil;
ERL_NIF_TERM atom_use_nil;
+ ERL_NIF_TERM atom_null_term;
ERL_NIF_TERM ref_object;
ERL_NIF_TERM ref_array;
@@ -44,6 +45,7 @@ ERL_NIF_TERM make_error(jiffy_st* st, ErlNifEnv* env, const char* error);
ERL_NIF_TERM make_obj_error(jiffy_st* st, ErlNifEnv* env, const char* error,
ERL_NIF_TERM obj);
int get_bytes_per_iter(ErlNifEnv* env, ERL_NIF_TERM val, size_t* bpi);
+int get_null_term(ErlNifEnv* env, ERL_NIF_TERM val, ERL_NIF_TERM *null_term);
int should_yield(size_t used, size_t limit);
int consume_timeslice(ErlNifEnv* env, size_t used, size_t limit);
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/cd1b2632/c_src/util.c
----------------------------------------------------------------------
diff --git a/c_src/util.c b/c_src/util.c
index c30a6d7..f05e1e8 100644
--- a/c_src/util.c
+++ b/c_src/util.c
@@ -63,6 +63,34 @@ get_bytes_per_iter(ErlNifEnv* env, ERL_NIF_TERM val, size_t* bpi)
}
int
+get_null_term(ErlNifEnv* env, ERL_NIF_TERM val, ERL_NIF_TERM *null_term)
+{
+ jiffy_st* st = (jiffy_st*) enif_priv_data(env);
+ const ERL_NIF_TERM* tuple;
+ int arity;
+
+ if(!enif_get_tuple(env, val, &arity, &tuple)) {
+ return 0;
+ }
+
+ if(arity != 2) {
+ return 0;
+ }
+
+ if(enif_compare(tuple[0], st->atom_null_term) != 0) {
+ return 0;
+ }
+
+ if(!enif_is_atom(env, tuple[1])) {
+ return 0;
+ }
+
+ *null_term = tuple[1];
+
+ return 1;
+}
+
+int
should_yield(size_t used, size_t limit)
{
if(limit == 0 || used < limit) {
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/cd1b2632/test/jiffy_02_literal_tests.erl
----------------------------------------------------------------------
diff --git a/test/jiffy_02_literal_tests.erl b/test/jiffy_02_literal_tests.erl
index 98b163c..2699199 100644
--- a/test/jiffy_02_literal_tests.erl
+++ b/test/jiffy_02_literal_tests.erl
@@ -31,3 +31,14 @@ nil_test_() ->
{"Decode", ?_assertEqual(nil, jiffy:decode(<<"null">>, [use_nil]))},
{"Encode", ?_assertEqual(<<"null">>, jiffy:encode(nil, [use_nil]))}
]}.
+
+null_term_test_() ->
+ T = [
+ {undefined, [{null_term, undefined}]},
+ {whatever, [{null_term, whatever}]},
+ {undefined, [use_nil, {null_term, undefined}]},
+ {nil, [{null_term, undefined}, use_nil]},
+ {whatever, [{null_term, undefined}, {null_term, whatever}]}
+ ],
+ {"null_term",
+ [?_assertEqual(R, jiffy:decode(<<"null">>, O)) || {R, O} <- T]}.
[10/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Merge pull request #65 from lpgauth/no_native
Add compile option no_native
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/2c394028
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/2c394028
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/2c394028
Branch: refs/heads/upstream
Commit: 2c394028691ad6cd60cf5bd7faa14c645ff27381
Parents: e371ec1 79f1dd1
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Jul 15 15:49:37 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Jul 15 15:49:37 2015 -0500
----------------------------------------------------------------------
src/jiffy.erl | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/2c394028/src/jiffy.erl
----------------------------------------------------------------------
[12/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Revamp yields back to Erlang
In the original PR for `return_trailer` @vlm pointed out that I wasn't
using enif_consume_timeslice correctly. This fixes that by changing out
its called.
Previously we attempted to define the total number of bytes to decode or
encode in a single NIF call and then would consume as much of the
timeslice as we processed. This is wrong because we may start the NIF
call with less than an entire timeslice left.
The new approach is to define the number of bytes to encode or decode
per reduction and then iteratively call enif_consume_timeslice until it
indicates that we should return.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/454928ff
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/454928ff
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/454928ff
Branch: refs/heads/upstream
Commit: 454928ff3435721a5e4bbda5e80df9f3931cb6ff
Parents: 6d2278e
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Jul 15 17:00:42 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Jul 15 18:40:27 2015 -0500
----------------------------------------------------------------------
README.md | 14 +++++++-----
c_src/decoder.c | 19 +++++++++-------
c_src/encoder.c | 22 +++++++++----------
c_src/jiffy.h | 7 +++---
c_src/util.c | 62 ++++++++++++++++++++++++++++++++++------------------
src/jiffy.erl | 6 +++--
6 files changed, 79 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/454928ff/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index f354ecf..2fe68ed 100644
--- a/README.md
+++ b/README.md
@@ -36,9 +36,6 @@ Errors are raised as exceptions.
The options for decode are:
-* `{bytes_per_iter, N}` where N >= 0 - This controls the number of
- bytes that Jiffy will process before yielding back to the VM. The
- mechanics of this yield are completely hidden from the end user.
* `return_maps` - Tell Jiffy to return objects using the maps data type
on VMs that support it. This raises an error on VMs that don't support
maps.
@@ -51,6 +48,12 @@ The options for decode are:
JSON term is decoded the return value of decode/2 becomes
`{has_trailer, FirstTerm, RestData::iodata()}`. This is useful to
decode multiple terms in a single binary.
+* `{bytes_per_red, N}` where N >= 0 - This controls the number of
+ bytes that Jiffy will process as an equivalent to a reduction. Each
+ 20 reductions we consume 1% of our allocated time slice for the current
+ process. When the Erlang VM indicates we need to return from the NIF.
+* `{bytes_per_iter, N}` where N >= 0 - Backwards compatible option
+ that is converted into the `bytes_per_red` value.
`jiffy:encode/1,2`
------------------
@@ -68,11 +71,10 @@ The options for encode are:
* `force_utf8` - Force strings to encode as UTF-8 by fixing broken
surrogate pairs and/or using the replacement character to remove
broken UTF-8 sequences in data.
-* `{bytes_per_iter, N}` where N >= 0 - This controls the number of
- bytes that Jiffy will generate before yielding back to the VM. The
- mechanics of this yield are completely hidden from the end user.
* `escape_forward_slashes` - Escapes the `/` character which can be
useful when encoding URLs in some cases.
+* `{bytes_per_red, N}` - Refer to the decode options
+* `{bytes_per_iter, N}` - Refer to the decode options
Data Format
-----------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/454928ff/c_src/decoder.c
----------------------------------------------------------------------
diff --git a/c_src/decoder.c b/c_src/decoder.c
index 60b3257..12debb6 100644
--- a/c_src/decoder.c
+++ b/c_src/decoder.c
@@ -49,7 +49,7 @@ typedef struct {
ERL_NIF_TERM arg;
ErlNifBinary bin;
- size_t bytes_per_iter;
+ size_t bytes_per_red;
int is_partial;
int return_maps;
int return_trailer;
@@ -78,7 +78,7 @@ dec_new(ErlNifEnv* env)
d->atoms = st;
- d->bytes_per_iter = DEFAULT_BYTES_PER_ITER;
+ d->bytes_per_red = DEFAULT_BYTES_PER_REDUCTION;
d->is_partial = 0;
d->return_maps = 0;
d->return_trailer = 0;
@@ -704,7 +704,9 @@ decode_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
}
while(enif_get_list_cell(env, opts, &val, &opts)) {
- if(get_bytes_per_iter(env, val, &(d->bytes_per_iter))) {
+ if(get_bytes_per_iter(env, val, &(d->bytes_per_red))) {
+ continue;
+ } else if(get_bytes_per_red(env, val, &(d->bytes_per_red))) {
continue;
} else if(enif_compare(val, d->atoms->atom_return_maps) == 0) {
#if MAP_TYPE_PRESENT
@@ -739,7 +741,7 @@ decode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
ERL_NIF_TERM val = argv[2];
ERL_NIF_TERM trailer;
ERL_NIF_TERM ret;
- size_t start;
+ size_t bytes_read = 0;
if(argc != 5) {
return enif_make_badarg(env);
@@ -758,11 +760,10 @@ decode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
curr = argv[4];
//fprintf(stderr, "Parsing:\r\n");
- start = d->i;
while(d->i < bin.size) {
//fprintf(stderr, "state: %d\r\n", dec_curr(d));
- if(should_yield(d->i - start, d->bytes_per_iter)) {
- consume_timeslice(env, d->i - start, d->bytes_per_iter);
+
+ if(should_yield(env, &bytes_read, d->bytes_per_red)) {
return enif_make_tuple5(
env,
st->atom_iter,
@@ -772,6 +773,9 @@ decode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
curr
);
}
+
+ bytes_read += 1;
+
switch(dec_curr(d)) {
case st_value:
switch(d->p[d->i]) {
@@ -1064,6 +1068,5 @@ decode_done:
}
done:
- consume_timeslice(env, d->i - start, d->bytes_per_iter);
return ret;
}
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/454928ff/c_src/encoder.c
----------------------------------------------------------------------
diff --git a/c_src/encoder.c b/c_src/encoder.c
index 59b1b52..4a96048 100644
--- a/c_src/encoder.c
+++ b/c_src/encoder.c
@@ -29,7 +29,7 @@ typedef struct {
ErlNifEnv* env;
jiffy_st* atoms;
- size_t bytes_per_iter;
+ size_t bytes_per_red;
int uescape;
int pretty;
@@ -74,7 +74,7 @@ enc_new(ErlNifEnv* env)
Encoder* e = enif_alloc_resource(st->res_enc, sizeof(Encoder));
e->atoms = st;
- e->bytes_per_iter = DEFAULT_BYTES_PER_ITER;
+ e->bytes_per_red = DEFAULT_BYTES_PER_REDUCTION;
e->uescape = 0;
e->pretty = 0;
e->use_nil = 0;
@@ -200,7 +200,7 @@ enc_unknown(Encoder* e, ERL_NIF_TERM value)
e->iolist = enif_make_list_cell(e->env, value, e->iolist);
e->iolen++;
-
+
// Track the total number of bytes produced before
// splitting our IO buffer. We add 16 to this value
// as a rough estimate of the number of bytes that
@@ -221,7 +221,7 @@ enc_unknown(Encoder* e, ERL_NIF_TERM value)
e->p = (char*) e->curr->data;
e->u = (unsigned char*) e->curr->data;
- e->i = 0;
+ e->i = 0;
}
return 1;
@@ -612,7 +612,9 @@ encode_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
e->use_nil = 1;
} else if(enif_compare(val, e->atoms->atom_force_utf8) == 0) {
// Ignore, handled in Erlang
- } else if(get_bytes_per_iter(env, val, &(e->bytes_per_iter))) {
+ } else if(get_bytes_per_iter(env, val, &(e->bytes_per_red))) {
+ continue;
+ } else if(get_bytes_per_red(env, val, &(e->bytes_per_red))) {
continue;
} else {
return enif_make_badarg(env);
@@ -639,7 +641,7 @@ encode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
double dval;
size_t start;
- size_t processed;
+ size_t bytes_written = 0;
if(argc != 3) {
return enif_make_badarg(env);
@@ -662,9 +664,9 @@ encode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
while(!enif_is_empty_list(env, stack)) {
- processed = (e->iosize + e->i) - start;
- if(should_yield(processed, e->bytes_per_iter)) {
- consume_timeslice(env, processed, e->bytes_per_iter);
+ bytes_written += (e->iosize + e->i) - start;
+
+ if(should_yield(env, &bytes_written, e->bytes_per_red)) {
return enif_make_tuple4(
env,
st->atom_iter,
@@ -870,8 +872,6 @@ encode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
}
done:
- processed = (e->iosize + e->i) - start;
- consume_timeslice(env, processed, e->bytes_per_iter);
return ret;
}
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/454928ff/c_src/jiffy.h
----------------------------------------------------------------------
diff --git a/c_src/jiffy.h b/c_src/jiffy.h
index 61c7b70..abe5154 100644
--- a/c_src/jiffy.h
+++ b/c_src/jiffy.h
@@ -6,7 +6,8 @@
#include "erl_nif.h"
-#define DEFAULT_BYTES_PER_ITER 2048
+#define DEFAULT_BYTES_PER_REDUCTION 20
+#define DEFAULT_ERLANG_REDUCTION_COUNT 2000
#define MAP_TYPE_PRESENT \
((ERL_NIF_MAJOR_VERSION == 2 && ERL_NIF_MINOR_VERSION >= 6) \
@@ -48,9 +49,9 @@ ERL_NIF_TERM make_error(jiffy_st* st, ErlNifEnv* env, const char* error);
ERL_NIF_TERM make_obj_error(jiffy_st* st, ErlNifEnv* env, const char* error,
ERL_NIF_TERM obj);
int get_bytes_per_iter(ErlNifEnv* env, ERL_NIF_TERM val, size_t* bpi);
+int get_bytes_per_red(ErlNifEnv* env, ERL_NIF_TERM val, size_t* bpr);
int get_null_term(ErlNifEnv* env, ERL_NIF_TERM val, ERL_NIF_TERM *null_term);
-int should_yield(size_t used, size_t limit);
-int consume_timeslice(ErlNifEnv* env, size_t used, size_t limit);
+int should_yield(ErlNifEnv* env, size_t* used, size_t bytes_per_red);
ERL_NIF_TERM decode_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM decode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/454928ff/c_src/util.c
----------------------------------------------------------------------
diff --git a/c_src/util.c b/c_src/util.c
index f05e1e8..7d8ac74 100644
--- a/c_src/util.c
+++ b/c_src/util.c
@@ -2,6 +2,7 @@
// See the LICENSE file for more information.
#include "jiffy.h"
+#include <stdio.h>
ERL_NIF_TERM
make_atom(ErlNifEnv* env, const char* name)
@@ -57,6 +58,36 @@ get_bytes_per_iter(ErlNifEnv* env, ERL_NIF_TERM val, size_t* bpi)
return 0;
}
+ // Calculate the number of bytes per reduction
+ *bpi = (size_t) (bytes / DEFAULT_ERLANG_REDUCTION_COUNT);
+
+ return 1;
+}
+
+int
+get_bytes_per_red(ErlNifEnv* env, ERL_NIF_TERM val, size_t* bpi)
+{
+ jiffy_st* st = (jiffy_st*) enif_priv_data(env);
+ const ERL_NIF_TERM* tuple;
+ int arity;
+ unsigned int bytes;
+
+ if(!enif_get_tuple(env, val, &arity, &tuple)) {
+ return 0;
+ }
+
+ if(arity != 2) {
+ return 0;
+ }
+
+ if(enif_compare(tuple[0], st->atom_bytes_per_iter) != 0) {
+ return 0;
+ }
+
+ if(!enif_get_uint(env, tuple[1], &bytes)) {
+ return 0;
+ }
+
*bpi = (size_t) bytes;
return 1;
@@ -91,31 +122,20 @@ get_null_term(ErlNifEnv* env, ERL_NIF_TERM val, ERL_NIF_TERM *null_term)
}
int
-should_yield(size_t used, size_t limit)
-{
- if(limit == 0 || used < limit) {
- return 0;
- }
-
- return 1;
-}
-
-int
-consume_timeslice(ErlNifEnv* env, size_t used, size_t limit)
+should_yield(ErlNifEnv* env, size_t* used, size_t bytes_per_red)
{
#if(ERL_NIF_MAJOR_VERSION >= 2 && ERL_NIF_MINOR_VERSION >= 4)
- double u = (double) used;
- double l = (double) limit;
- int perc = (int) (100.0 * (u / l));
-
- if(perc < 1) {
- perc = 1;
- } else if(perc > 100) {
- perc = 100;
+
+ if(((*used) / bytes_per_red) >= 20) {
+ *used = 0;
+ return enif_consume_timeslice(env, 1);
}
- return enif_consume_timeslice(env, perc);
-#else
return 0;
+
+#else
+
+ return ((*used) / bytes_per_red) >= DEFAULT_ERLANG_REDUCTION_COUNT;
+
#endif
}
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/454928ff/src/jiffy.erl
----------------------------------------------------------------------
diff --git a/src/jiffy.erl b/src/jiffy.erl
index 4517acb..9edaa3a 100644
--- a/src/jiffy.erl
+++ b/src/jiffy.erl
@@ -30,13 +30,15 @@
| use_nil
| return_trailer
| {null_term, any()}
- | {bytes_per_iter, non_neg_integer()}.
+ | {bytes_per_iter, non_neg_integer()}
+ | {bytes_per_red, non_neg_integer()}.
-type encode_option() :: uescape
| pretty
| force_utf8
| escape_forward_slashes
- | {bytes_per_iter, non_neg_integer()}.
+ | {bytes_per_iter, non_neg_integer()},
+ | {bytes_per_red, non_neg_integer()}.
-type decode_options() :: [decode_option()].
-type encode_options() :: [encode_option()].
[16/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Add map typespec for dialyzer
This obviously only exists on VMs that support it.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/e132b633
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/e132b633
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/e132b633
Branch: refs/heads/upstream
Commit: e132b633f586281cfce7d4f1e71a41c96555e963
Parents: f284a1b
Author: Paul J. Davis <pa...@gmail.com>
Authored: Fri Jul 17 11:59:50 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Fri Jul 17 11:59:50 2015 -0500
----------------------------------------------------------------------
src/jiffy.erl | 4 ++++
1 file changed, 4 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/e132b633/src/jiffy.erl
----------------------------------------------------------------------
diff --git a/src/jiffy.erl b/src/jiffy.erl
index c987997..4ee2a9e 100644
--- a/src/jiffy.erl
+++ b/src/jiffy.erl
@@ -23,6 +23,10 @@
-type json_number() :: integer() | float().
-type json_object() :: {[{json_string(),json_value()}]}.
+-ifndef(JIFFY_NO_MAPS).
+-type #{json_string() => json_value()}.
+-endif.
+
-type jiffy_decode_result() :: json_value()
| {has_trailer, json_value(), binary()}.
[09/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Add Dialyzer types and specs
Thanks to @joedevivo for the contribution.
Fixes #85
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/e371ec10
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/e371ec10
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/e371ec10
Branch: refs/heads/upstream
Commit: e371ec1075266240ec88a744cda036e8fddefd1c
Parents: 43d9516
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Jul 15 15:45:23 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Jul 15 15:45:23 2015 -0500
----------------------------------------------------------------------
src/jiffy.erl | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/e371ec10/src/jiffy.erl
----------------------------------------------------------------------
diff --git a/src/jiffy.erl b/src/jiffy.erl
index 23a0c9d..39c3aeb 100644
--- a/src/jiffy.erl
+++ b/src/jiffy.erl
@@ -8,10 +8,42 @@
-on_load(init/0).
+-type json_value() :: null
+ | true
+ | false
+ | json_string()
+ | json_number()
+ | json_object()
+ | json_array().
+
+-type json_array() :: [json_value()].
+-type json_string() :: binary().
+-type json_number() :: integer() | float().
+-type json_object() :: {[{json_string(),json_value()}]}.
+
+-type decode_option() :: return_maps
+ | use_nil
+ | {null_term, any()}
+ | {bytes_per_iter, non_neg_integer()}.
+
+-type encode_option() :: uescape
+ | pretty
+ | force_utf8
+ | escape_forward_slashes
+ | {bytes_per_iter, non_neg_integer()}.
+
+-type decode_options() :: [decode_option()].
+-type encode_options() :: [encode_option()].
+
+-export_type([json_value/0]).
+
+
+-spec decode(iolist() | binary()) -> json_value().
decode(Data) ->
decode(Data, []).
+-spec decode(iolist() | binary(), decode_options()) -> json_value().
decode(Data, Opts) when is_binary(Data), is_list(Opts) ->
case nif_decode_init(Data, Opts) of
{error, _} = Error ->
@@ -27,10 +59,12 @@ decode(Data, Opts) when is_list(Data) ->
decode(iolist_to_binary(Data), Opts).
+-spec encode(json_value()) -> iolist().
encode(Data) ->
encode(Data, []).
+-spec encode(json_value(), encode_options()) -> iolist().
encode(Data, Options) ->
ForceUTF8 = lists:member(force_utf8, Options),
case nif_encode_init(Data, Options) of
[11/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Ignore test XML files
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/238c653d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/238c653d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/238c653d
Branch: refs/heads/upstream
Commit: 238c653ded399076a7f65ee3414996cd6ca66986
Parents: 2c39402
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Jul 15 17:53:57 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Jul 15 17:57:56 2015 -0500
----------------------------------------------------------------------
.gitignore | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/238c653d/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 6666f22..b7aeb08 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@
.eunit
deps
erln8.config
+TEST-*.xml
[15/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Strings can be atoms or binaries
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/f284a1b2
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/f284a1b2
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/f284a1b2
Branch: refs/heads/upstream
Commit: f284a1b2b0799441665209a86ce14c1f0921d6ca
Parents: a32a12f
Author: Paul J. Davis <pa...@gmail.com>
Authored: Fri Jul 17 11:59:39 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Fri Jul 17 11:59:39 2015 -0500
----------------------------------------------------------------------
src/jiffy.erl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/f284a1b2/src/jiffy.erl
----------------------------------------------------------------------
diff --git a/src/jiffy.erl b/src/jiffy.erl
index 6fc0fa3..c987997 100644
--- a/src/jiffy.erl
+++ b/src/jiffy.erl
@@ -19,7 +19,7 @@
| json_array().
-type json_array() :: [json_value()].
--type json_string() :: binary().
+-type json_string() :: atom() | binary().
-type json_number() :: integer() | float().
-type json_object() :: {[{json_string(),json_value()}]}.
[17/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Fix map type spec
I was being lazy and relying on Travis. This fixes up the map spec for
newer VMs.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/32b89393
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/32b89393
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/32b89393
Branch: refs/heads/upstream
Commit: 32b89393d3d5cde1f9e34828671d8a2fe43a12a2
Parents: e132b63
Author: Paul J. Davis <pa...@gmail.com>
Authored: Fri Jul 17 12:16:48 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Fri Jul 17 12:16:48 2015 -0500
----------------------------------------------------------------------
src/jiffy.erl | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/32b89393/src/jiffy.erl
----------------------------------------------------------------------
diff --git a/src/jiffy.erl b/src/jiffy.erl
index 4ee2a9e..4c9577f 100644
--- a/src/jiffy.erl
+++ b/src/jiffy.erl
@@ -21,10 +21,16 @@
-type json_array() :: [json_value()].
-type json_string() :: atom() | binary().
-type json_number() :: integer() | float().
+
+-ifdef(JIFFY_NO_MAPS).
+
-type json_object() :: {[{json_string(),json_value()}]}.
--ifndef(JIFFY_NO_MAPS).
--type #{json_string() => json_value()}.
+-else.
+
+-type json_object() :: {[{json_string(),json_value()}]}
+ | #{json_string() => json_value()}.
+
-endif.
-type jiffy_decode_result() :: json_value()
[07/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Document new encoding and decoding options
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/3458b79c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/3458b79c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/3458b79c
Branch: refs/heads/upstream
Commit: 3458b79cac9fa612cd004bbcc4e46ca67463c08b
Parents: 5d6b265
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Jul 15 15:35:51 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Jul 15 15:35:51 2015 -0500
----------------------------------------------------------------------
README.md | 7 +++++++
1 file changed, 7 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/3458b79c/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 1e95bc0..7f51ce1 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,11 @@ The options for decode are:
* `return_maps` - Tell Jiffy to return objects using the maps data type
on VMs that support it. This raises an error on VMs that don't support
maps.
+* `{null_term, Term}` - Returns the specified `Term` instead of `null`
+ when decoding JSON. This is for people that wish to use `undefined`
+ instead of `null`.
+* `use_nil` - Returns the atom `nil` instead of `null` when decoding
+ JSON. This is a short hand for `{null_term, nil}`.
`jiffy:encode/1,2`
------------------
@@ -62,6 +67,8 @@ The options for encode are:
* `{bytes_per_iter, N}` where N >= 0 - This controls the number of
bytes that Jiffy will generate before yielding back to the VM. The
mechanics of this yield are completely hidden from the end user.
+* `escape_forward_slashes` - Escapes the `/` character which can be
+ useful when encoding URLs in some cases.
Data Format
-----------
[06/19] jiffy commit: updated refs/heads/upstream to f661ee9
Posted by kx...@apache.org.
Update double-conversion to latest master
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/5d6b2651
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/5d6b2651
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/5d6b2651
Branch: refs/heads/upstream
Commit: 5d6b2651c9ebdccf04ab99083cbf24919ebf25b9
Parents: a141843
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Jul 15 15:27:04 2015 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Jul 15 15:27:04 2015 -0500
----------------------------------------------------------------------
c_src/double-conversion/AUTHORS | 2 +
c_src/double-conversion/DOWNLOADED | 3 -
c_src/double-conversion/README | 45 ++++-
c_src/double-conversion/VERSION | 2 +
c_src/double-conversion/bignum-dtoa.cc | 11 +-
c_src/double-conversion/bignum-dtoa.h | 2 +-
c_src/double-conversion/bignum.cc | 30 +--
c_src/double-conversion/bignum.h | 3 +-
c_src/double-conversion/cached-powers.cc | 3 +-
c_src/double-conversion/diy-fp.cc | 4 +-
c_src/double-conversion/diy-fp.h | 24 +--
c_src/double-conversion/double-conversion.cc | 221 +++++++++++++++-------
c_src/double-conversion/double-conversion.h | 35 ++--
c_src/double-conversion/fast-dtoa.cc | 21 +-
c_src/double-conversion/fast-dtoa.h | 2 +-
c_src/double-conversion/fixed-dtoa.cc | 12 +-
c_src/double-conversion/fixed-dtoa.h | 2 +-
c_src/double-conversion/ieee.h | 4 +
c_src/double-conversion/strtod.cc | 5 +-
c_src/double-conversion/strtod.h | 2 +-
c_src/double-conversion/utils.h | 43 +++--
21 files changed, 315 insertions(+), 161 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/AUTHORS
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/AUTHORS b/c_src/double-conversion/AUTHORS
index ff2a5f4..88b38ae 100644
--- a/c_src/double-conversion/AUTHORS
+++ b/c_src/double-conversion/AUTHORS
@@ -10,3 +10,5 @@ Mozilla Foundation
Jeff Muizelaar <jm...@mozilla.com>
Mike Hommey <mh...@mozilla.com>
Martin Olsson <mn...@minimum.se>
+Kent Williams <ch...@gmail.com>
+Elan Ruusamäe <gl...@delfi.ee>
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/DOWNLOADED
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/DOWNLOADED b/c_src/double-conversion/DOWNLOADED
deleted file mode 100644
index 64724d8..0000000
--- a/c_src/double-conversion/DOWNLOADED
+++ /dev/null
@@ -1,3 +0,0 @@
-Downloaded: 2013-02-24
-
-https://double-conversion.googlecode.com/files/double-conversion-1.1.1.tar.gz
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/README
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/README b/c_src/double-conversion/README
index f186b42..fc54116 100644
--- a/c_src/double-conversion/README
+++ b/c_src/double-conversion/README
@@ -1,4 +1,4 @@
-http://code.google.com/p/double-conversion
+https://github.com/google/double-conversion/
This project (double-conversion) provides binary-decimal and decimal-binary
routines for IEEE doubles.
@@ -9,3 +9,46 @@ it can be used more easily in other projects.
There is extensive documentation in src/double-conversion.h. Other examples can
be found in test/cctest/test-conversions.cc.
+
+
+Building
+========
+
+This library can be built with scons [0] or cmake [1].
+The checked-in Makefile simply forwards to scons, and provides a
+shortcut to run all tests:
+
+ make
+ make test
+
+Scons
+-----
+
+The easiest way to install this library is to use `scons`. It builds
+the static and shared library, and is set up to install those at the
+correct locations:
+
+ scons install
+
+Use the `DESTDIR` option to change the target directory:
+
+ scons DESTDIR=alternative_directory install
+
+Cmake
+-----
+
+To use cmake run `cmake .` in the root directory. This overwrites the
+existing Makefile.
+
+Use `-DBUILD_SHARED_LIBS=ON` to enable the compilation of shared libraries.
+Note that this disables static libraries. There is currently no way to
+build both libraries at the same time with cmake.
+
+Use `-DBUILD_TESTING=ON` to build the test executable.
+
+ cmake . -DBUILD_TESTING=ON
+ make
+ test/cctest/cctest --list | tr -d '<' | xargs test/cctest/cctest
+
+[0]: http://www.scons.org
+[1]: http://www.cmake.org
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/VERSION
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/VERSION b/c_src/double-conversion/VERSION
new file mode 100644
index 0000000..2adab47
--- /dev/null
+++ b/c_src/double-conversion/VERSION
@@ -0,0 +1,2 @@
+Clone from: https://github.com/google/double-conversion
+Version: v2.0.1-23-gc3e0c97
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/bignum-dtoa.cc
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/bignum-dtoa.cc b/c_src/double-conversion/bignum-dtoa.cc
index b6c2e85..f1ad7a5 100644
--- a/c_src/double-conversion/bignum-dtoa.cc
+++ b/c_src/double-conversion/bignum-dtoa.cc
@@ -192,13 +192,13 @@ static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
delta_plus = delta_minus;
}
*length = 0;
- while (true) {
+ for (;;) {
uint16_t digit;
digit = numerator->DivideModuloIntBignum(*denominator);
ASSERT(digit <= 9); // digit is a uint16_t and therefore always positive.
// digit = numerator / denominator (integer division).
// numerator = numerator % denominator.
- buffer[(*length)++] = digit + '0';
+ buffer[(*length)++] = static_cast<char>(digit + '0');
// Can we stop already?
// If the remainder of the division is less than the distance to the lower
@@ -282,7 +282,7 @@ static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
// exponent (decimal_point), when rounding upwards.
static void GenerateCountedDigits(int count, int* decimal_point,
Bignum* numerator, Bignum* denominator,
- Vector<char>(buffer), int* length) {
+ Vector<char> buffer, int* length) {
ASSERT(count >= 0);
for (int i = 0; i < count - 1; ++i) {
uint16_t digit;
@@ -290,7 +290,7 @@ static void GenerateCountedDigits(int count, int* decimal_point,
ASSERT(digit <= 9); // digit is a uint16_t and therefore always positive.
// digit = numerator / denominator (integer division).
// numerator = numerator % denominator.
- buffer[i] = digit + '0';
+ buffer[i] = static_cast<char>(digit + '0');
// Prepare for next iteration.
numerator->Times10();
}
@@ -300,7 +300,8 @@ static void GenerateCountedDigits(int count, int* decimal_point,
if (Bignum::PlusCompare(*numerator, *numerator, *denominator) >= 0) {
digit++;
}
- buffer[count - 1] = digit + '0';
+ ASSERT(digit <= 10);
+ buffer[count - 1] = static_cast<char>(digit + '0');
// Correct bad digits (in case we had a sequence of '9's). Propagate the
// carry until we hat a non-'9' or til we reach the first digit.
for (int i = count - 1; i > 0; --i) {
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/bignum-dtoa.h
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/bignum-dtoa.h b/c_src/double-conversion/bignum-dtoa.h
index 34b9619..92455ec 100644
--- a/c_src/double-conversion/bignum-dtoa.h
+++ b/c_src/double-conversion/bignum-dtoa.h
@@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_BIGNUM_DTOA_H_
#define DOUBLE_CONVERSION_BIGNUM_DTOA_H_
-#include "utils.h"
+#include "double-conversion/utils.h"
namespace double_conversion {
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/bignum.cc
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/bignum.cc b/c_src/double-conversion/bignum.cc
index 3c88303..89c0ab2 100644
--- a/c_src/double-conversion/bignum.cc
+++ b/c_src/double-conversion/bignum.cc
@@ -25,8 +25,8 @@
// (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 "bignum.h"
-#include "utils.h"
+#include "double-conversion/bignum.h"
+#include "double-conversion/utils.h"
namespace double_conversion {
@@ -40,6 +40,7 @@ Bignum::Bignum()
template<typename S>
static int BitSize(S value) {
+ (void) value; // Mark variable as used.
return 8 * sizeof(value);
}
@@ -103,7 +104,7 @@ void Bignum::AssignDecimalString(Vector<const char> value) {
const int kMaxUint64DecimalDigits = 19;
Zero();
int length = value.length();
- unsigned int pos = 0;
+ int pos = 0;
// Let's just say that each digit needs 4 bits.
while (length >= kMaxUint64DecimalDigits) {
uint64_t digits = ReadUInt64(value, pos, kMaxUint64DecimalDigits);
@@ -122,9 +123,8 @@ void Bignum::AssignDecimalString(Vector<const char> value) {
static int HexCharValue(char c) {
if ('0' <= c && c <= '9') return c - '0';
if ('a' <= c && c <= 'f') return 10 + c - 'a';
- if ('A' <= c && c <= 'F') return 10 + c - 'A';
- UNREACHABLE();
- return 0; // To make compiler happy.
+ ASSERT('A' <= c && c <= 'F');
+ return 10 + c - 'A';
}
@@ -501,13 +501,14 @@ uint16_t Bignum::DivideModuloIntBignum(const Bignum& other) {
// Start by removing multiples of 'other' until both numbers have the same
// number of digits.
while (BigitLength() > other.BigitLength()) {
- // This naive approach is extremely inefficient if the this divided other
- // might be big. This function is implemented for doubleToString where
+ // This naive approach is extremely inefficient if `this` divided by other
+ // is big. This function is implemented for doubleToString where
// the result should be small (less than 10).
ASSERT(other.bigits_[other.used_digits_ - 1] >= ((1 << kBigitSize) / 16));
+ ASSERT(bigits_[used_digits_ - 1] < 0x10000);
// Remove the multiples of the first digit.
// Example this = 23 and other equals 9. -> Remove 2 multiples.
- result += bigits_[used_digits_ - 1];
+ result += static_cast<uint16_t>(bigits_[used_digits_ - 1]);
SubtractTimes(other, bigits_[used_digits_ - 1]);
}
@@ -523,13 +524,15 @@ uint16_t Bignum::DivideModuloIntBignum(const Bignum& other) {
// Shortcut for easy (and common) case.
int quotient = this_bigit / other_bigit;
bigits_[used_digits_ - 1] = this_bigit - other_bigit * quotient;
- result += quotient;
+ ASSERT(quotient < 0x10000);
+ result += static_cast<uint16_t>(quotient);
Clamp();
return result;
}
int division_estimate = this_bigit / (other_bigit + 1);
- result += division_estimate;
+ ASSERT(division_estimate < 0x10000);
+ result += static_cast<uint16_t>(division_estimate);
SubtractTimes(other, division_estimate);
if (other_bigit * (division_estimate + 1) > this_bigit) {
@@ -560,8 +563,8 @@ static int SizeInHexChars(S number) {
static char HexCharOfValue(int value) {
ASSERT(0 <= value && value <= 16);
- if (value < 10) return value + '0';
- return value - 10 + 'A';
+ if (value < 10) return static_cast<char>(value + '0');
+ return static_cast<char>(value - 10 + 'A');
}
@@ -755,7 +758,6 @@ void Bignum::SubtractTimes(const Bignum& other, int factor) {
Chunk difference = bigits_[i] - borrow;
bigits_[i] = difference & kBigitMask;
borrow = difference >> (kChunkSize - 1);
- ++i;
}
Clamp();
}
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/bignum.h
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/bignum.h b/c_src/double-conversion/bignum.h
index 5ec3544..57e4230 100644
--- a/c_src/double-conversion/bignum.h
+++ b/c_src/double-conversion/bignum.h
@@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_BIGNUM_H_
#define DOUBLE_CONVERSION_BIGNUM_H_
-#include "utils.h"
+#include "double-conversion/utils.h"
namespace double_conversion {
@@ -49,7 +49,6 @@ class Bignum {
void AssignPowerUInt16(uint16_t base, int exponent);
- void AddUInt16(uint16_t operand);
void AddUInt64(uint64_t operand);
void AddBignum(const Bignum& other);
// Precondition: this >= other.
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/cached-powers.cc
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/cached-powers.cc b/c_src/double-conversion/cached-powers.cc
index c676429..6cbc09b 100644
--- a/c_src/double-conversion/cached-powers.cc
+++ b/c_src/double-conversion/cached-powers.cc
@@ -29,7 +29,7 @@
#include <limits.h>
#include <math.h>
-#include "utils.h"
+#include "double-conversion/utils.h"
#include "cached-powers.h"
@@ -152,6 +152,7 @@ void PowersOfTenCache::GetCachedPowerForBinaryExponentRange(
ASSERT(0 <= index && index < kCachedPowersLength);
CachedPower cached_power = kCachedPowers[index];
ASSERT(min_exponent <= cached_power.binary_exponent);
+ (void) max_exponent; // Mark variable as used.
ASSERT(cached_power.binary_exponent <= max_exponent);
*decimal_exponent = cached_power.decimal_exponent;
*power = DiyFp(cached_power.significand, cached_power.binary_exponent);
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/diy-fp.cc
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/diy-fp.cc b/c_src/double-conversion/diy-fp.cc
index ddd1891..60b805e 100644
--- a/c_src/double-conversion/diy-fp.cc
+++ b/c_src/double-conversion/diy-fp.cc
@@ -26,8 +26,8 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include "diy-fp.h"
-#include "utils.h"
+#include "double-conversion/diy-fp.h"
+#include "double-conversion/utils.h"
namespace double_conversion {
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/diy-fp.h
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/diy-fp.h b/c_src/double-conversion/diy-fp.h
index 9dcf8fb..a0c0c15 100644
--- a/c_src/double-conversion/diy-fp.h
+++ b/c_src/double-conversion/diy-fp.h
@@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_DIY_FP_H_
#define DOUBLE_CONVERSION_DIY_FP_H_
-#include "utils.h"
+#include "double-conversion/utils.h"
namespace double_conversion {
@@ -42,7 +42,7 @@ class DiyFp {
static const int kSignificandSize = 64;
DiyFp() : f_(0), e_(0) {}
- DiyFp(uint64_t f, int e) : f_(f), e_(e) {}
+ DiyFp(uint64_t significand, int exponent) : f_(significand), e_(exponent) {}
// this = this - other.
// The exponents of both numbers must be the same and the significand of this
@@ -76,22 +76,22 @@ class DiyFp {
void Normalize() {
ASSERT(f_ != 0);
- uint64_t f = f_;
- int e = e_;
+ uint64_t significand = f_;
+ int exponent = e_;
// This method is mainly called for normalizing boundaries. In general
// boundaries need to be shifted by 10 bits. We thus optimize for this case.
const uint64_t k10MSBits = UINT64_2PART_C(0xFFC00000, 00000000);
- while ((f & k10MSBits) == 0) {
- f <<= 10;
- e -= 10;
+ while ((significand & k10MSBits) == 0) {
+ significand <<= 10;
+ exponent -= 10;
}
- while ((f & kUint64MSB) == 0) {
- f <<= 1;
- e--;
+ while ((significand & kUint64MSB) == 0) {
+ significand <<= 1;
+ exponent--;
}
- f_ = f;
- e_ = e;
+ f_ = significand;
+ e_ = exponent;
}
static DiyFp Normalize(const DiyFp& a) {
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/double-conversion.cc
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/double-conversion.cc b/c_src/double-conversion/double-conversion.cc
index a79fe92..a6fc0de 100644
--- a/c_src/double-conversion/double-conversion.cc
+++ b/c_src/double-conversion/double-conversion.cc
@@ -28,14 +28,14 @@
#include <limits.h>
#include <math.h>
-#include "double-conversion.h"
+#include "double-conversion/double-conversion.h"
-#include "bignum-dtoa.h"
-#include "fast-dtoa.h"
-#include "fixed-dtoa.h"
-#include "ieee.h"
-#include "strtod.h"
-#include "utils.h"
+#include "double-conversion/bignum-dtoa.h"
+#include "double-conversion/fast-dtoa.h"
+#include "double-conversion/fixed-dtoa.h"
+#include "double-conversion/ieee.h"
+#include "double-conversion/strtod.h"
+#include "double-conversion/utils.h"
namespace double_conversion {
@@ -348,7 +348,6 @@ static BignumDtoaMode DtoaToBignumDtoaMode(
case DoubleToStringConverter::PRECISION: return BIGNUM_DTOA_PRECISION;
default:
UNREACHABLE();
- return BIGNUM_DTOA_SHORTEST; // To silence compiler.
}
}
@@ -403,8 +402,8 @@ void DoubleToStringConverter::DoubleToAscii(double v,
vector, length, point);
break;
default:
- UNREACHABLE();
fast_worked = false;
+ UNREACHABLE();
}
if (fast_worked) return;
@@ -417,8 +416,9 @@ void DoubleToStringConverter::DoubleToAscii(double v,
// Consumes the given substring from the iterator.
// Returns false, if the substring does not match.
-static bool ConsumeSubString(const char** current,
- const char* end,
+template <class Iterator>
+static bool ConsumeSubString(Iterator* current,
+ Iterator end,
const char* substring) {
ASSERT(**current == *substring);
for (substring++; *substring != '\0'; substring++) {
@@ -440,10 +440,36 @@ static bool ConsumeSubString(const char** current,
const int kMaxSignificantDigits = 772;
+static const char kWhitespaceTable7[] = { 32, 13, 10, 9, 11, 12 };
+static const int kWhitespaceTable7Length = ARRAY_SIZE(kWhitespaceTable7);
+
+
+static const uc16 kWhitespaceTable16[] = {
+ 160, 8232, 8233, 5760, 6158, 8192, 8193, 8194, 8195,
+ 8196, 8197, 8198, 8199, 8200, 8201, 8202, 8239, 8287, 12288, 65279
+};
+static const int kWhitespaceTable16Length = ARRAY_SIZE(kWhitespaceTable16);
+
+
+static bool isWhitespace(int x) {
+ if (x < 128) {
+ for (int i = 0; i < kWhitespaceTable7Length; i++) {
+ if (kWhitespaceTable7[i] == x) return true;
+ }
+ } else {
+ for (int i = 0; i < kWhitespaceTable16Length; i++) {
+ if (kWhitespaceTable16[i] == x) return true;
+ }
+ }
+ return false;
+}
+
+
// Returns true if a nonspace found and false if the end has reached.
-static inline bool AdvanceToNonspace(const char** current, const char* end) {
+template <class Iterator>
+static inline bool AdvanceToNonspace(Iterator* current, Iterator end) {
while (*current != end) {
- if (**current != ' ') return true;
+ if (!isWhitespace(**current)) return true;
++*current;
}
return false;
@@ -462,26 +488,57 @@ static double SignedZero(bool sign) {
}
+// Returns true if 'c' is a decimal digit that is valid for the given radix.
+//
+// The function is small and could be inlined, but VS2012 emitted a warning
+// because it constant-propagated the radix and concluded that the last
+// condition was always true. By moving it into a separate function the
+// compiler wouldn't warn anymore.
+#if _MSC_VER
+#pragma optimize("",off)
+static bool IsDecimalDigitForRadix(int c, int radix) {
+ return '0' <= c && c <= '9' && (c - '0') < radix;
+}
+#pragma optimize("",on)
+#else
+static bool inline IsDecimalDigitForRadix(int c, int radix) {
+ return '0' <= c && c <= '9' && (c - '0') < radix;
+}
+#endif
+// Returns true if 'c' is a character digit that is valid for the given radix.
+// The 'a_character' should be 'a' or 'A'.
+//
+// The function is small and could be inlined, but VS2012 emitted a warning
+// because it constant-propagated the radix and concluded that the first
+// condition was always false. By moving it into a separate function the
+// compiler wouldn't warn anymore.
+static bool IsCharacterDigitForRadix(int c, int radix, char a_character) {
+ return radix > 10 && c >= a_character && c < a_character + radix - 10;
+}
+
+
// Parsing integers with radix 2, 4, 8, 16, 32. Assumes current != end.
-template <int radix_log_2>
-static double RadixStringToIeee(const char* current,
- const char* end,
+template <int radix_log_2, class Iterator>
+static double RadixStringToIeee(Iterator* current,
+ Iterator end,
bool sign,
bool allow_trailing_junk,
double junk_string_value,
bool read_as_double,
- const char** trailing_pointer) {
- ASSERT(current != end);
+ bool* result_is_junk) {
+ ASSERT(*current != end);
const int kDoubleSize = Double::kSignificandSize;
const int kSingleSize = Single::kSignificandSize;
const int kSignificandSize = read_as_double? kDoubleSize: kSingleSize;
+ *result_is_junk = true;
+
// Skip leading 0s.
- while (*current == '0') {
- ++current;
- if (current == end) {
- *trailing_pointer = end;
+ while (**current == '0') {
+ ++(*current);
+ if (*current == end) {
+ *result_is_junk = false;
return SignedZero(sign);
}
}
@@ -492,14 +549,14 @@ static double RadixStringToIeee(const char* current,
do {
int digit;
- if (*current >= '0' && *current <= '9' && *current < '0' + radix) {
- digit = static_cast<char>(*current) - '0';
- } else if (radix > 10 && *current >= 'a' && *current < 'a' + radix - 10) {
- digit = static_cast<char>(*current) - 'a' + 10;
- } else if (radix > 10 && *current >= 'A' && *current < 'A' + radix - 10) {
- digit = static_cast<char>(*current) - 'A' + 10;
+ if (IsDecimalDigitForRadix(**current, radix)) {
+ digit = static_cast<char>(**current) - '0';
+ } else if (IsCharacterDigitForRadix(**current, radix, 'a')) {
+ digit = static_cast<char>(**current) - 'a' + 10;
+ } else if (IsCharacterDigitForRadix(**current, radix, 'A')) {
+ digit = static_cast<char>(**current) - 'A' + 10;
} else {
- if (allow_trailing_junk || !AdvanceToNonspace(¤t, end)) {
+ if (allow_trailing_junk || !AdvanceToNonspace(current, end)) {
break;
} else {
return junk_string_value;
@@ -523,14 +580,14 @@ static double RadixStringToIeee(const char* current,
exponent = overflow_bits_count;
bool zero_tail = true;
- while (true) {
- ++current;
- if (current == end || !isDigit(*current, radix)) break;
- zero_tail = zero_tail && *current == '0';
+ for (;;) {
+ ++(*current);
+ if (*current == end || !isDigit(**current, radix)) break;
+ zero_tail = zero_tail && **current == '0';
exponent += radix_log_2;
}
- if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) {
+ if (!allow_trailing_junk && AdvanceToNonspace(current, end)) {
return junk_string_value;
}
@@ -552,13 +609,13 @@ static double RadixStringToIeee(const char* current,
}
break;
}
- ++current;
- } while (current != end);
+ ++(*current);
+ } while (*current != end);
ASSERT(number < ((int64_t)1 << kSignificandSize));
ASSERT(static_cast<int64_t>(static_cast<double>(number)) == number);
- *trailing_pointer = current;
+ *result_is_junk = false;
if (exponent == 0) {
if (sign) {
@@ -573,13 +630,14 @@ static double RadixStringToIeee(const char* current,
}
+template <class Iterator>
double StringToDoubleConverter::StringToIeee(
- const char* input,
+ Iterator input,
int length,
- int* processed_characters_count,
- bool read_as_double) {
- const char* current = input;
- const char* end = input + length;
+ bool read_as_double,
+ int* processed_characters_count) const {
+ Iterator current = input;
+ Iterator end = input + length;
*processed_characters_count = 0;
@@ -600,7 +658,7 @@ double StringToDoubleConverter::StringToIeee(
if (allow_leading_spaces || allow_trailing_spaces) {
if (!AdvanceToNonspace(¤t, end)) {
- *processed_characters_count = current - input;
+ *processed_characters_count = static_cast<int>(current - input);
return empty_string_value_;
}
if (!allow_leading_spaces && (input != current)) {
@@ -626,7 +684,7 @@ double StringToDoubleConverter::StringToIeee(
if (*current == '+' || *current == '-') {
sign = (*current == '-');
++current;
- const char* next_non_space = current;
+ Iterator next_non_space = current;
// Skip following spaces (if allowed).
if (!AdvanceToNonspace(&next_non_space, end)) return junk_string_value_;
if (!allow_spaces_after_sign && (current != next_non_space)) {
@@ -649,7 +707,7 @@ double StringToDoubleConverter::StringToIeee(
}
ASSERT(buffer_pos == 0);
- *processed_characters_count = current - input;
+ *processed_characters_count = static_cast<int>(current - input);
return sign ? -Double::Infinity() : Double::Infinity();
}
}
@@ -668,7 +726,7 @@ double StringToDoubleConverter::StringToIeee(
}
ASSERT(buffer_pos == 0);
- *processed_characters_count = current - input;
+ *processed_characters_count = static_cast<int>(current - input);
return sign ? -Double::NaN() : Double::NaN();
}
}
@@ -677,7 +735,7 @@ double StringToDoubleConverter::StringToIeee(
if (*current == '0') {
++current;
if (current == end) {
- *processed_characters_count = current - input;
+ *processed_characters_count = static_cast<int>(current - input);
return SignedZero(sign);
}
@@ -690,17 +748,17 @@ double StringToDoubleConverter::StringToIeee(
return junk_string_value_; // "0x".
}
- const char* tail_pointer = NULL;
- double result = RadixStringToIeee<4>(current,
+ bool result_is_junk;
+ double result = RadixStringToIeee<4>(¤t,
end,
sign,
allow_trailing_junk,
junk_string_value_,
read_as_double,
- &tail_pointer);
- if (tail_pointer != NULL) {
- if (allow_trailing_spaces) AdvanceToNonspace(&tail_pointer, end);
- *processed_characters_count = tail_pointer - input;
+ &result_is_junk);
+ if (!result_is_junk) {
+ if (allow_trailing_spaces) AdvanceToNonspace(¤t, end);
+ *processed_characters_count = static_cast<int>(current - input);
}
return result;
}
@@ -709,7 +767,7 @@ double StringToDoubleConverter::StringToIeee(
while (*current == '0') {
++current;
if (current == end) {
- *processed_characters_count = current - input;
+ *processed_characters_count = static_cast<int>(current - input);
return SignedZero(sign);
}
}
@@ -757,7 +815,7 @@ double StringToDoubleConverter::StringToIeee(
while (*current == '0') {
++current;
if (current == end) {
- *processed_characters_count = current - input;
+ *processed_characters_count = static_cast<int>(current - input);
return SignedZero(sign);
}
exponent--; // Move this 0 into the exponent.
@@ -801,9 +859,9 @@ double StringToDoubleConverter::StringToIeee(
return junk_string_value_;
}
}
- char sign = '+';
+ char exponen_sign = '+';
if (*current == '+' || *current == '-') {
- sign = static_cast<char>(*current);
+ exponen_sign = static_cast<char>(*current);
++current;
if (current == end) {
if (allow_trailing_junk) {
@@ -837,7 +895,7 @@ double StringToDoubleConverter::StringToIeee(
++current;
} while (current != end && *current >= '0' && *current <= '9');
- exponent += (sign == '-' ? -num : num);
+ exponent += (exponen_sign == '-' ? -num : num);
}
if (!(allow_trailing_spaces || allow_trailing_junk) && (current != end)) {
@@ -855,16 +913,17 @@ double StringToDoubleConverter::StringToIeee(
if (octal) {
double result;
- const char* tail_pointer = NULL;
- result = RadixStringToIeee<3>(buffer,
+ bool result_is_junk;
+ char* start = buffer;
+ result = RadixStringToIeee<3>(&start,
buffer + buffer_pos,
sign,
allow_trailing_junk,
junk_string_value_,
read_as_double,
- &tail_pointer);
- ASSERT(tail_pointer != NULL);
- *processed_characters_count = current - input;
+ &result_is_junk);
+ ASSERT(!result_is_junk);
+ *processed_characters_count = static_cast<int>(current - input);
return result;
}
@@ -882,8 +941,42 @@ double StringToDoubleConverter::StringToIeee(
} else {
converted = Strtof(Vector<const char>(buffer, buffer_pos), exponent);
}
- *processed_characters_count = current - input;
+ *processed_characters_count = static_cast<int>(current - input);
return sign? -converted: converted;
}
+
+double StringToDoubleConverter::StringToDouble(
+ const char* buffer,
+ int length,
+ int* processed_characters_count) const {
+ return StringToIeee(buffer, length, true, processed_characters_count);
+}
+
+
+double StringToDoubleConverter::StringToDouble(
+ const uc16* buffer,
+ int length,
+ int* processed_characters_count) const {
+ return StringToIeee(buffer, length, true, processed_characters_count);
+}
+
+
+float StringToDoubleConverter::StringToFloat(
+ const char* buffer,
+ int length,
+ int* processed_characters_count) const {
+ return static_cast<float>(StringToIeee(buffer, length, false,
+ processed_characters_count));
+}
+
+
+float StringToDoubleConverter::StringToFloat(
+ const uc16* buffer,
+ int length,
+ int* processed_characters_count) const {
+ return static_cast<float>(StringToIeee(buffer, length, false,
+ processed_characters_count));
+}
+
} // namespace double_conversion
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/double-conversion.h
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/double-conversion.h b/c_src/double-conversion/double-conversion.h
index f98edae..11fbcb8 100644
--- a/c_src/double-conversion/double-conversion.h
+++ b/c_src/double-conversion/double-conversion.h
@@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
#define DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
-#include "utils.h"
+#include "double-conversion/utils.h"
namespace double_conversion {
@@ -415,9 +415,10 @@ class StringToDoubleConverter {
// junk, too.
// - ALLOW_TRAILING_JUNK: ignore trailing characters that are not part of
// a double literal.
- // - ALLOW_LEADING_SPACES: skip over leading spaces.
- // - ALLOW_TRAILING_SPACES: ignore trailing spaces.
- // - ALLOW_SPACES_AFTER_SIGN: ignore spaces after the sign.
+ // - ALLOW_LEADING_SPACES: skip over leading whitespace, including spaces,
+ // new-lines, and tabs.
+ // - ALLOW_TRAILING_SPACES: ignore trailing whitespace.
+ // - ALLOW_SPACES_AFTER_SIGN: ignore whitespace after the sign.
// Ex: StringToDouble("- 123.2") -> -123.2.
// StringToDouble("+ 123.2") -> 123.2
//
@@ -502,19 +503,24 @@ class StringToDoubleConverter {
// in the 'processed_characters_count'. Trailing junk is never included.
double StringToDouble(const char* buffer,
int length,
- int* processed_characters_count) {
- return StringToIeee(buffer, length, processed_characters_count, true);
- }
+ int* processed_characters_count) const;
+
+ // Same as StringToDouble above but for 16 bit characters.
+ double StringToDouble(const uc16* buffer,
+ int length,
+ int* processed_characters_count) const;
// Same as StringToDouble but reads a float.
// Note that this is not equivalent to static_cast<float>(StringToDouble(...))
// due to potential double-rounding.
float StringToFloat(const char* buffer,
int length,
- int* processed_characters_count) {
- return static_cast<float>(StringToIeee(buffer, length,
- processed_characters_count, false));
- }
+ int* processed_characters_count) const;
+
+ // Same as StringToFloat above but for 16 bit characters.
+ float StringToFloat(const uc16* buffer,
+ int length,
+ int* processed_characters_count) const;
private:
const int flags_;
@@ -523,10 +529,11 @@ class StringToDoubleConverter {
const char* const infinity_symbol_;
const char* const nan_symbol_;
- double StringToIeee(const char* buffer,
+ template <class Iterator>
+ double StringToIeee(Iterator start_pointer,
int length,
- int* processed_characters_count,
- bool read_as_double);
+ bool read_as_double,
+ int* processed_characters_count) const;
DISALLOW_IMPLICIT_CONSTRUCTORS(StringToDoubleConverter);
};
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/fast-dtoa.cc
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/fast-dtoa.cc b/c_src/double-conversion/fast-dtoa.cc
index b2f7b8d..6135038 100644
--- a/c_src/double-conversion/fast-dtoa.cc
+++ b/c_src/double-conversion/fast-dtoa.cc
@@ -248,13 +248,8 @@ static void BiggestPowerTen(uint32_t number,
// Note: kPowersOf10[i] == 10^(i-1).
exponent_plus_one_guess++;
// We don't have any guarantees that 2^number_bits <= number.
- // TODO(floitsch): can we change the 'while' into an 'if'? We definitely see
- // number < (2^number_bits - 1), but I haven't encountered
- // number < (2^number_bits - 2) yet.
- while (number < kSmallPowersOfTen[exponent_plus_one_guess]) {
+ if (number < kSmallPowersOfTen[exponent_plus_one_guess]) {
exponent_plus_one_guess--;
- if (exponent_plus_one_guess <= 0)
- break;
}
*power = kSmallPowersOfTen[exponent_plus_one_guess];
*exponent_plus_one = exponent_plus_one_guess;
@@ -352,7 +347,8 @@ static bool DigitGen(DiyFp low,
// that is smaller than integrals.
while (*kappa > 0) {
int digit = integrals / divisor;
- buffer[*length] = '0' + digit;
+ ASSERT(digit <= 9);
+ buffer[*length] = static_cast<char>('0' + digit);
(*length)++;
integrals %= divisor;
(*kappa)--;
@@ -381,13 +377,14 @@ static bool DigitGen(DiyFp low,
ASSERT(one.e() >= -60);
ASSERT(fractionals < one.f());
ASSERT(UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF) / 10 >= one.f());
- while (true) {
+ for (;;) {
fractionals *= 10;
unit *= 10;
unsafe_interval.set_f(unsafe_interval.f() * 10);
// Integer division by one.
int digit = static_cast<int>(fractionals >> -one.e());
- buffer[*length] = '0' + digit;
+ ASSERT(digit <= 9);
+ buffer[*length] = static_cast<char>('0' + digit);
(*length)++;
fractionals &= one.f() - 1; // Modulo by one.
(*kappa)--;
@@ -461,7 +458,8 @@ static bool DigitGenCounted(DiyFp w,
// that is smaller than 'integrals'.
while (*kappa > 0) {
int digit = integrals / divisor;
- buffer[*length] = '0' + digit;
+ ASSERT(digit <= 9);
+ buffer[*length] = static_cast<char>('0' + digit);
(*length)++;
requested_digits--;
integrals %= divisor;
@@ -494,7 +492,8 @@ static bool DigitGenCounted(DiyFp w,
w_error *= 10;
// Integer division by one.
int digit = static_cast<int>(fractionals >> -one.e());
- buffer[*length] = '0' + digit;
+ ASSERT(digit <= 9);
+ buffer[*length] = static_cast<char>('0' + digit);
(*length)++;
requested_digits--;
fractionals &= one.f() - 1; // Modulo by one.
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/fast-dtoa.h
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/fast-dtoa.h b/c_src/double-conversion/fast-dtoa.h
index 5f1e8ee..259ee3a 100644
--- a/c_src/double-conversion/fast-dtoa.h
+++ b/c_src/double-conversion/fast-dtoa.h
@@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_FAST_DTOA_H_
#define DOUBLE_CONVERSION_FAST_DTOA_H_
-#include "utils.h"
+#include "double-conversion/utils.h"
namespace double_conversion {
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/fixed-dtoa.cc
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/fixed-dtoa.cc b/c_src/double-conversion/fixed-dtoa.cc
index d56b144..aef65fd 100644
--- a/c_src/double-conversion/fixed-dtoa.cc
+++ b/c_src/double-conversion/fixed-dtoa.cc
@@ -133,7 +133,7 @@ static void FillDigits32(uint32_t number, Vector<char> buffer, int* length) {
while (number != 0) {
int digit = number % 10;
number /= 10;
- buffer[(*length) + number_length] = '0' + digit;
+ buffer[(*length) + number_length] = static_cast<char>('0' + digit);
number_length++;
}
// Exchange the digits.
@@ -150,7 +150,7 @@ static void FillDigits32(uint32_t number, Vector<char> buffer, int* length) {
}
-static void FillDigits64FixedLength(uint64_t number, int requested_length,
+static void FillDigits64FixedLength(uint64_t number,
Vector<char> buffer, int* length) {
const uint32_t kTen7 = 10000000;
// For efficiency cut the number into 3 uint32_t parts, and print those.
@@ -253,7 +253,8 @@ static void FillFractionals(uint64_t fractionals, int exponent,
fractionals *= 5;
point--;
int digit = static_cast<int>(fractionals >> point);
- buffer[*length] = '0' + digit;
+ ASSERT(digit <= 9);
+ buffer[*length] = static_cast<char>('0' + digit);
(*length)++;
fractionals -= static_cast<uint64_t>(digit) << point;
}
@@ -274,7 +275,8 @@ static void FillFractionals(uint64_t fractionals, int exponent,
fractionals128.Multiply(5);
point--;
int digit = fractionals128.DivModPowerOf2(point);
- buffer[*length] = '0' + digit;
+ ASSERT(digit <= 9);
+ buffer[*length] = static_cast<char>('0' + digit);
(*length)++;
}
if (fractionals128.BitAt(point - 1) == 1) {
@@ -358,7 +360,7 @@ bool FastFixedDtoa(double v,
remainder = (dividend % divisor) << exponent;
}
FillDigits32(quotient, buffer, length);
- FillDigits64FixedLength(remainder, divisor_power, buffer, length);
+ FillDigits64FixedLength(remainder, buffer, length);
*decimal_point = *length;
} else if (exponent >= 0) {
// 0 <= exponent <= 11
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/fixed-dtoa.h
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/fixed-dtoa.h b/c_src/double-conversion/fixed-dtoa.h
index 3bdd08e..43de94e 100644
--- a/c_src/double-conversion/fixed-dtoa.h
+++ b/c_src/double-conversion/fixed-dtoa.h
@@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_FIXED_DTOA_H_
#define DOUBLE_CONVERSION_FIXED_DTOA_H_
-#include "utils.h"
+#include "double-conversion/utils.h"
namespace double_conversion {
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/ieee.h
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/ieee.h b/c_src/double-conversion/ieee.h
index 839dc47..661141d 100644
--- a/c_src/double-conversion/ieee.h
+++ b/c_src/double-conversion/ieee.h
@@ -256,6 +256,8 @@ class Double {
return (significand & kSignificandMask) |
(biased_exponent << kPhysicalSignificandSize);
}
+
+ DISALLOW_COPY_AND_ASSIGN(Double);
};
class Single {
@@ -391,6 +393,8 @@ class Single {
static const uint32_t kNaN = 0x7FC00000;
const uint32_t d32_;
+
+ DISALLOW_COPY_AND_ASSIGN(Single);
};
} // namespace double_conversion
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/strtod.cc
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/strtod.cc b/c_src/double-conversion/strtod.cc
index 9758989..17abcbb 100644
--- a/c_src/double-conversion/strtod.cc
+++ b/c_src/double-conversion/strtod.cc
@@ -137,6 +137,7 @@ static void TrimAndCut(Vector<const char> buffer, int exponent,
Vector<const char> right_trimmed = TrimTrailingZeros(left_trimmed);
exponent += left_trimmed.length() - right_trimmed.length();
if (right_trimmed.length() > kMaxSignificantDecimalDigits) {
+ (void) space_size; // Mark variable as used.
ASSERT(space_size >= kMaxSignificantDecimalDigits);
CutToMaxSignificantDigits(right_trimmed, exponent,
buffer_copy_space, updated_exponent);
@@ -263,7 +264,6 @@ static DiyFp AdjustmentPowerOfTen(int exponent) {
case 7: return DiyFp(UINT64_2PART_C(0x98968000, 00000000), -40);
default:
UNREACHABLE();
- return DiyFp(0, 0);
}
}
@@ -286,7 +286,7 @@ static bool DiyFpStrtod(Vector<const char> buffer,
const int kDenominator = 1 << kDenominatorLog;
// Move the remaining decimals into the exponent.
exponent += remaining_decimals;
- int error = (remaining_decimals == 0 ? 0 : kDenominator / 2);
+ uint64_t error = (remaining_decimals == 0 ? 0 : kDenominator / 2);
int old_e = input.e();
input.Normalize();
@@ -515,6 +515,7 @@ float Strtof(Vector<const char> buffer, int exponent) {
double double_next2 = Double(double_next).NextDouble();
f4 = static_cast<float>(double_next2);
}
+ (void) f2; // Mark variable as used.
ASSERT(f1 <= f2 && f2 <= f3 && f3 <= f4);
// If the guess doesn't lie near a single-precision boundary we can simply
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/strtod.h
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/strtod.h b/c_src/double-conversion/strtod.h
index ed0293b..00cf8a7 100644
--- a/c_src/double-conversion/strtod.h
+++ b/c_src/double-conversion/strtod.h
@@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_STRTOD_H_
#define DOUBLE_CONVERSION_STRTOD_H_
-#include "utils.h"
+#include "double-conversion/utils.h"
namespace double_conversion {
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/5d6b2651/c_src/double-conversion/utils.h
----------------------------------------------------------------------
diff --git a/c_src/double-conversion/utils.h b/c_src/double-conversion/utils.h
index 9ebb9ee..ce41e62 100644
--- a/c_src/double-conversion/utils.h
+++ b/c_src/double-conversion/utils.h
@@ -33,7 +33,8 @@
#include <assert.h>
#ifndef ASSERT
-#define ASSERT(condition) (assert(condition))
+#define ASSERT(condition) \
+ assert(condition);
#endif
#ifndef UNIMPLEMENTED
#define UNIMPLEMENTED() (abort())
@@ -55,11 +56,16 @@
#if defined(_M_X64) || defined(__x86_64__) || \
defined(__ARMEL__) || defined(__avr32__) || \
defined(__hppa__) || defined(__ia64__) || \
- defined(__mips__) || defined(__powerpc__) || \
+ defined(__mips__) || \
+ defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \
+ defined(_POWER) || defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \
defined(__sparc__) || defined(__sparc) || defined(__s390__) || \
defined(__SH4__) || defined(__alpha__) || \
- defined(_MIPS_ARCH_MIPS32R2)
+ defined(_MIPS_ARCH_MIPS32R2) || \
+ defined(__AARCH64EL__) || defined(__aarch64__)
#define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
+#elif defined(__mc68000__)
+#undef DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS
#elif defined(_M_IX86) || defined(__i386__) || defined(__i386)
#if defined(_WIN32)
// Windows uses a 64bit wide floating point stack.
@@ -71,6 +77,11 @@
#error Target architecture was not detected as supported by Double-Conversion.
#endif
+#if defined(__GNUC__)
+#define DOUBLE_CONVERSION_UNUSED __attribute__((unused))
+#else
+#define DOUBLE_CONVERSION_UNUSED
+#endif
#if defined(_WIN32) && !defined(__MINGW32__)
@@ -90,6 +101,8 @@ typedef unsigned __int64 uint64_t;
#endif
+typedef uint16_t uc16;
+
// The following macro works on both 32 and 64-bit platforms.
// Usage: instead of writing 0x1234567890123456
// write UINT64_2PART_C(0x12345678,90123456);
@@ -155,8 +168,8 @@ template <typename T>
class Vector {
public:
Vector() : start_(NULL), length_(0) {}
- Vector(T* data, int length) : start_(data), length_(length) {
- ASSERT(length == 0 || (length > 0 && data != NULL));
+ Vector(T* data, int len) : start_(data), length_(len) {
+ ASSERT(len == 0 || (len > 0 && data != NULL));
}
// Returns a vector using the same backing storage as this one,
@@ -198,8 +211,8 @@ class Vector {
// buffer bounds on all operations in debug mode.
class StringBuilder {
public:
- StringBuilder(char* buffer, int size)
- : buffer_(buffer, size), position_(0) { }
+ StringBuilder(char* buffer, int buffer_size)
+ : buffer_(buffer, buffer_size), position_(0) { }
~StringBuilder() { if (!is_finalized()) Finalize(); }
@@ -292,24 +305,12 @@ class StringBuilder {
// you can use BitCast to cast one pointer type to another. This confuses gcc
// enough that it can no longer see that you have cast one pointer type to
// another thus avoiding the warning.
-//
-// Adding an unused attribute for this static check. Apparently GCC 4.8
-// now throws an error for unused typedefs which triggers -Werror.
-//
-// PJD: 4-24-2013
-//
-
-#if defined(__GNUC__)
-#define UNUSED __attribute__((unused))
-#else
-#define UNUSED
-#endif
-
template <class Dest, class Source>
inline Dest BitCast(const Source& source) {
// Compile time assertion: sizeof(Dest) == sizeof(Source)
// A compile error here means your Dest and Source have different sizes.
- UNUSED typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1];
+ DOUBLE_CONVERSION_UNUSED
+ typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1];
Dest dest;
memmove(&dest, &source, sizeof(dest));