From 76a72558b3b876a1aaf0644431cff7dfe6b68b29 Mon Sep 17 00:00:00 2001 From: Vasily Titskiy Date: Thu, 26 May 2011 13:03:57 -0400 Subject: [PATCH 1/6] Fix all unaligned writes on ARM platform --- msgpack/sysdep.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/msgpack/sysdep.h b/msgpack/sysdep.h index 557c7cd6..9544ee3e 100644 --- a/msgpack/sysdep.h +++ b/msgpack/sysdep.h @@ -141,9 +141,25 @@ typedef unsigned int _msgpack_atomic_counter_t; do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0) -#define _msgpack_load16(cast, from) ((cast)_msgpack_be16(*(uint16_t*)from)) -#define _msgpack_load32(cast, from) ((cast)_msgpack_be32(*(uint32_t*)from)) -#define _msgpack_load64(cast, from) ((cast)_msgpack_be64(*(uint64_t*)from)) +#define _msgpack_load16(cast, from) ((cast)_msgpack_be16( \ + (((uint8_t*)from)[1] << 8) | ((uint8_t*)from)[0])) + +#define _msgpack_load32(cast, from) ((cast)_msgpack_be32( \ + (((uint8_t*)from)[3] << 24) | \ + (((uint8_t*)from)[2] << 16) | \ + (((uint8_t*)from)[1] << 8) | \ + (((uint8_t*)from)[0] ) )) + +#define _msgpack_load64(cast, from) ((cast)_msgpack_be64( \ + (((uint64_t)(((uint8_t*)from)[7])) << 56) | \ + (((uint64_t)(((uint8_t*)from)[6])) << 48) | \ + (((uint64_t)(((uint8_t*)from)[5])) << 40) | \ + (((uint64_t)(((uint8_t*)from)[4])) << 32) | \ + (((uint64_t)((uint8_t*)from)[3]) << 24) | \ + (((uint64_t)((uint8_t*)from)[2]) << 16) | \ + (((uint64_t)((uint8_t*)from)[1]) << 8) | \ + (((uint8_t*)from)[0] ))) + #endif /* msgpack/sysdep.h */ From cee09a02614acf00de1a711287c25fdf26e0e4ad Mon Sep 17 00:00:00 2001 From: Vasily Titskiy Date: Thu, 26 May 2011 13:27:25 -0400 Subject: [PATCH 2/6] Add support for GCC 3.x (no _sync* atomic builtins) Use atomic routines from libstdc++ instead. --- cpp/configure.in | 4 +--- cpp/src/Makefile.am | 3 ++- cpp/src/gcc_atomic.cpp | 17 +++++++++++++++++ cpp/src/gcc_atomic.h | 33 +++++++++++++++++++++++++++++++++ msgpack/sysdep.h | 4 ++-- 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 cpp/src/gcc_atomic.cpp create mode 100644 cpp/src/gcc_atomic.h diff --git a/cpp/configure.in b/cpp/configure.in index 95635c3c..cc86cdfd 100644 --- a/cpp/configure.in +++ b/cpp/configure.in @@ -50,9 +50,7 @@ AC_CACHE_CHECK([for __sync_* atomic operations], msgpack_cv_atomic_ops, [ ], [], msgpack_cv_atomic_ops="yes") ]) if test "$msgpack_cv_atomic_ops" != "yes"; then - AC_MSG_ERROR([__sync_* atomic operations are not supported. - -Note that gcc < 4.1 is not supported. + AC_MSG_NOTICE([__sync_* atomic operations are not found. Use libstdc++ instead. If you are using gcc >= 4.1 and the default target CPU architecture is "i386", try to add CFLAGS="-march=i686" and CXXFLAGS="-march=i686" options to ./configure as follows: diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index 0979d235..d96217a5 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -10,7 +10,8 @@ libmsgpack_la_SOURCES = \ if ENABLE_CXX libmsgpack_la_SOURCES += \ - object.cpp + object.cpp \ + gcc_atomic.cpp endif # -version-info CURRENT:REVISION:AGE diff --git a/cpp/src/gcc_atomic.cpp b/cpp/src/gcc_atomic.cpp new file mode 100644 index 00000000..599e832b --- /dev/null +++ b/cpp/src/gcc_atomic.cpp @@ -0,0 +1,17 @@ +#if defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41) + +#include "gcc_atomic.h" +#include + +int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr) +{ + return __gnu_cxx::__exchange_and_add(ptr, -1); +} + +int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr) +{ + return __gnu_cxx::__exchange_and_add(ptr, 1); +} + + +#endif // old gcc workaround diff --git a/cpp/src/gcc_atomic.h b/cpp/src/gcc_atomic.h new file mode 100644 index 00000000..842a48fb --- /dev/null +++ b/cpp/src/gcc_atomic.h @@ -0,0 +1,33 @@ +/* + * 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_GCC_ATOMIC_H__ +#define MSGPACK_GCC_ATOMIC_H__ + +#if defined(__cplusplus) +extern "C" { +#endif + +typedef int _msgpack_atomic_counter_t; + +int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr); +int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr); + + +#if defined(__cplusplus) +} +#endif + + +#endif // MSGPACK_GCC_ATOMIC_H__ diff --git a/msgpack/sysdep.h b/msgpack/sysdep.h index 557c7cd6..1707e900 100644 --- a/msgpack/sysdep.h +++ b/msgpack/sysdep.h @@ -36,19 +36,19 @@ typedef unsigned __int64 uint64_t; #include #endif - #ifdef _WIN32 #define _msgpack_atomic_counter_header typedef long _msgpack_atomic_counter_t; #define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr) #define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr) +#elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41) +#define _msgpack_atomic_counter_header "gcc_atomic.h" #else typedef unsigned int _msgpack_atomic_counter_t; #define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1) #define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1) #endif - #ifdef _WIN32 #ifdef __cplusplus From 177cc55ee5b530469eb5f3af873538f3c09d50ee Mon Sep 17 00:00:00 2001 From: Kazuki Ohta Date: Sun, 12 Jun 2011 14:44:57 +0900 Subject: [PATCH 3/6] s/msgpack.sourceforge.net/msgpack.org/ --- README.md | 10 +++++----- java/ivy.xml | 2 +- php/README | 2 +- ruby/msgpack.gemspec | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 066c45e4..1ec453e1 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Typical small integer (like flags or error code) is saved only in 1 byte, and ty ## Performance -![Serialization + Deserialization Speed Test](http://msgpack.sourceforge.net/index/speedtest.png) +![Serialization + Deserialization Speed Test](http://msgpack.org/index/speedtest.png) In this test, it measured the elapsed time of serializing and deserializing 200,000 target objects. The target object consists of the three integers and 512 bytes string. The source code of this test is available from [frsyuki' serializer-speed-test repository.](http://github.com/frsyuki/serializer-speed-test) @@ -24,14 +24,14 @@ The source code of this test is available from [frsyuki' serializer-speed-test r ## Getting Started -Usage and other documents about implementations in each language are found at [the web site.](http://msgpack.sourceforge.net/) +Usage and other documents about implementations in each language are found at [the web site.](http://msgpack.org/) ## Learn More - - [Project Web Site](http://msgpack.sourceforge.net/) - - [MessagePack format specification](http://msgpack.sourceforge.net/spec) + - [Project Web Site](http://msgpack.org/) + - [MessagePack format specification](http://wiki.msgpack.org/display/MSGPACK/Format+specification) - [Repository at github](http://github.com/msgpack/msgpack) - - [Wiki](http://msgpack.sourceforge.net/start) + - [Wiki](http://wiki.msgpack.org/display/MSGPACK/Home) - [MessagePack-RPC](http://github.com/msgpack/msgpack-rpc) diff --git a/java/ivy.xml b/java/ivy.xml index 2c8b727f..18ebe08e 100644 --- a/java/ivy.xml +++ b/java/ivy.xml @@ -3,7 +3,7 @@ - + MessagePack diff --git a/php/README b/php/README index ac8e4857..6e22a92d 100644 --- a/php/README +++ b/php/README @@ -8,4 +8,4 @@ But unlike JSON, it is very fast and small. Resources --------- - * [msgpack](http://msgpack.sourceforge.net/) + * [msgpack](http://msgpack.org/) diff --git a/ruby/msgpack.gemspec b/ruby/msgpack.gemspec index 95a2bd0a..942c4bb0 100644 --- a/ruby/msgpack.gemspec +++ b/ruby/msgpack.gemspec @@ -6,7 +6,7 @@ Gem::Specification.new do |s| s.summary = "MessagePack, a binary-based efficient data interchange format." s.author = "FURUHASHI Sadayuki" s.email = "frsyuki@users.sourceforge.jp" - s.homepage = "http://msgpack.sourceforge.net/" + s.homepage = "http://msgpack.org/" s.rubyforge_project = "msgpack" s.has_rdoc = true s.rdoc_options = ["ext"] From e5e2b9095c239b5c1e93b56dc7a3de3a36787086 Mon Sep 17 00:00:00 2001 From: FURUHASHI Sadayuki Date: Sun, 12 Jun 2011 14:47:29 +0900 Subject: [PATCH 4/6] updated README.md --- README.md | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1ec453e1..cd6d876e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Extremely efficient object serialization library. It's like JSON, but very fast ## What's MessagePack? -MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small. +**MessagePack** is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small. Typical small integer (like flags or error code) is saved only in 1 byte, and typical short string only needs 1 byte except the length of the string itself. \[1,2,3\] (3 elements array) is serialized in 4 bytes using MessagePack as follows: @@ -13,13 +13,19 @@ Typical small integer (like flags or error code) is saved only in 1 byte, and ty msg = [1,2,3].to_msgpack #=> "\x93\x01\x02\x03" MessagePack.unpack(msg) #=> [1,2,3] +**MessagePack-RPC** is cross-language RPC library for client, server and cluster applications. Because it releases you from complicated network programming completely and provides well-designed API, you can easily implement advanced network applications with MessagePack-RPC. -## Performance + require 'msgpack/rpc' + class MyHandler + def add(x,y) return x+y end + end + svr = MessagePack::RPC::Server.new + svr.listen('0.0.0.0', 18800, MyHandler.new) + svr.run -![Serialization + Deserialization Speed Test](http://msgpack.org/index/speedtest.png) - -In this test, it measured the elapsed time of serializing and deserializing 200,000 target objects. The target object consists of the three integers and 512 bytes string. -The source code of this test is available from [frsyuki' serializer-speed-test repository.](http://github.com/frsyuki/serializer-speed-test) + require 'msgpack/rpc' + c = MessagePack::RPC::Client.new('127.0.0.1',18800) + result = c.call(:add, 1, 2) #=> 3 ## Getting Started @@ -29,9 +35,8 @@ Usage and other documents about implementations in each language are found at [t ## Learn More - - [Project Web Site](http://msgpack.org/) - - [MessagePack format specification](http://wiki.msgpack.org/display/MSGPACK/Format+specification) - - [Repository at github](http://github.com/msgpack/msgpack) + - [Web Site](http://msgpack.org/) - [Wiki](http://wiki.msgpack.org/display/MSGPACK/Home) - - [MessagePack-RPC](http://github.com/msgpack/msgpack-rpc) + - [Issues](http://jira.msgpack.org/browse/MSGPACK) + - [Sources](https://github.com/msgpack) From cc0114c482ea1adc9415370b6b94c61498ae77cf Mon Sep 17 00:00:00 2001 From: FURUHASHI Sadayuki Date: Sun, 12 Jun 2011 15:16:13 +0900 Subject: [PATCH 5/6] cpp: fixed configure.in for gcc 3.x support --- cpp/configure.in | 30 ++++++++++++++++++++++++++++-- cpp/src/Makefile.am | 7 ++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/cpp/configure.in b/cpp/configure.in index cc86cdfd..b05f9183 100644 --- a/cpp/configure.in +++ b/cpp/configure.in @@ -16,7 +16,7 @@ AC_PROG_CC AC_MSG_CHECKING([if C++ API is enabled]) AC_ARG_ENABLE(cxx, AS_HELP_STRING([--disable-cxx], - [don't build C++ API]) ) + [don't build C++ API]) ) #' AC_MSG_RESULT([$enable_cxx]) if test "$enable_cxx" != "no"; then AC_PROG_CXX @@ -50,15 +50,41 @@ AC_CACHE_CHECK([for __sync_* atomic operations], msgpack_cv_atomic_ops, [ ], [], msgpack_cv_atomic_ops="yes") ]) if test "$msgpack_cv_atomic_ops" != "yes"; then - AC_MSG_NOTICE([__sync_* atomic operations are not found. Use libstdc++ instead. + if test "$enable_cxx" = "no"; then + AC_MSG_ERROR([__sync_* atomic operations are not found. Try to enable C++ support. +If you are using gcc >= 4.1 and the default target CPU architecture is "i386", try to +add CFLAGS="-march=i686" and CXXFLAGS="-march=i686" options to ./configure as follows: + + $ ./configure CFLAGS="-march=i686" CXXFLAGS="-march=i686" + ]) + fi + + AC_LANG_PUSH([C++]) + AC_CACHE_CHECK([for __gnu_cxx::__exchange_and_add], msgpack_cv_gcc_cxx_atomic_ops, [ + AC_TRY_LINK([ + #include + int atomic_sub(int i) { return __gnu_cxx::__exchange_and_add(&i, -1); } + int atomic_add(int i) { return __gnu_cxx::__exchange_and_add(&i, 1); } + ], [], msgpack_cv_gcc_cxx_atomic_ops="yes") + ]) + AC_LANG_POP([C++]) + + if test "$msgpack_cv_gcc_cxx_atomic_ops" != "yes"; then + AC_MSG_ERROR([__sync_* atomic operations nor __gnu_cxx::__exchange_and_add are not found. If you are using gcc >= 4.1 and the default target CPU architecture is "i386", try to add CFLAGS="-march=i686" and CXXFLAGS="-march=i686" options to ./configure as follows: $ ./configure CFLAGS="-march=i686" CXXFLAGS="-march=i686" ]) + + else + enable_gcc_cxx_atomic=yes + fi fi +AM_CONDITIONAL(ENABLE_GCC_CXX_ATOMIC, test "$enable_gcc_cxx_atomic" = "yes") + major=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'` minor=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'` diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index d96217a5..4a5dae26 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -10,10 +10,15 @@ libmsgpack_la_SOURCES = \ if ENABLE_CXX libmsgpack_la_SOURCES += \ - object.cpp \ + object.cpp +endif + +if ENABLE_GCC_CXX_ATOMIC +libmsgpack_la_SOURCES += \ gcc_atomic.cpp endif + # -version-info CURRENT:REVISION:AGE libmsgpack_la_LDFLAGS = -version-info 3:0:0 From 2f80e154f2d7eb8b677d5dea0de78d0ef102e0ac Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 24 Jun 2011 00:04:43 +0900 Subject: [PATCH 6/6] (python) Fix typo in ChangeLog --- python/ChangeLog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ChangeLog.rst b/python/ChangeLog.rst index a0aae257..10ddf4f0 100644 --- a/python/ChangeLog.rst +++ b/python/ChangeLog.rst @@ -4,7 +4,7 @@ New feature ----------- -* Add ``encoding`` and ``unicode_erros`` option to packer and unpacker. +* Add ``encoding`` and ``unicode_errors`` option to packer and unpacker. When this option is specified, (un)packs unicode object instead of bytes. This enables using msgpack as a replacement of json.