ox 1.8.7 → 1.8.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ox might be problematic. Click here for more details.

data/README.md CHANGED
@@ -34,6 +34,10 @@ A fast XML parser and Object marshaller as a Ruby gem.
34
34
 
35
35
  ## <a name="release">Release Notes</a>
36
36
 
37
+ ### Release 1.8.8
38
+
39
+ - Fixed bug in check for open and close element names matching.
40
+
37
41
  ### Release 1.8.7
38
42
 
39
43
  - Added a correct check for element open and close names.
@@ -42,11 +46,6 @@ A fast XML parser and Object marshaller as a Ruby gem.
42
46
 
43
47
  - Fixed a few minor bugs.
44
48
 
45
- ### Release 1.8.6
46
-
47
- - Removed broken check for matching start and end element names in SAX mode. The names are still included in the
48
- handler callbacks so the user can perform the check is desired.
49
-
50
49
  ## <a name="description">Description</a>
51
50
 
52
51
  Optimized XML (Ox), as the name implies was written to provide speed optimized
@@ -38,18 +38,22 @@
38
38
  #include "cache.h"
39
39
 
40
40
  struct _Cache {
41
- char *key; /* only set if the node has a value, and it is not an exact match */
41
+ /* The key is a length byte followed by the key as a string. If the key is longer than 254 characters then the
42
+ length is 255. The key can be for a premature value and in that case the length byte is greater than the length
43
+ of the key. */
44
+ char *key;
42
45
  VALUE value;
43
46
  struct _Cache *slots[16];
44
47
  };
45
48
 
46
49
  static void slot_print(Cache cache, unsigned int depth);
47
50
 
48
- static char* dupstr(const char *s) {
49
- size_t len = strlen(s) + 1;
51
+ static char* form_key(const char *s) {
52
+ size_t len = strlen(s);
50
53
  char *d = ALLOC_N(char, len);
51
54
 
52
- memcpy(d, s, len);
55
+ *d = (255 <= len) ? 255 : len;
56
+ memcpy(d + 1, s, len + 1);
53
57
 
54
58
  return d;
55
59
  }
@@ -74,41 +78,59 @@ ox_cache_get(Cache cache, const char *key, VALUE **slot, char **keyp) {
74
78
  }
75
79
  cache = *cp;
76
80
  cp = cache->slots + (unsigned int)(*k & 0x0F); /* lower 4 bits */
77
- if (0 == *cp) {
81
+ if (0 == *cp) { /* nothing on this tree so set key and value as a premature key/value pair */
78
82
  ox_cache_new(cp);
79
83
  cache = *cp;
80
- cache->key = ('\0' == *(k + 1)) ? 0 : dupstr(key);
84
+ cache->key = form_key(key);
81
85
  break;
82
- } else {
83
- cache = *cp;
84
- if (Qundef != cache->value && 0 != cache->key) {
85
- unsigned char *ck = (unsigned char*)(cache->key + (unsigned int)(k - (unsigned char*)key + 1));
86
-
87
- if (0 == strcmp((char*)ck, (char*)(k + 1))) {
88
- break;
89
- } else {
90
- Cache *cp2 = cp;
86
+ } else {
87
+ int depth = (int)(k - (unsigned char*)key + 1);
88
+
89
+ cache = *cp;
90
+
91
+ if ('\0' == *(k + 1)) { /* exact match */
92
+ if (0 == cache->key) { /* nothing in this spot so take it */
93
+ cache->key = form_key(key);
94
+ break;
95
+ } else if ((depth == *cache->key || 255 < depth) && 0 == strcmp(key, cache->key + 1)) { /* match */
96
+ break;
97
+ } else { /* have to move the current premature key/value deeper */
98
+ unsigned char *ck = (unsigned char*)(cache->key + depth + 1);
99
+ Cache orig = *cp;
91
100
 
92
- /* if value was set along with the key then there are no slots filled yet */
93
- cp2 = (*cp2)->slots + (*ck >> 4);
94
- ox_cache_new(cp2);
95
- cp2 = (*cp2)->slots + (*ck & 0x0F);
96
- ox_cache_new(cp2);
97
- if ('\0' == *(ck + 1)) {
98
- xfree(cache->key);
99
- } else {
100
- (*cp2)->key = cache->key;
101
- }
102
- (*cp2)->value = cache->value;
103
- cache->key = 0;
104
- cache->value = Qundef;
105
- }
106
- }
101
+ cp = (*cp)->slots + (*ck >> 4);
102
+ ox_cache_new(cp);
103
+ cp = (*cp)->slots + (*ck & 0x0F);
104
+ ox_cache_new(cp);
105
+ (*cp)->key = cache->key;
106
+ (*cp)->value = cache->value;
107
+ orig->key = 0;
108
+ orig->value = Qundef;
109
+ }
110
+ } else { /* not exact match but on the path */
111
+ if (0 != cache->key) { /* there is a key/value here already */
112
+ if (depth == *cache->key || (255 <= depth && 0 == strncmp(cache->key, key, depth) && '\0' == cache->key[depth])) { /* key belongs here */
113
+ continue;
114
+ } else {
115
+ unsigned char *ck = (unsigned char*)(cache->key + depth + 1);
116
+ Cache orig = *cp;
117
+
118
+ cp = (*cp)->slots + (*ck >> 4);
119
+ ox_cache_new(cp);
120
+ cp = (*cp)->slots + (*ck & 0x0F);
121
+ ox_cache_new(cp);
122
+ (*cp)->key = cache->key;
123
+ (*cp)->value = cache->value;
124
+ orig->key = 0;
125
+ orig->value = Qundef;
126
+ }
127
+ }
128
+ }
107
129
  }
108
130
  }
109
131
  *slot = &cache->value;
110
132
  if (0 != keyp) {
111
- *keyp = cache->key;
133
+ *keyp = cache->key + 1;
112
134
  }
113
135
  return cache->value;
114
136
  }
