Merge branch 'master' of frsyuki@git.sourceforge.jp:/gitroot/msgpack/msgpack

This commit is contained in:
frsyuki 2010-02-18 14:31:41 +09:00
commit 2c8048115d
53 changed files with 509 additions and 430 deletions

8
README
View File

@ -19,12 +19,12 @@ Binary-based efficient data interchange format.
$ make $ make
$ sudo make install $ sudo make install
To install Ruby binding, run ./gengem.sh script on ruby/ directory and install To install Ruby binding, run ./makegem.sh script on ruby/ directory and install
generated gem package. generated gem package.
$ cd ruby $ cd ruby
$ ./gengem.sh $ ./makegem.sh
$ gem install gem/pkg/msgpack-*.gem $ gem install msgpack-*.gem
*Usage *Usage
@ -54,7 +54,7 @@ Binary-based efficient data interchange format.
API Document is available at http://msgpack.sourceforge.jp/. API Document is available at http://msgpack.sourceforge.jp/.
Copyright (C) 2008-2009 FURUHASHI Sadayuki Copyright (C) 2008-2010 FURUHASHI Sadayuki
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -23,6 +23,6 @@ check_PROGRAMS = \
msgpackc_test_SOURCES = test.cpp msgpackc_test_SOURCES = test.cpp
msgpackc_test_CXXFLAGS = -I$(top_srcdir) -I$(top_srcdir)/c msgpackc_test_CXXFLAGS = -I$(top_srcdir) -I$(top_srcdir)/c
msgpackc_test_LDFLAGS = libmsgpackc.la -lgtest_main msgpackc_test_LDADD = libmsgpackc.la -lgtest_main
TESTS = $(check_PROGRAMS) TESTS = $(check_PROGRAMS)

View File

@ -1 +0,0 @@
.

View File

@ -19,7 +19,6 @@
#define MSGPACK_OBJECT_H__ #define MSGPACK_OBJECT_H__
#include "msgpack/zone.h" #include "msgpack/zone.h"
#include "msgpack/sysdep.h"
#include <stdio.h> #include <stdio.h>
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -18,6 +18,7 @@
#ifndef MSGPACK_ZONE_H__ #ifndef MSGPACK_ZONE_H__
#define MSGPACK_ZONE_H__ #define MSGPACK_ZONE_H__
#include "msgpack/sysdep.h"
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>

View File

@ -30,7 +30,7 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
vbuf->chunk_size = chunk_size; vbuf->chunk_size = chunk_size;
vbuf->ref_size = ref_size; vbuf->ref_size = ref_size;
// glibcは72バイト以下のmallocが高速 // glibcは72バイト以下のmallocが高速
size_t nfirst = (sizeof(struct iovec) < 72/2) ? size_t nfirst = (sizeof(struct iovec) < 72/2) ?
72 / sizeof(struct iovec) : 8; 72 / sizeof(struct iovec) : 8;

View File

