msgpack 0.2.2-mswin32 → 0.3.1-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/ext/msgpack.so CHANGED
Binary file
data/ext/pack.c CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
- * MessagePack packing routine for Ruby
2
+ * MessagePack for Ruby packing routine
3
3
  *
4
- * Copyright (C) 2008 FURUHASHI Sadayuki
4
+ * Copyright (C) 2008-2009 FURUHASHI Sadayuki
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -19,10 +19,10 @@
19
19
  #include "msgpack/pack_define.h"
20
20
 
21
21
  #define msgpack_pack_inline_func(name) \
22
- static inline void msgpack_pack_##name
22
+ static inline void msgpack_pack ## name
23
23
 
24
24
  #define msgpack_pack_inline_func_cint(name) \
25
- static inline void msgpack_pack_##name
25
+ static inline void msgpack_pack ## name
26
26
 
27
27
  #define msgpack_pack_user VALUE
28
28
 
data/ext/pack.h CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
- * MessagePack packing routine for Ruby
2
+ * MessagePack for Ruby packing routine
3
3
  *
4
- * Copyright (C) 2008 FURUHASHI Sadayuki
4
+ * Copyright (C) 2008-2009 FURUHASHI Sadayuki
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
data/ext/pack.o CHANGED
Binary file
data/ext/rbinit.c CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * MessagePack for Ruby
3
3
  *
4
- * Copyright (C) 2008 FURUHASHI Sadayuki
4
+ * Copyright (C) 2008-2009 FURUHASHI Sadayuki
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
data/ext/rbinit.o CHANGED
Binary file
data/ext/unpack.c CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
- * MessagePack unpacking routine for Ruby
2
+ * MessagePack for Ruby unpacking routine
3
3
  *
4
- * Copyright (C) 2008 FURUHASHI Sadayuki
4
+ * Copyright (C) 2008-2009 FURUHASHI Sadayuki
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -21,99 +21,99 @@
21
21
 
22
22
  typedef struct {
23
23
  int finished;
24
- VALUE origstr;
25
- } msgpack_unpack_context;
24
+ VALUE source;
25
+ } unpack_user;
26
26
 
27
27
 
28
28
  #define msgpack_unpack_struct(name) \
29
- struct msgpack_unpacker_##name
29
+ struct template ## name
30
30
 
31
31
  #define msgpack_unpack_func(ret, name) \
32
- ret msgpack_unpacker_##name
32
+ ret template ## name
33
33
 
34
34
  #define msgpack_unpack_callback(name) \
35
- template_callback_##name
35
+ template_callback ## name
36
36
 
37
37
  #define msgpack_unpack_object VALUE
38
38
 
39
- #define msgpack_unpack_user msgpack_unpack_context
39
+ #define msgpack_unpack_user unpack_user
40
40
 
41
41
 
42
- struct msgpack_unpacker_context;
43
- typedef struct msgpack_unpacker_context msgpack_unpacker;
42
+ struct template_context;
43
+ typedef struct template_context msgpack_unpack_t;
44
44
 
45
- static void msgpack_unpacker_init(msgpack_unpacker* ctx);
45
+ static void template_init(msgpack_unpack_t* u);
46
46
 
47
- static VALUE msgpack_unpacker_data(msgpack_unpacker* ctx);
47
+ static VALUE template_data(msgpack_unpack_t* u);
48
48
 
