rcstorable 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Rakefile +3 -1
  2. data/VERSION +1 -1
  3. data/ext/doc.rb +2 -0
  4. data/ext/rcstorable.c +15 -8
  5. metadata +13 -5
data/Rakefile CHANGED
@@ -12,7 +12,9 @@ begin
12
12
  gem.email = "burke.libbey@canadadrugs.com"
13
13
  gem.homepage = "http://canadadrugs.com"
14
14
  gem.authors = ["Burke Libbey"]
15
- gem.files.include '{spec,lib,ext}/**/*'
15
+ gem.files.include '{spec,lib}/**/*'
16
+ gem.files.include 'ext/**/*.{c,h,rb}'
17
+ gem.files.include 'ext/**/{Makefile,Rakefile}'
16
18
  gem.extensions = ["ext/extconf.rb"]
17
19
  end
18
20
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
data/ext/doc.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'rocco'
2
+ File.open('rcstorable.html','w'){|f|f.puts(Rocco.new('rcstorable.c',[],:language => 'c',:comment_pattern=>/^\s*\/?\*\/?/).to_html)}
data/ext/rcstorable.c CHANGED
@@ -16,10 +16,13 @@ static void read_n_hash_pairs(VALUE, uint32_t);
16
16
  static void read_n_array_entries(VALUE, uint32_t);
17
17
  static VALUE read_string(bool);
18
18
  static void read_magic_numbers();
19
- static void check_pointer(uchar*);
19
+ static inline void check_pointer(uchar*);
20
20
 
21
- enum perl_types
22
- {
21
+ // Perl Storable encodes values with an associated type.
22
+ // There are probably more types than are enumerated here,
23
+ // but I've yet to encounter them.
24
+
25
+ enum perl_types {
23
26
  PT_HASH_KEY = 1,
24
27
  PT_ARRAY = 2,
25
28
  PT_HASH = 3,
@@ -35,6 +38,8 @@ enum perl_types
35
38
  static uchar *serialized;
36
39
  static uchar *serialized_end;
37
40
 
41
+ static uchar *error_message = "malformed data";
42
+
38
43
  /*
39
44
  * Given a perl Storable frozen blob, decode it into a ruby data structure.
40
45
  */
@@ -58,12 +63,12 @@ thaw(VALUE self, VALUE str)
58
63
  * Malformed strings can theoretically cause segfaults. Segfaults are bad.
59
64
  * We'll check pretty much everything we do against the pre-computed end-of-string.
60
65
  */
61
- static void
66
+ static inline void
62
67
  check_pointer(uchar *ptr)
63
68
  {
64
- extern uchar *serialized_end;
69
+ extern uchar *serialized_end, *error_message;
65
70
  if (ptr > serialized_end) {
66
- rb_raise(rb_eRangeError, "malformed data");
71
+ rb_raise(rb_eRangeError, error_message);
67
72
  }
68
73
  }
69
74
 
@@ -155,11 +160,11 @@ static void
155
160
  read_n_array_entries(VALUE array, uint32_t num)
156
161
  {
157
162
  if (num == 0) { return; }
163
+ read_compact_size();
158
164
  rb_ary_push(array, read_object());
159
165
  read_n_array_entries(array, num-1);
160
166
  }
161
167
 
162
-
163
168
  /*
164
169
  * Given a size, read in a string of that size. Note that Storable seems to use 319 as a
165
170
  * magic value, meaning the string should be read until a very low character is found.
@@ -177,15 +182,17 @@ read_string(bool extended_size)
177
182
  uchar *tp = serialized;
178
183
 
179
184
  if (size == 319) { // apparently Storable uses \000\000\001\077 to mean "read until n<7"
185
+ printf("319\n");
180
186
  while (*tp++ >= 7) {
181
187
  check_pointer(tp);
182
188
  actual_size++;
183
189
  }
190
+ printf("319:%d\n",actual_size);
184
191
  size = actual_size;
185
192
  }
186
193
 
187
- uchar *np = malloc(size+1);
188
194
  check_pointer(serialized+size-1);
195
+ uchar *np = malloc(size+1);
189
196
  memcpy(np, serialized, size);
190
197
  serialized += size;
191
198
 
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcstorable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 2
9
+ version: 0.3.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - Burke Libbey
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-02 00:00:00 -06:00
17
+ date: 2010-05-10 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -27,6 +32,7 @@ files:
27
32
  - Rakefile
28
33
  - VERSION
29
34
  - ext/Makefile
35
+ - ext/doc.rb
30
36
  - ext/extconf.rb
31
37
  - ext/rcstorable.c
32
38
  - spec/rcstorable_spec.rb
@@ -44,18 +50,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - ">="
46
52
  - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
47
55
  version: "0"
48
- version:
49
56
  required_rubygems_version: !ruby/object:Gem::Requirement
50
57
  requirements:
51
58
  - - ">="
52
59
  - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
53
62
  version: "0"
54
- version:
55
63
  requirements: []
56
64
 
57
65
  rubyforge_project:
58
- rubygems_version: 1.3.5
66
+ rubygems_version: 1.3.6
59
67
  signing_key:
60
68
  specification_version: 3
61
69
  summary: Ruby C implementation of perl Storable's thaw