@ -104,7 +104,6 @@ static inline void init_finalizer_array(msgpack_zone_finalizer_array* fa)
static inline void call_finalizer_array(msgpack_zone_finalizer_array* fa) static inline void call_finalizer_array(msgpack_zone_finalizer_array* fa)
{ {
// 逆順に呼び出し
msgpack_zone_finalizer* fin = fa->tail; msgpack_zone_finalizer* fin = fa->tail;
for(; fin != fa->array; --fin) { for(; fin != fa->array; --fin) {
(*(fin-1)->func)((fin-1)->data); (*(fin-1)->func)((fin-1)->data);
@ -132,9 +131,6 @@ bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone,
size_t nnext; size_t nnext;
if(nused == 0) { if(nused == 0) {
// 初回の呼び出しfa->tail == fa->end == fa->array == NULL
// glibcは72バイト以下のmallocが高速
nnext = (sizeof(msgpack_zone_finalizer) < 72/2) ? nnext = (sizeof(msgpack_zone_finalizer) < 72/2) ?
72 / sizeof(msgpack_zone_finalizer) : 8; 72 / sizeof(msgpack_zone_finalizer) : 8;

View File

@ -36,16 +36,18 @@ AC_CHECK_HEADERS(tr1/unordered_set)
AC_LANG_POP([C++]) AC_LANG_POP([C++])
AC_CACHE_CHECK([for __sync_* atomic operations], msgpack_cv_atomic_ops, [ AC_CACHE_CHECK([for __sync_* atomic operations], msgpack_cv_atomic_ops, [
AC_TRY_LINK([ AC_TRY_LINK([
int atomic_sub(int i) { return __sync_sub_and_fetch(&i, 1); } int atomic_sub(int i) { return __sync_sub_and_fetch(&i, 1); }
int atomic_add(int i) { return __sync_add_and_fetch(&i, 1); } int atomic_add(int i) { return __sync_add_and_fetch(&i, 1); }
], [], msgpack_cv_atomic_ops="yes") ], [], msgpack_cv_atomic_ops="yes")
]) ])
if test "$msgpack_cv_atomic_ops" != "yes"; then if test "$msgpack_cv_atomic_ops" != "yes"; then
AC_MSG_ERROR([__sync_* atomic operations are not supported. AC_MSG_ERROR([__sync_* atomic operations are not supported.
Note that gcc < 4.1 is not supported. Note that gcc < 4.1 is not supported.
If you are using gcc-4.1 and the CPU architecture is x86, try to add
CFLAGS"--march=i686" and CXXFLAGS="-march=i668" options to ./configure as follows: If you are using gcc >= 4.1 and the default target CPU architecture is "i386", try to
add CFLAGS="--march=i686" and CXXFLAGS="-march=i668" options to ./configure as follows:
$ ./configure CFLAGS="-march=i686" CXXFLAGS="-march=i686" $ ./configure CFLAGS="-march=i686" CXXFLAGS="-march=i686"
]) ])

View File

@ -39,6 +39,6 @@ check_PROGRAMS = \
msgpack_test_SOURCES = test.cpp msgpack_test_SOURCES = test.cpp
msgpack_test_CXXFLAGS = -I$(top_srcdir) -I$(top_srcdir)/c -I$(top_srcdir)/cpp msgpack_test_CXXFLAGS = -I$(top_srcdir) -I$(top_srcdir)/c -I$(top_srcdir)/cpp
msgpack_test_LDFLAGS = libmsgpack.la -lgtest_main msgpack_test_LDADD = libmsgpack.la -lgtest_main
TESTS = $(check_PROGRAMS) TESTS = $(check_PROGRAMS)

View File

@ -1 +0,0 @@
.

View File

@ -29,11 +29,15 @@ inline std::vector<T>& operator>> (object o, std::vector<T>& v)
{ {
if(o.type != type::ARRAY) { throw type_error(); } if(o.type != type::ARRAY) { throw type_error(); }
v.resize(o.via.array.size); v.resize(o.via.array.size);
object* p = o.via.array.ptr; if(o.via.array.size > 0) {
object* const pend = o.via.array.ptr + o.via.array.size; object* p = o.via.array.ptr;
T* it = &v.front(); object* const pend = o.via.array.ptr + o.via.array.size;
for(; p < pend; ++p, ++it) { T* it = &v[0];
p->convert(it); do {
p->convert(it);
++p;
++it;
} while(p < pend);
} }
return v; return v;
} }

View File

@ -438,7 +438,7 @@ TEST(MSGPACK_STL, simple_buffer_multiset)
#ifdef HAVE_TR1_UNORDERED_MAP #ifdef HAVE_TR1_UNORDERED_MAP
#include <tr1/unordered_map> #include <tr1/unordered_map>
#include "cpp/type/tr1/unordered_map.hpp" #include "cpp/msgpack/type/tr1/unordered_map.hpp"
TEST(MSGPACK_TR1, simple_buffer_unordered_map) TEST(MSGPACK_TR1, simple_buffer_unordered_map)
{ {
for (unsigned int k = 0; k < kLoop; k++) { for (unsigned int k = 0; k < kLoop; k++) {
@ -499,7 +499,7 @@ TEST(MSGPACK_TR1, simple_buffer_unordered_multimap)
#ifdef HAVE_TR1_UNORDERED_SET #ifdef HAVE_TR1_UNORDERED_SET
#include <tr1/unordered_set> #include <tr1/unordered_set>
#include "cpp/type/tr1/unordered_set.hpp" #include "cpp/msgpack/type/tr1/unordered_set.hpp"
TEST(MSGPACK_TR1, simple_buffer_unordered_set) TEST(MSGPACK_TR1, simple_buffer_unordered_set)
{ {
for (unsigned int k = 0; k < kLoop; k++) { for (unsigned int k = 0; k < kLoop; k++) {

View File

@ -48,6 +48,17 @@ typedef unsigned int _msgpack_atomic_counter_t;
#ifdef _WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#ifdef __cplusplus
/* numeric_limits<T>::min,max */
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
#endif
#else #else
#include <arpa/inet.h> /* __BYTE_ORDER */ #include <arpa/inet.h> /* __BYTE_ORDER */
#endif #endif

275
msgpack_vc8.vcproj Normal file
View File

@ -0,0 +1,275 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="MessagePack"
ProjectGUID="{122A2EA4-B283-4241-9655-786DE78283B2}"
RootNamespace="MessagePack"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="cpp;c;."
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
MinimalRebuild="true"
BasicRuntimeChecks="1"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="cpp;c;."
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="ソース ファイル"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\c\object.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\$(InputName)1.obj"
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\$(InputName)1.obj"
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
CompileAs="2"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\cpp\object.cpp"
>
</File>
<File
RelativePath=".\c\unpack.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\c\vrefbuffer.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\c\zone.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="ヘッダー ファイル"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\msgpack\pack_define.h"
>
</File>
<File
RelativePath=".\msgpack\pack_template.h"
>
</File>
<File
RelativePath=".\msgpack\sysdep.h"
>
</File>
<File
RelativePath=".\msgpack\unpack_define.h"
>
</File>
<File
RelativePath=".\msgpack\unpack_template.h"
>
</File>
</Filter>
<Filter
Name="リソース ファイル"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -2,7 +2,7 @@
MessagePack Python Binding MessagePack Python Binding
=========================== ===========================
:author: Naoki INADA :author: INADA Naoki
:version: 0.1.0 :version: 0.1.0
:date: 2009-07-12 :date: 2009-07-12
@ -32,7 +32,11 @@ MinGW GCC.
TEST TEST
---- ----
MessagePack uses nosetest for testing. MessagePack uses `nosetest` for testing.
Run test with following command: Run test with following command:
$ nosetests test $ nosetests test
..
vim: filetype=rst

View File

@ -1,16 +1,41 @@
#!/usr/bin/env python #!/usr/bin/env python
# coding: utf-8 # coding: utf-8
from distutils.core import setup, Extension
#from Cython.Distutils import build_ext
import os import os
from glob import glob
from distutils.core import setup, Extension
from distutils.command.sdist import sdist
try:
from Cython.Distutils import build_ext
import Cython.Compiler.Main as cython_compiler
have_cython = True
except ImportError:
from distutils.command.build_ext import build_ext
have_cython = False
version = '0.2.0dev' version = '0.2.0dev'
# take care of extension modules.
if have_cython:
sources = ['msgpack/_msgpack.pyx']
class Sdist(sdist):
def __init__(self, *args, **kwargs):
for src in glob('msgpack/*.pyx'):
cython_compiler.compile(glob('msgpack/*.pyx'),
cython_compiler.default_options)
sdist.__init__(self, *args, **kwargs)
else:
sources = ['msgpack/_msgpack.c']
Sdist = sdist
msgpack_mod = Extension('msgpack._msgpack', msgpack_mod = Extension('msgpack._msgpack',
#sources=['msgpack/_msgpack.pyx'] sources=sources,
sources=['msgpack/_msgpack.c']
) )
del sources
desc = 'MessagePack (de)serializer.' desc = 'MessagePack (de)serializer.'
long_desc = desc + """ long_desc = desc + """
@ -26,14 +51,15 @@ What's MessagePack? (from http://msgpack.sourceforge.jp/)
""" """
setup(name='msgpack', setup(name='msgpack',
author='Naoki INADA', author='INADA Naoki',
author_email='songofacandy@gmail.com', author_email='songofacandy@gmail.com',
version=version, version=version,
#cmdclass={'build_ext': build_ext}, cmdclass={'build_ext': build_ext, 'sdist': Sdist},
ext_modules=[msgpack_mod], ext_modules=[msgpack_mod],
packages=['msgpack'], packages=['msgpack'],
description=desc, description=desc,
long_description=long_desc, long_description=long_desc,
url="http://msgpack.sourceforge.jp/",
classifiers=[ classifiers=[
'Development Status :: 4 - Beta', 'Development Status :: 4 - Beta',
'Intended Audience :: Developers', 'Intended Audience :: Developers',

View File

@ -1,41 +0,0 @@
#!/usr/bin/env python
# coding: utf-8
from distutils.core import setup, Extension
from Cython.Distutils import build_ext
import os
version = '0.2.0dev'
msgpack_mod = Extension('msgpack._msgpack',
sources=['msgpack/_msgpack.pyx']
)
desc = 'MessagePack (de)serializer.'
long_desc = desc + """
MessagePack_ (de)serializer for Python.
.. _MessagePack: http://msgpack.sourceforge.jp/
What's MessagePack? (from http://msgpack.sourceforge.jp/)
MessagePack is a binary-based efficient data interchange format that is
focused on high performance. It is like JSON, but very fast and small.
"""
setup(name='msgpack',
author='Naoki INADA',
author_email='songofacandy@gmail.com',
version=version,
cmdclass={'build_ext': build_ext},
ext_modules=[msgpack_mod],
packages=['msgpack'],
description=desc,
long_description=long_desc,
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
]
)

View File

@ -1,133 +0,0 @@
require 'rubygems'
require 'rake'
require 'rake/clean'
require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rake/contrib/rubyforgepublisher'
require 'rake/contrib/sshpublisher'
require 'fileutils'
include FileUtils
NAME = "msgpack"
AUTHOR = "FURUHASHI Sadayuki"
EMAIL = "frsyuki _at_ users.sourceforge.jp"
DESCRIPTION = "Binary-based efficient data interchange format."
RUBYFORGE_PROJECT = "msgpack"
HOMEPATH = "http://msgpack.sourceforge.jp/"
BIN_FILES = %w( )
VERS = "0.3.2"
#REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
REV = nil
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
RDOC_OPTS = [
'--title', "#{NAME} documentation",
"--charset", "utf-8",
"--opname", "index.html",
"--line-numbers",
"--main", "README",
"--inline-source",
]
task :default => [:test]
task :package => [:clean]
Rake::TestTask.new("test") do |t|
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.verbose = true
end
spec = Gem::Specification.new do |s|
s.name = NAME
s.version = VERS
s.platform = Gem::Platform::RUBY
s.has_rdoc = false
s.extra_rdoc_files = ["README", "ChangeLog", "AUTHORS"]
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
s.summary = DESCRIPTION
s.description = DESCRIPTION
s.author = AUTHOR
s.email = EMAIL
s.homepage = HOMEPATH
s.executables = BIN_FILES
s.rubyforge_project = RUBYFORGE_PROJECT
s.bindir = "bin"
s.require_path = "ext"
s.autorequire = ""
s.test_files = Dir["test/test_*.rb"]
#s.add_dependency('activesupport', '>=1.3.1')
#s.required_ruby_version = '>= 1.8.2'
s.files = %w(README ChangeLog Rakefile) +
Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
Dir.glob("ext/**/*.{h,c,rb}") +
Dir.glob("examples/**/*.rb") +
Dir.glob("tools/*.rb") +
Dir.glob("msgpack/*.h")
s.extensions = FileList["ext/**/extconf.rb"].to_a
end
Rake::GemPackageTask.new(spec) do |p|
p.need_tar = true
p.gem_spec = spec
end
task :install do
name = "#{NAME}-#{VERS}.gem"
sh %{rake package}
sh %{sudo gem install pkg/#{name}}
end
task :uninstall => [:clean] do
sh %{sudo gem uninstall #{NAME}}
end
#Rake::RDocTask.new do |rdoc|
# rdoc.rdoc_dir = 'html'
# rdoc.options += RDOC_OPTS
# rdoc.template = "resh"
# #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
# if ENV['DOC_FILES']
# rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
# else
# rdoc.rdoc_files.include('README', 'ChangeLog')
# rdoc.rdoc_files.include('lib/**/*.rb')
# rdoc.rdoc_files.include('ext/**/*.c')
# end
#end
desc "Publish to RubyForge"
task :rubyforge => [:rdoc, :package] do
require 'rubyforge'
Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'frsyuki').upload
end
desc 'Package and upload the release to rubyforge.'
task :release => [:clean, :package] do |t|
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
pkg = "pkg/#{NAME}-#{VERS}"
rf = RubyForge.new
puts "Logging in"
rf.login
c = rf.userconfig
# c["release_notes"] = description if description
# c["release_changes"] = changes if changes
c["preformatted"] = true
files = [
"#{pkg}.tgz",
"#{pkg}.gem"
].compact
puts "Releasing #{NAME} v. #{VERS}"
rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
end

View File

@ -1,21 +0,0 @@
#!/bin/sh
mkdir -p gem/ext
mkdir -p gem/msgpack
cp extconf.rb gem/ext/
cp pack.c gem/ext/
cp pack.h gem/ext/
cp rbinit.c gem/ext/
cp unpack.c gem/ext/
cp unpack.h gem/ext/
cat test_case.rb | sed "s/require ['\"]msgpack['\"]/require File.dirname(__FILE__) + '\/test_helper.rb'/" > gem/test/msgpack_test.rb
cp ../AUTHORS gem/AUTHORS
cp ../ChangeLog gem/ChangeLog
cp ../msgpack/pack_define.h gem/msgpack/
cp ../msgpack/pack_template.h gem/msgpack/
cp ../msgpack/unpack_define.h gem/msgpack/
cp ../msgpack/unpack_template.h gem/msgpack/
cp ../msgpack/sysdep.h gem/msgpack/
cd gem && rake --trace package

21
ruby/makegem.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/sh
mkdir -p ext
mkdir -p msgpack
cp extconf.rb ext/
cp pack.c ext/
cp pack.h ext/
cp rbinit.c ext/
cp unpack.c ext/
cp unpack.h ext/
cp ../AUTHORS ./
cp ../ChangeLog ./
cp ../msgpack/pack_define.h msgpack/
cp ../msgpack/pack_template.h msgpack/
cp ../msgpack/unpack_define.h msgpack/
cp ../msgpack/unpack_template.h msgpack/
cp ../msgpack/sysdep.h msgpack/
cat msgpack_test.rb | sed "s/require ['\"]msgpack['\"]/require File.dirname(__FILE__) + '\/test_helper.rb'/" > test/msgpack_test.rb
gem build msgpack.gemspec

26
ruby/msgpack.gemspec Executable file → Normal file
View File

@ -1,12 +1,16 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.platform = Gem::Platform::CURRENT s.platform = Gem::Platform::RUBY
s.name = "msgpack" s.name = "msgpack"
s.version = "0.3.2" s.version = "0.3.3"
s.summary = "MessagePack" s.summary = "MessagePack, a binary-based efficient data interchange format."
s.author = "FURUHASHI Sadayuki" s.author = "FURUHASHI Sadayuki"
s.email = "frsyuki@users.sourceforge.jp" s.email = "frsyuki@users.sourceforge.jp"
s.homepage = "http://msgpack.sourceforge.jp/" s.homepage = "http://msgpack.sourceforge.jp/"
s.rubyforge_project = "msgpack" s.rubyforge_project = "msgpack"
s.require_paths = ["lib", "ext"] s.has_rdoc = false
s.files = ["lib/**/*", "ext/**/*"].map {|g| Dir.glob(g) }.flatten s.extra_rdoc_files = ["README", "ChangeLog", "AUTHORS"]
s.require_paths = ["lib", "ext"]
s.files = Dir["lib/**/*", "ext/**/*", "msgpack/**/*", "test/**/*"]
s.test_files = Dir["test/test_*.rb"]
s.extensions = Dir["ext/**/extconf.rb"]
end end

View File

@ -1,122 +0,0 @@
require 'msgpack'
@up = MessagePack::Unpacker.new
def check(bytes, should)
puts "----"
@up.reset
src = bytes.pack('C*')
ret = @up.execute(src, 0)
if ret != src.length
puts "** EXTRA BYTES **"
end
puts bytes.map{|x|"%x"%x}.join(' ')
data = @up.data
p data
if data != should
puts "** TEST FAILED **"
p should
end
end
# SimpleValue
check([
0x93, 0xc0, 0xc2, 0xc3,
], [nil,false,true])
# Fixnum
check([
0x92,
0x93, 0x00, 0x40, 0x7f,
0x93, 0xe0, 0xf0, 0xff,
], [[0,64,127], [-32,-16,-1]])
# FixArray
check([
0x92,
0x90,
0x91,
0x91, 0xc0,
], [[],[[nil]]])
# FixRaw
check([
0x94,
0xa0,
0xa1, ?a,
0xa2, ?b, ?c,
0xa3, ?d, ?e, ?f,
], ["","a","bc","def"])
# FixMap
check([
0x82,
0xc2, 0x81,
0xc0, 0xc0,
0xc3, 0x81,
0xc0, 0x80,
], {false=>{nil=>nil}, true=>{nil=>{}}})
# unsigned int
check([
0x99,
0xcc, 0,
0xcc, 128,
0xcc, 255,
0xcd, 0x00, 0x00,
0xcd, 0x80, 0x00,
0xcd, 0xff, 0xff,
0xce, 0x00, 0x00, 0x00, 0x00,
0xce, 0x80, 0x00, 0x00, 0x00,
0xce, 0xff, 0xff, 0xff, 0xff,
], [0, 128, 255, 0, 32768, 65535, 0, 2147483648, 4294967295])
# signed int
check([
0x99,
0xd0, 0,
0xd0, 128,
0xd0, 255,
0xd1, 0x00, 0x00,
0xd1, 0x80, 0x00,
0xd1, 0xff, 0xff,
0xd2, 0x00, 0x00, 0x00, 0x00,
0xd2, 0x80, 0x00, 0x00, 0x00,
0xd2, 0xff, 0xff, 0xff, 0xff,
], [0, -128, -1, 0, -32768, -1, 0, -2147483648, -1])
# raw
check([
0x96,
0xda, 0x00, 0x00,
0xda, 0x00, 0x01, ?a,
0xda, 0x00, 0x02, ?a, ?b,
0xdb, 0x00, 0x00, 0x00, 0x00,
0xdb, 0x00, 0x00, 0x00, 0x01, ?a,
0xdb, 0x00, 0x00, 0x00, 0x02, ?a, ?b,
], ["", "a", "ab", "", "a", "ab"])
# array
check([
0x96,
0xdc, 0x00, 0x00,
0xdc, 0x00, 0x01, 0xc0,
0xdc, 0x00, 0x02, 0xc2, 0xc3,
0xdd, 0x00, 0x00, 0x00, 0x00,
0xdd, 0x00, 0x00, 0x00, 0x01, 0xc0,
0xdd, 0x00, 0x00, 0x00, 0x02, 0xc2, 0xc3
], [[], [nil], [false,true], [], [nil], [false,true]])
# map
check([
0x96,
0xde, 0x00, 0x00,
0xde, 0x00, 0x01, 0xc0, 0xc2,
0xde, 0x00, 0x02, 0xc0, 0xc2, 0xc3, 0xc2,
0xdf, 0x00, 0x00, 0x00, 0x00,
0xdf, 0x00, 0x00, 0x00, 0x01, 0xc0, 0xc2,
0xdf, 0x00, 0x00, 0x00, 0x02, 0xc0, 0xc2, 0xc3, 0xc2,
], [{}, {nil=>false}, {true=>false, nil=>false}, {}, {nil=>false}, {true=>false, nil=>false}])

View File

@ -1,58 +0,0 @@
require 'msgpack'
def check(data)
puts "---"
pack = data.to_msgpack
p data
puts pack.unpack('C*').map{|x|"%02x"%x}.join(' ')
re = MessagePack::unpack(pack)
if re != data
p re
puts "** TEST FAILED **"
end
end
check 0
check 1
check 127
check 128
check 255
check 256
check 65535
check 65536
check -1
check -32
check -33
check -128
check -129
check -32768
check -32769
check 1.0
check ""
check "a"
check "a"*31
check "a"*32
check nil
check true
check false
check []
check [[]]
check [[], nil]
check( {nil=>0} )
check (1<<23)
__END__
ary = []
i = 0
while i < (1<<16)
ary << i
i += 1
end
check ary

View File

@ -18,10 +18,16 @@
#include "ruby.h" #include "ruby.h"
#include "msgpack/unpack_define.h" #include "msgpack/unpack_define.h"
static ID s_sysread;
typedef struct { typedef struct {
int finished; int finished;
VALUE source; VALUE source;
size_t offset;
size_t parsed;
VALUE buffer;
VALUE stream;
VALUE streambuf;
} unpack_user; } unpack_user;
@ -144,6 +150,9 @@ static void MessagePack_Unpacker_free(void* data)
static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp) static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp)
{ {
unsigned int i; unsigned int i;
rb_gc_mark(mp->user.buffer);
rb_gc_mark(mp->user.stream);
rb_gc_mark(mp->user.streambuf);
for(i=0; i < mp->top; ++i) { for(i=0; i < mp->top; ++i) {
rb_gc_mark(mp->stack[i].obj); rb_gc_mark(mp->stack[i].obj);
rb_gc_mark(mp->stack[i].map_key); /* maybe map_key is not initialized */ rb_gc_mark(mp->stack[i].map_key); /* maybe map_key is not initialized */
@ -164,14 +173,32 @@ static VALUE MessagePack_Unpacker_reset(VALUE self)
UNPACKER(self, mp); UNPACKER(self, mp);
template_init(mp); template_init(mp);
init_stack(mp); init_stack(mp);
unpack_user u = {0, Qnil}; mp->user.finished = 0;
mp->user = u;
return self; return self;
} }
static VALUE MessagePack_Unpacker_initialize(VALUE self) static VALUE MessagePack_Unpacker_initialize(int argc, VALUE *argv, VALUE self)
{ {
return MessagePack_Unpacker_reset(self); VALUE stream;
switch(argc) {
case 0:
stream = Qnil;
break;
case 1:
stream = argv[0];
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
}
MessagePack_Unpacker_reset(self);
UNPACKER(self, mp);
mp->user.offset = 0;
mp->user.parsed = 0;
mp->user.buffer = rb_str_new("",0);
mp->user.stream = stream;
mp->user.streambuf = rb_str_new("",0);
return self;
} }
@ -249,6 +276,87 @@ static VALUE MessagePack_Unpacker_data(VALUE self)
} }
static VALUE MessagePack_Unpacker_feed(VALUE self, VALUE data)
{
UNPACKER(self, mp);
StringValue(data);
rb_str_cat(mp->user.buffer, RSTRING_PTR(data), RSTRING_LEN(data));
return Qnil;
}
static VALUE MessagePack_Unpacker_stream_get(VALUE self)
{
UNPACKER(self, mp);
return mp->user.stream;
}
static VALUE MessagePack_Unpacker_stream_set(VALUE self, VALUE val)
{
UNPACKER(self, mp);
return mp->user.stream = val;
}
static VALUE MessagePack_Unpacker_fill(VALUE self)
{
UNPACKER(self, mp);
if(mp->user.stream == Qnil) {
return Qnil;
}
size_t len;
if(RSTRING_LEN(mp->user.buffer) == 0) {
rb_funcall(mp->user.stream, s_sysread, 2, LONG2FIX(64*1024), mp->user.buffer);
len = RSTRING_LEN(mp->user.buffer);
} else {
rb_funcall(mp->user.stream, s_sysread, 2, LONG2FIX(64*1024), mp->user.streambuf);
len = RSTRING_LEN(mp->user.streambuf);
rb_str_cat(mp->user.buffer, RSTRING_PTR(mp->user.streambuf), RSTRING_LEN(mp->user.streambuf));
}
return LONG2FIX(len);
}
static VALUE MessagePack_Unpacker_each(VALUE self)
{
UNPACKER(self, mp);
int ret;
#ifdef RETURN_ENUMERATOR
RETURN_ENUMERATOR(self, 0, 0);
#endif
while(1) {
if(RSTRING_LEN(mp->user.buffer) <= mp->user.offset) {
do_fill:
{
VALUE len = MessagePack_Unpacker_fill(self);
if(len == Qnil || FIX2LONG(len) == 0) {
break;
}
}
}
mp->user.source = mp->user.buffer;
ret = template_execute(mp, RSTRING_PTR(mp->user.buffer), RSTRING_LEN(mp->user.buffer), &mp->user.offset);
mp->user.source = Qnil;
if(ret < 0) {
rb_raise(eUnpackError, "parse error.");
} else if(ret > 0) {
VALUE data = template_data(mp);
template_init(mp);
init_stack(mp);
rb_yield(data);
} else {
goto do_fill;
}
}
return Qnil;
}
static VALUE MessagePack_unpack_impl(VALUE args) static VALUE MessagePack_unpack_impl(VALUE args)
{ {
msgpack_unpack_t* mp = (msgpack_unpack_t*)((VALUE*)args)[0]; msgpack_unpack_t* mp = (msgpack_unpack_t*)((VALUE*)args)[0];
@ -292,7 +400,7 @@ static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
msgpack_unpack_t mp; msgpack_unpack_t mp;
template_init(&mp); template_init(&mp);
init_stack(&mp); init_stack(&mp);
unpack_user u = {0, Qnil}; unpack_user u = {0, Qnil, 0, 0, Qnil, Qnil, Qnil};
mp.user = u; mp.user = u;
rb_gc_disable(); rb_gc_disable();
@ -313,17 +421,22 @@ static VALUE MessagePack_unpack(VALUE self, VALUE data)
void Init_msgpack_unpack(VALUE mMessagePack) void Init_msgpack_unpack(VALUE mMessagePack)
{ {
s_sysread = rb_intern("sysread");
eUnpackError = rb_define_class_under(mMessagePack, "UnpackError", rb_eStandardError); eUnpackError = rb_define_class_under(mMessagePack, "UnpackError", rb_eStandardError);
cUnpacker = rb_define_class_under(mMessagePack, "Unpacker", rb_cObject); cUnpacker = rb_define_class_under(mMessagePack, "Unpacker", rb_cObject);
rb_define_alloc_func(cUnpacker, MessagePack_Unpacker_alloc); rb_define_alloc_func(cUnpacker, MessagePack_Unpacker_alloc);
rb_define_method(cUnpacker, "initialize", MessagePack_Unpacker_initialize, 0); rb_define_method(cUnpacker, "initialize", MessagePack_Unpacker_initialize, -1);
rb_define_method(cUnpacker, "execute", MessagePack_Unpacker_execute, 2); rb_define_method(cUnpacker, "execute", MessagePack_Unpacker_execute, 2);
rb_define_method(cUnpacker, "execute_limit", MessagePack_Unpacker_execute_limit, 3); rb_define_method(cUnpacker, "execute_limit", MessagePack_Unpacker_execute_limit, 3);
rb_define_method(cUnpacker, "finished?", MessagePack_Unpacker_finished_p, 0); rb_define_method(cUnpacker, "finished?", MessagePack_Unpacker_finished_p, 0);
rb_define_method(cUnpacker, "data", MessagePack_Unpacker_data, 0); rb_define_method(cUnpacker, "data", MessagePack_Unpacker_data, 0);
rb_define_method(cUnpacker, "reset", MessagePack_Unpacker_reset, 0); rb_define_method(cUnpacker, "reset", MessagePack_Unpacker_reset, 0);
rb_define_method(cUnpacker, "feed", MessagePack_Unpacker_feed, 1);
rb_define_method(cUnpacker, "fill", MessagePack_Unpacker_fill, 0);
rb_define_method(cUnpacker, "each", MessagePack_Unpacker_each, 0);
rb_define_method(cUnpacker, "stream", MessagePack_Unpacker_stream_get, 0);
rb_define_method(cUnpacker, "stream=", MessagePack_Unpacker_stream_set, 1);
rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack, 1); rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack, 1);
rb_define_module_function(mMessagePack, "unpack_limit", MessagePack_unpack_limit, 2); rb_define_module_function(mMessagePack, "unpack_limit", MessagePack_unpack_limit, 2);
} }