49
- static int msgpack_unpacker_execute(msgpack_unpacker* ctx,
49
+ static int template_execute(msgpack_unpack_t* u,
50
50
  const char* data, size_t len, size_t* off);
51
51
 
52
52
 
53
- static inline VALUE template_callback_init(msgpack_unpack_context* x)
53
+ static inline VALUE template_callback_root(unpack_user* u)
54
54
  { return Qnil; }
55
55
 
56
- static inline VALUE template_callback_uint8(msgpack_unpack_context* x, uint8_t d)
57
- { return INT2FIX(d); }
56
+ static inline int template_callback_uint8(unpack_user* u, uint8_t d, VALUE* o)
57
+ { *o = INT2FIX(d); return 0; }
58
58
 
59
- static inline VALUE template_callback_uint16(msgpack_unpack_context* x, uint16_t d)
60
- { return INT2FIX(d); }
59
+ static inline int template_callback_uint16(unpack_user* u, uint16_t d, VALUE* o)
60
+ { *o = INT2FIX(d); return 0; }
61
61
 
62
- static inline VALUE template_callback_uint32(msgpack_unpack_context* x, uint32_t d)
63
- { return UINT2NUM(d); }
62
+ static inline int template_callback_uint32(unpack_user* u, uint32_t d, VALUE* o)
63
+ { *o = UINT2NUM(d); return 0; }
64
64
 
65
- static inline VALUE template_callback_uint64(msgpack_unpack_context* x, uint64_t d)
66
- { return rb_ull2inum(d); }
65
+ static inline int template_callback_uint64(unpack_user* u, uint64_t d, VALUE* o)
66
+ { *o = rb_ull2inum(d); return 0; }
67
67
 
68
- static inline VALUE template_callback_int8(msgpack_unpack_context* x, int8_t d)
69
- { return INT2FIX((long)d); }
68
+ static inline int template_callback_int8(unpack_user* u, int8_t d, VALUE* o)
69
+ { *o = INT2FIX((long)d); return 0; }
70
70
 
71
- static inline VALUE template_callback_int16(msgpack_unpack_context* x, int16_t d)
72
- { return INT2FIX((long)d); }
71
+ static inline int template_callback_int16(unpack_user* u, int16_t d, VALUE* o)
72
+ { *o = INT2FIX((long)d); return 0; }
73
73
 
74
- static inline VALUE template_callback_int32(msgpack_unpack_context* x, int32_t d)
75
- { return INT2NUM((long)d); }
74
+ static inline int template_callback_int32(unpack_user* u, int32_t d, VALUE* o)
75
+ { *o = INT2NUM((long)d); return 0; }
76
76
 
77
- static inline VALUE template_callback_int64(msgpack_unpack_context* x, int64_t d)
78
- { return rb_ll2inum(d); }
77
+ static inline int template_callback_int64(unpack_user* u, int64_t d, VALUE* o)
78
+ { *o = rb_ll2inum(d); return 0; }
79
79
 
80
- static inline VALUE template_callback_float(msgpack_unpack_context* x, float d)
81
- { return rb_float_new(d); }
80
+ static inline int template_callback_float(unpack_user* u, float d, VALUE* o)
81
+ { *o = rb_float_new(d); return 0; }
82
82
 
83
- static inline VALUE template_callback_double(msgpack_unpack_context* x, double d)
84
- { return rb_float_new(d); }
83
+ static inline int template_callback_double(unpack_user* u, double d, VALUE* o)
84
+ { *o = rb_float_new(d); return 0; }
85
85
 
86
- static inline VALUE template_callback_nil(msgpack_unpack_context* x)
87
- { return Qnil; }
86
+ static inline int template_callback_nil(unpack_user* u, VALUE* o)
87
+ { *o = Qnil; return 0; }
88
88
 
89
- static inline VALUE template_callback_true(msgpack_unpack_context* x)
90
- { return Qtrue; }
89
+ static inline int template_callback_true(unpack_user* u, VALUE* o)
90
+ { *o = Qtrue; return 0; }
91
91
 
92
- static inline VALUE template_callback_false(msgpack_unpack_context* x)
93
- { return Qfalse; }
92
+ static inline int template_callback_false(unpack_user* u, VALUE* o)
93
+ { *o = Qfalse; return 0;}
94
94
 
95
- static inline VALUE template_callback_array(msgpack_unpack_context* x, unsigned int n)
96
- { return rb_ary_new2(n); }
95
+ static inline int template_callback_array(unpack_user* u, unsigned int n, VALUE* o)
96
+ { *o = rb_ary_new2(n); return 0; }
97
97
 
98
- static inline void template_callback_array_item(msgpack_unpack_context* x, VALUE* c, VALUE o)
99
- { rb_ary_push(*c, o); } // FIXME set value directry RARRAY_PTR(obj)[RARRAY_LEN(obj)++]
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
100
 
101
- static inline VALUE template_callback_map(msgpack_unpack_context* x, unsigned int n)
102
- { return rb_hash_new(); }
101
+ static inline int template_callback_map(unpack_user* u, unsigned int n, VALUE* o)
102
+ { *o = rb_hash_new(); return 0; }
103
103
 
104
- static inline void template_callback_map_item(msgpack_unpack_context* x, VALUE* c, VALUE k, VALUE v)
105
- { rb_hash_aset(*c, k, v); }
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
106
 
107
- static inline VALUE template_callback_raw(msgpack_unpack_context* x, const char* b, const char* p, unsigned int l)
108
- { return l == 0 ? rb_str_new(0,0) : rb_str_substr(x->origstr, p - b, l); }
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
109
 
110
110
 
111
111
  #include "msgpack/unpack_template.h"
112
112
 
113
113
 
114
114
  #define UNPACKER(from, name) \
115
- msgpack_unpacker *name = NULL; \
116
- Data_Get_Struct(from, msgpack_unpacker, name); \
115
+ msgpack_unpack_t *name = NULL; \
116
+ Data_Get_Struct(from, msgpack_unpack_t, name); \
117
117
  if(name == NULL) { \
118
118
  rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
119
119
  }
@@ -132,7 +132,7 @@ static void MessagePack_Unpacker_free(void* data)
132
132
  if(data) { free(data); }
133
133
  }
134
134
 