@@ -137,7 +159,6 @@ slot_print(Cache c, unsigned int depth) {
137
159
  if (0 == (*cp)->key && Qundef == (*cp)->value) {
138
160
  printf("%s%02u:\n", indent, i);
139
161
  } else {
140
- const char *key = (0 == (*cp)->key) ? "*" : (*cp)->key;
141
162
  const char *vs;
142
163
  const char *clas;
143
164
 
@@ -150,7 +171,7 @@ slot_print(Cache c, unsigned int depth) {
150
171
  vs = StringValuePtr(rs);
151
172
  clas = rb_class2name(rb_obj_class((*cp)->value));
152
173
  }
153
- printf("%s%02u: %s = %s (%s)\n", indent, i, key, vs, clas);
174
+ printf("%s%02u: %s = %s (%s)\n", indent, i, (*cp)->key, vs, clas);
154
175
  }
155
176
  slot_print(*cp, depth + 2);
156
177
  }
@@ -49,6 +49,7 @@ ox_cache_test() {
49
49
 
50
50
  ox_cache_new(&c);
51
51
  for (d = data; 0 != *d; d++) {
52
+ /*printf("*** cache_get on %s\n", *d);*/
52
53
  v = ox_cache_get(c, *d, &slot, 0);
53
54
  if (Qundef == v) {
54
55
  if (0 == slot) {
@@ -63,7 +64,7 @@ ox_cache_test() {
63
64
 
64
65
  printf("*** get on '%s' returned '%s' (%s)\n", *d, StringValuePtr(rs), rb_class2name(rb_obj_class(v)));
65
66
  }
66
- /*ox_cache_print(c); */
67
+ /*ox_cache_print(c);*/
67
68
  }
68
69
  ox_cache_print(c);
69
70
  }
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Ox
3
3
  # Current version of the module.
4
- VERSION = '1.8.7'
4
+ VERSION = '1.8.8'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.7
4
+ version: 1.8.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-08 00:00:00.000000000 Z
12
+ date: 2013-02-17 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! "A fast XML parser and object serializer that uses only standard C
15
15
  lib.\n \nOptimized XML (Ox), as the name implies was written to provide