Fixed other issues with "bitmask" globset encoding
authorWolfgang Wourdeau <wsourdeau@inverse.ca>
Mon, 1 Aug 2011 20:54:51 +0000 (20:54 +0000)
committerWolfgang Wourdeau <wsourdeau@inverse.ca>
Mon, 1 Aug 2011 20:54:51 +0000 (20:54 +0000)
libmapi/idset.c
testprogs/globset.py

index f9432c6ea448e6f39cf13abac414b47885265d7c..fd1f7e142bc5efc511b754ed09b07369cba63c6c 100644 (file)
@@ -207,12 +207,12 @@ static inline void GLOBSET_parser_do_bitmask(struct GLOBSET_parser *parser)
                if (blank) {
                        if ((mask & bit)) {
                                blank = false;
-                               lowValue = baseValue | ((uint64_t) bit << 40);
+                               lowValue = baseValue + ((uint64_t) (bit + 1) << 40);
                                highValue = lowValue;
                        }
                }
                else {
-                       if ((mask & bit) == 0 || i == 7) {
+                       if ((mask & bit) == 0) {
                                range = talloc_zero(parser, struct globset_range);
                                range->low = lowValue;
                                range->high = highValue;
@@ -221,10 +221,18 @@ static inline void GLOBSET_parser_do_bitmask(struct GLOBSET_parser *parser)
                                blank = true;
                        }
                        else {
-                               highValue = baseValue | ((uint64_t) bit << 40);
+                               highValue = baseValue + ((uint64_t) (bit + 1) << 40);
                        }
                }
        }
+
+       if (!blank) {
+               range = talloc_zero(parser, struct globset_range);
+               range->low = lowValue;
+               range->high = highValue;
+               DLIST_ADD_END(parser->ranges, range, void);
+               parser->range_count++;
+       }
 }
 
 /**
index 2b5196ca8c886ae2e32b40e6c9be0c353d608155..35961439609489d3c51cd4d5d33ca73b0b1cdf7b 100644 (file)
@@ -51,20 +51,28 @@ class GLOBSetRunner:
         blank = False
         lowValue = combined
         highValue = lowValue
+        # print "doBitmask: start (start: %x)" % lowValue
 
         for x in xrange(8):
             bit = 1 << x
+            # print "mask: %s; bit: %s" % (bin(mask), bin(bit))
             if blank:
                 if (mask & bit) != 0:
                     blank = False
-                    lowValue = combined | (bit << 40)
+                    lowValue = combined + ((x + 1) << 40)
                     highValue = lowValue
+                    # print "doBitmask: new record (ends: %x)" % lowValue
             else:
-                if (mask & bit) == 0 or x == 7:
+                if (mask & bit) == 0:
+                    # print "doBitmask: commit: [%.12x:%.12x]" % (lowValue, highValue)
                     self.ranges.append((lowValue, highValue))
                     blank = True
                 else:
-                    highValue = combined | (bit << 40)
+                    highValue = combined + ((x + 1) << 40)
+                    # print "doBitmask: extending range (highValue: %x)" % highValue
+
+        if not blank:
+            self.ranges.append((lowValue, highValue))
 
     def _doRange(self):
         nbr = 6 - self.stackByteLength
@@ -85,6 +93,8 @@ class GLOBSetRunner:
         else:
             raise Exception, "reached negative range count"
 
+        # print "doRange: [%.12x:%.12x]" % (lowValue, highValue)
+
         self.ranges.append((lowValue, highValue))
 
     def _rangeValue(self, bytes):
@@ -122,6 +132,9 @@ class GLOBSetRunner:
                 command_method = command_methods[command]
                 command_method()
             else:
+                # print "buffer: %s..." % ["%.2x" % ord(x) for x in self.buffer[self.start_pos:self.pos]]
+                # for x in self.ranges:
+                #     print "[%.12x:%.12x]" % x
                 raise Exception, "unknown command: %x at pos %d" % (command, self.pos)
 
         return (self.pos - self.start_pos)