From ad052cb510e3be659df0322cbf33e4840c010b9b Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Fri, 25 Jun 2010 01:26:57 +0900 Subject: [PATCH 01/26] updated readme --- erlang/README.md | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/erlang/README.md b/erlang/README.md index 50d446d6..8616d5ec 100644 --- a/erlang/README.md +++ b/erlang/README.md @@ -2,18 +2,8 @@ MessagePack for Erlang ====================== Binary-based efficient object serialization library. -## Status +see wiki ( http://redmine.msgpack.org/projects/msgpack/wiki/QuickStartErlang ) for details -still in development. +# Status -TODOs: - - decide string specification. - -## Installation - -## Example - -## License - - - - +0.1.0 released. From a1b2b41cdcb4bbc98e21bcd334b729ec6e7b90d5 Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Sat, 26 Jun 2010 08:40:36 +0900 Subject: [PATCH 02/26] erlang: bugfix(serialization of -234 goes <<208,22>> while it should go int16 <<0xD1, ...>>) --- erlang/msgpack.erl | 20 ++++++++++---------- erlang/testcase_generator.rb | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index 789ed535..63d648cd 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -86,15 +86,12 @@ pack_uint_(N) when is_integer( N ) , N < 128 -> % uint 8 pack_uint_( N ) when is_integer( N ) andalso N < 256 -> << 16#CC:8, N:8 >>; - % uint 16 pack_uint_( N ) when is_integer( N ) andalso N < 65536 -> << 16#CD:8, N:16/big-unsigned-integer-unit:1 >>; - % uint 32 pack_uint_( N ) when is_integer( N ) andalso N < 16#FFFFFFFF-> << 16#CE:8, N:32/big-unsigned-integer-unit:1 >>; - % uint 64 pack_uint_( N ) when is_integer( N )-> << 16#CF:8, N:64/big-unsigned-integer-unit:1 >>. @@ -103,13 +100,13 @@ pack_uint_( N ) when is_integer( N )-> pack_int_( N ) when is_integer( N ) , N >= -32-> << 2#111:3, N:5 >>; % int 8 -pack_int_( N ) when is_integer( N ) , N >= -256 -> - << 16#D0:8, N:8 >>; +pack_int_( N ) when is_integer( N ) , N > -128 -> + << 16#D0:8, N:8/big-signed-integer-unit:1 >>; % int 16 -pack_int_( N ) when is_integer( N ), N >= -65536 -> +pack_int_( N ) when is_integer( N ), N > -32768 -> << 16#D1:8, N:16/big-signed-integer-unit:1 >>; % int 32 -pack_int_( N ) when is_integer( N ), N >= -16#FFFFFFFF -> +pack_int_( N ) when is_integer( N ), N > -16#FFFFFFFF -> << 16#D2:8, N:32/big-signed-integer-unit:1 >>; % int 64 pack_int_( N ) when is_integer( N )-> @@ -351,6 +348,7 @@ test_data()-> <<"hogehoge">>, <<"243546rf7g68h798j", 0, 23, 255>>, <<"hoasfdafdas][">>, [0,42, <<"sum">>, [1,2]], [1,42, nil, [3]], + -234, -40000, -16#10000000, -16#100000000, 42 ]. @@ -409,6 +407,7 @@ unknown_test()-> [23, 234, 0.23], [0,42,<<"sum">>, [1,2]], [1,42, nil, [3]], dict:from_list([{1,2},{<<"hoge">>,nil}]), + -234, -50000, 42 ], Port = open_port({spawn, "ruby testcase_generator.rb"}, [binary]), @@ -419,9 +418,10 @@ unknown_test()-> port_close(Port). test_([]) -> 0; -test_([S|Rest])-> - Pack = msgpack:pack(S), - {S, <<>>} = msgpack:unpack( Pack ), +test_([Before|Rest])-> + Pack = msgpack:pack(Before), + {After, <<>>} = msgpack:unpack( Pack ), + ?assertEqual(Before, After), 1+test_(Rest). other_test()-> diff --git a/erlang/testcase_generator.rb b/erlang/testcase_generator.rb index cfc36f96..8445bdd5 100644 --- a/erlang/testcase_generator.rb +++ b/erlang/testcase_generator.rb @@ -45,6 +45,7 @@ objs = [0, 1, 2, 123, 512, 1230, 678908, [23, 234, 0.23], [0,42,"sum", [1,2]], [1,42, nil, [3]], { 1 => 2, "hoge" => nil }, + -234, -50000, 42 ] begin From b471e52e281d189396a78cef3eb7ecacbab51d21 Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Tue, 29 Jun 2010 00:21:47 +0900 Subject: [PATCH 03/26] erlang: explicit API for serializing proplists, so as not to make wrong call of pack({proplists()}). --- erlang/msgpack.erl | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index c8070651..29e1728e 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -24,6 +24,7 @@ %% for C API (http://msgpack.sourceforge.jp/c:doc) %% except buffering functions (both copying and zero-copying). -export([pack/1, unpack/1, unpack_all/1]). +-export([pack_map/1]) % compile: % erl> c(msgpack). @@ -51,7 +52,7 @@ pack(List) when is_list(List) -> pack({Map}) when is_list(Map) -> pack_map(Map); pack(Map) when is_tuple(Map), element(1,Map)=:=dict -> - pack_map(dict:from_list(Map)); + pack_map(dict:to_list(Map)); pack(_O) -> {error, undefined}. @@ -78,6 +79,15 @@ unpack_all(Data)-> [Term|unpack_all(Binary)] end. +pack_map(M)-> + case length(M) of + Len when Len < 16 -> + << 2#1000:4, Len:4/integer-unit:1, (pack_map_(M, <<>>))/binary >>; + Len when Len < 16#10000 -> % 65536 + << 16#DE:8, Len:16/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >>; + Len -> + << 16#DF:8, Len:32/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >> + end. % ===== internal APIs ===== % @@ -162,17 +172,6 @@ unpack_array_(Bin, RestLen, RetList) when is_binary(Bin)-> {Term, Rest}-> unpack_array_(Rest, RestLen-1, [Term|RetList]) end. -% FIXME: write test for pack_map/1 -pack_map(M)-> - case length(M) of - Len when Len < 16 -> - << 2#1000:4, Len:4/integer-unit:1, (pack_map_(M, <<>>))/binary >>; - Len when Len < 16#10000 -> % 65536 - << 16#DE:8, Len:16/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >>; - Len -> - << 16#DF:8, Len:32/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >> - end. - pack_map_([], Acc) -> Acc; pack_map_([{Key,Value}|Tail], Acc) -> pack_map_(Tail, << Acc/binary, (pack(Key))/binary, (pack(Value))/binary>>). @@ -404,7 +403,7 @@ unknown_test()-> -234.4355, 1.0e-34, 1.0e64, [23, 234, 0.23], [0,42,<<"sum">>, [1,2]], [1,42, nil, [3]], - dict:from_list([{1,2},{<<"hoge">>,nil}]), + {[{1,2},{<<"hoge">>,nil}]}, -234, -50000, 42 ], From 90e305d789d231258e26a2dc546cfdb6f8c09ce8 Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Tue, 29 Jun 2010 00:21:47 +0900 Subject: [PATCH 04/26] erlang: explicit API for serializing proplists, so as not to make wrong call of pack({proplists()}). --- erlang/msgpack.erl | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index c8070651..a168b553 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -24,6 +24,7 @@ %% for C API (http://msgpack.sourceforge.jp/c:doc) %% except buffering functions (both copying and zero-copying). -export([pack/1, unpack/1, unpack_all/1]). +-export([pack_map/1]). % compile: % erl> c(msgpack). @@ -51,7 +52,7 @@ pack(List) when is_list(List) -> pack({Map}) when is_list(Map) -> pack_map(Map); pack(Map) when is_tuple(Map), element(1,Map)=:=dict -> - pack_map(dict:from_list(Map)); + pack_map(dict:to_list(Map)); pack(_O) -> {error, undefined}. @@ -78,6 +79,15 @@ unpack_all(Data)-> [Term|unpack_all(Binary)] end. +pack_map(M)-> + case length(M) of + Len when Len < 16 -> + << 2#1000:4, Len:4/integer-unit:1, (pack_map_(M, <<>>))/binary >>; + Len when Len < 16#10000 -> % 65536 + << 16#DE:8, Len:16/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >>; + Len -> + << 16#DF:8, Len:32/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >> + end. % ===== internal APIs ===== % @@ -162,17 +172,6 @@ unpack_array_(Bin, RestLen, RetList) when is_binary(Bin)-> {Term, Rest}-> unpack_array_(Rest, RestLen-1, [Term|RetList]) end. -% FIXME: write test for pack_map/1 -pack_map(M)-> - case length(M) of - Len when Len < 16 -> - << 2#1000:4, Len:4/integer-unit:1, (pack_map_(M, <<>>))/binary >>; - Len when Len < 16#10000 -> % 65536 - << 16#DE:8, Len:16/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >>; - Len -> - << 16#DF:8, Len:32/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >> - end. - pack_map_([], Acc) -> Acc; pack_map_([{Key,Value}|Tail], Acc) -> pack_map_(Tail, << Acc/binary, (pack(Key))/binary, (pack(Value))/binary>>). @@ -404,7 +403,7 @@ unknown_test()-> -234.4355, 1.0e-34, 1.0e64, [23, 234, 0.23], [0,42,<<"sum">>, [1,2]], [1,42, nil, [3]], - dict:from_list([{1,2},{<<"hoge">>,nil}]), + {[{1,2},{<<"hoge">>,nil}]}, -234, -50000, 42 ], From 9fffa9800ae4b09180d2b892f1f70215534a874b Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 29 Jun 2010 14:54:09 +0900 Subject: [PATCH 05/26] ruby: fixes RDoc of Unpacker#execute and Unpacker#execute_impl --- ruby/makegem.sh | 2 ++ ruby/unpack.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ruby/makegem.sh b/ruby/makegem.sh index 827f4521..d21f06a1 100755 --- a/ruby/makegem.sh +++ b/ruby/makegem.sh @@ -19,6 +19,8 @@ cp ../test/cases.json test/ gem build msgpack.gemspec +rdoc rbinit.c pack.c unpack.c + if [ $? -eq 0 ]; then rm -rf ext msgpack test/msgpack_test.rb fi diff --git a/ruby/unpack.c b/ruby/unpack.c index 65ae476e..151dbf4a 100644 --- a/ruby/unpack.c +++ b/ruby/unpack.c @@ -638,7 +638,7 @@ static VALUE MessagePack_Unpacker_execute_impl(VALUE self, VALUE data, * Document-method: MessagePack::Unpacker#execute_limit * * call-seq: - * unpacker.unpack_limit(data, offset, limit) -> next offset + * unpacker.execute_limit(data, offset, limit) -> next offset * * Deserializes one object over the specified buffer from _offset_ bytes upto _limit_ bytes. * @@ -660,7 +660,7 @@ static VALUE MessagePack_Unpacker_execute_limit(VALUE self, VALUE data, * Document-method: MessagePack::Unpacker#execute * * call-seq: - * unpacker.unpack(data, offset) -> next offset + * unpacker.execute(data, offset) -> next offset * * Deserializes one object over the specified buffer from _offset_ bytes. * From 34a29cd0a50eea4a0e008fe3947c86179d536540 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 29 Jun 2010 14:54:40 +0900 Subject: [PATCH 06/26] ruby: fixes SEGV problem caused by GC bug at MessagePack_Unpacker_mark. --- ruby/test/test_helper.rb | 1 + ruby/unpack.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ruby/test/test_helper.rb b/ruby/test/test_helper.rb index 19226ef0..bf9fee86 100644 --- a/ruby/test/test_helper.rb +++ b/ruby/test/test_helper.rb @@ -5,3 +5,4 @@ rescue LoadError require File.dirname(__FILE__) + '/../lib/msgpack' end +GC.stress = true diff --git a/ruby/unpack.c b/ruby/unpack.c index 151dbf4a..09481510 100644 --- a/ruby/unpack.c +++ b/ruby/unpack.c @@ -287,6 +287,7 @@ static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp) unsigned int i; rb_gc_mark(mp->user.stream); rb_gc_mark(mp->user.streambuf); + rb_gc_mark_maybe(template_data(mp)); for(i=0; i < mp->top; ++i) { rb_gc_mark(mp->stack[i].obj); rb_gc_mark_maybe(mp->stack[i].map_key); @@ -297,6 +298,17 @@ static VALUE MessagePack_Unpacker_alloc(VALUE klass) { VALUE obj; msgpack_unpack_t* mp = ALLOC_N(msgpack_unpack_t, 1); + + // rb_gc_mark (not _maybe) is used for following member objects. + mp->user.stream = Qnil; + mp->user.streambuf = Qnil; + + mp->user.finished = 0; + mp->user.offset = 0; + mp->user.buffer.size = 0; + mp->user.buffer.free = 0; + mp->user.buffer.ptr = NULL; + obj = Data_Wrap_Struct(klass, MessagePack_Unpacker_mark, MessagePack_Unpacker_free, mp); return obj; @@ -343,14 +355,10 @@ static VALUE MessagePack_Unpacker_initialize(int argc, VALUE *argv, VALUE self) UNPACKER(self, mp); template_init(mp); - mp->user.finished = 0; - mp->user.offset = 0; - mp->user.buffer.size = 0; - mp->user.buffer.free = 0; - mp->user.buffer.ptr = NULL; mp->user.stream = stream; mp->user.streambuf = rb_str_buf_new(MSGPACK_UNPACKER_BUFFER_RESERVE_SIZE); mp->user.stream_append_method = append_method_of(stream); + return self; } From 123ae024c6d5c217f18a9444c61b292145227278 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 29 Jun 2010 15:12:52 +0900 Subject: [PATCH 07/26] ruby: MessagePack::VERSION constant --- ruby/extconf.rb | 3 ++- ruby/msgpack.gemspec | 3 ++- ruby/rbinit.c | 4 +++- ruby/test/test_helper.rb | 2 +- ruby/test/test_pack_unpack.rb | 4 ++++ ruby/version.rb | 3 +++ 6 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 ruby/version.rb diff --git a/ruby/extconf.rb b/ruby/extconf.rb index e6d4bd6d..eb6a389f 100644 --- a/ruby/extconf.rb +++ b/ruby/extconf.rb @@ -1,4 +1,5 @@ require 'mkmf' -$CFLAGS << " -I.. -Wall -O4" +require './version.rb' +$CFLAGS << %[ -I.. -Wall -O4 -DMESSAGEPACK_VERSION=\\"#{MessagePack::VERSION}\\"] create_makefile('msgpack') diff --git a/ruby/msgpack.gemspec b/ruby/msgpack.gemspec index fb6338a5..95a2bd0a 100644 --- a/ruby/msgpack.gemspec +++ b/ruby/msgpack.gemspec @@ -1,7 +1,8 @@ +require './version.rb' Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.name = "msgpack" - s.version = "0.4.2" + s.version = MessagePack::VERSION s.summary = "MessagePack, a binary-based efficient data interchange format." s.author = "FURUHASHI Sadayuki" s.email = "frsyuki@users.sourceforge.jp" diff --git a/ruby/rbinit.c b/ruby/rbinit.c index ad51f6b4..28a8bfec 100644 --- a/ruby/rbinit.c +++ b/ruby/rbinit.c @@ -43,7 +43,9 @@ static VALUE mMessagePack; void Init_msgpack(void) { mMessagePack = rb_define_module("MessagePack"); + + rb_define_const(mMessagePack, "VERSION", rb_str_new2(MESSAGEPACK_VERSION)); + Init_msgpack_unpack(mMessagePack); Init_msgpack_pack(mMessagePack); } - diff --git a/ruby/test/test_helper.rb b/ruby/test/test_helper.rb index bf9fee86..80d7806a 100644 --- a/ruby/test/test_helper.rb +++ b/ruby/test/test_helper.rb @@ -5,4 +5,4 @@ rescue LoadError require File.dirname(__FILE__) + '/../lib/msgpack' end -GC.stress = true +#GC.stress = true diff --git a/ruby/test/test_pack_unpack.rb b/ruby/test/test_pack_unpack.rb index 9dff44f1..25bde81e 100644 --- a/ruby/test/test_pack_unpack.rb +++ b/ruby/test/test_pack_unpack.rb @@ -276,6 +276,10 @@ class MessagePackTestPackUnpack < Test::Unit::TestCase assert_equal(parsed, num) end + it "MessagePack::VERSION constant" do + p MessagePack::VERSION + end + private def check(len, obj) v = obj.to_msgpack diff --git a/ruby/version.rb b/ruby/version.rb new file mode 100644 index 00000000..b1566203 --- /dev/null +++ b/ruby/version.rb @@ -0,0 +1,3 @@ +module MessagePack + VERSION = "0.4.3" +end From 20de730541475516aa7a6361af1d1b5e4ea574b8 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 29 Jun 2010 15:39:47 +0900 Subject: [PATCH 08/26] ruby: 0.4.3 --- ruby/ChangeLog | 6 ++++++ ruby/makegem.sh | 1 + 2 files changed, 7 insertions(+) diff --git a/ruby/ChangeLog b/ruby/ChangeLog index e69de29b..d3a72829 100644 --- a/ruby/ChangeLog +++ b/ruby/ChangeLog @@ -0,0 +1,6 @@ + +2010-06-29 version 0.4.3: + + * Adds MessagePack::VERSION constant + * Fixes SEGV problem caused by GC bug at MessagePack_Unpacker_mark + diff --git a/ruby/makegem.sh b/ruby/makegem.sh index d21f06a1..bf30cd47 100755 --- a/ruby/makegem.sh +++ b/ruby/makegem.sh @@ -8,6 +8,7 @@ cp pack.h ext/ cp rbinit.c ext/ cp unpack.c ext/ cp unpack.h ext/ +cp version.rb ext/ cp ../msgpack/pack_define.h msgpack/ cp ../msgpack/pack_template.h msgpack/ cp ../msgpack/unpack_define.h msgpack/ From 83b4b7d83d0d32b2c30d26e51439b4dfec3127f9 Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Thu, 1 Jul 2010 00:58:48 +0900 Subject: [PATCH 09/26] erlang: more suitable variable name and removing unnecessary guards. --- erlang/msgpack.erl | 75 +++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index a168b553..c99002c3 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -31,20 +31,24 @@ % erl> S = . % erl> {S, <<>>} = msgpack:unpack( msgpack:pack(S) ). -type reason() :: enomem | badarg | no_code_matches. --type msgpack_term() :: [msgpack_term()] | {[{msgpack_term(),msgpack_term()}]} | integer() | float(). +-type msgpack_term() :: [msgpack_term()] + | {[{msgpack_term(),msgpack_term()}]} + | integer() | float() | binary(). % ===== external APIs ===== % -spec pack(Term::msgpack_term()) -> binary(). -pack(O) when is_integer(O) andalso O < 0 -> - pack_int_(O); -pack(O) when is_integer(O) -> - pack_uint_(O); -pack(O) when is_float(O) -> - pack_double(O); +pack(I) when is_integer(I) andalso I < 0 -> + pack_int_(I); +pack(I) when is_integer(I) -> + pack_uint_(I); +pack(F) when is_float(F) -> + pack_double(F); pack(nil) -> - pack_nil(); -pack(Bool) when is_atom(Bool) -> - pack_bool(Bool); + << 16#C0:8 >>; +pack(true) -> + << 16#C3:8 >>; +pack(false) -> + << 16#C2:8 >>; pack(Bin) when is_binary(Bin) -> pack_raw(Bin); pack(List) when is_list(List) -> @@ -53,7 +57,7 @@ pack({Map}) when is_list(Map) -> pack_map(Map); pack(Map) when is_tuple(Map), element(1,Map)=:=dict -> pack_map(dict:to_list(Map)); -pack(_O) -> +pack(_Other) -> {error, undefined}. % unpacking. @@ -92,53 +96,47 @@ pack_map(M)-> % ===== internal APIs ===== % % positive fixnum -pack_uint_(N) when is_integer( N ) , N < 128 -> +pack_uint_(N) when N < 128 -> << 2#0:1, N:7 >>; % uint 8 -pack_uint_( N ) when is_integer( N ) andalso N < 256 -> +pack_uint_(N) when N < 256 -> << 16#CC:8, N:8 >>; % uint 16 -pack_uint_( N ) when is_integer( N ) andalso N < 65536 -> +pack_uint_(N) when N < 65536 -> << 16#CD:8, N:16/big-unsigned-integer-unit:1 >>; % uint 32 -pack_uint_( N ) when is_integer( N ) andalso N < 16#FFFFFFFF-> +pack_uint_(N) when N < 16#FFFFFFFF-> << 16#CE:8, N:32/big-unsigned-integer-unit:1 >>; % uint 64 -pack_uint_( N ) when is_integer( N )-> +pack_uint_(N) -> << 16#CF:8, N:64/big-unsigned-integer-unit:1 >>. % negative fixnum -pack_int_( N ) when is_integer( N ) , N >= -32-> +pack_int_(N) when is_integer(N) , N >= -32-> << 2#111:3, N:5 >>; % int 8 -pack_int_( N ) when is_integer( N ) , N > -128 -> +pack_int_(N) when N > -128 -> << 16#D0:8, N:8/big-signed-integer-unit:1 >>; % int 16 -pack_int_( N ) when is_integer( N ), N > -32768 -> +pack_int_(N) when N > -32768 -> << 16#D1:8, N:16/big-signed-integer-unit:1 >>; % int 32 -pack_int_( N ) when is_integer( N ), N > -16#FFFFFFFF -> +pack_int_(N) when N > -16#FFFFFFFF -> << 16#D2:8, N:32/big-signed-integer-unit:1 >>; % int 64 -pack_int_( N ) when is_integer( N )-> +pack_int_(N) -> << 16#D3:8, N:64/big-signed-integer-unit:1 >>. -% nil -pack_nil()-> << 16#C0:8 >>. -% pack_true / pack_false -pack_bool(true)-> << 16#C3:8 >>; -pack_bool(false)-> << 16#C2:8 >>. - % float : erlang's float is always IEEE 754 64bit format. %pack_float(F) when is_float(F)-> % << 16#CA:8, F:32/big-float-unit:1 >>. % pack_double(F). % double -pack_double(F) when is_float(F)-> +pack_double(F) -> << 16#CB:8, F:64/big-float-unit:1 >>. % raw bytes -pack_raw(Bin) when is_binary(Bin)-> +pack_raw(Bin) -> case byte_size(Bin) of Len when Len < 6-> << 2#101:3, Len:5, Bin/binary >>; @@ -149,7 +147,7 @@ pack_raw(Bin) when is_binary(Bin)-> end. % list / tuple -pack_array(L) when is_list(L)-> +pack_array(L) -> case length(L) of Len when Len < 16 -> << 2#1001:4, Len:4/integer-unit:1, (pack_array_(L, <<>>))/binary >>; @@ -165,10 +163,10 @@ pack_array_([Head|Tail], Acc) -> % FIXME! this should be tail-recursive and without lists:reverse/1 unpack_array_(<<>>, 0, RetList) -> {lists:reverse(RetList), <<>>}; unpack_array_(Remain, 0, RetList) when is_binary(Remain)-> {lists:reverse(RetList), Remain}; -unpack_array_(<<>>, RestLen, _RetList) when RestLen > 0 -> {more, RestLen}; +unpack_array_(<<>>, RestLen, _RetList) when RestLen > 0 -> {more, undefined}; unpack_array_(Bin, RestLen, RetList) when is_binary(Bin)-> case unpack(Bin) of - {more, Len} -> {more, Len+RestLen-1}; + {more, Len} -> {more, undefined}; {Term, Rest}-> unpack_array_(Rest, RestLen-1, [Term|RetList]) end. @@ -179,8 +177,8 @@ pack_map_([{Key,Value}|Tail], Acc) -> % FIXME: write test for unpack_map/1 -spec unpack_map_(binary(), non_neg_integer(), [{term(), msgpack_term()}])-> {more, non_neg_integer()} | { any(), binary()}. -unpack_map_(Bin, 0, Acc) when is_binary(Bin) -> {{lists:reverse(Acc)}, Bin}; -unpack_map_(Bin, Len, Acc) when is_binary(Bin) and is_integer(Len) -> +unpack_map_(Bin, 0, Acc) -> {{lists:reverse(Acc)}, Bin}; +unpack_map_(Bin, Len, Acc) -> case unpack(Bin) of { more, MoreLen } -> { more, MoreLen+Len-1 }; { Key, Rest } -> @@ -371,9 +369,12 @@ test_p(Len,Term,OrigBin,Len) -> {Term, <<>>}=msgpack:unpack(OrigBin); test_p(I,_,OrigBin,Len) when I < Len-> <> = OrigBin, - {more, N}=msgpack:unpack(Bin), - ?assert(0 < N), - ?assert(N < Len). + case msgpack:unpack(Bin) of + {more, N} when not is_integer(N) -> + ?assertEqual(undefined, N); + {more, N} -> + ?assert( N < Len ) + end. partial_test()-> % error handling test. Term = lists:seq(0, 45), From acb8fa613e87081267ec9963e5770580208e3e1f Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Thu, 1 Jul 2010 01:02:19 +0900 Subject: [PATCH 10/26] erlang: adding shorthand fix for {more, undefined} problem --- erlang/msgpack.erl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index c99002c3..d24220be 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -166,7 +166,7 @@ unpack_array_(Remain, 0, RetList) when is_binary(Remain)-> {lists:reverse(RetLis unpack_array_(<<>>, RestLen, _RetList) when RestLen > 0 -> {more, undefined}; unpack_array_(Bin, RestLen, RetList) when is_binary(Bin)-> case unpack(Bin) of - {more, Len} -> {more, undefined}; + {more, _} -> {more, undefined}; {Term, Rest}-> unpack_array_(Rest, RestLen-1, [Term|RetList]) end. @@ -180,11 +180,11 @@ pack_map_([{Key,Value}|Tail], Acc) -> unpack_map_(Bin, 0, Acc) -> {{lists:reverse(Acc)}, Bin}; unpack_map_(Bin, Len, Acc) -> case unpack(Bin) of - { more, MoreLen } -> { more, MoreLen+Len-1 }; - { Key, Rest } -> + {more, _} -> {more, undefined}; + {Key, Rest} -> case unpack(Rest) of - {more, MoreLen} -> { more, MoreLen+Len-1 }; - { Value, Rest2 } -> + {more, _} -> {more, undefined}; + {Value, Rest2} -> unpack_map_(Rest2,Len-1,[{Key,Value}|Acc]) end end. From 2469768a85a067e5ba425d09ebd717cd0104449a Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Thu, 1 Jul 2010 01:07:56 +0900 Subject: [PATCH 11/26] erlang: reducing unnecessary binary matching in unpack_/2 * more efficient unpack_/1 by Vincent de Phille's code. thanks. --- erlang/msgpack.erl | 207 +++++++++++++++------------------------------ 1 file changed, 70 insertions(+), 137 deletions(-) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index d24220be..703dce25 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -69,10 +69,11 @@ pack(_Other) -> unpack(Bin) when not is_binary(Bin)-> {error, badarg}; unpack(Bin) when bit_size(Bin) >= 8 -> - << Flag:8/unsigned-integer, Payload/binary >> = Bin, - unpack_(Flag, Payload); -unpack(<<>>)-> % when bit_size(Bin) < 8 -> - {more, 1}. + unpack_(Bin); +unpack(<<>>)-> + {more, 1}; +unpack(_) -> + {more, undefined}. -spec unpack_all( binary() ) -> [msgpack_term()]. unpack_all(Data)-> @@ -83,6 +84,7 @@ unpack_all(Data)-> [Term|unpack_all(Binary)] end. +-spec pack_map(M::[{msgpack_term(),msgpack_term()}])-> binary(). pack_map(M)-> case length(M) of Len when Len < 16 -> @@ -189,143 +191,74 @@ unpack_map_(Bin, Len, Acc) -> end end. -% {more, --spec unpack_(Flag::integer(), Payload::binary())-> - {more, pos_integer()} | {msgpack_term(), binary()} | {error, reason()}. -unpack_(Flag, Payload)-> - PayloadLen = byte_size(Payload), - case Flag of - 16#C0 -> - {nil, Payload}; - 16#C2 -> - {false, Payload}; - 16#C3 -> - {true, Payload}; +-spec unpack_(Payload::binary()) -> + {more, pos_integer()} | {msgpack_term(), binary()} | {error, reason()}. +unpack_(Binary)-> + case Binary of +% ATOMS + <<16#C0, Rest/binary>> -> {nil, Rest}; + <<16#C2, Rest/binary>> -> {false, Rest}; + <<16#C3, Rest/binary>> -> {true, Rest}; +% Floats + <<16#CA, Val:32/float-unit:1, Rest/binary>> -> {Val, Rest}; + <<16#CB, Val:64/float-unit:1, Rest/binary>> -> {Val, Rest}; +% Unsigned integers + <<16#CC, Val:8/unsigned-integer, Rest/binary>> -> {Val, Rest}; + <<16#CD, Val:16/big-unsigned-integer-unit:1, Rest/binary>> -> {Val, Rest}; + <<16#CE, Val:32/big-unsigned-integer-unit:1, Rest/binary>> -> {Val, Rest}; + <<16#CF, Val:64/big-unsigned-integer-unit:1, Rest/binary>> -> {Val, Rest}; +% Signed integers + <<16#D0, Val:8/signed-integer, Rest/binary>> -> {Val, Rest}; + <<16#D1, Val:16/big-signed-integer-unit:1, Rest/binary>> -> {Val, Rest}; + <<16#D2, Val:32/big-signed-integer-unit:1, Rest/binary>> -> {Val, Rest}; + <<16#D3, Val:64/big-signed-integer-unit:1, Rest/binary>> -> {Val, Rest}; +% Raw bytes + <<16#DA, Len:16/unsigned-integer-unit:1, Val:Len/binary, Rest/binary>> -> {Val, Rest}; + <<16#DB, Len:32/unsigned-integer-unit:1, Val:Len/binary, Rest/binary>> -> {Val, Rest}; +% Arrays + <<16#DC, Len:16/big-unsigned-integer-unit:1, Rest/binary>> -> unpack_array_(Rest, Len, []); + <<16#DD, Len:32/big-unsigned-integer-unit:1, Rest/binary>> -> unpack_array_(Rest, Len, []); +% Maps + <<16#DE, Len:16/big-unsigned-integer-unit:1, Rest/binary>> -> unpack_map_(Rest, Len, []); + <<16#DF, Len:32/big-unsigned-integer-unit:1, Rest/binary>> -> unpack_map_(Rest, Len, []); - 16#CA when PayloadLen >= 4 -> % 32bit float - << Return:32/float-unit:1, Rest/binary >> = Payload, - {Return, Rest}; - 16#CA -> - {more, 4-PayloadLen}; % at least more +% Tag-encoded lengths (kept last, for speed) + <<0:1, Val:7, Rest/binary>> -> {Val, Rest}; % positive int + <<2#111:3, Val:5, Rest/binary>> -> {Val - 2#100000, Rest}; % negative int + <<2#101:3, Len:5, Val:Len/binary, Rest/binary>> -> {Val, Rest}; % raw bytes + <<2#1001:4, Len:4, Rest/binary>> -> unpack_array_(Rest, Len, []); % array + <<2#1000:4, Len:4, Rest/binary>> -> unpack_map_(Rest, Len, []); % map + +% Incomplete / invalid data + <<16#CA, Rest/binary>> -> {more, 4-byte_size(Rest)}; + <<16#CB, Rest/binary>> -> {more, 8-byte_size(Rest)}; + <<16#CC>> -> {more, 1}; + <<16#CD, Rest/binary>> -> {more, 2-byte_size(Rest)}; + <<16#CE, Rest/binary>> -> {more, 4-byte_size(Rest)}; + <<16#CF, Rest/binary>> -> {more, 8-byte_size(Rest)}; + <<16#D0>> -> {more, 1}; + <<16#D1, Rest/binary>> -> {more, 2-byte_size(Rest)}; + <<16#D2, Rest/binary>> -> {more, 4-byte_size(Rest)}; + <<16#D3, Rest/binary>> -> {more, 8-byte_size(Rest)}; + <<16#DA, Rest/binary>> -> {more, 16-byte_size(Rest)}; + <<16#DB, Rest/binary>> -> {more, 32-byte_size(Rest)}; + <<16#DC, Rest/binary>> -> {more, 2-byte_size(Rest)}; + <<16#DD, Rest/binary>> -> {more, 4-byte_size(Rest)}; + <<16#DE, Rest/binary>> -> {more, 2-byte_size(Rest)}; + <<16#DF, Rest/binary>> -> {more, 4-byte_size(Rest)}; + <<2#101:3, Len:5, Rest/binary>> -> {more, Len-byte_size(Rest)}; - 16#CB when PayloadLen >= 8 -> % 64bit float - << Return:64/float-unit:1, Rest/binary >> = Payload, - {Return, Rest}; - 16#CB -> - {more, 8-PayloadLen}; - - 16#CC when PayloadLen >= 1 -> % uint 8 - << Int:8/unsigned-integer, Rest/binary >> = Payload, - {Int, Rest}; - 16#CC -> - {more, 1}; - - 16#CD when PayloadLen >= 2 -> % uint 16 - << Int:16/big-unsigned-integer-unit:1, Rest/binary >> = Payload, - {Int, Rest}; - 16#CD -> - {more, 2-PayloadLen}; - - 16#CE when PayloadLen >= 4 -> - << Int:32/big-unsigned-integer-unit:1, Rest/binary >> = Payload, - {Int, Rest}; - 16#CE -> - {more, 4-PayloadLen}; % at least more - - 16#CF when PayloadLen >= 8 -> - << Int:64/big-unsigned-integer-unit:1, Rest/binary >> = Payload, - {Int, Rest}; - 16#CF -> - {more, 8-PayloadLen}; - - 16#D0 when PayloadLen >= 1 -> % int 8 - << Int:8/big-signed-integer-unit:1, Rest/binary >> = Payload, - {Int, Rest}; - 16#D0 -> - {more, 1}; - - 16#D1 when PayloadLen >= 2 -> % int 16 - << Int:16/big-signed-integer-unit:1, Rest/binary >> = Payload, - {Int, Rest}; - 16#D1 -> - {more, 2-PayloadLen}; - - 16#D2 when PayloadLen >= 4 -> % int 32 - << Int:32/big-signed-integer-unit:1, Rest/binary >> = Payload, - {Int, Rest}; - 16#D2 -> - {more, 4-PayloadLen}; - - 16#D3 when PayloadLen >= 8 -> % int 64 - << Int:64/big-signed-integer-unit:1, Rest/binary >> = Payload, - {Int, Rest}; - 16#D3 -> - {more, 8-PayloadLen}; - - 16#DA when PayloadLen >= 2 -> % raw 16 - << Len:16/unsigned-integer-unit:1, Rest/binary >> = Payload, - << Return:Len/binary, Remain/binary >> = Rest, - {Return, Remain}; - 16#DA -> - {more, 16-PayloadLen}; - - 16#DB when PayloadLen >= 4 -> % raw 32 - << Len:32/big-unsigned-integer-unit:1, Rest/binary >> = Payload, - << Return:Len/binary, Remain/binary >> = Rest, - {Return, Remain}; - 16#DB -> - {more, 4-PayloadLen}; - - 16#DC when PayloadLen >= 2 -> % array 16 - << Len:16/big-unsigned-integer-unit:1, Rest/binary >> = Payload, - unpack_array_(Rest, Len, []); - 16#DC -> - {more, 2-PayloadLen}; - - 16#DD when PayloadLen >= 4 -> % array 32 - << Len:32/big-unsigned-integer-unit:1, Rest/binary >> = Payload, - unpack_array_(Rest, Len, []); - 16#DD -> - {more, 4-PayloadLen}; - - 16#DE when PayloadLen >= 2 -> % map 16 - << Len:16/big-unsigned-integer-unit:1, Rest/binary >> = Payload, - unpack_map_(Rest, Len, []); - 16#DE -> - {more, 2-PayloadLen}; - - 16#DF when PayloadLen >= 4 -> % map 32 - << Len:32/big-unsigned-integer-unit:1, Rest/binary >> = Payload, - unpack_map_(Rest, Len, []); - - % positive fixnum - Code when Code >= 2#00000000, Code < 2#10000000-> - {Code, Payload}; - - % negative fixnum - Code when Code >= 2#11100000 -> - {(Code - 16#100), Payload}; - - Code when Code >= 2#10100000 , Code < 2#11000000 -> -% 101XXXXX for FixRaw - Len = Code rem 2#10100000, - << Return:Len/binary, Remain/binary >> = Payload, - {Return, Remain}; - - Code when Code >= 2#10010000 , Code < 2#10100000 -> -% 1001XXXX for FixArray - Len = Code rem 2#10010000, - unpack_array_(Payload, Len, []); - - Code when Code >= 2#10000000 , Code < 2#10010000 -> -% 1000XXXX for FixMap - Len = Code rem 2#10000000, - unpack_map_(Payload, Len, []); - - _Other -> - {error, no_code_matches} + <<>> -> {more, 1}; + <<2#101:3, _/binary>> -> {more, undefined}; + <> when F==16#C1; + F==16#C7; F==16#C8; F==16#C9; F==16#D5; + F==16#D6; F==16#D7; F==16#D8; F==16#D9-> + {error, {badarg, <>}}; + Other -> + {error, {badarg, Other}} end. + % ===== test codes ===== % -include_lib("eunit/include/eunit.hrl"). -ifdef(EUNIT). From 370e92b1a6d79cd6d65840cae588ded11b167fce Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Thu, 1 Jul 2010 01:14:20 +0900 Subject: [PATCH 12/26] erlang: just a golf. --- erlang/msgpack.erl | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index 703dce25..6d94a230 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -200,34 +200,34 @@ unpack_(Binary)-> <<16#C2, Rest/binary>> -> {false, Rest}; <<16#C3, Rest/binary>> -> {true, Rest}; % Floats - <<16#CA, Val:32/float-unit:1, Rest/binary>> -> {Val, Rest}; - <<16#CB, Val:64/float-unit:1, Rest/binary>> -> {Val, Rest}; + <<16#CA, V:32/float-unit:1, Rest/binary>> -> {V, Rest}; + <<16#CB, V:64/float-unit:1, Rest/binary>> -> {V, Rest}; % Unsigned integers - <<16#CC, Val:8/unsigned-integer, Rest/binary>> -> {Val, Rest}; - <<16#CD, Val:16/big-unsigned-integer-unit:1, Rest/binary>> -> {Val, Rest}; - <<16#CE, Val:32/big-unsigned-integer-unit:1, Rest/binary>> -> {Val, Rest}; - <<16#CF, Val:64/big-unsigned-integer-unit:1, Rest/binary>> -> {Val, Rest}; + <<16#CC, V:8/unsigned-integer, Rest/binary>> -> {V, Rest}; + <<16#CD, V:16/big-unsigned-integer-unit:1, Rest/binary>> -> {V, Rest}; + <<16#CE, V:32/big-unsigned-integer-unit:1, Rest/binary>> -> {V, Rest}; + <<16#CF, V:64/big-unsigned-integer-unit:1, Rest/binary>> -> {V, Rest}; % Signed integers - <<16#D0, Val:8/signed-integer, Rest/binary>> -> {Val, Rest}; - <<16#D1, Val:16/big-signed-integer-unit:1, Rest/binary>> -> {Val, Rest}; - <<16#D2, Val:32/big-signed-integer-unit:1, Rest/binary>> -> {Val, Rest}; - <<16#D3, Val:64/big-signed-integer-unit:1, Rest/binary>> -> {Val, Rest}; + <<16#D0, V:8/signed-integer, Rest/binary>> -> {V, Rest}; + <<16#D1, V:16/big-signed-integer-unit:1, Rest/binary>> -> {V, Rest}; + <<16#D2, V:32/big-signed-integer-unit:1, Rest/binary>> -> {V, Rest}; + <<16#D3, V:64/big-signed-integer-unit:1, Rest/binary>> -> {V, Rest}; % Raw bytes - <<16#DA, Len:16/unsigned-integer-unit:1, Val:Len/binary, Rest/binary>> -> {Val, Rest}; - <<16#DB, Len:32/unsigned-integer-unit:1, Val:Len/binary, Rest/binary>> -> {Val, Rest}; + <<16#DA, L:16/unsigned-integer-unit:1, V:L/binary, Rest/binary>> -> {V, Rest}; + <<16#DB, L:32/unsigned-integer-unit:1, V:L/binary, Rest/binary>> -> {V, Rest}; % Arrays - <<16#DC, Len:16/big-unsigned-integer-unit:1, Rest/binary>> -> unpack_array_(Rest, Len, []); - <<16#DD, Len:32/big-unsigned-integer-unit:1, Rest/binary>> -> unpack_array_(Rest, Len, []); + <<16#DC, L:16/big-unsigned-integer-unit:1, Rest/binary>> -> unpack_array_(Rest, L, []); + <<16#DD, L:32/big-unsigned-integer-unit:1, Rest/binary>> -> unpack_array_(Rest, L, []); % Maps - <<16#DE, Len:16/big-unsigned-integer-unit:1, Rest/binary>> -> unpack_map_(Rest, Len, []); - <<16#DF, Len:32/big-unsigned-integer-unit:1, Rest/binary>> -> unpack_map_(Rest, Len, []); + <<16#DE, L:16/big-unsigned-integer-unit:1, Rest/binary>> -> unpack_map_(Rest, L, []); + <<16#DF, L:32/big-unsigned-integer-unit:1, Rest/binary>> -> unpack_map_(Rest, L, []); % Tag-encoded lengths (kept last, for speed) - <<0:1, Val:7, Rest/binary>> -> {Val, Rest}; % positive int - <<2#111:3, Val:5, Rest/binary>> -> {Val - 2#100000, Rest}; % negative int - <<2#101:3, Len:5, Val:Len/binary, Rest/binary>> -> {Val, Rest}; % raw bytes - <<2#1001:4, Len:4, Rest/binary>> -> unpack_array_(Rest, Len, []); % array - <<2#1000:4, Len:4, Rest/binary>> -> unpack_map_(Rest, Len, []); % map + <<0:1, V:7, Rest/binary>> -> {V, Rest}; % positive int + <<2#111:3, V:5, Rest/binary>> -> {V - 2#100000, Rest}; % negative int + <<2#101:3, L:5, V:L/binary, Rest/binary>> -> {V, Rest}; % raw bytes + <<2#1001:4, L:4, Rest/binary>> -> unpack_array_(Rest, L, []); % array + <<2#1000:4, L:4, Rest/binary>> -> unpack_map_(Rest, L, []); % map % Incomplete / invalid data <<16#CA, Rest/binary>> -> {more, 4-byte_size(Rest)}; @@ -246,7 +246,7 @@ unpack_(Binary)-> <<16#DD, Rest/binary>> -> {more, 4-byte_size(Rest)}; <<16#DE, Rest/binary>> -> {more, 2-byte_size(Rest)}; <<16#DF, Rest/binary>> -> {more, 4-byte_size(Rest)}; - <<2#101:3, Len:5, Rest/binary>> -> {more, Len-byte_size(Rest)}; + <<2#101:3, L:5, Rest/binary>> -> {more, L-byte_size(Rest)}; <<>> -> {more, 1}; <<2#101:3, _/binary>> -> {more, undefined}; From ff5d5d7cbcb7e136370f3450d67b06244d5c3bc7 Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Thu, 1 Jul 2010 01:14:38 +0900 Subject: [PATCH 13/26] erlang: updated the comments --- erlang/msgpack.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index 6d94a230..8a542712 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -162,7 +162,7 @@ pack_array_([], Acc) -> Acc; pack_array_([Head|Tail], Acc) -> pack_array_(Tail, <>). -% FIXME! this should be tail-recursive and without lists:reverse/1 +% FIXME! this should be without lists:reverse/1 unpack_array_(<<>>, 0, RetList) -> {lists:reverse(RetList), <<>>}; unpack_array_(Remain, 0, RetList) when is_binary(Remain)-> {lists:reverse(RetList), Remain}; unpack_array_(<<>>, RestLen, _RetList) when RestLen > 0 -> {more, undefined}; @@ -176,7 +176,7 @@ pack_map_([], Acc) -> Acc; pack_map_([{Key,Value}|Tail], Acc) -> pack_map_(Tail, << Acc/binary, (pack(Key))/binary, (pack(Value))/binary>>). -% FIXME: write test for unpack_map/1 +% FIXME! this should be without lists:reverse/1 -spec unpack_map_(binary(), non_neg_integer(), [{term(), msgpack_term()}])-> {more, non_neg_integer()} | { any(), binary()}. unpack_map_(Bin, 0, Acc) -> {{lists:reverse(Acc)}, Bin}; From 584462f9b9efefa25e93600024c3d9680923b3a4 Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Thu, 1 Jul 2010 01:16:25 +0900 Subject: [PATCH 14/26] erlang: improved spec. --- erlang/msgpack.erl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index 8a542712..aab07b72 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -64,8 +64,9 @@ pack(_Other) -> % if failed in decoding and not end, get more data % and feed more Bin into this function. % TODO: error case for imcomplete format when short for any type formats. --spec unpack( binary() )-> - {msgpack_term(), binary()} | {more, non_neg_integer()} | {error, reason()}. +-spec unpack( Bin::binary() )-> {msgpack_term(), binary()} | + {more, non_neg_integer()} | {more, undefined} | + {error, reason()}. unpack(Bin) when not is_binary(Bin)-> {error, badarg}; unpack(Bin) when bit_size(Bin) >= 8 -> From 71dd44f4308dbdda2d087130452182093262ee01 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 6 Jul 2010 12:26:21 +0900 Subject: [PATCH 15/26] cpp: adds operator<<(std::ostream&, const tuple&) (experimental) --- cpp/src/msgpack/type/tuple.hpp.erb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cpp/src/msgpack/type/tuple.hpp.erb b/cpp/src/msgpack/type/tuple.hpp.erb index 0d9ae91c..ebef8163 100644 --- a/cpp/src/msgpack/type/tuple.hpp.erb +++ b/cpp/src/msgpack/type/tuple.hpp.erb @@ -187,5 +187,20 @@ inline void operator<< ( } // namespace msgpack + +//inline std::ostream& operator<< (std::ostream& o, const msgpack::type::tuple<>& v) { +// return o << "[]"; +//} +//<%0.upto(GENERATION_LIMIT) {|i|%> +//template , typename A<%=j%><%}%>> +//inline std::ostream& operator<< (std::ostream& o, +// const msgpack::type::tuple, A<%=j%><%}%>>& v) { +// return o << "[" +// <%0.upto(i) {|j|%> +// <<<%if j != 0 then%> ", " <<<%end%> v.template get<<%=j%>>()<%}%> +// << "]"; +//} +//<%}%> + #endif /* msgpack/type/tuple.hpp */ From 3af10a1d000882f338529360bf35ae0e3a21ffc4 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 6 Jul 2010 17:00:58 +0900 Subject: [PATCH 16/26] cpp: adds MSGPACK_VERSION{,_MAJOR,_MINOR} macros and msgpack{,_major,_minor} functions --- cpp/Makefile.am | 1 - cpp/configure.in | 5 +++++ cpp/src/Makefile.am | 15 ++++++++++---- cpp/src/msgpack.h | 2 ++ cpp/src/msgpack/version.h.in | 40 ++++++++++++++++++++++++++++++++++++ cpp/src/version.c | 17 +++++++++++++++ cpp/test/Makefile.am | 3 +++ 7 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 cpp/src/msgpack/version.h.in create mode 100644 cpp/src/version.c diff --git a/cpp/Makefile.am b/cpp/Makefile.am index 871ff8c0..7dd48910 100644 --- a/cpp/Makefile.am +++ b/cpp/Makefile.am @@ -12,7 +12,6 @@ EXTRA_DIST = \ $(DOC_FILES) doxygen: - ./preprocess ./preprocess clean cd src && $(MAKE) doxygen ./preprocess diff --git a/cpp/configure.in b/cpp/configure.in index 0895be4b..ffe3671e 100644 --- a/cpp/configure.in +++ b/cpp/configure.in @@ -54,5 +54,10 @@ add CFLAGS="--march=i686" and CXXFLAGS="-march=i686" options to ./configure as f ]) fi +major=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'` +minor=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'` +AC_SUBST(VERSION_MAJOR, $major) +AC_SUBST(VERSION_MINOR, $minor) + AC_OUTPUT([Makefile src/Makefile test/Makefile]) diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index 6b6457e6..78d14aa3 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -4,6 +4,7 @@ lib_LTLIBRARIES = libmsgpack.la libmsgpack_la_SOURCES = \ unpack.c \ objectc.c \ + version.c \ vrefbuffer.c \ zone.c \ object.cpp @@ -18,15 +19,12 @@ lib_LTLIBRARIES += libmsgpackc.la libmsgpackc_la_SOURCES = \ unpack.c \ objectc.c \ + version.c \ vrefbuffer.c \ zone.c libmsgpackc_la_LDFLAGS = -version-info 2:0:0 -# work around for duplicated file name -kumo_manager_CFLAGS = $(AM_CFLAGS) -kumo_manager_CXXFLAGS = $(AM_CXXFLAGS) - nobase_include_HEADERS = \ msgpack/pack_define.h \ @@ -44,6 +42,7 @@ nobase_include_HEADERS = \ msgpack/zone.h \ msgpack.hpp \ msgpack/sbuffer.hpp \ + msgpack/version.h \ msgpack/vrefbuffer.hpp \ msgpack/zbuffer.hpp \ msgpack/pack.hpp \ @@ -69,11 +68,19 @@ nobase_include_HEADERS = \ msgpack/type/tr1/unordered_set.hpp EXTRA_DIST = \ + msgpack/version.h.in \ msgpack/zone.hpp.erb \ msgpack/type/define.hpp.erb \ msgpack/type/tuple.hpp.erb +msgpack/version.h: msgpack/version.h.in Makefile.in + sed -e s/VERSION_UNDEFINED/$(VERSION)/ \ + -e s/VERSION_MAJOR_UNDEFINED/$(VERSION_MAJOR)/ \ + -e s/VERSION_MINOR_UNDEFINED/$(VERSION_MINOR)/ \ + $< > $@ + + doxygen_c: cat ../Doxyfile > Doxyfile_c echo "FILE_PATTERNS = *.h" >> Doxyfile_c diff --git a/cpp/src/msgpack.h b/cpp/src/msgpack.h index 0cd8a199..08f27688 100644 --- a/cpp/src/msgpack.h +++ b/cpp/src/msgpack.h @@ -26,3 +26,5 @@ #include "msgpack/unpack.h" #include "msgpack/sbuffer.h" #include "msgpack/vrefbuffer.h" +#include "msgpack/version.h" + diff --git a/cpp/src/msgpack/version.h.in b/cpp/src/msgpack/version.h.in new file mode 100644 index 00000000..af292d0d --- /dev/null +++ b/cpp/src/msgpack/version.h.in @@ -0,0 +1,40 @@ +/* + * MessagePack for C version information + * + * Copyright (C) 2008-2009 FURUHASHI Sadayuki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MSGPACK_VERSION_H__ +#define MSGPACK_VERSION_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +const char* msgpack_version(void); +int msgpack_version_major(void); +int msgpack_version_minor(void); + +#define MSGPACK_VERSION "VERSION_UNDEFINED" +#define MSGPACK_VERSION_MAJOR VERSION_MAJOR_UNDEFINED +#define MSGPACK_VERSION_MINOR VERSION_MINOR_UNDEFINED + + +#ifdef __cplusplus +} +#endif + +#endif /* msgpack/version.h */ + diff --git a/cpp/src/version.c b/cpp/src/version.c new file mode 100644 index 00000000..3d956f18 --- /dev/null +++ b/cpp/src/version.c @@ -0,0 +1,17 @@ +#include "msgpack.h" + +const char* msgpack_version(void) +{ + return MSGPACK_VERSION; +} + +int msgpack_version_major(void) +{ + return MSGPACK_VERSION_MAJOR; +} + +int msgpack_version_minor(void) +{ + return MSGPACK_VERSION_MINOR; +} + diff --git a/cpp/test/Makefile.am b/cpp/test/Makefile.am index 1f522150..bb9439e3 100644 --- a/cpp/test/Makefile.am +++ b/cpp/test/Makefile.am @@ -13,6 +13,7 @@ check_PROGRAMS = \ convert \ buffer \ cases \ + version \ msgpackc_test \ msgpack_test @@ -37,6 +38,8 @@ buffer_LDADD = -lz cases_SOURCES = cases.cc +version_SOURCES = version.cc + msgpackc_test_SOURCES = msgpackc_test.cpp msgpack_test_SOURCES = msgpack_test.cpp From c57f6161415156328bd7039be44895b868ee6f76 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 6 Jul 2010 17:10:25 +0900 Subject: [PATCH 17/26] cpp: adds MSGPACK_VERSION{,_MAJOR,_MINOR} macros and msgpack{,_major,_minor} functions --- cpp/src/Makefile.am | 2 ++ cpp/test/version.cc | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 cpp/test/version.cc diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index 78d14aa3..79b692d4 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -80,6 +80,8 @@ msgpack/version.h: msgpack/version.h.in Makefile.in -e s/VERSION_MINOR_UNDEFINED/$(VERSION_MINOR)/ \ $< > $@ +#version.c: msgpack/version.h + doxygen_c: cat ../Doxyfile > Doxyfile_c diff --git a/cpp/test/version.cc b/cpp/test/version.cc new file mode 100644 index 00000000..9357271e --- /dev/null +++ b/cpp/test/version.cc @@ -0,0 +1,13 @@ +#include +#include + +TEST(version, print) +{ + printf("MSGPACK_VERSION : %s\n", MSGPACK_VERSION); + printf("MSGPACK_VERSION_MAJOR : %d\n", MSGPACK_VERSION_MAJOR); + printf("MSGPACK_VERSION_MINOR : %d\n", MSGPACK_VERSION_MINOR); + printf("msgpack_version() : %s\n", msgpack_version()); + printf("msgpack_version_major() : %d\n", msgpack_version_major()); + printf("msgpack_version_minor() : %d\n", msgpack_version_minor()); +} + From a2bd5ae6386af95617635fec1503640cbadb627b Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 6 Jul 2010 17:45:15 +0900 Subject: [PATCH 18/26] cpp: ./configure supports --disable-cxx option not to build/install C++ API --- cpp/configure.in | 27 ++++++++++++++++++--------- cpp/src/Makefile.am | 14 ++++++++++---- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/cpp/configure.in b/cpp/configure.in index ffe3671e..04fa8e34 100644 --- a/cpp/configure.in +++ b/cpp/configure.in @@ -9,23 +9,31 @@ CFLAGS="-O4 -Wall $CFLAGS" AC_SUBST(CXXFLAGS) CXXFLAGS="-O4 -Wall $CXXFLAGS" + AC_PROG_CC -AC_PROG_CXX + + +AC_MSG_CHECKING([if C++ API is enabled]) +AC_ARG_ENABLE(cxx, + AS_HELP_STRING([--disable-cxx], + [don't build C++ API]) ) +AC_MSG_RESULT([$enable_cxx]) +if test "$enable_cxx" != "no"; then + AC_PROG_CXX + AM_PROG_CC_C_O +fi +AM_CONDITIONAL(ENABLE_CXX, test "$enable_cxx" != "no") + AC_PROG_LIBTOOL AM_PROG_AS -AM_PROG_CC_C_O - -AC_LANG_PUSH([C++]) -AC_CHECK_HEADERS(tr1/unordered_map) -AC_CHECK_HEADERS(tr1/unordered_set) -AC_LANG_POP([C++]) AC_MSG_CHECKING([if debug option is enabled]) AC_ARG_ENABLE(debug, AS_HELP_STRING([--disable-debug], - [disable assert macros and omit -g option.]) ) + [disable assert macros and omit -g option]) ) +AC_MSG_RESULT([$enable_debug]) if test "$enable_debug" != "no"; then CXXFLAGS="$CXXFLAGS -g" CFLAGS="$CFLAGS -g" @@ -33,7 +41,6 @@ else CXXFLAGS="$CXXFLAGS -DNDEBUG" CFLAGS="$CFLAGS -DNDEBUG" fi -AC_MSG_RESULT($enable_debug) AC_CACHE_CHECK([for __sync_* atomic operations], msgpack_cv_atomic_ops, [ @@ -54,10 +61,12 @@ add CFLAGS="--march=i686" and CXXFLAGS="-march=i686" options to ./configure as f ]) fi + major=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'` minor=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'` AC_SUBST(VERSION_MAJOR, $major) AC_SUBST(VERSION_MINOR, $minor) + AC_OUTPUT([Makefile src/Makefile test/Makefile]) diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index 79b692d4..fc673856 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -6,8 +6,12 @@ libmsgpack_la_SOURCES = \ objectc.c \ version.c \ vrefbuffer.c \ - zone.c \ + zone.c + +if ENABLE_CXX +libmsgpack_la_SOURCES += \ object.cpp +endif # -version-info CURRENT:REVISION:AGE libmsgpack_la_LDFLAGS = -version-info 3:0:0 @@ -39,7 +43,10 @@ nobase_include_HEADERS = \ msgpack/pack.h \ msgpack/unpack.h \ msgpack/object.h \ - msgpack/zone.h \ + msgpack/zone.h + +if ENABLE_CXX +nobase_include_HEADERS += \ msgpack.hpp \ msgpack/sbuffer.hpp \ msgpack/version.h \ @@ -66,6 +73,7 @@ nobase_include_HEADERS = \ msgpack/type/define.hpp \ msgpack/type/tr1/unordered_map.hpp \ msgpack/type/tr1/unordered_set.hpp +endif EXTRA_DIST = \ msgpack/version.h.in \ @@ -80,8 +88,6 @@ msgpack/version.h: msgpack/version.h.in Makefile.in -e s/VERSION_MINOR_UNDEFINED/$(VERSION_MINOR)/ \ $< > $@ -#version.c: msgpack/version.h - doxygen_c: cat ../Doxyfile > Doxyfile_c From 39facd5dc660b90304e4d3d593244a5b9f7cd6f0 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 6 Jul 2010 17:59:07 +0900 Subject: [PATCH 19/26] cpp: version 0.5.1 --- cpp/ChangeLog | 10 ++++++++++ cpp/configure.in | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cpp/ChangeLog b/cpp/ChangeLog index 53a99910..3277c139 100644 --- a/cpp/ChangeLog +++ b/cpp/ChangeLog @@ -1,4 +1,14 @@ +2010-07-06 version 0.5.1: + + * Add msgpack_vrefbuffer_new and msgpack_vrefbuffer_free + * Add msgpack_sbuffer_new and msgpack_sbuffer_free + * Add msgpack_unpacker_next and msgpack_unpack_next + * msgpack::unpack returns void + * Add MSGPACK_VERSION{,_MAJOR,_MINOR} macros to check header version + * Add msgpack_version{,_major,_minor} functions to check library version + * ./configure supports --disable-cxx option not to build C++ API + 2010-04-29 version 0.5.0: * msgpack_object_type is changed. MSGPACK_OBJECT_NIL is now 0x00. diff --git a/cpp/configure.in b/cpp/configure.in index 04fa8e34..dd04ed47 100644 --- a/cpp/configure.in +++ b/cpp/configure.in @@ -1,6 +1,6 @@ AC_INIT(src/object.cpp) AC_CONFIG_AUX_DIR(ac) -AM_INIT_AUTOMAKE(msgpack, 0.5.0) +AM_INIT_AUTOMAKE(msgpack, 0.5.1) AC_CONFIG_HEADER(config.h) AC_SUBST(CFLAGS) From 0c331d288715b156f262cdb7841fb0dba4dc5d83 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 6 Jul 2010 18:18:28 +0900 Subject: [PATCH 20/26] cpp: updates vcproj --- cpp/msgpack_vc8.postbuild.bat | 77 ++++++++++++++++++----------------- cpp/msgpack_vc8.vcproj | 40 +++++++++++++----- cpp/src/Makefile.am | 2 +- 3 files changed, 70 insertions(+), 49 deletions(-) diff --git a/cpp/msgpack_vc8.postbuild.bat b/cpp/msgpack_vc8.postbuild.bat index bae13f37..20fabbb9 100644 --- a/cpp/msgpack_vc8.postbuild.bat +++ b/cpp/msgpack_vc8.postbuild.bat @@ -2,42 +2,43 @@ IF NOT EXIST include MKDIR include IF NOT EXIST include\msgpack MKDIR include\msgpack IF NOT EXIST include\msgpack\type MKDIR include\msgpack\type IF NOT EXIST include\msgpack\type\tr1 MKDIR include\msgpack\type\tr1 -copy msgpack\pack_define.h include\msgpack\ -copy msgpack\pack_template.h include\msgpack\ -copy msgpack\unpack_define.h include\msgpack\ -copy msgpack\unpack_template.h include\msgpack\ -copy msgpack\sysdep.h include\msgpack\ -copy msgpack.h include\ -copy msgpack\sbuffer.h include\msgpack\ -copy msgpack\vrefbuffer.h include\msgpack\ -copy msgpack\zbuffer.h include\msgpack\ -copy msgpack\pack.h include\msgpack\ -copy msgpack\unpack.h include\msgpack\ -copy msgpack\object.h include\msgpack\ -copy msgpack\zone.h include\msgpack\ -copy msgpack.hpp include\ -copy msgpack\sbuffer.hpp include\msgpack\ -copy msgpack\vrefbuffer.hpp include\msgpack\ -copy msgpack\zbuffer.hpp include\msgpack\ -copy msgpack\pack.hpp include\msgpack\ -copy msgpack\unpack.hpp include\msgpack\ -copy msgpack\object.hpp include\msgpack\ -copy msgpack\zone.hpp include\msgpack\ -copy msgpack\type.hpp include\msgpack\type\ -copy msgpack\type\bool.hpp include\msgpack\type\ -copy msgpack\type\float.hpp include\msgpack\type\ -copy msgpack\type\int.hpp include\msgpack\type\ -copy msgpack\type\list.hpp include\msgpack\type\ -copy msgpack\type\deque.hpp include\msgpack\type\ -copy msgpack\type\map.hpp include\msgpack\type\ -copy msgpack\type\nil.hpp include\msgpack\type\ -copy msgpack\type\pair.hpp include\msgpack\type\ -copy msgpack\type\raw.hpp include\msgpack\type\ -copy msgpack\type\set.hpp include\msgpack\type\ -copy msgpack\type\string.hpp include\msgpack\type\ -copy msgpack\type\vector.hpp include\msgpack\type\ -copy msgpack\type\tuple.hpp include\msgpack\type\ -copy msgpack\type\define.hpp include\msgpack\type\ -copy msgpack\type\tr1\unordered_map.hpp include\msgpack\type\ -copy msgpack\type\tr1\unordered_set.hpp include\msgpack\type\ +copy src\msgpack\pack_define.h include\msgpack\ +copy src\msgpack\pack_template.h include\msgpack\ +copy src\msgpack\unpack_define.h include\msgpack\ +copy src\msgpack\unpack_template.h include\msgpack\ +copy src\msgpack\sysdep.h include\msgpack\ +copy src\msgpack.h include\ +copy src\msgpack\sbuffer.h include\msgpack\ +copy src\msgpack\version.h include\msgpack\ +copy src\msgpack\vrefbuffer.h include\msgpack\ +copy src\msgpack\zbuffer.h include\msgpack\ +copy src\msgpack\pack.h include\msgpack\ +copy src\msgpack\unpack.h include\msgpack\ +copy src\msgpack\object.h include\msgpack\ +copy src\msgpack\zone.h include\msgpack\ +copy src\msgpack.hpp include\ +copy src\msgpack\sbuffer.hpp include\msgpack\ +copy src\msgpack\vrefbuffer.hpp include\msgpack\ +copy src\msgpack\zbuffer.hpp include\msgpack\ +copy src\msgpack\pack.hpp include\msgpack\ +copy src\msgpack\unpack.hpp include\msgpack\ +copy src\msgpack\object.hpp include\msgpack\ +copy src\msgpack\zone.hpp include\msgpack\ +copy src\msgpack\type.hpp include\msgpack\type\ +copy src\msgpack\type\bool.hpp include\msgpack\type\ +copy src\msgpack\type\float.hpp include\msgpack\type\ +copy src\msgpack\type\int.hpp include\msgpack\type\ +copy src\msgpack\type\list.hpp include\msgpack\type\ +copy src\msgpack\type\deque.hpp include\msgpack\type\ +copy src\msgpack\type\map.hpp include\msgpack\type\ +copy src\msgpack\type\nil.hpp include\msgpack\type\ +copy src\msgpack\type\pair.hpp include\msgpack\type\ +copy src\msgpack\type\raw.hpp include\msgpack\type\ +copy src\msgpack\type\set.hpp include\msgpack\type\ +copy src\msgpack\type\string.hpp include\msgpack\type\ +copy src\msgpack\type\vector.hpp include\msgpack\type\ +copy src\msgpack\type\tuple.hpp include\msgpack\type\ +copy src\msgpack\type\define.hpp include\msgpack\type\ +copy src\msgpack\type\tr1\unordered_map.hpp include\msgpack\type\ +copy src\msgpack\type\tr1\unordered_set.hpp include\msgpack\type\ diff --git a/cpp/msgpack_vc8.vcproj b/cpp/msgpack_vc8.vcproj index 58047909..ed0daa47 100644 --- a/cpp/msgpack_vc8.vcproj +++ b/cpp/msgpack_vc8.vcproj @@ -157,7 +157,7 @@ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > + + + + + + + + @@ -247,23 +267,23 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index fc673856..a6910b4a 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -38,6 +38,7 @@ nobase_include_HEADERS = \ msgpack/sysdep.h \ msgpack.h \ msgpack/sbuffer.h \ + msgpack/version.h \ msgpack/vrefbuffer.h \ msgpack/zbuffer.h \ msgpack/pack.h \ @@ -49,7 +50,6 @@ if ENABLE_CXX nobase_include_HEADERS += \ msgpack.hpp \ msgpack/sbuffer.hpp \ - msgpack/version.h \ msgpack/vrefbuffer.hpp \ msgpack/zbuffer.hpp \ msgpack/pack.hpp \ From fe77251242f34e08f49f41fbbb2561e9278d8635 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 6 Jul 2010 19:16:49 +0900 Subject: [PATCH 21/26] cpp: fixes missing dependency to generate version.h --- cpp/src/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index a6910b4a..e12eb245 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -88,6 +88,8 @@ msgpack/version.h: msgpack/version.h.in Makefile.in -e s/VERSION_MINOR_UNDEFINED/$(VERSION_MINOR)/ \ $< > $@ +version.c: msgpack/version.h + doxygen_c: cat ../Doxyfile > Doxyfile_c From 167e2475d89cb867428b9e7b5aac7f269fd95ecb Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 6 Jul 2010 23:30:15 +0900 Subject: [PATCH 22/26] cpp: generate version.h using AC_OUTPUT macro in ./configure --- cpp/configure.in | 5 ++++- cpp/src/Makefile.am | 9 --------- cpp/src/msgpack/version.h.in | 6 +++--- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/cpp/configure.in b/cpp/configure.in index dd04ed47..ab29501f 100644 --- a/cpp/configure.in +++ b/cpp/configure.in @@ -68,5 +68,8 @@ AC_SUBST(VERSION_MAJOR, $major) AC_SUBST(VERSION_MINOR, $minor) -AC_OUTPUT([Makefile src/Makefile test/Makefile]) +AC_OUTPUT([Makefile + src/Makefile + src/msgpack/version.h + test/Makefile]) diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index e12eb245..31096f0c 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -82,15 +82,6 @@ EXTRA_DIST = \ msgpack/type/tuple.hpp.erb -msgpack/version.h: msgpack/version.h.in Makefile.in - sed -e s/VERSION_UNDEFINED/$(VERSION)/ \ - -e s/VERSION_MAJOR_UNDEFINED/$(VERSION_MAJOR)/ \ - -e s/VERSION_MINOR_UNDEFINED/$(VERSION_MINOR)/ \ - $< > $@ - -version.c: msgpack/version.h - - doxygen_c: cat ../Doxyfile > Doxyfile_c echo "FILE_PATTERNS = *.h" >> Doxyfile_c diff --git a/cpp/src/msgpack/version.h.in b/cpp/src/msgpack/version.h.in index af292d0d..f1feb331 100644 --- a/cpp/src/msgpack/version.h.in +++ b/cpp/src/msgpack/version.h.in @@ -27,9 +27,9 @@ const char* msgpack_version(void); int msgpack_version_major(void); int msgpack_version_minor(void); -#define MSGPACK_VERSION "VERSION_UNDEFINED" -#define MSGPACK_VERSION_MAJOR VERSION_MAJOR_UNDEFINED -#define MSGPACK_VERSION_MINOR VERSION_MINOR_UNDEFINED +#define MSGPACK_VERSION "@VERSION@" +#define MSGPACK_VERSION_MAJOR @VERSION_MAJOR@ +#define MSGPACK_VERSION_MINOR @VERSION_MINOR@ #ifdef __cplusplus From 45fb482ab42c7f47bf65313ade6808d0cfe3bca5 Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Thu, 8 Jul 2010 23:36:18 +0900 Subject: [PATCH 23/26] erlang: added simple performance test. --- erlang/msgpack.erl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index aab07b72..ee993115 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -359,4 +359,9 @@ test_([Before|Rest])-> other_test()-> {more,1}=msgpack:unpack(<<>>). +benchmark_test()-> + Data=[test_data() || _ <- lists:seq(0, 10000)], + S=?debugTime(" serialize", msgpack:pack(Data)), + {Data,<<>>}=?debugTime("deserialize", msgpack:unpack(S)). + -endif. From 485915c27a3ddf12e4ba4c9c0e27769869bb945c Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Thu, 8 Jul 2010 23:39:47 +0900 Subject: [PATCH 24/26] erlang: added simple performance test description. --- erlang/msgpack.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index ee993115..94fed86f 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -362,6 +362,7 @@ other_test()-> benchmark_test()-> Data=[test_data() || _ <- lists:seq(0, 10000)], S=?debugTime(" serialize", msgpack:pack(Data)), - {Data,<<>>}=?debugTime("deserialize", msgpack:unpack(S)). + {Data,<<>>}=?debugTime("deserialize", msgpack:unpack(S)), + ?debugFmt("for ~p KB test data.", [byte_size(S) div 1024]). -endif. From eab66a022e5b5fd9c4731ae8ba970b2146e27599 Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Fri, 9 Jul 2010 01:04:09 +0900 Subject: [PATCH 25/26] erlang: added try-catch clause for easy error handling --- erlang/msgpack.erl | 220 +++++++++++++++++++++++---------------------- 1 file changed, 112 insertions(+), 108 deletions(-) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index 94fed86f..d4fd0ba2 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -19,9 +19,8 @@ -author('kuenishi+msgpack@gmail.com'). %% tuples, atoms are not supported. lists, integers, double, and so on. -%% see http://msgpack.sourceforge.jp/spec for -%% supported formats. APIs are almost compatible -%% for C API (http://msgpack.sourceforge.jp/c:doc) +%% see http://msgpack.sourceforge.jp/spec for supported formats. +%% APIs are almost compatible with C API (http://msgpack.sourceforge.jp/c:doc) %% except buffering functions (both copying and zero-copying). -export([pack/1, unpack/1, unpack_all/1]). -export([pack_map/1]). @@ -30,51 +29,38 @@ % erl> c(msgpack). % erl> S = . % erl> {S, <<>>} = msgpack:unpack( msgpack:pack(S) ). --type reason() :: enomem | badarg | no_code_matches. +-type reason() :: enomem | badarg | no_code_matches | undefined. -type msgpack_term() :: [msgpack_term()] | {[{msgpack_term(),msgpack_term()}]} | integer() | float() | binary(). % ===== external APIs ===== % --spec pack(Term::msgpack_term()) -> binary(). -pack(I) when is_integer(I) andalso I < 0 -> - pack_int_(I); -pack(I) when is_integer(I) -> - pack_uint_(I); -pack(F) when is_float(F) -> - pack_double(F); -pack(nil) -> - << 16#C0:8 >>; -pack(true) -> - << 16#C3:8 >>; -pack(false) -> - << 16#C2:8 >>; -pack(Bin) when is_binary(Bin) -> - pack_raw(Bin); -pack(List) when is_list(List) -> - pack_array(List); -pack({Map}) when is_list(Map) -> - pack_map(Map); -pack(Map) when is_tuple(Map), element(1,Map)=:=dict -> - pack_map(dict:to_list(Map)); -pack(_Other) -> - {error, undefined}. +-spec pack(Term::msgpack_term()) -> binary() | {error, reason()}. +pack(Term)-> + try + pack_(Term) + catch + error:Error when is_tuple(Error), element(1, Error) =:= error -> + Error; + throw:Exception -> + erlang:display(Exception), + {error, Exception} + end. % unpacking. % if failed in decoding and not end, get more data % and feed more Bin into this function. % TODO: error case for imcomplete format when short for any type formats. --spec unpack( Bin::binary() )-> {msgpack_term(), binary()} | - {more, non_neg_integer()} | {more, undefined} | - {error, reason()}. -unpack(Bin) when not is_binary(Bin)-> - {error, badarg}; -unpack(Bin) when bit_size(Bin) >= 8 -> - unpack_(Bin); -unpack(<<>>)-> - {more, 1}; -unpack(_) -> - {more, undefined}. +-spec unpack( Bin::binary() )-> {msgpack_term(), binary()} | {error, reason()}. +unpack(Bin)-> + try + unpack_(Bin) + catch + error:Error when is_tuple(Error), element(1, Error) =:= error -> + Error; + throw:Exception -> + {error, Exception} + end. -spec unpack_all( binary() ) -> [msgpack_term()]. unpack_all(Data)-> @@ -85,7 +71,7 @@ unpack_all(Data)-> [Term|unpack_all(Binary)] end. --spec pack_map(M::[{msgpack_term(),msgpack_term()}])-> binary(). +-spec pack_map(M::[{msgpack_term(),msgpack_term()}])-> binary() | {error, badarg}. pack_map(M)-> case length(M) of Len when Len < 16 -> @@ -98,6 +84,31 @@ pack_map(M)-> % ===== internal APIs ===== % +% pack them all +-spec pack_(msgpack_term()) -> binary() | no_return(). +pack_(I) when is_integer(I) andalso I < 0 -> + pack_int_(I); +pack_(I) when is_integer(I) -> + pack_uint_(I); +pack_(F) when is_float(F) -> + pack_double(F); +pack_(nil) -> + << 16#C0:8 >>; +pack_(true) -> + << 16#C3:8 >>; +pack_(false) -> + << 16#C2:8 >>; +pack_(Bin) when is_binary(Bin) -> + pack_raw(Bin); +pack_(List) when is_list(List) -> + pack_array(List); +pack_({Map}) when is_list(Map) -> + pack_map(Map); +pack_(Map) when is_tuple(Map), element(1,Map)=:=dict -> + pack_map(dict:to_list(Map)); +pack_(_Other) -> + throw({error, undefined}). + % positive fixnum pack_uint_(N) when N < 128 -> << 2#0:1, N:7 >>; @@ -149,7 +160,7 @@ pack_raw(Bin) -> << 16#DB:8, Len:32/big-unsigned-integer-unit:1, Bin/binary >> end. -% list / tuple +% list pack_array(L) -> case length(L) of Len when Len < 16 -> @@ -159,43 +170,40 @@ pack_array(L) -> Len -> << 16#DD:8, Len:32/big-unsigned-integer-unit:1,(pack_array_(L, <<>>))/binary >> end. + pack_array_([], Acc) -> Acc; pack_array_([Head|Tail], Acc) -> - pack_array_(Tail, <>). + pack_array_(Tail, <>). -% FIXME! this should be without lists:reverse/1 -unpack_array_(<<>>, 0, RetList) -> {lists:reverse(RetList), <<>>}; -unpack_array_(Remain, 0, RetList) when is_binary(Remain)-> {lists:reverse(RetList), Remain}; -unpack_array_(<<>>, RestLen, _RetList) when RestLen > 0 -> {more, undefined}; -unpack_array_(Bin, RestLen, RetList) when is_binary(Bin)-> - case unpack(Bin) of - {more, _} -> {more, undefined}; - {Term, Rest}-> unpack_array_(Rest, RestLen-1, [Term|RetList]) - end. +% Users SHOULD NOT send too long list: this uses lists:reverse/1 +unpack_array_(Remain, 0, Acc) when is_binary(Remain)-> {lists:reverse(Acc), Remain}; +unpack_array_(<<>>, RestLen, _) when RestLen > 0 -> throw(short); +unpack_array_(Bin, RestLen, Acc) when is_binary(Bin)-> + {Term, Rest}=unpack_(Bin), + unpack_array_(Rest, RestLen-1, [Term|Acc]). pack_map_([], Acc) -> Acc; pack_map_([{Key,Value}|Tail], Acc) -> - pack_map_(Tail, << Acc/binary, (pack(Key))/binary, (pack(Value))/binary>>). + pack_map_(Tail, << Acc/binary, (pack_(Key))/binary, (pack_(Value))/binary>>). -% FIXME! this should be without lists:reverse/1 --spec unpack_map_(binary(), non_neg_integer(), [{term(), msgpack_term()}])-> - {more, non_neg_integer()} | { any(), binary()}. +% Users SHOULD NOT send too long list: this uses lists:reverse/1 +-spec unpack_map_(binary(), non_neg_integer(), [{msgpack_term(), msgpack_term()}])-> + {[{msgpack_term(), msgpack_term()}], binary()} | no_return(). unpack_map_(Bin, 0, Acc) -> {{lists:reverse(Acc)}, Bin}; +unpack_map_(<<>>, _, _ ) -> throw(short); unpack_map_(Bin, Len, Acc) -> - case unpack(Bin) of - {more, _} -> {more, undefined}; - {Key, Rest} -> - case unpack(Rest) of - {more, _} -> {more, undefined}; - {Value, Rest2} -> - unpack_map_(Rest2,Len-1,[{Key,Value}|Acc]) - end - end. + {Key, Rest} = unpack_(Bin), + {Value, Rest2} = unpack_(Rest), + unpack_map_(Rest2,Len-1,[{Key,Value}|Acc]). --spec unpack_(Payload::binary()) -> - {more, pos_integer()} | {msgpack_term(), binary()} | {error, reason()}. -unpack_(Binary)-> - case Binary of +% unpack then all +-spec unpack_(Bin::binary()) -> {msgpack_term(), binary()} | {error, reason()} | no_return(). +unpack_(Bin) when not is_binary(Bin)-> + throw(badarg); +unpack_(<<>>)-> + throw(short); +unpack_(Bin) when bit_size(Bin) >= 8 -> + case Bin of % ATOMS <<16#C0, Rest/binary>> -> {nil, Rest}; <<16#C2, Rest/binary>> -> {false, Rest}; @@ -231,35 +239,36 @@ unpack_(Binary)-> <<2#1000:4, L:4, Rest/binary>> -> unpack_map_(Rest, L, []); % map % Incomplete / invalid data - <<16#CA, Rest/binary>> -> {more, 4-byte_size(Rest)}; - <<16#CB, Rest/binary>> -> {more, 8-byte_size(Rest)}; - <<16#CC>> -> {more, 1}; - <<16#CD, Rest/binary>> -> {more, 2-byte_size(Rest)}; - <<16#CE, Rest/binary>> -> {more, 4-byte_size(Rest)}; - <<16#CF, Rest/binary>> -> {more, 8-byte_size(Rest)}; - <<16#D0>> -> {more, 1}; - <<16#D1, Rest/binary>> -> {more, 2-byte_size(Rest)}; - <<16#D2, Rest/binary>> -> {more, 4-byte_size(Rest)}; - <<16#D3, Rest/binary>> -> {more, 8-byte_size(Rest)}; - <<16#DA, Rest/binary>> -> {more, 16-byte_size(Rest)}; - <<16#DB, Rest/binary>> -> {more, 32-byte_size(Rest)}; - <<16#DC, Rest/binary>> -> {more, 2-byte_size(Rest)}; - <<16#DD, Rest/binary>> -> {more, 4-byte_size(Rest)}; - <<16#DE, Rest/binary>> -> {more, 2-byte_size(Rest)}; - <<16#DF, Rest/binary>> -> {more, 4-byte_size(Rest)}; - <<2#101:3, L:5, Rest/binary>> -> {more, L-byte_size(Rest)}; +% <<_:16/integer, _/binary>> + _ -> throw(short) +%% <<16#CA, _/binary>> -> {more, 4-byte_size(Rest)}; +%% <<16#CB, Rest/binary>> -> {more, 8-byte_size(Rest)}; +%% <<16#CC>> -> {more, 1}; +%% <<16#CD, Rest/binary>> -> {more, 2-byte_size(Rest)}; +%% <<16#CE, Rest/binary>> -> {more, 4-byte_size(Rest)}; +%% <<16#CF, Rest/binary>> -> {more, 8-byte_size(Rest)}; +%% <<16#D0>> -> {more, 1}; +%% <<16#D1, Rest/binary>> -> {more, 2-byte_size(Rest)}; +%% <<16#D2, Rest/binary>> -> {more, 4-byte_size(Rest)}; +%% <<16#D3, Rest/binary>> -> {more, 8-byte_size(Rest)}; +%% <<16#DA, Rest/binary>> -> {more, 16-byte_size(Rest)}; +%% <<16#DB, Rest/binary>> -> {more, 32-byte_size(Rest)}; +%% <<16#DC, Rest/binary>> -> {more, 2-byte_size(Rest)}; +%% <<16#DD, Rest/binary>> -> {more, 4-byte_size(Rest)}; +%% <<16#DE, Rest/binary>> -> {more, 2-byte_size(Rest)}; +%% <<16#DF, Rest/binary>> -> {more, 4-byte_size(Rest)}; +%% <<2#101:3, L:5, Rest/binary>> -> throw(short); % {more, L-byte_size(Rest)}; - <<>> -> {more, 1}; - <<2#101:3, _/binary>> -> {more, undefined}; - <> when F==16#C1; - F==16#C7; F==16#C8; F==16#C9; F==16#D5; - F==16#D6; F==16#D7; F==16#D8; F==16#D9-> - {error, {badarg, <>}}; - Other -> - {error, {badarg, Other}} +%% <<>> -> throw(short); % {more, 1}; +%% <<2#101:3, _/binary>> -> {more, undefined}; +%% <> when F==16#C1; +%% F==16#C7; F==16#C8; F==16#C9; F==16#D5; +%% F==16#D6; F==16#D7; F==16#D8; F==16#D9-> +%% throw({badarg, <>}); +% Other -> +% throw({unknown, Other}) end. - % ===== test codes ===== % -include_lib("eunit/include/eunit.hrl"). -ifdef(EUNIT). @@ -268,9 +277,15 @@ compare_all([], [])-> ok; compare_all([], R)-> {toomuchrhs, R}; compare_all(L, [])-> {toomuchlhs, L}; compare_all([LH|LTL], [RH|RTL]) -> - LH=RH, + ?assertEqual(LH, RH), compare_all(LTL, RTL). +test_([]) -> 0; +test_([Term|Rest])-> + Pack = msgpack:pack(Term), + ?assertEqual({Term, <<>>}, msgpack:unpack( Pack )), + 1+test_(Rest). + test_data()-> [true, false, nil, 0, 1, 2, 123, 512, 1230, 678908, 16#FFFFFFFFFF, @@ -303,12 +318,7 @@ test_p(Len,Term,OrigBin,Len) -> {Term, <<>>}=msgpack:unpack(OrigBin); test_p(I,_,OrigBin,Len) when I < Len-> <> = OrigBin, - case msgpack:unpack(Bin) of - {more, N} when not is_integer(N) -> - ?assertEqual(undefined, N); - {more, N} -> - ?assert( N < Len ) - end. + ?assertEqual({error,short}, msgpack:unpack(Bin)). partial_test()-> % error handling test. Term = lists:seq(0, 45), @@ -343,21 +353,15 @@ unknown_test()-> 42 ], Port = open_port({spawn, "ruby testcase_generator.rb"}, [binary]), + timer:sleep(1), receive {Port, {data, Data}}-> compare_all(Tests, msgpack:unpack_all(Data)) after 1024-> ?assert(false) end, port_close(Port). -test_([]) -> 0; -test_([Before|Rest])-> - Pack = msgpack:pack(Before), - {After, <<>>} = msgpack:unpack( Pack ), - ?assertEqual(Before, After), - 1+test_(Rest). - other_test()-> - {more,1}=msgpack:unpack(<<>>). + ?assertEqual({error,short},msgpack:unpack(<<>>)). benchmark_test()-> Data=[test_data() || _ <- lists:seq(0, 10000)], From e799082e5c4d39094c666da0f1c52ab2d6eb088c Mon Sep 17 00:00:00 2001 From: UENISHI Kota Date: Fri, 9 Jul 2010 01:21:35 +0900 Subject: [PATCH 26/26] erlang: better test cases, except 'Broken pipe' --- erlang/msgpack.erl | 74 +++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 47 deletions(-) diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index d4fd0ba2..96ea407c 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -142,7 +142,7 @@ pack_int_(N) -> << 16#D3:8, N:64/big-signed-integer-unit:1 >>. % float : erlang's float is always IEEE 754 64bit format. -%pack_float(F) when is_float(F)-> +% pack_float(F) when is_float(F)-> % << 16#CA:8, F:32/big-float-unit:1 >>. % pack_double(F). % double @@ -198,10 +198,7 @@ unpack_map_(Bin, Len, Acc) -> % unpack then all -spec unpack_(Bin::binary()) -> {msgpack_term(), binary()} | {error, reason()} | no_return(). -unpack_(Bin) when not is_binary(Bin)-> - throw(badarg); -unpack_(<<>>)-> - throw(short); +unpack_(Bin) when not is_binary(Bin)-> throw(badarg); unpack_(Bin) when bit_size(Bin) >= 8 -> case Bin of % ATOMS @@ -239,43 +236,31 @@ unpack_(Bin) when bit_size(Bin) >= 8 -> <<2#1000:4, L:4, Rest/binary>> -> unpack_map_(Rest, L, []); % map % Incomplete / invalid data -% <<_:16/integer, _/binary>> - _ -> throw(short) -%% <<16#CA, _/binary>> -> {more, 4-byte_size(Rest)}; -%% <<16#CB, Rest/binary>> -> {more, 8-byte_size(Rest)}; -%% <<16#CC>> -> {more, 1}; -%% <<16#CD, Rest/binary>> -> {more, 2-byte_size(Rest)}; -%% <<16#CE, Rest/binary>> -> {more, 4-byte_size(Rest)}; -%% <<16#CF, Rest/binary>> -> {more, 8-byte_size(Rest)}; -%% <<16#D0>> -> {more, 1}; -%% <<16#D1, Rest/binary>> -> {more, 2-byte_size(Rest)}; -%% <<16#D2, Rest/binary>> -> {more, 4-byte_size(Rest)}; -%% <<16#D3, Rest/binary>> -> {more, 8-byte_size(Rest)}; -%% <<16#DA, Rest/binary>> -> {more, 16-byte_size(Rest)}; -%% <<16#DB, Rest/binary>> -> {more, 32-byte_size(Rest)}; -%% <<16#DC, Rest/binary>> -> {more, 2-byte_size(Rest)}; -%% <<16#DD, Rest/binary>> -> {more, 4-byte_size(Rest)}; -%% <<16#DE, Rest/binary>> -> {more, 2-byte_size(Rest)}; -%% <<16#DF, Rest/binary>> -> {more, 4-byte_size(Rest)}; -%% <<2#101:3, L:5, Rest/binary>> -> throw(short); % {more, L-byte_size(Rest)}; - -%% <<>> -> throw(short); % {more, 1}; -%% <<2#101:3, _/binary>> -> {more, undefined}; -%% <> when F==16#C1; -%% F==16#C7; F==16#C8; F==16#C9; F==16#D5; -%% F==16#D6; F==16#D7; F==16#D8; F==16#D9-> -%% throw({badarg, <>}); -% Other -> -% throw({unknown, Other}) - end. + <> when F==16#CA; F==16#CB; F==16#CC; + F==16#CD; F==16#CE; F==16#CF; + F==16#D0; F==16#D1; F==16#D2; + F==16#D3; F==16#DA; F==16#DB; + F==16#DC; F==16#DD; F==16#DE; + F==16#DF -> + throw(short); + <> when F==16#C1; + F==16#C7; F==16#C8; F==16#C9; + F==16#D5; F==16#D6; F==16#D7; + F==16#D8; F==16#D9 -> + throw(badarg); + _ -> + throw(short) % or unknown/badarg? + end; +unpack_(<<>>)-> throw(short); +unpack_(<<2#101:3, _/binary>>) -> throw(short). % ===== test codes ===== % -include_lib("eunit/include/eunit.hrl"). -ifdef(EUNIT). compare_all([], [])-> ok; -compare_all([], R)-> {toomuchrhs, R}; -compare_all(L, [])-> {toomuchlhs, L}; +compare_all([], R)-> {toomuchrhs, R}; +compare_all(L, [])-> {toomuchlhs, L}; compare_all([LH|LTL], [RH|RTL]) -> ?assertEqual(LH, RH), compare_all(LTL, RTL). @@ -305,9 +290,9 @@ basic_test()-> Passed = length(Tests). port_test()-> + Port = open_port({spawn, "ruby ../test/crosslang.rb"}, [binary]), Tests = test_data(), {[Tests],<<>>} = msgpack:unpack(msgpack:pack([Tests])), - Port = open_port({spawn, "ruby ../test/crosslang.rb"}, [binary]), true = port_command(Port, msgpack:pack(Tests) ), receive {Port, {data, Data}}-> {Tests, <<>>}=msgpack:unpack(Data) @@ -328,10 +313,7 @@ partial_test()-> % error handling test. long_test()-> Longer = lists:seq(0, 655), -% Longest = lists:seq(0,12345), - {Longer, <<>>} = msgpack:unpack(msgpack:pack(Longer)), -% {Longest, <<>>} = msgpack:unpack(msgpack:pack(Longest)). - ok. + {Longer, <<>>} = msgpack:unpack(msgpack:pack(Longer)). map_test()-> Ints = lists:seq(0, 65), @@ -341,6 +323,7 @@ map_test()-> ok. unknown_test()-> + Port = open_port({spawn, "ruby testcase_generator.rb"}, [binary]), Tests = [0, 1, 2, 123, 512, 1230, 678908, -1, -23, -512, -1230, -567898, <<"hogehoge">>, <<"243546rf7g68h798j">>, @@ -348,16 +331,13 @@ unknown_test()-> -234.4355, 1.0e-34, 1.0e64, [23, 234, 0.23], [0,42,<<"sum">>, [1,2]], [1,42, nil, [3]], - {[{1,2},{<<"hoge">>,nil}]}, + {[{1,2},{<<"hoge">>,nil}]}, % map -234, -50000, 42 ], - Port = open_port({spawn, "ruby testcase_generator.rb"}, [binary]), - timer:sleep(1), receive - {Port, {data, Data}}-> - compare_all(Tests, msgpack:unpack_all(Data)) - after 1024-> ?assert(false) end, + {Port, {data, Data}}-> compare_all(Tests, msgpack:unpack_all(Data)) + after 1024-> ?assert(false) end, port_close(Port). other_test()->