msgpack 0.3.0-x86-mingw32 → 0.3.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/ext/Makefile ADDED
@@ -0,0 +1,156 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ #### Start of system configuration section. ####
5
+
6
+ srcdir = .
7
+ topdir = c:/MinGW/lib/ruby/1.8/i386-mingw32
8
+ hdrdir = $(topdir)
9
+ VPATH = $(srcdir);$(topdir);$(hdrdir)
10
+
11
+ DESTDIR = c:
12
+ exec_prefix = $(prefix)
13
+ prefix = $(DESTDIR)/MinGW
14
+ sharedstatedir = $(prefix)/com
15
+ mandir = $(datarootdir)/man
16
+ psdir = $(docdir)
17
+ oldincludedir = $(DESTDIR)/usr/include
18
+ localedir = $(datarootdir)/locale
19
+ bindir = $(exec_prefix)/bin
20
+ libexecdir = $(exec_prefix)/libexec
21
+ sitedir = $(libdir)/ruby/site_ruby
22
+ htmldir = $(docdir)
23
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
24
+ includedir = $(prefix)/include
25
+ infodir = $(datarootdir)/info
26
+ vendorlibdir = $(vendordir)/$(ruby_version)
27
+ sysconfdir = $(prefix)/etc
28
+ libdir = $(exec_prefix)/lib
29
+ sbindir = $(exec_prefix)/sbin
30
+ rubylibdir = $(libdir)/ruby/$(ruby_version)
31
+ docdir = $(datarootdir)/doc/$(PACKAGE)
32
+ dvidir = $(docdir)
33
+ vendordir = $(libdir)/ruby/vendor_ruby
34
+ datarootdir = $(prefix)/share
35
+ pdfdir = $(docdir)
36
+ archdir = $(rubylibdir)/$(arch)
37
+ sitearchdir = $(sitelibdir)/$(sitearch)
38
+ datadir = $(datarootdir)
39
+ localstatedir = $(prefix)/var
40
+ sitelibdir = $(sitedir)/$(ruby_version)
41
+
42
+ CC = gcc
43
+ LIBRUBY = lib$(LIBRUBY_SO).a
44
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
45
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
46
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
47
+
48
+ RUBY_EXTCONF_H =
49
+ CFLAGS = -g -O2 $(cflags) -I.. -Wall -O4
50
+ INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
51
+ DEFS =
52
+ CPPFLAGS = $(DEFS) $(cppflags)
53
+ CXXFLAGS = $(CFLAGS)
54
+ ldflags = -L.
55
+ dldflags = -Wl,--enable-auto-image-base,--enable-auto-import,--export-all
56
+ archflag =
57
+ DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
58
+ LDSHARED = gcc -shared -s
59
+ AR = ar
60
+ EXEEXT = .exe
61
+
62
+ RUBY_INSTALL_NAME = ruby
63
+ RUBY_SO_NAME = msvcrt-ruby18
64
+ arch = i386-mingw32
65
+ sitearch = i386-msvcrt
66
+ ruby_version = 1.8
67
+ ruby = c:/MinGW/bin/ruby
68
+ RUBY = $(ruby)
69
+ RM = rm -f
70
+ MAKEDIRS = mkdir -p
71
+ INSTALL = /bin/install -c
72
+ INSTALL_PROG = $(INSTALL) -m 0755
73
+ INSTALL_DATA = $(INSTALL) -m 644
74
+ COPY = cp
75
+
76
+ #### End of system configuration section. ####
77
+
78
+ preload =
79
+
80
+ libpath = . $(libdir)
81
+ LIBPATH = -L. -L$(libdir)
82
+ DEFFILE =
83
+
84
+ CLEANFILES = mkmf.log
85
+ DISTCLEANFILES =
86
+
87
+ extout =
88
+ extout_prefix =
89
+ target_prefix =
90
+ LOCAL_LIBS =
91
+ LIBS = $(LIBRUBYARG_SHARED) -lshell32 -lwsock32
92
+ SRCS = pack.c rbinit.c unpack.c
93
+ OBJS = pack.o rbinit.o unpack.o
94
+ TARGET = msgpack
95
+ DLLIB = $(TARGET).so
96
+ EXTSTATIC =
97
+ STATIC_LIB =
98
+
99
+ BINDIR = $(bindir)
100
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
101
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
102
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
103
+
104
+ TARGET_SO = $(DLLIB)
105
+ CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
106
+ CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
107
+
108
+ all: $(DLLIB)
109
+ static: $(STATIC_LIB)
110
+
111
+ clean:
112
+ @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
113
+
114
+ distclean: clean
115
+ @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
116
+ @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
117
+
118
+ realclean: distclean
119
+ install: install-so install-rb
120
+
121
+ install-so: $(RUBYARCHDIR)
122
+ install-so: $(RUBYARCHDIR)/$(DLLIB)
123
+ $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
124
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
125
+ install-rb: pre-install-rb install-rb-default
126
+ install-rb-default: pre-install-rb-default
127
+ pre-install-rb: Makefile
128
+ pre-install-rb-default: Makefile
129
+ $(RUBYARCHDIR):
130
+ $(MAKEDIRS) $@
131
+
132
+ site-install: site-install-so site-install-rb
133
+ site-install-so: install-so
134
+ site-install-rb: install-rb
135
+
136
+ .SUFFIXES: .c .m .cc .cxx .cpp .o
137
+
138
+ .cc.o:
139
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
140
+
141
+ .cxx.o:
142
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
143
+
144
+ .cpp.o:
145
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
146
+
147
+ .c.o:
148
+ $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
149
+
150
+ $(DLLIB): $(OBJS)
151
+ @-$(RM) $@
152
+ $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
153
+
154
+
155
+
156
+ $(OBJS): ruby.h defines.h
data/ext/extconf.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'mkmf'
2
+ $CFLAGS << " -I.. -Wall -O4"
3
+ create_makefile('msgpack')
4
+
data/ext/msgpack.so ADDED
Binary file
data/ext/pack.c ADDED
@@ -0,0 +1,165 @@
1
+ /*
2
+ * MessagePack for Ruby packing routine
3
+ *
4
+ * Copyright (C) 2008-2009 FURUHASHI Sadayuki
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ #include "ruby.h"
19
+ #include "msgpack/pack_define.h"
20
+
21
+ #define msgpack_pack_inline_func(name) \
22
+ static inline void msgpack_pack ## name
23
+
24
+ #define msgpack_pack_inline_func_cint(name) \
25
+ static inline void msgpack_pack ## name
26
+
27
+ #define msgpack_pack_user VALUE
28
+
29
+ #define msgpack_pack_append_buffer(user, buf, len) \
30
+ rb_str_buf_cat(user, (const void*)buf, len)
31
+
32
+ #include "msgpack/pack_template.h"
33
+
34
+
35
+ #ifndef RUBY_VM
36
+ #include "st.h" // ruby hash
37
+ #endif
38
+
39
+ static ID s_to_msgpack;
40
+
41
+ #define ARG_BUFFER(name, argc, argv) \
42
+ VALUE name; \
43
+ if(argc == 1) { \
44
+ name = argv[0]; \
45
+ } else if(argc == 0) { \
46
+ name = rb_str_buf_new(0); \
47
+ } else { \
48
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc); \
49
+ }
50
+
51
+ static VALUE MessagePack_NilClass_to_msgpack(int argc, VALUE *argv, VALUE self)
52
+ {
53
+ ARG_BUFFER(out, argc, argv);
54
+ msgpack_pack_nil(out);
55
+ return out;
56
+ }
57
+
58
+ static VALUE MessagePack_TrueClass_to_msgpack(int argc, VALUE *argv, VALUE self)
59
+ {
60
+ ARG_BUFFER(out, argc, argv);
61
+ msgpack_pack_true(out);
62
+ return out;
63
+ }
64
+
65
+ static VALUE MessagePack_FalseClass_to_msgpack(int argc, VALUE *argv, VALUE self)
66
+ {
67
+ ARG_BUFFER(out, argc, argv);
68
+ msgpack_pack_false(out);
69
+ return out;
70
+ }
71
+
72
+
73
+ static VALUE MessagePack_Fixnum_to_msgpack(int argc, VALUE *argv, VALUE self)
74
+ {
75
+ ARG_BUFFER(out, argc, argv);
76
+ msgpack_pack_long(out, FIX2LONG(self));
77
+ return out;
78
+ }
79
+
80
+
81
+ #ifndef RBIGNUM_SIGN // Ruby 1.8
82
+ #define RBIGNUM_SIGN(b) (RBIGNUM(b)->sign)
83
+ #endif
84
+
85
+ static VALUE MessagePack_Bignum_to_msgpack(int argc, VALUE *argv, VALUE self)
86
+ {
87
+ ARG_BUFFER(out, argc, argv);
88
+ // FIXME bignum
89
+ if(RBIGNUM_SIGN(self)) { // positive
90
+ msgpack_pack_uint64(out, rb_big2ull(self));
91
+ } else { // negative
92
+ msgpack_pack_int64(out, rb_big2ll(self));
93
+ }
94
+ return out;
95
+ }
96
+
97
+ static VALUE MessagePack_Float_to_msgpack(int argc, VALUE *argv, VALUE self)
98
+ {
99
+ ARG_BUFFER(out, argc, argv);
100
+ msgpack_pack_double(out, rb_num2dbl(self));
101
+ return out;
102
+ }
103
+
104
+ static VALUE MessagePack_String_to_msgpack(int argc, VALUE *argv, VALUE self)
105
+ {
106
+ ARG_BUFFER(out, argc, argv);
107
+ msgpack_pack_raw(out, RSTRING_LEN(self));
108
+ msgpack_pack_raw_body(out, RSTRING_PTR(self), RSTRING_LEN(self));
109
+ return out;
110
+ }
111
+
112
+ static VALUE MessagePack_Array_to_msgpack(int argc, VALUE *argv, VALUE self)
113
+ {
114
+ ARG_BUFFER(out, argc, argv);
115
+ msgpack_pack_array(out, RARRAY_LEN(self));
116
+ VALUE* p = RARRAY_PTR(self);
117
+ VALUE* const pend = p + RARRAY_LEN(self);
118
+ for(;p != pend; ++p) {
119
+ rb_funcall(*p, s_to_msgpack, 1, out);
120
+ }
121
+ return out;
122
+ }
123
+
124
+ #ifndef RHASH_SIZE // Ruby 1.8
125
+ #define RHASH_SIZE(h) (RHASH(h)->tbl ? RHASH(h)->tbl->num_entries : 0)
126
+ #endif
127
+
128
+ static int MessagePack_Hash_to_msgpack_foreach(VALUE key, VALUE value, VALUE out)
129
+ {
130
+ if (key == Qundef) { return ST_CONTINUE; }
131
+ rb_funcall(key, s_to_msgpack, 1, out);
132
+ rb_funcall(value, s_to_msgpack, 1, out);
133
+ return ST_CONTINUE;
134
+ }
135
+
136
+ static VALUE MessagePack_Hash_to_msgpack(int argc, VALUE *argv, VALUE self)
137
+ {
138
+ ARG_BUFFER(out, argc, argv);
139
+ msgpack_pack_map(out, RHASH_SIZE(self));
140
+ rb_hash_foreach(self, MessagePack_Hash_to_msgpack_foreach, out);
141
+ return out;
142
+ }
143
+
144
+
145
+ static VALUE MessagePack_pack(VALUE self, VALUE data)
146
+ {
147
+ return rb_funcall(data, s_to_msgpack, 0);
148
+ }
149
+
150
+
151
+ void Init_msgpack_pack(VALUE mMessagePack)
152
+ {
153
+ s_to_msgpack = rb_intern("to_msgpack");
154
+ rb_define_method_id(rb_cNilClass, s_to_msgpack, MessagePack_NilClass_to_msgpack, -1);
155
+ rb_define_method_id(rb_cTrueClass, s_to_msgpack, MessagePack_TrueClass_to_msgpack, -1);
156
+ rb_define_method_id(rb_cFalseClass, s_to_msgpack, MessagePack_FalseClass_to_msgpack, -1);
157
+ rb_define_method_id(rb_cFixnum, s_to_msgpack, MessagePack_Fixnum_to_msgpack, -1);
158
+ rb_define_method_id(rb_cBignum, s_to_msgpack, MessagePack_Bignum_to_msgpack, -1);
159
+ rb_define_method_id(rb_cFloat, s_to_msgpack, MessagePack_Float_to_msgpack, -1);
160
+ rb_define_method_id(rb_cString, s_to_msgpack, MessagePack_String_to_msgpack, -1);
161
+ rb_define_method_id(rb_cArray, s_to_msgpack, MessagePack_Array_to_msgpack, -1);
162
+ rb_define_method_id(rb_cHash, s_to_msgpack, MessagePack_Hash_to_msgpack, -1);
163
+ rb_define_module_function(mMessagePack, "pack", MessagePack_pack, 1);
164
+ }
165
+
data/ext/pack.h ADDED
@@ -0,0 +1,26 @@
1
+ /*
2
+ * MessagePack for Ruby packing routine
3
+ *
4
+ * Copyright (C) 2008-2009 FURUHASHI Sadayuki
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ #ifndef PACK_H__
19
+ #define PACK_H__
20
+
21
+ #include "ruby.h"
22
+
23
+ void Init_msgpack_pack(VALUE mMessagePack);
24
+
25
+ #endif /* pack.h */
26
+
data/ext/pack.o ADDED
Binary file
data/ext/rbinit.c ADDED
@@ -0,0 +1,29 @@
1
+ /*
2
+ * MessagePack for Ruby
3
+ *
4
+ * Copyright (C) 2008-2009 FURUHASHI Sadayuki
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ #include "pack.h"
19
+ #include "unpack.h"
20
+
21
+ static VALUE mMessagePack;
22
+
23
+ void Init_msgpack(void)
24
+ {
25
+ mMessagePack = rb_define_module("MessagePack");
26
+ Init_msgpack_unpack(mMessagePack);
27
+ Init_msgpack_pack(mMessagePack);
28
+ }
29
+
data/ext/rbinit.o ADDED
Binary file
data/ext/unpack.c ADDED
@@ -0,0 +1,318 @@
1
+ /*
2
+ * MessagePack for Ruby unpacking routine
3
+ *
4
+ * Copyright (C) 2008-2009 FURUHASHI Sadayuki
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ #include "ruby.h"
19
+ #include "msgpack/unpack_define.h"
20
+
21
+
22
+ typedef struct {
23
+ int finished;
24
+ VALUE source;
25
+ } unpack_user;
26
+
27
+
28
+ #define msgpack_unpack_struct(name) \
29
+ struct template ## name
30
+
31
+ #define msgpack_unpack_func(ret, name) \
32
+ ret template ## name
33
+
34
+ #define msgpack_unpack_callback(name) \
35
+ template_callback ## name
36
+
37
+ #define msgpack_unpack_object VALUE
38
+
39
+ #define msgpack_unpack_user unpack_user
40
+
41
+
42
+ struct template_context;
43
+ typedef struct template_context msgpack_unpack_t;
44
+
45
+ static void template_init(msgpack_unpack_t* u);
46
+
47
+ static VALUE template_data(msgpack_unpack_t* u);
48
+
49
+ static int template_execute(msgpack_unpack_t* u,
50
+ const char* data, size_t len, size_t* off);
51
+
52
+
53
+ static inline VALUE template_callback_root(unpack_user* u)
54
+ { return Qnil; }
55
+
56
+ static inline int template_callback_uint8(unpack_user* u, uint8_t d, VALUE* o)
57
+ { *o = INT2FIX(d); return 0; }
58
+
59
+ static inline int template_callback_uint16(unpack_user* u, uint16_t d, VALUE* o)
60
+ { *o = INT2FIX(d); return 0; }
61
+
62
+ static inline int template_callback_uint32(unpack_user* u, uint32_t d, VALUE* o)
63
+ { *o = UINT2NUM(d); return 0; }
64
+
65
+ static inline int template_callback_uint64(unpack_user* u, uint64_t d, VALUE* o)
66
+ { *o = rb_ull2inum(d); return 0; }
67
+
68
+ static inline int template_callback_int8(unpack_user* u, int8_t d, VALUE* o)
69
+ { *o = INT2FIX((long)d); return 0; }
70
+
71
+ static inline int template_callback_int16(unpack_user* u, int16_t d, VALUE* o)
72
+ { *o = INT2FIX((long)d); return 0; }
73
+
74
+ static inline int template_callback_int32(unpack_user* u, int32_t d, VALUE* o)
75
+ { *o = INT2NUM((long)d); return 0; }
76
+
77
+ static inline int template_callback_int64(unpack_user* u, int64_t d, VALUE* o)
78
+ { *o = rb_ll2inum(d); return 0; }
79
+
80
+ static inline int template_callback_float(unpack_user* u, float d, VALUE* o)
81
+ { *o = rb_float_new(d); return 0; }
82
+
83
+ static inline int template_callback_double(unpack_user* u, double d, VALUE* o)
84
+ { *o = rb_float_new(d); return 0; }
85
+
86
+ static inline int template_callback_nil(unpack_user* u, VALUE* o)
87
+ { *o = Qnil; return 0; }
88
+
89
+ static inline int template_callback_true(unpack_user* u, VALUE* o)
90
+ { *o = Qtrue; return 0; }
91
+
92
+ static inline int template_callback_false(unpack_user* u, VALUE* o)
93
+ { *o = Qfalse; return 0;}
94
+
95
+ static inline int template_callback_array(unpack_user* u, unsigned int n, VALUE* o)
96
+ { *o = rb_ary_new2(n); return 0; }
97
+
98
+ static inline int template_callback_array_item(unpack_user* u, VALUE* c, VALUE o)
99
+ { rb_ary_push(*c, o); return 0; } // FIXME set value directry RARRAY_PTR(obj)[RARRAY_LEN(obj)++]
100
+
101
+ static inline int template_callback_map(unpack_user* u, unsigned int n, VALUE* o)
102
+ { *o = rb_hash_new(); return 0; }
103
+
104
+ static inline int template_callback_map_item(unpack_user* u, VALUE* c, VALUE k, VALUE v)
105
+ { rb_hash_aset(*c, k, v); return 0; }
106
+
107
+ static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, VALUE* o)
108
+ { *o = (l == 0) ? rb_str_new(0,0) : rb_str_substr(u->source, p - b, l); return 0; }
109
+
110
+
111
+ #include "msgpack/unpack_template.h"
112
+
113
+
114
+ #define UNPACKER(from, name) \
115
+ msgpack_unpack_t *name = NULL; \
116
+ Data_Get_Struct(from, msgpack_unpack_t, name); \
117
+ if(name == NULL) { \
118
+ rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
119
+ }
120
+
121
+ #define CHECK_STRING_TYPE(value) \
122
+ value = rb_check_string_type(value); \
123
+ if( NIL_P(value) ) { \
124
+ rb_raise(rb_eTypeError, "instance of String needed"); \
125
+ }
126
+
127
+ static VALUE cUnpacker;
128
+ static VALUE eUnpackError;
129
+
130
+ static void MessagePack_Unpacker_free(void* data)
131
+ {
132
+ if(data) { free(data); }
133
+ }
134
+
135
+ static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp)
136
+ {
137
+ unsigned int i;
138
+ for(i=0; i < mp->top; ++i) {
139
+ rb_gc_mark(mp->stack[i].obj);
140
+ rb_gc_mark(mp->stack[i].map_key);
141
+ }
142
+ }
143
+
144
+ static VALUE MessagePack_Unpacker_alloc(VALUE klass)
145
+ {
146
+ VALUE obj;
147
+ msgpack_unpack_t* mp = ALLOC_N(msgpack_unpack_t, 1);
148
+ obj = Data_Wrap_Struct(klass, MessagePack_Unpacker_mark,
149
+ MessagePack_Unpacker_free, mp);
150
+ return obj;
151
+ }
152
+
153
+ static VALUE MessagePack_Unpacker_reset(VALUE self)
154
+ {
155
+ UNPACKER(self, mp);
156
+ template_init(mp);
157
+ unpack_user u = {0, Qnil};
158
+ mp->user = u;
159
+ return self;
160
+ }
161
+
162
+ static VALUE MessagePack_Unpacker_initialize(VALUE self)
163
+ {
164
+ return MessagePack_Unpacker_reset(self);
165
+ }
166
+
167
+
168
+ static VALUE MessagePack_Unpacker_execute_impl(VALUE args)
169
+ {
170
+ VALUE self = ((VALUE*)args)[0];
171
+ VALUE data = ((VALUE*)args)[1];
172
+
173
+ UNPACKER(self, mp);
174
+ size_t from = NUM2UINT(((VALUE*)args)[2]);
175
+ char* dptr = RSTRING_PTR(data);
176
+ long dlen = FIX2LONG(((VALUE*)args)[3]);
177
+ int ret;
178
+
179
+ if(from >= dlen) {
180
+ rb_raise(eUnpackError, "offset is bigger than data buffer size.");
181
+ }
182
+
183
+ mp->user.source = data;
184
+ ret = template_execute(mp, dptr, (size_t)dlen, &from);
185
+ mp->user.source = Qnil;
186
+
187
+ if(ret < 0) {
188
+ rb_raise(eUnpackError, "parse error.");
189
+ } else if(ret > 0) {
190
+ mp->user.finished = 1;
191
+ return ULONG2NUM(from);
192
+ } else {
193
+ mp->user.finished = 0;
194
+ return ULONG2NUM(from);
195
+ }
196
+ }
197
+
198
+ static VALUE MessagePack_Unpacker_execute_rescue(VALUE nouse)
199
+ {
200
+ rb_gc_enable();
201
+ #ifdef RUBY_VM
202
+ rb_exc_raise(rb_errinfo());
203
+ #else
204
+ rb_exc_raise(ruby_errinfo);
205
+ #endif
206
+ }
207
+
208
+ static VALUE MessagePack_Unpacker_execute_limit(VALUE self, VALUE data,
209
+ VALUE off, VALUE limit)
210
+ {
211
+ // FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
212
+ rb_gc_disable();
213
+ VALUE args[4] = {self, data, off, limit};
214
+ VALUE ret = rb_rescue(MessagePack_Unpacker_execute_impl, (VALUE)args,
215
+ MessagePack_Unpacker_execute_rescue, Qnil);
216
+ rb_gc_enable();
217
+ return ret;
218
+ }
219
+
220
+ static VALUE MessagePack_Unpacker_execute(VALUE self, VALUE data, VALUE off)
221
+ {
222
+ return MessagePack_Unpacker_execute_limit(self, data, off,
223
+ LONG2FIX(RSTRING_LEN(data)));
224
+ }
225
+
226
+ static VALUE MessagePack_Unpacker_finished_p(VALUE self)
227
+ {
228
+ UNPACKER(self, mp);
229
+ if(mp->user.finished) {
230
+ return Qtrue;
231
+ }
232
+ return Qfalse;
233
+ }
234
+
235
+ static VALUE MessagePack_Unpacker_data(VALUE self)
236
+ {
237
+ UNPACKER(self, mp);
238
+ return template_data(mp);
239
+ }
240
+
241
+
242
+ static VALUE MessagePack_unpack_impl(VALUE args)
243
+ {
244
+ msgpack_unpack_t* mp = (msgpack_unpack_t*)((VALUE*)args)[0];
245
+ VALUE data = ((VALUE*)args)[1];
246
+
247
+ size_t from = 0;
248
+ char* dptr = RSTRING_PTR(data);
249
+ long dlen = FIX2LONG(((VALUE*)args)[2]);
250
+ int ret;
251
+
252
+ mp->user.source = data;
253
+ ret = template_execute(mp, dptr, (size_t)dlen, &from);
254
+ mp->user.source = Qnil;
255
+
256
+ if(ret < 0) {
257
+ rb_raise(eUnpackError, "parse error.");
258
+ } else if(ret == 0) {
259
+ rb_raise(eUnpackError, "insufficient bytes.");
260
+ } else {
261
+ if(from < dlen) {
262
+ rb_raise(eUnpackError, "extra bytes.");
263
+ }
264
+ return template_data(mp);
265
+ }
266
+ }
267
+
268
+ static VALUE MessagePack_unpack_rescue(VALUE args)
269
+ {
270
+ rb_gc_enable();
271
+ #ifdef RUBY_VM
272
+ rb_exc_raise(rb_errinfo());
273
+ #else
274
+ rb_exc_raise(ruby_errinfo);
275
+ #endif
276
+ }
277
+
278
+ static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
279
+ {
280
+ CHECK_STRING_TYPE(data);
281
+
282
+ msgpack_unpack_t mp;
283
+ template_init(&mp);
284
+ unpack_user u = {0, Qnil};
285
+ mp.user = u;
286
+
287
+ rb_gc_disable();
288
+ VALUE args[3] = {(VALUE)&mp, data, limit};
289
+ VALUE ret = rb_rescue(MessagePack_unpack_impl, (VALUE)args,
290
+ MessagePack_unpack_rescue, Qnil);
291
+ rb_gc_enable();
292
+
293
+ return ret;
294
+ }
295
+
296
+ static VALUE MessagePack_unpack(VALUE self, VALUE data)
297
+ {
298
+ return MessagePack_unpack_limit(self, data,
299
+ LONG2FIX(RSTRING_LEN(data)));
300
+ }
301
+
302
+
303
+ void Init_msgpack_unpack(VALUE mMessagePack)
304
+ {
305
+ eUnpackError = rb_define_class_under(mMessagePack, "UnpackError", rb_eStandardError);
306
+ cUnpacker = rb_define_class_under(mMessagePack, "Unpacker", rb_cObject);
307
+ rb_define_alloc_func(cUnpacker, MessagePack_Unpacker_alloc);
308
+ rb_define_method(cUnpacker, "initialize", MessagePack_Unpacker_initialize, 0);
309
+ rb_define_method(cUnpacker, "execute", MessagePack_Unpacker_execute, 2);
310
+ rb_define_method(cUnpacker, "execute_limit", MessagePack_Unpacker_execute_limit, 3);
311
+ rb_define_method(cUnpacker, "finished?", MessagePack_Unpacker_finished_p, 0);
312
+ rb_define_method(cUnpacker, "data", MessagePack_Unpacker_data, 0);
313
+ rb_define_method(cUnpacker, "reset", MessagePack_Unpacker_reset, 0);
314
+ rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack, 1);
315
+ rb_define_module_function(mMessagePack, "unpack_limit", MessagePack_unpack_limit, 2);
316
+ }
317
+
318
+
data/ext/unpack.h ADDED
@@ -0,0 +1,26 @@
1
+ /*
2
+ * MessagePack for Ruby unpacking routine
3
+ *
4
+ * Copyright (C) 2008-2009 FURUHASHI Sadayuki
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ #ifndef UNPACK_H__
19
+ #define UNPACK_H__
20
+
21
+ #include "ruby.h"
22
+
23
+ void Init_msgpack_unpack(VALUE mMessagePack);
24
+
25
+ #endif /* unpack.h */
26
+
data/ext/unpack.o ADDED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: x86-mingw32
6
6
  authors:
7
7
  - FURUHASHI Sadayuki
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-01 00:00:00 +09:00
12
+ date: 2009-03-04 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -21,8 +21,18 @@ extensions: []
21
21
 
22
22
  extra_rdoc_files: []
23
23
 
24
- files: []
25
-
24
+ files:
25
+ - ext/extconf.rb
26
+ - ext/Makefile
27
+ - ext/msgpack.so
28
+ - ext/pack.c
29
+ - ext/pack.h
30
+ - ext/pack.o
31
+ - ext/rbinit.c
32
+ - ext/rbinit.o
33
+ - ext/unpack.c
34
+ - ext/unpack.h
35
+ - ext/unpack.o
26
36
  has_rdoc: false
27
37
  homepage: http://msgpack.sourceforge.jp/
28
38
  post_install_message:
@@ -45,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
55
  version:
46
56
  requirements: []
47
57
 
48
- rubyforge_project:
58
+ rubyforge_project: msgpack
49
59
  rubygems_version: 1.3.1
50
60
  signing_key:
51
61
  specification_version: 2