135
- static void MessagePack_Unpacker_mark(msgpack_unpacker *mp)
135
+ static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp)
136
136
  {
137
137
  unsigned int i;
138
138
  for(i=0; i < mp->top; ++i) {
@@ -144,7 +144,7 @@ static void MessagePack_Unpacker_mark(msgpack_unpacker *mp)
144
144
  static VALUE MessagePack_Unpacker_alloc(VALUE klass)
145
145
  {
146
146
  VALUE obj;
147
- msgpack_unpacker* mp = ALLOC_N(msgpack_unpacker, 1);
147
+ msgpack_unpack_t* mp = ALLOC_N(msgpack_unpack_t, 1);
148
148
  obj = Data_Wrap_Struct(klass, MessagePack_Unpacker_mark,
149
149
  MessagePack_Unpacker_free, mp);
150
150
  return obj;
@@ -153,9 +153,9 @@ static VALUE MessagePack_Unpacker_alloc(VALUE klass)
153
153
  static VALUE MessagePack_Unpacker_reset(VALUE self)
154
154
  {
155
155
  UNPACKER(self, mp);
156
- msgpack_unpacker_init(mp);
157
- msgpack_unpack_context ctx = {0, Qnil};
158
- mp->user = ctx;
156
+ template_init(mp);
157
+ unpack_user u = {0, Qnil};
158
+ mp->user = u;
159
159
  return self;
160
160
  }
161
161
 
@@ -169,21 +169,20 @@ static VALUE MessagePack_Unpacker_execute_impl(VALUE args)
169
169
  {
170
170
  VALUE self = ((VALUE*)args)[0];
171
171
  VALUE data = ((VALUE*)args)[1];
172
- VALUE off = ((VALUE*)args)[2];
173
172
 
174
173
  UNPACKER(self, mp);
175
- size_t from = NUM2UINT(off);
174
+ size_t from = NUM2UINT(((VALUE*)args)[2]);
176
175
  char* dptr = RSTRING_PTR(data);
177
- long dlen = RSTRING_LEN(data);
176
+ long dlen = FIX2LONG(((VALUE*)args)[3]);
178
177
  int ret;
179
178
 
180
179
  if(from >= dlen) {
181
180
  rb_raise(eUnpackError, "offset is bigger than data buffer size.");
182
181
  }
183
182
 
184
- mp->user.origstr = data;
185
- ret = msgpack_unpacker_execute(mp, dptr, (size_t)dlen, &from);
186
- mp->user.origstr = Qnil;
183
+ mp->user.source = data;
184
+ ret = template_execute(mp, dptr, (size_t)dlen, &from);
185
+ mp->user.source = Qnil;
187
186
 
188
187
  if(ret < 0) {
189
188
  rb_raise(eUnpackError, "parse error.");
@@ -206,17 +205,24 @@ static VALUE MessagePack_Unpacker_execute_rescue(VALUE nouse)
206
205
  #endif
207
206
  }
208
207
 
209
- static VALUE MessagePack_Unpacker_execute(VALUE self, VALUE data, VALUE off)
208
+ static VALUE MessagePack_Unpacker_execute_limit(VALUE self, VALUE data,
209
+ VALUE off, VALUE limit)
210
210
  {
211
211
  // FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
212
212
  rb_gc_disable();
213
- VALUE args[3] = {self, data, off};
213
+ VALUE args[4] = {self, data, off, limit};
214
214
  VALUE ret = rb_rescue(MessagePack_Unpacker_execute_impl, (VALUE)args,
215
215
  MessagePack_Unpacker_execute_rescue, Qnil);
216
216
  rb_gc_enable();
217
217
  return ret;
218
218
  }
219
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
+
220
226
  static VALUE MessagePack_Unpacker_finished_p(VALUE self)
221
227
  {
222
228
  UNPACKER(self, mp);
@@ -229,23 +235,23 @@ static VALUE MessagePack_Unpacker_finished_p(VALUE self)
229
235
  static VALUE MessagePack_Unpacker_data(VALUE self)
230
236
  {
231
237
  UNPACKER(self, mp);
232
- return msgpack_unpacker_data(mp);
238
+ return template_data(mp);
233
239
  }
234
240
 
235
241
 
236
242
  static VALUE MessagePack_unpack_impl(VALUE args)
237
243
  {
238
- msgpack_unpacker* mp = (msgpack_unpacker*)((VALUE*)args)[0];
244
+ msgpack_unpack_t* mp = (msgpack_unpack_t*)((VALUE*)args)[0];
239
245
  VALUE data = ((VALUE*)args)[1];
240
246
 
241
247
  size_t from = 0;
242
248
  char* dptr = RSTRING_PTR(data);
243
- long dlen = RSTRING_LEN(data);
249
+ long dlen = FIX2LONG(((VALUE*)args)[2]);
244
250
  int ret;
245
251
 
246
- mp->user.origstr = data;
247
- ret = msgpack_unpacker_execute(mp, dptr, (size_t)dlen, &from);
248
- mp->user.origstr = Qnil;
252
+ mp->user.source = data;
253
+ ret = template_execute(mp, dptr, (size_t)dlen, &from);
254
+ mp->user.source = Qnil;
249
255
 
250
256
  if(ret < 0) {
251
257
  rb_raise(eUnpackError, "parse error.");
@@ -255,7 +261,7 @@ static VALUE MessagePack_unpack_impl(VALUE args)
255
261
  if(from < dlen) {
256
262
  rb_raise(eUnpackError, "extra bytes.");
257
263
  }
258
- return msgpack_unpacker_data(mp);
264
+ return template_data(mp);
259
265
  }
260
266
  }
261
267
 
@@ -269,22 +275,30 @@ static VALUE MessagePack_unpack_rescue(VALUE args)
269
275
  #endif
270
276
  }
271
277
 
272
- static VALUE MessagePack_unpack(VALUE self, VALUE data)
278
+ static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
273
279
  {
274
280
  CHECK_STRING_TYPE(data);
275
- msgpack_unpacker mp;
276
- msgpack_unpacker_init(&mp);
277
- msgpack_unpack_context ctx = {0, Qnil};
278
- mp.user = ctx;
281
+
282
+ msgpack_unpack_t mp;
283
+ template_init(&mp);
284
+ unpack_user u = {0, Qnil};
285
+ mp.user = u;
279
286
 
280
287
  rb_gc_disable();
281
- VALUE args[2] = {(VALUE)&mp, data};
288
+ VALUE args[3] = {(VALUE)&mp, data, limit};
282
289
  VALUE ret = rb_rescue(MessagePack_unpack_impl, (VALUE)args,
283
290
  MessagePack_unpack_rescue, Qnil);
284
291
  rb_gc_enable();
292
+
285
293
  return ret;
286
294
  }
287
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
+
288
302
 
289
303
  void Init_msgpack_unpack(VALUE mMessagePack)
290
304
  {
@@ -293,10 +307,12 @@ void Init_msgpack_unpack(VALUE mMessagePack)
293
307
  rb_define_alloc_func(cUnpacker, MessagePack_Unpacker_alloc);
294
308
  rb_define_method(cUnpacker, "initialize", MessagePack_Unpacker_initialize, 0);
295
309
  rb_define_method(cUnpacker, "execute", MessagePack_Unpacker_execute, 2);
310
+ rb_define_method(cUnpacker, "execute_limit", MessagePack_Unpacker_execute_limit, 3);
296
311
  rb_define_method(cUnpacker, "finished?", MessagePack_Unpacker_finished_p, 0);
297
312
  rb_define_method(cUnpacker, "data", MessagePack_Unpacker_data, 0);
298
313
  rb_define_method(cUnpacker, "reset", MessagePack_Unpacker_reset, 0);
299
314
  rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack, 1);
315
+ rb_define_module_function(mMessagePack, "unpack_limit", MessagePack_unpack_limit, 2);
300
316
  }
301
317
 
302
318
 
data/ext/unpack.h CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
- * MessagePack unpacking routine for Ruby
2
+ * MessagePack for Ruby unpacking routine
3
3
  *
4
- * Copyright (C) 2008 FURUHASHI Sadayuki
4
+ * Copyright (C) 2008-2009 FURUHASHI Sadayuki
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
data/ext/unpack.o CHANGED
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.2.2
4
+ version: 0.3.1
5
5
  platform: mswin32
6
6
  authors:
7
7
  - FURUHASHI Sadayuki
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-11 00:00:00 +09:00
12
+ date: 2009-03-04 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,8 +22,6 @@ extensions: []
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
- - lib/msgpack
26
- - lib/msgpack/version.rb
27
25
  - ext/extconf.rb
28
26
  - ext/Makefile
29
27
  - ext/msgpack.so
@@ -36,7 +34,7 @@ files:
36
34
  - ext/unpack.h
37
35
  - ext/unpack.o
38
36
  has_rdoc: false
39
- homepage: https://launchpad.net/msgpack/
37
+ homepage: http://msgpack.sourceforge.jp/
40
38
  post_install_message:
41
39
  rdoc_options: []
42
40
 
@@ -57,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
55
  version:
58
56
  requirements: []
59
57
 
60
- rubyforge_project:
58
+ rubyforge_project: msgpack
61
59
  rubygems_version: 1.3.1
62
60
  signing_key:
63
61
  specification_version: 2
@@ -1,9 +0,0 @@
1
- module MessagePack
2
- module VERSION #:nodoc:
3
- MAJOR = 0
4
- MINOR = 2
5
- TINY = 1
6
-
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- end
9
- end